Search in sources :

Example 26 with AtlasRelationshipEndDef

use of org.apache.atlas.model.typedef.AtlasRelationshipEndDef in project atlas by apache.

the class TestRelationshipUtilsV2 method getDepartmentEmployeeTypes.

public static AtlasTypesDef getDepartmentEmployeeTypes() throws AtlasBaseException {
    /**
     ***** Person Type ******
     */
    AtlasEntityDef personType = createClassTypeDef(PERSON_TYPE, description(PERSON_TYPE), superType(null), createUniqueRequiredAttrDef("name", "string"), createOptionalAttrDef("address", ADDRESS_TYPE), createOptionalAttrDef("birthday", "date"), createOptionalAttrDef("hasPets", "boolean"), createOptionalAttrDef("numberOfCars", "byte"), createOptionalAttrDef("houseNumber", "short"), createOptionalAttrDef("carMileage", "int"), createOptionalAttrDef("age", "float"), createOptionalAttrDef("numberOfStarsEstimate", "biginteger"), createOptionalAttrDef("approximationOfPi", "bigdecimal"));
    /**
     ***** Employee Type ******
     */
    AtlasEntityDef employeeType = createClassTypeDef(EMPLOYEE_TYPE, description(EMPLOYEE_TYPE), superType(PERSON_TYPE), createOptionalAttrDef("orgLevel", ORG_LEVEL_TYPE), createOptionalAttrDef("shares", "long"), createOptionalAttrDef("salary", "double"));
    /**
     ***** Department Type ******
     */
    AtlasEntityDef departmentType = createClassTypeDef(DEPARTMENT_TYPE, description(DEPARTMENT_TYPE), superType(null), createUniqueRequiredAttrDef("name", "string"));
    /**
     ***** Manager Type ******
     */
    AtlasEntityDef managerType = createClassTypeDef(MANAGER_TYPE, description(MANAGER_TYPE), superType(EMPLOYEE_TYPE));
    /**
     ***** Address Type ******
     */
    AtlasStructDef addressType = createStructTypeDef(ADDRESS_TYPE, description(ADDRESS_TYPE), createRequiredAttrDef("street", "string"), createRequiredAttrDef("city", "string"));
    /**
     ***** Organization Level Type ******
     */
    AtlasEnumDef orgLevelType = new AtlasEnumDef(ORG_LEVEL_TYPE, description(ORG_LEVEL_TYPE), DEFAULT_VERSION, getOrgLevelElements());
    /**
     ***** Security Clearance Type ******
     */
    AtlasClassificationDef securityClearanceType = createTraitTypeDef(SECURITY_CLEARANCE_TYPE, description(SECURITY_CLEARANCE_TYPE), superType(null), createRequiredAttrDef("level", "int"));
    /**
     ***** [Department -> Employee] Relationship ******
     */
    AtlasRelationshipDef employeeDepartmentType = new AtlasRelationshipDef(EMPLOYEE_DEPARTMENT_TYPE, description(EMPLOYEE_DEPARTMENT_TYPE), DEFAULT_VERSION, AGGREGATION, ONE_TO_TWO, new AtlasRelationshipEndDef(EMPLOYEE_TYPE, "department", SINGLE), new AtlasRelationshipEndDef(DEPARTMENT_TYPE, "employees", SET, true));
    /**
     ***** [Manager -> Employee] Relationship ******
     */
    AtlasRelationshipDef employeeManagerType = new AtlasRelationshipDef(EMPLOYEE_MANAGER_TYPE, description(EMPLOYEE_MANAGER_TYPE), DEFAULT_VERSION, AGGREGATION, ONE_TO_TWO, new AtlasRelationshipEndDef(EMPLOYEE_TYPE, "manager", SINGLE), new AtlasRelationshipEndDef(MANAGER_TYPE, "subordinates", SET, true));
    /**
     ***** [Mentors -> Employee] Relationship ******
     */
    AtlasRelationshipDef employeeMentorsType = new AtlasRelationshipDef(EMPLOYEE_MENTORS_TYPE, description(EMPLOYEE_MENTORS_TYPE), DEFAULT_VERSION, AGGREGATION, ONE_TO_TWO, new AtlasRelationshipEndDef(EMPLOYEE_TYPE, "mentors", SET), new AtlasRelationshipEndDef(EMPLOYEE_TYPE, "mentees", SET, true));
    /**
     ***** [Friends -> Employee] Relationship ******
     */
    AtlasRelationshipDef employeeFriendsType = new AtlasRelationshipDef(EMPLOYEE_FRIENDS_TYPE, description(EMPLOYEE_FRIENDS_TYPE), DEFAULT_VERSION, ASSOCIATION, ONE_TO_TWO, new AtlasRelationshipEndDef(EMPLOYEE_TYPE, "friends", SET), new AtlasRelationshipEndDef(EMPLOYEE_TYPE, "friends", SET));
    /**
     ***** [Person -> Sibling] Relationship ******
     */
    AtlasRelationshipDef personSiblingType = new AtlasRelationshipDef(PERSON_SIBLING_TYPE, description(PERSON_SIBLING_TYPE), DEFAULT_VERSION, ASSOCIATION, BOTH, new AtlasRelationshipEndDef(PERSON_TYPE, "sibling", SINGLE), new AtlasRelationshipEndDef(PERSON_TYPE, "sibling", SINGLE));
    return new AtlasTypesDef(Collections.singletonList(orgLevelType), Collections.singletonList(addressType), Collections.singletonList(securityClearanceType), Arrays.asList(personType, employeeType, departmentType, managerType), Arrays.asList(employeeDepartmentType, employeeManagerType, employeeMentorsType, employeeFriendsType, personSiblingType));
}
Also used : AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasRelationshipDef(org.apache.atlas.model.typedef.AtlasRelationshipDef) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef) AtlasRelationshipEndDef(org.apache.atlas.model.typedef.AtlasRelationshipEndDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef)

