use of org.apache.atlas.model.glossary.AtlasGlossary in project atlas by apache.
the class GlossaryServiceTest method testCreateGlossary.
@Test(groups = "Glossary.CREATE")
public void testCreateGlossary() {
try {
AtlasGlossary created = glossaryService.createGlossary(bankGlossary);
bankGlossary.setGuid(created.getGuid());
created = glossaryService.createGlossary(creditUnionGlossary);
creditUnionGlossary.setGuid(created.getGuid());
} catch (AtlasBaseException e) {
fail("Glossary creation should've succeeded", e);
}
// Duplicate create calls should fail with 409 Conflict
try {
glossaryService.createGlossary(bankGlossary);
fail("Glossary duplicate creation should've failed");
} catch (AtlasBaseException e) {
assertEquals(e.getAtlasErrorCode(), AtlasErrorCode.GLOSSARY_ALREADY_EXISTS);
}
try {
glossaryService.createGlossary(creditUnionGlossary);
fail("Glossary duplicate creation should've failed");
} catch (AtlasBaseException e) {
assertEquals(e.getAtlasErrorCode(), AtlasErrorCode.GLOSSARY_ALREADY_EXISTS);
}
try {
List<AtlasRelatedCategoryHeader> glossaryCategories = glossaryService.getGlossaryCategoriesHeaders(bankGlossary.getGuid(), 0, 10, SortOrder.ASCENDING);
assertNotNull(glossaryCategories);
assertEquals(glossaryCategories.size(), 0);
glossaryCategories = glossaryService.getGlossaryCategoriesHeaders(creditUnionGlossary.getGuid(), 0, 10, SortOrder.ASCENDING);
assertNotNull(glossaryCategories);
assertEquals(glossaryCategories.size(), 0);
} catch (AtlasBaseException e) {
fail("Get glossary categories calls should've succeeded", e);
}
try {
List<AtlasRelatedTermHeader> glossaryCategories = glossaryService.getGlossaryTermsHeaders(bankGlossary.getGuid(), 0, 10, SortOrder.ASCENDING);
assertNotNull(glossaryCategories);
assertEquals(glossaryCategories.size(), 0);
glossaryCategories = glossaryService.getGlossaryTermsHeaders(creditUnionGlossary.getGuid(), 0, 10, SortOrder.ASCENDING);
assertNotNull(glossaryCategories);
assertEquals(glossaryCategories.size(), 0);
} catch (AtlasBaseException e) {
fail("Get glossary categories calls should've succeeded", e);
}
// Glossary anchor
AtlasGlossaryHeader glossaryId = new AtlasGlossaryHeader();
glossaryId.setGlossaryGuid(bankGlossary.getGuid());
// Create terms
checkingAccount.setAnchor(glossaryId);
savingsAccount.setAnchor(glossaryId);
fixedRateMortgage.setAnchor(glossaryId);
adjustableRateMortgage.setAnchor(glossaryId);
// Create glossary categories
accountCategory.setAnchor(glossaryId);
customerCategory.setAnchor(glossaryId);
mortgageCategory.setAnchor(glossaryId);
}
use of org.apache.atlas.model.glossary.AtlasGlossary in project atlas by apache.
the class GlossaryCategoryUtils method processParentRemoval.
private void processParentRemoval(AtlasGlossaryCategory storeObject, AtlasGlossaryCategory updatedCategory, AtlasRelatedCategoryHeader existingParent, Map<String, AtlasGlossaryCategory> impactedCategories) throws AtlasBaseException {
if (DEBUG_ENABLED) {
LOG.debug("Removing category parent, category = {}, parent = {}", storeObject.getGuid(), existingParent.getDisplayText());
}
relationshipStore.deleteById(existingParent.getRelationGuid(), true);
// Parent deleted, qualifiedName needs recomputation
// Derive the qualifiedName of the Glossary
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());
}
updateChildCategories(storeObject, storeObject.getChildrenCategories(), impactedCategories, false);
}
use of org.apache.atlas.model.glossary.AtlasGlossary in project atlas by apache.
the class GlossaryService method getGlossary.
/**
* Get specific glossary
*
* @param glossaryGuid unique identifier
* @return Glossary corresponding to specified glossaryGuid
* @throws AtlasBaseException
*/
@GraphTransaction
public AtlasGlossary getGlossary(String glossaryGuid) throws AtlasBaseException {
if (DEBUG_ENABLED) {
LOG.debug("==> GlossaryService.getGlossary({})", glossaryGuid);
}
if (Objects.isNull(glossaryGuid)) {
throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "glossaryGuid is null/empty");
}
AtlasGlossary atlasGlossary = getGlossarySkeleton(glossaryGuid);
AtlasGlossary ret = dataAccess.load(atlasGlossary);
setInfoForRelations(ret);
if (DEBUG_ENABLED) {
LOG.debug("<== GlossaryService.getGlossary() : {}", ret);
}
return ret;
}
use of org.apache.atlas.model.glossary.AtlasGlossary in project atlas by apache.
the class GlossaryService method getGlossaries.
/**
* List all glossaries
*
* @param limit page size - no paging by default
* @param offset offset for pagination
* @param sortOrder ASC (default) or DESC
* @return List of all glossaries
* @throws AtlasBaseException
*/
@GraphTransaction
public List<AtlasGlossary> getGlossaries(int limit, int offset, SortOrder sortOrder) throws AtlasBaseException {
if (DEBUG_ENABLED) {
LOG.debug("==> GlossaryService.getGlossaries({}, {}, {})", limit, offset, sortOrder);
}
List<String> glossaryGuids = AtlasGraphUtilsV2.findEntityGUIDsByType(GlossaryUtils.ATLAS_GLOSSARY_TYPENAME, sortOrder);
PaginationHelper paginationHelper = new PaginationHelper<>(glossaryGuids, offset, limit);
List<AtlasGlossary> ret;
List<String> guidsToLoad = paginationHelper.getPaginatedList();
AtlasEntity.AtlasEntitiesWithExtInfo glossaryEntities;
if (CollectionUtils.isNotEmpty(guidsToLoad)) {
glossaryEntities = dataAccess.getAtlasEntityStore().getByIds(guidsToLoad, true, false);
ret = new ArrayList<>();
for (AtlasEntity glossaryEntity : glossaryEntities.getEntities()) {
AtlasGlossary glossary = glossaryDTO.from(glossaryEntity);
ret.add(glossary);
}
} else {
ret = Collections.emptyList();
}
if (DEBUG_ENABLED) {
LOG.debug("<== GlossaryService.getGlossaries() : {}", ret);
}
return ret;
}
use of org.apache.atlas.model.glossary.AtlasGlossary in project atlas by apache.
the class GlossaryService method updateGlossary.
@GraphTransaction
public AtlasGlossary updateGlossary(AtlasGlossary atlasGlossary) throws AtlasBaseException {
if (DEBUG_ENABLED) {
LOG.debug("==> GlossaryService.updateGlossary({})", atlasGlossary);
}
if (Objects.isNull(atlasGlossary)) {
throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "Glossary is null/empty");
}
if (StringUtils.isEmpty(atlasGlossary.getName())) {
throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "DisplayName can't be null/empty");
}
if (isNameInvalid(atlasGlossary.getName())) {
throw new AtlasBaseException(AtlasErrorCode.INVALID_DISPLAY_NAME);
}
AtlasGlossary storeObject = dataAccess.load(atlasGlossary);
if (!storeObject.equals(atlasGlossary)) {
atlasGlossary.setGuid(storeObject.getGuid());
atlasGlossary.setQualifiedName(storeObject.getQualifiedName());
storeObject = dataAccess.save(atlasGlossary);
setInfoForRelations(storeObject);
}
if (DEBUG_ENABLED) {
LOG.debug("<== GlossaryService.updateGlossary() : {}", storeObject);
}
return storeObject;
}
Aggregations