Search in sources :

Example 1 with AtlasRelatedTermHeader

use of org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader in project atlas by apache.

the class AbstractGlossaryDTO method constructRelatedTermId.

protected AtlasRelatedTermHeader constructRelatedTermId(AtlasRelatedObjectId relatedObjectId) {
    AtlasRelatedTermHeader ret = new AtlasRelatedTermHeader();
    ret.setTermGuid(relatedObjectId.getGuid());
    ret.setRelationGuid(relatedObjectId.getRelationshipGuid());
    ret.setDisplayText(relatedObjectId.getDisplayText());
    AtlasStruct relationshipAttributes = relatedObjectId.getRelationshipAttributes();
    if (relationshipAttributes != null) {
        ret.setDescription((String) relationshipAttributes.getAttribute("description"));
        ret.setExpression((String) relationshipAttributes.getAttribute("expression"));
        ret.setSource((String) relationshipAttributes.getAttribute("source"));
        ret.setSteward((String) relationshipAttributes.getAttribute("steward"));
        Object status = relationshipAttributes.getAttribute("status");
        if (status instanceof String) {
            ret.setStatus(AtlasTermRelationshipStatus.valueOf((String) status));
        } else if (status instanceof AtlasTermRelationshipStatus) {
            ret.setStatus((AtlasTermRelationshipStatus) status);
        }
    }
    return ret;
}
Also used : AtlasStruct(org.apache.atlas.model.instance.AtlasStruct) AtlasRelatedTermHeader(org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader) AbstractDataTransferObject(org.apache.atlas.repository.ogm.AbstractDataTransferObject) AtlasBaseModelObject(org.apache.atlas.model.AtlasBaseModelObject) AtlasTermRelationshipStatus(org.apache.atlas.model.glossary.enums.AtlasTermRelationshipStatus)

Example 2 with AtlasRelatedTermHeader

use of org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader in project atlas by apache.

the class GlossaryServiceTest method testAddTermsToCategory.

