Search in sources :

Example 21 with AtlasGlossary

use of org.apache.atlas.model.glossary.AtlasGlossary in project atlas by apache.

the class GlossaryServiceTest method testCreateGlossary.

@Test(groups = "Glossary.CREATE")
public void testCreateGlossary() {
    try {
        AtlasGlossary created = glossaryService.createGlossary(bankGlossary);
        bankGlossary.setGuid(created.getGuid());
        created = glossaryService.createGlossary(creditUnionGlossary);
        creditUnionGlossary.setGuid(created.getGuid());
    } catch (AtlasBaseException e) {
        fail("Glossary creation should've succeeded", e);
    }
    // Duplicate create calls should fail with 409 Conflict
    try {
        glossaryService.createGlossary(bankGlossary);
        fail("Glossary duplicate creation should've failed");
    } catch (AtlasBaseException e) {
        assertEquals(e.getAtlasErrorCode(), AtlasErrorCode.GLOSSARY_ALREADY_EXISTS);
    }
    try {
        glossaryService.createGlossary(creditUnionGlossary);
        fail("Glossary duplicate creation should've failed");
    } catch (AtlasBaseException e) {
        assertEquals(e.getAtlasErrorCode(), AtlasErrorCode.GLOSSARY_ALREADY_EXISTS);
    }
    try {
        List<AtlasRelatedCategoryHeader> glossaryCategories = glossaryService.getGlossaryCategoriesHeaders(bankGlossary.getGuid(), 0, 10, SortOrder.ASCENDING);
        assertNotNull(glossaryCategories);
        assertEquals(glossaryCategories.size(), 0);
        glossaryCategories = glossaryService.getGlossaryCategoriesHeaders(creditUnionGlossary.getGuid(), 0, 10, SortOrder.ASCENDING);
        assertNotNull(glossaryCategories);
        assertEquals(glossaryCategories.size(), 0);
    } catch (AtlasBaseException e) {
        fail("Get glossary categories calls should've succeeded", e);
    }
    try {
        List<AtlasRelatedTermHeader> glossaryCategories = glossaryService.getGlossaryTermsHeaders(bankGlossary.getGuid(), 0, 10, SortOrder.ASCENDING);
        assertNotNull(glossaryCategories);
        assertEquals(glossaryCategories.size(), 0);
        glossaryCategories = glossaryService.getGlossaryTermsHeaders(creditUnionGlossary.getGuid(), 0, 10, SortOrder.ASCENDING);
        assertNotNull(glossaryCategories);
        assertEquals(glossaryCategories.size(), 0);
    } catch (AtlasBaseException e) {
        fail("Get glossary categories calls should've succeeded", e);
    }
    // Glossary anchor
    AtlasGlossaryHeader glossaryId = new AtlasGlossaryHeader();
    glossaryId.setGlossaryGuid(bankGlossary.getGuid());
    // Create terms
    checkingAccount.setAnchor(glossaryId);
    savingsAccount.setAnchor(glossaryId);
    fixedRateMortgage.setAnchor(glossaryId);
    adjustableRateMortgage.setAnchor(glossaryId);
    // Create glossary categories
    accountCategory.setAnchor(glossaryId);
    customerCategory.setAnchor(glossaryId);
    mortgageCategory.setAnchor(glossaryId);
}
Also used : AtlasGlossary(org.apache.atlas.model.glossary.AtlasGlossary) AtlasGlossaryHeader(org.apache.atlas.model.glossary.relations.AtlasGlossaryHeader) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasRelatedTermHeader(org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader) AtlasRelatedCategoryHeader(org.apache.atlas.model.glossary.relations.AtlasRelatedCategoryHeader) Test(org.testng.annotations.Test)

Example 22 with AtlasGlossary

use of org.apache.atlas.model.glossary.AtlasGlossary in project atlas by apache.

the class GlossaryCategoryUtils method processParentRemoval.

private void processParentRemoval(AtlasGlossaryCategory storeObject, AtlasGlossaryCategory updatedCategory, AtlasRelatedCategoryHeader existingParent, Map<String, AtlasGlossaryCategory> impactedCategories) throws AtlasBaseException {
    if (DEBUG_ENABLED) {
        LOG.debug("Removing category parent, category = {}, parent = {}", storeObject.getGuid(), existingParent.getDisplayText());
    }
    relationshipStore.deleteById(existingParent.getRelationGuid(), true);
    // Parent deleted, qualifiedName needs recomputation
    // Derive the qualifiedName of the Glossary
    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());
    }
    updateChildCategories(storeObject, storeObject.getChildrenCategories(), impactedCategories, false);
}
Also used : AtlasGlossary(org.apache.atlas.model.glossary.AtlasGlossary)

