mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-09-26 09:22:14 +00:00
This commit is contained in:
parent
13fb6b5c96
commit
b7711bf21a
@ -17,6 +17,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
|||||||
import org.jdbi.v3.sqlobject.transaction.Transaction;
|
import org.jdbi.v3.sqlobject.transaction.Transaction;
|
||||||
import org.openmetadata.catalog.Entity;
|
import org.openmetadata.catalog.Entity;
|
||||||
import org.openmetadata.catalog.entity.data.Location;
|
import org.openmetadata.catalog.entity.data.Location;
|
||||||
|
import org.openmetadata.catalog.entity.services.StorageService;
|
||||||
import org.openmetadata.catalog.exception.CatalogExceptionMessage;
|
import org.openmetadata.catalog.exception.CatalogExceptionMessage;
|
||||||
import org.openmetadata.catalog.resources.locations.LocationResource;
|
import org.openmetadata.catalog.resources.locations.LocationResource;
|
||||||
import org.openmetadata.catalog.type.ChangeDescription;
|
import org.openmetadata.catalog.type.ChangeDescription;
|
||||||
@ -57,8 +58,8 @@ public class LocationRepository extends EntityRepository<Location> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Location setFields(Location location, Fields fields) throws IOException {
|
public Location setFields(Location location, Fields fields) throws IOException {
|
||||||
|
location.setService(getService(location));
|
||||||
location.setOwner(fields.contains("owner") ? getOwner(location) : null);
|
location.setOwner(fields.contains("owner") ? getOwner(location) : null);
|
||||||
location.setService(fields.contains("service") ? getService(location) : null);
|
|
||||||
location.setFollowers(fields.contains("followers") ? getFollowers(location) : null);
|
location.setFollowers(fields.contains("followers") ? getFollowers(location) : null);
|
||||||
location.setTags(fields.contains("tags") ? getTags(location.getFullyQualifiedName()) : null);
|
location.setTags(fields.contains("tags") ? getTags(location.getFullyQualifiedName()) : null);
|
||||||
return location;
|
return location;
|
||||||
@ -142,17 +143,21 @@ public class LocationRepository extends EntityRepository<Location> {
|
|||||||
return EntityUtil.populateOwner(dao.userDAO(), dao.teamDAO(), location.getOwner());
|
return EntityUtil.populateOwner(dao.userDAO(), dao.teamDAO(), location.getOwner());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private StorageService getService(UUID serviceId, String entityType) throws IOException {
|
||||||
|
if (entityType.equalsIgnoreCase(Entity.STORAGE_SERVICE)) {
|
||||||
|
return dao.storageServiceDAO().findEntityById(serviceId);
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException(CatalogExceptionMessage.invalidServiceEntity(entityType, Entity.LOCATION));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void prepare(Location location) throws IOException {
|
public void prepare(Location location) throws IOException {
|
||||||
EntityReference storageService = getService(location.getService());
|
StorageService storageService = getService(location.getService().getId(), location.getService().getType());
|
||||||
location.setService(storageService);
|
location.setService(new StorageServiceRepository.StorageServiceEntityInterface(storageService)
|
||||||
// Set data in location entity based on storage relationship
|
.getEntityReference());
|
||||||
|
location.setServiceType(storageService.getServiceType());
|
||||||
location.setFullyQualifiedName(getFQN(location));
|
location.setFullyQualifiedName(getFQN(location));
|
||||||
|
EntityUtil.populateOwner(dao.userDAO(), dao.teamDAO(), location.getOwner()); // Validate owner
|
||||||
// Check if owner is valid and set the relationship
|
|
||||||
location.setOwner(EntityUtil.populateOwner(dao.userDAO(), dao.teamDAO(), location.getOwner()));
|
|
||||||
|
|
||||||
// Validate location tags and add derived tags to the list
|
|
||||||
location.setTags(EntityUtil.addDerivedTags(dao.tagDAO(), location.getTags()));
|
location.setTags(EntityUtil.addDerivedTags(dao.tagDAO(), location.getTags()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -674,7 +674,8 @@ public class LocationResourceTest extends CatalogApplicationTest {
|
|||||||
location = byName ? getLocationByName(location.getFullyQualifiedName(), fields, adminAuthHeaders()) :
|
location = byName ? getLocationByName(location.getFullyQualifiedName(), fields, adminAuthHeaders()) :
|
||||||
getLocation(location.getId(), fields, adminAuthHeaders());
|
getLocation(location.getId(), fields, adminAuthHeaders());
|
||||||
assertNotNull(location.getOwner());
|
assertNotNull(location.getOwner());
|
||||||
assertNull(location.getService());
|
assertNotNull(location.getService()); // We always return the service
|
||||||
|
assertNotNull(location.getServiceType()); // We always return the service
|
||||||
|
|
||||||
// .../locations?fields=owner,service
|
// .../locations?fields=owner,service
|
||||||
fields = "owner,service";
|
fields = "owner,service";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user