Search in sources :

Example 11 with AtlasEntityDef

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

the class TypeConverterUtil method toAtlasEntityDefs.

private static List<AtlasEntityDef> toAtlasEntityDefs(List<HierarchicalTypeDefinition<ClassType>> classTypeDefinitions, AtlasTypeRegistry registry) throws AtlasBaseException {
    List<AtlasEntityDef> atlasEntityDefs = new ArrayList<AtlasEntityDef>();
    for (HierarchicalTypeDefinition<ClassType> classType : classTypeDefinitions) {
        List<AtlasAttributeDef> attrDefs = new ArrayList<AtlasAttributeDef>();
        AtlasEntityDef atlasEntityDef = new AtlasEntityDef();
        String classTypeDefName = classType.typeName;
        atlasEntityDef.setName(classTypeDefName);
        atlasEntityDef.setDescription(classType.typeDescription);
        atlasEntityDef.setTypeVersion(classType.typeVersion);
        atlasEntityDef.setSuperTypes(classType.superTypes);
        AttributeDefinition[] attrDefinitions = classType.attributeDefinitions;
        for (AttributeDefinition oldAttr : attrDefinitions) {
            AtlasAttributeDef newAttr = toAtlasAttributeDef(oldAttr);
            attrDefs.add(newAttr);
        }
        atlasEntityDef.setAttributeDefs(attrDefs);
        atlasEntityDefs.add(atlasEntityDef);
    }
    return atlasEntityDefs;
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) ArrayList(java.util.ArrayList) AttributeDefinition(org.apache.atlas.typesystem.types.AttributeDefinition) ClassType(org.apache.atlas.typesystem.types.ClassType)

Example 12 with AtlasEntityDef

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

the class TestAtlasEntityType method createColumnEntityDefWithInvalidInverseAttributeType.

private AtlasEntityDef createColumnEntityDefWithInvalidInverseAttributeType() {
    AtlasEntityDef column = new AtlasEntityDef(TYPE_COLUMN);
    AtlasAttributeDef attrTable = new AtlasAttributeDef(ATTR_TABLE, TYPE_TABLE);
    Map<String, Object> params = new HashMap<>();
    params.put(AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE, ATTR_NAME);
    attrTable.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF, params));
    column.addAttribute(attrTable);
    return column;
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) HashMap(java.util.HashMap) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) AtlasConstraintDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)

Example 13 with AtlasEntityDef

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

the class TestAtlasEntityType method createColumnEntityDef.

private AtlasEntityDef createColumnEntityDef() {
    AtlasEntityDef column = new AtlasEntityDef(TYPE_COLUMN);
    AtlasAttributeDef attrTable = new AtlasAttributeDef(ATTR_TABLE, TYPE_TABLE);
    Map<String, Object> params = new HashMap<>();
    params.put(AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE, ATTR_COLUMNS);
    attrTable.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF, params));
    column.addAttribute(attrTable);
    return column;
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) HashMap(java.util.HashMap) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) AtlasConstraintDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)

Example 14 with AtlasEntityDef

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

the class TestAtlasEntityType method createColumnEntityDefWithNonExistingInverseAttribute.

private AtlasEntityDef createColumnEntityDefWithNonExistingInverseAttribute() {
    AtlasEntityDef column = new AtlasEntityDef(TYPE_COLUMN);
    AtlasAttributeDef attrTable = new AtlasAttributeDef(ATTR_TABLE, TYPE_TABLE);
    Map<String, Object> params = new HashMap<>();
    params.put(AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE, "non-existing:" + ATTR_COLUMNS);
    attrTable.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF, params));
    column.addAttribute(attrTable);
    return column;
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) HashMap(java.util.HashMap) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) AtlasConstraintDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)

Example 15 with AtlasEntityDef

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

the class TestAtlasEntityType method testConstraintInValidInverseRef_InvalidAttributeTypeForInverseAttribute.

@Test
public void testConstraintInValidInverseRef_InvalidAttributeTypeForInverseAttribute() {
    AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry ttr = null;
    boolean commit = false;
    List<AtlasEntityDef> entityDefs = new ArrayList<>();
    AtlasErrorCode errorCode = null;
    entityDefs.add(createTableEntityDef());
    entityDefs.add(createColumnEntityDefWithInvaidAttributeTypeForInverseAttribute());
    try {
        ttr = typeRegistry.lockTypeRegistryForUpdate();
        ttr.addTypes(entityDefs);
        commit = true;
    } catch (AtlasBaseException excp) {
        errorCode = excp.getAtlasErrorCode();
    } finally {
        typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
    }
    assertEquals(errorCode, AtlasErrorCode.CONSTRAINT_INVERSE_REF_ATTRIBUTE_INVALID_TYPE, "expected invalid constraint failure - missing refAttribute");
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasTransientTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry) ArrayList(java.util.ArrayList) AtlasErrorCode(org.apache.atlas.AtlasErrorCode) Test(org.testng.annotations.Test)

Aggregations

AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)67 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)30 Test (org.testng.annotations.Test)25 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)24 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)24 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)19 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)18 ArrayList (java.util.ArrayList)17 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)17 AtlasConstraintDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)14 HashMap (java.util.HashMap)12 AtlasTransientTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry)9 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)7 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)7 AtlasTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry)7 AtlasEnumElementDef (org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef)6 AtlasErrorCode (org.apache.atlas.AtlasErrorCode)5 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)5 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)5 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)5