Example 27 with AtlasRelationshipEndDef

use of org.apache.atlas.model.typedef.AtlasRelationshipEndDef in project atlas by apache.

the class TestRelationshipUtilsV2 method getInverseReferenceTestTypes.

public static AtlasTypesDef getInverseReferenceTestTypes() throws AtlasBaseException {
    AtlasEntityDef aType = createClassTypeDef(TYPE_A, superType(null), createUniqueRequiredAttrDef("name", "string"));
    AtlasEntityDef bType = createClassTypeDef(TYPE_B, superType(null), createUniqueRequiredAttrDef("name", "string"));
    AtlasRelationshipDef relationshipType1 = new AtlasRelationshipDef("TypeA_to_TypeB_on_b", description("TypeA_to_TypeB_on_b"), DEFAULT_VERSION, ASSOCIATION, ONE_TO_TWO, new AtlasRelationshipEndDef(TYPE_A, "b", SINGLE), new AtlasRelationshipEndDef(TYPE_B, "a", SINGLE));
    AtlasRelationshipDef relationshipType2 = new AtlasRelationshipDef("TypeA_to_TypeB_on_oneB", description("TypeA_to_TypeB_on_oneB"), DEFAULT_VERSION, ASSOCIATION, ONE_TO_TWO, new AtlasRelationshipEndDef(TYPE_A, "oneB", SINGLE), new AtlasRelationshipEndDef(TYPE_B, "manyA", SET));
    AtlasRelationshipDef relationshipType3 = new AtlasRelationshipDef("TypeA_to_TypeB_on_manyB", description("TypeA_to_TypeB_on_manyB"), DEFAULT_VERSION, ASSOCIATION, ONE_TO_TWO, new AtlasRelationshipEndDef(TYPE_A, "manyB", SET), new AtlasRelationshipEndDef(TYPE_B, "manyToManyA", SET));
    AtlasRelationshipDef relationshipType4 = new AtlasRelationshipDef("TypeB_to_TypeA_on_mappedFromA", description("TypeB_to_TypeA_on_mappedFromA"), DEFAULT_VERSION, ASSOCIATION, ONE_TO_TWO, new AtlasRelationshipEndDef(TYPE_B, "mappedFromA", SINGLE), new AtlasRelationshipEndDef(TYPE_A, "mapToB", SET));
    return new AtlasTypesDef(Collections.<AtlasEnumDef>emptyList(), Collections.<AtlasStructDef>emptyList(), Collections.<AtlasClassificationDef>emptyList(), Arrays.asList(aType, bType), Arrays.asList(relationshipType1, relationshipType2, relationshipType3, relationshipType4));
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasRelationshipDef(org.apache.atlas.model.typedef.AtlasRelationshipDef) AtlasRelationshipEndDef(org.apache.atlas.model.typedef.AtlasRelationshipEndDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef)

Example 28 with AtlasRelationshipEndDef

use of org.apache.atlas.model.typedef.AtlasRelationshipEndDef in project atlas by apache.

the class TestAtlasRelationshipType method createRelationshipTypes.

private void createRelationshipTypes() throws AtlasBaseException {
    AtlasRelationshipDef deptEmployeeRelationDef = new AtlasRelationshipDef(DEPT_EMPLOYEE_RELATION_TYPE, getDescription(DEPT_EMPLOYEE_RELATION_TYPE), "1.0", RelationshipCategory.ASSOCIATION, PropagateTags.ONE_TO_TWO, new AtlasRelationshipEndDef(EMPLOYEE_TYPE, "department", Cardinality.SINGLE), new AtlasRelationshipEndDef(DEPARTMENT_TYPE, "employees", Cardinality.SET));
    AtlasRelationshipDef employeeAddrRelationDef = new AtlasRelationshipDef(EMPLOYEE_ADDRESS_RELATION_TYPE, getDescription(EMPLOYEE_ADDRESS_RELATION_TYPE), "1.0", RelationshipCategory.ASSOCIATION, PropagateTags.ONE_TO_TWO, new AtlasRelationshipEndDef(EMPLOYEE_TYPE, "address", Cardinality.SINGLE), new AtlasRelationshipEndDef(ADDRESS_TYPE, "employees", Cardinality.SET));
    createTypes(new ArrayList<>(Arrays.asList(deptEmployeeRelationDef, employeeAddrRelationDef)));
}
Also used : AtlasRelationshipDef(org.apache.atlas.model.typedef.AtlasRelationshipDef) AtlasRelationshipEndDef(org.apache.atlas.model.typedef.AtlasRelationshipEndDef)

Example 29 with AtlasRelationshipEndDef

use of org.apache.atlas.model.typedef.AtlasRelationshipEndDef in project atlas by apache.

the class AtlasRelationshipType method validateAtlasRelationshipDef.

/**
 * Throw an exception so we can junit easily.
 *
 * This method assumes that the 2 ends are not null.
 *
 * @param relationshipDef
 * @throws AtlasBaseException
 */
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) {
        // we support 0 or 1 of these flags.
        throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_DOUBLE_CONTAINERS, name);
    }
    if ((isContainer1 || isContainer2)) {
        // we have an isContainer defined in an end
        if (relationshipCategory == RelationshipCategory.ASSOCIATION) {
            // associations are not containment relationships - so do not allow an endpoint with isContainer
            throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_ASSOCIATION_AND_CONTAINER, name);
        }
    } else {
        // we do not have an isContainer defined on an end
        if (relationshipCategory == RelationshipCategory.COMPOSITION) {
            // COMPOSITION needs one end to be the container.
            throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_COMPOSITION_NO_CONTAINER, name);
        } else if (relationshipCategory == RelationshipCategory.AGGREGATION) {
            // AGGREGATION needs one end to be the container.
            throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_AGGREGATION_NO_CONTAINER, name);
        }
    }
    if (relationshipCategory == RelationshipCategory.COMPOSITION) {
        // composition children should not be multiple cardinality
        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);
        }
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasRelationshipEndDef(org.apache.atlas.model.typedef.AtlasRelationshipEndDef) RelationshipCategory(org.apache.atlas.model.typedef.AtlasRelationshipDef.RelationshipCategory)

