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

The following examples show how to use org.apache.atlas.AtlasErrorCode#CLASSIFICATION_NOT_FOUND . 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: EntityGraphMapper.java    From atlas with Apache License 2.0 6 votes vote down vote up
public void validateAndNormalizeForUpdate(AtlasClassification classification) throws AtlasBaseException {
    AtlasClassificationType type = typeRegistry.getClassificationTypeByName(classification.getTypeName());

    if (type == null) {
        throw new AtlasBaseException(AtlasErrorCode.CLASSIFICATION_NOT_FOUND, classification.getTypeName());
    }

    List<String> messages = new ArrayList<>();

    type.validateValueForUpdate(classification, classification.getTypeName(), messages);

    if (!messages.isEmpty()) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, messages);
    }

    type.getNormalizedValueForUpdate(classification);
}
 
Example 2
Source File: AtlasEntityStoreV2.java    From atlas with Apache License 2.0 6 votes vote down vote up
private void validateAndNormalize(AtlasClassification classification) throws AtlasBaseException {
    AtlasClassificationType type = typeRegistry.getClassificationTypeByName(classification.getTypeName());

    if (type == null) {
        throw new AtlasBaseException(AtlasErrorCode.CLASSIFICATION_NOT_FOUND, classification.getTypeName());
    }

    List<String> messages = new ArrayList<>();

    type.validateValue(classification, classification.getTypeName(), messages);

    if (!messages.isEmpty()) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, messages);
    }

    type.getNormalizedValue(classification);
}
 
Example 3
Source File: AtlasEntityStoreV1.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private void validateAndNormalize(AtlasClassification classification) throws AtlasBaseException {
    AtlasClassificationType type = typeRegistry.getClassificationTypeByName(classification.getTypeName());

    if (type == null) {
        throw new AtlasBaseException(AtlasErrorCode.CLASSIFICATION_NOT_FOUND, classification.getTypeName());
    }

    List<String> messages = new ArrayList<>();

    type.validateValue(classification, classification.getTypeName(), messages);

    if (!messages.isEmpty()) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, messages);
    }

    type.getNormalizedValue(classification);
}
 
Example 4
Source File: AtlasEntityStoreV1.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private void validateAndNormalizeForUpdate(AtlasClassification classification) throws AtlasBaseException {
    AtlasClassificationType type = typeRegistry.getClassificationTypeByName(classification.getTypeName());

    if (type == null) {
        throw new AtlasBaseException(AtlasErrorCode.CLASSIFICATION_NOT_FOUND, classification.getTypeName());
    }

    List<String> messages = new ArrayList<>();

    type.validateValueForUpdate(classification, classification.getTypeName(), messages);

    if (!messages.isEmpty()) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, messages);
    }

    type.getNormalizedValueForUpdate(classification);
}
 
Example 5
Source File: EntityResource.java    From atlas with Apache License 2.0 5 votes vote down vote up
public static WebApplicationException toWebApplicationException(AtlasBaseException e) {
    if (e.getAtlasErrorCode() == AtlasErrorCode.CLASSIFICATION_NOT_FOUND
        || e.getAtlasErrorCode() == AtlasErrorCode.INSTANCE_GUID_NOT_FOUND
        || e.getAtlasErrorCode() == AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND) {
        return new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.NOT_FOUND));
    }

    if (e.getAtlasErrorCode() == AtlasErrorCode.INVALID_PARAMETERS
        || e.getAtlasErrorCode() == AtlasErrorCode.INSTANCE_CRUD_INVALID_PARAMS) {
        return new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
    }

    return new WebApplicationException(Servlets.getErrorResponse(e, e.getAtlasErrorCode().getHttpCode()));
}
 
