Java Code Examples for org.apache.atlas.AtlasErrorCode#INVALID_DISPLAY_NAME

The following examples show how to use org.apache.atlas.AtlasErrorCode#INVALID_DISPLAY_NAME . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GlossaryService.java    From atlas with Apache License 2.0 5 votes vote down vote up
/**
 * Create a glossary
 *
 * @param atlasGlossary Glossary specification to be created
 * @return Glossary definition
 * @throws AtlasBaseException
 */
@GraphTransaction
public AtlasGlossary createGlossary(AtlasGlossary atlasGlossary) throws AtlasBaseException {
    if (DEBUG_ENABLED) {
        LOG.debug("==> GlossaryService.createGlossary({})", atlasGlossary);
    }

    if (Objects.isNull(atlasGlossary)) {
        throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "Glossary definition missing");
    }

    if (StringUtils.isEmpty(atlasGlossary.getQualifiedName())) {
        if (StringUtils.isEmpty(atlasGlossary.getName())) {
            throw new AtlasBaseException(AtlasErrorCode.GLOSSARY_QUALIFIED_NAME_CANT_BE_DERIVED);
        }
        if (isNameInvalid(atlasGlossary.getName())){
            throw new AtlasBaseException(AtlasErrorCode.INVALID_DISPLAY_NAME);
        } else {
            atlasGlossary.setQualifiedName(atlasGlossary.getName());
        }
    }

    if (glossaryExists(atlasGlossary)) {
        throw new AtlasBaseException(AtlasErrorCode.GLOSSARY_ALREADY_EXISTS, atlasGlossary.getQualifiedName());
    }

    AtlasGlossary storeObject = dataAccess.save(atlasGlossary);

    if (DEBUG_ENABLED) {
        LOG.debug("<== GlossaryService.createGlossary() : {}", storeObject);
    }

    return storeObject;
}
 
Example 2
Source File: GlossaryService.java    From atlas with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 3
Source File: GlossaryService.java    From atlas with Apache License 2.0 4 votes vote down vote up
@GraphTransaction
public AtlasGlossaryTerm createTerm(AtlasGlossaryTerm glossaryTerm) throws AtlasBaseException {
    if (DEBUG_ENABLED) {
        LOG.debug("==> GlossaryService.create({})", glossaryTerm);
    }
    if (Objects.isNull(glossaryTerm)) {
        throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "GlossaryTerm definition missing");
    }
    if (Objects.isNull(glossaryTerm.getAnchor())) {
        throw new AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ANCHOR);
    }
    if (StringUtils.isEmpty(glossaryTerm.getName())) {
        throw new AtlasBaseException(AtlasErrorCode.GLOSSARY_TERM_QUALIFIED_NAME_CANT_BE_DERIVED);
    }

    if (isNameInvalid(glossaryTerm.getName())){
        throw new AtlasBaseException(AtlasErrorCode.INVALID_DISPLAY_NAME);
    } else {
        // Derive the qualifiedName
        String        anchorGlossaryGuid = glossaryTerm.getAnchor().getGlossaryGuid();
        AtlasGlossary glossary           = dataAccess.load(getGlossarySkeleton(anchorGlossaryGuid));
        glossaryTerm.setQualifiedName(glossaryTerm.getName() + "@" + glossary.getQualifiedName());

        if (LOG.isDebugEnabled()) {
            LOG.debug("Derived qualifiedName = {}", glossaryTerm.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 (termExists(glossaryTerm)) {
        throw new AtlasBaseException(AtlasErrorCode.GLOSSARY_TERM_ALREADY_EXISTS, glossaryTerm.getQualifiedName());
    }

    AtlasGlossaryTerm storeObject = dataAccess.save(glossaryTerm);
    glossaryTermUtils.processTermRelations(storeObject, glossaryTerm, GlossaryUtils.RelationshipOperation.CREATE);

    // Re-load term after handling relations
    storeObject = dataAccess.load(glossaryTerm);
    setInfoForRelations(storeObject);

    if (DEBUG_ENABLED) {
        LOG.debug("<== GlossaryService.create() : {}", storeObject);
    }
    return storeObject;
}
 
Example 4
Source File: GlossaryService.java    From atlas with Apache License 2.0 4 votes vote down vote up
@GraphTransaction
public AtlasGlossaryTerm updateTerm(AtlasGlossaryTerm atlasGlossaryTerm) throws AtlasBaseException {
    if (DEBUG_ENABLED) {
        LOG.debug("==> GlossaryService.updateTerm({})", atlasGlossaryTerm);
    }

    if (Objects.isNull(atlasGlossaryTerm)) {
        throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "atlasGlossaryTerm is null/empty");
    }

    if (StringUtils.isEmpty(atlasGlossaryTerm.getName())) {
        throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "DisplayName can't be null/empty");
    }

    if (isNameInvalid(atlasGlossaryTerm.getName())) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_DISPLAY_NAME);
    }

    AtlasGlossaryTerm storeObject = dataAccess.load(atlasGlossaryTerm);
    if (!storeObject.equals(atlasGlossaryTerm)) {
        try {
            atlasGlossaryTerm.setGuid(storeObject.getGuid());
            atlasGlossaryTerm.setQualifiedName(storeObject.getQualifiedName());

            storeObject = dataAccess.save(atlasGlossaryTerm);
        } catch (AtlasBaseException e) {
            LOG.debug("Glossary term had no immediate attr updates. Exception: {}", e.getMessage());
        }

        glossaryTermUtils.processTermRelations(storeObject, atlasGlossaryTerm, GlossaryUtils.RelationshipOperation.UPDATE);

        // If qualifiedName changes due to anchor change, we need to persist the term again with updated qualifiedName
        if (StringUtils.equals(storeObject.getQualifiedName(), atlasGlossaryTerm.getQualifiedName())) {
            storeObject = dataAccess.load(atlasGlossaryTerm);
        } else {
            atlasGlossaryTerm.setQualifiedName(storeObject.getQualifiedName());

            if (termExists(atlasGlossaryTerm)) {
                throw new AtlasBaseException(AtlasErrorCode.GLOSSARY_TERM_ALREADY_EXISTS, atlasGlossaryTerm.getQualifiedName());
            }

            storeObject = dataAccess.save(atlasGlossaryTerm);
        }
    }

    setInfoForRelations(storeObject);

    if (DEBUG_ENABLED) {
        LOG.debug("<== GlossaryService.updateTerm() : {}", storeObject);
    }

    return storeObject;
}
 
