You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by ap...@apache.org on 2018/05/16 06:48:22 UTC

[1/3] atlas git commit: ATLAS-2686: Term can't be deleted if it's assigned to any entity

Repository: atlas
Updated Branches:
  refs/heads/branch-1.0 1daef085a -> 6f57b4100


ATLAS-2686: Term can't be deleted if it's assigned to any entity

Change-Id: I4cddcfe76eabcf7ee705b60848521158bb33a8a5
(cherry picked from commit 2ff71e308ed86c44830f9f5dd48bf5450815abc6)


Project: http://git-wip-us.apache.org/repos/asf/atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/fd00220c
Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/fd00220c
Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/fd00220c

Branch: refs/heads/branch-1.0
Commit: fd00220cdf69defbe4733eb863dfbd52bf17ff3b
Parents: 1daef08
Author: apoorvnaik <ap...@apache.org>
Authored: Tue May 15 13:19:49 2018 -0700
Committer: apoorvnaik <ap...@apache.org>
Committed: Tue May 15 23:47:38 2018 -0700

----------------------------------------------------------------------
 intg/src/main/java/org/apache/atlas/AtlasErrorCode.java       | 1 +
 .../main/java/org/apache/atlas/glossary/GlossaryService.java  | 7 +++++--
 2 files changed, 6 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/atlas/blob/fd00220c/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java
