use of org.apache.atlas.typesystem.types.StructTypeDefinition in project incubator-atlas by apache.
the class TypeConverterUtil method enumToTypesDef.
private static TypesDef enumToTypesDef(AtlasEnumType enumType) {
TypesDef ret = null;
AtlasEnumDef enumDef = enumType.getEnumDef();
String enumName = enumDef.getName();
String enumDesc = enumDef.getDescription();
String enumVersion = enumDef.getTypeVersion();
EnumValue[] enumValues = getEnumValues(enumDef.getElementDefs());
if (enumName != null && enumValues != null && enumValues.length > 0) {
EnumTypeDefinition enumTypeDef = new EnumTypeDefinition(enumName, enumDesc, enumVersion, enumValues);
ret = TypesUtil.getTypesDef(ImmutableList.of(enumTypeDef), ImmutableList.<StructTypeDefinition>of(), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), ImmutableList.<HierarchicalTypeDefinition<ClassType>>of());
}
return ret;
}
use of org.apache.atlas.typesystem.types.StructTypeDefinition in project incubator-atlas by apache.
the class TypeConverterUtil method toAtlasStructDefs.
private static List<AtlasStructDef> toAtlasStructDefs(List<StructTypeDefinition> structTypeDefinitions) throws AtlasBaseException {
List<AtlasStructDef> ret = new ArrayList<AtlasStructDef>();
for (StructTypeDefinition structType : structTypeDefinitions) {
AtlasStructDef structDef = new AtlasStructDef();
List<AtlasAttributeDef> attrDefs = new ArrayList<AtlasAttributeDef>();
structDef.setName(structType.typeName);
structDef.setDescription(structType.typeDescription);
structDef.setTypeVersion(structType.typeVersion);
AttributeDefinition[] attrDefinitions = structType.attributeDefinitions;
for (AttributeDefinition attrDefinition : attrDefinitions) {
attrDefs.add(toAtlasAttributeDef(attrDefinition));
}
structDef.setAttributeDefs(attrDefs);
ret.add(structDef);
}
return ret;
}
use of org.apache.atlas.typesystem.types.StructTypeDefinition in project incubator-atlas by apache.
the class TypeConverterUtil method structToTypesDef.
private static TypesDef structToTypesDef(AtlasStructType structType, AtlasTypeRegistry registry) throws AtlasBaseException {
String typeName = structType.getStructDef().getName();
String typeDesc = structType.getStructDef().getDescription();
String typeVersion = structType.getStructDef().getTypeVersion();
AttributeDefinition[] attributes = getAttributes(structType, registry);
StructTypeDefinition structTypeDef = TypesUtil.createStructTypeDef(typeName, typeDesc, typeVersion, attributes);
TypesDef ret = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.of(structTypeDef), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), ImmutableList.<HierarchicalTypeDefinition<ClassType>>of());
return ret;
}
use of org.apache.atlas.typesystem.types.StructTypeDefinition in project incubator-atlas by apache.
the class FieldMappingTest method testOutputStruct.
@Test
public void testOutputStruct() throws Exception {
// ATLAS-645: verify that FieldMapping.output(IStruct) does not infinitely recurse
// when an IStruct and ITypedReferenceableInstance reference each other.
HierarchicalTypeDefinition<ClassType> valueDef = TypesUtil.createClassTypeDef("Value", ImmutableSet.<String>of(), new AttributeDefinition("owner", "Owner", Multiplicity.OPTIONAL, false, null));
// Define struct type with reference, where the value is a class reference to Value.
StructTypeDefinition ownerDef = TypesUtil.createStructTypeDef("Owner", new AttributeDefinition("value", "Value", Multiplicity.OPTIONAL, false, null));
TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.of(ownerDef), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), ImmutableList.of(valueDef));
TypeSystem typeSystem = TypeSystem.getInstance();
typeSystem.reset();
typeSystem.defineTypes(typesDef);
StructType ownerType = typeSystem.getDataType(StructType.class, "Owner");
ClassType valueType = typeSystem.getDataType(ClassType.class, "Value");
// Prior to fix for ATLAS-645, this call would throw a StackOverflowError
try {
ownerType.toString();
} catch (StackOverflowError e) {
Assert.fail("Infinite recursion in StructType.toString() caused StackOverflowError");
}
// Create instances of Owner and Value that reference each other.
ITypedStruct 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(), "", null);
} catch (StackOverflowError e) {
Assert.fail("Infinite recursion in FieldMapping.output() caused StackOverflowError");
}
}
Aggregations