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

The following examples show how to use org.apache.atlas.AtlasErrorCode#INVALID_VALUE . 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: ImportTransformer.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
public static ImportTransformer getTransformer(String transformerSpec) throws AtlasBaseException {
    String[] params = StringUtils.split(transformerSpec, TRANSFORMER_PARAMETER_SEPARATOR);
    String   key    = (params == null || params.length < 1) ? transformerSpec : params[0];

    final ImportTransformer ret;

    if (StringUtils.isEmpty(key)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_VALUE, "Error creating ImportTransformer. Invalid transformer-specification: {}.", transformerSpec);
    } else if (key.equals("replace")) {
        String toFindStr  = (params == null || params.length < 2) ? "" : params[1];
        String replaceStr = (params == null || params.length < 3) ? "" : params[2];

        ret = new Replace(toFindStr, replaceStr);
    } else if (key.equals("lowercase")) {
        ret = new Lowercase();
    } else if (key.equals("uppercase")) {
        ret = new Uppercase();
    } else {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_VALUE, "Error creating ImportTransformer. Unknown transformer: {}.", transformerSpec);
    }

    return ret;
}
 
Example 2
Source File: AtlasInstanceConverter.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
public static AtlasBaseException toAtlasBaseException(AtlasException e) {
    if (e instanceof EntityExistsException) {
        return new AtlasBaseException(AtlasErrorCode.INSTANCE_ALREADY_EXISTS, e.getMessage());
    }

    if ( e instanceof EntityNotFoundException || e instanceof TraitNotFoundException) {
        return new AtlasBaseException(AtlasErrorCode.INSTANCE_NOT_FOUND, e.getMessage());
    }

    if ( e instanceof TypeNotFoundException) {
        return new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, e.getMessage());
    }

    if (e instanceof ValueConversionException) {
        return new AtlasBaseException(AtlasErrorCode.INVALID_VALUE, e, e.getMessage());
    }

    return new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, e.getMessage());
}
 
Example 3
Source File: AtlasRelationshipStoreV2.java    From atlas with Apache License 2.0 5 votes vote down vote up
private void validateRelationship(AtlasRelationship relationship) throws AtlasBaseException {
    if (relationship == null) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "AtlasRelationship is null");
    }

    String                relationshipName = relationship.getTypeName();
    String                end1TypeName     = getTypeNameFromObjectId(relationship.getEnd1());
    String                end2TypeName     = getTypeNameFromObjectId(relationship.getEnd2());
    AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationshipName);

    if (relationshipType == null) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_VALUE, "unknown relationship type'" + relationshipName + "'");
    }

    if (relationship.getEnd1() == null || relationship.getEnd2() == null) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "end1/end2 is null");
    }

    boolean validEndTypes = false;

    if (relationshipType.getEnd1Type().isTypeOrSuperTypeOf(end1TypeName)) {
        validEndTypes = relationshipType.getEnd2Type().isTypeOrSuperTypeOf(end2TypeName);
    } else if (relationshipType.getEnd2Type().isTypeOrSuperTypeOf(end1TypeName)) {
        validEndTypes = relationshipType.getEnd1Type().isTypeOrSuperTypeOf(end2TypeName);
    }

    if (!validEndTypes) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_RELATIONSHIP_END_TYPE, relationshipName, relationshipType.getEnd2Type().getTypeName(), end1TypeName);
    }

    validateEnds(relationship);

    validateAndNormalize(relationship);
}
 
