Search in sources :

Example 41 with AtlasEnumDef

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;
}
Also used : TypesDef(org.apache.atlas.v1.model.typedef.TypesDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) EnumValue(org.apache.atlas.v1.model.typedef.EnumTypeDefinition.EnumValue) EnumTypeDefinition(org.apache.atlas.v1.model.typedef.EnumTypeDefinition) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef)

Example 42 with AtlasEnumDef

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());
    }
}
Also used : AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef)

Example 43 with AtlasEnumDef

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));
}
Also used : AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasRelationshipDef(org.apache.atlas.model.typedef.AtlasRelationshipDef) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef) AtlasRelationshipEndDef(org.apache.atlas.model.typedef.AtlasRelationshipEndDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef)

Example 44 with AtlasEnumDef

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;
}
Also used : AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) 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 45 with AtlasEnumDef

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;
}
Also used : AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasEnumElementDef(org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef)

Aggregations

AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)61 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)33 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)29 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)27 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)24 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)16 AtlasEnumElementDef (org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef)14 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)13 ArrayList (java.util.ArrayList)12 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)12 Test (org.testng.annotations.Test)11 AtlasConstraintDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)9 HashMap (java.util.HashMap)8 AtlasTypeAccessRequest (org.apache.atlas.authorize.AtlasTypeAccessRequest)5 AtlasServiceException (org.apache.atlas.AtlasServiceException)2 AtlasRelationshipDef (org.apache.atlas.model.typedef.AtlasRelationshipDef)2 AtlasRelationshipEndDef (org.apache.atlas.model.typedef.AtlasRelationshipEndDef)2 TypesDef (org.apache.atlas.typesystem.TypesDef)2 EnumTypeDefinition (org.apache.atlas.typesystem.types.EnumTypeDefinition)2 EnumTypeDefinition (org.apache.atlas.v1.model.typedef.EnumTypeDefinition)2