Repository: atlas Updated Branches: refs/heads/branch-1.0 d5f817d6d -> 2a8c2d3de
ATLAS-2700: Error message fix ATLAS-2701: Usage attribute not getting persisted for term ATLAS-2702: Term qualifiedName not persisting after anchor change Change-Id: I23b53086b2bb2380f451e7d85b59096edc610181 (cherry picked from commit 9044e0375cea58641b0f54c1732980f1401fd845) Project: http://git-wip-us.apache.org/repos/asf/atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/49a4f964 Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/49a4f964 Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/49a4f964 Branch: refs/heads/branch-1.0 Commit: 49a4f9641e954fc873304b7b1cf03a1b6ec55bfd Parents: d5f817d Author: apoorvnaik <apoorvn...@apache.org> Authored: Thu May 17 14:17:43 2018 -0700 Committer: Madhan Neethiraj <mad...@apache.org> Committed: Fri May 18 10:16:40 2018 -0700 ---------------------------------------------------------------------- .../java/org/apache/atlas/AtlasErrorCode.java | 4 ++-- .../apache/atlas/glossary/GlossaryService.java | 23 +++++++++++++++----- .../atlas/glossary/GlossaryTermUtils.java | 2 +- .../ogm/glossary/AtlasGlossaryTermDTO.java | 2 ++ 4 files changed, 22 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/atlas/blob/49a4f964/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 4397dd9..0f6ce85 100644 --- a/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java +++ b/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java @@ -143,11 +143,11 @@ public enum AtlasErrorCode { RELATIONSHIP_END_IS_NULL(400, "ATLAS-400-00-07D", "Relationship end is invalid. Expected {0} but is NULL"), INVALID_TERM_RELATION_TO_SELF(400, "ATLAS-400-00-07E", "Invalid Term relationship: Term can't have a relationship with self"), INVALID_CHILD_CATEGORY_DIFFERENT_GLOSSARY(400, "ATLAS-400-00-07F", "Invalid child category relationship: Child category (guid = {0}) belongs to different glossary"), - INVALID_TERM_DISSOCIATION(400, "ATLAS-400-00-080", "Given term (guid={0}) is not associated to entity(guid={1})"), + INVALID_TERM_DISSOCIATION(400, "ATLAS-400-00-080", "Given relationshipGuid({0}) is invalid for term (guid={1}) and entity(guid={2})"), 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."), + TERM_HAS_ENTITY_ASSOCIATION(400, "ATLAS-400-00-086", "Term (guid={0}) can't be deleted as it has been assigned to {1} 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/49a4f964/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 bae2ea1..bd9095b 100644 --- a/repository/src/main/java/org/apache/atlas/glossary/GlossaryService.java +++ b/repository/src/main/java/org/apache/atlas/glossary/GlossaryService.java @@ -348,7 +348,12 @@ public class GlossaryService { glossaryTermUtils.processTermRelations(storeObject, glossaryTerm, GlossaryUtils.RelationshipOperation.CREATE); // Re-load term after handling relations - storeObject = dataAccess.load(glossaryTerm); + if (StringUtils.equals(storeObject.getQualifiedName(), glossaryTerm.getQualifiedName())) { + storeObject = dataAccess.load(glossaryTerm); + } else { + glossaryTerm.setQualifiedName(storeObject.getQualifiedName()); + storeObject = dataAccess.save(glossaryTerm); + } setInfoForRelations(storeObject); if (DEBUG_ENABLED) { @@ -409,11 +414,17 @@ public class GlossaryService { LOG.debug("Glossary term had no immediate attr updates. Exception: {}", e.getMessage()); } finally { glossaryTermUtils.processTermRelations(storeObject, atlasGlossaryTerm, GlossaryUtils.RelationshipOperation.UPDATE); - } + // If qualifiedName changes due to anchor change, we need to persist the term again with updated qualifiedName + if (StringUtils.equals(storeObject.getQualifiedName(), atlasGlossaryTerm.getQualifiedName())) { + storeObject = dataAccess.load(atlasGlossaryTerm); + } else { + atlasGlossaryTerm.setQualifiedName(storeObject.getQualifiedName()); + storeObject = dataAccess.save(atlasGlossaryTerm); + } + } } - storeObject = dataAccess.load(atlasGlossaryTerm); setInfoForRelations(storeObject); if (DEBUG_ENABLED) { @@ -539,11 +550,11 @@ public class GlossaryService { dataAccess.save(impactedCategories.values()); // Since the current category is also affected, we need to update qualifiedName and save again - if (!StringUtils.equals(glossaryCategory.getQualifiedName(), storeObject.getQualifiedName())) { + if (StringUtils.equals(glossaryCategory.getQualifiedName(), storeObject.getQualifiedName())) { + storeObject = dataAccess.load(glossaryCategory); + } else { glossaryCategory.setQualifiedName(storeObject.getQualifiedName()); storeObject = dataAccess.save(glossaryCategory); - } else { - storeObject = dataAccess.load(glossaryCategory); } setInfoForRelations(storeObject); http://git-wip-us.apache.org/repos/asf/atlas/blob/49a4f964/repository/src/main/java/org/apache/atlas/glossary/GlossaryTermUtils.java ---------------------------------------------------------------------- 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 2c38d31..2af4e79 100644 --- a/repository/src/main/java/org/apache/atlas/glossary/GlossaryTermUtils.java +++ b/repository/src/main/java/org/apache/atlas/glossary/GlossaryTermUtils.java @@ -121,7 +121,7 @@ public class GlossaryTermUtils extends GlossaryUtils { if (CollectionUtils.isNotEmpty(assignedEntities) && isRelationshipGuidSame(existingTermRelation, relatedObjectId)) { relationshipStore.deleteById(relatedObjectId.getRelationshipGuid()); } else { - throw new AtlasBaseException(AtlasErrorCode.INVALID_TERM_DISSOCIATION, glossaryTerm.getGuid(), relatedObjectId.getGuid()); + throw new AtlasBaseException(AtlasErrorCode.INVALID_TERM_DISSOCIATION, relatedObjectId.getRelationshipGuid(), glossaryTerm.getGuid(), relatedObjectId.getGuid()); } } } http://git-wip-us.apache.org/repos/asf/atlas/blob/49a4f964/repository/src/main/java/org/apache/atlas/repository/ogm/glossary/AtlasGlossaryTermDTO.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/ogm/glossary/AtlasGlossaryTermDTO.java b/repository/src/main/java/org/apache/atlas/repository/ogm/glossary/AtlasGlossaryTermDTO.java index 9fed84a..d557752 100644 --- a/repository/src/main/java/org/apache/atlas/repository/ogm/glossary/AtlasGlossaryTermDTO.java +++ b/repository/src/main/java/org/apache/atlas/repository/ogm/glossary/AtlasGlossaryTermDTO.java @@ -60,6 +60,7 @@ public class AtlasGlossaryTermDTO extends AbstractGlossaryDTO<AtlasGlossaryTerm> ret.setLongDescription((String) entity.getAttribute("longDescription")); ret.setExamples((List<String>) entity.getAttribute("examples")); ret.setAbbreviation((String) entity.getAttribute("abbreviation")); + ret.setUsage((String) entity.getAttribute("usage")); Object anchor = entity.getRelationshipAttribute("anchor"); if (anchor instanceof AtlasRelatedObjectId) { @@ -212,6 +213,7 @@ public class AtlasGlossaryTermDTO extends AbstractGlossaryDTO<AtlasGlossaryTerm> ret.setAttribute("longDescription", obj.getLongDescription()); ret.setAttribute("examples", obj.getExamples()); ret.setAttribute("abbreviation", obj.getAbbreviation()); + ret.setAttribute("usage", obj.getUsage()); if (CollectionUtils.isNotEmpty(obj.getClassifications())) { if (LOG.isDebugEnabled()) {