Fix #1527: List locations is not including the service and the serviceType in the result (#1530)

This commit is contained in:
Alberto Miorin 2021-12-03 03:54:14 +01:00 committed by GitHub
parent 13fb6b5c96
commit b7711bf21a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 10 deletions

View File

@ -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;
@ -141,18 +142,22 @@ public class LocationRepository extends EntityRepository<Location> {
public EntityReference getOwnerReference(Location location) throws IOException {
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()));
}

View File

@ -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";