use of org.apache.atlas.model.typedef.AtlasTypesDef in project incubator-atlas by apache.
the class TestUtilsV2 method defineDeptEmployeeTypes.
/**
* Class Hierarchy is:
* Department(name : String, employees : Array[Person])
* Person(name : String, department : Department, manager : Manager)
* Manager(subordinates : Array[Person]) extends Person
* <p/>
* Persons can have SecurityClearance(level : Int) clearance.
*/
public static AtlasTypesDef defineDeptEmployeeTypes() {
String _description = "_description";
AtlasEnumDef orgLevelEnum = new AtlasEnumDef("OrgLevel", "OrgLevel" + _description, "1.0", Arrays.asList(new AtlasEnumElementDef("L1", "Element" + _description, 1), new AtlasEnumElementDef("L2", "Element" + _description, 2)));
AtlasStructDef addressDetails = createStructTypeDef("Address", "Address" + _description, AtlasTypeUtil.createRequiredAttrDef("street", "string"), AtlasTypeUtil.createRequiredAttrDef("city", "string"));
AtlasEntityDef deptTypeDef = AtlasTypeUtil.createClassTypeDef(DEPARTMENT_TYPE, "Department" + _description, ImmutableSet.<String>of(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"), new AtlasAttributeDef("employees", String.format("array<%s>", "Employee"), 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, ImmutableSet.<String>of(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"), AtlasTypeUtil.createOptionalAttrDef("address", "Address"), AtlasTypeUtil.createOptionalAttrDef("birthday", "date"), AtlasTypeUtil.createOptionalAttrDef("hasPets", "boolean"), AtlasTypeUtil.createOptionalAttrDef("numberOfCars", "byte"), AtlasTypeUtil.createOptionalAttrDef("houseNumber", "short"), AtlasTypeUtil.createOptionalAttrDef("carMileage", "int"), AtlasTypeUtil.createOptionalAttrDef("age", "float"), AtlasTypeUtil.createOptionalAttrDef("numberOfStarsEstimate", "biginteger"), AtlasTypeUtil.createOptionalAttrDef("approximationOfPi", "bigdecimal"));
AtlasEntityDef employeeTypeDef = AtlasTypeUtil.createClassTypeDef("Employee", "Employee" + _description, ImmutableSet.of("Person"), AtlasTypeUtil.createOptionalAttrDef("orgLevel", "OrgLevel"), new AtlasAttributeDef("department", "Department", false, AtlasAttributeDef.Cardinality.SINGLE, 1, 1, false, false, new ArrayList<AtlasConstraintDef>()), 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", EMPLOYEE_TYPE, true, AtlasAttributeDef.Cardinality.SINGLE, 0, 1, false, false, Collections.<AtlasConstraintDef>emptyList()), AtlasTypeUtil.createOptionalAttrDef("shares", "long"), AtlasTypeUtil.createOptionalAttrDef("salary", "double"));
employeeTypeDef.getAttribute("department").addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF, new HashMap<String, Object>() {
{
put(AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE, "employees");
}
}));
AtlasEntityDef managerTypeDef = AtlasTypeUtil.createClassTypeDef("Manager", "Manager" + _description, ImmutableSet.of("Employee"), new AtlasAttributeDef("subordinates", String.format("array<%s>", "Employee"), false, AtlasAttributeDef.Cardinality.SET, 1, 10, false, false, Collections.<AtlasConstraintDef>emptyList()));
AtlasClassificationDef securityClearanceTypeDef = AtlasTypeUtil.createTraitTypeDef("SecurityClearance", "SecurityClearance" + _description, ImmutableSet.<String>of(), AtlasTypeUtil.createRequiredAttrDef("level", "int"));
return new AtlasTypesDef(ImmutableList.of(orgLevelEnum), ImmutableList.of(addressDetails), ImmutableList.of(securityClearanceTypeDef), ImmutableList.of(deptTypeDef, personTypeDef, employeeTypeDef, managerTypeDef));
}
use of org.apache.atlas.model.typedef.AtlasTypesDef in project incubator-atlas by apache.
the class RestUtilsTest method convertV1toV2.
private List<AtlasEntityDef> convertV1toV2(List<HierarchicalTypeDefinition<ClassType>> types) throws AtlasBaseException {
ImmutableList<HierarchicalTypeDefinition<ClassType>> classTypeList = ImmutableList.<HierarchicalTypeDefinition<ClassType>>builder().addAll(types).build();
TypesDef toConvert = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), classTypeList);
String json = TypesSerialization.toJson(toConvert);
AtlasTypeRegistry emptyRegistry = new AtlasTypeRegistry();
AtlasTypesDef converted = TypeConverterUtil.toAtlasTypesDef(json, emptyRegistry);
List<AtlasEntityDef> convertedEntityDefs = converted.getEntityDefs();
return convertedEntityDefs;
}
use of org.apache.atlas.model.typedef.AtlasTypesDef in project incubator-atlas by apache.
the class TestEntitiesREST method setUp.
@BeforeClass
public void setUp() throws Exception {
AtlasTypesDef[] testTypesDefs = new AtlasTypesDef[] { TestUtilsV2.defineHiveTypes() };
for (AtlasTypesDef typesDef : testTypesDefs) {
AtlasTypesDef typesToCreate = AtlasTypeDefStoreInitializer.getTypesToCreate(typesDef, typeRegistry);
if (!typesToCreate.isEmpty()) {
typeStore.createTypesDef(typesToCreate);
}
}
dbEntity = TestUtilsV2.createDBEntity();
tableEntity = TestUtilsV2.createTableEntity(dbEntity);
final AtlasEntity colEntity = TestUtilsV2.createColumnEntity(tableEntity);
columns = new ArrayList<AtlasEntity>() {
{
add(colEntity);
}
};
tableEntity.setAttribute("columns", getObjIdList(columns));
}
use of org.apache.atlas.model.typedef.AtlasTypesDef in project incubator-atlas by apache.
the class TestEntityREST method setUp.
@BeforeClass
public void setUp() throws Exception {
AtlasTypesDef typesDef = TestUtilsV2.defineHiveTypes();
typeStore.createTypesDef(typesDef);
}
use of org.apache.atlas.model.typedef.AtlasTypesDef in project incubator-atlas by apache.
the class EntityV2JerseyResourceIT method testDeleteExistentTraitNonExistentForEntity.
@Test(dependsOnMethods = "testSubmitEntity")
public void testDeleteExistentTraitNonExistentForEntity() throws Exception {
final String guid = createHiveTable().getGuid();
final String traitName = "PII_Trait" + randomString();
AtlasClassificationDef piiTrait = AtlasTypeUtil.createTraitTypeDef(traitName, ImmutableSet.<String>of(), AtlasTypeUtil.createRequiredAttrDef("type", "string"));
AtlasTypesDef typesDef = new AtlasTypesDef();
typesDef.getClassificationDefs().add(piiTrait);
createType(typesDef);
try {
atlasClientV2.deleteClassification(guid, traitName);
fail("Deletion should've failed for non-existent trait association");
} catch (AtlasServiceException ex) {
Assert.assertNotNull(ex.getStatus());
assertEquals(ex.getStatus(), ClientResponse.Status.NOT_FOUND);
}
}
Aggregations