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 d46edc801dc..43a3f10e93a 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 @@ -121,9 +121,8 @@ public class ClassificationRepository extends EntityRepository { @Transaction @Override public void entitySpecificUpdate() { - // TODO mutuallyExclusive from false to true? - recordChange( - "mutuallyExclusive", original.getMutuallyExclusive(), updated.getMutuallyExclusive()); + // Mutually exclusive cannot be updated + updated.setMutuallyExclusive(original.getMutuallyExclusive()); recordChange("disabled", original.getDisabled(), updated.getDisabled()); updateName(original, updated); } 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 cb33c1a7e7c..bf6f7425bdc 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 @@ -286,6 +286,8 @@ public class GlossaryRepository extends EntityRepository { @Override public void entitySpecificUpdate() { updateName(original, updated); + // Mutually exclusive cannot be updated + updated.setMutuallyExclusive(original.getMutuallyExclusive()); } public void updateName(Glossary original, Glossary updated) { 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 3846818b9cd..3771aab5a5b 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 @@ -684,6 +684,23 @@ public class GlossaryTermRepository extends EntityRepository { updateRelatedTerms(original, updated); updateName(original, updated); updateParent(original, updated); + // Mutually exclusive cannot be updated + updated.setMutuallyExclusive(original.getMutuallyExclusive()); + } + + private boolean validateIfTagsAreEqual( + List originalTags, List updatedTags) { + Set originalTagsFqn = + listOrEmpty(originalTags).stream() + .map(TagLabel::getTagFQN) + .collect(Collectors.toCollection(TreeSet::new)); + Set updatedTagsFqn = + listOrEmpty(updatedTags).stream() + .map(TagLabel::getTagFQN) + .collect(Collectors.toCollection(TreeSet::new)); + + // Validate if both are exactly equal + return originalTagsFqn.equals(updatedTagsFqn); } @Override @@ -695,34 +712,34 @@ public class GlossaryTermRepository extends EntityRepository { // updatedTags cannot be immutable list, as we are adding the origTags to updatedTags even if // its empty. updatedTags = Optional.ofNullable(updatedTags).orElse(new ArrayList<>()); - if (origTags.isEmpty() && updatedTags.isEmpty()) { - return; // Nothing to update + if (!(origTags.isEmpty() && updatedTags.isEmpty()) + && !validateIfTagsAreEqual(origTags, updatedTags)) { + List targetFQNHashes = daoCollection.tagUsageDAO().getTargetFQNHashForTag(fqn); + for (String fqnHash : targetFQNHashes) { + Map> allAssetTags = + daoCollection.tagUsageDAO().getTagsByPrefix(fqnHash, "%", false); + + // Assets FQN is not available / we can use fqnHash for now + checkMutuallyExclusiveForParentAndSubField("", fqnHash, allAssetTags, updatedTags, true); + } + + // Remove current entity tags in the database. It will be added back later from the merged + // tag + // list. + daoCollection.tagUsageDAO().deleteTagsByTarget(fqn); + + if (operation.isPut()) { + // PUT operation merges tags in the request with what already exists + EntityUtil.mergeTags(updatedTags, origTags); + checkMutuallyExclusive(updatedTags); + } + + List addedTags = new ArrayList<>(); + List deletedTags = new ArrayList<>(); + recordListChange(fieldName, origTags, updatedTags, addedTags, deletedTags, tagLabelMatch); + updatedTags.sort(compareTagLabel); + applyTags(updatedTags, fqn); } - - List targetFQNHashes = daoCollection.tagUsageDAO().getTargetFQNHashForTag(fqn); - for (String fqnHash : targetFQNHashes) { - Map> allAssetTags = - daoCollection.tagUsageDAO().getTagsByPrefix(fqnHash, "%", false); - - // Assets FQN is not available / we can use fqnHash for now - checkMutuallyExclusiveForParentAndSubField("", fqnHash, allAssetTags, updatedTags, true); - } - - // Remove current entity tags in the database. It will be added back later from the merged tag - // list. - daoCollection.tagUsageDAO().deleteTagsByTarget(fqn); - - if (operation.isPut()) { - // PUT operation merges tags in the request with what already exists - EntityUtil.mergeTags(updatedTags, origTags); - checkMutuallyExclusive(updatedTags); - } - - List addedTags = new ArrayList<>(); - List deletedTags = new ArrayList<>(); - recordListChange(fieldName, origTags, updatedTags, addedTags, deletedTags, tagLabelMatch); - updatedTags.sort(compareTagLabel); - applyTags(updatedTags, fqn); } private void updateStatus(GlossaryTerm origTerm, GlossaryTerm updatedTerm) {