use of org.apache.atlas.typesystem.TypesDef in project incubator-atlas by apache.
the class TypeConverterUtil method entityToTypesDef.
private static TypesDef entityToTypesDef(AtlasEntityType entityType, AtlasTypeRegistry registry) throws AtlasBaseException {
String typeName = entityType.getEntityDef().getName();
String typeDesc = entityType.getEntityDef().getDescription();
String typeVersion = entityType.getEntityDef().getTypeVersion();
ImmutableSet superTypes = ImmutableSet.copyOf(entityType.getEntityDef().getSuperTypes());
AttributeDefinition[] attributes = getAttributes(entityType, registry);
HierarchicalTypeDefinition<ClassType> classType = TypesUtil.createClassTypeDef(typeName, typeDesc, typeVersion, superTypes, attributes);
TypesDef ret = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), ImmutableList.of(classType));
return ret;
}
use of org.apache.atlas.typesystem.TypesDef in project incubator-atlas by apache.
the class GraphHelperTest method setUp.
@BeforeClass
public void setUp() throws Exception {
typeSystem = TypeSystem.getInstance();
typeSystem.reset();
new GraphBackedSearchIndexer(typeRegistry);
TypesDef typesDef = TestUtils.defineHiveTypes();
try {
metadataService.getTypeDefinition(TestUtils.TABLE_TYPE);
} catch (TypeNotFoundException e) {
metadataService.createType(TypesSerialization.toJson(typesDef));
}
TestUtils.defineDeptEmployeeTypes(typeSystem);
}
use of org.apache.atlas.typesystem.TypesDef in project incubator-atlas by apache.
the class FieldMappingTest method testOutputReferenceableInstance.
@Test
public void testOutputReferenceableInstance() throws Exception {
// ATLAS-645: verify that FieldMapping.output(IReferenceableInstance)
// does not infinitely recurse when ITypedReferenceableInstance's reference each other.
HierarchicalTypeDefinition<ClassType> valueDef = TypesUtil.createClassTypeDef("Value", ImmutableSet.<String>of(), new AttributeDefinition("owner", "Owner", Multiplicity.OPTIONAL, false, null));
// Define class type with reference, where the value is a class reference to Value.
HierarchicalTypeDefinition<ClassType> ownerDef = TypesUtil.createClassTypeDef("Owner", ImmutableSet.<String>of(), new AttributeDefinition("value", "Value", Multiplicity.OPTIONAL, false, null));
TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), ImmutableList.of(ownerDef, valueDef));
TypeSystem typeSystem = TypeSystem.getInstance();
typeSystem.defineTypes(typesDef);
ClassType ownerType = typeSystem.getDataType(ClassType.class, "Owner");
// Prior to fix for ATLAS-645, this call would throw a StackOverflowError
try {
ownerType.toString();
} catch (StackOverflowError e) {
Assert.fail("Infinite recursion in ClassType.toString() caused StackOverflowError");
}
ClassType valueType = typeSystem.getDataType(ClassType.class, "Value");
// Create instances of Owner and Value that reference each other.
ITypedReferenceableInstance ownerInstance = ownerType.createInstance();
ITypedReferenceableInstance valueInstance = valueType.createInstance();
// Set Owner.value reference to Value instance.
ownerInstance.set("value", valueInstance);
// Set Value.owner reference on Owner instance.
valueInstance.set("owner", ownerInstance);
// Prior to fix for ATLAS-645, this call would throw a StackOverflowError
try {
ownerInstance.fieldMapping().output(ownerInstance, new StringBuilder(), "", new HashSet<IReferenceableInstance>());
} catch (StackOverflowError e) {
Assert.fail("Infinite recursion in FieldMapping.output() caused StackOverflowError");
}
}
use of org.apache.atlas.typesystem.TypesDef in project incubator-atlas by apache.
the class ClassTest method testSerDeWithoutDescription.
@Test
public void testSerDeWithoutDescription() throws Exception {
HierarchicalTypeDefinition<ClassType> clsType = TypesUtil.createClassTypeDef("Random", ImmutableSet.<String>of(), TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE));
TypesDef typesDef = getTypesDef(clsType);
String json = TypesSerialization.toJson(typesDef);
System.out.println("json " + json);
TypesSerialization.fromJson(json);
}
use of org.apache.atlas.typesystem.TypesDef 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;
}
Aggregations