Example 6
Source File: AtlasEntityStoreV2.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
@GraphTransaction
public AtlasClassification getClassification(String guid, String classificationName) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Getting classifications for entities={}", guid);
    }

    AtlasClassification ret          = null;
    AtlasEntityHeader   entityHeader = entityRetriever.toAtlasEntityHeaderWithClassifications(guid);

    if (CollectionUtils.isNotEmpty(entityHeader.getClassifications())) {
        AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_READ, entityHeader), "get classification: guid=", guid, ", classification=", classificationName);

        for (AtlasClassification classification : entityHeader.getClassifications()) {
            if (!StringUtils.equalsIgnoreCase(classification.getTypeName(), classificationName)) {
                continue;
            }

            if (StringUtils.isEmpty(classification.getEntityGuid()) || StringUtils.equalsIgnoreCase(classification.getEntityGuid(), guid)) {
                ret = classification;
                break;
            } else if (ret == null) {
                ret = classification;
            }
        }
    }

    if (ret == null) {
        throw new AtlasBaseException(AtlasErrorCode.CLASSIFICATION_NOT_FOUND, classificationName);
    }

    return ret;
}
 
Example 7
Source File: EntityResource.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
public static WebApplicationException toWebApplicationException(AtlasBaseException e) {
    if (e.getAtlasErrorCode() == AtlasErrorCode.CLASSIFICATION_NOT_FOUND
        || e.getAtlasErrorCode() == AtlasErrorCode.INSTANCE_GUID_NOT_FOUND
        || e.getAtlasErrorCode() == AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND) {
        return new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.NOT_FOUND));
    }

    if (e.getAtlasErrorCode() == AtlasErrorCode.INVALID_PARAMETERS
        || e.getAtlasErrorCode() == AtlasErrorCode.INSTANCE_CRUD_INVALID_PARAMS) {
        return new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
    }

    return new WebApplicationException(Servlets.getErrorResponse(e, e.getAtlasErrorCode().getHttpCode()));
}
 
Example 8
Source File: EntityGraphRetriever.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
public AtlasClassification getClassification(String guid, String classificationName) throws AtlasBaseException {

        AtlasVertex instanceVertex = AtlasGraphUtilsV1.findByGuid(guid);
        if (instanceVertex == null) {
            throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
        }

        List<AtlasClassification> classifications = getClassifications(instanceVertex, classificationName);

        if(CollectionUtils.isEmpty(classifications)) {
            throw new AtlasBaseException(AtlasErrorCode.CLASSIFICATION_NOT_FOUND, classificationName);
        }

        return classifications.get(0);
    }
 
Example 9
Source File: EntityGraphRetriever.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private List<AtlasClassification> getClassifications(AtlasVertex instanceVertex, @Nullable String classificationNameFilter) throws AtlasBaseException {
    List<AtlasClassification> classifications = new ArrayList<>();
    List<String> classificationNames = GraphHelper.getTraitNames(instanceVertex);

    if (CollectionUtils.isNotEmpty(classificationNames)) {
        for (String classificationName : classificationNames) {
            AtlasClassification classification;
            if (StringUtils.isNotEmpty(classificationNameFilter)) {
                if (classificationName.equals(classificationNameFilter)) {
                    classification = getClassification(instanceVertex, classificationName);
                    classifications.add(classification);
                    return classifications;
                }
            } else {
                classification = getClassification(instanceVertex, classificationName);
                classifications.add(classification);
            }
        }


        if (StringUtils.isNotEmpty(classificationNameFilter)) {
            //Should not reach here if classification present
            throw new AtlasBaseException(AtlasErrorCode.CLASSIFICATION_NOT_FOUND, classificationNameFilter);
        }
    }
    return classifications;
}
 
Example 10
Source File: EntityGraphMapper.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private void validateClassificationExists(List<String> existingClassifications, List<String> suppliedClassifications) throws AtlasBaseException {
    Set<String> existingNames = new HashSet<>(existingClassifications);
    for (String classificationName : suppliedClassifications) {
        if (!existingNames.contains(classificationName)) {
            throw new AtlasBaseException(AtlasErrorCode.CLASSIFICATION_NOT_FOUND, classificationName);
        }
    }
}
 
