boolean isContainer2 = endDef2.getIsContainer(); if ((endDef1.getCardinality() == AtlasAttributeDef.Cardinality.LIST) || (endDef2.getCardinality() == AtlasAttributeDef.Cardinality.LIST)) { throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_LIST_ON_END, name); if (endDef1.getCardinality() == AtlasAttributeDef.Cardinality.SET && !endDef1.getIsContainer()) { throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_COMPOSITION_MULTIPLE_PARENTS, name); if ((endDef2.getCardinality() == AtlasAttributeDef.Cardinality.SET) && !endDef2.getIsContainer()) { throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_COMPOSITION_MULTIPLE_PARENTS, name);
boolean isContainer2 = endDef2.getIsContainer(); if ((endDef1.getCardinality() == AtlasAttributeDef.Cardinality.LIST) || (endDef2.getCardinality() == AtlasAttributeDef.Cardinality.LIST)) { throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_LIST_ON_END, name); if (endDef1.getCardinality() == AtlasAttributeDef.Cardinality.SET && !endDef1.getIsContainer()) { throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_COMPOSITION_MULTIPLE_PARENTS, name); if ((endDef2.getCardinality() == AtlasAttributeDef.Cardinality.SET) && !endDef2.getIsContainer()) { throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_COMPOSITION_MULTIPLE_PARENTS, name);
/** * 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 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); }
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; }