Search in sources :

Example 16 with AtlasRelationshipDef

use of org.apache.atlas.model.typedef.AtlasRelationshipDef in project incubator-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 } };
}
Also used : AtlasRelationshipDef(org.apache.atlas.model.typedef.AtlasRelationshipDef) AtlasRelationshipEndDef(org.apache.atlas.model.typedef.AtlasRelationshipEndDef) DataProvider(org.testng.annotations.DataProvider)

Example 17 with AtlasRelationshipDef

use of org.apache.atlas.model.typedef.AtlasRelationshipDef in project incubator-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));
    /**
     ***** [Mentor -> Employee] Relationship ******
     */
    AtlasRelationshipDef employeeMentorType = new AtlasRelationshipDef(EMPLOYEE_MENTOR_TYPE, description(EMPLOYEE_MENTOR_TYPE), DEFAULT_VERSION, ASSOCIATION, ONE_TO_TWO, new AtlasRelationshipEndDef(EMPLOYEE_TYPE, "mentor", SINGLE), new AtlasRelationshipEndDef(EMPLOYEE_TYPE, "mentees", SET));
    return new AtlasTypesDef(ImmutableList.of(orgLevelType), ImmutableList.of(addressType), ImmutableList.of(securityClearanceType), ImmutableList.of(personType, employeeType, departmentType, managerType), ImmutableList.of(employeeDepartmentType, employeeManagerType, employeeMentorType));
}
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 18 with AtlasRelationshipDef

use of org.apache.atlas.model.typedef.AtlasRelationshipDef in project incubator-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(ImmutableList.<AtlasEnumDef>of(), ImmutableList.<AtlasStructDef>of(), ImmutableList.<AtlasClassificationDef>of(), ImmutableList.of(aType, bType), ImmutableList.of(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 19 with AtlasRelationshipDef

use of org.apache.atlas.model.typedef.AtlasRelationshipDef in project incubator-atlas by apache.

the class EntityGraphRetriever method mapVertexToRelationshipAttribute.

private Object mapVertexToRelationshipAttribute(AtlasVertex entityVertex, AtlasEntityType entityType, AtlasAttribute attribute) throws AtlasBaseException {
    Object ret = null;
    AtlasRelationshipDef relationshipDef = graphHelper.getRelationshipDef(entityVertex, entityType, attribute.getName());
    if (relationshipDef == null) {
        throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID, "relationshipDef is null");
    }
    AtlasRelationshipEndDef endDef1 = relationshipDef.getEndDef1();
    AtlasRelationshipEndDef endDef2 = relationshipDef.getEndDef2();
    AtlasEntityType endDef1Type = typeRegistry.getEntityTypeByName(endDef1.getType());
    AtlasEntityType endDef2Type = typeRegistry.getEntityTypeByName(endDef2.getType());
    AtlasRelationshipEndDef attributeEndDef = null;
    if (endDef1Type.isTypeOrSuperTypeOf(entityType.getTypeName()) && StringUtils.equals(endDef1.getName(), attribute.getName())) {
        attributeEndDef = endDef1;
    } else if (endDef2Type.isTypeOrSuperTypeOf(entityType.getTypeName()) && StringUtils.equals(endDef2.getName(), attribute.getName())) {
        attributeEndDef = endDef2;
    }
    if (attributeEndDef == null) {
        throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID, relationshipDef.toString());
    }
    switch(attributeEndDef.getCardinality()) {
        case SINGLE:
            ret = mapRelatedVertexToObjectId(entityVertex, attribute);
            break;
        case LIST:
        case SET:
            ret = mapRelationshipArrayAttribute(entityVertex, attribute);
            break;
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasRelationshipDef(org.apache.atlas.model.typedef.AtlasRelationshipDef) AtlasRelationshipEndDef(org.apache.atlas.model.typedef.AtlasRelationshipEndDef)

Example 20 with AtlasRelationshipDef

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

the class TypesREST method getRelationshipDefByGuid.

/**
 * Get the relationship definition for the given guid
 * @param guid relationship guid
 * @return relationship definition
 * @throws AtlasBaseException
 * @HTTP 200 On successful lookup of the the relationship definition by it's guid
 * @HTTP 404 On Failed lookup for the given guid
 */
@GET
@Path("/relationshipdef/guid/{guid}")
@Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasRelationshipDef getRelationshipDefByGuid(@PathParam("guid") String guid) throws AtlasBaseException {
    Servlets.validateQueryParamLength("guid", guid);
    AtlasRelationshipDef ret = typeDefStore.getRelationshipDefByGuid(guid);
    return ret;
}
Also used : AtlasRelationshipDef(org.apache.atlas.model.typedef.AtlasRelationshipDef)

Aggregations

AtlasRelationshipDef (org.apache.atlas.model.typedef.AtlasRelationshipDef)46 AtlasRelationshipEndDef (org.apache.atlas.model.typedef.AtlasRelationshipEndDef)25 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)15 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)13 DataProvider (org.testng.annotations.DataProvider)10 AtlasTypeAccessRequest (org.apache.atlas.authorize.AtlasTypeAccessRequest)5 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)4 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)4 AtlasType (org.apache.atlas.type.AtlasType)4 Test (org.testng.annotations.Test)4 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)3 AtlasRelationshipType (org.apache.atlas.type.AtlasRelationshipType)3 AtlasAttribute (org.apache.atlas.type.AtlasStructType.AtlasAttribute)3 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)2 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)2 PropagateTags (org.apache.atlas.model.typedef.AtlasRelationshipDef.PropagateTags)2 RelationshipCategory (org.apache.atlas.model.typedef.AtlasRelationshipDef.RelationshipCategory)2 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)2 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)2 ArrayList (java.util.ArrayList)1