Search in sources :

Example 1 with AtlasGlossaryHeader

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

the class GlossaryExample method createGlossaryTerm.

public void createGlossaryTerm() throws Exception {
    if (empSalaryTerm != null) {
        SampleApp.log("EmpSalaryTerm: term already exists");
        return;
    }
    AtlasGlossaryHeader glossary = new AtlasGlossaryHeader();
    AtlasGlossaryTerm term = new AtlasGlossaryTerm();
    glossary.setGlossaryGuid(empGlossary.getGuid());
    glossary.setDisplayText(empGlossary.getName());
    term.setAnchor(glossary);
    term.setName("EmpSalaryTerm");
    empSalaryTerm = client.createGlossaryTerm(term);
    if (empSalaryTerm != null) {
        SampleApp.log("Created term for Employee Salary: " + empSalaryTerm);
    }
}
Also used : AtlasGlossaryHeader(org.apache.atlas.model.glossary.relations.AtlasGlossaryHeader) AtlasGlossaryTerm(org.apache.atlas.model.glossary.AtlasGlossaryTerm)

Example 2 with AtlasGlossaryHeader

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

the class GlossaryClientV2IT method testCreateGlossaryCategories.

@Test(dependsOnMethods = "testCreateGlossaryCategory")
public void testCreateGlossaryCategories() throws Exception {
    List<AtlasGlossaryCategory> glossaryCategories = new ArrayList<>();
    AtlasGlossaryCategory category1 = new AtlasGlossaryCategory();
    AtlasGlossaryHeader header1 = new AtlasGlossaryHeader();
    header1.setGlossaryGuid(healthCareGlossary.getGuid());
    header1.setDisplayText(healthCareGlossary.getName());
    category1.setAnchor(header1);
    category1.setName("category1ForEducation");
    glossaryCategories.add(category1);
    // Setting different category
    AtlasGlossaryCategory category2 = new AtlasGlossaryCategory();
    category2.setAnchor(header1);
    category2.setName("category2ForEducation");
    glossaryCategories.add(category2);
    List<AtlasGlossaryCategory> list = atlasClientV2.createGlossaryCategories(glossaryCategories);
    assertNotNull(list);
    assertEquals(list.size(), 2);
}
Also used : AtlasGlossaryHeader(org.apache.atlas.model.glossary.relations.AtlasGlossaryHeader) ArrayList(java.util.ArrayList) AtlasGlossaryCategory(org.apache.atlas.model.glossary.AtlasGlossaryCategory) Test(org.testng.annotations.Test)

Example 3 with AtlasGlossaryHeader

use of org.apache.atlas.model.glossary.relations.AtlasGlossaryHeader 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 4 with AtlasGlossaryHeader

use of org.apache.atlas.model.glossary.relations.AtlasGlossaryHeader 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)

Example 5 with AtlasGlossaryHeader

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

the class GlossaryTermUtils method populateGlossaryTermObject.

