Search in sources :

Example 1 with AtlasGlossary

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

the class AtlasGlossaryDTO method from.

@Override
public AtlasGlossary from(final AtlasEntity entity) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasGlossaryDTO.from()", entity);
    }
    Objects.requireNonNull(entity, "entity");
    AtlasGlossary ret = new AtlasGlossary();
    ret.setGuid(entity.getGuid());
    ret.setQualifiedName((String) entity.getAttribute("qualifiedName"));
    ret.setName((String) entity.getAttribute("name"));
    ret.setShortDescription((String) entity.getAttribute("shortDescription"));
    ret.setLongDescription((String) entity.getAttribute("longDescription"));
    ret.setLanguage((String) entity.getAttribute("language"));
    ret.setUsage((String) entity.getAttribute("usage"));
    ret.setAdditionalAttributes((Map) entity.getAttribute("additionalAttributes"));
    Object categoriesAttr = entity.getRelationshipAttribute("categories");
    Object termsAttr = entity.getRelationshipAttribute("terms");
    // Populate categories
    if (Objects.nonNull(categoriesAttr)) {
        LOG.debug("Processing categories");
        if (categoriesAttr instanceof Collection) {
            for (Object o : (Collection) categoriesAttr) {
                if (o instanceof AtlasRelatedObjectId) {
                    ret.addCategory(constructRelatedCategoryId((AtlasRelatedObjectId) o));
                }
            }
        }
    }
    // Populate terms
    if (Objects.nonNull(termsAttr)) {
        LOG.debug("Processing terms");
        if (termsAttr instanceof Collection) {
            for (Object o : (Collection) termsAttr) {
                if (o instanceof AtlasRelatedObjectId) {
                    ret.addTerm(constructRelatedTermId((AtlasRelatedObjectId) o));
                }
            }
        }
    }
    return ret;
}
Also used : AtlasGlossary(org.apache.atlas.model.glossary.AtlasGlossary) AtlasRelatedObjectId(org.apache.atlas.model.instance.AtlasRelatedObjectId) Collection(java.util.Collection)

Example 2 with AtlasGlossary

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

the class GlossaryService method getGlossaryTermsHeaders.

@GraphTransaction
public List<AtlasRelatedTermHeader> getGlossaryTermsHeaders(String glossaryGuid, int offset, int limit, SortOrder sortOrder) throws AtlasBaseException {
    if (Objects.isNull(glossaryGuid)) {
        throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "glossaryGuid is null/empty");
    }
    if (DEBUG_ENABLED) {
        LOG.debug("==> GlossaryService.getGlossaryTermsHeaders({}, {}, {}, {})", glossaryGuid, offset, limit, sortOrder);
    }
    AtlasGlossary glossary = getGlossary(glossaryGuid);
    List<AtlasRelatedTermHeader> ret;
    if (CollectionUtils.isNotEmpty(glossary.getTerms())) {
        List<AtlasRelatedTermHeader> terms = new ArrayList<>(glossary.getTerms());
        if (sortOrder != null) {
            terms.sort((o1, o2) -> sortOrder == SortOrder.ASCENDING ? o1.getDisplayText().compareTo(o2.getDisplayText()) : o2.getDisplayText().compareTo(o1.getDisplayText()));
        }
        ret = new PaginationHelper<>(terms, offset, limit).getPaginatedList();
    } else {
        ret = Collections.emptyList();
    }
    if (DEBUG_ENABLED) {
        LOG.debug("<== GlossaryService.getGlossaryTermsHeaders() : {}", ret);
    }
    return ret;
}
Also used : AtlasGlossary(org.apache.atlas.model.glossary.AtlasGlossary) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasRelatedTermHeader(org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader) ArrayList(java.util.ArrayList) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 3 with AtlasGlossary

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

the class GlossaryService method createCategory.

