use of org.apache.atlas.model.glossary.AtlasGlossary in project atlas by apache.
the class GlossaryClientV2IT method testGetGlossaryByGuid.
@Test(dependsOnMethods = "testCreateGlossary")
public void testGetGlossaryByGuid() throws Exception {
healthCareGlossary = createAndGetGlossary("HealthCare");
AtlasGlossary atlasGlossaryByGuid = atlasClientV2.getGlossaryByGuid(healthCareGlossary.getGuid());
assertNotNull(atlasGlossaryByGuid);
assertEquals(healthCareGlossary.getGuid(), atlasGlossaryByGuid.getGuid());
}
use of org.apache.atlas.model.glossary.AtlasGlossary in project atlas by apache.
the class GlossaryClientV2IT method testCreateGlossaryTerms.
@Test(dependsOnMethods = "testGetGlossaryByGuid")
public void testCreateGlossaryTerms() throws Exception {
List<AtlasGlossaryTerm> list = new ArrayList<>();
int index = 0;
List<AtlasGlossary> glossaries = atlasClientV2.getAllGlossaries("ASC", 5, 0);
List<AtlasGlossary> glossaryList = mapper.convertValue(glossaries, new TypeReference<List<AtlasGlossary>>() {
});
for (AtlasGlossary glossary : glossaryList) {
AtlasGlossaryTerm term = new AtlasGlossaryTerm();
AtlasGlossaryHeader header = new AtlasGlossaryHeader();
header.setGlossaryGuid(glossary.getGuid());
header.setDisplayText(glossary.getName());
term.setAnchor(header);
term.setName("termName" + index);
list.add(term);
index++;
}
List<AtlasGlossaryTerm> termList = atlasClientV2.createGlossaryTerms(list);
assertNotNull(termList);
assertEquals(termList.size(), 3);
}
use of org.apache.atlas.model.glossary.AtlasGlossary in project atlas by apache.
the class GlossaryServiceTest method setupSampleGlossary.
@BeforeClass
public void setupSampleGlossary() {
try {
TestLoadModelUtils.loadAllModels("0000-Area0", typeDefStore, typeRegistry);
} catch (AtlasBaseException | IOException e) {
throw new SkipException("SubjectArea model loading failed");
}
try {
AtlasClassificationDef classificationDef = new AtlasClassificationDef("TestClassification", "Test only classification");
AtlasTypesDef typesDef = new AtlasTypesDef();
typesDef.setClassificationDefs(Arrays.asList(classificationDef));
typeDefStore.createTypesDef(typesDef);
} catch (AtlasBaseException e) {
throw new SkipException("Test classification creation failed");
}
// Glossary
bankGlossary = new AtlasGlossary();
bankGlossary.setQualifiedName("testBankingGlossary");
bankGlossary.setName("Banking glossary");
bankGlossary.setShortDescription("Short description");
bankGlossary.setLongDescription("Long description");
bankGlossary.setUsage("N/A");
bankGlossary.setLanguage("en-US");
creditUnionGlossary = new AtlasGlossary();
creditUnionGlossary.setQualifiedName("testCreditUnionGlossary");
creditUnionGlossary.setName("Credit union glossary");
creditUnionGlossary.setShortDescription("Short description");
creditUnionGlossary.setLongDescription("Long description");
creditUnionGlossary.setUsage("N/A");
creditUnionGlossary.setLanguage("en-US");
// Category
accountCategory = new AtlasGlossaryCategory();
accountCategory.setName("Account categorization");
accountCategory.setShortDescription("Short description");
accountCategory.setLongDescription("Long description");
customerCategory = new AtlasGlossaryCategory();
customerCategory.setQualifiedName("customer@testBankingGlossary");
customerCategory.setName("Customer category");
customerCategory.setShortDescription("Short description");
customerCategory.setLongDescription("Long description");
mortgageCategory = new AtlasGlossaryCategory();
mortgageCategory.setName("Mortgage categorization");
mortgageCategory.setShortDescription("Short description");
mortgageCategory.setLongDescription("Long description");
// Terms
checkingAccount = new AtlasGlossaryTerm();
checkingAccount.setName("A checking account");
checkingAccount.setShortDescription("Short description");
checkingAccount.setLongDescription("Long description");
checkingAccount.setAbbreviation("CHK");
checkingAccount.setExamples(Arrays.asList("Personal", "Joint"));
checkingAccount.setUsage("N/A");
savingsAccount = new AtlasGlossaryTerm();
savingsAccount.setQualifiedName("sav_acc@testBankingGlossary");
savingsAccount.setName("A savings account");
savingsAccount.setShortDescription("Short description");
savingsAccount.setLongDescription("Long description");
savingsAccount.setAbbreviation("SAV");
savingsAccount.setExamples(Arrays.asList("Personal", "Joint"));
savingsAccount.setUsage("N/A");
fixedRateMortgage = new AtlasGlossaryTerm();
fixedRateMortgage.setName("Conventional mortgage");
fixedRateMortgage.setShortDescription("Short description");
fixedRateMortgage.setLongDescription("Long description");
fixedRateMortgage.setAbbreviation("FMTG");
fixedRateMortgage.setExamples(Arrays.asList("15-yr", "30-yr"));
fixedRateMortgage.setUsage("N/A");
adjustableRateMortgage = new AtlasGlossaryTerm();
adjustableRateMortgage.setQualifiedName("arm_mtg@testBankingGlossary");
adjustableRateMortgage.setName("ARM loans");
adjustableRateMortgage.setShortDescription("Short description");
adjustableRateMortgage.setLongDescription("Long description");
adjustableRateMortgage.setAbbreviation("ARMTG");
adjustableRateMortgage.setExamples(Arrays.asList("5/1", "7/1", "10/1"));
adjustableRateMortgage.setUsage("N/A");
}
use of org.apache.atlas.model.glossary.AtlasGlossary 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.AtlasGlossary in project atlas by apache.
the class GlossaryCategoryUtils method processCategoryAnchor.
private void processCategoryAnchor(AtlasGlossaryCategory storeObject, AtlasGlossaryCategory updatedCategory, RelationshipOperation op, Map<String, AtlasGlossaryCategory> impactedCategories) throws AtlasBaseException {
if (Objects.isNull(updatedCategory.getAnchor()) && op != RelationshipOperation.DELETE) {
throw new AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ANCHOR);
}
AtlasGlossaryHeader existingAnchor = storeObject.getAnchor();
AtlasGlossaryHeader updatedCategoryAnchor = updatedCategory.getAnchor();
switch(op) {
case CREATE:
if (StringUtils.isEmpty(updatedCategoryAnchor.getGlossaryGuid())) {
throw new AtlasBaseException(AtlasErrorCode.INVALID_NEW_ANCHOR_GUID);
} else {
if (DEBUG_ENABLED) {
LOG.debug("Creating new category anchor, category = {}, glossary = {}", storeObject.getGuid(), updatedCategory.getAnchor().getGlossaryGuid());
}
String anchorGlossaryGuid = updatedCategory.getAnchor().getGlossaryGuid();
createRelationship(defineCategoryAnchorRelation(anchorGlossaryGuid, storeObject.getGuid()));
}
break;
case UPDATE:
if (!Objects.equals(existingAnchor, updatedCategoryAnchor)) {
if (Objects.isNull(updatedCategory.getAnchor().getGlossaryGuid())) {
throw new AtlasBaseException(AtlasErrorCode.INVALID_NEW_ANCHOR_GUID);
}
if (DEBUG_ENABLED) {
LOG.debug("Updating category anchor, currAnchor = {}, newAnchor = {} and category = {}", storeObject.getAnchor().getGlossaryGuid(), updatedCategory.getAnchor().getGlossaryGuid(), storeObject.getGuid());
}
relationshipStore.deleteById(storeObject.getAnchor().getRelationGuid(), true);
// Derive the qualifiedName when anchor changes
String anchorGlossaryGuid = updatedCategory.getAnchor().getGlossaryGuid();
AtlasGlossary glossary = dataAccess.load(getGlossarySkeleton(anchorGlossaryGuid));
storeObject.setQualifiedName(storeObject.getName() + "@" + glossary.getQualifiedName());
if (LOG.isDebugEnabled()) {
LOG.debug("Derived qualifiedName = {}", storeObject.getQualifiedName());
}
createRelationship(defineCategoryAnchorRelation(updatedCategory.getAnchor().getGlossaryGuid(), storeObject.getGuid()));
// Anchor changed, qualifiedName of children needs an update
updateChildCategories(storeObject, storeObject.getChildrenCategories(), impactedCategories, false);
}
break;
case DELETE:
if (Objects.nonNull(storeObject.getAnchor())) {
if (DEBUG_ENABLED) {
LOG.debug("Deleting category anchor");
}
relationshipStore.deleteById(storeObject.getAnchor().getRelationGuid(), true);
}
break;
}
}
Aggregations