use of org.apache.atlas.model.typedef.AtlasRelationshipDef in project 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);
}
AtlasRelationshipDef existingDef = typeRegistry.getRelationshipDefByGuid(guid);
AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_UPDATE, existingDef), "update relationship-Def ", (existingDef != null ? existingDef.getName() : 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 atlas by apache.
the class AtlasRelationshipStoreV1 method validateEnds.
/**
* Validate the ends of the passed relationship
* @param relationship
* @throws AtlasBaseException
*/
private void validateEnds(AtlasRelationship relationship) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("validateEnds entry relationship:" + relationship);
}
List<AtlasObjectId> ends = new ArrayList<>();
List<AtlasRelationshipEndDef> endDefs = new ArrayList<>();
String relationshipTypeName = relationship.getTypeName();
AtlasRelationshipDef relationshipDef = typeRegistry.getRelationshipDefByName(relationshipTypeName);
ends.add(relationship.getEnd1());
ends.add(relationship.getEnd2());
endDefs.add(relationshipDef.getEndDef1());
endDefs.add(relationshipDef.getEndDef2());
for (int i = 0; i < ends.size(); i++) {
AtlasObjectId end = ends.get(i);
String guid = end.getGuid();
String typeName = end.getTypeName();
Map<String, Object> uniqueAttributes = end.getUniqueAttributes();
AtlasVertex endVertex = AtlasGraphUtilsV1.findByGuid(guid);
if (!AtlasTypeUtil.isValidGuid(guid) || endVertex == null) {
throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
} else if (MapUtils.isNotEmpty(uniqueAttributes)) {
AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName);
if (AtlasGraphUtilsV1.findByUniqueAttributes(entityType, uniqueAttributes) == null) {
throw new AtlasBaseException(AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND, typeName, uniqueAttributes.toString());
}
} else {
// check whether the guid is the correct type
String vertexTypeName = endVertex.getProperty(Constants.TYPE_NAME_PROPERTY_KEY, String.class);
if (!Objects.equals(vertexTypeName, typeName)) {
String attrName = endDefs.get(i).getName();
throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_INVALID_ENDTYPE, attrName, guid, vertexTypeName, typeName);
}
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("validateEnds exit successfully validated relationship:" + relationship);
}
}
use of org.apache.atlas.model.typedef.AtlasRelationshipDef in project atlas by apache.
the class AtlasRelationshipDefStoreV1Test method updateValidProperties.
@DataProvider
public Object[][] updateValidProperties() {
AtlasRelationshipDef existingType = AtlasTypeUtil.createRelationshipTypeDef("basicType", "description", "0", AtlasRelationshipDef.RelationshipCategory.ASSOCIATION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, new AtlasRelationshipEndDef("typeC", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), new AtlasRelationshipEndDef("typeD", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), AtlasTypeUtil.createRequiredAttrDef("aaaa", "string"), AtlasTypeUtil.createRequiredAttrDef("bbbb", "string"));
AtlasRelationshipDef newType = AtlasTypeUtil.createRelationshipTypeDef("basicType", // updated
"description1", // updated
"1", AtlasRelationshipDef.RelationshipCategory.ASSOCIATION, // updated
AtlasRelationshipDef.PropagateTags.BOTH, new AtlasRelationshipEndDef("typeC", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), new AtlasRelationshipEndDef("typeD", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), AtlasTypeUtil.createRequiredAttrDef("aaaa", "string"), AtlasTypeUtil.createRequiredAttrDef("bbbb", "string"));
return new Object[][] { { existingType, newType } };
}
use of org.apache.atlas.model.typedef.AtlasRelationshipDef in project atlas by apache.
the class AtlasRelationshipDefStoreV1Test method updateRelCat.
@DataProvider
public Object[][] updateRelCat() {
AtlasRelationshipDef existingType = AtlasTypeUtil.createRelationshipTypeDef("basicType", "description", "", AtlasRelationshipDef.RelationshipCategory.ASSOCIATION, AtlasRelationshipDef.PropagateTags.BOTH, new AtlasRelationshipEndDef("typeC", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), new AtlasRelationshipEndDef("typeD", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), AtlasTypeUtil.createRequiredAttrDef("aaaa", "string"), AtlasTypeUtil.createRequiredAttrDef("bbbb", "string"));
AtlasRelationshipDef newType = AtlasTypeUtil.createRelationshipTypeDef("basicType", "description", "", AtlasRelationshipDef.RelationshipCategory.AGGREGATION, AtlasRelationshipDef.PropagateTags.BOTH, new AtlasRelationshipEndDef("typeC", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), new AtlasRelationshipEndDef("typeD", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), AtlasTypeUtil.createRequiredAttrDef("aaaa", "string"), AtlasTypeUtil.createRequiredAttrDef("bbbb", "string"));
return new Object[][] { { existingType, newType } };
}
use of org.apache.atlas.model.typedef.AtlasRelationshipDef in project atlas by apache.
the class AtlasRelationshipDefStoreV1Test method updateEnd1.
@DataProvider
public Object[][] updateEnd1() {
AtlasRelationshipDef existingType = AtlasTypeUtil.createRelationshipTypeDef("basicType", "description", "", AtlasRelationshipDef.RelationshipCategory.ASSOCIATION, AtlasRelationshipDef.PropagateTags.BOTH, new AtlasRelationshipEndDef("typeC", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), new AtlasRelationshipEndDef("typeD", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), AtlasTypeUtil.createRequiredAttrDef("aaaa", "string"), AtlasTypeUtil.createRequiredAttrDef("bbbb", "string"));
AtlasRelationshipDef changeType = AtlasTypeUtil.createRelationshipTypeDef("basicType", "description", "", AtlasRelationshipDef.RelationshipCategory.ASSOCIATION, AtlasRelationshipDef.PropagateTags.BOTH, new AtlasRelationshipEndDef("typeE", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), new AtlasRelationshipEndDef("typeD", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), AtlasTypeUtil.createRequiredAttrDef("aaaa", "string"), AtlasTypeUtil.createRequiredAttrDef("bbbb", "string"));
AtlasRelationshipDef changeAttr = AtlasTypeUtil.createRelationshipTypeDef("basicType", "description", "", AtlasRelationshipDef.RelationshipCategory.ASSOCIATION, AtlasRelationshipDef.PropagateTags.BOTH, new AtlasRelationshipEndDef("typeC", "attr2", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), new AtlasRelationshipEndDef("typeD", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), AtlasTypeUtil.createRequiredAttrDef("aaaa", "string"), AtlasTypeUtil.createRequiredAttrDef("bbbb", "string"));
AtlasRelationshipDef changeCardinality = AtlasTypeUtil.createRelationshipTypeDef("basicType", "description", "", AtlasRelationshipDef.RelationshipCategory.ASSOCIATION, AtlasRelationshipDef.PropagateTags.BOTH, new AtlasRelationshipEndDef("typeC", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.LIST), new AtlasRelationshipEndDef("typeD", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), AtlasTypeUtil.createRequiredAttrDef("aaaa", "string"), AtlasTypeUtil.createRequiredAttrDef("bbbb", "string"));
return new Object[][] { { existingType, changeType }, { existingType, changeAttr }, { existingType, changeCardinality } };
}
Aggregations