@Test(groups = "Glossary.UPDATE", dependsOnGroups = "Glossary.CREATE")
public void testAddTermsToCategory() {
    assertNotNull(accountCategory);
    try {
        accountCategory = glossaryService.getCategory(accountCategory.getGuid());
        assertTrue(CollectionUtils.isEmpty(accountCategory.getTerms()));
    } catch (AtlasBaseException e) {
        fail("Fetch of accountCategory should've succeeded", e);
    }
    for (AtlasGlossaryTerm term : Arrays.asList(checkingAccount, savingsAccount)) {
        try {
            AtlasGlossaryTerm termEntry = glossaryService.getTerm(term.getGuid());
            AtlasRelatedTermHeader relatedTermId = new AtlasRelatedTermHeader();
            relatedTermId.setTermGuid(termEntry.getGuid());
            relatedTermId.setStatus(AtlasTermRelationshipStatus.ACTIVE);
            relatedTermId.setSteward("UT");
            relatedTermId.setSource("UT");
            relatedTermId.setExpression("N/A");
            relatedTermId.setDescription("Categorization under account category");
            accountCategory.addTerm(relatedTermId);
        } catch (AtlasBaseException e) {
            fail("Term fetching should've succeeded", e);
        }
    }
    try {
        AtlasGlossaryCategory updated = glossaryService.updateCategory(accountCategory);
        assertNotNull(updated.getTerms());
        assertEquals(updated.getTerms().size(), 2);
        accountCategory = updated;
    } catch (AtlasBaseException e) {
        fail("Glossary category update should've succeeded", e);
    }
    assertNotNull(accountCategory);
    try {
        accountCategory = glossaryService.getCategory(accountCategory.getGuid());
    } catch (AtlasBaseException e) {
        fail("Fetch of accountCategory should've succeeded", e);
    }
    for (AtlasGlossaryTerm term : Arrays.asList(fixedRateMortgage, adjustableRateMortgage)) {
        try {
            AtlasGlossaryTerm termEntry = glossaryService.getTerm(term.getGuid());
            AtlasRelatedTermHeader relatedTermId = new AtlasRelatedTermHeader();
            relatedTermId.setTermGuid(termEntry.getGuid());
            relatedTermId.setStatus(AtlasTermRelationshipStatus.ACTIVE);
            relatedTermId.setSteward("UT");
            relatedTermId.setSource("UT");
            relatedTermId.setExpression("N/A");
            relatedTermId.setDescription("Categorization under mortgage category");
            mortgageCategory.addTerm(relatedTermId);
        } catch (AtlasBaseException e) {
            fail("Term fetching should've succeeded", e);
        }
    }
    try {
        AtlasGlossaryCategory updated = glossaryService.updateCategory(mortgageCategory);
        assertNotNull(updated.getTerms());
        assertEquals(updated.getTerms().size(), 2);
        mortgageCategory = updated;
    } catch (AtlasBaseException e) {
        fail("Glossary category update should've succeeded", e);
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasRelatedTermHeader(org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader) AtlasGlossaryTerm(org.apache.atlas.model.glossary.AtlasGlossaryTerm) AtlasGlossaryCategory(org.apache.atlas.model.glossary.AtlasGlossaryCategory) Test(org.testng.annotations.Test)

Example 3 with AtlasRelatedTermHeader

use of org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader in project atlas by apache.

the class GlossaryServiceTest method testGetCategoryTerms.

@Test(dataProvider = "getCategoryTermsProvider", dependsOnGroups = "Glossary.CREATE")
public void testGetCategoryTerms(int offset, int limit, int expected) {
    for (AtlasGlossaryCategory c : Arrays.asList(accountCategory, mortgageCategory)) {
        try {
            List<AtlasRelatedTermHeader> categoryTerms = glossaryService.getCategoryTerms(c.getGuid(), offset, limit, SortOrder.ASCENDING);
            assertNotNull(categoryTerms);
            assertEquals(categoryTerms.size(), expected);
        } catch (AtlasBaseException e) {
            fail("Category term retrieval should've been a success", e);
        }
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasRelatedTermHeader(org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader) AtlasGlossaryCategory(org.apache.atlas.model.glossary.AtlasGlossaryCategory) Test(org.testng.annotations.Test)

Example 4 with AtlasRelatedTermHeader

use of org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader in project atlas by apache.

the class GlossaryServiceTest method testGetGlossaryTerms.

@Test(dataProvider = "getGlossaryTermsProvider", groups = "Glossary.GET.postUpdate", dependsOnGroups = "Glossary.UPDATE")
public void testGetGlossaryTerms(int offset, int limit, int expected) {
    String guid = bankGlossary.getGuid();
    SortOrder sortOrder = SortOrder.ASCENDING;
    try {
        List<AtlasRelatedTermHeader> glossaryTerms = glossaryService.getGlossaryTermsHeaders(guid, offset, limit, sortOrder);
        assertNotNull(glossaryTerms);
        assertEquals(glossaryTerms.size(), expected);
    } catch (AtlasBaseException e) {
        fail("Glossary term fetching should've succeeded", e);
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasRelatedTermHeader(org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader) SortOrder(org.apache.atlas.SortOrder) Test(org.testng.annotations.Test)

Example 5 with AtlasRelatedTermHeader

use of org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader in project atlas by apache.

the class GlossaryCategoryUtils method updateTermCategorizationRelationships.

private void updateTermCategorizationRelationships(AtlasGlossaryCategory storeObject, Collection<AtlasRelatedTermHeader> terms) throws AtlasBaseException {
    if (CollectionUtils.isNotEmpty(terms)) {
        for (AtlasRelatedTermHeader term : terms) {
            if (DEBUG_ENABLED) {
                LOG.debug("Updating term relation with category = {}, term = {}", storeObject.getName(), term.getDisplayText());
            }
            AtlasRelationship relationship = relationshipStore.getById(term.getRelationGuid());
            updateRelationshipAttributes(relationship, term);
            relationshipStore.update(relationship);
        }
    }
}
Also used : AtlasRelatedTermHeader(org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader) AtlasRelationship(org.apache.atlas.model.instance.AtlasRelationship)

Aggregations

AtlasRelatedTermHeader (org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader)19 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)12 Test (org.testng.annotations.Test)8 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)4 AtlasGlossaryTerm (org.apache.atlas.model.glossary.AtlasGlossaryTerm)4 ArrayList (java.util.ArrayList)3 AtlasGlossary (org.apache.atlas.model.glossary.AtlasGlossary)3 AtlasGlossaryCategory (org.apache.atlas.model.glossary.AtlasGlossaryCategory)3 AtlasGlossaryHeader (org.apache.atlas.model.glossary.relations.AtlasGlossaryHeader)3 HashMap (java.util.HashMap)2 Set (java.util.Set)2 AtlasRelatedCategoryHeader (org.apache.atlas.model.glossary.relations.AtlasRelatedCategoryHeader)2 AtlasRelationship (org.apache.atlas.model.instance.AtlasRelationship)2 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)2 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 SortOrder (org.apache.atlas.SortOrder)1 AtlasBaseModelObject (org.apache.atlas.model.AtlasBaseModelObject)1 AtlasTermRelationshipStatus (org.apache.atlas.model.glossary.enums.AtlasTermRelationshipStatus)1