use of org.apache.atlas.model.typedef.AtlasEntityDef in project atlas by apache.
the class AtlasEntityStoreV1Test method testSpecialCharacters.
@Test(enabled = false)
public // TODO : Failing in typedef creation
void testSpecialCharacters() throws Exception {
// Verify that type can be created with reserved characters in typename, attribute name
final String typeName = TestUtilsV2.randomString(10);
String strAttrName = randomStrWithReservedChars();
String arrayAttrName = randomStrWithReservedChars();
String mapAttrName = randomStrWithReservedChars();
AtlasEntityDef typeDefinition = AtlasTypeUtil.createClassTypeDef(typeName, "Special chars test type", ImmutableSet.<String>of(), AtlasTypeUtil.createOptionalAttrDef(strAttrName, "string"), AtlasTypeUtil.createOptionalAttrDef(arrayAttrName, "array<string>"), AtlasTypeUtil.createOptionalAttrDef(mapAttrName, "map<string,string>"));
AtlasTypesDef atlasTypesDef = new AtlasTypesDef(null, null, null, Arrays.asList(typeDefinition));
typeDefStore.createTypesDef(atlasTypesDef);
// verify that entity can be created with reserved characters in string value, array value and map key and value
AtlasEntity entity = new AtlasEntity();
entity.setAttribute(strAttrName, randomStrWithReservedChars());
entity.setAttribute(arrayAttrName, new String[] { randomStrWithReservedChars() });
entity.setAttribute(mapAttrName, new HashMap<String, String>() {
{
put(randomStrWithReservedChars(), randomStrWithReservedChars());
}
});
AtlasEntityWithExtInfo entityWithExtInfo = new AtlasEntityWithExtInfo(entity);
final EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(entityWithExtInfo), false);
final AtlasEntityHeader firstEntityCreated = response.getFirstEntityCreated();
validateEntity(entityWithExtInfo, getEntityFromStore(firstEntityCreated));
// Verify that search with reserved characters works - for string attribute
// String query =
// String.format("`%s` where `%s` = '%s'", typeName, strAttrName, entity.getAttribute(strAttrName));
// String responseJson = discoveryService.searchByDSL(query, new QueryParams(1, 0));
// JSONObject response = new JSONObject(responseJson);
// assertEquals(response.getJSONArray("rows").length(), 1);
}
use of org.apache.atlas.model.typedef.AtlasEntityDef 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.AtlasEntityDef in project atlas by apache.
the class TestRelationshipUtilsV2 method getInverseReferenceTestTypes.
public static AtlasTypesDef getInverseReferenceTestTypes() throws AtlasBaseException {
AtlasEntityDef aType = createClassTypeDef(TYPE_A, superType(null), createUniqueRequiredAttrDef("name", "string"));
AtlasEntityDef bType = createClassTypeDef(TYPE_B, superType(null), createUniqueRequiredAttrDef("name", "string"));
AtlasRelationshipDef relationshipType1 = new AtlasRelationshipDef("TypeA_to_TypeB_on_b", description("TypeA_to_TypeB_on_b"), DEFAULT_VERSION, ASSOCIATION, ONE_TO_TWO, new AtlasRelationshipEndDef(TYPE_A, "b", SINGLE), new AtlasRelationshipEndDef(TYPE_B, "a", SINGLE));
AtlasRelationshipDef relationshipType2 = new AtlasRelationshipDef("TypeA_to_TypeB_on_oneB", description("TypeA_to_TypeB_on_oneB"), DEFAULT_VERSION, ASSOCIATION, ONE_TO_TWO, new AtlasRelationshipEndDef(TYPE_A, "oneB", SINGLE), new AtlasRelationshipEndDef(TYPE_B, "manyA", SET));
AtlasRelationshipDef relationshipType3 = new AtlasRelationshipDef("TypeA_to_TypeB_on_manyB", description("TypeA_to_TypeB_on_manyB"), DEFAULT_VERSION, ASSOCIATION, ONE_TO_TWO, new AtlasRelationshipEndDef(TYPE_A, "manyB", SET), new AtlasRelationshipEndDef(TYPE_B, "manyToManyA", SET));
AtlasRelationshipDef relationshipType4 = new AtlasRelationshipDef("TypeB_to_TypeA_on_mappedFromA", description("TypeB_to_TypeA_on_mappedFromA"), DEFAULT_VERSION, ASSOCIATION, ONE_TO_TWO, new AtlasRelationshipEndDef(TYPE_B, "mappedFromA", SINGLE), new AtlasRelationshipEndDef(TYPE_A, "mapToB", SET));
return new AtlasTypesDef(Collections.<AtlasEnumDef>emptyList(), Collections.<AtlasStructDef>emptyList(), Collections.<AtlasClassificationDef>emptyList(), Arrays.asList(aType, bType), Arrays.asList(relationshipType1, relationshipType2, relationshipType3, relationshipType4));
}
use of org.apache.atlas.model.typedef.AtlasEntityDef in project atlas by apache.
the class TestAtlasEntity method testEntitySerDeWithSuperTypes.
@Test
public void testEntitySerDeWithSuperTypes() throws AtlasBaseException {
AtlasEntityDef entityDef = ModelTestUtil.getEntityDefWithSuperTypes();
AtlasTypeRegistry typeRegistry = ModelTestUtil.getTypesRegistry();
AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entityDef.getName());
assertNotNull(entityType);
AtlasEntity ent1 = entityType.createDefaultValue();
String jsonString = AtlasType.toJson(ent1);
AtlasEntity ent2 = AtlasType.fromJson(jsonString, AtlasEntity.class);
entityType.normalizeAttributeValues(ent2);
assertEquals(ent2, ent1, "Incorrect serialization/deserialization of AtlasEntity with superTypes");
}
use of org.apache.atlas.model.typedef.AtlasEntityDef in project atlas by apache.
the class TestUtilsV2 method getEntityWithInvalidSuperType.
public static AtlasEntityDef getEntityWithInvalidSuperType() {
AtlasEntityDef entityDef = simpleType().getEntityDefs().get(0);
entityDef.addSuperType("!@#$%");
return entityDef;
}
Aggregations