Search in sources :

Example 66 with AtlasType

use of org.apache.atlas.type.AtlasType in project atlas by apache.

the class AtlasArrayFormatConverter method fromV2ToV1.

@Override
public Collection fromV2ToV1(Object v2Obj, AtlasType type, ConverterContext ctx) throws AtlasBaseException {
    Collection ret = null;
    if (v2Obj != null) {
        if (v2Obj instanceof List) {
            ret = new ArrayList();
        } else if (v2Obj instanceof Set) {
            ret = new LinkedHashSet();
        } else {
            throw new AtlasBaseException(AtlasErrorCode.UNEXPECTED_TYPE, "List or Set", v2Obj.getClass().getCanonicalName());
        }
        AtlasArrayType arrType = (AtlasArrayType) type;
        AtlasType elemType = arrType.getElementType();
        AtlasFormatConverter elemConverter = converterRegistry.getConverter(elemType.getTypeCategory());
        Collection v2List = (Collection) v2Obj;
        for (Object v2Elem : v2List) {
            Object convertedVal = elemConverter.fromV2ToV1(v2Elem, elemType, ctx);
            ret.add(convertedVal);
        }
    }
    return ret;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AtlasArrayType(org.apache.atlas.type.AtlasArrayType) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) ArrayList(java.util.ArrayList) Collection(java.util.Collection) AtlasType(org.apache.atlas.type.AtlasType) ArrayList(java.util.ArrayList) List(java.util.List)

Example 67 with AtlasType

use of org.apache.atlas.type.AtlasType in project atlas by apache.

the class AtlasEntityFormatConverter method fromV1ToV2.

@Override
public AtlasEntity fromV1ToV2(Object v1Obj, AtlasType type, ConverterContext context) throws AtlasBaseException {
    AtlasEntity entity = null;
    if (v1Obj != null) {
        AtlasEntityType entityType = (AtlasEntityType) type;
        if (v1Obj instanceof Referenceable) {
            Referenceable entRef = (Referenceable) v1Obj;
            String guid = entRef.getId().getId();
            if (!context.entityExists(guid)) {
                entity = new AtlasEntity(entRef.getTypeName(), super.fromV1ToV2(entityType, entRef.getValues(), context));
                entity.setGuid(entRef.getId().getId());
                entity.setStatus(convertState(entRef.getId().getState()));
                if (entRef.getSystemAttributes() != null) {
                    entity.setCreatedBy(entRef.getSystemAttributes().getCreatedBy());
                    entity.setCreateTime(entRef.getSystemAttributes().getCreatedTime());
                    entity.setUpdatedBy(entRef.getSystemAttributes().getModifiedBy());
                    entity.setUpdateTime(entRef.getSystemAttributes().getModifiedTime());
                }
                entity.setVersion((long) entRef.getId().getVersion());
                if (CollectionUtils.isNotEmpty(entRef.getTraitNames())) {
                    List<AtlasClassification> classifications = new ArrayList<>();
                    AtlasFormatConverter traitConverter = converterRegistry.getConverter(TypeCategory.CLASSIFICATION);
                    for (String traitName : entRef.getTraitNames()) {
                        Struct trait = entRef.getTraits().get(traitName);
                        AtlasType classifiType = typeRegistry.getType(traitName);
                        AtlasClassification classification = (AtlasClassification) traitConverter.fromV1ToV2(trait, classifiType, context);
                        classifications.add(classification);
                    }
                    entity.setClassifications(classifications);
                }
            }
        } else {
            throw new AtlasBaseException(AtlasErrorCode.UNEXPECTED_TYPE, "Referenceable", v1Obj.getClass().getCanonicalName());
        }
    }
    return entity;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) Referenceable(org.apache.atlas.v1.model.instance.Referenceable) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) ArrayList(java.util.ArrayList) AtlasType(org.apache.atlas.type.AtlasType) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) Struct(org.apache.atlas.v1.model.instance.Struct)

Example 68 with AtlasType

use of org.apache.atlas.type.AtlasType in project atlas by apache.

the class AtlasInstanceConverter method getTrait.

public Struct getTrait(AtlasClassification classification) throws AtlasBaseException {
    AtlasFormatConverter converter = instanceFormatters.getConverter(TypeCategory.CLASSIFICATION);
    AtlasType classificationType = typeRegistry.getType(classification.getTypeName());
    Struct trait = (Struct) converter.fromV2ToV1(classification, classificationType, new ConverterContext());
    return trait;
}
Also used : ConverterContext(org.apache.atlas.repository.converters.AtlasFormatConverter.ConverterContext) AtlasType(org.apache.atlas.type.AtlasType) Struct(org.apache.atlas.v1.model.instance.Struct)