Example 30 with AtlasRelationshipEndDef

use of org.apache.atlas.model.typedef.AtlasRelationshipEndDef in project atlas by apache.

the class AtlasRelationshipType method addRelationshipEdgeDirection.

private void addRelationshipEdgeDirection() {
    AtlasRelationshipEndDef endDef1 = relationshipDef.getEndDef1();
    AtlasRelationshipEndDef endDef2 = relationshipDef.getEndDef2();
    if (StringUtils.equals(endDef1.getType(), endDef2.getType()) && StringUtils.equals(endDef1.getName(), endDef2.getName())) {
        AtlasAttribute endAttribute = end1Type.getRelationshipAttribute(endDef1.getName());
        endAttribute.setRelationshipEdgeDirection(BOTH);
    } else {
        AtlasAttribute end1Attribute = end1Type.getRelationshipAttribute(endDef1.getName());
        AtlasAttribute end2Attribute = end2Type.getRelationshipAttribute(endDef2.getName());
        // default relationship edge direction is end1 (out) -> end2 (in)
        AtlasRelationshipEdgeDirection end1Direction = OUT;
        AtlasRelationshipEdgeDirection end2Direction = IN;
        if (endDef1.getIsLegacyAttribute() && endDef2.getIsLegacyAttribute()) {
            end2Direction = OUT;
        } else if (!endDef1.getIsLegacyAttribute() && endDef2.getIsLegacyAttribute()) {
            end1Direction = IN;
            end2Direction = OUT;
        }
        end1Attribute.setRelationshipEdgeDirection(end1Direction);
        end2Attribute.setRelationshipEdgeDirection(end2Direction);
    }
}
Also used : AtlasRelationshipEdgeDirection(org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdgeDirection) AtlasRelationshipEndDef(org.apache.atlas.model.typedef.AtlasRelationshipEndDef)

Aggregations

AtlasRelationshipEndDef (org.apache.atlas.model.typedef.AtlasRelationshipEndDef)40 AtlasRelationshipDef (org.apache.atlas.model.typedef.AtlasRelationshipDef)25 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)13 DataProvider (org.testng.annotations.DataProvider)10 RelationshipCategory (org.apache.atlas.model.typedef.AtlasRelationshipDef.RelationshipCategory)6 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)4 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)4 AtlasAttribute (org.apache.atlas.type.AtlasStructType.AtlasAttribute)4 Test (org.testng.annotations.Test)4 PropagateTags (org.apache.atlas.model.typedef.AtlasRelationshipDef.PropagateTags)3 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)3 AtlasRelationshipType (org.apache.atlas.type.AtlasRelationshipType)3 AtlasException (org.apache.atlas.AtlasException)2 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)2 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)2 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)2 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)2 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)2 AtlasRelationshipEdgeDirection (org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdgeDirection)2 AtlasType (org.apache.atlas.type.AtlasType)2