Search in sources :

Example 1 with AtlasGlossaryTerm

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

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

the class ExportTypeProcessor method addTerms.

private void addTerms(AtlasEntity entity, ExportService.ExportContext context) {
    Object relAttrMeanings = entity.getRelationshipAttribute(RELATIONSHIP_ATTR_MEANINGS);
    if (relAttrMeanings == null || !(relAttrMeanings instanceof List)) {
        return;
    }
    List list = (List) relAttrMeanings;
    if (CollectionUtils.isEmpty(list)) {
        return;
    }
    for (Object objectId : list) {
        if (objectId instanceof AtlasRelatedObjectId) {
            AtlasRelatedObjectId termObjectId = (AtlasRelatedObjectId) objectId;
            try {
                AtlasGlossaryTerm term = glossaryService.getTerm(termObjectId.getGuid());
                context.termsGlossary.put(termObjectId.getGuid(), term.getAnchor().getGlossaryGuid());
            } catch (AtlasBaseException e) {
                LOG.warn("Error fetching term details: {}", termObjectId);
            }
        }
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasRelatedObjectId(org.apache.atlas.model.instance.AtlasRelatedObjectId) AtlasGlossaryTerm(org.apache.atlas.model.glossary.AtlasGlossaryTerm) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with AtlasGlossaryTerm

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

the class GlossaryService method updateGlossaryTermsRelation.

private void updateGlossaryTermsRelation(List<AtlasGlossaryTerm> glossaryTerms, BulkImportResponse bulkImportResponse) {
    for (AtlasGlossaryTerm glossaryTerm : glossaryTerms) {
        glossaryTermUtils.updateGlossaryTermRelations(glossaryTerm);
        if (glossaryTerm.hasTerms()) {
            String glossaryTermName = glossaryTerm.getName();
            String glossaryName = getGlossaryName(glossaryTerm);
            try {
                updateTerm(glossaryTerm, false);
            } catch (AtlasBaseException e) {
                LOG.error(AtlasErrorCode.FAILED_TO_UPDATE_GLOSSARY_TERM.toString(), glossaryTermName, e);
                bulkImportResponse.addToFailedImportInfoList(new ImportInfo(glossaryName, glossaryTermName, FAILED, e.getMessage()));
            }
        }
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasGlossaryTerm(org.apache.atlas.model.glossary.AtlasGlossaryTerm) ImportInfo(org.apache.atlas.bulkimport.BulkImportResponse.ImportInfo)

Example 4 with AtlasGlossaryTerm

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

the class GlossaryService method getDuplicateGlossaryRelatedTerm.

private String getDuplicateGlossaryRelatedTerm(AtlasGlossaryTerm atlasGlossaryTerm) throws AtlasBaseException {
    Map<AtlasGlossaryTerm.Relation, Set<AtlasRelatedTermHeader>> relatedTermsMap = atlasGlossaryTerm.getRelatedTerms();
    for (Map.Entry<AtlasGlossaryTerm.Relation, Set<AtlasRelatedTermHeader>> relatedTermsMapEntry : relatedTermsMap.entrySet()) {
        Set<AtlasRelatedTermHeader> termHeaders = relatedTermsMapEntry.getValue();
        if (CollectionUtils.isNotEmpty(termHeaders)) {
            List<AtlasRelatedTermHeader> duplicateTermHeaders = termHeaders.stream().collect(Collectors.groupingBy(AtlasRelatedTermHeader::getTermGuid)).values().stream().filter(duplicates -> duplicates.size() > 1).flatMap(Collection::stream).collect(Collectors.toList());
            if (CollectionUtils.isNotEmpty(duplicateTermHeaders) && duplicateTermHeaders.size() > 0) {
                String dupTermGuid = duplicateTermHeaders.get(0).getTermGuid();
                AtlasGlossaryTerm glossaryTerm = getTerm(dupTermGuid);
                return glossaryTerm.getQualifiedName();
            }
        }
    }
    return StringUtils.EMPTY;
}
Also used : Set(java.util.Set) AtlasRelatedTermHeader(org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader) AtlasGlossaryTerm(org.apache.atlas.model.glossary.AtlasGlossaryTerm) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with AtlasGlossaryTerm

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

the class GlossaryService method createTerm.

@GraphTransaction
public AtlasGlossaryTerm createTerm(AtlasGlossaryTerm term) throws AtlasBaseException {
    if (DEBUG_ENABLED) {
        LOG.debug("==> GlossaryService.create({})", term);
    }
    if (Objects.isNull(term)) {
        throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "GlossaryTerm definition missing");
    }
    if (Objects.isNull(term.getAnchor())) {
        throw new AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ANCHOR);
    }
    if (StringUtils.isEmpty(term.getName())) {
        throw new AtlasBaseException(AtlasErrorCode.GLOSSARY_TERM_QUALIFIED_NAME_CANT_BE_DERIVED);
    }
    if (isNameInvalid(term.getName())) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_DISPLAY_NAME);
    } else {
        // Derive the qualifiedName
        String anchorGlossaryGuid = term.getAnchor().getGlossaryGuid();
        String glossaryQualifiedName = getGlossaryQualifiedName(anchorGlossaryGuid);
        if (StringUtils.isEmpty(glossaryQualifiedName)) {
            throw new AtlasBaseException(AtlasErrorCode.GLOSSARY_QUALIFIED_NAME_CANT_BE_DERIVED);
        }
        term.setQualifiedName(term.getName() + "@" + glossaryQualifiedName);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Derived qualifiedName = {}", term.getQualifiedName());
        }
    }
    // This might fail for the case when the term's qualifiedName has been updated and the duplicate request comes in with old name
    if (termExists2(term)) {
        throw new AtlasBaseException(AtlasErrorCode.GLOSSARY_TERM_ALREADY_EXISTS, term.getQualifiedName());
    }
    AtlasGlossaryTerm storeGlossaryTerm = dataAccess.save(term);
    glossaryTermUtils.processTermRelations(storeGlossaryTerm, term, GlossaryUtils.RelationshipOperation.CREATE);
    // Re-load term after handling relations
    storeGlossaryTerm = dataAccess.load(term);
    setInfoForRelations(storeGlossaryTerm);
    if (DEBUG_ENABLED) {
        LOG.debug("<== GlossaryService.create() : {}", storeGlossaryTerm);
    }
    return storeGlossaryTerm;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasGlossaryTerm(org.apache.atlas.model.glossary.AtlasGlossaryTerm) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Aggregations

AtlasGlossaryTerm (org.apache.atlas.model.glossary.AtlasGlossaryTerm)41 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)22 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)12 Test (org.testng.annotations.Test)11 ArrayList (java.util.ArrayList)9 AtlasGlossaryHeader (org.apache.atlas.model.glossary.relations.AtlasGlossaryHeader)7 ImportInfo (org.apache.atlas.bulkimport.BulkImportResponse.ImportInfo)5 AtlasRelatedTermHeader (org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader)5 AtlasRelatedObjectId (org.apache.atlas.model.instance.AtlasRelatedObjectId)5 List (java.util.List)4 Set (java.util.Set)4 AtlasGlossary (org.apache.atlas.model.glossary.AtlasGlossary)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 AtlasGlossaryCategory (org.apache.atlas.model.glossary.AtlasGlossaryCategory)3 Collection (java.util.Collection)2 Path (javax.ws.rs.Path)2 Timed (org.apache.atlas.annotation.Timed)2 BulkImportResponse (org.apache.atlas.bulkimport.BulkImportResponse)2 AtlasTermCategorizationHeader (org.apache.atlas.model.glossary.relations.AtlasTermCategorizationHeader)2