Search in sources :

Example 96 with AtlasEntityDef

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

the class TestUtilsV2 method defineInvalidUpdatedDeptEmployeeTypes.

public static AtlasTypesDef defineInvalidUpdatedDeptEmployeeTypes() {
    String _description = "_description_updated";
    // Test ordinal changes
    AtlasEnumDef orgLevelEnum = new AtlasEnumDef("OrgLevel", "OrgLevel" + _description, "1.0", Arrays.asList(new AtlasEnumElementDef("L2", "Element" + _description, 1), new AtlasEnumElementDef("L1", "Element" + _description, 2), new AtlasEnumElementDef("L3", "Element" + _description, 3)));
    AtlasStructDef addressDetails = createStructTypeDef("Address", "Address" + _description, AtlasTypeUtil.createRequiredAttrDef("street", "string"), AtlasTypeUtil.createRequiredAttrDef("city", "string"), AtlasTypeUtil.createRequiredAttrDef("zip", "int"));
    AtlasEntityDef deptTypeDef = AtlasTypeUtil.createClassTypeDef(DEPARTMENT_TYPE, "Department" + _description, Collections.<String>emptySet(), AtlasTypeUtil.createRequiredAttrDef("name", "string"), AtlasTypeUtil.createRequiredAttrDef("dep-code", "string"), new AtlasAttributeDef("employees", String.format("array<%s>", "Person"), true, AtlasAttributeDef.Cardinality.SINGLE, 0, 1, false, false, new ArrayList<AtlasStructDef.AtlasConstraintDef>() {

        {
            add(new AtlasStructDef.AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_OWNED_REF));
        }
    }));
    AtlasEntityDef personTypeDef = AtlasTypeUtil.createClassTypeDef("Person", "Person" + _description, Collections.<String>emptySet(), AtlasTypeUtil.createRequiredAttrDef("name", "string"), AtlasTypeUtil.createRequiredAttrDef("emp-code", "string"), AtlasTypeUtil.createOptionalAttrDef("orgLevel", "OrgLevel"), AtlasTypeUtil.createOptionalAttrDef("address", "Address"), new AtlasAttributeDef("department", "Department", false, AtlasAttributeDef.Cardinality.SINGLE, 1, 1, false, false, Collections.<AtlasConstraintDef>emptyList()), new AtlasAttributeDef("manager", "Manager", true, AtlasAttributeDef.Cardinality.SINGLE, 0, 1, false, false, new ArrayList<AtlasConstraintDef>() {

        {
            add(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF, new HashMap<String, Object>() {

                {
                    put(AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE, "subordinates");
                }
            }));
        }
    }), new AtlasAttributeDef("mentor", "Person", true, AtlasAttributeDef.Cardinality.SINGLE, 0, 1, false, false, Collections.<AtlasConstraintDef>emptyList()), AtlasTypeUtil.createOptionalAttrDef("birthday", "date"), AtlasTypeUtil.createOptionalAttrDef("hasPets", "boolean"), AtlasTypeUtil.createOptionalAttrDef("numberOfCars", "byte"), AtlasTypeUtil.createOptionalAttrDef("houseNumber", "short"), AtlasTypeUtil.createOptionalAttrDef("carMileage", "int"), AtlasTypeUtil.createOptionalAttrDef("shares", "long"), AtlasTypeUtil.createOptionalAttrDef("salary", "double"), AtlasTypeUtil.createRequiredAttrDef("age", "float"), AtlasTypeUtil.createOptionalAttrDef("numberOfStarsEstimate", "biginteger"), AtlasTypeUtil.createOptionalAttrDef("approximationOfPi", "bigdecimal"));
    AtlasTypesDef ret = new AtlasTypesDef(Collections.singletonList(orgLevelEnum), Collections.singletonList(addressDetails), Collections.<AtlasClassificationDef>emptyList(), Arrays.asList(deptTypeDef, personTypeDef));
    populateSystemAttributes(ret);
    return ret;
}
Also used : AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasEnumElementDef(org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef) 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) ArrayList(java.util.ArrayList) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef) AtlasConstraintDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef)

Example 97 with AtlasEntityDef

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

the class TestAtlasEntityType method testValidConstraints.

@Test
public void testValidConstraints() {
    AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry ttr = null;
    boolean commit = false;
    List<AtlasEntityDef> entityDefs = new ArrayList<>();
    String failureMsg = null;
    entityDefs.add(createTableEntityDef());
    entityDefs.add(createColumnEntityDef());
    try {
        ttr = typeRegistry.lockTypeRegistryForUpdate();
        ttr.addTypes(entityDefs);
        AtlasEntityType typeTable = ttr.getEntityTypeByName(TYPE_TABLE);
        AtlasEntityType typeColumn = ttr.getEntityTypeByName(TYPE_COLUMN);
        assertTrue(typeTable.getAttribute(ATTR_COLUMNS).isOwnedRef());
        assertNull(typeTable.getAttribute(ATTR_COLUMNS).getInverseRefAttributeName());
        assertFalse(typeColumn.getAttribute(ATTR_TABLE).isOwnedRef());
        assertEquals(typeColumn.getAttribute(ATTR_TABLE).getInverseRefAttributeName(), ATTR_COLUMNS);
        assertEquals(typeColumn.getAttribute(ATTR_TABLE).getInverseRefAttribute(), typeTable.getAttribute(ATTR_COLUMNS));
        commit = true;
    } catch (AtlasBaseException excp) {
        failureMsg = excp.getMessage();
    } finally {
        typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
    }
    assertNull(failureMsg, "failed to create types " + TYPE_TABLE + " and " + TYPE_COLUMN);
}
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) Test(org.testng.annotations.Test)

Example 98 with AtlasEntityDef

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

the class TestAtlasEntityType method testConstraintInValidInverseRef_NonExistingAttribute.

@Test
public void testConstraintInValidInverseRef_NonExistingAttribute() {
    AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry ttr = null;
    boolean commit = false;
    List<AtlasEntityDef> entityDefs = new ArrayList<>();
    AtlasErrorCode errorCode = null;
    entityDefs.add(createTableEntityDef());
    entityDefs.add(createColumnEntityDefWithNonExistingInverseAttribute());
    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_INVERSE_ATTRIBUTE_NON_EXISTING, "expected invalid constraint failure - non-existing 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)

Example 99 with AtlasEntityDef

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

Example 100 with AtlasEntityDef

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

the class TestAtlasEntityType method createColumnEntityDefWithMissingInverseAttribute.

private AtlasEntityDef createColumnEntityDefWithMissingInverseAttribute() {
    AtlasEntityDef column = new AtlasEntityDef(TYPE_COLUMN);
    AtlasAttributeDef attrTable = new AtlasAttributeDef(ATTR_TABLE, TYPE_TABLE);
    attrTable.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF));
    column.addAttribute(attrTable);
    return column;
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) AtlasConstraintDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)

Aggregations

AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)141 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)55 Test (org.testng.annotations.Test)51 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)40 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)37 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)35 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)31 AtlasConstraintDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)31 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)30 ArrayList (java.util.ArrayList)29 HashMap (java.util.HashMap)21 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)14 AtlasEnumElementDef (org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef)13 AtlasTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry)13 AtlasTransientTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry)13 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)12 AtlasErrorCode (org.apache.atlas.AtlasErrorCode)11 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)9 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)8 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)8