mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-09-26 01:15:08 +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.openmetadata.catalog.Entity;
|
||||
import org.openmetadata.catalog.entity.data.Location;
|
||||
import org.openmetadata.catalog.entity.services.StorageService;
|
||||
import org.openmetadata.catalog.exception.CatalogExceptionMessage;
|
||||
import org.openmetadata.catalog.resources.locations.LocationResource;
|
||||
import org.openmetadata.catalog.type.ChangeDescription;
|
||||
@ -57,8 +58,8 @@ public class LocationRepository extends EntityRepository<Location> {
|
||||
|
||||
@Override
|
||||
public Location setFields(Location location, Fields fields) throws IOException {
|
||||
location.setService(getService(location));
|
||||
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.setTags(fields.contains("tags") ? getTags(location.getFullyQualifiedName()) : null);
|
||||
return location;
|
||||
@ -142,17 +143,21 @@ public class LocationRepository extends EntityRepository<Location> {
|
||||
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
|
||||
public void prepare(Location location) throws IOException {
|
||||
EntityReference storageService = getService(location.getService());
|
||||
location.setService(storageService);
|
||||
// Set data in location entity based on storage relationship
|
||||
StorageService storageService = getService(location.getService().getId(), location.getService().getType());
|
||||
location.setService(new StorageServiceRepository.StorageServiceEntityInterface(storageService)
|
||||
.getEntityReference());
|
||||
location.setServiceType(storageService.getServiceType());
|
||||
location.setFullyQualifiedName(getFQN(location));
|
||||
|
||||
// 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
|
||||
EntityUtil.populateOwner(dao.userDAO(), dao.teamDAO(), location.getOwner()); // Validate owner
|
||||
location.setTags(EntityUtil.addDerivedTags(dao.tagDAO(), location.getTags()));
|
||||
}
|
||||
|
||||
|
@ -674,7 +674,8 @@ public class LocationResourceTest extends CatalogApplicationTest {
|
||||
location = byName ? getLocationByName(location.getFullyQualifiedName(), fields, adminAuthHeaders()) :
|
||||
getLocation(location.getId(), fields, adminAuthHeaders());
|
||||
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
|
||||
fields = "owner,service";
|
||||
|
Loading…
x
Reference in New Issue
Block a user