use of org.apache.atlas.model.typedef.AtlasRelationshipDef in project atlas by apache.
the class AtlasRelationshipStoreV1 method getRelationshipEdgeLabel.
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;
}
use of org.apache.atlas.model.typedef.AtlasRelationshipDef in project atlas by apache.
the class EntityGraphRetriever method mapVertexToRelationshipAttribute.
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;
}
use of org.apache.atlas.model.typedef.AtlasRelationshipDef in project atlas by apache.
the class AtlasRelationshipDefStoreV1 method update.
@Override
public AtlasRelationshipDef update(AtlasRelationshipDef relationshipDef) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasRelationshipDefStoreV1.update({})", relationshipDef);
}
validateType(relationshipDef);
AtlasRelationshipDef ret = StringUtils.isNotBlank(relationshipDef.getGuid()) ? updateByGuid(relationshipDef.getGuid(), relationshipDef) : updateByName(relationshipDef.getName(), relationshipDef);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasRelationshipDefStoreV1.update({}): {}", relationshipDef, ret);
}
return ret;
}
use of org.apache.atlas.model.typedef.AtlasRelationshipDef in project atlas by apache.
the class AtlasRelationshipDefStoreV1 method updateByName.
@Override
public AtlasRelationshipDef updateByName(String name, AtlasRelationshipDef relationshipDef) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasRelationshipDefStoreV1.updateByName({}, {})", name, relationshipDef);
}
AtlasRelationshipDef existingDef = typeRegistry.getRelationshipDefByName(name);
AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_UPDATE, existingDef), "update relationship-def ", name);
validateType(relationshipDef);
AtlasType type = typeRegistry.getType(relationshipDef.getName());
if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.RELATIONSHIP) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, relationshipDef.getName(), TypeCategory.RELATIONSHIP.name());
}
AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.RELATIONSHIP);
if (vertex == null) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
}
preUpdateCheck(relationshipDef, (AtlasRelationshipType) type, vertex);
AtlasRelationshipDef ret = toRelationshipDef(vertex);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasRelationshipDefStoreV1.updateByName({}, {}): {}", name, relationshipDef, ret);
}
return ret;
}
use of org.apache.atlas.model.typedef.AtlasRelationshipDef in project atlas by apache.
the class AtlasRelationshipDefStoreV1 method toRelationshipDef.
private AtlasRelationshipDef toRelationshipDef(AtlasVertex vertex) throws AtlasBaseException {
AtlasRelationshipDef ret = null;
if (vertex != null && typeDefStore.isTypeVertex(vertex, TypeCategory.RELATIONSHIP)) {
String name = vertex.getProperty(Constants.TYPENAME_PROPERTY_KEY, String.class);
String description = vertex.getProperty(Constants.TYPEDESCRIPTION_PROPERTY_KEY, String.class);
String version = vertex.getProperty(Constants.TYPEVERSION_PROPERTY_KEY, String.class);
String end1Str = vertex.getProperty(Constants.RELATIONSHIPTYPE_END1_KEY, String.class);
String end2Str = vertex.getProperty(Constants.RELATIONSHIPTYPE_END2_KEY, String.class);
String relationStr = vertex.getProperty(Constants.RELATIONSHIPTYPE_CATEGORY_KEY, String.class);
String propagateStr = vertex.getProperty(Constants.RELATIONSHIPTYPE_TAG_PROPAGATION_KEY, String.class);
// set the ends
AtlasRelationshipEndDef endDef1 = AtlasType.fromJson(end1Str, AtlasRelationshipEndDef.class);
AtlasRelationshipEndDef endDef2 = AtlasType.fromJson(end2Str, AtlasRelationshipEndDef.class);
// set the relationship Category
RelationshipCategory relationshipCategory = null;
for (RelationshipCategory value : RelationshipCategory.values()) {
if (value.name().equals(relationStr)) {
relationshipCategory = value;
}
}
// set the propagateTags
PropagateTags propagateTags = null;
for (PropagateTags value : PropagateTags.values()) {
if (value.name().equals(propagateStr)) {
propagateTags = value;
}
}
ret = new AtlasRelationshipDef(name, description, version, relationshipCategory, propagateTags, endDef1, endDef2);
// add in the attributes
AtlasStructDefStoreV1.toStructDef(vertex, ret, typeDefStore);
}
return ret;
}
Aggregations