Search in sources :

Example 51 with AtlasType

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

the class LineageUtils method isDataSet.

private static boolean isDataSet(String typeName, AtlasTypeRegistry registry) throws AtlasBaseException {
    boolean ret = false;
    AtlasType type = registry.getType(typeName);
    if (type instanceof AtlasEntityType) {
        AtlasEntityType entityType = (AtlasEntityType) type;
        ret = entityType.getAllSuperTypes().contains(AtlasBaseTypeDef.ATLAS_TYPE_DATASET);
    }
    return ret;
}
Also used : AtlasType(org.apache.atlas.type.AtlasType) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 52 with AtlasType

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

the class AtlasStructDefStoreV1 method updateByGuid.

@Override
public AtlasStructDef updateByGuid(String guid, AtlasStructDef structDef) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasStructDefStoreV1.updateByGuid({})", guid);
    }
    AtlasStructDef existingDef = typeRegistry.getStructDefByGuid(guid);
    AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_UPDATE, existingDef), "update struct-def ", (existingDef != null ? existingDef.getName() : guid));
    validateType(structDef);
    AtlasType type = typeRegistry.getTypeByGuid(guid);
    if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.STRUCT) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, structDef.getName(), TypeCategory.STRUCT.name());
    }
    AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.STRUCT);
    if (vertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
    }
    AtlasStructDefStoreV1.updateVertexPreUpdate(structDef, (AtlasStructType) type, vertex, typeDefStore);
    AtlasStructDefStoreV1.updateVertexAddReferences(structDef, vertex, typeDefStore);
    AtlasStructDef ret = toStructDef(vertex);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasStructDefStoreV1.updateByGuid({}): {}", guid, ret);
    }
    return ret;
}
Also used : AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasTypeAccessRequest(org.apache.atlas.authorize.AtlasTypeAccessRequest) AtlasType(org.apache.atlas.type.AtlasType)

Example 53 with AtlasType

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

the class DeleteHandlerV1 method deleteTypeVertex.

/**
 * Deleting any type vertex. Goes over the complex attributes and removes the references
 * @param instanceVertex
 * @throws AtlasException
 */
protected void deleteTypeVertex(AtlasVertex instanceVertex, boolean force) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Deleting {}", string(instanceVertex));
    }
    String typeName = GraphHelper.getTypeName(instanceVertex);
    AtlasType parentType = typeRegistry.getType(typeName);
    if (parentType instanceof AtlasStructType) {
        AtlasStructType structType = (AtlasStructType) parentType;
        boolean isEntityType = (parentType instanceof AtlasEntityType);
        for (AtlasStructType.AtlasAttribute attributeInfo : structType.getAllAttributes().values()) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Deleting attribute {} for {}", attributeInfo.getName(), string(instanceVertex));
            }
            boolean isOwned = isEntityType && attributeInfo.isOwnedRef();
            AtlasType attrType = attributeInfo.getAttributeType();
            String edgeLabel = AtlasGraphUtilsV1.getAttributeEdgeLabel(structType, attributeInfo.getName());
            switch(attrType.getTypeCategory()) {
                case OBJECT_ID_TYPE:
                    // If its class attribute, delete the reference
                    deleteEdgeReference(instanceVertex, edgeLabel, attrType.getTypeCategory(), isOwned);
                    break;
                case STRUCT:
                    // If its struct attribute, delete the reference
                    deleteEdgeReference(instanceVertex, edgeLabel, attrType.getTypeCategory(), false);
                    break;
                case ARRAY:
                    // For array attribute, if the element is struct/class, delete all the references
                    AtlasArrayType arrType = (AtlasArrayType) attrType;
                    AtlasType elemType = arrType.getElementType();
                    if (AtlasGraphUtilsV1.isReference(elemType.getTypeCategory())) {
                        Iterator<AtlasEdge> edges = graphHelper.getOutGoingEdgesByLabel(instanceVertex, edgeLabel);
                        if (edges != null) {
                            while (edges.hasNext()) {
                                AtlasEdge edge = edges.next();
                                deleteEdgeReference(edge, elemType.getTypeCategory(), isOwned, false, instanceVertex);
                            }
                        }
                    }
                    break;
                case MAP:
                    // For map attribute, if the value type is struct/class, delete all the references
                    AtlasMapType mapType = (AtlasMapType) attrType;
                    AtlasType keyType = mapType.getKeyType();
                    TypeCategory valueTypeCategory = mapType.getValueType().getTypeCategory();
                    String propertyName = AtlasGraphUtilsV1.getQualifiedAttributePropertyKey(structType, attributeInfo.getName());
                    if (AtlasGraphUtilsV1.isReference(valueTypeCategory)) {
                        List<Object> keys = EntityGraphMapper.getArrayElementsProperty(keyType, instanceVertex, propertyName);
                        if (keys != null) {
                            for (Object key : keys) {
                                String mapEdgeLabel = GraphHelper.getQualifiedNameForMapKey(edgeLabel, (String) key);
                                deleteEdgeReference(instanceVertex, mapEdgeLabel, valueTypeCategory, isOwned);
                            }
                        }
                    }
                    break;
            }
        }
    }
    deleteVertex(instanceVertex, force);
}
Also used : AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasArrayType(org.apache.atlas.type.AtlasArrayType) AtlasType(org.apache.atlas.type.AtlasType) AtlasStructType(org.apache.atlas.type.AtlasStructType) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) AtlasMapType(org.apache.atlas.type.AtlasMapType) TypeCategory(org.apache.atlas.model.TypeCategory) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 54 with AtlasType

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

the class DeleteHandlerV1 method getAttributeForEdge.

protected AtlasAttribute getAttributeForEdge(String edgeLabel) throws AtlasBaseException {
    AtlasEdgeLabel atlasEdgeLabel = new AtlasEdgeLabel(edgeLabel);
    AtlasType parentType = typeRegistry.getType(atlasEdgeLabel.getTypeName());
    AtlasStructType parentStructType = (AtlasStructType) parentType;
    return parentStructType.getAttribute(atlasEdgeLabel.getAttributeName());
}
Also used : AtlasEdgeLabel(org.apache.atlas.repository.graph.AtlasEdgeLabel) AtlasType(org.apache.atlas.type.AtlasType) AtlasStructType(org.apache.atlas.type.AtlasStructType)

Example 55 with AtlasType

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

the class EntityGraphRetriever method mapAttributes.

private void mapAttributes(AtlasEdge edge, AtlasRelationship relationship) throws AtlasBaseException {
    AtlasType objType = typeRegistry.getType(relationship.getTypeName());
    if (!(objType instanceof AtlasRelationshipType)) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, relationship.getTypeName());
    }
    AtlasRelationshipType relationshipType = (AtlasRelationshipType) objType;
    for (AtlasAttribute attribute : relationshipType.getAllAttributes().values()) {
        // mapping only primitive attributes
        Object attrValue = mapVertexToPrimitive(edge, attribute.getQualifiedName(), attribute.getAttributeDef());
        relationship.setAttribute(attribute.getName(), attrValue);
    }
}
Also used : AtlasRelationshipType(org.apache.atlas.type.AtlasRelationshipType) AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) 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