use of org.apache.atlas.model.typedef.AtlasEnumDef in project atlas by apache.
the class TypeConverterUtil method enumToTypesDef.
private static TypesDef enumToTypesDef(AtlasEnumType enumType) {
AtlasEnumDef enumDef = enumType.getEnumDef();
String enumName = enumDef.getName();
String enumDesc = enumDef.getDescription();
String enumVersion = enumDef.getTypeVersion();
List<EnumValue> enumValues = getEnumValues(enumDef.getElementDefs());
EnumTypeDefinition enumTypeDef = new EnumTypeDefinition(enumName, enumDesc, enumVersion, enumValues);
TypesDef ret = new TypesDef(Arrays.asList(enumTypeDef), null, null, null);
return ret;
}
use of org.apache.atlas.model.typedef.AtlasEnumDef in project atlas by apache.
the class GraphBackedSearchIndexer method addIndexForType.
private void addIndexForType(AtlasGraphManagement management, AtlasBaseTypeDef typeDef) {
if (typeDef instanceof AtlasEnumDef) {
// Only handle complex types like Struct, Classification and Entity
return;
}
if (typeDef instanceof AtlasStructDef) {
AtlasStructDef structDef = (AtlasStructDef) typeDef;
List<AtlasAttributeDef> attributeDefs = structDef.getAttributeDefs();
if (CollectionUtils.isNotEmpty(attributeDefs)) {
for (AtlasAttributeDef attributeDef : attributeDefs) {
createIndexForAttribute(management, typeDef.getName(), attributeDef);
}
}
} else if (!AtlasTypeUtil.isBuiltInType(typeDef.getName())) {
throw new IllegalArgumentException("bad data type" + typeDef.getName());
}
}
use of org.apache.atlas.model.typedef.AtlasEnumDef in project atlas by apache.
the class TestRelationshipUtilsV2 method getDepartmentEmployeeTypes.
public static AtlasTypesDef getDepartmentEmployeeTypes() throws AtlasBaseException {
/**
***** Person Type ******
*/
AtlasEntityDef personType = createClassTypeDef(PERSON_TYPE, description(PERSON_TYPE), superType(null), createUniqueRequiredAttrDef("name", "string"), createOptionalAttrDef("address", ADDRESS_TYPE), createOptionalAttrDef("birthday", "date"), createOptionalAttrDef("hasPets", "boolean"), createOptionalAttrDef("numberOfCars", "byte"), createOptionalAttrDef("houseNumber", "short"), createOptionalAttrDef("carMileage", "int"), createOptionalAttrDef("age", "float"), createOptionalAttrDef("numberOfStarsEstimate", "biginteger"), createOptionalAttrDef("approximationOfPi", "bigdecimal"));
/**
***** Employee Type ******
*/
AtlasEntityDef employeeType = createClassTypeDef(EMPLOYEE_TYPE, description(EMPLOYEE_TYPE), superType(PERSON_TYPE), createOptionalAttrDef("orgLevel", ORG_LEVEL_TYPE), createOptionalAttrDef("shares", "long"), createOptionalAttrDef("salary", "double"));
/**
***** Department Type ******
*/
AtlasEntityDef departmentType = createClassTypeDef(DEPARTMENT_TYPE, description(DEPARTMENT_TYPE), superType(null), createUniqueRequiredAttrDef("name", "string"));
/**
***** Manager Type ******
*/
AtlasEntityDef managerType = createClassTypeDef(MANAGER_TYPE, description(MANAGER_TYPE), superType(EMPLOYEE_TYPE));
/**
***** Address Type ******
*/
AtlasStructDef addressType = createStructTypeDef(ADDRESS_TYPE, description(ADDRESS_TYPE), createRequiredAttrDef("street", "string"), createRequiredAttrDef("city", "string"));
/**
***** Organization Level Type ******
*/
AtlasEnumDef orgLevelType = new AtlasEnumDef(ORG_LEVEL_TYPE, description(ORG_LEVEL_TYPE), DEFAULT_VERSION, getOrgLevelElements());
/**
***** Security Clearance Type ******
*/
AtlasClassificationDef securityClearanceType = createTraitTypeDef(SECURITY_CLEARANCE_TYPE, description(SECURITY_CLEARANCE_TYPE), superType(null), createRequiredAttrDef("level", "int"));
/**
***** [Department -> Employee] Relationship ******
*/
AtlasRelationshipDef employeeDepartmentType = new AtlasRelationshipDef(EMPLOYEE_DEPARTMENT_TYPE, description(EMPLOYEE_DEPARTMENT_TYPE), DEFAULT_VERSION, AGGREGATION, ONE_TO_TWO, new AtlasRelationshipEndDef(EMPLOYEE_TYPE, "department", SINGLE), new AtlasRelationshipEndDef(DEPARTMENT_TYPE, "employees", SET, true));
/**
***** [Manager -> Employee] Relationship ******
*/
AtlasRelationshipDef employeeManagerType = new AtlasRelationshipDef(EMPLOYEE_MANAGER_TYPE, description(EMPLOYEE_MANAGER_TYPE), DEFAULT_VERSION, AGGREGATION, ONE_TO_TWO, new AtlasRelationshipEndDef(EMPLOYEE_TYPE, "manager", SINGLE), new AtlasRelationshipEndDef(MANAGER_TYPE, "subordinates", SET, true));
/**
***** [Mentors -> Employee] Relationship ******
*/
AtlasRelationshipDef employeeMentorsType = new AtlasRelationshipDef(EMPLOYEE_MENTORS_TYPE, description(EMPLOYEE_MENTORS_TYPE), DEFAULT_VERSION, AGGREGATION, ONE_TO_TWO, new AtlasRelationshipEndDef(EMPLOYEE_TYPE, "mentors", SET), new AtlasRelationshipEndDef(EMPLOYEE_TYPE, "mentees", SET, true));
/**
***** [Friends -> Employee] Relationship ******
*/
AtlasRelationshipDef employeeFriendsType = new AtlasRelationshipDef(EMPLOYEE_FRIENDS_TYPE, description(EMPLOYEE_FRIENDS_TYPE), DEFAULT_VERSION, ASSOCIATION, ONE_TO_TWO, new AtlasRelationshipEndDef(EMPLOYEE_TYPE, "friends", SET), new AtlasRelationshipEndDef(EMPLOYEE_TYPE, "friends", SET));
/**
***** [Person -> Sibling] Relationship ******
*/
AtlasRelationshipDef personSiblingType = new AtlasRelationshipDef(PERSON_SIBLING_TYPE, description(PERSON_SIBLING_TYPE), DEFAULT_VERSION, ASSOCIATION, BOTH, new AtlasRelationshipEndDef(PERSON_TYPE, "sibling", SINGLE), new AtlasRelationshipEndDef(PERSON_TYPE, "sibling", SINGLE));
return new AtlasTypesDef(Collections.singletonList(orgLevelType), Collections.singletonList(addressType), Collections.singletonList(securityClearanceType), Arrays.asList(personType, employeeType, departmentType, managerType), Arrays.asList(employeeDepartmentType, employeeManagerType, employeeMentorsType, employeeFriendsType, personSiblingType));
}
use of org.apache.atlas.model.typedef.AtlasEnumDef in project atlas by apache.
the class TestUtilsV2 method defineValidUpdatedDeptEmployeeTypes.
public static AtlasTypesDef defineValidUpdatedDeptEmployeeTypes() {
String _description = "_description_updated";
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"), AtlasTypeUtil.createOptionalAttrDef("zip", "int"));
AtlasEntityDef deptTypeDef = AtlasTypeUtil.createClassTypeDef(DEPARTMENT_TYPE, "Department" + _description, Collections.<String>emptySet(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"), AtlasTypeUtil.createOptionalAttrDef("dep-code", "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, Collections.<String>emptySet(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"), AtlasTypeUtil.createOptionalAttrDef("email", "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, Collections.singleton("Person"), AtlasTypeUtil.createOptionalAttrDef("orgLevel", "OrgLevel"), AtlasTypeUtil.createOptionalAttrDef("empCode", "string"), 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", EMPLOYEE_TYPE, true, AtlasAttributeDef.Cardinality.SINGLE, 0, 1, false, false, Collections.<AtlasConstraintDef>emptyList()), AtlasTypeUtil.createOptionalAttrDef("shares", "long"), AtlasTypeUtil.createOptionalAttrDef("salary", "double"));
AtlasEntityDef managerTypeDef = AtlasTypeUtil.createClassTypeDef("Manager", "Manager" + _description, Collections.singleton("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, Collections.<String>emptySet(), AtlasTypeUtil.createRequiredAttrDef("level", "int"));
AtlasTypesDef ret = new AtlasTypesDef(Collections.singletonList(orgLevelEnum), Collections.singletonList(addressDetails), Collections.singletonList(securityClearanceTypeDef), Arrays.asList(deptTypeDef, personTypeDef, employeeTypeDef, managerTypeDef));
populateSystemAttributes(ret);
return ret;
}
use of org.apache.atlas.model.typedef.AtlasEnumDef in project atlas by apache.
the class TestUtilsV2 method simpleType.
public static AtlasTypesDef simpleType() {
AtlasEntityDef superTypeDefinition = AtlasTypeUtil.createClassTypeDef("h_type", Collections.<String>emptySet(), AtlasTypeUtil.createOptionalAttrDef("attr", "string"));
AtlasStructDef structTypeDefinition = new AtlasStructDef("s_type", "structType", "1.0", Arrays.asList(AtlasTypeUtil.createRequiredAttrDef("name", "string")));
AtlasClassificationDef traitTypeDefinition = AtlasTypeUtil.createTraitTypeDef("t_type", "traitType", Collections.<String>emptySet());
AtlasEnumDef enumTypeDefinition = new AtlasEnumDef("e_type", "enumType", "1.0", Arrays.asList(new AtlasEnumElementDef("ONE", "Element Description", 1)));
AtlasTypesDef ret = AtlasTypeUtil.getTypesDef(Collections.singletonList(enumTypeDefinition), Collections.singletonList(structTypeDefinition), Collections.singletonList(traitTypeDefinition), Collections.singletonList(superTypeDefinition));
populateSystemAttributes(ret);
return ret;
}
Aggregations