use of org.apache.atlas.model.typedef.AtlasRelationshipDef in project incubator-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);
}
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 incubator-atlas by apache.
the class AtlasRelationshipDefStoreV1 method updateByGuid.
@Override
public AtlasRelationshipDef updateByGuid(String guid, AtlasRelationshipDef relationshipDef) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasRelationshipDefStoreV1.updateByGuid({})", guid);
}
validateType(relationshipDef);
AtlasType type = typeRegistry.getTypeByGuid(guid);
if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.RELATIONSHIP) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, relationshipDef.getName(), TypeCategory.RELATIONSHIP.name());
}
AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.RELATIONSHIP);
if (vertex == null) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
}
preUpdateCheck(relationshipDef, (AtlasRelationshipType) type, vertex);
// updates should not effect the edges between the types as we do not allow updates that change the endpoints.
AtlasRelationshipDef ret = toRelationshipDef(vertex);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasRelationshipDefStoreV1.updateByGuid({}): {}", guid, ret);
}
return ret;
}
use of org.apache.atlas.model.typedef.AtlasRelationshipDef in project incubator-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 incubator-atlas by apache.
the class AtlasRelationshipDefStoreV1 method preUpdateCheck.
private void preUpdateCheck(AtlasRelationshipDef newRelationshipDef, AtlasRelationshipType relationshipType, AtlasVertex vertex) throws AtlasBaseException {
// We will not support an update to endpoints or category key
AtlasRelationshipDef existingRelationshipDef = toRelationshipDef(vertex);
preUpdateCheck(newRelationshipDef, existingRelationshipDef);
// we do allow change to tag propagation and the addition of new attributes.
AtlasStructDefStoreV1.updateVertexPreUpdate(newRelationshipDef, relationshipType, vertex, typeDefStore);
setVertexPropertiesFromRelationshipDef(newRelationshipDef, vertex);
}
use of org.apache.atlas.model.typedef.AtlasRelationshipDef in project incubator-atlas by apache.
the class GraphHelper method getRelationshipDef.
public AtlasRelationshipDef getRelationshipDef(AtlasVertex entityVertex, AtlasEntityType entityType, String attributeName) {
List<AtlasRelationshipType> relationshipTypes = entityType.getRelationshipAttributeType(attributeName);
AtlasRelationshipDef ret = null;
if (relationshipTypes.size() > 1) {
Iterator<AtlasEdge> iter = entityVertex.getEdges(AtlasEdgeDirection.IN).iterator();
while (iter.hasNext() && ret == null) {
String edgeTypeName = AtlasGraphUtilsV1.getTypeName(iter.next());
for (AtlasRelationshipType relationType : relationshipTypes) {
AtlasRelationshipDef relationshipDef = relationType.getRelationshipDef();
if (StringUtils.equals(edgeTypeName, relationshipDef.getName())) {
ret = relationshipDef;
break;
}
}
}
if (ret == null) {
ret = relationshipTypes.get(0).getRelationshipDef();
}
} else {
// relationshipTypes will have at least one relationshipDef
ret = relationshipTypes.get(0).getRelationshipDef();
}
return ret;
}
Aggregations