Example 4
Source File: AtlasRelationshipType.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
void resolveReferences(AtlasTypeRegistry typeRegistry) throws AtlasBaseException {
    super.resolveReferences(typeRegistry);

    if (relationshipDef == null) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_VALUE, "relationshipDef is null");
    }

    String end1TypeName = relationshipDef.getEndDef1() != null ? relationshipDef.getEndDef1().getType() : null;
    String end2TypeName = relationshipDef.getEndDef2() != null ? relationshipDef.getEndDef2().getType() : null;

    AtlasType type1 = typeRegistry.getType(end1TypeName);
    AtlasType type2 = typeRegistry.getType(end2TypeName);

    if (type1 instanceof AtlasEntityType) {
        end1Type = (AtlasEntityType) type1;
    } else {
        throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID_END_TYPE, getTypeName(), end1TypeName);
    }

    if (type2 instanceof AtlasEntityType) {
        end2Type = (AtlasEntityType) type2;
    } else {
        throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID_END_TYPE, getTypeName(), end2TypeName);
    }

    validateAtlasRelationshipDef(relationshipDef);
}
 
Example 5
Source File: EntityGraphMapper.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
public void updateClassification(final EntityMutationContext context, String guid, AtlasClassification classification)
                                 throws AtlasBaseException {

    AtlasVertex instanceVertex = AtlasGraphUtilsV1.findByGuid(guid);

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

    String entityTypeName = AtlasGraphUtilsV1.getTypeName(instanceVertex);

    final AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entityTypeName);

    if (LOG.isDebugEnabled()) {
        LOG.debug("Updating classification {} for entity {}", classification, guid);
    }

    // get the classification vertex from entity
    String      relationshipLabel    = GraphHelper.getTraitLabel(entityTypeName, classification.getTypeName());
    AtlasEdge   classificationEdge   = graphHelper.getEdgeForLabel(instanceVertex, relationshipLabel);

    if (classificationEdge == null) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_VALUE, "classificationEdge is null for label: " + relationshipLabel);
    }

    AtlasVertex classificationVertex = classificationEdge.getInVertex();

    if (LOG.isDebugEnabled()) {
        LOG.debug("updating vertex {} for trait {}", string(classificationVertex), classification.getTypeName());
    }

    mapClassification(EntityOperation.UPDATE, context, classification, entityType, instanceVertex, classificationVertex);
}
 
Example 6
Source File: AtlasRelationshipStoreV1.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private void validateRelationship(AtlasRelationship relationship) throws AtlasBaseException {
    if (relationship == null) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "AtlasRelationship is null");
    }

    String                relationshipName = relationship.getTypeName();
    String                end1TypeName     = getTypeNameFromObjectId(relationship.getEnd1());
    String                end2TypeName     = getTypeNameFromObjectId(relationship.getEnd2());
    AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationshipName);

    if (relationshipType == null) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_VALUE, "unknown relationship type'" + relationshipName + "'");
    }

    if (relationship.getEnd1() == null || relationship.getEnd2() == null) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "end1/end2 is null");
    }

    if (!relationshipType.getEnd1Type().isTypeOrSuperTypeOf(end1TypeName) &&
            !relationshipType.getEnd2Type().isTypeOrSuperTypeOf(end1TypeName)) {

        throw new AtlasBaseException(AtlasErrorCode.INVALID_RELATIONSHIP_END_TYPE, relationshipName,
                                     relationshipType.getEnd2Type().getTypeName(), end1TypeName);
    }

    if (!relationshipType.getEnd2Type().isTypeOrSuperTypeOf(end2TypeName) &&
            !relationshipType.getEnd1Type().isTypeOrSuperTypeOf(end2TypeName)) {

        throw new AtlasBaseException(AtlasErrorCode.INVALID_RELATIONSHIP_END_TYPE, relationshipName,
                                     relationshipType.getEnd1Type().getTypeName(), end2TypeName);
    }

    validateEnd(relationship.getEnd1());

    validateEnd(relationship.getEnd2());

    validateAndNormalize(relationship);
}
 
