Search in sources :

Example 1 with AtlasAttributeDef

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

the class TestAtlasTypeRegistry method testClassificationDefValidHierarchy.

/*
     *             L0
     *          /      \
     *         /         \
     *      L1_1----      L1_2
     *      /  \    \    /   \
     *     /    \    \  /     \
     *   L2_1  L2_2   L2_3   L2_4
     */
@Test
public void testClassificationDefValidHierarchy() {
    AtlasClassificationDef classifiL0 = new AtlasClassificationDef("L0");
    AtlasClassificationDef classifiL1_1 = new AtlasClassificationDef("L1-1");
    AtlasClassificationDef classifiL1_2 = new AtlasClassificationDef("L1-2");
    AtlasClassificationDef classifiL2_1 = new AtlasClassificationDef("L2-1");
    AtlasClassificationDef classifiL2_2 = new AtlasClassificationDef("L2-2");
    AtlasClassificationDef classifiL2_3 = new AtlasClassificationDef("L2-3");
    AtlasClassificationDef classifiL2_4 = new AtlasClassificationDef("L2-4");
    classifiL1_1.addSuperType(classifiL0.getName());
    classifiL1_2.addSuperType(classifiL0.getName());
    classifiL2_1.addSuperType(classifiL1_1.getName());
    classifiL2_2.addSuperType(classifiL1_1.getName());
    classifiL2_3.addSuperType(classifiL1_1.getName());
    classifiL2_3.addSuperType(classifiL1_2.getName());
    classifiL2_4.addSuperType(classifiL1_2.getName());
    classifiL0.addAttribute(new AtlasAttributeDef("L0_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    classifiL1_1.addAttribute(new AtlasAttributeDef("L1-1_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    classifiL1_2.addAttribute(new AtlasAttributeDef("L1-2_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    classifiL2_1.addAttribute(new AtlasAttributeDef("L2-1_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    classifiL2_2.addAttribute(new AtlasAttributeDef("L2-2_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    classifiL2_3.addAttribute(new AtlasAttributeDef("L2-3_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    classifiL2_4.addAttribute(new AtlasAttributeDef("L2-4_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    AtlasTypesDef typesDef = new AtlasTypesDef();
    typesDef.getClassificationDefs().add(classifiL0);
    typesDef.getClassificationDefs().add(classifiL1_1);
    typesDef.getClassificationDefs().add(classifiL1_2);
    typesDef.getClassificationDefs().add(classifiL2_1);
    typesDef.getClassificationDefs().add(classifiL2_2);
    typesDef.getClassificationDefs().add(classifiL2_3);
    typesDef.getClassificationDefs().add(classifiL2_4);
    AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry ttr = null;
    boolean commit = false;
    String failureMsg = null;
    try {
        ttr = typeRegistry.lockTypeRegistryForUpdate();
        ttr.addTypes(typesDef);
        commit = true;
    } catch (AtlasBaseException excp) {
        failureMsg = excp.getMessage();
    } finally {
        typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
    }
    assertNull(failureMsg);
    validateSuperTypes(typeRegistry, "L0", new HashSet<String>());
    validateSuperTypes(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L0")));
    validateSuperTypes(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L0")));
    validateSuperTypes(typeRegistry, "L2-1", new HashSet<>(Arrays.asList("L1-1", "L0")));
    validateSuperTypes(typeRegistry, "L2-2", new HashSet<>(Arrays.asList("L1-1", "L0")));
    validateSuperTypes(typeRegistry, "L2-3", new HashSet<>(Arrays.asList("L1-1", "L0", "L1-2")));
    validateSuperTypes(typeRegistry, "L2-4", new HashSet<>(Arrays.asList("L1-2", "L0")));
    validateSubTypes(typeRegistry, "L0", new HashSet<>(Arrays.asList("L1-1", "L1-2", "L2-1", "L2-2", "L2-3", "L2-4")));
    validateSubTypes(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L2-1", "L2-2", "L2-3")));
    validateSubTypes(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L2-3", "L2-4")));
    validateSubTypes(typeRegistry, "L2-1", new HashSet<String>());
    validateSubTypes(typeRegistry, "L2-2", new HashSet<String>());
    validateSubTypes(typeRegistry, "L2-3", new HashSet<String>());
    validateSubTypes(typeRegistry, "L2-4", new HashSet<String>());
    validateAttributeNames(typeRegistry, "L0", new HashSet<>(Arrays.asList("L0_a1")));
    validateAttributeNames(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L0_a1", "L1-1_a1")));
    validateAttributeNames(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L0_a1", "L1-2_a1")));
    validateAttributeNames(typeRegistry, "L2-1", new HashSet<>(Arrays.asList("L0_a1", "L1-1_a1", "L2-1_a1")));
    validateAttributeNames(typeRegistry, "L2-2", new HashSet<>(Arrays.asList("L0_a1", "L1-1_a1", "L2-2_a1")));
    validateAttributeNames(typeRegistry, "L2-3", new HashSet<>(Arrays.asList("L0_a1", "L1-1_a1", "L1-2_a1", "L2-3_a1")));
    validateAttributeNames(typeRegistry, "L2-4", new HashSet<>(Arrays.asList("L0_a1", "L1-2_a1", "L2-4_a1")));
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) AtlasTransientTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry) Test(org.testng.annotations.Test)

Example 2 with AtlasAttributeDef

use of org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef 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 3 with AtlasAttributeDef

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

the class TestAtlasStructType method testInvalidStructDef_MultiValuedAttributeNotArray.

@Test
public void testInvalidStructDef_MultiValuedAttributeNotArray() {
    AtlasAttributeDef invalidMultiValuedAttrib = new AtlasAttributeDef("invalidAttributeDef", ATLAS_TYPE_INT);
    invalidMultiValuedAttrib.setCardinality(Cardinality.LIST);
    AtlasStructDef invalidStructDef = ModelTestUtil.newStructDef();
    invalidStructDef.addAttribute(invalidMultiValuedAttrib);
    try {
        AtlasStructType invalidStructType = new AtlasStructType(invalidStructDef, ModelTestUtil.getTypesRegistry());
        fail("invalidStructDef not detected: structDef=" + invalidStructDef + "; structType=" + invalidStructType);
    } catch (AtlasBaseException excp) {
        assertTrue(excp.getAtlasErrorCode() == AtlasErrorCode.INVALID_ATTRIBUTE_TYPE_FOR_CARDINALITY);
        invalidStructDef.removeAttribute("invalidAttributeDef");
    }
}
Also used : AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) Test(org.testng.annotations.Test)

Example 4 with AtlasAttributeDef

use of org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef 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 5 with AtlasAttributeDef

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

Aggregations

AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)52 AtlasConstraintDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)19 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)17 HashMap (java.util.HashMap)14 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)13 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)12 ArrayList (java.util.ArrayList)11 Test (org.testng.annotations.Test)10 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)9 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)8 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)7 AttributeDefinition (org.apache.atlas.typesystem.types.AttributeDefinition)5 AtlasEnumElementDef (org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef)4 Map (java.util.Map)3 AtlasAttribute (org.apache.atlas.type.AtlasStructType.AtlasAttribute)3 AtlasTransientTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)2 AtlasStruct (org.apache.atlas.model.instance.AtlasStruct)2 ClassType (org.apache.atlas.typesystem.types.ClassType)2