Example 23 with AtlasGlossary

use of org.apache.atlas.model.glossary.AtlasGlossary in project atlas by apache.

the class GlossaryService method getGlossary.

/**
 * Get specific glossary
 *
 * @param glossaryGuid unique identifier
 * @return Glossary corresponding to specified glossaryGuid
 * @throws AtlasBaseException
 */
@GraphTransaction
public AtlasGlossary getGlossary(String glossaryGuid) throws AtlasBaseException {
    if (DEBUG_ENABLED) {
        LOG.debug("==> GlossaryService.getGlossary({})", glossaryGuid);
    }
    if (Objects.isNull(glossaryGuid)) {
        throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "glossaryGuid is null/empty");
    }
    AtlasGlossary atlasGlossary = getGlossarySkeleton(glossaryGuid);
    AtlasGlossary ret = dataAccess.load(atlasGlossary);
    setInfoForRelations(ret);
    if (DEBUG_ENABLED) {
        LOG.debug("<== GlossaryService.getGlossary() : {}", ret);
    }
    return ret;
}
Also used : AtlasGlossary(org.apache.atlas.model.glossary.AtlasGlossary) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 24 with AtlasGlossary

use of org.apache.atlas.model.glossary.AtlasGlossary in project atlas by apache.

the class GlossaryService method getGlossaries.

/**
 * List all glossaries
 *
 * @param limit     page size - no paging by default
 * @param offset    offset for pagination
 * @param sortOrder ASC (default) or DESC
 * @return List of all glossaries
 * @throws AtlasBaseException
 */
@GraphTransaction
public List<AtlasGlossary> getGlossaries(int limit, int offset, SortOrder sortOrder) throws AtlasBaseException {
    if (DEBUG_ENABLED) {
        LOG.debug("==> GlossaryService.getGlossaries({}, {}, {})", limit, offset, sortOrder);
    }
    List<String> glossaryGuids = AtlasGraphUtilsV2.findEntityGUIDsByType(GlossaryUtils.ATLAS_GLOSSARY_TYPENAME, sortOrder);
    PaginationHelper paginationHelper = new PaginationHelper<>(glossaryGuids, offset, limit);
    List<AtlasGlossary> ret;
    List<String> guidsToLoad = paginationHelper.getPaginatedList();
    AtlasEntity.AtlasEntitiesWithExtInfo glossaryEntities;
    if (CollectionUtils.isNotEmpty(guidsToLoad)) {
        glossaryEntities = dataAccess.getAtlasEntityStore().getByIds(guidsToLoad, true, false);
        ret = new ArrayList<>();
        for (AtlasEntity glossaryEntity : glossaryEntities.getEntities()) {
            AtlasGlossary glossary = glossaryDTO.from(glossaryEntity);
            ret.add(glossary);
        }
    } else {
        ret = Collections.emptyList();
    }
    if (DEBUG_ENABLED) {
        LOG.debug("<== GlossaryService.getGlossaries() : {}", ret);
    }
    return ret;
}
Also used : AtlasGlossary(org.apache.atlas.model.glossary.AtlasGlossary) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 25 with AtlasGlossary

use of org.apache.atlas.model.glossary.AtlasGlossary in project atlas by apache.

the class GlossaryService method updateGlossary.

@GraphTransaction
public AtlasGlossary updateGlossary(AtlasGlossary atlasGlossary) throws AtlasBaseException {
    if (DEBUG_ENABLED) {
        LOG.debug("==> GlossaryService.updateGlossary({})", atlasGlossary);
    }
    if (Objects.isNull(atlasGlossary)) {
        throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "Glossary is null/empty");
    }
    if (StringUtils.isEmpty(atlasGlossary.getName())) {
        throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "DisplayName can't be null/empty");
    }
    if (isNameInvalid(atlasGlossary.getName())) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_DISPLAY_NAME);
    }
    AtlasGlossary storeObject = dataAccess.load(atlasGlossary);
    if (!storeObject.equals(atlasGlossary)) {
        atlasGlossary.setGuid(storeObject.getGuid());
        atlasGlossary.setQualifiedName(storeObject.getQualifiedName());
        storeObject = dataAccess.save(atlasGlossary);
        setInfoForRelations(storeObject);
    }
    if (DEBUG_ENABLED) {
        LOG.debug("<== GlossaryService.updateGlossary() : {}", storeObject);
    }
    return storeObject;
}
Also used : AtlasGlossary(org.apache.atlas.model.glossary.AtlasGlossary) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

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