protected AtlasGlossaryTerm populateGlossaryTermObject(List<String> failedTermMsgList, String[] record, String glossaryGuid, boolean populateRelations) {
    int length = record.length;
    int i = INDEX_FOR_TERM_AT_RECORD;
    AtlasGlossaryTerm ret = new AtlasGlossaryTerm();
    if (length > i) {
        ret.setName(record[i]);
    }
    if (StringUtils.isBlank(ret.getName())) {
        if (!populateRelations) {
            failedTermMsgList.add("The TermName is blank for provided record: " + Arrays.toString(record));
        }
    } else {
        ret.setAnchor(new AtlasGlossaryHeader(glossaryGuid));
        ret.setShortDescription((length > ++i) ? record[i] : null);
        ret.setLongDescription((length > ++i) ? record[i] : null);
        ret.setExamples((length > ++i) ? (List<String>) getListValue(record[i]) : null);
        ret.setAbbreviation((length > ++i) ? record[i] : null);
        ret.setUsage((length > ++i) ? record[i] : null);
        ret.setAdditionalAttributes(((length > ++i) ? (Map<String, Object>) getMapValue(record[i], failedTermMsgList, populateRelations) : null));
        if (populateRelations) {
            ret.setTranslationTerms((length > ++i) ? (Set<AtlasRelatedTermHeader>) getAtlasRelatedTermHeaderSet(record[i], ret.getName(), record[INDEX_FOR_GLOSSARY_AT_RECORD], failedTermMsgList) : null);
            ret.setValidValuesFor((length > ++i) ? (Set<AtlasRelatedTermHeader>) getAtlasRelatedTermHeaderSet(record[i], ret.getName(), record[INDEX_FOR_GLOSSARY_AT_RECORD], failedTermMsgList) : null);
            ret.setSynonyms((length > ++i) ? (Set<AtlasRelatedTermHeader>) getAtlasRelatedTermHeaderSet(record[i], ret.getName(), record[INDEX_FOR_GLOSSARY_AT_RECORD], failedTermMsgList) : null);
            ret.setReplacedBy((length > ++i) ? (Set<AtlasRelatedTermHeader>) getAtlasRelatedTermHeaderSet(record[i], ret.getName(), record[INDEX_FOR_GLOSSARY_AT_RECORD], failedTermMsgList) : null);
            ret.setValidValues((length > ++i) ? (Set<AtlasRelatedTermHeader>) getAtlasRelatedTermHeaderSet(record[i], ret.getName(), record[INDEX_FOR_GLOSSARY_AT_RECORD], failedTermMsgList) : null);
            ret.setReplacementTerms((length > ++i) ? (Set<AtlasRelatedTermHeader>) getAtlasRelatedTermHeaderSet(record[i], ret.getName(), record[INDEX_FOR_GLOSSARY_AT_RECORD], failedTermMsgList) : null);
            ret.setSeeAlso((length > ++i) ? (Set<AtlasRelatedTermHeader>) getAtlasRelatedTermHeaderSet(record[i], ret.getName(), record[INDEX_FOR_GLOSSARY_AT_RECORD], failedTermMsgList) : null);
            ret.setTranslatedTerms((length > ++i) ? (Set<AtlasRelatedTermHeader>) getAtlasRelatedTermHeaderSet(record[i], ret.getName(), record[INDEX_FOR_GLOSSARY_AT_RECORD], failedTermMsgList) : null);
            ret.setIsA((length > ++i) ? (Set<AtlasRelatedTermHeader>) getAtlasRelatedTermHeaderSet(record[i], ret.getName(), record[INDEX_FOR_GLOSSARY_AT_RECORD], failedTermMsgList) : null);
            ret.setAntonyms((length > ++i) ? (Set<AtlasRelatedTermHeader>) getAtlasRelatedTermHeaderSet(record[i], ret.getName(), record[INDEX_FOR_GLOSSARY_AT_RECORD], failedTermMsgList) : null);
            ret.setClassifies((length > ++i) ? (Set<AtlasRelatedTermHeader>) getAtlasRelatedTermHeaderSet(record[i], ret.getName(), record[INDEX_FOR_GLOSSARY_AT_RECORD], failedTermMsgList) : null);
            ret.setPreferredToTerms((length > ++i) ? (Set<AtlasRelatedTermHeader>) getAtlasRelatedTermHeaderSet(record[i], ret.getName(), record[INDEX_FOR_GLOSSARY_AT_RECORD], failedTermMsgList) : null);
            ret.setPreferredTerms((length > ++i) ? (Set<AtlasRelatedTermHeader>) getAtlasRelatedTermHeaderSet(record[i], ret.getName(), record[INDEX_FOR_GLOSSARY_AT_RECORD], failedTermMsgList) : null);
        }
    }
    return ret;
}
Also used : AtlasGlossaryHeader(org.apache.atlas.model.glossary.relations.AtlasGlossaryHeader) HashSet(java.util.HashSet) Set(java.util.Set) AtlasGlossaryTerm(org.apache.atlas.model.glossary.AtlasGlossaryTerm) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

AtlasGlossaryHeader (org.apache.atlas.model.glossary.relations.AtlasGlossaryHeader)16 Test (org.testng.annotations.Test)8 AtlasGlossaryTerm (org.apache.atlas.model.glossary.AtlasGlossaryTerm)7 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)6 AtlasGlossary (org.apache.atlas.model.glossary.AtlasGlossary)5 ArrayList (java.util.ArrayList)3 AtlasGlossaryCategory (org.apache.atlas.model.glossary.AtlasGlossaryCategory)3 AtlasRelatedTermHeader (org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader)3 List (java.util.List)2 AtlasRelatedCategoryHeader (org.apache.atlas.model.glossary.relations.AtlasRelatedCategoryHeader)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1