Search in sources :

Example 11 with AtlasStructType

use of org.apache.atlas.type.AtlasStructType in project incubator-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 12 with AtlasStructType

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

the class AtlasStructFormatConverter method fromV2ToV1.

@Override
public Object fromV2ToV1(Object v2Obj, AtlasType type, ConverterContext converterContext) throws AtlasBaseException {
    Struct ret = null;
    if (v2Obj != null) {
        AtlasStructType structType = (AtlasStructType) type;
        if (v2Obj instanceof Map) {
            final Map v2Map = (Map) v2Obj;
            final Map v2Attribs;
            if (v2Map.containsKey(ATTRIBUTES_PROPERTY_KEY)) {
                v2Attribs = (Map) v2Map.get(ATTRIBUTES_PROPERTY_KEY);
            } else {
                v2Attribs = v2Map;
            }
            if (MapUtils.isNotEmpty(v2Attribs)) {
                ret = new Struct(type.getTypeName(), fromV2ToV1(structType, v2Attribs, converterContext));
            } else {
                ret = new Struct(type.getTypeName());
            }
        } else if (v2Obj instanceof AtlasStruct) {
            AtlasStruct struct = (AtlasStruct) v2Obj;
            ret = new Struct(type.getTypeName(), fromV2ToV1(structType, struct.getAttributes(), converterContext));
        } else {
            throw new AtlasBaseException(AtlasErrorCode.UNEXPECTED_TYPE, "Map or AtlasStruct", v2Obj.getClass().getCanonicalName());
        }
    }
    return ret;
}
Also used : AtlasStruct(org.apache.atlas.model.instance.AtlasStruct) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasStructType(org.apache.atlas.type.AtlasStructType) HashMap(java.util.HashMap) Map(java.util.Map) AtlasStruct(org.apache.atlas.model.instance.AtlasStruct) IStruct(org.apache.atlas.typesystem.IStruct) Struct(org.apache.atlas.typesystem.Struct)

Example 13 with AtlasStructType

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

the class AtlasStructFormatConverter method fromV1ToV2.

@Override
public Object fromV1ToV2(Object v1Obj, AtlasType type, ConverterContext converterContext) throws AtlasBaseException {
    AtlasStruct ret = null;
    if (v1Obj != null) {
        AtlasStructType structType = (AtlasStructType) type;
        if (v1Obj instanceof Map) {
            final Map v1Map = (Map) v1Obj;
            final Map v1Attribs = (Map) v1Map.get(ATTRIBUTES_PROPERTY_KEY);
            if (MapUtils.isNotEmpty(v1Attribs)) {
                ret = new AtlasStruct(type.getTypeName(), fromV1ToV2(structType, v1Attribs, converterContext));
            } else {
                ret = new AtlasStruct(type.getTypeName());
            }
        } else if (v1Obj instanceof IStruct) {
            IStruct struct = (IStruct) v1Obj;
            Map<String, Object> v1Attribs = null;
            try {
                v1Attribs = struct.getValuesMap();
            } catch (AtlasException excp) {
                LOG.error("IStruct.getValuesMap() failed", excp);
            }
            ret = new AtlasStruct(type.getTypeName(), fromV1ToV2(structType, v1Attribs, converterContext));
        } else {
            throw new AtlasBaseException(AtlasErrorCode.UNEXPECTED_TYPE, "Map or IStruct", v1Obj.getClass().getCanonicalName());
        }
    }
    return ret;
}
Also used : AtlasStruct(org.apache.atlas.model.instance.AtlasStruct) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasStructType(org.apache.atlas.type.AtlasStructType) AtlasException(org.apache.atlas.AtlasException) HashMap(java.util.HashMap) Map(java.util.Map) IStruct(org.apache.atlas.typesystem.IStruct)

Example 14 with AtlasStructType

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

the class RestUtilsTest method convertToJsonAndBack.

private AtlasAttributeDef convertToJsonAndBack(AtlasTypeRegistry registry, AtlasStructDef structDef, AtlasAttributeDef attributeDef, boolean compositeExpected) throws AtlasBaseException {
    AtlasTypeDefGraphStoreV1 typeDefStore = makeTypeStore(registry);
    AtlasStructType structType = (AtlasStructType) registry.getType(structDef.getName());
    AtlasAttribute attribute = structType.getAttribute(attributeDef.getName());
    String attribJson = AtlasStructDefStoreV1.toJsonFromAttribute(attribute);
    Map attrInfo = AtlasType.fromJson(attribJson, Map.class);
    Assert.assertEquals(attrInfo.get("isComposite"), compositeExpected);
    return AtlasStructDefStoreV1.toAttributeDefFromJson(structDef, attrInfo, typeDefStore);
}
Also used : AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasTypeDefGraphStoreV1(org.apache.atlas.repository.store.graph.v1.AtlasTypeDefGraphStoreV1) AtlasStructType(org.apache.atlas.type.AtlasStructType) Map(java.util.Map)

Example 15 with AtlasStructType

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

the class EntityGraphMapper method addInverseReference.

private void addInverseReference(AttributeMutationContext ctx, AtlasAttribute inverseAttribute, AtlasEdge edge) throws AtlasBaseException {
    AtlasStructType inverseType = inverseAttribute.getDefinedInType();
    String propertyName = AtlasGraphUtilsV1.getQualifiedAttributePropertyKey(inverseType, inverseAttribute.getName());
    AtlasVertex vertex = edge.getOutVertex();
    AtlasVertex inverseVertex = edge.getInVertex();
    String inverseEdgeLabel = AtlasGraphUtilsV1.getEdgeLabel(propertyName);
    AtlasEdge inverseEdge = graphHelper.getEdgeForLabel(inverseVertex, inverseEdgeLabel);
    AtlasEdge newEdge;
    try {
        newEdge = graphHelper.getOrCreateEdge(inverseVertex, vertex, inverseEdgeLabel);
    } catch (RepositoryException e) {
        throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e);
    }
    boolean inverseUpdated = true;
    switch(inverseAttribute.getAttributeType().getTypeCategory()) {
        case OBJECT_ID_TYPE:
            if (inverseEdge != null) {
                if (!inverseEdge.equals(newEdge)) {
                    // Disconnect old reference
                    deleteHandler.deleteEdgeReference(inverseEdge, inverseAttribute.getAttributeType().getTypeCategory(), inverseAttribute.isOwnedRef(), true);
                } else {
                    // Edge already exists for this attribute between these vertices.
                    inverseUpdated = false;
                }
            }
            break;
        case ARRAY:
            // Add edge ID to property value
            List<String> elements = inverseVertex.getProperty(propertyName, List.class);
            if (elements == null) {
                elements = new ArrayList<>();
                elements.add(newEdge.getId().toString());
                inverseVertex.setProperty(propertyName, elements);
            } else {
                if (!elements.contains(newEdge.getId().toString())) {
                    elements.add(newEdge.getId().toString());
                    inverseVertex.setProperty(propertyName, elements);
                } else {
                    // Property value list already contains the edge ID.
                    inverseUpdated = false;
                }
            }
            break;
        default:
            break;
    }
    if (inverseUpdated) {
        updateModificationMetadata(inverseVertex);
        AtlasObjectId inverseEntityId = new AtlasObjectId(AtlasGraphUtilsV1.getIdFromVertex(inverseVertex), inverseType.getTypeName());
        RequestContextV1.get().recordEntityUpdate(inverseEntityId);
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasStructType(org.apache.atlas.type.AtlasStructType) RepositoryException(org.apache.atlas.repository.RepositoryException) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

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