----------------------------------------------------------------------
diff --git a/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java b/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java
index 3a60978..dd86e48 100644
--- a/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java
+++ b/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java
@@ -146,6 +146,7 @@ public enum AtlasErrorCode {
     INVALID_TERM_DISSOCIATION(400, "ATLAS-400-00-080", "Given term (guid={0}) is not associated to entity(guid={1})"),
     ATTRIBUTE_TYPE_INVALID(400, "ATLAS-400-00-081", "{0}.{1}: invalid attribute type. Attribute cannot be of type classification"),
     MISSING_CATEGORY_DISPLAY_NAME(400, "ATLAS-400-00-082", "Category displayName is empty/null"),
+    TERM_HAS_ENTITY_ASSOCIATION(400, "ATLAS-400-00-086", "Term (guid={}) can't be deleted as it has been assigned to {} entities."),
 
     UNAUTHORIZED_ACCESS(403, "ATLAS-403-00-001", "{0} is not authorized to perform {1}"),
 

http://git-wip-us.apache.org/repos/asf/atlas/blob/fd00220c/repository/src/main/java/org/apache/atlas/glossary/GlossaryService.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/glossary/GlossaryService.java b/repository/src/main/java/org/apache/atlas/glossary/GlossaryService.java
index bc9fe2a..a83f6d5 100644
--- a/repository/src/main/java/org/apache/atlas/glossary/GlossaryService.java
+++ b/repository/src/main/java/org/apache/atlas/glossary/GlossaryService.java
@@ -413,11 +413,14 @@ public class GlossaryService {
 
         AtlasGlossaryTerm storeObject = dataAccess.load(getAtlasGlossaryTermSkeleton(termGuid));
 
+        // Term can't be deleted if it is assigned to any entity
+        if (CollectionUtils.isNotEmpty(storeObject.getAssignedEntities())) {
+            throw new AtlasBaseException(AtlasErrorCode.TERM_HAS_ENTITY_ASSOCIATION, storeObject.getGuid(), String.valueOf(storeObject.getAssignedEntities().size()));
+        }
+
         // Remove term from Glossary
         glossaryTermUtils.processTermRelations(storeObject, storeObject, GlossaryUtils.RelationshipOperation.DELETE);
 
-        // Remove term associations with Entities
-        glossaryTermUtils.processTermDissociation(storeObject, storeObject.getAssignedEntities());
 
         // Now delete the term
         dataAccess.delete(termGuid);


[2/3] atlas git commit: ATLAS-2685: Impose displayName restrictions for Glossary, term and category.

Posted by ap...@apache.org.
ATLAS-2685: Impose displayName restrictions for Glossary, term and category.

Change-Id: I4cddcfe76eabcf7ee705b60848521158bb33a8a5
(cherry picked from commit e48a4864ac3a3f52191a0f3c14e4151e31e75665)


Project: http://git-wip-us.apache.org/repos/asf/atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/24bee5a0
Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/24bee5a0
Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/24bee5a0

Branch: refs/heads/branch-1.0
Commit: 24bee5a0a9d592f09b7685b5a1d3ba82acefb34c
Parents: fd00220
Author: apoorvnaik <ap...@apache.org>
Authored: Tue May 15 11:25:00 2018 -0700
Committer: apoorvnaik <ap...@apache.org>
Committed: Tue May 15 23:47:48 2018 -0700

----------------------------------------------------------------------
 .../java/org/apache/atlas/AtlasErrorCode.java   |  1 +
 .../apache/atlas/glossary/GlossaryService.java  | 27 ++++++++++++++++++++
 .../atlas/glossary/GlossaryServiceTest.java     |  2 +-
 3 files changed, 29 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/atlas/blob/24bee5a0/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java
----------------------------------------------------------------------
diff --git a/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java b/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java
index dd86e48..4397dd9 100644
--- a/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java
+++ b/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java
@@ -146,6 +146,7 @@ public enum AtlasErrorCode {
     INVALID_TERM_DISSOCIATION(400, "ATLAS-400-00-080", "Given term (guid={0}) is not associated to entity(guid={1})"),
     ATTRIBUTE_TYPE_INVALID(400, "ATLAS-400-00-081", "{0}.{1}: invalid attribute type. Attribute cannot be of type classification"),
     MISSING_CATEGORY_DISPLAY_NAME(400, "ATLAS-400-00-082", "Category displayName is empty/null"),
+    INVALID_DISPLAY_NAME(400, "ATLAS-400-00-083", "displayName cannot contain following special chars ('@', '.')"),
     TERM_HAS_ENTITY_ASSOCIATION(400, "ATLAS-400-00-086", "Term (guid={}) can't be deleted as it has been assigned to {} entities."),
 
     UNAUTHORIZED_ACCESS(403, "ATLAS-403-00-001", "{0} is not authorized to perform {1}"),

http://git-wip-us.apache.org/repos/asf/atlas/blob/24bee5a0/repository/src/main/java/org/apache/atlas/glossary/GlossaryService.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/glossary/GlossaryService.java b/repository/src/main/java/org/apache/atlas/glossary/GlossaryService.java
index a83f6d5..9a8676b 100644
--- a/repository/src/main/java/org/apache/atlas/glossary/GlossaryService.java
+++ b/repository/src/main/java/org/apache/atlas/glossary/GlossaryService.java
@@ -66,6 +66,8 @@ public class GlossaryService {
     private final GlossaryCategoryUtils glossaryCategoryUtils;
     private final AtlasTypeRegistry     atlasTypeRegistry;
 
+    private final char[] invalidNameChars = {'@', '.'};
+
     @Inject
     public GlossaryService(DataAccess dataAccess, final AtlasRelationshipStore relationshipStore, final AtlasTypeRegistry typeRegistry) {
         this.dataAccess = dataAccess;
@@ -134,6 +136,8 @@ public class GlossaryService {
         if (StringUtils.isEmpty(atlasGlossary.getQualifiedName())) {
             if (StringUtils.isEmpty(atlasGlossary.getDisplayName())) {
                 throw new AtlasBaseException(AtlasErrorCode.GLOSSARY_QUALIFIED_NAME_CANT_BE_DERIVED);
+            } else if (isNameInvalid(atlasGlossary.getDisplayName())){
+                throw new AtlasBaseException(AtlasErrorCode.INVALID_DISPLAY_NAME);
             } else {
                 atlasGlossary.setQualifiedName(atlasGlossary.getDisplayName());
             }
@@ -242,6 +246,10 @@ public class GlossaryService {
             throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "DisplayName can't be null/empty");
         }
 
+        if (isNameInvalid(atlasGlossary.getDisplayName())) {
+            throw new AtlasBaseException(AtlasErrorCode.INVALID_DISPLAY_NAME);
+        }
+
         AtlasGlossary storeObject = dataAccess.load(atlasGlossary);
 
         if (!storeObject.equals(atlasGlossary)) {
@@ -321,6 +329,9 @@ public class GlossaryService {
         if (StringUtils.isEmpty(glossaryTerm.getDisplayName())) {
             throw new AtlasBaseException(AtlasErrorCode.GLOSSARY_TERM_QUALIFIED_NAME_CANT_BE_DERIVED);
         }
+        if (isNameInvalid(glossaryTerm.getDisplayName())) {
+            throw new AtlasBaseException(AtlasErrorCode.INVALID_DISPLAY_NAME);
+        }
 
         // This might fail for the case when the term's qualifiedName has been updated and the duplicate request comes in with old name
         if (termExists(glossaryTerm)) {
@@ -377,6 +388,10 @@ public class GlossaryService {
             throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "DisplayName can't be null/empty");
         }
 
+        if (isNameInvalid(atlasGlossaryTerm.getDisplayName())) {
+            throw new AtlasBaseException(AtlasErrorCode.INVALID_DISPLAY_NAME);
+        }
+
         AtlasGlossaryTerm storeObject = dataAccess.load(atlasGlossaryTerm);
         if (!storeObject.equals(atlasGlossaryTerm)) {
             try {
@@ -495,6 +510,10 @@ public class GlossaryService {
         if (Objects.isNull(glossaryCategory.getDisplayName())) {
             throw new AtlasBaseException(AtlasErrorCode.MISSING_CATEGORY_DISPLAY_NAME);
         }
+        if (isNameInvalid(glossaryCategory.getDisplayName())) {
+            throw new AtlasBaseException(AtlasErrorCode.INVALID_DISPLAY_NAME);
+        }
+
 
         // This might fail for the case when the category's qualifiedName has been updated during a hierarchy change
         // and the duplicate request comes in with old name
@@ -561,6 +580,10 @@ public class GlossaryService {
             throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "DisplayName can't be null/empty");
         }
 
+        if (isNameInvalid(glossaryCategory.getDisplayName())) {
+            throw new AtlasBaseException(AtlasErrorCode.INVALID_DISPLAY_NAME);
+        }
+
         AtlasGlossaryCategory storeObject = dataAccess.load(glossaryCategory);
 
         if (!storeObject.equals(glossaryCategory)) {
@@ -952,6 +975,10 @@ public class GlossaryService {
         termHeaders.forEach(t -> t.setDisplayText(termMap.get(t.getTermGuid()).getDisplayName()));
     }
 
+    private boolean isNameInvalid(String name) {
+        return StringUtils.containsAny(name, invalidNameChars);
+    }
+
     static class PaginationHelper<T> {
         private int     pageStart;
         private int     pageEnd;

http://git-wip-us.apache.org/repos/asf/atlas/blob/24bee5a0/repository/src/test/java/org/apache/atlas/glossary/GlossaryServiceTest.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/glossary/GlossaryServiceTest.java b/repository/src/test/java/org/apache/atlas/glossary/GlossaryServiceTest.java
index f661650..6a6b971 100644
--- a/repository/src/test/java/org/apache/atlas/glossary/GlossaryServiceTest.java
+++ b/repository/src/test/java/org/apache/atlas/glossary/GlossaryServiceTest.java
@@ -164,7 +164,7 @@ public class GlossaryServiceTest {
 
         fixedRateMortgage = new AtlasGlossaryTerm();
         fixedRateMortgage.setQualifiedName("fixed_mtg@testBankingGlossary");
-        fixedRateMortgage.setDisplayName("15/30 yr mortgage");
+        fixedRateMortgage.setDisplayName("Conventional mortgage");
         fixedRateMortgage.setShortDescription("Short description");
         fixedRateMortgage.setLongDescription("Long description");
         fixedRateMortgage.setAbbreviation("FMTG");


[3/3] atlas git commit: ATLAS-2679 #2

Posted by ap...@apache.org.
ATLAS-2679 #2

Change-Id: I00ce22fe7dc58ef193f9fe884a36316171abbcb2
(cherry picked from commit 8119492fc6b6475bdb6e09a2e04572c6e185f5f0)


Project: http://git-wip-us.apache.org/repos/asf/atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/6f57b410
Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/6f57b410
Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/6f57b410

Branch: refs/heads/branch-1.0
Commit: 6f57b41002923826d052a88cc45aeff316dfc056
Parents: 24bee5a
Author: apoorvnaik <ap...@apache.org>
Authored: Tue May 15 23:39:54 2018 -0700
Committer: apoorvnaik <ap...@apache.org>
Committed: Tue May 15 23:47:51 2018 -0700

----------------------------------------------------------------------
 .../apache/atlas/glossary/GlossaryService.java  | 33 +++++++++++++-------
 .../atlas/glossary/GlossaryServiceTest.java     |  4 ---
 2 files changed, 21 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/atlas/blob/6f57b410/repository/src/main/java/org/apache/atlas/glossary/GlossaryService.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/glossary/GlossaryService.java b/repository/src/main/java/org/apache/atlas/glossary/GlossaryService.java
index 9a8676b..bae2ea1 100644
--- a/repository/src/main/java/org/apache/atlas/glossary/GlossaryService.java
+++ b/repository/src/main/java/org/apache/atlas/glossary/GlossaryService.java
@@ -136,7 +136,8 @@ public class GlossaryService {
         if (StringUtils.isEmpty(atlasGlossary.getQualifiedName())) {
             if (StringUtils.isEmpty(atlasGlossary.getDisplayName())) {
                 throw new AtlasBaseException(AtlasErrorCode.GLOSSARY_QUALIFIED_NAME_CANT_BE_DERIVED);
-            } else if (isNameInvalid(atlasGlossary.getDisplayName())){
+            }
+            if (isNameInvalid(atlasGlossary.getDisplayName())){
                 throw new AtlasBaseException(AtlasErrorCode.INVALID_DISPLAY_NAME);
             } else {
                 atlasGlossary.setQualifiedName(atlasGlossary.getDisplayName());
@@ -326,11 +327,16 @@ public class GlossaryService {
         if (Objects.isNull(glossaryTerm.getAnchor())) {
             throw new AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ANCHOR);
         }
-        if (StringUtils.isEmpty(glossaryTerm.getDisplayName())) {
-            throw new AtlasBaseException(AtlasErrorCode.GLOSSARY_TERM_QUALIFIED_NAME_CANT_BE_DERIVED);
-        }
-        if (isNameInvalid(glossaryTerm.getDisplayName())) {
-            throw new AtlasBaseException(AtlasErrorCode.INVALID_DISPLAY_NAME);
+        if (StringUtils.isEmpty(glossaryTerm.getQualifiedName())) {
+            if (StringUtils.isEmpty(glossaryTerm.getDisplayName())) {
+                throw new AtlasBaseException(AtlasErrorCode.GLOSSARY_TERM_QUALIFIED_NAME_CANT_BE_DERIVED);
+            }
+
+            if (isNameInvalid(glossaryTerm.getDisplayName())){
+                throw new AtlasBaseException(AtlasErrorCode.INVALID_DISPLAY_NAME);
+            } else {
+                glossaryTerm.setQualifiedName(glossaryTerm.getDisplayName());
+            }
         }
 
         // This might fail for the case when the term's qualifiedName has been updated and the duplicate request comes in with old name
@@ -507,14 +513,17 @@ public class GlossaryService {
         if (Objects.isNull(glossaryCategory.getAnchor())) {
             throw new AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ANCHOR);
         }
-        if (Objects.isNull(glossaryCategory.getDisplayName())) {
-            throw new AtlasBaseException(AtlasErrorCode.MISSING_CATEGORY_DISPLAY_NAME);
-        }
-        if (isNameInvalid(glossaryCategory.getDisplayName())) {
-            throw new AtlasBaseException(AtlasErrorCode.INVALID_DISPLAY_NAME);
+        if (StringUtils.isEmpty(glossaryCategory.getQualifiedName())) {
+            if (StringUtils.isEmpty(glossaryCategory.getDisplayName())) {
+                throw new AtlasBaseException(AtlasErrorCode.GLOSSARY_CATEGORY_QUALIFIED_NAME_CANT_BE_DERIVED);
+            }
+            if (isNameInvalid(glossaryCategory.getDisplayName())){
+                throw new AtlasBaseException(AtlasErrorCode.INVALID_DISPLAY_NAME);
+            } else {
+                glossaryCategory.setQualifiedName(glossaryCategory.getDisplayName());
+            }
         }
 
-
         // This might fail for the case when the category's qualifiedName has been updated during a hierarchy change
         // and the duplicate request comes in with old name
         if (categoryExists(glossaryCategory)) {

http://git-wip-us.apache.org/repos/asf/atlas/blob/6f57b410/repository/src/test/java/org/apache/atlas/glossary/GlossaryServiceTest.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/glossary/GlossaryServiceTest.java b/repository/src/test/java/org/apache/atlas/glossary/GlossaryServiceTest.java
index 6a6b971..c72e642 100644
--- a/repository/src/test/java/org/apache/atlas/glossary/GlossaryServiceTest.java
+++ b/repository/src/test/java/org/apache/atlas/glossary/GlossaryServiceTest.java
@@ -126,7 +126,6 @@ public class GlossaryServiceTest {
 
         // Category
         accountCategory = new AtlasGlossaryCategory();
-        accountCategory.setQualifiedName("acc@testBankingGlossary");
         accountCategory.setDisplayName("Account categorization");
         accountCategory.setShortDescription("Short description");
         accountCategory.setLongDescription("Long description");
@@ -138,14 +137,12 @@ public class GlossaryServiceTest {
         customerCategory.setLongDescription("Long description");
 
         mortgageCategory = new AtlasGlossaryCategory();
-        mortgageCategory.setQualifiedName("mtg@testBankingGlossary");
         mortgageCategory.setDisplayName("Mortgage categorization");
         mortgageCategory.setShortDescription("Short description");
         mortgageCategory.setLongDescription("Long description");
 
         // Terms
         checkingAccount = new AtlasGlossaryTerm();
-        checkingAccount.setQualifiedName("chk_acc@testBankingGlossary");
         checkingAccount.setDisplayName("A checking account");
         checkingAccount.setShortDescription("Short description");
         checkingAccount.setLongDescription("Long description");
@@ -163,7 +160,6 @@ public class GlossaryServiceTest {
         savingsAccount.setUsage("N/A");
 
         fixedRateMortgage = new AtlasGlossaryTerm();
-        fixedRateMortgage.setQualifiedName("fixed_mtg@testBankingGlossary");
         fixedRateMortgage.setDisplayName("Conventional mortgage");
         fixedRateMortgage.setShortDescription("Short description");
         fixedRateMortgage.setLongDescription("Long description");