Search in sources :

Example 16 with AtlasStructType

use of org.apache.atlas.type.AtlasStructType 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 17 with AtlasStructType

use of org.apache.atlas.type.AtlasStructType 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 18 with AtlasStructType

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

the class ExportService method addType.

private void addType(AtlasType type, ExportContext context) {
    if (type.getTypeCategory() == TypeCategory.PRIMITIVE) {
        return;
    }
    if (type instanceof AtlasArrayType) {
        AtlasArrayType arrayType = (AtlasArrayType) type;
        addType(arrayType.getElementType(), context);
    } else if (type instanceof AtlasMapType) {
        AtlasMapType mapType = (AtlasMapType) type;
        addType(mapType.getKeyType(), context);
        addType(mapType.getValueType(), context);
    } else if (type instanceof AtlasEntityType) {
        addEntityType((AtlasEntityType) type, context);
    } else if (type instanceof AtlasClassificationType) {
        addClassificationType((AtlasClassificationType) type, context);
    } else if (type instanceof AtlasStructType) {
        addStructType((AtlasStructType) type, context);
    } else if (type instanceof AtlasEnumType) {
        addEnumType((AtlasEnumType) type, context);
    }
}
Also used : AtlasArrayType(org.apache.atlas.type.AtlasArrayType) AtlasEnumType(org.apache.atlas.type.AtlasEnumType) AtlasStructType(org.apache.atlas.type.AtlasStructType) AtlasClassificationType(org.apache.atlas.type.AtlasClassificationType) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) AtlasMapType(org.apache.atlas.type.AtlasMapType)

Example 19 with AtlasStructType

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

the class EntityGraphMapper method createInverseReferenceUsingRelationship.

private AtlasEdge createInverseReferenceUsingRelationship(AtlasAttribute inverseAttribute, AtlasEdge edge, Map<String, Object> relationshipAttributes) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> createInverseReferenceUsingRelationship()");
    }
    String inverseAttributeName = inverseAttribute.getName();
    AtlasType inverseAttributeType = inverseAttribute.getDefinedInType();
    AtlasVertex inverseVertex = edge.getInVertex();
    AtlasVertex vertex = edge.getOutVertex();
    AtlasEdge ret;
    if (inverseAttributeType instanceof AtlasEntityType) {
        AtlasEntityType entityType = (AtlasEntityType) inverseAttributeType;
        if (entityType.hasRelationshipAttribute(inverseAttributeName)) {
            String relationshipName = graphHelper.getRelationshipDefName(inverseVertex, entityType, inverseAttributeName);
            ret = getOrCreateRelationship(inverseVertex, vertex, relationshipName, relationshipAttributes);
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug("No RelationshipDef defined between {} and {} on attribute: {}", inverseAttributeType, AtlasGraphUtilsV1.getTypeName(vertex), inverseAttributeName);
            }
            // if no RelationshipDef found, use legacy way to create edges
            ret = createInverseReference(inverseAttribute, (AtlasStructType) inverseAttributeType, inverseVertex, vertex);
        }
    } else {
        // inverseAttribute not of type AtlasEntityType, use legacy way to create edges
        ret = createInverseReference(inverseAttribute, (AtlasStructType) inverseAttributeType, inverseVertex, vertex);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== createInverseReferenceUsingRelationship()");
    }
    return ret;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasType(org.apache.atlas.type.AtlasType) AtlasStructType(org.apache.atlas.type.AtlasStructType) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 20 with AtlasStructType

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

the class EntityGraphMapper method mapAttributes.

private void mapAttributes(AtlasStruct struct, AtlasVertex vertex, EntityOperation op, EntityMutationContext context) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> mapAttributes({}, {})", op, struct.getTypeName());
    }
    if (MapUtils.isNotEmpty(struct.getAttributes())) {
        AtlasStructType structType = getStructType(struct.getTypeName());
        if (op.equals(CREATE)) {
            for (AtlasAttribute attribute : structType.getAllAttributes().values()) {
                Object attrValue = struct.getAttribute(attribute.getName());
                mapAttribute(attribute, attrValue, vertex, op, context);
            }
        } else if (op.equals(UPDATE)) {
            for (String attrName : struct.getAttributes().keySet()) {
                AtlasAttribute attribute = structType.getAttribute(attrName);
                if (attribute != null) {
                    Object attrValue = struct.getAttribute(attrName);
                    mapAttribute(attribute, attrValue, vertex, op, context);
                } else {
                    LOG.warn("mapAttributes(): invalid attribute {}.{}. Ignored..", struct.getTypeName(), attrName);
                }
            }
        }
        updateModificationMetadata(vertex);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== mapAttributes({}, {})", op, struct.getTypeName());
    }
}
Also used : AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasStructType(org.apache.atlas.type.AtlasStructType)

Aggregations

AtlasStructType (org.apache.atlas.type.AtlasStructType)27 AtlasType (org.apache.atlas.type.AtlasType)12 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)10 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)8 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)7 AtlasAttribute (org.apache.atlas.type.AtlasStructType.AtlasAttribute)7 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)6 AtlasArrayType (org.apache.atlas.type.AtlasArrayType)5 AtlasStruct (org.apache.atlas.model.instance.AtlasStruct)4 AtlasMapType (org.apache.atlas.type.AtlasMapType)4 Map (java.util.Map)3 RequestContextV1 (org.apache.atlas.RequestContextV1)3 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)3 HashMap (java.util.HashMap)2 TypeCategory (org.apache.atlas.model.TypeCategory)2 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)2 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)2 AtlasEdgeLabel (org.apache.atlas.repository.graph.AtlasEdgeLabel)2 AtlasTypeDefGraphStoreV1 (org.apache.atlas.repository.store.graph.v1.AtlasTypeDefGraphStoreV1)2 AtlasClassificationType (org.apache.atlas.type.AtlasClassificationType)2