Commit 66f8ae16 by apoorvnaik

ATLAS-2679: Update qualifiedName category hierarchy corresponding to any change to category

Change-Id: I4cddcfe76eabcf7ee705b60848521158bb33a8a5
parent 801db28b
...@@ -26,6 +26,7 @@ import java.util.Arrays; ...@@ -26,6 +26,7 @@ import java.util.Arrays;
public enum AtlasErrorCode { public enum AtlasErrorCode {
NO_SEARCH_RESULTS(204, "ATLAS-204-00-001", "Given search filter {0} did not yield any results"), NO_SEARCH_RESULTS(204, "ATLAS-204-00-001", "Given search filter {0} did not yield any results"),
DATA_ACCESS_SAVE_FAILED(204, "ATLAS-204-00-002", "Save failed: {0} has no updates"),
UNKNOWN_TYPE(400, "ATLAS-400-00-001", "Unknown type {0} for {1}.{2}"), UNKNOWN_TYPE(400, "ATLAS-400-00-001", "Unknown type {0} for {1}.{2}"),
CIRCULAR_REFERENCE(400, "ATLAS-400-00-002", "{0}: invalid supertypes - circular reference back to self {1}"), CIRCULAR_REFERENCE(400, "ATLAS-400-00-002", "{0}: invalid supertypes - circular reference back to self {1}"),
...@@ -144,6 +145,7 @@ public enum AtlasErrorCode { ...@@ -144,6 +145,7 @@ public enum AtlasErrorCode {
INVALID_CHILD_CATEGORY_DIFFERENT_GLOSSARY(400, "ATLAS-400-00-07F", "Invalid child category relationship: Child category (guid = {0}) belongs to different glossary"), 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 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"), 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"),
UNAUTHORIZED_ACCESS(403, "ATLAS-403-00-001", "{0} is not authorized to perform {1}"), UNAUTHORIZED_ACCESS(403, "ATLAS-403-00-001", "{0} is not authorized to perform {1}"),
...@@ -196,7 +198,6 @@ public enum AtlasErrorCode { ...@@ -196,7 +198,6 @@ public enum AtlasErrorCode {
SQOOP_HOOK(500, "ATLAS-500-00-00F", "SqoopHook: {0}"), SQOOP_HOOK(500, "ATLAS-500-00-00F", "SqoopHook: {0}"),
HIVE_HOOK(500, "ATLAS-500-00-010", "HiveHook: {0}"), HIVE_HOOK(500, "ATLAS-500-00-010", "HiveHook: {0}"),
HIVE_HOOK_METASTORE_BRIDGE(500, "ATLAS-500-00-011", "HiveHookMetaStoreBridge: {0}"), HIVE_HOOK_METASTORE_BRIDGE(500, "ATLAS-500-00-011", "HiveHookMetaStoreBridge: {0}"),
DATA_ACCESS_SAVE_FAILED(500, "ATLAS-500-00-012", "Save failed: {0}"),
DATA_ACCESS_LOAD_FAILED(500, "ATLAS-500-00-013", "Load failed: {0}"), DATA_ACCESS_LOAD_FAILED(500, "ATLAS-500-00-013", "Load failed: {0}"),
ENTITY_NOTIFICATION_FAILED(500, "ATLAS-500-00-014", "Notification failed for operation: {0} : {1}"); ENTITY_NOTIFICATION_FAILED(500, "ATLAS-500-00-014", "Notification failed for operation: {0} : {1}");
......
...@@ -146,12 +146,10 @@ public class AtlasGlossary extends AtlasGlossaryBaseObject { ...@@ -146,12 +146,10 @@ public class AtlasGlossary extends AtlasGlossaryBaseObject {
@Override @Override
protected StringBuilder toString(final StringBuilder sb) { protected StringBuilder toString(final StringBuilder sb) {
sb.append("{"); sb.append(", language='").append(language).append('\'');
sb.append("language='").append(language).append('\'');
sb.append(", usage='").append(usage).append('\''); sb.append(", usage='").append(usage).append('\'');
sb.append(", terms=").append(terms); sb.append(", terms=").append(terms);
sb.append(", categories=").append(categories); sb.append(", categories=").append(categories);
sb.append('}');
return sb; return sb;
} }
...@@ -234,11 +232,8 @@ public class AtlasGlossary extends AtlasGlossaryBaseObject { ...@@ -234,11 +232,8 @@ public class AtlasGlossary extends AtlasGlossaryBaseObject {
@Override @Override
public StringBuilder toString(StringBuilder sb) { public StringBuilder toString(StringBuilder sb) {
sb.append("{");
super.toString(sb);
sb.append(", termInfo=").append(termInfo); sb.append(", termInfo=").append(termInfo);
sb.append(", categoryInfo=").append(categoryInfo); sb.append(", categoryInfo=").append(categoryInfo);
sb.append('}');
return sb; return sb;
} }
......
...@@ -29,13 +29,13 @@ import java.util.Objects; ...@@ -29,13 +29,13 @@ import java.util.Objects;
public abstract class AtlasGlossaryBaseObject extends AtlasBaseModelObject { public abstract class AtlasGlossaryBaseObject extends AtlasBaseModelObject {
// Core attributes // Core attributes
private String qualifiedName;
protected String displayName; protected String displayName;
protected String shortDescription; protected String shortDescription;
protected String longDescription; protected String longDescription;
// Classifications // Classifications
protected List<AtlasClassification> classifications; protected List<AtlasClassification> classifications;
private String qualifiedName;
public AtlasGlossaryBaseObject() { public AtlasGlossaryBaseObject() {
} }
...@@ -129,13 +129,11 @@ public abstract class AtlasGlossaryBaseObject extends AtlasBaseModelObject { ...@@ -129,13 +129,11 @@ public abstract class AtlasGlossaryBaseObject extends AtlasBaseModelObject {
@Override @Override
protected StringBuilder toString(final StringBuilder sb) { protected StringBuilder toString(final StringBuilder sb) {
sb.append("{"); sb.append(", qualifiedName='").append(qualifiedName).append('\'');
sb.append("displayName='").append(displayName).append('\''); sb.append(", displayName='").append(displayName).append('\'');
sb.append(", shortDescription='").append(shortDescription).append('\''); sb.append(", shortDescription='").append(shortDescription).append('\'');
sb.append(", longDescription='").append(longDescription).append('\''); sb.append(", longDescription='").append(longDescription).append('\'');
sb.append(", classifications=").append(classifications); sb.append(", classifications=").append(classifications);
sb.append(", qualifiedName='").append(qualifiedName).append('\'');
sb.append('}');
return sb; return sb;
} }
......
...@@ -138,16 +138,10 @@ public class AtlasGlossaryCategory extends AtlasGlossaryBaseObject { ...@@ -138,16 +138,10 @@ public class AtlasGlossaryCategory extends AtlasGlossaryBaseObject {
@Override @Override
protected StringBuilder toString(final StringBuilder sb) { protected StringBuilder toString(final StringBuilder sb) {
sb.append("{");
sb.append("displayName='").append(getDisplayName()).append('\'');
sb.append(", shortDescription='").append(getShortDescription()).append('\'');
sb.append(", longDescription='").append(getLongDescription()).append('\'');
sb.append(", anchor=").append(anchor); sb.append(", anchor=").append(anchor);
sb.append(", parentCategory=").append(parentCategory); sb.append(", parentCategory=").append(parentCategory);
sb.append(", childrenCategories=").append(childrenCategories); sb.append(", childrenCategories=").append(childrenCategories);
sb.append(", terms=").append(terms); sb.append(", terms=").append(terms);
sb.append(", classifications=").append(getClassifications());
sb.append('}');
return sb; return sb;
} }
......
...@@ -376,7 +376,6 @@ public class AtlasGlossaryTerm extends AtlasGlossaryBaseObject { ...@@ -376,7 +376,6 @@ public class AtlasGlossaryTerm extends AtlasGlossaryBaseObject {
@Override @Override
protected StringBuilder toString(final StringBuilder sb) { protected StringBuilder toString(final StringBuilder sb) {
sb.append("{");
sb.append("examples=").append(examples); sb.append("examples=").append(examples);
sb.append(", abbreviation='").append(abbreviation).append('\''); sb.append(", abbreviation='").append(abbreviation).append('\'');
sb.append(", usage='").append(usage).append('\''); sb.append(", usage='").append(usage).append('\'');
...@@ -396,7 +395,6 @@ public class AtlasGlossaryTerm extends AtlasGlossaryBaseObject { ...@@ -396,7 +395,6 @@ public class AtlasGlossaryTerm extends AtlasGlossaryBaseObject {
sb.append(", classifies=").append(classifies); sb.append(", classifies=").append(classifies);
sb.append(", validValues=").append(validValues); sb.append(", validValues=").append(validValues);
sb.append(", validValuesFor=").append(validValuesFor); sb.append(", validValuesFor=").append(validValuesFor);
sb.append('}');
return sb; return sb;
} }
......
...@@ -19,6 +19,9 @@ package org.apache.atlas.glossary; ...@@ -19,6 +19,9 @@ package org.apache.atlas.glossary;
import org.apache.atlas.AtlasErrorCode; import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.glossary.AtlasGlossary;
import org.apache.atlas.model.glossary.AtlasGlossaryCategory;
import org.apache.atlas.model.glossary.AtlasGlossaryTerm;
import org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader; import org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader;
import org.apache.atlas.model.instance.AtlasRelationship; import org.apache.atlas.model.instance.AtlasRelationship;
import org.apache.atlas.repository.ogm.DataAccess; import org.apache.atlas.repository.ogm.DataAccess;
...@@ -64,6 +67,26 @@ public abstract class GlossaryUtils { ...@@ -64,6 +67,26 @@ public abstract class GlossaryUtils {
this.dataAccess = dataAccess; this.dataAccess = dataAccess;
} }
public static AtlasGlossary getGlossarySkeleton(String glossaryGuid) {
AtlasGlossary glossary = new AtlasGlossary();
glossary.setGuid(glossaryGuid);
return glossary;
}
public static AtlasGlossaryTerm getAtlasGlossaryTermSkeleton(final String termGuid) {
AtlasGlossaryTerm glossaryTerm = new AtlasGlossaryTerm();
glossaryTerm.setGuid(termGuid);
return glossaryTerm;
}
public static AtlasGlossaryCategory getAtlasGlossaryCategorySkeleton(final String categoryGuid) {
AtlasGlossaryCategory glossaryCategory = new AtlasGlossaryCategory();
glossaryCategory.setGuid(categoryGuid);
return glossaryCategory;
}
protected void createRelationship(AtlasRelationship relationship) throws AtlasBaseException { protected void createRelationship(AtlasRelationship relationship) throws AtlasBaseException {
try { try {
relationshipStore.create(relationship); relationshipStore.create(relationship);
......
...@@ -314,7 +314,12 @@ public class GlossaryServiceTest { ...@@ -314,7 +314,12 @@ public class GlossaryServiceTest {
List<AtlasGlossaryCategory> categories = glossaryService.createCategories(Arrays.asList(accountCategory, mortgageCategory)); List<AtlasGlossaryCategory> categories = glossaryService.createCategories(Arrays.asList(accountCategory, mortgageCategory));
accountCategory.setGuid(categories.get(0).getGuid()); accountCategory.setGuid(categories.get(0).getGuid());
assertNotNull(accountCategory.getParentCategory());
assertEquals(accountCategory.getParentCategory().getCategoryGuid(), customerCategory.getGuid());
assertTrue(accountCategory.getQualifiedName().endsWith(customerCategory.getQualifiedName()));
mortgageCategory.setGuid(categories.get(1).getGuid()); mortgageCategory.setGuid(categories.get(1).getGuid());
assertNull(mortgageCategory.getParentCategory());
} catch (AtlasBaseException e) { } catch (AtlasBaseException e) {
fail("Category creation should've succeeded", e); fail("Category creation should've succeeded", e);
} }
...@@ -395,11 +400,51 @@ public class GlossaryServiceTest { ...@@ -395,11 +400,51 @@ public class GlossaryServiceTest {
public void testDeleteGlossary() { public void testDeleteGlossary() {
try { try {
glossaryService.deleteGlossary(bankGlossary.getGuid()); glossaryService.deleteGlossary(bankGlossary.getGuid());
// Fetch deleted glossary
try { try {
glossaryService.getGlossary(bankGlossary.getGuid()); glossaryService.getGlossary(bankGlossary.getGuid());
} catch (AtlasBaseException e) { } catch (AtlasBaseException e) {
assertEquals(e.getAtlasErrorCode(), AtlasErrorCode.INSTANCE_GUID_NOT_FOUND); assertEquals(e.getAtlasErrorCode(), AtlasErrorCode.INSTANCE_GUID_NOT_FOUND);
} }
// Fetch delete terms
try {
glossaryService.getTerm(fixedRateMortgage.getGuid());
} catch (AtlasBaseException e) {
assertEquals(e.getAtlasErrorCode(), AtlasErrorCode.INSTANCE_GUID_NOT_FOUND);
}
try {
glossaryService.getTerm(adjustableRateMortgage.getGuid());
} catch (AtlasBaseException e) {
assertEquals(e.getAtlasErrorCode(), AtlasErrorCode.INSTANCE_GUID_NOT_FOUND);
}
try {
glossaryService.getTerm(savingsAccount.getGuid());
} catch (AtlasBaseException e) {
assertEquals(e.getAtlasErrorCode(), AtlasErrorCode.INSTANCE_GUID_NOT_FOUND);
}
try {
glossaryService.getTerm(checkingAccount.getGuid());
} catch (AtlasBaseException e) {
assertEquals(e.getAtlasErrorCode(), AtlasErrorCode.INSTANCE_GUID_NOT_FOUND);
}
// Fetch deleted categories
try {
glossaryService.getCategory(customerCategory.getGuid());
} catch (AtlasBaseException e) {
assertEquals(e.getAtlasErrorCode(), AtlasErrorCode.INSTANCE_GUID_NOT_FOUND);
}
try {
glossaryService.getCategory(accountCategory.getGuid());
} catch (AtlasBaseException e) {
assertEquals(e.getAtlasErrorCode(), AtlasErrorCode.INSTANCE_GUID_NOT_FOUND);
}
try {
glossaryService.getCategory(mortgageCategory.getGuid());
} catch (AtlasBaseException e) {
assertEquals(e.getAtlasErrorCode(), AtlasErrorCode.INSTANCE_GUID_NOT_FOUND);
}
} catch (AtlasBaseException e) { } catch (AtlasBaseException e) {
fail("Glossary delete should've succeeded", e); fail("Glossary delete should've succeeded", e);
} }
...@@ -460,11 +505,22 @@ public class GlossaryServiceTest { ...@@ -460,11 +505,22 @@ public class GlossaryServiceTest {
// Unlink children // Unlink children
try { try {
AtlasGlossaryCategory category = glossaryService.getCategory(customerCategory.getGuid()); customerCategory = glossaryService.getCategory(customerCategory.getGuid());
category.setChildrenCategories(null); customerCategory.setChildrenCategories(null);
category = glossaryService.updateCategory(category); customerCategory = glossaryService.updateCategory(customerCategory);
assertNotNull(category); assertNotNull(customerCategory);
assertNull(category.getChildrenCategories()); assertNull(customerCategory.getChildrenCategories());
accountCategory = glossaryService.getCategory(accountCategory.getGuid());
assertNull(accountCategory.getParentCategory());
assertTrue(accountCategory.getQualifiedName().endsWith(bankGlossary.getQualifiedName()));
mortgageCategory = glossaryService.getCategory(mortgageCategory.getGuid());
assertNull(mortgageCategory.getParentCategory());
assertTrue(mortgageCategory.getQualifiedName().endsWith(bankGlossary.getQualifiedName()));
} catch (AtlasBaseException e) { } catch (AtlasBaseException e) {
fail("Customer category fetch should've succeeded"); fail("Customer category fetch should've succeeded");
} }
...@@ -519,16 +575,27 @@ public class GlossaryServiceTest { ...@@ -519,16 +575,27 @@ public class GlossaryServiceTest {
try { try {
customerCategory = glossaryService.getCategory(customerCategory.getGuid()); customerCategory = glossaryService.getCategory(customerCategory.getGuid());
mortgageCategory = glossaryService.getCategory(mortgageCategory.getGuid());
accountCategory = glossaryService.getCategory(accountCategory.getGuid());
} catch (AtlasBaseException e) { } catch (AtlasBaseException e) {
fail("Category fetch for migration should've succeeded"); fail("Category fetch for migration should've succeeded");
} }
customerCategory.setAnchor(newGlossaryHeader); customerCategory.setAnchor(newGlossaryHeader);
customerCategory.setChildrenCategories(null); mortgageCategory.setAnchor(newGlossaryHeader);
accountCategory.setAnchor(newGlossaryHeader);
try { try {
customerCategory = glossaryService.updateCategory(customerCategory); customerCategory = glossaryService.updateCategory(customerCategory);
assertTrue(CollectionUtils.isEmpty(customerCategory.getChildrenCategories())); mortgageCategory = glossaryService.updateCategory(mortgageCategory);
accountCategory = glossaryService.updateCategory(accountCategory);
assertTrue(customerCategory.getQualifiedName().endsWith(creditUnionGlossary.getQualifiedName()));
assertEquals(customerCategory.getAnchor().getGlossaryGuid(), newGlossaryHeader.getGlossaryGuid());
assertTrue(accountCategory.getQualifiedName().endsWith(creditUnionGlossary.getQualifiedName()));
assertEquals(accountCategory.getAnchor().getGlossaryGuid(), newGlossaryHeader.getGlossaryGuid());
assertTrue(mortgageCategory.getQualifiedName().endsWith(creditUnionGlossary.getQualifiedName()));
assertEquals(mortgageCategory.getAnchor().getGlossaryGuid(), newGlossaryHeader.getGlossaryGuid());
} catch (AtlasBaseException e) { } catch (AtlasBaseException e) {
fail("Category anchor change should've succeeded"); fail("Category anchor change should've succeeded");
} }
...@@ -536,10 +603,50 @@ public class GlossaryServiceTest { ...@@ -536,10 +603,50 @@ public class GlossaryServiceTest {
try { try {
List<AtlasRelatedCategoryHeader> categories = glossaryService.getGlossaryCategoriesHeaders(creditUnionGlossary.getGuid(), 0, 5, SortOrder.ASCENDING); List<AtlasRelatedCategoryHeader> categories = glossaryService.getGlossaryCategoriesHeaders(creditUnionGlossary.getGuid(), 0, 5, SortOrder.ASCENDING);
assertNotNull(categories); assertNotNull(categories);
assertEquals(categories.size(), 1); assertEquals(categories.size(), 3);
} catch (AtlasBaseException e) { } catch (AtlasBaseException e) {
fail("Category migration should've succeeded", e); fail("Category migration should've succeeded", e);
} }
// Move the entire hierarchy back to the original glossary
AtlasRelatedCategoryHeader child1 = new AtlasRelatedCategoryHeader();
child1.setCategoryGuid(accountCategory.getGuid());
AtlasRelatedCategoryHeader child2 = new AtlasRelatedCategoryHeader();
child2.setCategoryGuid(mortgageCategory.getGuid());
customerCategory.addChild(child1);
customerCategory.addChild(child2);
try {
customerCategory = glossaryService.updateCategory(customerCategory);
assertTrue(CollectionUtils.isNotEmpty(customerCategory.getChildrenCategories()));
} catch (AtlasBaseException e) {
fail("Children addition to Category should've succeeded");
}
customerCategory.setAnchor(newGlossaryHeader);
newGlossaryHeader.setGlossaryGuid(bankGlossary.getGuid());
try {
customerCategory = glossaryService.getCategory(customerCategory.getGuid());
assertTrue(CollectionUtils.isNotEmpty(customerCategory.getChildrenCategories()));
} catch (AtlasBaseException e) {
fail("Category fetch should've succeeded");
}
try {
accountCategory = glossaryService.getCategory(accountCategory.getGuid());
assertEquals(accountCategory.getAnchor().getGlossaryGuid(), customerCategory.getAnchor().getGlossaryGuid());
} catch (AtlasBaseException e) {
fail("Category fetch should've succeeded");
}
try {
mortgageCategory = glossaryService.getCategory(mortgageCategory.getGuid());
assertEquals(mortgageCategory.getAnchor().getGlossaryGuid(), customerCategory.getAnchor().getGlossaryGuid());
} catch (AtlasBaseException e) {
fail("Category fetch should've succeeded");
}
} }
@Test(groups = "Glossary.UPDATE", dependsOnGroups = "Glossary.CREATE") @Test(groups = "Glossary.UPDATE", dependsOnGroups = "Glossary.CREATE")
...@@ -689,6 +796,12 @@ public class GlossaryServiceTest { ...@@ -689,6 +796,12 @@ public class GlossaryServiceTest {
} catch (AtlasBaseException e) { } catch (AtlasBaseException e) {
fail("Term update should've succeeded", e); fail("Term update should've succeeded", e);
} }
try {
entityStore.deleteById(relatedObjectId.getGuid());
} catch (AtlasBaseException e) {
fail("Entity delete should've succeeded");
}
} }
@Test(groups = "Glossary.UPDATE", dependsOnGroups = "Glossary.CREATE") @Test(groups = "Glossary.UPDATE", dependsOnGroups = "Glossary.CREATE")
......
...@@ -394,7 +394,7 @@ public class GlossaryREST { ...@@ -394,7 +394,7 @@ public class GlossaryREST {
try { try {
glossary.setAttribute(entry.getKey(), entry.getValue()); glossary.setAttribute(entry.getKey(), entry.getValue());
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
throw new AtlasBaseException(AtlasErrorCode.INVALID_PARTIAL_UPDATE_ATTR, "Glossary", entry.getKey()); throw new AtlasBaseException(AtlasErrorCode.INVALID_PARTIAL_UPDATE_ATTR, entry.getKey(), "Glossary");
} }
} }
return glossaryService.updateGlossary(glossary); return glossaryService.updateGlossary(glossary);
......
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