use of org.apache.atlas.model.glossary.relations.AtlasRelatedCategoryHeader in project atlas by apache.
the class GlossaryServiceTest method testCategoryCreation.
@Test(groups = "Glossary.CREATE", dependsOnMethods = "testCreateGlossary")
public void testCategoryCreation() {
try {
customerCategory = glossaryService.createCategory(customerCategory);
AtlasRelatedCategoryHeader parentHeader = new AtlasRelatedCategoryHeader();
parentHeader.setCategoryGuid(customerCategory.getGuid());
// Test parent relation
accountCategory.setParentCategory(parentHeader);
List<AtlasGlossaryCategory> categories = glossaryService.createCategories(Arrays.asList(accountCategory, mortgageCategory));
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());
assertNull(mortgageCategory.getParentCategory());
} catch (AtlasBaseException e) {
fail("Category creation should've succeeded", e);
}
}
use of org.apache.atlas.model.glossary.relations.AtlasRelatedCategoryHeader in project atlas by apache.
the class GlossaryServiceTest method testUpdateGlossary.
@Test(groups = "Glossary.UPDATE", dependsOnGroups = "Glossary.CREATE")
public void testUpdateGlossary() {
try {
bankGlossary = glossaryService.getGlossary(bankGlossary.getGuid());
bankGlossary.setShortDescription("Updated short description");
bankGlossary.setLongDescription("Updated long description");
AtlasGlossary updatedGlossary = glossaryService.updateGlossary(bankGlossary);
assertNotNull(updatedGlossary);
assertEquals(updatedGlossary.getGuid(), bankGlossary.getGuid());
// assertEquals(updatedGlossary.getCategories(), bankGlossary.getCategories());
// assertEquals(updatedGlossary.getTerms(), bankGlossary.getTerms());
// assertEquals(updatedGlossary, bankGlossary);
// There's some weirdness around the equality check of HashSet, hence the conversion to ArrayList
ArrayList<AtlasRelatedCategoryHeader> a = new ArrayList<>(updatedGlossary.getCategories());
ArrayList<AtlasRelatedCategoryHeader> b = new ArrayList<>(bankGlossary.getCategories());
assertEquals(a, b);
} catch (AtlasBaseException e) {
fail("Glossary fetch/update should've succeeded", e);
}
}
use of org.apache.atlas.model.glossary.relations.AtlasRelatedCategoryHeader in project atlas by apache.
the class GlossaryServiceTest method testGetGlossaryCategories.
@Test(dataProvider = "getGlossaryCategoriesProvider", groups = "Glossary.GET.postUpdate", dependsOnGroups = "Glossary.UPDATE")
public void testGetGlossaryCategories(int offset, int limit, int expected) {
String guid = bankGlossary.getGuid();
SortOrder sortOrder = SortOrder.ASCENDING;
try {
List<AtlasRelatedCategoryHeader> glossaryCategories = glossaryService.getGlossaryCategoriesHeaders(guid, offset, limit, sortOrder);
assertNotNull(glossaryCategories);
assertEquals(glossaryCategories.size(), expected);
} catch (AtlasBaseException e) {
fail("Glossary term fetching should've succeeded");
}
}
use of org.apache.atlas.model.glossary.relations.AtlasRelatedCategoryHeader in project atlas by apache.
the class GlossaryCategoryUtils method updateCategoryRelationships.
private void updateCategoryRelationships(AtlasGlossaryCategory storeObject, Collection<AtlasRelatedCategoryHeader> toUpdate) throws AtlasBaseException {
if (CollectionUtils.isNotEmpty(toUpdate)) {
for (AtlasRelatedCategoryHeader categoryHeader : toUpdate) {
if (DEBUG_ENABLED) {
LOG.debug("Updating child, category = {}, child = {}", storeObject.getName(), categoryHeader.getDisplayText());
}
AtlasRelationship childRelationship = relationshipStore.getById(categoryHeader.getRelationGuid());
updateRelationshipAttributes(childRelationship, categoryHeader);
relationshipStore.update(childRelationship);
}
}
}
use of org.apache.atlas.model.glossary.relations.AtlasRelatedCategoryHeader in project atlas by apache.
the class GlossaryCategoryUtils method processParentCategory.
private void processParentCategory(AtlasGlossaryCategory storeObject, AtlasGlossaryCategory updatedCategory, RelationshipOperation op, Map<String, AtlasGlossaryCategory> impactedCategories) throws AtlasBaseException {
AtlasRelatedCategoryHeader newParent = updatedCategory.getParentCategory();
AtlasRelatedCategoryHeader existingParent = storeObject.getParentCategory();
switch(op) {
case CREATE:
if (Objects.nonNull(newParent)) {
processNewParent(storeObject, newParent, impactedCategories);
}
break;
case UPDATE:
if (Objects.equals(newParent, existingParent)) {
if (DEBUG_ENABLED) {
LOG.debug("No change to parent");
}
break;
}
if (Objects.isNull(existingParent)) {
processNewParent(storeObject, newParent, impactedCategories);
} else if (Objects.isNull(newParent)) {
processParentRemoval(storeObject, updatedCategory, existingParent, impactedCategories);
} else {
if (DEBUG_ENABLED) {
LOG.debug("Updating category parent, category = {}, currParent = {}, newParent = {}", storeObject.getGuid(), existingParent.getDisplayText(), newParent.getDisplayText());
}
AtlasRelationship parentRelationship = relationshipStore.getById(existingParent.getRelationGuid());
if (existingParent.getCategoryGuid().equals(newParent.getCategoryGuid())) {
updateRelationshipAttributes(parentRelationship, newParent);
relationshipStore.update(parentRelationship);
} else {
// Delete link to existing parent and link to new parent
relationshipStore.deleteById(parentRelationship.getGuid(), true);
createRelationship(defineCategoryHierarchyLink(newParent, storeObject.getGuid()));
}
}
break;
case DELETE:
if (Objects.nonNull(existingParent)) {
processParentRemoval(storeObject, updatedCategory, existingParent, impactedCategories);
}
break;
}
}
Aggregations