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 2017/03/17 23:13:06 UTC
incubator-atlas git commit: ATLAS-1664: Able to add already added tag
to an entity through REST API:
Repository: incubator-atlas
Updated Branches:
refs/heads/master 0c9790289 -> 1612b3058
ATLAS-1664: Able to add already added tag to an entity through REST API:
Signed-off-by: apoorvnaik <an...@hortonworks.com>
Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/1612b305
Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/1612b305
Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/1612b305
Branch: refs/heads/master
Commit: 1612b3058a0bc8317dd6f3ff4980fead0d36df28
Parents: 0c97902
Author: Sarath Subramanian <ss...@hortonworks.com>
Authored: Fri Mar 17 09:36:08 2017 -0700
Committer: apoorvnaik <an...@hortonworks.com>
Committed: Fri Mar 17 16:12:29 2017 -0700
----------------------------------------------------------------------
.../store/graph/v1/AtlasEntityStoreV1.java | 39 ++++++++++++++++++++
.../org/apache/atlas/web/rest/EntityREST.java | 2 +-
2 files changed, 40 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/1612b305/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java
index cce3fca..86fd6ad 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java
@@ -432,6 +432,9 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore {
validateAndNormalize(classification);
}
+ // validate if entity, not already associated with classifications
+ validateEntityAssociations(guid, classifications);
+
EntityGraphMapper graphMapper = new EntityGraphMapper(deleteHandler, typeRegistry);
graphMapper.addClassifications(new EntityMutationContext(), guid, classifications);
@@ -460,6 +463,9 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore {
List<AtlasClassification> classifications = Collections.singletonList(classification);
for (String guid : guids) {
+ // validate if entity, not already associated with classifications
+ validateEntityAssociations(guid, classifications);
+
graphMapper.addClassifications(new EntityMutationContext(), guid, classifications);
// notify listeners on classification addition
@@ -598,4 +604,37 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore {
type.getNormalizedValue(classification);
}
+
+ /**
+ * Validate if classification is not already associated with the entities
+ * @param guid unique entity id
+ * @param classifications list of classifications to be associated
+ */
+ private void validateEntityAssociations(String guid, List<AtlasClassification> classifications) throws AtlasBaseException {
+ List<String> entityClassifications = getClassificationNames(guid);
+
+ for (AtlasClassification classification : classifications) {
+ String newClassification = classification.getTypeName();
+
+ if (CollectionUtils.isNotEmpty(entityClassifications) && entityClassifications.contains(newClassification)) {
+ throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "entity: " + guid +
+ ", already associated with classification: " + newClassification);
+ }
+ }
+ }
+
+ private List<String> getClassificationNames(String guid) throws AtlasBaseException {
+ List<String> ret = null;
+ List<AtlasClassification> classifications = getClassifications(guid);
+
+ if (CollectionUtils.isNotEmpty(classifications)) {
+ ret = new ArrayList<>();
+
+ for (AtlasClassification classification : classifications) {
+ ret.add(classification.getTypeName());
+ }
+ }
+
+ return ret;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/1612b305/webapp/src/main/java/org/apache/atlas/web/rest/EntityREST.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/rest/EntityREST.java b/webapp/src/main/java/org/apache/atlas/web/rest/EntityREST.java
index 98dc918..671590d 100644
--- a/webapp/src/main/java/org/apache/atlas/web/rest/EntityREST.java
+++ b/webapp/src/main/java/org/apache/atlas/web/rest/EntityREST.java
@@ -474,7 +474,7 @@ public class EntityREST {
AtlasClassification classification = request == null ? null : request.getClassification();
List<String> entityGuids = request == null ? null : request.getEntityGuids();
- if (classification == null || org.apache.commons.lang.StringUtils.isEmpty(classification.getTypeName())) {
+ if (classification == null || StringUtils.isEmpty(classification.getTypeName())) {
throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "no classification");
}