[GlossaryTerm] Fix Glossary Term Issue (#16068)

* - Don't update gloosary Term in case of equal tags

* - Invert Conditions

* - Mutually Exclusive cannot be updated

* - Fix Failing Tests
This commit is contained in:
Mohit Yadav 2024-04-29 18:16:49 +05:30 committed by GitHub
parent 92e5b080cf
commit fa73171dff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 48 additions and 30 deletions

View File

@ -121,9 +121,8 @@ public class ClassificationRepository extends EntityRepository<Classification> {
@Transaction @Transaction
@Override @Override
public void entitySpecificUpdate() { public void entitySpecificUpdate() {
// TODO mutuallyExclusive from false to true? // Mutually exclusive cannot be updated
recordChange( updated.setMutuallyExclusive(original.getMutuallyExclusive());
"mutuallyExclusive", original.getMutuallyExclusive(), updated.getMutuallyExclusive());
recordChange("disabled", original.getDisabled(), updated.getDisabled()); recordChange("disabled", original.getDisabled(), updated.getDisabled());
updateName(original, updated); updateName(original, updated);
} }

View File

@ -286,6 +286,8 @@ public class GlossaryRepository extends EntityRepository<Glossary> {
@Override @Override
public void entitySpecificUpdate() { public void entitySpecificUpdate() {
updateName(original, updated); updateName(original, updated);
// Mutually exclusive cannot be updated
updated.setMutuallyExclusive(original.getMutuallyExclusive());
} }
public void updateName(Glossary original, Glossary updated) { public void updateName(Glossary original, Glossary updated) {

View File

@ -684,6 +684,23 @@ public class GlossaryTermRepository extends EntityRepository<GlossaryTerm> {
updateRelatedTerms(original, updated); updateRelatedTerms(original, updated);
updateName(original, updated); updateName(original, updated);
updateParent(original, updated); updateParent(original, updated);
// Mutually exclusive cannot be updated
updated.setMutuallyExclusive(original.getMutuallyExclusive());
}
private boolean validateIfTagsAreEqual(
List<TagLabel> originalTags, List<TagLabel> updatedTags) {
Set<String> originalTagsFqn =
listOrEmpty(originalTags).stream()
.map(TagLabel::getTagFQN)
.collect(Collectors.toCollection(TreeSet::new));
Set<String> updatedTagsFqn =
listOrEmpty(updatedTags).stream()
.map(TagLabel::getTagFQN)
.collect(Collectors.toCollection(TreeSet::new));
// Validate if both are exactly equal
return originalTagsFqn.equals(updatedTagsFqn);
} }
@Override @Override
@ -695,10 +712,8 @@ public class GlossaryTermRepository extends EntityRepository<GlossaryTerm> {
// updatedTags cannot be immutable list, as we are adding the origTags to updatedTags even if // updatedTags cannot be immutable list, as we are adding the origTags to updatedTags even if
// its empty. // its empty.
updatedTags = Optional.ofNullable(updatedTags).orElse(new ArrayList<>()); updatedTags = Optional.ofNullable(updatedTags).orElse(new ArrayList<>());
if (origTags.isEmpty() && updatedTags.isEmpty()) { if (!(origTags.isEmpty() && updatedTags.isEmpty())
return; // Nothing to update && !validateIfTagsAreEqual(origTags, updatedTags)) {
}
List<String> targetFQNHashes = daoCollection.tagUsageDAO().getTargetFQNHashForTag(fqn); List<String> targetFQNHashes = daoCollection.tagUsageDAO().getTargetFQNHashForTag(fqn);
for (String fqnHash : targetFQNHashes) { for (String fqnHash : targetFQNHashes) {
Map<String, List<TagLabel>> allAssetTags = Map<String, List<TagLabel>> allAssetTags =
@ -708,7 +723,8 @@ public class GlossaryTermRepository extends EntityRepository<GlossaryTerm> {
checkMutuallyExclusiveForParentAndSubField("", fqnHash, allAssetTags, updatedTags, true); checkMutuallyExclusiveForParentAndSubField("", fqnHash, allAssetTags, updatedTags, true);
} }
// Remove current entity tags in the database. It will be added back later from the merged tag // Remove current entity tags in the database. It will be added back later from the merged
// tag
// list. // list.
daoCollection.tagUsageDAO().deleteTagsByTarget(fqn); daoCollection.tagUsageDAO().deleteTagsByTarget(fqn);
@ -724,6 +740,7 @@ public class GlossaryTermRepository extends EntityRepository<GlossaryTerm> {
updatedTags.sort(compareTagLabel); updatedTags.sort(compareTagLabel);
applyTags(updatedTags, fqn); applyTags(updatedTags, fqn);
} }
}
private void updateStatus(GlossaryTerm origTerm, GlossaryTerm updatedTerm) { private void updateStatus(GlossaryTerm origTerm, GlossaryTerm updatedTerm) {
if (origTerm.getStatus() == updatedTerm.getStatus()) { if (origTerm.getStatus() == updatedTerm.getStatus()) {