Search in sources :

Example 11 with AtlasRelationshipDef

use of org.apache.atlas.model.typedef.AtlasRelationshipDef 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"));
}
Also used : AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasRelationshipDef(org.apache.atlas.model.typedef.AtlasRelationshipDef) AtlasRelationshipEndDef(org.apache.atlas.model.typedef.AtlasRelationshipEndDef) Test(org.testng.annotations.Test)

Example 12 with AtlasRelationshipDef

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

the class AtlasRelationshipDefStoreV1 method create.

@Override
public AtlasRelationshipDef create(AtlasRelationshipDef relationshipDef, Object preCreateResult) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasRelationshipDefStoreV1.create({}, {})", relationshipDef, preCreateResult);
    }
    AtlasVertex vertex;
    if (preCreateResult == null || !(preCreateResult instanceof AtlasVertex)) {
        vertex = preCreate(relationshipDef);
    } else {
        vertex = (AtlasVertex) preCreateResult;
    }
    AtlasRelationshipDef ret = toRelationshipDef(vertex);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasRelationshipDefStoreV1.create({}, {}): {}", relationshipDef, preCreateResult, ret);
    }
    return ret;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasRelationshipDef(org.apache.atlas.model.typedef.AtlasRelationshipDef)

Example 13 with AtlasRelationshipDef

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

Example 14 with AtlasRelationshipDef

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

the class AtlasRelationshipDefStoreV1 method getByGuid.

@Override
public AtlasRelationshipDef getByGuid(String guid) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasRelationshipDefStoreV1.getByGuid({})", guid);
    }
    AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.RELATIONSHIP);
    if (vertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
    }
    AtlasRelationshipDef ret = toRelationshipDef(vertex);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasRelationshipDefStoreV1.getByGuid({}): {}", guid, ret);
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasRelationshipDef(org.apache.atlas.model.typedef.AtlasRelationshipDef)

Example 15 with AtlasRelationshipDef

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

the class AtlasRelationshipDefStoreV1Test method updateEnd2.

@DataProvider
public Object[][] updateEnd2() {
    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("typeC", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), new AtlasRelationshipEndDef("typeE", "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", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), new AtlasRelationshipEndDef("typeD", "attr2", 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.SINGLE), new AtlasRelationshipEndDef("typeD", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.LIST), AtlasTypeUtil.createRequiredAttrDef("aaaa", "string"), AtlasTypeUtil.createRequiredAttrDef("bbbb", "string"));
    return new Object[][] { { existingType, changeType }, { existingType, changeAttr }, { existingType, changeCardinality } };
}
Also used : AtlasRelationshipDef(org.apache.atlas.model.typedef.AtlasRelationshipDef) AtlasRelationshipEndDef(org.apache.atlas.model.typedef.AtlasRelationshipEndDef) DataProvider(org.testng.annotations.DataProvider)

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