@Override public int hashCode() { return Objects.hash(type, getName(), description, isContainer, cardinality, isLegacyAttribute); }
@Override public int hashCode() { return Objects.hash(type, getName(), isContainer, cardinality, isLegacyAttribute); }
private static String getKey(AtlasRelationshipEndDef endDef) { return getKey(endDef.getIsLegacyAttribute(), endDef.getType(), endDef.getName()); }
private void updateVertexPreCreate(AtlasRelationshipDef relationshipDef, AtlasRelationshipType relationshipType, AtlasVertex vertex) throws AtlasBaseException { AtlasRelationshipEndDef end1 = relationshipDef.getEndDef1(); AtlasRelationshipEndDef end2 = relationshipDef.getEndDef2(); // check whether the names added on the relationship Ends are reserved if required. final boolean allowReservedKeywords; try { allowReservedKeywords = ApplicationProperties.get().getBoolean(ALLOW_RESERVED_KEYWORDS, true); } catch (AtlasException e) { throw new AtlasBaseException(e); } if (!allowReservedKeywords) { if (AtlasDSL.Parser.isKeyword(end1.getName())) { throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_END1_NAME_INVALID, end1.getName()); } if (AtlasDSL.Parser.isKeyword(end2.getName())) { throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_END2_NAME_INVALID, end2.getName()); } } AtlasStructDefStoreV2.updateVertexPreCreate(relationshipDef, relationshipType, vertex, typeDefStore); // Update ends setVertexPropertiesFromRelationshipDef(relationshipDef, vertex); }
private void updateVertexPreCreate(AtlasRelationshipDef relationshipDef, AtlasRelationshipType relationshipType, AtlasVertex vertex) throws AtlasBaseException { AtlasRelationshipEndDef end1 = relationshipDef.getEndDef1(); AtlasRelationshipEndDef end2 = relationshipDef.getEndDef2(); // check whether the names added on the relationship Ends are reserved if required. final boolean allowReservedKeywords; try { allowReservedKeywords = ApplicationProperties.get().getBoolean(ALLOW_RESERVED_KEYWORDS, true); } catch (AtlasException e) { throw new AtlasBaseException(e); } if (!allowReservedKeywords) { if (AtlasDSL.Parser.isKeyword(end1.getName())) { throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_END1_NAME_INVALID, end1.getName()); } if (AtlasDSL.Parser.isKeyword(end2.getName())) { throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_END2_NAME_INVALID, end2.getName()); } } AtlasStructDefStoreV2.updateVertexPreCreate(relationshipDef, relationshipType, vertex, typeDefStore); // Update ends setVertexPropertiesFromRelationshipDef(relationshipDef, vertex); }
private void addRelationshipEdgeDirection() { AtlasRelationshipEndDef endDef1 = relationshipDef.getEndDef1(); AtlasRelationshipEndDef endDef2 = relationshipDef.getEndDef2(); if (StringUtils.equals(endDef1.getType(), endDef2.getType()) && StringUtils.equals(endDef1.getName(), endDef2.getName())) { AtlasAttribute endAttribute = end1Type.getRelationshipAttribute(endDef1.getName()); endAttribute.setRelationshipEdgeDirection(BOTH); } else { AtlasAttribute end1Attribute = end1Type.getRelationshipAttribute(endDef1.getName()); AtlasAttribute end2Attribute = end2Type.getRelationshipAttribute(endDef2.getName()); //default relationship edge direction is end1 (out) -> end2 (in) AtlasRelationshipEdgeDirection end1Direction = OUT; AtlasRelationshipEdgeDirection end2Direction = IN; if (endDef1.getIsLegacyAttribute() && endDef2.getIsLegacyAttribute()) { end2Direction = OUT; } else if (!endDef1.getIsLegacyAttribute() && endDef2.getIsLegacyAttribute()) { end1Direction = IN; end2Direction = OUT; } end1Attribute.setRelationshipEdgeDirection(end1Direction); end2Attribute.setRelationshipEdgeDirection(end2Direction); } }
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; } }
String attrName = endDefs.get(i).getName();
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 addRelationshipEdgeDirection() { AtlasRelationshipEndDef endDef1 = relationshipDef.getEndDef1(); AtlasRelationshipEndDef endDef2 = relationshipDef.getEndDef2(); AtlasAttribute end1Attribute = end1Type.getRelationshipAttribute(endDef1.getName()); AtlasAttribute end2Attribute = end2Type.getRelationshipAttribute(endDef2.getName()); //default relationship edge direction is end1 (out) -> end2 (in) AtlasRelationshipEdgeDirection end1Direction = OUT; AtlasRelationshipEdgeDirection end2Direction = IN; if (endDef1.getIsLegacyAttribute() && endDef2.getIsLegacyAttribute()) { end2Direction = OUT; } else if (!endDef1.getIsLegacyAttribute() && endDef2.getIsLegacyAttribute()) { end1Direction = IN; end2Direction = OUT; } end1Attribute.setRelationshipEdgeDirection(end1Direction); end2Attribute.setRelationshipEdgeDirection(end2Direction); }
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; }
/** * Construct using an existing AtlasRelationshipEndDef * @param other */ public AtlasRelationshipEndDef(AtlasRelationshipEndDef other) { if (other != null) { setType(other.getType()); setName(other.getName()); setIsContainer(other.getIsContainer()); setCardinality(other.getCardinality()); setIsLegacyAttribute(other.isLegacyAttribute); } }
/** * Construct using an existing AtlasRelationshipEndDef * @param other */ public AtlasRelationshipEndDef(AtlasRelationshipEndDef other) { if (other != null) { setType(other.getType()); setName(other.getName()); setIsContainer(other.getIsContainer()); setCardinality(other.getCardinality()); setIsLegacyAttribute(other.isLegacyAttribute); setDescription(other.description); } }
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; }
private void addRelationshipAttributeToEndType(AtlasRelationshipEndDef endDef, AtlasEntityType entityType, String attrTypeName, AtlasTypeRegistry typeRegistry, String relationshipLabel) throws AtlasBaseException { String attrName = (endDef != null) ? endDef.getName() : null; if (StringUtils.isEmpty(attrName)) { return; } AtlasAttribute attribute = entityType.getAttribute(attrName); // if relationshipLabel is null, then legacyLabel is mentioned at both ends, // use the respective end's legacyLabel as relationshipLabel if (relationshipLabel == null) { relationshipLabel = getLegacyEdgeLabel(entityType, attrName); } if (attribute == null) { //attr doesn't exist in type - is a new relationship attribute if (endDef.getCardinality() == Cardinality.SET) { attrTypeName = AtlasBaseTypeDef.getArrayTypeName(attrTypeName); } attribute = new AtlasAttribute(entityType, new AtlasAttributeDef(attrName, attrTypeName), typeRegistry.getType(attrTypeName), relationshipLabel); } else { // attribute already exists (legacy attribute which is also a relationship attribute) // add relationshipLabel information to existing attribute attribute.setRelationshipEdgeLabel(relationshipLabel); } entityType.addRelationshipAttribute(attrName, attribute); entityType.addRelationshipAttributeType(attrName, this); }
private void addRelationshipAttributeToEndType(AtlasRelationshipEndDef endDef, AtlasEntityType entityType, String attrTypeName, AtlasTypeRegistry typeRegistry, String relationshipLabel) throws AtlasBaseException { String attrName = (endDef != null) ? endDef.getName() : null; if (StringUtils.isEmpty(attrName)) { return; } AtlasAttribute attribute = entityType.getAttribute(attrName); // if relationshipLabel is null, then legacyLabel is mentioned at both ends, // use the respective end's legacyLabel as relationshipLabel if (relationshipLabel == null) { relationshipLabel = getLegacyEdgeLabel(entityType, attrName); } if (attribute == null) { //attr doesn't exist in type - is a new relationship attribute if (endDef.getCardinality() == Cardinality.SET) { attrTypeName = AtlasBaseTypeDef.getArrayTypeName(attrTypeName); } attribute = new AtlasAttribute(entityType, new AtlasAttributeDef(attrName, attrTypeName), typeRegistry.getType(attrTypeName), relationshipLabel); } else { // attribute already exists (legacy attribute which is also a relationship attribute) // add relationshipLabel information to existing attribute attribute.setRelationshipEdgeLabel(relationshipLabel); } entityType.addRelationshipAttribute(attrName, attribute); entityType.addRelationshipAttributeType(attrName, this); }
@Override void resolveReferencesPhase2(AtlasTypeRegistry typeRegistry) throws AtlasBaseException { super.resolveReferencesPhase2(typeRegistry); AtlasRelationshipEndDef endDef1 = relationshipDef.getEndDef1(); AtlasRelationshipEndDef endDef2 = relationshipDef.getEndDef2(); String relationshipLabel = null; // if legacyLabel is not specified at both ends, use relationshipDef name as relationship label. // if legacyLabel is specified in any one end, use it as the relationship label for both ends (legacy case). // if legacyLabel is specified at both ends use the respective end's legacyLabel as relationship label (legacy case). if (!endDef1.getIsLegacyAttribute() && !endDef2.getIsLegacyAttribute()) { relationshipLabel = relationshipDef.getRelationshipLabel(); } else if (endDef1.getIsLegacyAttribute() && !endDef2.getIsLegacyAttribute()) { relationshipLabel = getLegacyEdgeLabel(end1Type, endDef1.getName()); } else if (!endDef1.getIsLegacyAttribute() && endDef2.getIsLegacyAttribute()) { relationshipLabel = getLegacyEdgeLabel(end2Type, endDef2.getName()); } addRelationshipAttributeToEndType(endDef1, end1Type, end2Type.getTypeName(), typeRegistry, relationshipLabel); addRelationshipAttributeToEndType(endDef2, end2Type, end1Type.getTypeName(), typeRegistry, relationshipLabel); // add relationship edge direction information addRelationshipEdgeDirection(); }
@Override public void resolveReferencesPhase2(AtlasTypeRegistry typeRegistry) throws AtlasBaseException { super.resolveReferencesPhase2(typeRegistry); AtlasRelationshipEndDef endDef1 = relationshipDef.getEndDef1(); AtlasRelationshipEndDef endDef2 = relationshipDef.getEndDef2(); String relationshipLabel = null; // if legacyLabel is not specified at both ends, use relationshipDef name as relationship label. // if legacyLabel is specified in any one end, use it as the relationship label for both ends (legacy case). // if legacyLabel is specified at both ends use the respective end's legacyLabel as relationship label (legacy case). if (!endDef1.getIsLegacyAttribute() && !endDef2.getIsLegacyAttribute()) { relationshipLabel = relationshipDef.getRelationshipLabel(); } else if (endDef1.getIsLegacyAttribute() && !endDef2.getIsLegacyAttribute()) { relationshipLabel = getLegacyEdgeLabel(end1Type, endDef1.getName()); } else if (!endDef1.getIsLegacyAttribute() && endDef2.getIsLegacyAttribute()) { relationshipLabel = getLegacyEdgeLabel(end2Type, endDef2.getName()); } addRelationshipAttributeToEndType(endDef1, end1Type, end2Type.getTypeName(), typeRegistry, relationshipLabel); addRelationshipAttributeToEndType(endDef2, end2Type, end1Type.getTypeName(), typeRegistry, relationshipLabel); // add relationship edge direction information addRelationshipEdgeDirection(); }