Search in sources :

Example 11 with AtlasRelationshipEndDef

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

the class AtlasRelationshipType method addRelationshipEdgeDirection.

private void addRelationshipEdgeDirection() {
    AtlasRelationshipEndDef endDef1 = relationshipDef.getEndDef1();
    AtlasRelationshipEndDef endDef2 = relationshipDef.getEndDef2();
    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)

Example 12 with AtlasRelationshipEndDef

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

the class AtlasRelationshipDefStoreV1 method updateVertexPreCreate.

private void updateVertexPreCreate(AtlasRelationshipDef relationshipDef, AtlasRelationshipType relationshipType, AtlasVertex vertex) throws AtlasBaseException {
    AtlasRelationshipEndDef end1 = relationshipDef.getEndDef1();
    AtlasRelationshipEndDef end2 = relationshipDef.getEndDef2();
    // check whether the names added on the relationship Ends are reserved if required.
    final boolean allowReservedKeywords;
    try {
        allowReservedKeywords = ApplicationProperties.get().getBoolean(ALLOW_RESERVED_KEYWORDS, true);
    } catch (AtlasException e) {
        throw new AtlasBaseException(e);
    }
    if (!allowReservedKeywords) {
        if (QueryParser.isKeyword(end1.getName())) {
            throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_END1_NAME_INVALID, end1.getName());
        }
        if (QueryParser.isKeyword(end2.getName())) {
            throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_END2_NAME_INVALID, end2.getName());
        }
    }
    AtlasStructDefStoreV1.updateVertexPreCreate(relationshipDef, relationshipType, vertex, typeDefStore);
    // Update ends
    setVertexPropertiesFromRelationshipDef(relationshipDef, vertex);
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasException(org.apache.atlas.AtlasException) AtlasRelationshipEndDef(org.apache.atlas.model.typedef.AtlasRelationshipEndDef)

Example 13 with AtlasRelationshipEndDef

use of org.apache.atlas.model.typedef.AtlasRelationshipEndDef 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 AtlasRelationshipEndDef

use of org.apache.atlas.model.typedef.AtlasRelationshipEndDef 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)

Example 15 with AtlasRelationshipEndDef

use of org.apache.atlas.model.typedef.AtlasRelationshipEndDef 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)

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