private void addRelationshipType(AtlasRelationshipType relationshipType, ExportService.ExportContext context) { if (!context.relationshipTypes.contains(relationshipType.getTypeName())) { context.relationshipTypes.add(relationshipType.getTypeName()); addAttributeTypes(relationshipType, context); addEntityType(relationshipType.getEnd1Type(), context); addEntityType(relationshipType.getEnd2Type(), context); } }
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 String getRelationshipEdgeLabel(String typeName, String relationshipTypeName) { AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationshipTypeName); AtlasRelationshipDef relationshipDef = relationshipType.getRelationshipDef(); AtlasEntityType end1Type = relationshipType.getEnd1Type(); AtlasEntityType end2Type = relationshipType.getEnd2Type(); Set<String> vertexTypes = getTypeAndAllSuperTypes(typeName); AtlasAttribute attribute = null; if (vertexTypes.contains(end1Type.getTypeName())) { String attributeName = relationshipDef.getEndDef1().getName(); attribute = (attributeName != null) ? end1Type.getAttribute(attributeName) : null; } else if (vertexTypes.contains(end2Type.getTypeName())) { String attributeName = relationshipDef.getEndDef2().getName(); attribute = (attributeName != null) ? end2Type.getAttribute(attributeName) : null; } return (attribute != null) ? attribute.getRelationshipEdgeLabel() : null; }
private String getRelationshipEdgeLabel(String typeName, String relationshipTypeName) { AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationshipTypeName); AtlasRelationshipDef relationshipDef = relationshipType.getRelationshipDef(); AtlasEntityType end1Type = relationshipType.getEnd1Type(); AtlasEntityType end2Type = relationshipType.getEnd2Type(); Set<String> vertexTypes = getTypeAndAllSuperTypes(typeName); AtlasAttribute attribute = null; if (vertexTypes.contains(end1Type.getTypeName())) { String attributeName = relationshipDef.getEndDef1().getName(); attribute = (attributeName != null) ? end1Type.getAttribute(attributeName) : null; } else if (vertexTypes.contains(end2Type.getTypeName())) { String attributeName = relationshipDef.getEndDef2().getName(); attribute = (attributeName != null) ? end2Type.getAttribute(attributeName) : null; } return (attribute != null) ? attribute.getRelationshipEdgeLabel() : null; } }
private String getRelationshipEdgeLabel(AtlasVertex fromVertex, AtlasVertex toVertex, String relationshipTypeName) { if (LOG.isDebugEnabled()) { LOG.debug("getRelationshipEdgeLabel({})", relationshipTypeName); } AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationshipTypeName); String ret = relationshipType.getRelationshipDef().getRelationshipLabel(); AtlasRelationshipEndDef endDef1 = relationshipType.getRelationshipDef().getEndDef1(); AtlasRelationshipEndDef endDef2 = relationshipType.getRelationshipDef().getEndDef2(); Set<String> fromVertexTypes = getTypeAndAllSuperTypes(AtlasGraphUtilsV2.getTypeName(fromVertex)); Set<String> toVertexTypes = getTypeAndAllSuperTypes(AtlasGraphUtilsV2.getTypeName(toVertex)); AtlasAttribute attribute = null; // validate entity type and all its supertypes contains relationshipDefs end type // e.g. [hive_process -> hive_table] -> [Process -> DataSet] if (fromVertexTypes.contains(endDef1.getType()) && toVertexTypes.contains(endDef2.getType())) { String attributeName = endDef1.getName(); attribute = relationshipType.getEnd1Type().getRelationshipAttribute(attributeName); } else if (fromVertexTypes.contains(endDef2.getType()) && toVertexTypes.contains(endDef1.getType())) { String attributeName = endDef2.getName(); attribute = relationshipType.getEnd2Type().getRelationshipAttribute(attributeName); } if (attribute != null) { ret = attribute.getRelationshipEdgeLabel(); } return ret; }
private String getRelationshipEdgeLabel(AtlasVertex fromVertex, AtlasVertex toVertex, String relationshipTypeName) { if (LOG.isDebugEnabled()) { LOG.debug("getRelationshipEdgeLabel({})", relationshipTypeName); } AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationshipTypeName); String ret = relationshipType.getRelationshipDef().getRelationshipLabel(); AtlasRelationshipEndDef endDef1 = relationshipType.getRelationshipDef().getEndDef1(); AtlasRelationshipEndDef endDef2 = relationshipType.getRelationshipDef().getEndDef2(); Set<String> fromVertexTypes = getTypeAndAllSuperTypes(AtlasGraphUtilsV2.getTypeName(fromVertex)); Set<String> toVertexTypes = getTypeAndAllSuperTypes(AtlasGraphUtilsV2.getTypeName(toVertex)); AtlasAttribute attribute = null; // validate entity type and all its supertypes contains relationshipDefs end type // e.g. [hive_process -> hive_table] -> [Process -> DataSet] if (fromVertexTypes.contains(endDef1.getType()) && toVertexTypes.contains(endDef2.getType())) { String attributeName = endDef1.getName(); attribute = relationshipType.getEnd1Type().getRelationshipAttribute(attributeName); } else if (fromVertexTypes.contains(endDef2.getType()) && toVertexTypes.contains(endDef1.getType())) { String attributeName = endDef2.getName(); attribute = relationshipType.getEnd2Type().getRelationshipAttribute(attributeName); } if (attribute != null) { ret = attribute.getRelationshipEdgeLabel(); } return ret; }
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); }