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;
}
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;
}
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;
}
use of org.apache.atlas.model.glossary.AtlasGlossary in project atlas by apache.
the class GlossaryTermUtils method processTermAnchor.
private void processTermAnchor(AtlasGlossaryTerm currentTerm, AtlasGlossaryTerm updatedTerm, RelationshipOperation op) throws AtlasBaseException {
if (Objects.isNull(updatedTerm.getAnchor()) && op != RelationshipOperation.DELETE) {
throw new AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ANCHOR);
}
// glossary_g1
AtlasGlossaryHeader currentTermGlossary = currentTerm.getAnchor();
// glossary_g2
AtlasGlossaryHeader updatedTermGlossary = updatedTerm.getAnchor();
String updatedTermGlossaryGuid = updatedTermGlossary.getGlossaryGuid();
String currentTermGlossaryGuid = currentTermGlossary.getGlossaryGuid();
switch(op) {
case CREATE:
if (Objects.isNull(updatedTermGlossaryGuid)) {
throw new AtlasBaseException(AtlasErrorCode.INVALID_NEW_ANCHOR_GUID);
} else {
if (DEBUG_ENABLED) {
LOG.debug("Creating new term anchor, category = {}, glossary = {}", currentTerm.getGuid(), updatedTerm.getAnchor().getGlossaryGuid());
}
if (!StringUtils.equals(updatedTermGlossaryGuid, currentTermGlossaryGuid)) {
createRelationship(defineTermAnchorRelation(updatedTermGlossaryGuid, currentTerm.getGuid()));
}
}
break;
case UPDATE:
if (!Objects.equals(updatedTermGlossary, currentTermGlossary)) {
if (Objects.isNull(updatedTermGlossaryGuid)) {
throw new AtlasBaseException(AtlasErrorCode.INVALID_NEW_ANCHOR_GUID);
}
if (DEBUG_ENABLED) {
LOG.debug("Updating term anchor, currAnchor = {}, newAnchor = {} and term = {}", currentTermGlossaryGuid, updatedTermGlossaryGuid, currentTerm.getName());
}
relationshipStore.deleteById(currentTermGlossary.getRelationGuid(), true);
// Derive the qualifiedName when anchor changes
String anchorGlossaryGuid = updatedTermGlossaryGuid;
AtlasGlossary glossary = dataAccess.load(getGlossarySkeleton(anchorGlossaryGuid));
currentTerm.setQualifiedName(currentTerm.getName() + "@" + glossary.getQualifiedName());
if (LOG.isDebugEnabled()) {
LOG.debug("Derived qualifiedName = {}", currentTerm.getQualifiedName());
}
createRelationship(defineTermAnchorRelation(updatedTermGlossaryGuid, currentTerm.getGuid()));
}
break;
case DELETE:
if (Objects.nonNull(currentTermGlossary)) {
if (DEBUG_ENABLED) {
LOG.debug("Deleting term anchor");
}
relationshipStore.deleteById(currentTermGlossary.getRelationGuid(), true);
}
break;
}
}
use of org.apache.atlas.model.glossary.AtlasGlossary in project atlas by apache.
the class GlossaryTermUtils method createGlossary.
private String createGlossary(String glossaryName, List<String> failedTermMsgs) throws AtlasBaseException {
String ret = null;
if (GlossaryService.isNameInvalid(glossaryName)) {
LOG.error("The provided Glossary Name is invalid : " + glossaryName);
failedTermMsgs.add("The provided Glossary Name {" + glossaryName + "} is invalid : " + AtlasErrorCode.INVALID_DISPLAY_NAME.getFormattedErrorMessage());
} else {
AtlasGlossary glossary = new AtlasGlossary();
glossary.setQualifiedName(glossaryName);
glossary.setName(glossaryName);
glossary = dataAccess.save(glossary);
ret = glossary.getGuid();
}
return ret;
}
Aggregations