Commit 96e5f1cb by apoorvnaik

ATLAS-2711: Fix duplicate qualifiedName issue

Change-Id: I23b53086b2bb2380f451e7d85b59096edc610181
parent d218fb4f
...@@ -352,6 +352,11 @@ public class GlossaryService { ...@@ -352,6 +352,11 @@ public class GlossaryService {
storeObject = dataAccess.load(glossaryTerm); storeObject = dataAccess.load(glossaryTerm);
} else { } else {
glossaryTerm.setQualifiedName(storeObject.getQualifiedName()); glossaryTerm.setQualifiedName(storeObject.getQualifiedName());
if (termExists(glossaryTerm)) {
throw new AtlasBaseException(AtlasErrorCode.GLOSSARY_TERM_ALREADY_EXISTS, glossaryTerm.getQualifiedName());
}
storeObject = dataAccess.save(glossaryTerm); storeObject = dataAccess.save(glossaryTerm);
} }
setInfoForRelations(storeObject); setInfoForRelations(storeObject);
...@@ -412,16 +417,21 @@ public class GlossaryService { ...@@ -412,16 +417,21 @@ public class GlossaryService {
storeObject = dataAccess.save(atlasGlossaryTerm); storeObject = dataAccess.save(atlasGlossaryTerm);
} catch (AtlasBaseException e) { } catch (AtlasBaseException e) {
LOG.debug("Glossary term had no immediate attr updates. Exception: {}", e.getMessage()); 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 glossaryTermUtils.processTermRelations(storeObject, atlasGlossaryTerm, GlossaryUtils.RelationshipOperation.UPDATE);
if (StringUtils.equals(storeObject.getQualifiedName(), atlasGlossaryTerm.getQualifiedName())) {
storeObject = dataAccess.load(atlasGlossaryTerm); // If qualifiedName changes due to anchor change, we need to persist the term again with updated qualifiedName
} else { if (StringUtils.equals(storeObject.getQualifiedName(), atlasGlossaryTerm.getQualifiedName())) {
atlasGlossaryTerm.setQualifiedName(storeObject.getQualifiedName()); storeObject = dataAccess.load(atlasGlossaryTerm);
storeObject = dataAccess.save(atlasGlossaryTerm); } else {
atlasGlossaryTerm.setQualifiedName(storeObject.getQualifiedName());
if (termExists(atlasGlossaryTerm)) {
throw new AtlasBaseException(AtlasErrorCode.GLOSSARY_TERM_ALREADY_EXISTS, atlasGlossaryTerm.getQualifiedName());
} }
storeObject = dataAccess.save(atlasGlossaryTerm);
} }
} }
...@@ -546,17 +556,22 @@ public class GlossaryService { ...@@ -546,17 +556,22 @@ public class GlossaryService {
// Attempt relation creation and gather all impacted categories // Attempt relation creation and gather all impacted categories
Map<String, AtlasGlossaryCategory> impactedCategories = glossaryCategoryUtils.processCategoryRelations(storeObject, glossaryCategory, GlossaryUtils.RelationshipOperation.CREATE); Map<String, AtlasGlossaryCategory> impactedCategories = glossaryCategoryUtils.processCategoryRelations(storeObject, glossaryCategory, GlossaryUtils.RelationshipOperation.CREATE);
// Re save the categories in case any qualifiedName change has occurred
dataAccess.save(impactedCategories.values());
// Since the current category is also affected, we need to update qualifiedName and save again // 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); storeObject = dataAccess.load(glossaryCategory);
} else { } else {
glossaryCategory.setQualifiedName(storeObject.getQualifiedName()); glossaryCategory.setQualifiedName(storeObject.getQualifiedName());
if (categoryExists(glossaryCategory)) {
throw new AtlasBaseException(AtlasErrorCode.GLOSSARY_CATEGORY_ALREADY_EXISTS, glossaryCategory.getQualifiedName());
}
storeObject = dataAccess.save(glossaryCategory); storeObject = dataAccess.save(glossaryCategory);
} }
// Re save the categories in case any qualifiedName change has occurred
dataAccess.save(impactedCategories.values());
setInfoForRelations(storeObject); setInfoForRelations(storeObject);
if (DEBUG_ENABLED) { if (DEBUG_ENABLED) {
...@@ -575,7 +590,6 @@ public class GlossaryService { ...@@ -575,7 +590,6 @@ public class GlossaryService {
throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "glossaryCategory is null/empty"); throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "glossaryCategory is null/empty");
} }
List<AtlasGlossaryCategory> ret = new ArrayList<>(); List<AtlasGlossaryCategory> ret = new ArrayList<>();
for (AtlasGlossaryCategory category : glossaryCategory) { for (AtlasGlossaryCategory category : glossaryCategory) {
ret.add(createCategory(category)); ret.add(createCategory(category));
...@@ -614,17 +628,24 @@ public class GlossaryService { ...@@ -614,17 +628,24 @@ public class GlossaryService {
storeObject = dataAccess.save(glossaryCategory); storeObject = dataAccess.save(glossaryCategory);
} catch (AtlasBaseException e) { } catch (AtlasBaseException e) {
LOG.debug("No immediate attribute update. Exception: {}", e.getMessage()); LOG.debug("No immediate attribute update. Exception: {}", e.getMessage());
} finally { }
Map<String, AtlasGlossaryCategory> impactedCategories = glossaryCategoryUtils.processCategoryRelations(storeObject, glossaryCategory, GlossaryUtils.RelationshipOperation.UPDATE);
dataAccess.save(impactedCategories.values()); Map<String, AtlasGlossaryCategory> impactedCategories = glossaryCategoryUtils.processCategoryRelations(storeObject, glossaryCategory, GlossaryUtils.RelationshipOperation.UPDATE);
// Since the current category is also affected, we need to update qualifiedName and save again
if (!StringUtils.equals(glossaryCategory.getQualifiedName(), storeObject.getQualifiedName())){ // Since the current category is also affected, we need to update qualifiedName and save again
glossaryCategory.setQualifiedName(storeObject.getQualifiedName()); if (StringUtils.equals(glossaryCategory.getQualifiedName(), storeObject.getQualifiedName())) {
storeObject = dataAccess.save(glossaryCategory); storeObject = dataAccess.load(glossaryCategory);
} else { } else {
storeObject = dataAccess.load(glossaryCategory); glossaryCategory.setQualifiedName(storeObject.getQualifiedName());
if (categoryExists(glossaryCategory)) {
throw new AtlasBaseException(AtlasErrorCode.GLOSSARY_CATEGORY_ALREADY_EXISTS, glossaryCategory.getQualifiedName());
} }
storeObject = dataAccess.save(glossaryCategory);
} }
dataAccess.save(impactedCategories.values());
} }
if (DEBUG_ENABLED) { if (DEBUG_ENABLED) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment