use of org.apache.atlas.model.typedef.AtlasRelationshipEndDef 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;
}
use of org.apache.atlas.model.typedef.AtlasRelationshipEndDef in project atlas by apache.
the class AtlasRelationshipDefStoreV1Test method updateRename.
@DataProvider
public Object[][] updateRename() {
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("basicType2", "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"));
return new Object[][] { { existingType, newType } };
}
use of org.apache.atlas.model.typedef.AtlasRelationshipEndDef in project atlas by apache.
the class AtlasRelationshipType method resolveReferencesPhase2.
@Override
void resolveReferencesPhase2(AtlasTypeRegistry typeRegistry) throws AtlasBaseException {
super.resolveReferencesPhase2(typeRegistry);
AtlasRelationshipEndDef endDef1 = relationshipDef.getEndDef1();
AtlasRelationshipEndDef endDef2 = relationshipDef.getEndDef2();
String relationshipLabel = null;
// 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();
}
use of org.apache.atlas.model.typedef.AtlasRelationshipEndDef in project atlas by apache.
the class TestAtlasRelationshipType method testvalidateAtlasRelationshipDef.
@Test
public void testvalidateAtlasRelationshipDef() throws AtlasBaseException {
AtlasRelationshipEndDef ep_single = new AtlasRelationshipEndDef("typeA", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE);
AtlasRelationshipEndDef ep_single_container = new AtlasRelationshipEndDef("typeB", "attr2", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE);
AtlasRelationshipEndDef ep_single_container_2 = new AtlasRelationshipEndDef("typeC", "attr3", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE, true);
AtlasRelationshipEndDef ep_single_container_3 = new AtlasRelationshipEndDef("typeD", "attr4", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE, true);
AtlasRelationshipEndDef ep_SET = new AtlasRelationshipEndDef("typeD", "attr4", AtlasStructDef.AtlasAttributeDef.Cardinality.SET, false);
AtlasRelationshipEndDef ep_LIST = new AtlasRelationshipEndDef("typeE", "attr5", AtlasStructDef.AtlasAttributeDef.Cardinality.LIST, true);
AtlasRelationshipEndDef ep_SET_container = new AtlasRelationshipEndDef("typeF", "attr6", AtlasStructDef.AtlasAttributeDef.Cardinality.SET, true);
AtlasRelationshipDef relationshipDef1 = new AtlasRelationshipDef("emptyRelationshipDef", "desc 1", "version1", AtlasRelationshipDef.RelationshipCategory.ASSOCIATION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, ep_single, ep_SET);
AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef1);
AtlasRelationshipDef relationshipDef2 = new AtlasRelationshipDef("emptyRelationshipDef", "desc 1", "version1", AtlasRelationshipDef.RelationshipCategory.COMPOSITION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, ep_SET_container, ep_single);
AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef2);
AtlasRelationshipDef relationshipDef3 = new AtlasRelationshipDef("emptyRelationshipDef", "desc 1", "version1", AtlasRelationshipDef.RelationshipCategory.AGGREGATION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, ep_SET_container, ep_single);
AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef3);
try {
AtlasRelationshipDef relationshipDef = new AtlasRelationshipDef("emptyRelationshipDef", "desc 1", "version1", AtlasRelationshipDef.RelationshipCategory.ASSOCIATION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, ep_single_container_2, ep_single_container);
AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef);
fail("This call is expected to fail");
} catch (AtlasBaseException abe) {
if (!abe.getAtlasErrorCode().equals(AtlasErrorCode.RELATIONSHIPDEF_ASSOCIATION_AND_CONTAINER)) {
fail("This call expected a different error");
}
}
try {
AtlasRelationshipDef relationshipDef = new AtlasRelationshipDef("emptyRelationshipDef", "desc 1", "version1", AtlasRelationshipDef.RelationshipCategory.COMPOSITION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, ep_single, ep_single_container);
AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef);
fail("This call is expected to fail");
} catch (AtlasBaseException abe) {
if (!abe.getAtlasErrorCode().equals(AtlasErrorCode.RELATIONSHIPDEF_COMPOSITION_NO_CONTAINER)) {
fail("This call expected a different error");
}
}
try {
AtlasRelationshipDef relationshipDef = new AtlasRelationshipDef("emptyRelationshipDef", "desc 1", "version1", AtlasRelationshipDef.RelationshipCategory.AGGREGATION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, ep_single, ep_single_container);
AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef);
fail("This call is expected to fail");
} catch (AtlasBaseException abe) {
if (!abe.getAtlasErrorCode().equals(AtlasErrorCode.RELATIONSHIPDEF_AGGREGATION_NO_CONTAINER)) {
fail("This call expected a different error");
}
}
try {
AtlasRelationshipDef relationshipDef = new AtlasRelationshipDef("emptyRelationshipDef", "desc 1", "version1", AtlasRelationshipDef.RelationshipCategory.COMPOSITION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, ep_SET_container, ep_SET);
AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef);
fail("This call is expected to fail");
} catch (AtlasBaseException abe) {
if (!abe.getAtlasErrorCode().equals(AtlasErrorCode.RELATIONSHIPDEF_COMPOSITION_MULTIPLE_PARENTS)) {
fail("This call expected a different error");
}
}
try {
AtlasRelationshipDef relationshipDef = new AtlasRelationshipDef("emptyRelationshipDef", "desc 1", "version1", AtlasRelationshipDef.RelationshipCategory.COMPOSITION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, ep_single, ep_LIST);
AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef);
fail("This call is expected to fail");
} catch (AtlasBaseException abe) {
if (!abe.getAtlasErrorCode().equals(AtlasErrorCode.RELATIONSHIPDEF_LIST_ON_END)) {
fail("This call expected a different error");
}
}
try {
AtlasRelationshipDef relationshipDef = new AtlasRelationshipDef("emptyRelationshipDef", "desc 1", "version1", AtlasRelationshipDef.RelationshipCategory.COMPOSITION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, ep_LIST, ep_single);
AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef);
fail("This call is expected to fail");
} catch (AtlasBaseException abe) {
if (!abe.getAtlasErrorCode().equals(AtlasErrorCode.RELATIONSHIPDEF_LIST_ON_END)) {
fail("This call expected a different error");
}
}
}
use of org.apache.atlas.model.typedef.AtlasRelationshipEndDef in project atlas by apache.
the class TestAtlasRelationshipType method testRelationshipAttributesOnExistingAttributes.
@Test(dependsOnMethods = "testRelationshipAttributes")
public void testRelationshipAttributesOnExistingAttributes() throws Exception {
AtlasRelationshipDef employeePhoneRelationDef = new AtlasRelationshipDef(EMPLOYEE_PHONE_RELATION_TYPE, getDescription(EMPLOYEE_PHONE_RELATION_TYPE), "1.0", RelationshipCategory.ASSOCIATION, PropagateTags.ONE_TO_TWO, new AtlasRelationshipEndDef(EMPLOYEE_TYPE, "phone_no", Cardinality.SINGLE), new AtlasRelationshipEndDef(PHONE_TYPE, "owner", Cardinality.SINGLE));
createType(employeePhoneRelationDef);
Map<String, AtlasAttribute> employeeRelationshipAttrs = getRelationAttrsForType(EMPLOYEE_TYPE);
Map<String, AtlasAttribute> employeeAttrs = getAttrsForType(EMPLOYEE_TYPE);
// validate if phone_no exists in both relationAttributes and attributes
Assert.assertTrue(employeeRelationshipAttrs.containsKey("phone_no"));
Assert.assertTrue(employeeAttrs.containsKey("phone_no"));
}
Aggregations