AtlasRelationshipType extends AtlasStructType { public static void validateAtlasRelationshipDef(AtlasRelationshipDef relationshipDef) throws AtlasBaseException { AtlasRelationshipEndDef endDef1 = relationshipDef.getEndDef1(); AtlasRelationshipEndDef endDef2 = relationshipDef.getEndDef2(); RelationshipCategory relationshipCategory = relationshipDef.getRelationshipCategory(); String name = relationshipDef.getName(); boolean isContainer1 = endDef1.getIsContainer(); 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 (isContainer1 && isContainer2) { throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_DOUBLE_CONTAINERS, name); } if ((isContainer1 || isContainer2)) { if (relationshipCategory == RelationshipCategory.ASSOCIATION) { throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_ASSOCIATION_AND_CONTAINER, name); } } else { if (relationshipCategory == RelationshipCategory.COMPOSITION) { throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_COMPOSITION_NO_CONTAINER, name); } else if (relationshipCategory == RelationshipCategory.AGGREGATION) { throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_AGGREGATION_NO_CONTAINER, name); } } if (relationshipCategory == RelationshipCategory.COMPOSITION) { 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); } } } AtlasRelationshipType(AtlasRelationshipDef relationshipDef);  AtlasRelationshipType(AtlasRelationshipDef relationshipDef, AtlasTypeRegistry typeRegistry); AtlasRelationshipDef getRelationshipDef(); @Override void resolveReferences(AtlasTypeRegistry typeRegistry); @Override void resolveReferencesPhase2(AtlasTypeRegistry typeRegistry); @Override boolean isValidValue(Object obj); @Override boolean isValidValueForUpdate(Object obj); AtlasEntityType getEnd1Type(); AtlasEntityType getEnd2Type(); static void validateAtlasRelationshipDef(AtlasRelationshipDef relationshipDef);  }
@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"); } } }