mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-11-07 22:44:08 +00:00
[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:
parent
92e5b080cf
commit
fa73171dff
@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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) {
|
||||||
|
|||||||
@ -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,34 +712,34 @@ 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);
|
||||||
|
for (String fqnHash : targetFQNHashes) {
|
||||||
|
Map<String, List<TagLabel>> 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<TagLabel> addedTags = new ArrayList<>();
|
||||||
|
List<TagLabel> deletedTags = new ArrayList<>();
|
||||||
|
recordListChange(fieldName, origTags, updatedTags, addedTags, deletedTags, tagLabelMatch);
|
||||||
|
updatedTags.sort(compareTagLabel);
|
||||||
|
applyTags(updatedTags, fqn);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> targetFQNHashes = daoCollection.tagUsageDAO().getTargetFQNHashForTag(fqn);
|
|
||||||
for (String fqnHash : targetFQNHashes) {
|
|
||||||
Map<String, List<TagLabel>> 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<TagLabel> addedTags = new ArrayList<>();
|
|
||||||
List<TagLabel> deletedTags = new ArrayList<>();
|
|
||||||
recordListChange(fieldName, origTags, updatedTags, addedTags, deletedTags, tagLabelMatch);
|
|
||||||
updatedTags.sort(compareTagLabel);
|
|
||||||
applyTags(updatedTags, fqn);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateStatus(GlossaryTerm origTerm, GlossaryTerm updatedTerm) {
|
private void updateStatus(GlossaryTerm origTerm, GlossaryTerm updatedTerm) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user