mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-09-25 17:04:54 +00:00
This commit is contained in:
parent
90e9f809be
commit
d24b5e9c50
@ -15,6 +15,7 @@ package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import static javax.ws.rs.core.Response.Status.CREATED;
|
||||
import static org.openmetadata.catalog.Entity.FIELD_OWNER;
|
||||
import static org.openmetadata.catalog.type.Include.ALL;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
@ -139,7 +140,7 @@ public class DatabaseRepository extends EntityRepository<Database> {
|
||||
List<String> result = findTo(database.getId(), Entity.DATABASE, Relationship.HAS, Entity.LOCATION);
|
||||
if (result.size() == 1) {
|
||||
String locationId = result.get(0);
|
||||
return daoCollection.locationDAO().findEntityReferenceById(UUID.fromString(locationId));
|
||||
return daoCollection.locationDAO().findEntityReferenceById(UUID.fromString(locationId), ALL);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ public class DatabaseServiceRepository extends EntityRepository<DatabaseService>
|
||||
List<EntityReference> airflowPipelines = new ArrayList<>();
|
||||
for (String airflowPipelineId : airflowPipelineIds) {
|
||||
airflowPipelines.add(
|
||||
daoCollection.airflowPipelineDAO().findEntityReferenceById(UUID.fromString(airflowPipelineId)));
|
||||
daoCollection.airflowPipelineDAO().findEntityReferenceById(UUID.fromString(airflowPipelineId), Include.ALL));
|
||||
}
|
||||
return airflowPipelines;
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ package org.openmetadata.catalog.jdbi3;
|
||||
import static org.openmetadata.catalog.Entity.FIELD_DESCRIPTION;
|
||||
import static org.openmetadata.catalog.Entity.FIELD_OWNER;
|
||||
import static org.openmetadata.catalog.Entity.getEntityFields;
|
||||
import static org.openmetadata.catalog.type.Include.ALL;
|
||||
import static org.openmetadata.catalog.type.Include.DELETED;
|
||||
import static org.openmetadata.catalog.util.EntityUtil.compareTagLabel;
|
||||
import static org.openmetadata.catalog.util.EntityUtil.entityReferenceMatch;
|
||||
@ -235,7 +236,7 @@ public abstract class EntityRepository<T> {
|
||||
@Transaction
|
||||
public void initSeedData(T entity) throws IOException {
|
||||
EntityInterface<T> entityInterface = Entity.getEntityInterface(entity);
|
||||
String existingJson = dao.findJsonByFqn(entityInterface.getFullyQualifiedName(), Include.ALL);
|
||||
String existingJson = dao.findJsonByFqn(entityInterface.getFullyQualifiedName(), ALL);
|
||||
if (existingJson != null) {
|
||||
LOG.info("{} {} is already initialized", entityType, entityInterface.getFullyQualifiedName());
|
||||
return;
|
||||
@ -336,7 +337,7 @@ public abstract class EntityRepository<T> {
|
||||
return JsonUtils.readValue(json, entityClass);
|
||||
}
|
||||
// If requested the latest version, return it from current version of the entity
|
||||
T entity = setFields(dao.findEntityById(UUID.fromString(id), Include.ALL), putFields);
|
||||
T entity = setFields(dao.findEntityById(UUID.fromString(id), ALL), putFields);
|
||||
EntityInterface<T> entityInterface = getEntityInterface(entity);
|
||||
if (entityInterface.getVersion().equals(requestedVersion)) {
|
||||
return entity;
|
||||
@ -347,7 +348,7 @@ public abstract class EntityRepository<T> {
|
||||
|
||||
@Transaction
|
||||
public EntityHistory listVersions(String id) throws IOException, ParseException {
|
||||
T latest = setFields(dao.findEntityById(UUID.fromString(id), Include.ALL), putFields);
|
||||
T latest = setFields(dao.findEntityById(UUID.fromString(id), ALL), putFields);
|
||||
String extensionPrefix = EntityUtil.getVersionExtensionPrefix(entityType);
|
||||
List<EntityVersionPair> oldVersions = daoCollection.entityExtensionDAO().getEntityVersions(id, extensionPrefix);
|
||||
oldVersions.sort(EntityUtil.compareVersion.reversed());
|
||||
@ -380,7 +381,7 @@ public abstract class EntityRepository<T> {
|
||||
EntityInterface<T> updatedInterface = getEntityInterface(updated);
|
||||
|
||||
// Check if there is any original, deleted or not
|
||||
T original = JsonUtils.readValue(dao.findJsonByFqn(getFullyQualifiedName(updated), Include.ALL), entityClass);
|
||||
T original = JsonUtils.readValue(dao.findJsonByFqn(getFullyQualifiedName(updated), ALL), entityClass);
|
||||
if (original == null) {
|
||||
return new PutResponse<>(Status.CREATED, withHref(uriInfo, createNewEntity(updated)), RestUtil.ENTITY_CREATED);
|
||||
}
|
||||
@ -775,7 +776,7 @@ public abstract class EntityRepository<T> {
|
||||
List<EntityReference> refs = findFrom(toId, toEntityType, Relationship.CONTAINS);
|
||||
// An entity can have only one container
|
||||
ensureSingleRelationship(toEntityType, toId, refs, "container", true);
|
||||
return Entity.getEntityReferenceById(refs.get(0).getType(), refs.get(0).getId());
|
||||
return Entity.getEntityReferenceById(refs.get(0).getType(), refs.get(0).getId(), ALL);
|
||||
}
|
||||
|
||||
public void ensureSingleRelationship(
|
||||
@ -795,7 +796,7 @@ public abstract class EntityRepository<T> {
|
||||
public EntityReference getOwner(UUID id, String entityType) throws IOException, ParseException {
|
||||
List<EntityReference> refs = findFrom(id, entityType, Relationship.OWNS);
|
||||
ensureSingleRelationship(entityType, id, refs, "owners", false);
|
||||
return refs.isEmpty() ? null : Entity.getEntityReferenceById(refs.get(0).getType(), refs.get(0).getId());
|
||||
return refs.isEmpty() ? null : Entity.getEntityReferenceById(refs.get(0).getType(), refs.get(0).getId(), ALL);
|
||||
}
|
||||
|
||||
public List<String> findTo(UUID fromId, String fromEntityType, Relationship relationship, String toEntityType) {
|
||||
|
@ -17,6 +17,7 @@
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import static org.openmetadata.catalog.Entity.GLOSSARY_TERM;
|
||||
import static org.openmetadata.catalog.type.Include.ALL;
|
||||
import static org.openmetadata.catalog.util.EntityUtil.stringMatch;
|
||||
import static org.openmetadata.catalog.util.EntityUtil.termReferenceMatch;
|
||||
import static org.openmetadata.common.utils.CommonUtil.listOrEmpty;
|
||||
@ -79,7 +80,7 @@ public class GlossaryTermRepository extends EntityRepository<GlossaryTerm> {
|
||||
|
||||
private EntityReference getParent(GlossaryTerm entity) throws IOException {
|
||||
List<String> ids = findFrom(entity.getId(), GLOSSARY_TERM, Relationship.PARENT_OF, GLOSSARY_TERM);
|
||||
return ids.size() == 1 ? Entity.getEntityReferenceById(GLOSSARY_TERM, UUID.fromString(ids.get(0))) : null;
|
||||
return ids.size() == 1 ? Entity.getEntityReferenceById(GLOSSARY_TERM, UUID.fromString(ids.get(0)), ALL) : null;
|
||||
}
|
||||
|
||||
private List<EntityReference> getChildren(GlossaryTerm entity) throws IOException {
|
||||
@ -187,7 +188,7 @@ public class GlossaryTermRepository extends EntityRepository<GlossaryTerm> {
|
||||
}
|
||||
|
||||
public EntityReference getGlossary(String id) throws IOException {
|
||||
return daoCollection.glossaryDAO().findEntityReferenceById(UUID.fromString(id));
|
||||
return daoCollection.glossaryDAO().findEntityReferenceById(UUID.fromString(id), ALL);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -15,6 +15,7 @@ package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import static org.openmetadata.catalog.Entity.FIELD_OWNER;
|
||||
import static org.openmetadata.catalog.Entity.MLMODEL;
|
||||
import static org.openmetadata.catalog.type.Include.ALL;
|
||||
import static org.openmetadata.catalog.util.EntityUtil.entityReferenceMatch;
|
||||
import static org.openmetadata.catalog.util.EntityUtil.mlFeatureMatch;
|
||||
import static org.openmetadata.catalog.util.EntityUtil.mlHyperParameterMatch;
|
||||
@ -192,7 +193,9 @@ public class MlModelRepository extends EntityRepository<MlModel> {
|
||||
if (mlModel != null) {
|
||||
List<String> ids = findTo(mlModel.getId(), Entity.MLMODEL, Relationship.USES, Entity.DASHBOARD);
|
||||
ensureSingleRelationship(MLMODEL, mlModel.getId(), ids, "dashboards", false);
|
||||
return ids.isEmpty() ? null : daoCollection.dashboardDAO().findEntityReferenceById(UUID.fromString(ids.get(0)));
|
||||
return ids.isEmpty()
|
||||
? null
|
||||
: daoCollection.dashboardDAO().findEntityReferenceById(UUID.fromString(ids.get(0)), ALL);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -13,6 +13,8 @@
|
||||
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import static org.openmetadata.catalog.type.Include.ALL;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.security.GeneralSecurityException;
|
||||
@ -62,13 +64,13 @@ public class RoleRepository extends EntityRepository<Role> {
|
||||
|
||||
@Override
|
||||
public Role setFields(Role role, Fields fields) throws IOException {
|
||||
role.setPolicy(fields.contains("policy") ? getPolicyForRole(role) : null);
|
||||
role.setTeams(fields.contains("teams") ? getTeamsForRole(role) : null);
|
||||
role.setUsers(fields.contains("users") ? getUsersForRole(role) : null);
|
||||
role.setPolicy(fields.contains("policy") ? getPolicy(role) : null);
|
||||
role.setTeams(fields.contains("teams") ? getTeams(role) : null);
|
||||
role.setUsers(fields.contains("users") ? getUsers(role) : null);
|
||||
return role;
|
||||
}
|
||||
|
||||
private EntityReference getPolicyForRole(@NonNull Role role) throws IOException {
|
||||
private EntityReference getPolicy(@NonNull Role role) throws IOException {
|
||||
List<String> result = findTo(role.getId(), Entity.ROLE, Relationship.CONTAINS, Entity.POLICY);
|
||||
if (result.size() != 1) {
|
||||
LOG.warn(
|
||||
@ -77,15 +79,15 @@ public class RoleRepository extends EntityRepository<Role> {
|
||||
role.getName());
|
||||
return null;
|
||||
}
|
||||
return Entity.getEntityReferenceById(Entity.POLICY, UUID.fromString(result.get(0)));
|
||||
return Entity.getEntityReferenceById(Entity.POLICY, UUID.fromString(result.get(0)), ALL);
|
||||
}
|
||||
|
||||
private List<EntityReference> getUsersForRole(@NonNull Role role) throws IOException {
|
||||
private List<EntityReference> getUsers(@NonNull Role role) throws IOException {
|
||||
List<String> ids = findFrom(role.getId(), Entity.ROLE, Relationship.HAS, Entity.USER);
|
||||
return EntityUtil.populateEntityReferences(ids, Entity.USER);
|
||||
}
|
||||
|
||||
private List<EntityReference> getTeamsForRole(@NonNull Role role) throws IOException {
|
||||
private List<EntityReference> getTeams(@NonNull Role role) throws IOException {
|
||||
List<String> ids = findFrom(role.getId(), Entity.ROLE, Relationship.HAS, Entity.TEAM);
|
||||
return EntityUtil.populateEntityReferences(ids, Entity.TEAM);
|
||||
}
|
||||
|
@ -92,6 +92,7 @@ import org.openmetadata.catalog.api.services.CreateMessagingService.MessagingSer
|
||||
import org.openmetadata.catalog.api.services.CreatePipelineService;
|
||||
import org.openmetadata.catalog.api.services.CreatePipelineService.PipelineServiceType;
|
||||
import org.openmetadata.catalog.api.services.CreateStorageService;
|
||||
import org.openmetadata.catalog.api.teams.CreateTeam;
|
||||
import org.openmetadata.catalog.entity.data.Chart;
|
||||
import org.openmetadata.catalog.entity.data.Database;
|
||||
import org.openmetadata.catalog.entity.data.Glossary;
|
||||
@ -845,11 +846,24 @@ public abstract class EntityResourceTest<T, K> extends CatalogApplicationTest {
|
||||
if (!supportsOwner) {
|
||||
return;
|
||||
}
|
||||
|
||||
TeamResourceTest teamResourceTest = new TeamResourceTest();
|
||||
CreateTeam createTeam = teamResourceTest.createRequest(test);
|
||||
Team team = teamResourceTest.createAndCheckEntity(createTeam, ADMIN_AUTH_HEADERS);
|
||||
EntityReference teamReference = new TeamEntityInterface(team).getEntityReference();
|
||||
|
||||
// Entity with user as owner is created successfully
|
||||
createAndCheckEntity(createRequest(getEntityName(test, 1), "", "", USER_OWNER1), ADMIN_AUTH_HEADERS);
|
||||
|
||||
// Entity with team as owner is created successfully
|
||||
createAndCheckEntity(createRequest(getEntityName(test, 2), "", "", TEAM_OWNER1), ADMIN_AUTH_HEADERS);
|
||||
T entity = createAndCheckEntity(createRequest(getEntityName(test, 2), "", "", teamReference), ADMIN_AUTH_HEADERS);
|
||||
EntityInterface<T> entityInterface = getEntityInterface(entity);
|
||||
|
||||
// Delete team and ensure the entity still exists but with owner as deleted
|
||||
teamResourceTest.deleteEntity(team.getId(), ADMIN_AUTH_HEADERS);
|
||||
entity = getEntity(entityInterface.getId(), "owner", ADMIN_AUTH_HEADERS);
|
||||
entityInterface = getEntityInterface(entity);
|
||||
assertTrue(entityInterface.getOwner().getDeleted());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user