Search in sources :

Example 1 with TypeCategory

use of org.apache.atlas.typesystem.types.DataTypes.TypeCategory in project incubator-atlas by apache.

the class GraphBackedTypeStore method getTypesFromVertices.

private TypesDef getTypesFromVertices(Iterator<AtlasVertex> vertices) throws AtlasException {
    ImmutableList.Builder<EnumTypeDefinition> enums = ImmutableList.builder();
    ImmutableList.Builder<StructTypeDefinition> structs = ImmutableList.builder();
    ImmutableList.Builder<HierarchicalTypeDefinition<ClassType>> classTypes = ImmutableList.builder();
    ImmutableList.Builder<HierarchicalTypeDefinition<TraitType>> traits = ImmutableList.builder();
    while (vertices.hasNext()) {
        AtlasVertex vertex = vertices.next();
        DataTypes.TypeCategory typeCategory = GraphHelper.getSingleValuedProperty(vertex, Constants.TYPE_CATEGORY_PROPERTY_KEY, TypeCategory.class);
        String typeName = GraphHelper.getSingleValuedProperty(vertex, Constants.TYPENAME_PROPERTY_KEY, String.class);
        String typeDescription = GraphHelper.getSingleValuedProperty(vertex, Constants.TYPEDESCRIPTION_PROPERTY_KEY, String.class);
        LOG.info("Restoring type {}.{}.{}", typeCategory, typeName, typeDescription);
        switch(typeCategory) {
            case ENUM:
                enums.add(getEnumType(vertex));
                break;
            case STRUCT:
                AttributeDefinition[] attributes = getAttributes(vertex, typeName);
                structs.add(new StructTypeDefinition(typeName, typeDescription, attributes));
                break;
            case CLASS:
                ImmutableSet<String> superTypes = getSuperTypes(vertex);
                attributes = getAttributes(vertex, typeName);
                classTypes.add(new HierarchicalTypeDefinition(ClassType.class, typeName, typeDescription, superTypes, attributes));
                break;
            case TRAIT:
                superTypes = getSuperTypes(vertex);
                attributes = getAttributes(vertex, typeName);
                traits.add(new HierarchicalTypeDefinition(TraitType.class, typeName, typeDescription, superTypes, attributes));
                break;
            default:
                throw new IllegalArgumentException("Unhandled type category " + typeCategory);
        }
    }
    return TypesUtil.getTypesDef(enums.build(), structs.build(), traits.build(), classTypes.build());
}
Also used : TypeCategory(org.apache.atlas.typesystem.types.DataTypes.TypeCategory) ImmutableList(com.google.common.collect.ImmutableList) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex)

Example 2 with TypeCategory

use of org.apache.atlas.typesystem.types.DataTypes.TypeCategory in project incubator-atlas by apache.

the class AtlasTypeDefGraphStoreV1 method isTypeVertex.

@VisibleForTesting
public boolean isTypeVertex(AtlasVertex vertex, TypeCategory category) {
    boolean ret = false;
    if (isTypeVertex(vertex)) {
        TypeCategory vertexCategory = vertex.getProperty(Constants.TYPE_CATEGORY_PROPERTY_KEY, TypeCategory.class);
        ret = category.equals(vertexCategory);
    }
    return ret;
}
Also used : TypeCategory(org.apache.atlas.typesystem.types.DataTypes.TypeCategory) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

TypeCategory (org.apache.atlas.typesystem.types.DataTypes.TypeCategory)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableList (com.google.common.collect.ImmutableList)1 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)1