Example 7
Source File: AtlasRelationshipType.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Override
public void resolveReferences(AtlasTypeRegistry typeRegistry) throws AtlasBaseException {
    super.resolveReferences(typeRegistry);

    if (relationshipDef == null) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_VALUE, "relationshipDef is null");
    }

    String end1TypeName = relationshipDef.getEndDef1() != null ? relationshipDef.getEndDef1().getType() : null;
    String end2TypeName = relationshipDef.getEndDef2() != null ? relationshipDef.getEndDef2().getType() : null;

    AtlasType type1 = typeRegistry.getType(end1TypeName);
    AtlasType type2 = typeRegistry.getType(end2TypeName);

    if (type1 instanceof AtlasEntityType) {
        end1Type = (AtlasEntityType) type1;

    } else {
        throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID_END_TYPE, getTypeName(), end1TypeName);
    }

    if (type2 instanceof AtlasEntityType) {
        end2Type = (AtlasEntityType) type2;

    } else {
        throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID_END_TYPE, getTypeName(), end2TypeName);
    }

    validateAtlasRelationshipDef(this.relationshipDef);
}
 
Example 8
Source File: AtlasRelationshipStoreV2.java    From atlas with Apache License 2.0 4 votes vote down vote up
private void validateRelationship(AtlasVertex end1Vertex, AtlasVertex end2Vertex,  AtlasRelationship relationship) throws AtlasBaseException {

        String relationshipName = relationship.getTypeName();

        AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationshipName);

        if (relationshipType == null) {
            throw new AtlasBaseException(AtlasErrorCode.INVALID_VALUE, "unknown relationship type'" + relationshipName + "'");
        }

        if (end1Vertex == null) {
            throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_END_IS_NULL, relationshipType.getEnd1Type().getTypeName());
        }

        if (end2Vertex == null) {
            throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_END_IS_NULL, relationshipType.getEnd2Type().getTypeName());
        }

        String                end1TypeName     = AtlasGraphUtilsV2.getTypeName(end1Vertex);
        String                end2TypeName     = AtlasGraphUtilsV2.getTypeName(end2Vertex);

        boolean validEndTypes = false;

        if (relationshipType.getEnd1Type().isTypeOrSuperTypeOf(end1TypeName)) {
            validEndTypes = relationshipType.getEnd2Type().isTypeOrSuperTypeOf(end2TypeName);
        } else if (relationshipType.getEnd2Type().isTypeOrSuperTypeOf(end1TypeName)) {
            validEndTypes = relationshipType.getEnd1Type().isTypeOrSuperTypeOf(end2TypeName);
        }

        if (!validEndTypes) {
            throw new AtlasBaseException(AtlasErrorCode.INVALID_RELATIONSHIP_END_TYPE, relationshipName, relationshipType.getEnd2Type().getTypeName(), end1TypeName);
        }

        PropagateTags typePropagation = relationshipType.getRelationshipDef().getPropagateTags();
        PropagateTags edgePropagation = relationship.getPropagateTags();

        if (typePropagation == null) {
            typePropagation = NONE;
        }

        if (edgePropagation == null) {
            edgePropagation = NONE;
        }

        /*
          +-------------+----------------------------------------+
          |     type    |                edge                    |
          +-------------+-------+------------+------------+------+
          |             | NONE  | ONE_TO_TWO | TWO_TO_ONE | BOTH |
          |-------------+-------+------------+------------+------|
          | NONE        |   Y   |     N      |      N     |   N  |
          | ONE_TO_TWO  |   Y   |     Y      |      N     |   N  |
          | TWO_TO_ONE  |   Y   |     N      |      Y     |   N  |
          | BOTH        |   Y   |     Y      |      Y     |   Y  |
          +-------------+-------+------------+------------+------+
         */

        if (edgePropagation != NONE && typePropagation != BOTH && edgePropagation != typePropagation) {
            throw new AtlasBaseException(AtlasErrorCode.INVALID_PROPAGATION_TYPE, edgePropagation.toString(), relationshipName, typePropagation.toString());
        }

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

        relationshipType.validateValue(relationship, relationshipName, messages);

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

        relationshipType.getNormalizedValue(relationship);
    }