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;
}
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);
}
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");
}
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");
}
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;
}
Aggregations