This is an automated email from the ASF dual-hosted git repository.

sidmishra pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/atlas.git


The following commit(s) were added to refs/heads/branch-2.0 by this push:
     new d5ae35f  ATLAS-4288: Added code to create PreferredToTerms 
relationships when it exists alone
d5ae35f is described below

commit d5ae35f1a9304ef8011be71258e6e1d7fb4dd60b
Author: sidmishra <sidmis...@cloudera.com>
AuthorDate: Mon May 17 22:40:00 2021 -0700

    ATLAS-4288: Added code to create PreferredToTerms relationships when it 
exists alone
    
    Signed-off-by: Sidharth Mishra <sidmis...@apache.org>
    (cherry picked from commit 64bea6a5e98fbb87a76d53f9e7e2f5ca01671426)
---
 .../atlas/model/glossary/AtlasGlossaryTerm.java    |  4 ++++
 .../apache/atlas/glossary/GlossaryTermUtils.java   | 26 +++++++++++++---------
 2 files changed, 19 insertions(+), 11 deletions(-)

diff --git 
a/intg/src/main/java/org/apache/atlas/model/glossary/AtlasGlossaryTerm.java 
b/intg/src/main/java/org/apache/atlas/model/glossary/AtlasGlossaryTerm.java
index ee306c6..f0f362b 100644
--- a/intg/src/main/java/org/apache/atlas/model/glossary/AtlasGlossaryTerm.java
+++ b/intg/src/main/java/org/apache/atlas/model/glossary/AtlasGlossaryTerm.java
@@ -224,6 +224,10 @@ public class AtlasGlossaryTerm extends 
AtlasGlossaryBaseObject {
 
     public void setPreferredToTerms(final Set<AtlasRelatedTermHeader> 
preferredToTerms) {
         this.preferredToTerms = preferredToTerms;
+
+        if (CollectionUtils.isNotEmpty(preferredToTerms)) {
+            hasTerms = true;
+        }
     }
 
     public Set<AtlasRelatedTermHeader> getReplacementTerms() {
diff --git 
a/repository/src/main/java/org/apache/atlas/glossary/GlossaryTermUtils.java 
b/repository/src/main/java/org/apache/atlas/glossary/GlossaryTermUtils.java
index fa02c8e..d92daee 100644
--- a/repository/src/main/java/org/apache/atlas/glossary/GlossaryTermUtils.java
+++ b/repository/src/main/java/org/apache/atlas/glossary/GlossaryTermUtils.java
@@ -725,21 +725,25 @@ public class GlossaryTermUtils extends GlossaryUtils {
                     String relatedTermQualifiedName = dataArray[1] + 
invalidNameChars[0] + dataArray[0];
                     String currTermQualifiedName    = termName + 
invalidNameChars[0] + glossaryName;
 
-                    vertex = 
AtlasGraphUtilsV2.findByTypeAndUniquePropertyName(GlossaryUtils.ATLAS_GLOSSARY_TERM_TYPENAME,
-                            GlossaryUtils.ATLAS_GLOSSARY_TERM_TYPENAME + 
invalidNameChars[1] + QUALIFIED_NAME_ATTR, relatedTermQualifiedName);
+                    if 
(relatedTermQualifiedName.equalsIgnoreCase(currTermQualifiedName)) {
+                        failedTermMsgs.add("Invalid relationship specified for 
Term. Term cannot have a relationship with self");
+                    } else {
+                        vertex = 
AtlasGraphUtilsV2.findByTypeAndUniquePropertyName(GlossaryUtils.ATLAS_GLOSSARY_TERM_TYPENAME,
+                                GlossaryUtils.ATLAS_GLOSSARY_TERM_TYPENAME + 
invalidNameChars[1] + QUALIFIED_NAME_ATTR, relatedTermQualifiedName);
 
-                    if (vertex != null) {
-                        String glossaryTermGuid = 
AtlasGraphUtilsV2.getIdFromVertex(vertex);
+                        if (vertex != null) {
+                            String glossaryTermGuid = 
AtlasGraphUtilsV2.getIdFromVertex(vertex);
 
-                        relatedTermHeader       = new AtlasRelatedTermHeader();
-                        relatedTermHeader.setTermGuid(glossaryTermGuid);
+                            relatedTermHeader = new AtlasRelatedTermHeader();
+                            relatedTermHeader.setTermGuid(glossaryTermGuid);
 
-                        cacheRelatedTermQNameGuid(currTermQualifiedName, 
relatedTermQualifiedName, glossaryTermGuid);
+                            cacheRelatedTermQNameGuid(currTermQualifiedName, 
relatedTermQualifiedName, glossaryTermGuid);
 
-                        ret.add(relatedTermHeader);
-                    } else {
-                        failedTermMsgs.add("The provided Reference " + 
dataArray[1] + "@" + dataArray[0] +
-                                " does not exist at Atlas referred at record 
with TermName  : " + termName + " and GlossaryName : " + glossaryName);
+                            ret.add(relatedTermHeader);
+                        } else {
+                            failedTermMsgs.add("The provided Reference " + 
dataArray[1] + "@" + dataArray[0] +
+                                    " does not exist at Atlas referred at 
record with TermName  : " + termName + " and GlossaryName : " + glossaryName);
+                        }
                     }
                 } else {
                     failedTermMsgs.add("Incorrect relation data specified for 
the term : " + termName + "@" + glossaryName);

Reply via email to