Search in sources :

Example 6 with AtlasGlossary

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());
}
Also used : AtlasGlossary(org.apache.atlas.model.glossary.AtlasGlossary) Test(org.testng.annotations.Test)

Example 7 with AtlasGlossary

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);
}
Also used : AtlasGlossary(org.apache.atlas.model.glossary.AtlasGlossary) AtlasGlossaryHeader(org.apache.atlas.model.glossary.relations.AtlasGlossaryHeader) AtlasGlossaryTerm(org.apache.atlas.model.glossary.AtlasGlossaryTerm) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.testng.annotations.Test)

Example 8 with AtlasGlossary

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");
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasGlossary(org.apache.atlas.model.glossary.AtlasGlossary) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasGlossaryTerm(org.apache.atlas.model.glossary.AtlasGlossaryTerm) IOException(java.io.IOException) SkipException(org.testng.SkipException) AtlasGlossaryCategory(org.apache.atlas.model.glossary.AtlasGlossaryCategory) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) BeforeClass(org.testng.annotations.BeforeClass)

Example 9 with AtlasGlossary

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);
    }
}
Also used : AtlasGlossary(org.apache.atlas.model.glossary.AtlasGlossary) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) ArrayList(java.util.ArrayList) AtlasRelatedCategoryHeader(org.apache.atlas.model.glossary.relations.AtlasRelatedCategoryHeader) Test(org.testng.annotations.Test)

Example 10 with AtlasGlossary

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;
    }
}
Also used : AtlasGlossary(org.apache.atlas.model.glossary.AtlasGlossary) AtlasGlossaryHeader(org.apache.atlas.model.glossary.relations.AtlasGlossaryHeader) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException)

Aggregations

AtlasGlossary (org.apache.atlas.model.glossary.AtlasGlossary)29 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)15 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)8 AtlasRelatedCategoryHeader (org.apache.atlas.model.glossary.relations.AtlasRelatedCategoryHeader)6 Test (org.testng.annotations.Test)6 ArrayList (java.util.ArrayList)5 AtlasGlossaryHeader (org.apache.atlas.model.glossary.relations.AtlasGlossaryHeader)5 AtlasGlossaryCategory (org.apache.atlas.model.glossary.AtlasGlossaryCategory)4 AtlasGlossaryTerm (org.apache.atlas.model.glossary.AtlasGlossaryTerm)4 AtlasRelatedTermHeader (org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader)4 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Path (javax.ws.rs.Path)2 Timed (org.apache.atlas.annotation.Timed)2 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)2 AtlasRelatedObjectId (org.apache.atlas.model.instance.AtlasRelatedObjectId)2 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)2 IOException (java.io.IOException)1