Example 11
Source File: EntityGraphMapper.java    From atlas with Apache License 2.0 4 votes vote down vote up
public void deleteClassification(String entityGuid, String classificationName) throws AtlasBaseException {
    if (StringUtils.isEmpty(classificationName)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_CLASSIFICATION_PARAMS, "delete", entityGuid);
    }

    AtlasVertex entityVertex = AtlasGraphUtilsV2.findByGuid(this.graph, entityGuid);

    if (entityVertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, entityGuid);
    }

    AtlasPerfTracer perf = null;

    if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
        perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityGraphMapper.deleteClassification");
    }

    List<String> traitNames = getTraitNames(entityVertex);

    if (CollectionUtils.isEmpty(traitNames)) {
        throw new AtlasBaseException(AtlasErrorCode.NO_CLASSIFICATIONS_FOUND_FOR_ENTITY, entityGuid);
    }

    validateClassificationExists(traitNames, classificationName);

    AtlasVertex         classificationVertex = getClassificationVertex(entityVertex, classificationName);
    AtlasClassification classification       = entityRetriever.toAtlasClassification(classificationVertex);

    if (classification == null) {
        throw new AtlasBaseException(AtlasErrorCode.CLASSIFICATION_NOT_FOUND, classificationName);
    }

    // remove classification from propagated entities if propagation is turned on
    final List<AtlasVertex> entityVertices;

    if (isPropagationEnabled(classificationVertex)) {
        entityVertices = deleteDelegate.getHandler().removeTagPropagation(classificationVertex);

        if (LOG.isDebugEnabled()) {
            LOG.debug("Number of propagations to delete -> {}", entityVertices.size());
        }
    } else {
        entityVertices = new ArrayList<>();
    }

    // add associated entity to entityVertices list
    if (!entityVertices.contains(entityVertex)) {
        entityVertices.add(entityVertex);
    }

    // remove classifications from associated entity
    if (LOG.isDebugEnabled()) {
        LOG.debug("Removing classification: [{}] from: [{}][{}] with edge label: [{}]", classificationName,
                getTypeName(entityVertex), entityGuid, CLASSIFICATION_LABEL);
    }

    AtlasEdge edge = getClassificationEdge(entityVertex, classificationVertex);

    deleteDelegate.getHandler().deleteEdgeReference(edge, CLASSIFICATION, false, true, entityVertex);

    traitNames.remove(classificationName);

    // update 'TRAIT_NAMES_PROPERTY_KEY' property
    entityVertex.removePropertyValue(TRAIT_NAMES_PROPERTY_KEY, classificationName);

    // update 'CLASSIFICATION_NAMES_KEY' property
    entityVertex.removeProperty(CLASSIFICATION_NAMES_KEY);

    entityVertex.setProperty(CLASSIFICATION_NAMES_KEY, getClassificationNamesString(traitNames));

    updateModificationMetadata(entityVertex);

    if (CollectionUtils.isNotEmpty(entityVertices)) {
        List<AtlasEntity> propagatedEntities = updateClassificationText(classification, entityVertices);

        //Sending audit request for all entities at once
        entityChangeNotifier.onClassificationsDeletedFromEntities(propagatedEntities, Collections.singletonList(classification));
    }
    AtlasPerfTracer.log(perf);
}
 
Example 12
Source File: AtlasEntityStoreV1.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
@Override
@GraphTransaction
public void updateClassifications(String guid, List<AtlasClassification> newClassifications) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Updating classifications={} for entity={}", newClassifications, guid);
    }

    if (StringUtils.isEmpty(guid)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "Guid not specified");
    }

    if (CollectionUtils.isEmpty(newClassifications)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "classifications(s) not specified");
    }

    GraphTransactionInterceptor.lockObjectAndReleasePostCommit(guid);
    List<AtlasClassification> updatedClassifications = new ArrayList<>();

    for (AtlasClassification newClassification : newClassifications) {
        String              classificationName = newClassification.getTypeName();
        AtlasClassification oldClassification  = getClassification(guid, classificationName);

        if (oldClassification == null) {
            throw new AtlasBaseException(AtlasErrorCode.CLASSIFICATION_NOT_FOUND, classificationName);
        }

        validateAndNormalizeForUpdate(newClassification);

        Map<String, Object> newAttrs = newClassification.getAttributes();

        if (MapUtils.isNotEmpty(newAttrs)) {
            for (String attrName : newAttrs.keySet()) {
                oldClassification.setAttribute(attrName, newAttrs.get(attrName));
            }
        }

        entityGraphMapper.updateClassification(new EntityMutationContext(), guid, oldClassification);

        updatedClassifications.add(oldClassification);
    }

    // notify listeners on update to classifications
    entityChangeNotifier.onClassificationUpdatedToEntity(guid, updatedClassifications);
}