Search in sources :

Example 1 with AtlasRelatedCategoryHeader

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

Example 2 with AtlasRelatedCategoryHeader

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);
    }
}
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 3 with AtlasRelatedCategoryHeader

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

Example 4 with AtlasRelatedCategoryHeader

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);
        }
    }
}
Also used : AtlasRelatedCategoryHeader(org.apache.atlas.model.glossary.relations.AtlasRelatedCategoryHeader) AtlasRelationship(org.apache.atlas.model.instance.AtlasRelationship)

Example 5 with AtlasRelatedCategoryHeader

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;
    }
}
Also used : AtlasRelatedCategoryHeader(org.apache.atlas.model.glossary.relations.AtlasRelatedCategoryHeader) AtlasRelationship(org.apache.atlas.model.instance.AtlasRelationship)

Aggregations

AtlasRelatedCategoryHeader (org.apache.atlas.model.glossary.relations.AtlasRelatedCategoryHeader)16 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)12 AtlasGlossaryCategory (org.apache.atlas.model.glossary.AtlasGlossaryCategory)7 AtlasGlossary (org.apache.atlas.model.glossary.AtlasGlossary)6 Test (org.testng.annotations.Test)6 ArrayList (java.util.ArrayList)5 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)5 AtlasRelatedTermHeader (org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader)3 HashMap (java.util.HashMap)2 List (java.util.List)2 SortOrder (org.apache.atlas.SortOrder)2 AtlasGlossaryHeader (org.apache.atlas.model.glossary.relations.AtlasGlossaryHeader)2 AtlasRelationship (org.apache.atlas.model.instance.AtlasRelationship)2 InputStream (java.io.InputStream)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1