Search in sources :

Example 1 with StructTypeDefinition

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

Example 2 with StructTypeDefinition

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;
}
Also used : AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) ArrayList(java.util.ArrayList) AttributeDefinition(org.apache.atlas.typesystem.types.AttributeDefinition) StructTypeDefinition(org.apache.atlas.typesystem.types.StructTypeDefinition)

Example 3 with StructTypeDefinition

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;
}
Also used : AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) TypesDef(org.apache.atlas.typesystem.TypesDef) TraitType(org.apache.atlas.typesystem.types.TraitType) AttributeDefinition(org.apache.atlas.typesystem.types.AttributeDefinition) ClassType(org.apache.atlas.typesystem.types.ClassType) StructTypeDefinition(org.apache.atlas.typesystem.types.StructTypeDefinition)

Example 4 with StructTypeDefinition

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");
    }
}
Also used : TypeSystem(org.apache.atlas.typesystem.types.TypeSystem) TypesDef(org.apache.atlas.typesystem.TypesDef) TraitType(org.apache.atlas.typesystem.types.TraitType) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) AttributeDefinition(org.apache.atlas.typesystem.types.AttributeDefinition) ClassType(org.apache.atlas.typesystem.types.ClassType) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) StructTypeDefinition(org.apache.atlas.typesystem.types.StructTypeDefinition) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

StructTypeDefinition (org.apache.atlas.typesystem.types.StructTypeDefinition)4 TypesDef (org.apache.atlas.typesystem.TypesDef)3 AttributeDefinition (org.apache.atlas.typesystem.types.AttributeDefinition)3 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)2 ClassType (org.apache.atlas.typesystem.types.ClassType)2 TraitType (org.apache.atlas.typesystem.types.TraitType)2 ArrayList (java.util.ArrayList)1 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)1 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)1 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)1 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)1 ITypedStruct (org.apache.atlas.typesystem.ITypedStruct)1 EnumTypeDefinition (org.apache.atlas.typesystem.types.EnumTypeDefinition)1 EnumValue (org.apache.atlas.typesystem.types.EnumValue)1 HierarchicalTypeDefinition (org.apache.atlas.typesystem.types.HierarchicalTypeDefinition)1 TypeSystem (org.apache.atlas.typesystem.types.TypeSystem)1 BeforeTest (org.testng.annotations.BeforeTest)1 Test (org.testng.annotations.Test)1