Search in sources :

Example 21 with AtlasType

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

the class AtlasEntityDefStoreV1 method preCreate.

@Override
public AtlasVertex preCreate(AtlasEntityDef entityDef) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasEntityDefStoreV1.preCreate({})", entityDef);
    }
    validateType(entityDef);
    AtlasType type = typeRegistry.getType(entityDef.getName());
    if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.ENTITY) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, entityDef.getName(), TypeCategory.CLASS.name());
    }
    AtlasVertex ret = typeDefStore.findTypeVertexByName(entityDef.getName());
    if (ret != null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_ALREADY_EXISTS, entityDef.getName());
    }
    ret = typeDefStore.createTypeVertex(entityDef);
    updateVertexPreCreate(entityDef, (AtlasEntityType) type, ret);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasEntityDefStoreV1.preCreate({}): {}", entityDef, ret);
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasType(org.apache.atlas.type.AtlasType)

Example 22 with AtlasType

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

the class AtlasArrayFormatConverter method fromV1ToV2.

@Override
public Collection fromV1ToV2(Object v1Obj, AtlasType type, ConverterContext ctx) throws AtlasBaseException {
    Collection ret = null;
    if (v1Obj != null) {
        if (v1Obj instanceof Set) {
            ret = new LinkedHashSet();
        } else {
            ret = new ArrayList();
        }
        AtlasArrayType arrType = (AtlasArrayType) type;
        AtlasType elemType = arrType.getElementType();
        AtlasFormatConverter elemConverter = converterRegistry.getConverter(elemType.getTypeCategory());
        if (v1Obj instanceof Collection) {
            Collection v1List = (Collection) v1Obj;
            for (Object v1Elem : v1List) {
                Object convertedVal = elemConverter.fromV1ToV2(v1Elem, elemType, ctx);
                ret.add(convertedVal);
            }
        } else {
            Object convertedVal = elemConverter.fromV1ToV2(v1Obj, 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) ArrayList(java.util.ArrayList) Collection(java.util.Collection) AtlasType(org.apache.atlas.type.AtlasType)

Example 23 with AtlasType

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

the class AtlasArrayFormatConverter method isValidValueV1.

@Override
public boolean isValidValueV1(Object v1Obj, AtlasType type) {
    boolean ret = false;
    if (v1Obj == null) {
        return true;
    }
    if (type instanceof AtlasArrayType) {
        AtlasArrayType arrType = (AtlasArrayType) type;
        AtlasType elemType = arrType.getElementType();
        AtlasFormatConverter elemConverter = null;
        try {
            elemConverter = converterRegistry.getConverter(elemType.getTypeCategory());
        } catch (AtlasBaseException excp) {
            LOG.warn("failed to get element converter. type={}", type.getTypeName(), excp);
            ret = false;
        }
        if (elemConverter != null) {
            if (v1Obj instanceof Collection) {
                // for empty array
                ret = true;
                for (Object v1Elem : (Collection) v1Obj) {
                    ret = elemConverter.isValidValueV1(v1Elem, elemType);
                    if (!ret) {
                        break;
                    }
                }
            } else {
                ret = elemConverter.isValidValueV1(v1Obj, elemType);
            }
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("AtlasArrayFormatConverter.isValidValueV1(type={}, value={}): {}", (v1Obj != null ? v1Obj.getClass().getCanonicalName() : null), v1Obj, ret);
    }
    return ret;
}
Also used : AtlasArrayType(org.apache.atlas.type.AtlasArrayType) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasType(org.apache.atlas.type.AtlasType) Collection(java.util.Collection)

Example 24 with AtlasType

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

the class AtlasInstanceConverter method getReferenceable.

public Referenceable getReferenceable(AtlasEntity entity, final ConverterContext ctx) throws AtlasBaseException {
    AtlasFormatConverter converter = instanceFormatters.getConverter(TypeCategory.ENTITY);
    AtlasType entityType = typeRegistry.getType(entity.getTypeName());
    Referenceable ref = (Referenceable) converter.fromV2ToV1(entity, entityType, ctx);
    return ref;
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) AtlasType(org.apache.atlas.type.AtlasType)

Example 25 with AtlasType

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

the class GraphBackedSearchIndexer method cleanupIndexForAttribute.

private void cleanupIndexForAttribute(AtlasGraphManagement management, String typeName, AtlasAttributeDef attributeDef) {
    final String propertyName = GraphHelper.encodePropertyKey(typeName + "." + attributeDef.getName());
    String attribTypeName = attributeDef.getTypeName();
    boolean isBuiltInType = AtlasTypeUtil.isBuiltInType(attribTypeName);
    boolean isArrayType = AtlasTypeUtil.isArrayType(attribTypeName);
    boolean isMapType = AtlasTypeUtil.isMapType(attribTypeName);
    try {
        AtlasType atlasType = typeRegistry.getType(attribTypeName);
        if (isMapType || isArrayType || isClassificationType(atlasType) || isEntityType(atlasType)) {
            LOG.warn("Ignoring non-indexable attribute {}", attribTypeName);
        } else if (isBuiltInType || isEnumType(atlasType)) {
            cleanupIndex(management, propertyName);
        } else if (isStructType(atlasType)) {
            AtlasStructDef structDef = typeRegistry.getStructDefByName(attribTypeName);
            cleanupIndices(management, structDef);
        }
    } catch (AtlasBaseException e) {
        LOG.error("No type exists for {}", attribTypeName, e);
    }
}
Also used : AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasType(org.apache.atlas.type.AtlasType)

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