diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/exception/CatalogGenericExceptionMapper.java b/openmetadata-service/src/main/java/org/openmetadata/service/exception/CatalogGenericExceptionMapper.java index a63b922e27d..a4c7ae6c536 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/exception/CatalogGenericExceptionMapper.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/exception/CatalogGenericExceptionMapper.java @@ -42,7 +42,6 @@ public class CatalogGenericExceptionMapper implements ExceptionMapper @Override public Response toResponse(Throwable ex) { LOG.debug(ex.getMessage()); - ex.printStackTrace(); if (ex instanceof ProcessingException || ex instanceof IllegalArgumentException || ex instanceof javax.ws.rs.BadRequestException) { diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/BotRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/BotRepository.java index 7a5f0227458..15aa689c292 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/BotRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/BotRepository.java @@ -40,7 +40,7 @@ public class BotRepository extends EntityRepository { @Override public Bot clearFields(Bot entity, Fields fields) { - return entity; // Nothing to do + return entity; } @Override diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ChartRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ChartRepository.java index 54f8e4f3bc7..16493f73f71 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ChartRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ChartRepository.java @@ -74,10 +74,7 @@ public class ChartRepository extends EntityRepository { @Override public Chart setFields(Chart chart, Fields fields) { - if (chart.getService() == null) { - chart.setService(getContainer(chart.getId())); - } - return chart; + return chart.withService(getContainer(chart.getId())); } @Override diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ClassificationRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ClassificationRepository.java index 9804bbde0f0..11eeaf6278c 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ClassificationRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ClassificationRepository.java @@ -32,6 +32,7 @@ import org.openmetadata.schema.type.TagLabel.TagSource; import org.openmetadata.service.Entity; import org.openmetadata.service.exception.CatalogExceptionMessage; import org.openmetadata.service.jdbi3.CollectionDAO.EntityRelationshipRecord; +import org.openmetadata.service.jdbi3.EntityRepository.EntityUpdater; import org.openmetadata.service.resources.tags.ClassificationResource; import org.openmetadata.service.util.EntityUtil.Fields; @@ -46,6 +47,7 @@ public class ClassificationRepository extends EntityRepository { dao, "", ""); + quoteFqn = true; } @Override @@ -55,13 +57,8 @@ public class ClassificationRepository extends EntityRepository { @Override public Classification setFields(Classification classification, Fields fields) { - if (fields.contains("termCount")) { - classification.withTermCount(getTermCount(classification)); - } - if (fields.contains("usageCount")) { - classification.withUsageCount(getUsageCount(classification)); - } - return classification; + classification.withTermCount(fields.contains("termCount") ? getTermCount(classification) : null); + return classification.withUsageCount(fields.contains("usageCount") ? getUsageCount(classification) : null); } @Override @@ -86,18 +83,12 @@ public class ClassificationRepository extends EntityRepository { } private int getTermCount(Classification classification) { - if (classification.getTermCount() != null) { - return classification.getTermCount(); - } ListFilter filter = new ListFilter(Include.NON_DELETED).addQueryParam("parent", classification.getFullyQualifiedName()); return daoCollection.tagDAO().listCount(filter); } private Integer getUsageCount(Classification classification) { - if (classification.getUsageCount() != null) { - return classification.getUsageCount(); - } return daoCollection.tagUsageDAO().getTagCount(TagSource.CLASSIFICATION.ordinal(), classification.getName()); } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ContainerRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ContainerRepository.java index 24e0f0ab52e..0c6792cbd14 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ContainerRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ContainerRepository.java @@ -9,7 +9,6 @@ import static org.openmetadata.service.Entity.STORAGE_SERVICE; import com.google.common.collect.Lists; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import javax.json.JsonPatch; import org.openmetadata.schema.EntityInterface; @@ -48,8 +47,7 @@ public class ContainerRepository extends EntityRepository { @Override public Container setFields(Container container, EntityUtil.Fields fields) { setDefaultFields(container); - container.setChildren(fields.contains("children") ? getChildrenContainers(container) : container.getChildren()); - container.setParent(fields.contains("parent") ? getParentContainer(container) : container.getParent()); + container.setParent(fields.contains("parent") ? getParent(container) : container.getParent()); if (container.getDataModel() != null) { populateDataModelColumnTags(fields.contains(FIELD_TAGS), container.getDataModel().getColumns()); } @@ -58,6 +56,7 @@ public class ContainerRepository extends EntityRepository { @Override public Container clearFields(Container container, EntityUtil.Fields fields) { + container.setChildren(fields.contains("children") ? getChildren(container) : null); container.setParent(fields.contains("parent") ? container.getParent() : null); return container.withDataModel(fields.contains("dataModel") ? container.getDataModel() : null); } @@ -69,33 +68,12 @@ public class ContainerRepository extends EntityRepository { } } - private EntityReference getParentContainer(Container container) { - if (container == null) return null; - return container.getParent() != null - ? container.getParent() - : getFromEntityRef(container.getId(), Relationship.CONTAINS, CONTAINER, false); - } - private void setDefaultFields(Container container) { - if (container.getService() != null) { - { - return; - } - } EntityReference parentServiceRef = getFromEntityRef(container.getId(), Relationship.CONTAINS, STORAGE_SERVICE, true); container.withService(parentServiceRef); } - private List getChildrenContainers(Container container) { - if (container == null) { - return Collections.emptyList(); - } - return !nullOrEmpty(container.getChildren()) - ? container.getChildren() - : findTo(container.getId(), CONTAINER, Relationship.CONTAINS, CONTAINER); - } - @Override public void setFullyQualifiedName(Container container) { if (container.getParent() != null) { diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DashboardDataModelRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DashboardDataModelRepository.java index eb24659153f..1434eb75a35 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DashboardDataModelRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DashboardDataModelRepository.java @@ -161,10 +161,8 @@ public class DashboardDataModelRepository extends EntityRepository columns) { for (Column c : listOrEmpty(columns)) { - if (c.getTags() == null) { - c.setTags(setTags ? getTags(c.getFullyQualifiedName()) : c.getTags()); - getColumnTags(setTags, c.getChildren()); - } + c.setTags(setTags ? getTags(c.getFullyQualifiedName()) : c.getTags()); + getColumnTags(setTags, c.getChildren()); } } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DashboardRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DashboardRepository.java index b4a17267ee8..dd16f560f96 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DashboardRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DashboardRepository.java @@ -83,16 +83,10 @@ public class DashboardRepository extends EntityRepository { @Override public Dashboard setFields(Dashboard dashboard, Fields fields) { - if (dashboard.getService() == null) { - dashboard.setService(getContainer(dashboard.getId())); - } - if (dashboard.getCharts() == null) { - dashboard.setCharts(fields.contains("charts") ? getRelatedEntities(dashboard, Entity.CHART) : null); - } - if (dashboard.getDataModels() == null) { - dashboard.setDataModels( - fields.contains("dataModels") ? getRelatedEntities(dashboard, Entity.DASHBOARD_DATA_MODEL) : null); - } + dashboard.setService(getContainer(dashboard.getId())); + dashboard.setCharts(fields.contains("charts") ? getRelatedEntities(dashboard, Entity.CHART) : null); + dashboard.setDataModels( + fields.contains("dataModels") ? getRelatedEntities(dashboard, Entity.DASHBOARD_DATA_MODEL) : null); if (dashboard.getUsageSummary() == null) { dashboard.withUsageSummary( fields.contains("usageSummary") @@ -187,10 +181,9 @@ public class DashboardRepository extends EntityRepository { } private List getRelatedEntities(Dashboard dashboard, String entityType) { - if (dashboard == null) { - return Collections.emptyList(); - } - return findTo(dashboard.getId(), Entity.DASHBOARD, Relationship.HAS, entityType); + return dashboard == null + ? Collections.emptyList() + : findTo(dashboard.getId(), Entity.DASHBOARD, Relationship.HAS, entityType); } /** Handles entity updated from PUT and POST operation. */ diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DataProductRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DataProductRepository.java index b7f5d83841f..48621ceeef0 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DataProductRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DataProductRepository.java @@ -14,7 +14,6 @@ package org.openmetadata.service.jdbi3; import static org.openmetadata.common.utils.CommonUtil.listOrEmpty; -import static org.openmetadata.common.utils.CommonUtil.nullOrEmpty; import java.util.List; import lombok.extern.slf4j.Slf4j; @@ -51,13 +50,6 @@ public class DataProductRepository extends EntityRepository { return entity.withExperts(fields.contains("experts") ? entity.getExperts() : null); } - // TODO to to inheritance for experts - private List getExperts(DataProduct entity) { - return !nullOrEmpty(entity.getExperts()) - ? entity.getExperts() - : findTo(entity.getId(), Entity.DATA_PRODUCT, Relationship.EXPERT, Entity.USER); - } - @Override public void prepare(DataProduct entity) { // Parent, Experts, Owner are already validated diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DatabaseRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DatabaseRepository.java index 3dfde040918..2a4dda5304f 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DatabaseRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DatabaseRepository.java @@ -13,7 +13,6 @@ package org.openmetadata.service.jdbi3; -import static org.openmetadata.common.utils.CommonUtil.nullOrEmpty; import static org.openmetadata.schema.type.Include.ALL; import static org.openmetadata.service.Entity.DATABASE_SERVICE; import static org.openmetadata.service.Entity.FIELD_DOMAIN; @@ -25,6 +24,7 @@ import org.openmetadata.schema.type.EntityReference; import org.openmetadata.schema.type.Include; import org.openmetadata.schema.type.Relationship; import org.openmetadata.service.Entity; +import org.openmetadata.service.jdbi3.EntityRepository.EntityUpdater; import org.openmetadata.service.resources.databases.DatabaseResource; import org.openmetadata.service.util.EntityUtil; import org.openmetadata.service.util.EntityUtil.Fields; @@ -71,18 +71,13 @@ public class DatabaseRepository extends EntityRepository { } private List getSchemas(Database database) { - if (database == null) { - return null; - } - return !nullOrEmpty(database.getDatabaseSchemas()) - ? database.getDatabaseSchemas() + return database == null + ? null : findTo(database.getId(), Entity.DATABASE, Relationship.CONTAINS, Entity.DATABASE_SCHEMA); } public Database setFields(Database database, Fields fields) { - if (database.getService() == null) { - database.setService(getContainer(database.getId())); - } + database.setService(getContainer(database.getId())); database.setDatabaseSchemas( fields.contains("databaseSchemas") ? getSchemas(database) : database.getDatabaseSchemas()); if (database.getUsageSummary() == null) { diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DatabaseSchemaRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DatabaseSchemaRepository.java index f7d078537f4..0f861c6e2a4 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DatabaseSchemaRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DatabaseSchemaRepository.java @@ -26,6 +26,7 @@ import org.openmetadata.schema.type.EntityReference; import org.openmetadata.schema.type.Include; import org.openmetadata.schema.type.Relationship; import org.openmetadata.service.Entity; +import org.openmetadata.service.jdbi3.EntityRepository.EntityUpdater; import org.openmetadata.service.resources.databases.DatabaseSchemaResource; import org.openmetadata.service.util.EntityUtil; import org.openmetadata.service.util.EntityUtil.Fields; @@ -73,10 +74,9 @@ public class DatabaseSchemaRepository extends EntityRepository { } private List getTables(DatabaseSchema schema) { - if (schema == null) { - return Collections.emptyList(); - } - return findTo(schema.getId(), Entity.DATABASE_SCHEMA, Relationship.CONTAINS, Entity.TABLE); + return schema == null + ? Collections.emptyList() + : findTo(schema.getId(), Entity.DATABASE_SCHEMA, Relationship.CONTAINS, Entity.TABLE); } public DatabaseSchema setFields(DatabaseSchema schema, Fields fields) { @@ -92,11 +92,9 @@ public class DatabaseSchemaRepository extends EntityRepository { } private void setDefaultFields(DatabaseSchema schema) { - EntityReference databaseRef = schema.getDatabase() != null ? schema.getDatabase() : getContainer(schema.getId()); - if (schema.getService() == null) { - Database database = Entity.getEntity(databaseRef, "", Include.ALL); - schema.withDatabase(databaseRef).withService(database.getService()); - } + EntityReference databaseRef = getContainer(schema.getId()); + Database database = Entity.getEntity(databaseRef, "", Include.ALL); + schema.withDatabase(databaseRef).withService(database.getService()); } @Override diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DomainRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DomainRepository.java index fab120fb5be..00c919b68ce 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DomainRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DomainRepository.java @@ -14,8 +14,6 @@ package org.openmetadata.service.jdbi3; import static org.openmetadata.common.utils.CommonUtil.listOrEmpty; -import static org.openmetadata.common.utils.CommonUtil.nullOrEmpty; -import static org.openmetadata.service.Entity.DOMAIN; import java.util.List; import lombok.extern.slf4j.Slf4j; @@ -44,34 +42,13 @@ public class DomainRepository extends EntityRepository { @Override public Domain setFields(Domain entity, Fields fields) { - entity.withParent(fields.contains("parent") ? getParent(entity) : entity.getParent()); - entity.withChildren(fields.contains("children") ? getChildren(entity) : entity.getChildren()); - return entity.withExperts(fields.contains("experts") ? getExperts(entity) : entity.getExperts()); + return entity.withParent(fields.contains("parent") ? getParent(entity) : entity.getParent()); } @Override public Domain clearFields(Domain entity, Fields fields) { entity.withParent(fields.contains("parent") ? entity.getParent() : null); - entity.withChildren(fields.contains("children") ? entity.getChildren() : null); - return entity.withExperts(fields.contains("experts") ? entity.getExperts() : null); - } - - private EntityReference getParent(Domain entity) { - return entity.getParent() != null - ? entity.getParent() - : getFromEntityRef(entity.getId(), Relationship.CONTAINS, DOMAIN, false); - } - - private List getChildren(Domain entity) { - return !nullOrEmpty(entity.getChildren()) - ? entity.getChildren() - : findTo(entity.getId(), DOMAIN, Relationship.CONTAINS, DOMAIN); - } - - private List getExperts(Domain entity) { - return !nullOrEmpty(entity.getExperts()) - ? entity.getExperts() - : findTo(entity.getId(), Entity.DOMAIN, Relationship.EXPERT, Entity.USER); + return entity; } @Override diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java index 350658a3b34..356c44033a0 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java @@ -681,6 +681,9 @@ public abstract class EntityRepository { entity.setDomain(fields.contains(FIELD_DOMAIN) ? getDomain(entity) : entity.getDomain()); entity.setDataProducts(fields.contains(FIELD_DATA_PRODUCTS) ? getDataProducts(entity) : entity.getDataProducts()); entity.setFollowers(fields.contains(FIELD_FOLLOWERS) ? getFollowers(entity) : entity.getFollowers()); + entity.setChildren(fields.contains("children") ? getChildren(entity) : entity.getChildren()); + entity.setExperts(fields.contains("experts") ? getExperts(entity) : entity.getExperts()); + entity.setReviewers(fields.contains("reviewers") ? getReviewers(entity) : entity.getReviewers()); setFields(entity, fields); return entity; } @@ -692,6 +695,9 @@ public abstract class EntityRepository { entity.setDomain(fields.contains(FIELD_DOMAIN) ? entity.getDomain() : null); entity.setDataProducts(fields.contains(FIELD_DATA_PRODUCTS) ? entity.getDataProducts() : null); entity.setFollowers(fields.contains(FIELD_FOLLOWERS) ? entity.getFollowers() : null); + entity.setChildren(fields.contains("children") ? entity.getChildren() : null); + entity.setExperts(fields.contains("experts") ? entity.getExperts() : null); + entity.setReviewers(fields.contains("reviewers") ? entity.getReviewers() : null); clearFields(entity, fields); return entity; } @@ -964,13 +970,17 @@ public abstract class EntityRepository { Entity.getFeedRepository().deleteByAbout(entityInterface.getId()); // Remove entity from the cache - CACHE_WITH_ID.invalidate(new ImmutablePair<>(entityType, entityInterface.getId())); - CACHE_WITH_NAME.invalidate(new ImmutablePair<>(entityType, entityInterface.getFullyQualifiedName())); + invalidate(entityInterface); // Finally, delete the entity dao.delete(id); } + private void invalidate(T entity) { + CACHE_WITH_ID.invalidate(new ImmutablePair<>(entityType, entity.getId())); + CACHE_WITH_NAME.invalidate(new ImmutablePair<>(entityType, entity.getFullyQualifiedName())); + } + @Transaction public PutResponse deleteFollower(String updatedBy, UUID entityId, UUID userId) { T entity = find(entityId, NON_DELETED); @@ -1034,8 +1044,7 @@ public abstract class EntityRepository { if (update) { dao.update(entity.getId(), entity.getFullyQualifiedName(), JsonUtils.pojoToJson(entity)); LOG.info("Updated {}:{}:{}", entityType, entity.getId(), entity.getFullyQualifiedName()); - CACHE_WITH_ID.invalidate(new ImmutablePair<>(entityType, entity.getId())); - CACHE_WITH_NAME.invalidate(new ImmutablePair<>(entityType, entity.getFullyQualifiedName())); + invalidate(entity); } else { dao.insert(entity, entity.getFullyQualifiedName()); LOG.info("Created {}:{}:{}", entityType, entity.getId(), entity.getFullyQualifiedName()); @@ -1172,8 +1181,8 @@ public abstract class EntityRepository { } public Object getExtension(T entity) { - if (!supportsExtension || entity.getExtension() != null) { - return entity.getExtension(); + if (!supportsExtension) { + return null; } String fieldFQNPrefix = TypeRegistry.getCustomPropertyFQNPrefix(entityType); List records = @@ -1260,7 +1269,7 @@ public abstract class EntityRepository { } protected List getTags(T entity) { - return !supportsTags || !nullOrEmpty(entity.getTags()) ? entity.getTags() : getTags(entity.getFullyQualifiedName()); + return !supportsTags ? null : getTags(entity.getFullyQualifiedName()); } protected List getTags(String fqn) { @@ -1268,11 +1277,8 @@ public abstract class EntityRepository { } protected List getFollowers(T entity) { - if (!supportsFollower || entity == null) { - return Collections.emptyList(); - } - return !nullOrEmpty(entity.getFollowers()) - ? entity.getFollowers() + return !supportsFollower || entity == null + ? Collections.emptyList() : findFrom(entity.getId(), entityType, Relationship.FOLLOWS, Entity.USER); } @@ -1500,22 +1506,31 @@ public abstract class EntityRepository { } public EntityReference getOwner(T entity) { - return !supportsOwner || entity.getOwner() != null - ? entity.getOwner() - : getFromEntityRef(entity.getId(), Relationship.OWNS, null, false); + return !supportsOwner ? null : getFromEntityRef(entity.getId(), Relationship.OWNS, null, false); } public EntityReference getDomain(T entity) { - return entity.getDomain() != null - ? entity.getDomain() - : getFromEntityRef(entity.getId(), Relationship.HAS, DOMAIN, false); + return getFromEntityRef(entity.getId(), Relationship.HAS, DOMAIN, false); } private List getDataProducts(T entity) { - if (!supportsDataProducts || nullOrEmpty(entity.getDataProducts())) { - return entity.getDataProducts(); - } - return findFrom(entity.getId(), entityType, Relationship.HAS, DATA_PRODUCT); + return !supportsDataProducts ? null : findFrom(entity.getId(), entityType, Relationship.HAS, DATA_PRODUCT); + } + + protected EntityReference getParent(T entity) { + return getFromEntityRef(entity.getId(), Relationship.CONTAINS, entityType, false); + } + + protected List getChildren(T entity) { + return findTo(entity.getId(), entityType, Relationship.CONTAINS, entityType); + } + + protected List getReviewers(T entity) { + return findFrom(entity.getId(), entityType, Relationship.REVIEWS, Entity.USER); + } + + protected List getExperts(T entity) { + return findTo(entity.getId(), entityType, Relationship.EXPERT, Entity.USER); } public EntityReference getOwner(EntityReference ref) { diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/GlossaryRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/GlossaryRepository.java index 46886713498..e908fe425bb 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/GlossaryRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/GlossaryRepository.java @@ -80,14 +80,12 @@ public class GlossaryRepository extends EntityRepository { @Override public Glossary setFields(Glossary glossary, Fields fields) { glossary.setTermCount(fields.contains("termCount") ? getTermCount(glossary) : glossary.getTermCount()); - glossary.setReviewers(fields.contains("reviewers") ? getReviewers(glossary) : glossary.getReviewers()); return glossary.withUsageCount(fields.contains("usageCount") ? getUsageCount(glossary) : glossary.getUsageCount()); } @Override public Glossary clearFields(Glossary glossary, Fields fields) { glossary.setTermCount(fields.contains("termCount") ? glossary.getTermCount() : null); - glossary.setReviewers(fields.contains("reviewers") ? glossary.getReviewers() : null); return glossary.withUsageCount(fields.contains("usageCount") ? glossary.getUsageCount() : null); } @@ -113,15 +111,10 @@ public class GlossaryRepository extends EntityRepository { } private Integer getUsageCount(Glossary glossary) { - return glossary.getUsageCount() != null - ? glossary.getUsageCount() - : daoCollection.tagUsageDAO().getTagCount(TagSource.GLOSSARY.ordinal(), glossary.getName()); + return daoCollection.tagUsageDAO().getTagCount(TagSource.GLOSSARY.ordinal(), glossary.getName()); } private Integer getTermCount(Glossary glossary) { - if (glossary.getTermCount() != null) { - return glossary.getTermCount(); - } ListFilter filter = new ListFilter(Include.NON_DELETED).addQueryParam("parent", FullyQualifiedName.build(glossary.getName())); return daoCollection.glossaryTermDAO().listCount(filter); @@ -151,12 +144,6 @@ public class GlossaryRepository extends EntityRepository { return glossaryCsv.importCsv(csv, dryRun); } - private List getReviewers(Glossary entity) { - return !nullOrEmpty(entity.getReviewers()) - ? entity.getReviewers() - : findFrom(entity.getId(), Entity.GLOSSARY, Relationship.REVIEWS, Entity.USER); - } - public static class GlossaryCsv extends EntityCsv { public static final CsvDocumentation DOCUMENTATION = getCsvDocumentation(Entity.GLOSSARY); public static final List HEADERS = DOCUMENTATION.getHeaders(); diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/GlossaryTermRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/GlossaryTermRepository.java index 1690076336a..ff732061c5e 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/GlossaryTermRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/GlossaryTermRepository.java @@ -72,17 +72,13 @@ public class GlossaryTermRepository extends EntityRepository { @Override public GlossaryTerm setFields(GlossaryTerm entity, Fields fields) { entity.withGlossary(getGlossary(entity)).withParent(getParent(entity)); - entity.setChildren(fields.contains("children") ? getChildren(entity) : entity.getChildren()); entity.setRelatedTerms(fields.contains("relatedTerms") ? getRelatedTerms(entity) : entity.getRelatedTerms()); - entity.setReviewers(fields.contains(FIELD_REVIEWERS) ? getReviewers(entity) : entity.getReviewers()); return entity.withUsageCount(fields.contains("usageCount") ? getUsageCount(entity) : entity.getUsageCount()); } @Override public GlossaryTerm clearFields(GlossaryTerm entity, Fields fields) { - entity.setChildren(fields.contains("children") ? entity.getChildren() : null); entity.setRelatedTerms(fields.contains("relatedTerms") ? entity.getRelatedTerms() : null); - entity.setReviewers(fields.contains(FIELD_REVIEWERS) ? entity.getReviewers() : null); return entity.withUsageCount(fields.contains("usageCount") ? entity.getUsageCount() : null); } @@ -131,33 +127,11 @@ public class GlossaryTermRepository extends EntityRepository { } private Integer getUsageCount(GlossaryTerm term) { - return term.getUsageCount() != null - ? term.getUsageCount() - : daoCollection.tagUsageDAO().getTagCount(TagSource.GLOSSARY.ordinal(), term.getFullyQualifiedName()); - } - - private EntityReference getParent(GlossaryTerm entity) { - return entity.getParent() != null - ? entity.getParent() - : getFromEntityRef(entity.getId(), Relationship.CONTAINS, GLOSSARY_TERM, false); - } - - private List getChildren(GlossaryTerm entity) { - return !nullOrEmpty(entity.getChildren()) - ? entity.getChildren() - : findTo(entity.getId(), GLOSSARY_TERM, Relationship.CONTAINS, GLOSSARY_TERM); + return daoCollection.tagUsageDAO().getTagCount(TagSource.GLOSSARY.ordinal(), term.getFullyQualifiedName()); } private List getRelatedTerms(GlossaryTerm entity) { - return !nullOrEmpty(entity.getRelatedTerms()) - ? entity.getRelatedTerms() - : findBoth(entity.getId(), GLOSSARY_TERM, Relationship.RELATED_TO, GLOSSARY_TERM); - } - - private List getReviewers(GlossaryTerm entity) { - return !nullOrEmpty(entity.getReviewers()) - ? entity.getReviewers() - : findFrom(entity.getId(), GLOSSARY_TERM, Relationship.REVIEWS, Entity.USER); + return findBoth(entity.getId(), GLOSSARY_TERM, Relationship.RELATED_TO, GLOSSARY_TERM); } @Override diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/KpiRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/KpiRepository.java index f4ea864839b..d3489712003 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/KpiRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/KpiRepository.java @@ -45,11 +45,8 @@ public class KpiRepository extends EntityRepository { @Override public Kpi setFields(Kpi kpi, EntityUtil.Fields fields) { kpi.setDataInsightChart(fields.contains("dataInsightChart") ? getDataInsightChart(kpi) : kpi.getDataInsightChart()); - if (kpi.getKpiResult() == null) { - kpi.withKpiResult( - fields.contains(KPI_RESULT_FIELD) ? getKpiResult(kpi.getFullyQualifiedName()) : kpi.getKpiResult()); - } - return kpi; + return kpi.withKpiResult( + fields.contains(KPI_RESULT_FIELD) ? getKpiResult(kpi.getFullyQualifiedName()) : kpi.getKpiResult()); } @Override @@ -155,9 +152,7 @@ public class KpiRepository extends EntityRepository { } private EntityReference getDataInsightChart(Kpi kpi) { - return kpi.getDataInsightChart() != null - ? kpi.getDataInsightChart() - : getToEntityRef(kpi.getId(), Relationship.USES, DATA_INSIGHT_CHART, true); + return getToEntityRef(kpi.getId(), Relationship.USES, DATA_INSIGHT_CHART, true); } public KpiResult getKpiResult(String fqn) { diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/MetricsRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/MetricsRepository.java index 5b4946c86f1..2d95a1ae050 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/MetricsRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/MetricsRepository.java @@ -38,9 +38,7 @@ public class MetricsRepository extends EntityRepository { @Override public Metrics setFields(Metrics metrics, Fields fields) { - if (metrics.getService() == null) { - metrics.setService(getContainer(metrics.getId())); // service is a default field - } + metrics.setService(getContainer(metrics.getId())); // service is a default field if (metrics.getUsageSummary() == null) { metrics.withUsageSummary( fields.contains("usageSummary") diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/MlModelRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/MlModelRepository.java index ea9eef1abae..4d75ff17621 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/MlModelRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/MlModelRepository.java @@ -76,9 +76,7 @@ public class MlModelRepository extends EntityRepository { @Override public MlModel setFields(MlModel mlModel, Fields fields) { - if (mlModel.getService() == null) { - mlModel.setService(getContainer(mlModel.getId())); - } + mlModel.setService(getContainer(mlModel.getId())); mlModel.setDashboard(fields.contains("dashboard") ? getDashboard(mlModel) : mlModel.getDashboard()); if (mlModel.getUsageSummary() == null) { mlModel.withUsageSummary( @@ -279,12 +277,7 @@ public class MlModelRepository extends EntityRepository { } private EntityReference getDashboard(MlModel mlModel) { - if (mlModel == null) { - return null; - } - return mlModel.getDashboard() != null - ? mlModel.getDashboard() - : getToEntityRef(mlModel.getId(), Relationship.USES, DASHBOARD, false); + return mlModel == null ? null : getToEntityRef(mlModel.getId(), Relationship.USES, DASHBOARD, false); } public void setDashboard(MlModel mlModel, EntityReference dashboard) { diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/PipelineRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/PipelineRepository.java index 097b254c3c8..b3490504eac 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/PipelineRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/PipelineRepository.java @@ -100,9 +100,7 @@ public class PipelineRepository extends EntityRepository { @Override public Pipeline setFields(Pipeline pipeline, Fields fields) { - if (pipeline.getService() == null) { - pipeline.setService(getContainer(pipeline.getId())); - } + pipeline.setService(getContainer(pipeline.getId())); getTaskTags(fields.contains(FIELD_TAGS), pipeline.getTasks()); return pipeline.withPipelineStatus( fields.contains("pipelineStatus") ? getPipelineStatus(pipeline) : pipeline.getPipelineStatus()); @@ -115,9 +113,6 @@ public class PipelineRepository extends EntityRepository { } private PipelineStatus getPipelineStatus(Pipeline pipeline) { - if (pipeline.getPipelineStatus() != null) { - return pipeline.getPipelineStatus(); - } return JsonUtils.readValue( getLatestExtensionFromTimeseries(pipeline.getFullyQualifiedName(), PIPELINE_STATUS_EXTENSION), PipelineStatus.class); diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/PolicyRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/PolicyRepository.java index 949ae387c3d..fecc713fa1e 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/PolicyRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/PolicyRepository.java @@ -15,7 +15,6 @@ package org.openmetadata.service.jdbi3; import static java.lang.Boolean.FALSE; import static org.openmetadata.common.utils.CommonUtil.listOrEmpty; -import static org.openmetadata.common.utils.CommonUtil.nullOrEmpty; import static org.openmetadata.schema.type.MetadataOperation.EDIT_ALL; import static org.openmetadata.schema.type.MetadataOperation.VIEW_ALL; import static org.openmetadata.service.Entity.ALL_RESOURCES; @@ -64,16 +63,12 @@ public class PolicyRepository extends EntityRepository { /* Get all the teams that use this policy */ private List getTeams(Policy policy) { - return !nullOrEmpty(policy.getTeams()) - ? policy.getTeams() - : findFrom(policy.getId(), POLICY, Relationship.HAS, Entity.TEAM); + return findFrom(policy.getId(), POLICY, Relationship.HAS, Entity.TEAM); } /* Get all the roles that use this policy */ private List getRoles(Policy policy) { - return !nullOrEmpty(policy.getRoles()) - ? policy.getRoles() - : findFrom(policy.getId(), POLICY, Relationship.HAS, Entity.ROLE); + return findFrom(policy.getId(), POLICY, Relationship.HAS, Entity.ROLE); } @Override diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/QueryRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/QueryRepository.java index e1ec2f3c741..eb69da70095 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/QueryRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/QueryRepository.java @@ -42,8 +42,7 @@ public class QueryRepository extends EntityRepository { public Query setFields(Query entity, EntityUtil.Fields fields) { entity.setVotes(fields.contains("votes") ? getVotes(entity) : entity.getVotes()); entity.setQueryUsedIn(fields.contains(QUERY_USED_IN_FIELD) ? getQueryUsage(entity) : entity.getQueryUsedIn()); - entity.setUsers(fields.contains("users") ? getQueryUsers(entity) : entity.getUsers()); - return entity; + return entity.withUsers(fields.contains("users") ? getQueryUsers(entity) : entity.getUsers()); } @Override @@ -54,23 +53,15 @@ public class QueryRepository extends EntityRepository { } public List getQueryUsage(Query queryEntity) { - if (queryEntity == null) { - return Collections.emptyList(); - } - if (!nullOrEmpty(queryEntity.getQueryUsedIn())) { - return queryEntity.getQueryUsedIn(); - } - return findFrom(queryEntity.getId(), Entity.QUERY, Relationship.MENTIONED_IN, null); + return queryEntity == null + ? Collections.emptyList() + : findFrom(queryEntity.getId(), Entity.QUERY, Relationship.MENTIONED_IN, null); } public List getQueryUsers(Query queryEntity) { - if (queryEntity == null) { - return Collections.emptyList(); - } - if (!nullOrEmpty(queryEntity.getUsers())) { - return queryEntity.getUsers(); - } - return findFrom(queryEntity.getId(), Entity.QUERY, Relationship.USES, USER); + return queryEntity == null + ? Collections.emptyList() + : findFrom(queryEntity.getId(), Entity.QUERY, Relationship.USES, USER); } @Override diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ReportRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ReportRepository.java index ed28e31f0b6..1f8f61c3b44 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ReportRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ReportRepository.java @@ -30,9 +30,7 @@ public class ReportRepository extends EntityRepository { @Override public Report setFields(Report report, Fields fields) { - if (report.getService() == null) { - report.setService(getService(report)); // service is a default field - } + report.setService(getService(report)); // service is a default field if (report.getUsageSummary() == null) { report.withUsageSummary( fields.contains("usageSummary") diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/RoleRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/RoleRepository.java index 9e9af96b8ed..ec2ede5728c 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/RoleRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/RoleRepository.java @@ -15,7 +15,6 @@ package org.openmetadata.service.jdbi3; import static java.lang.Boolean.FALSE; import static org.openmetadata.common.utils.CommonUtil.listOrEmpty; -import static org.openmetadata.common.utils.CommonUtil.nullOrEmpty; import static org.openmetadata.service.Entity.POLICIES; import static org.openmetadata.service.util.EntityUtil.entityReferenceMatch; @@ -54,21 +53,15 @@ public class RoleRepository extends EntityRepository { } private List getPolicies(@NonNull Role role) { - return !nullOrEmpty(role.getPolicies()) - ? role.getPolicies() - : findTo(role.getId(), Entity.ROLE, Relationship.HAS, Entity.POLICY); + return findTo(role.getId(), Entity.ROLE, Relationship.HAS, Entity.POLICY); } private List getUsers(@NonNull Role role) { - return !nullOrEmpty(role.getUsers()) - ? role.getUsers() - : findFrom(role.getId(), Entity.ROLE, Relationship.HAS, Entity.USER); + return findFrom(role.getId(), Entity.ROLE, Relationship.HAS, Entity.USER); } private List getTeams(@NonNull Role role) { - return !nullOrEmpty(role.getTeams()) - ? role.getTeams() - : findFrom(role.getId(), Entity.ROLE, Relationship.HAS, Entity.TEAM); + return findFrom(role.getId(), Entity.ROLE, Relationship.HAS, Entity.TEAM); } @Override diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ServiceEntityRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ServiceEntityRepository.java index 151347a8ba6..6131a28ad77 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ServiceEntityRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ServiceEntityRepository.java @@ -58,7 +58,6 @@ public abstract class ServiceEntityRepository< @Override public T setFields(T entity, EntityUtil.Fields fields) { - // TODO add getPipelines to ServiceEntityInterface entity.setPipelines(fields.contains("pipelines") ? getIngestionPipelines(entity) : null); return entity; } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TableRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TableRepository.java index 0350a2ba6d2..2baa0b4d7f2 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TableRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TableRepository.java @@ -118,7 +118,6 @@ public class TableRepository extends EntityRepository { @Override public Table setFields(Table table, Fields fields) { setDefaultFields(table); - // TODO fix this if (table.getUsageSummary() == null) { table.setUsageSummary( fields.contains("usageSummary") @@ -172,9 +171,7 @@ public class TableRepository extends EntityRepository
{ } private void setDefaultFields(Table table) { - EntityReference schemaRef = - table.getDatabaseSchema() != null ? table.getDatabaseSchema() : getContainer(table.getId()); - // TODO optimize + EntityReference schemaRef = getContainer(table.getId()); DatabaseSchema schema = Entity.getEntity(schemaRef, "", ALL); table.withDatabaseSchema(schemaRef).withDatabase(schema.getDatabase()).withService(schema.getService()); } @@ -295,9 +292,6 @@ public class TableRepository extends EntityRepository
{ @Transaction public TestSuite getTestSuite(Table table) { - if (table.getTestSuite() != null) { - return table.getTestSuite(); - } List entityRelationshipRecords = daoCollection.relationshipDAO().findTo(table.getId().toString(), TABLE, Relationship.CONTAINS.ordinal()); Optional testSuiteRelationshipRecord = @@ -778,10 +772,8 @@ public class TableRepository extends EntityRepository
{ // TODO duplicated code private void getColumnTags(boolean setTags, List columns) { for (Column c : listOrEmpty(columns)) { - if (c.getTags() == null) { - c.setTags(setTags ? getTags(c.getFullyQualifiedName()) : c.getTags()); - getColumnTags(setTags, c.getChildren()); - } + c.setTags(setTags ? getTags(c.getFullyQualifiedName()) : c.getTags()); + getColumnTags(setTags, c.getChildren()); } } @@ -904,9 +896,6 @@ public class TableRepository extends EntityRepository
{ } private TableJoins getJoins(Table table) { - if (table.getJoins() != null) { - return table.getJoins(); - } String today = RestUtil.DATE_FORMAT.format(new Date()); String todayMinus30Days = CommonUtil.getDateStringByOffset(RestUtil.DATE_FORMAT, today, -30); return new TableJoins() @@ -994,9 +983,7 @@ public class TableRepository extends EntityRepository
{ // Add custom metrics info to columns if requested List columns = table.getColumns(); for (Column c : listOrEmpty(columns)) { - if (nullOrEmpty(c.getCustomMetrics())) { - c.setCustomMetrics(setMetrics ? getCustomMetrics(table, c.getName()) : c.getCustomMetrics()); - } + c.setCustomMetrics(setMetrics ? getCustomMetrics(table, c.getName()) : c.getCustomMetrics()); } } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TagRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TagRepository.java index a24f1f2f369..14074e267df 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TagRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TagRepository.java @@ -115,7 +115,6 @@ public class TagRepository extends EntityRepository { @Override public Tag setFields(Tag tag, Fields fields) { tag.withClassification(getClassification(tag)).withParent(getParent(tag)); - tag.setChildren(fields.contains("children") ? getChildren(tag) : tag.getChildren()); if (fields.contains("usageCount")) { tag.withUsageCount(getUsageCount(tag)); } @@ -124,7 +123,6 @@ public class TagRepository extends EntityRepository { @Override public Tag clearFields(Tag tag, Fields fields) { - tag.setChildren(fields.contains("children") ? tag.getChildren() : null); return tag.withUsageCount(fields.contains("usageCount") ? tag.getUsageCount() : null); } @@ -134,21 +132,8 @@ public class TagRepository extends EntityRepository { : daoCollection.tagUsageDAO().getTagCount(TagSource.CLASSIFICATION.ordinal(), tag.getFullyQualifiedName()); } - private List getChildren(Tag entity) { - // Don't use cache to handle tag name changes - return !nullOrEmpty(entity.getChildren()) - ? entity.getChildren() - : findTo(entity.getId(), TAG, Relationship.CONTAINS, TAG); - } - - private EntityReference getParent(Tag tag) { - return tag.getParent() != null ? tag.getParent() : getFromEntityRef(tag.getId(), Relationship.CONTAINS, TAG, false); - } - private EntityReference getClassification(Tag tag) { - return tag.getClassification() != null - ? tag.getClassification() - : getFromEntityRef(tag.getId(), Relationship.CONTAINS, Entity.CLASSIFICATION, true); + return getFromEntityRef(tag.getId(), Relationship.CONTAINS, Entity.CLASSIFICATION, true); } private void addClassificationRelationship(Tag term) { diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TeamRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TeamRepository.java index 14eb7c7bfc1..a38a11cae7f 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TeamRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TeamRepository.java @@ -95,14 +95,9 @@ public class TeamRepository extends EntityRepository { team.setDefaultRoles(fields.contains(DEFAULT_ROLES) ? getDefaultRoles(team) : team.getDefaultRoles()); team.setInheritedRoles(fields.contains(DEFAULT_ROLES) ? getInheritedRoles(team) : team.getInheritedRoles()); team.setParents(fields.contains(PARENTS_FIELD) ? getParents(team) : team.getParents()); - if (team.getChildren() == null) { - team.setChildren(fields.contains("children") ? getChildren(team.getId()) : team.getChildren()); - } team.setPolicies(fields.contains("policies") ? getPolicies(team) : team.getPolicies()); team.setChildrenCount(fields.contains("childrenCount") ? getChildrenCount(team) : team.getChildrenCount()); - if (team.getUserCount() == null) { - team.setUserCount(fields.contains("userCount") ? getUserCount(team.getId()) : team.getUserCount()); - } + team.setUserCount(fields.contains("userCount") ? getUserCount(team.getId()) : team.getUserCount()); return team; } @@ -114,7 +109,6 @@ public class TeamRepository extends EntityRepository { team.setDefaultRoles(fields.contains(DEFAULT_ROLES) ? team.getDefaultRoles() : null); team.setInheritedRoles(fields.contains(DEFAULT_ROLES) ? team.getInheritedRoles() : null); team.setParents(fields.contains(PARENTS_FIELD) ? team.getParents() : null); - team.setChildren(fields.contains("children") ? team.getChildren() : null); team.setPolicies(fields.contains("policies") ? team.getPolicies() : null); team.setChildrenCount(fields.contains("childrenCount") ? team.getChildrenCount() : null); return team.withUserCount(fields.contains("userCount") ? team.getUserCount() : null); @@ -345,7 +339,7 @@ public class TeamRepository extends EntityRepository { } private List getUsers(Team team) { - return !nullOrEmpty(team.getUsers()) ? team.getUsers() : findTo(team.getId(), TEAM, Relationship.HAS, Entity.USER); + return findTo(team.getId(), TEAM, Relationship.HAS, Entity.USER); } private List getUsersRelationshipRecords(UUID teamId) { @@ -371,19 +365,14 @@ public class TeamRepository extends EntityRepository { private List getOwns(Team team) { // Compile entities owned by the team - return !nullOrEmpty(team.getOwns()) ? team.getOwns() : findTo(team.getId(), TEAM, Relationship.OWNS, null); + return findTo(team.getId(), TEAM, Relationship.OWNS, null); } private List getDefaultRoles(Team team) { - return !nullOrEmpty(team.getDefaultRoles()) - ? team.getDefaultRoles() - : findTo(team.getId(), TEAM, Relationship.HAS, Entity.ROLE); + return findTo(team.getId(), TEAM, Relationship.HAS, Entity.ROLE); } private List getParents(Team team) { - if (!nullOrEmpty(team.getParents())) { - return team.getParents(); - } List parents = findFrom(team.getId(), TEAM, Relationship.PARENT_OF, TEAM); if (organization != null && listOrEmpty(parents).isEmpty() && !team.getId().equals(organization.getId())) { return new ArrayList<>(List.of(organization.getEntityReference())); @@ -403,7 +392,12 @@ public class TeamRepository extends EntityRepository { return parents; } - private List getChildren(UUID teamId) { + @Override + protected List getChildren(Team team) { + return getChildren(team.getId()); + } + + protected List getChildren(UUID teamId) { if (teamId.equals(organization.getId())) { // For organization all the parentless teams are children List children = daoCollection.teamDAO().listTeamsUnderOrganization(teamId.toString()); return EntityUtil.populateEntityReferencesById(EntityUtil.strToIds(children), Entity.TEAM); @@ -412,11 +406,11 @@ public class TeamRepository extends EntityRepository { } private Integer getChildrenCount(Team team) { - return team.getChildrenCount() != null ? team.getChildrenCount() : getChildren(team.getId()).size(); + return !nullOrEmpty(team.getChildren()) ? team.getChildren().size() : getChildren(team).size(); } private List getPolicies(Team team) { - return !nullOrEmpty(team.getPolicies()) ? team.getPolicies() : findTo(team.getId(), TEAM, Relationship.HAS, POLICY); + return findTo(team.getId(), TEAM, Relationship.HAS, POLICY); } private void populateChildren(Team team) { diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TestCaseRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TestCaseRepository.java index d7b3f113a1f..83e3dc8658c 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TestCaseRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TestCaseRepository.java @@ -1,6 +1,5 @@ package org.openmetadata.service.jdbi3; -import static org.openmetadata.common.utils.CommonUtil.nullOrEmpty; import static org.openmetadata.service.Entity.TEST_CASE; import static org.openmetadata.service.Entity.TEST_DEFINITION; import static org.openmetadata.service.Entity.TEST_SUITE; @@ -122,9 +121,6 @@ public class TestCaseRepository extends EntityRepository { } private EntityReference getTestSuite(TestCase test) { - if (test.getTestSuite() != null) { - return test.getTestSuite(); - } // `testSuite` field returns the executable `testSuite` linked to that testCase List records = findFromRecords(test.getId(), entityType, Relationship.CONTAINS, TEST_SUITE); @@ -139,9 +135,6 @@ public class TestCaseRepository extends EntityRepository { } private List getTestSuites(TestCase test) { - if (!nullOrEmpty(test.getTestSuites())) { - return test.getTestSuites(); - } // `testSuites` field returns all the `testSuite` (executable and logical) linked to that testCase List records = findFromRecords(test.getId(), entityType, Relationship.CONTAINS, TEST_SUITE); @@ -152,9 +145,7 @@ public class TestCaseRepository extends EntityRepository { } private EntityReference getTestDefinition(TestCase test) { - return test.getTestDefinition() != null - ? test.getTestDefinition() - : getFromEntityRef(test.getId(), Relationship.APPLIED_TO, TEST_DEFINITION, true); + return getFromEntityRef(test.getId(), Relationship.APPLIED_TO, TEST_DEFINITION, true); } private void validateTestParameters( @@ -279,9 +270,6 @@ public class TestCaseRepository extends EntityRepository { } private TestCaseResult getTestCaseResult(TestCase testCase) { - if (testCase.getTestCaseResult() != null) { - return testCase.getTestCaseResult(); - } return JsonUtils.readValue( getLatestExtensionFromTimeseries(testCase.getFullyQualifiedName(), TESTCASE_RESULT_EXTENSION), TestCaseResult.class); diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TestSuiteRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TestSuiteRepository.java index 71a84d283a3..06570a057c9 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TestSuiteRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TestSuiteRepository.java @@ -1,7 +1,6 @@ package org.openmetadata.service.jdbi3; import static org.openmetadata.common.utils.CommonUtil.listOrEmpty; -import static org.openmetadata.common.utils.CommonUtil.nullOrEmpty; import static org.openmetadata.service.Entity.TEST_CASE; import static org.openmetadata.service.Entity.TEST_SUITE; import static org.openmetadata.service.jdbi3.TestCaseRepository.TESTCASE_RESULT_EXTENSION; @@ -53,9 +52,6 @@ public class TestSuiteRepository extends EntityRepository { } private TestSummary getTestSummary(TestSuite entity) { - if (entity.getSummary() != null) { - return entity.getSummary(); - } List testCases = getTestCases(entity); List testCaseFQNs = testCases.stream().map(EntityReference::getFullyQualifiedName).collect(Collectors.toList()); @@ -70,9 +66,7 @@ public class TestSuiteRepository extends EntityRepository { } private List getTestCases(TestSuite entity) { - return !nullOrEmpty(entity.getTests()) - ? entity.getTests() - : findTo(entity.getId(), TEST_SUITE, Relationship.CONTAINS, TEST_CASE); + return findTo(entity.getId(), TEST_SUITE, Relationship.CONTAINS, TEST_CASE); } @Override diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TopicRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TopicRepository.java index 5ea75728774..df2365a0e04 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TopicRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TopicRepository.java @@ -120,9 +120,7 @@ public class TopicRepository extends EntityRepository { @Override public Topic setFields(Topic topic, Fields fields) { - if (topic.getService() == null) { - topic.setService(getContainer(topic.getId())); - } + topic.setService(getContainer(topic.getId())); if (topic.getMessageSchema() != null) { getFieldTags(fields.contains(FIELD_TAGS), topic.getMessageSchema().getSchemaFields()); } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TypeRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TypeRepository.java index dec138b1cfe..1db3b7cd236 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TypeRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TypeRepository.java @@ -17,7 +17,6 @@ package org.openmetadata.service.jdbi3; import static org.openmetadata.common.utils.CommonUtil.listOrEmpty; -import static org.openmetadata.common.utils.CommonUtil.nullOrEmpty; import static org.openmetadata.schema.type.Include.NON_DELETED; import static org.openmetadata.service.Entity.FIELD_DESCRIPTION; import static org.openmetadata.service.util.EntityUtil.customFieldMatch; @@ -127,9 +126,6 @@ public class TypeRepository extends EntityRepository { } private List getCustomProperties(Type type) { - if (!nullOrEmpty(type.getCustomProperties())) { - return type.getCustomProperties(); - } if (type.getCategory().equals(Category.Field)) { return null; // Property type fields don't support custom properties } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/UserRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/UserRepository.java index 26eb81858d8..43a2799e8f9 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/UserRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/UserRepository.java @@ -121,10 +121,6 @@ public class UserRepository extends EntityRepository { if (Boolean.TRUE.equals(user.getIsBot())) { return null; // No inherited roles for bots } - if (!nullOrEmpty(user.getInheritedRoles())) { - return user.getInheritedRoles(); - } - getTeams(user); return SubjectContext.getRolesForTeams(getTeams(user)); } @@ -255,9 +251,6 @@ public class UserRepository extends EntityRepository { } private List getOwns(User user) { - if (user.getOwns() != null) { - return user.getOwns(); - } // Compile entities owned by the user List ownedEntities = daoCollection.relationshipDAO().findTo(user.getId().toString(), USER, Relationship.OWNS.ordinal()); @@ -273,7 +266,7 @@ public class UserRepository extends EntityRepository { } private List getFollows(User user) { - return user.getFollows() != null ? user.getFollows() : findTo(user.getId(), USER, Relationship.FOLLOWS, null); + return findTo(user.getId(), USER, Relationship.FOLLOWS, null); } private List getTeamChildren(UUID teamId) { @@ -307,14 +300,11 @@ public class UserRepository extends EntityRepository { /* Get all the roles that user has been assigned and inherited from the team to User entity */ private List getRoles(User user) { - return user.getRoles() != null ? user.getRoles() : findTo(user.getId(), USER, Relationship.HAS, Entity.ROLE); + return findTo(user.getId(), USER, Relationship.HAS, Entity.ROLE); } /* Get all the teams that user belongs to User entity */ public List getTeams(User user) { - if (!nullOrEmpty(user.getTeams())) { - return user.getTeams(); - } List teams = findFrom(user.getId(), USER, Relationship.HAS, Entity.TEAM); // Filter deleted teams teams = listOrEmpty(teams).stream().filter(team -> !team.getDeleted()).collect(Collectors.toList()); diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/resources/tags/TagResource.java b/openmetadata-service/src/main/java/org/openmetadata/service/resources/tags/TagResource.java index 6e8cd3b776a..6f5f4a02870 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/resources/tags/TagResource.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/resources/tags/TagResource.java @@ -93,7 +93,7 @@ import org.openmetadata.service.util.ResultList; public class TagResource extends EntityResource { private final CollectionDAO daoCollection; public static final String TAG_COLLECTION_PATH = "/v1/tags/"; - static final String FIELDS = "children, usageCount"; + static final String FIELDS = "parent,children,usageCount"; static class TagList extends ResultList { /* Required for serde */ diff --git a/openmetadata-spec/src/main/java/org/openmetadata/schema/EntityInterface.java b/openmetadata-spec/src/main/java/org/openmetadata/schema/EntityInterface.java index 59ba1cc5510..158cc84b334 100644 --- a/openmetadata-spec/src/main/java/org/openmetadata/schema/EntityInterface.java +++ b/openmetadata-spec/src/main/java/org/openmetadata/schema/EntityInterface.java @@ -82,6 +82,18 @@ public interface EntityInterface { return null; } + default List getChildren() { + return null; + } + + default List getReviewers() { + return null; + } + + default List getExperts() { + return null; + } + default EntityReference getDomain() { return null; } @@ -124,6 +136,18 @@ public interface EntityInterface { /* no-op implementation to be overridden */ } + default void setChildren(List entityReference) { + /* no-op implementation to be overridden */ + } + + default void setReviewers(List entityReference) { + /* no-op implementation to be overridden */ + } + + default void setExperts(List entityReference) { + /* no-op implementation to be overridden */ + } + default void setDomain(EntityReference entityReference) { /* no-op implementation to be overridden */ } diff --git a/openmetadata-spec/src/main/resources/json/schema/entity/data/pipeline.json b/openmetadata-spec/src/main/resources/json/schema/entity/data/pipeline.json index c7d8720c9e1..2b658a2092e 100644 --- a/openmetadata-spec/src/main/resources/json/schema/entity/data/pipeline.json +++ b/openmetadata-spec/src/main/resources/json/schema/entity/data/pipeline.json @@ -9,7 +9,7 @@ "javaInterfaces": ["org.openmetadata.schema.EntityInterface"], "definitions": { "entityName": { - "description": "Name of a table. Expected to be unique within a database.", + "description": "Name of a pipeline. Expected to be unique within a pipeline service.", "type": "string", "minLength": 1, "maxLength": 128,