Example 5
Source File: GlossaryService.java    From atlas with Apache License 2.0 4 votes vote down vote up
@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());
        }


    }

    // This might fail for the case when the category's qualifiedName has been updated during a hierarchy change
    // 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;
}
 
Example 6
Source File: GlossaryService.java    From atlas with Apache License 2.0 4 votes vote down vote up
@GraphTransaction
public AtlasGlossaryCategory updateCategory(AtlasGlossaryCategory glossaryCategory) throws AtlasBaseException {
    if (DEBUG_ENABLED) {
        LOG.debug("==> GlossaryService.updateCategory({})", glossaryCategory);
    }

    if (Objects.isNull(glossaryCategory)) {
        throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "GlossaryCategory is null/empty");
    }

    if (StringUtils.isEmpty(glossaryCategory.getName())) {
        throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "DisplayName can't be null/empty");
    }

    if (isNameInvalid(glossaryCategory.getName())) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_DISPLAY_NAME);
    }

    AtlasGlossaryCategory storeObject = dataAccess.load(glossaryCategory);

    if (!storeObject.equals(glossaryCategory)) {
        try {
            glossaryCategory.setGuid(storeObject.getGuid());
            glossaryCategory.setQualifiedName(storeObject.getQualifiedName());

            storeObject = dataAccess.save(glossaryCategory);
        } catch (AtlasBaseException e) {
            LOG.debug("No immediate attribute update. Exception: {}", e.getMessage());
        }

        Map<String, AtlasGlossaryCategory> impactedCategories = glossaryCategoryUtils.processCategoryRelations(storeObject, glossaryCategory, GlossaryUtils.RelationshipOperation.UPDATE);

        // 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);
        }

        dataAccess.save(impactedCategories.values());
    }

    if (DEBUG_ENABLED) {
        LOG.debug("<== GlossaryService.updateCategory() : {}", storeObject);
    }

    setInfoForRelations(storeObject);

    return storeObject;
}