Example 69 with AtlasType

use of org.apache.atlas.type.AtlasType in project atlas by apache.

the class GraphBackedSearchIndexer method createIndexForAttribute.

private void createIndexForAttribute(AtlasGraphManagement management, String typeName, AtlasAttributeDef attributeDef) {
    final String propertyName = GraphHelper.encodePropertyKey(typeName + "." + attributeDef.getName());
    AtlasCardinality cardinality = toAtlasCardinality(attributeDef.getCardinality());
    boolean isUnique = attributeDef.getIsUnique();
    boolean isIndexable = attributeDef.getIsIndexable();
    String attribTypeName = attributeDef.getTypeName();
    boolean isBuiltInType = AtlasTypeUtil.isBuiltInType(attribTypeName);
    boolean isArrayType = AtlasTypeUtil.isArrayType(attribTypeName);
    boolean isMapType = AtlasTypeUtil.isMapType(attribTypeName);
    try {
        AtlasType atlasType = typeRegistry.getType(typeName);
        AtlasType attributeType = typeRegistry.getType(attribTypeName);
        if (isMapType || isClassificationType(attributeType)) {
            LOG.warn("Ignoring non-indexable attribute {}", attribTypeName);
        }
        if (isArrayType) {
            createLabelIfNeeded(management, propertyName, attribTypeName);
        }
        if (isEntityType(attributeType)) {
            createEdgeLabel(management, propertyName);
        } else if (isBuiltInType) {
            if (isRelationshipType(atlasType)) {
                createEdgeIndex(management, propertyName, getPrimitiveClass(attribTypeName), cardinality, false);
            } else {
                createVertexIndex(management, propertyName, getPrimitiveClass(attribTypeName), isUnique, cardinality, false, isIndexable);
            }
        } else if (isEnumType(attributeType)) {
            if (isRelationshipType(atlasType)) {
                createEdgeIndex(management, propertyName, String.class, cardinality, false);
            } else {
                createVertexIndex(management, propertyName, String.class, isUnique, cardinality, false, isIndexable);
            }
        } else if (isStructType(attributeType)) {
            AtlasStructDef structDef = typeRegistry.getStructDefByName(attribTypeName);
            updateIndexForTypeDef(management, structDef);
        }
    } catch (AtlasBaseException e) {
        LOG.error("No type exists for {}", attribTypeName, e);
    }
}
Also used : AtlasCardinality(org.apache.atlas.repository.graphdb.AtlasCardinality) AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasType(org.apache.atlas.type.AtlasType)

Example 70 with AtlasType

use of org.apache.atlas.type.AtlasType in project atlas by apache.

the class EntityDiscoveryService method isRelationshipAttribute.

private boolean isRelationshipAttribute(AtlasAttribute attribute) throws AtlasBaseException {
    boolean ret = true;
    AtlasType attrType = attribute.getAttributeType();
    if (attrType.getTypeCategory() == ARRAY) {
        attrType = ((AtlasArrayType) attrType).getElementType();
    } else if (attrType.getTypeCategory() == MAP) {
        attrType = ((AtlasMapType) attrType).getValueType();
    }
    if (attrType.getTypeCategory() != OBJECT_ID_TYPE) {
        ret = false;
    }
    return ret;
}
Also used : AtlasType(org.apache.atlas.type.AtlasType) AtlasMapType(org.apache.atlas.type.AtlasMapType)

Aggregations

AtlasType (org.apache.atlas.type.AtlasType)95 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)51 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)33 AtlasAttribute (org.apache.atlas.type.AtlasStructType.AtlasAttribute)23 AtlasArrayType (org.apache.atlas.type.AtlasArrayType)17 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)17 AtlasStructType (org.apache.atlas.type.AtlasStructType)16 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)15 AtlasMapType (org.apache.atlas.type.AtlasMapType)13 ArrayList (java.util.ArrayList)11 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)9 HashMap (java.util.HashMap)8 AtlasTypeAccessRequest (org.apache.atlas.authorize.AtlasTypeAccessRequest)8 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)8 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)8 Map (java.util.Map)7 List (java.util.List)6 Collection (java.util.Collection)5 LinkedHashSet (java.util.LinkedHashSet)5 Set (java.util.Set)4