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);
}
}
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);
}
}
}
}
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()));
}
}
}
}
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;
}
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;
}
Aggregations