use of org.apache.atlas.type.AtlasRelationshipType in project atlas by apache.
the class AtlasRelationshipStoreV1 method validateRelationship.
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);
}
use of org.apache.atlas.type.AtlasRelationshipType in project atlas by apache.
the class AtlasRelationshipStoreV1 method createRelationship.
private AtlasEdge createRelationship(AtlasVertex end1Vertex, AtlasVertex end2Vertex, AtlasRelationship relationship) throws AtlasBaseException {
AtlasEdge ret = null;
try {
ret = getRelationshipEdge(end1Vertex, end2Vertex, relationship.getTypeName());
if (ret == null) {
ret = createRelationshipEdge(end1Vertex, end2Vertex, relationship);
AtlasRelationshipType relationType = typeRegistry.getRelationshipTypeByName(relationship.getTypeName());
if (MapUtils.isNotEmpty(relationType.getAllAttributes())) {
for (AtlasAttribute attr : relationType.getAllAttributes().values()) {
String attrName = attr.getName();
String attrVertexProperty = attr.getVertexPropertyName();
Object attrValue = relationship.getAttribute(attrName);
AtlasGraphUtilsV1.setProperty(ret, attrVertexProperty, attrValue);
}
}
} else {
throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_ALREADY_EXISTS, relationship.getTypeName(), AtlasGraphUtilsV1.getIdFromVertex(end1Vertex), AtlasGraphUtilsV1.getIdFromVertex(end2Vertex));
}
} catch (RepositoryException e) {
throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e);
}
return ret;
}
use of org.apache.atlas.type.AtlasRelationshipType in project incubator-atlas by apache.
the class AtlasRelationshipStoreV1 method validateAndNormalize.
private void validateAndNormalize(AtlasRelationship relationship) throws AtlasBaseException {
List<String> messages = new ArrayList<>();
if (!AtlasTypeUtil.isValidGuid(relationship.getGuid())) {
throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_GUID_NOT_FOUND, relationship.getGuid());
}
AtlasRelationshipType type = typeRegistry.getRelationshipTypeByName(relationship.getTypeName());
if (type == null) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, TypeCategory.RELATIONSHIP.name(), relationship.getTypeName());
}
type.validateValue(relationship, relationship.getTypeName(), messages);
if (!messages.isEmpty()) {
throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_CRUD_INVALID_PARAMS, messages);
}
type.getNormalizedValue(relationship);
}
use of org.apache.atlas.type.AtlasRelationshipType in project incubator-atlas by apache.
the class AtlasRelationshipStoreV1 method mapAttributes.
private void mapAttributes(AtlasEdge edge, AtlasRelationship relationship) throws AtlasBaseException {
AtlasType objType = typeRegistry.getType(relationship.getTypeName());
if (!(objType instanceof AtlasRelationshipType)) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, relationship.getTypeName());
}
AtlasRelationshipType relationshipType = (AtlasRelationshipType) objType;
for (AtlasAttribute attribute : relationshipType.getAllAttributes().values()) {
// mapping only primitive attributes
Object attrValue = entityRetriever.mapVertexToPrimitive(edge, attribute.getQualifiedName(), attribute.getAttributeDef());
relationship.setAttribute(attribute.getName(), attrValue);
}
}
use of org.apache.atlas.type.AtlasRelationshipType in project incubator-atlas by apache.
the class AtlasRelationshipStoreV1 method validateRelationship.
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);
}
Aggregations