@GraphTransaction
public AtlasGlossaryCategory createCategory(AtlasGlossaryCategory glossaryCategory) throws AtlasBaseException {
    if (DEBUG_ENABLED) {
        LOG.debug("==> GlossaryService.createCategory({})", glossaryCategory);
    }
    if (Objects.isNull(glossaryCategory)) {
        throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "GlossaryCategory definition missing");
    }
    if (Objects.isNull(glossaryCategory.getAnchor())) {
        throw new AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ANCHOR);
    }
    if (StringUtils.isEmpty(glossaryCategory.getName())) {
        throw new AtlasBaseException(AtlasErrorCode.GLOSSARY_CATEGORY_QUALIFIED_NAME_CANT_BE_DERIVED);
    }
    if (isNameInvalid(glossaryCategory.getName())) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_DISPLAY_NAME);
    } else {
        // Derive the qualifiedName
        String anchorGlossaryGuid = glossaryCategory.getAnchor().getGlossaryGuid();
        AtlasGlossary glossary = dataAccess.load(getGlossarySkeleton(anchorGlossaryGuid));
        glossaryCategory.setQualifiedName(glossaryCategory.getName() + "@" + glossary.getQualifiedName());
        if (LOG.isDebugEnabled()) {
            LOG.debug("Derived qualifiedName = {}", glossaryCategory.getQualifiedName());
        }
    }
    // and the duplicate request comes in with old name
    if (categoryExists(glossaryCategory)) {
        throw new AtlasBaseException(AtlasErrorCode.GLOSSARY_CATEGORY_ALREADY_EXISTS, glossaryCategory.getQualifiedName());
    }
    AtlasGlossaryCategory storeObject = dataAccess.save(glossaryCategory);
    // Attempt relation creation and gather all impacted categories
    Map<String, AtlasGlossaryCategory> impactedCategories = glossaryCategoryUtils.processCategoryRelations(storeObject, glossaryCategory, GlossaryUtils.RelationshipOperation.CREATE);
    // Since the current category is also affected, we need to update qualifiedName and save again
    if (StringUtils.equals(glossaryCategory.getQualifiedName(), storeObject.getQualifiedName())) {
        storeObject = dataAccess.load(glossaryCategory);
    } else {
        glossaryCategory.setQualifiedName(storeObject.getQualifiedName());
        if (categoryExists(glossaryCategory)) {
            throw new AtlasBaseException(AtlasErrorCode.GLOSSARY_CATEGORY_ALREADY_EXISTS, glossaryCategory.getQualifiedName());
        }
        storeObject = dataAccess.save(glossaryCategory);
    }
    // Re save the categories in case any qualifiedName change has occurred
    dataAccess.save(impactedCategories.values());
    setInfoForRelations(storeObject);
    if (DEBUG_ENABLED) {
        LOG.debug("<== GlossaryService.createCategory() : {}", storeObject);
    }
    return storeObject;
}
Also used : AtlasGlossary(org.apache.atlas.model.glossary.AtlasGlossary) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasGlossaryCategory(org.apache.atlas.model.glossary.AtlasGlossaryCategory) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 4 with AtlasGlossary

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

the class GlossaryService method getGlossaryCategoriesHeaders.

@GraphTransaction
public List<AtlasRelatedCategoryHeader> getGlossaryCategoriesHeaders(String glossaryGuid, int offset, int limit, SortOrder sortOrder) throws AtlasBaseException {
    if (Objects.isNull(glossaryGuid)) {
        throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "glossaryGuid is null/empty");
    }
    if (DEBUG_ENABLED) {
        LOG.debug("==> GlossaryService.getGlossaryCategoriesHeaders({}, {}, {}, {})", glossaryGuid, offset, limit, sortOrder);
    }
    List<AtlasRelatedCategoryHeader> ret;
    AtlasGlossary glossary = getGlossary(glossaryGuid);
    if (CollectionUtils.isNotEmpty(glossary.getCategories())) {
        List<AtlasRelatedCategoryHeader> categories = new ArrayList<>(glossary.getCategories());
        if (sortOrder != null) {
            categories.sort((o1, o2) -> sortOrder == SortOrder.ASCENDING ? o1.getDisplayText().compareTo(o2.getDisplayText()) : o2.getDisplayText().compareTo(o1.getDisplayText()));
        }
        ret = new PaginationHelper<>(categories, offset, limit).getPaginatedList();
    } else {
        ret = Collections.emptyList();
    }
    if (DEBUG_ENABLED) {
        LOG.debug("<== GlossaryService.getGlossaryCategoriesHeaders() : {}", ret);
    }
    return ret;
}
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) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 5 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)

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 AtlasRelatedObjectId (org.apache.atlas.model.instance.AtlasRelatedObjectId)2 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1