/** * Validate the fields in the the RelationshipType are consistent with respect to themselves. * @param relationship * @throws AtlasBaseException */ private boolean validateRelationship(AtlasRelationship relationship) { String end1TypeName = relationship.getEnd1() != null ? relationship.getEnd1().getTypeName() : null; String end2TypeName = relationship.getEnd2() != null ? relationship.getEnd2().getTypeName() : null; if (StringUtils.isNotEmpty(end1TypeName) && StringUtils.isNotEmpty(end2TypeName)) { return end1Type.isTypeOrSuperTypeOf(end1TypeName) && end2Type.isTypeOrSuperTypeOf(end2TypeName) && super.isValidValue(relationship); } return false; }
private void validateRelationship(AtlasVertex end1Vertex, AtlasVertex end2Vertex, String relationshipName, Map<String, Object> attributes) throws AtlasBaseException { 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); } List<String> messages = new ArrayList<>(); AtlasRelationship relationship = new AtlasRelationship(relationshipName, attributes); relationshipType.validateValue(relationship, relationshipName, messages); if (!messages.isEmpty()) { throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_CRUD_INVALID_PARAMS, messages); } relationshipType.getNormalizedValue(relationship); }
private void validateRelationship(AtlasVertex end1Vertex, AtlasVertex end2Vertex, String relationshipName, Map<String, Object> attributes) throws AtlasBaseException { 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); } List<String> messages = new ArrayList<>(); AtlasRelationship relationship = new AtlasRelationship(relationshipName, attributes); relationshipType.validateValue(relationship, relationshipName, messages); if (!messages.isEmpty()) { throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_CRUD_INVALID_PARAMS, messages); } relationshipType.getNormalizedValue(relationship); }
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); }
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); }
private Object mapVertexToRelationshipAttribute(AtlasVertex entityVertex, AtlasEntityType entityType, AtlasAttribute attribute) throws AtlasBaseException { Object ret = null; AtlasRelationshipDef relationshipDef = graphHelper.getRelationshipDef(entityVertex, entityType, attribute.getName()); if (relationshipDef == null) { throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID, "relationshipDef is null"); } AtlasRelationshipEndDef endDef1 = relationshipDef.getEndDef1(); AtlasRelationshipEndDef endDef2 = relationshipDef.getEndDef2(); AtlasEntityType endDef1Type = typeRegistry.getEntityTypeByName(endDef1.getType()); AtlasEntityType endDef2Type = typeRegistry.getEntityTypeByName(endDef2.getType()); AtlasRelationshipEndDef attributeEndDef = null; if (endDef1Type.isTypeOrSuperTypeOf(entityType.getTypeName()) && StringUtils.equals(endDef1.getName(), attribute.getName())) { attributeEndDef = endDef1; } else if (endDef2Type.isTypeOrSuperTypeOf(entityType.getTypeName()) && StringUtils.equals(endDef2.getName(), attribute.getName())) { attributeEndDef = endDef2; } if (attributeEndDef == null) { throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID, relationshipDef.toString()); } switch (attributeEndDef.getCardinality()) { case SINGLE: ret = mapRelatedVertexToObjectId(entityVertex, attribute); break; case LIST: case SET: ret = mapRelationshipArrayAttribute(entityVertex, attribute); break; } return ret; }
private Object mapVertexToRelationshipAttribute(AtlasVertex entityVertex, AtlasEntityType entityType, AtlasAttribute attribute) throws AtlasBaseException { Object ret = null; AtlasRelationshipDef relationshipDef = graphHelper.getRelationshipDef(entityVertex, entityType, attribute.getName()); if (relationshipDef == null) { throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID, "relationshipDef is null"); } AtlasRelationshipEndDef endDef1 = relationshipDef.getEndDef1(); AtlasRelationshipEndDef endDef2 = relationshipDef.getEndDef2(); AtlasEntityType endDef1Type = typeRegistry.getEntityTypeByName(endDef1.getType()); AtlasEntityType endDef2Type = typeRegistry.getEntityTypeByName(endDef2.getType()); AtlasRelationshipEndDef attributeEndDef = null; if (endDef1Type.isTypeOrSuperTypeOf(entityType.getTypeName()) && StringUtils.equals(endDef1.getName(), attribute.getName())) { attributeEndDef = endDef1; } else if (endDef2Type.isTypeOrSuperTypeOf(entityType.getTypeName()) && StringUtils.equals(endDef2.getName(), attribute.getName())) { attributeEndDef = endDef2; } if (attributeEndDef == null) { throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID, relationshipDef.toString()); } switch (attributeEndDef.getCardinality()) { case SINGLE: ret = mapRelatedVertexToObjectId(entityVertex, attribute); break; case LIST: case SET: ret = mapRelationshipArrayAttribute(entityVertex, attribute); break; } return ret; }