Search in sources :

Example 16 with VertexFrame

use of com.tinkerpop.frames.VertexFrame in project org.openntf.domino by OpenNTF.

the class JsonSearchAdapter method putJsonProperty.

@Override
public void putJsonProperty(final String paramKey, Object value) {
    Object frame = getFrame();
    if (frame != null) {
        CaseInsensitiveString key = new CaseInsensitiveString(paramKey);
        Method crystal = getSetters().get(key);
        if (crystal != null) {
            try {
                Class<?>[] types = crystal.getParameterTypes();
                Class<?> type = types[0];
                if (value == null) {
                    String propName = null;
                    TypedProperty tprop = crystal.getAnnotation(TypedProperty.class);
                    if (tprop != null) {
                        propName = tprop.value();
                    } else {
                        Property prop = crystal.getAnnotation(Property.class);
                        if (prop != null) {
                            propName = prop.value();
                        }
                    }
                    if (propName != null) {
                        if (frame instanceof VertexFrame) {
                            ((VertexFrame) frame).asVertex().setProperty(propName, null);
                        } else if (frame instanceof EdgeFrame) {
                            ((EdgeFrame) frame).asEdge().setProperty(propName, null);
                        }
                    } else {
                        System.err.println("ALERT the next operation will probably throw an exception");
                        Object[] nullarg = { type.cast(null) };
                        crystal.invoke(frame, nullarg);
                    }
                } else if (!type.isAssignableFrom(value.getClass())) {
                    value = TypeUtils.convertToTarget(value, type, org.openntf.domino.utils.Factory.getSession(SessionType.CURRENT));
                    crystal.invoke(frame, value);
                } else if (JsonJavaObject.class.equals(type)) {
                    // FIXME NTF this is a complete hack :(
                    TypedProperty prop = crystal.getAnnotation(TypedProperty.class);
                    String itemname = prop.value();
                    if (frame instanceof DVertexFrame) {
                        Document doc = ((DVertexFrame) frame).asDocument();
                        TypeUtils.writeToItem(doc, itemname, value, false);
                    }
                } else {
                    crystal.invoke(frame, value);
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        } else {
            Method man = getGetters().get(key);
            if (man == null) {
                // undefined property
                if (frame instanceof EdgeFrame) {
                    ((EdgeFrame) frame).asEdge().setProperty(paramKey, value);
                } else if (frame instanceof VertexFrame) {
                    ((VertexFrame) frame).asVertex().setProperty(paramKey, value);
                }
            } else {
            // NTF if there is a getter but no setter, this is a
            // read-only property. Disregard the JSON
            }
        }
    }
}
Also used : EdgeFrame(com.tinkerpop.frames.EdgeFrame) DEdgeFrame(org.openntf.domino.graph2.builtin.DEdgeFrame) Method(java.lang.reflect.Method) CaseInsensitiveString(org.openntf.domino.types.CaseInsensitiveString) Document(org.openntf.domino.Document) CaseInsensitiveString(org.openntf.domino.types.CaseInsensitiveString) UserAccessException(org.openntf.domino.exceptions.UserAccessException) DVertexFrame(org.openntf.domino.graph2.builtin.DVertexFrame) DVertexFrame(org.openntf.domino.graph2.builtin.DVertexFrame) VertexFrame(com.tinkerpop.frames.VertexFrame) JsonJavaObject(com.ibm.commons.util.io.json.JsonJavaObject) JsonObject(com.ibm.commons.util.io.json.JsonObject) Property(com.tinkerpop.frames.Property) TypedProperty(org.openntf.domino.graph2.annotations.TypedProperty) TypedProperty(org.openntf.domino.graph2.annotations.TypedProperty)

Example 17 with VertexFrame

use of com.tinkerpop.frames.VertexFrame in project org.openntf.domino by OpenNTF.

the class JsonSearchAdapter method getJsonProperties.

@Override
public Iterator<String> getJsonProperties() {
    List<String> result = new ArrayList<String>();
    result.add("@id");
    result.add("@type");
    result.add("@editable");
    if (getIncludeDebug()) {
        result.add("@debug");
    }
    Collection<CharSequence> props = getProperties();
    if (props == null) {
        // NoteCoordinate nc = (NoteCoordinate)
        // ((VertexFrame)frame_).asVertex().getId();
        props = new ArrayList<CharSequence>();
        props.addAll(getGetters().keySet());
        if (props == null || props.size() < 5) {
            if (frame_ instanceof DVertexFrame) {
                try {
                    Set<String> raw = ((DVertexFrame) frame_).asVertex().getPropertyKeys();
                    props.addAll(CaseInsensitiveString.toCaseInsensitive(raw));
                } catch (Throwable t) {
                    Throwable cause = t.getCause();
                    if (cause != null) {
                        System.err.println("Exception trying to process a frame of type " + DGraphUtils.findInterface(frame_) + " resulting in a " + cause.getClass().getSimpleName());
                        cause.printStackTrace();
                        try {
                            throw cause;
                        } catch (Throwable e) {
                            e.printStackTrace();
                        }
                    }
                }
            } else if (frame_ instanceof DEdgeFrame) {
            // Set<CharSequence> raw = ((DEdgeFrame)
            // frame_).asMap().keySet();
            // props.addAll(CaseInsensitiveString.toCaseInsensitive(raw));
            }
        }
    }
    for (CharSequence cis : props) {
        result.add(cis.toString());
    }
    Object frame = getFrame();
    if (frame instanceof VertexFrame && getIncludeEdges()) {
        result.add("@edges");
    }
    if (getIncludeActions()) {
        result.add("@actions");
    }
    if (frame instanceof VertexFrame && getIncludeCounts()) {
        for (CaseInsensitiveString key : getCounters().keySet()) {
            result.add("@counts" + key.toString());
        }
    }
    if (frame instanceof VertexFrame) {
        Vertex v = ((VertexFrame) frame).asVertex();
        if (v instanceof DProxyVertex) {
            result.add("@proxyid");
        }
    }
    if (frame instanceof VertexFrame && getLabels() != null) {
        for (CharSequence cis : getLabels()) {
            result.add("#" + cis.toString());
        }
    }
    if (frame instanceof EdgeFrame) {
        result.add("@in");
        result.add("@out");
    }
    if (frame instanceof ViewVertex) {
        result.add("@columninfo");
    }
    if (frame instanceof ViewVertex.Contains) {
        Edge edge = ((ViewVertex.Contains) frame).asEdge();
        if (edge instanceof DEdge) {
            result.addAll(((DEdge) edge).getDelegate().keySet());
        }
    }
    Collection<CharSequence> hideProps = getHideProperties();
    if (hideProps != null && !hideProps.isEmpty()) {
        for (CharSequence cis : hideProps) {
            result.remove(cis.toString());
        }
    }
    return result.iterator();
}
Also used : ViewVertex(org.openntf.domino.graph2.builtin.ViewVertex) DVertex(org.openntf.domino.graph2.impl.DVertex) Vertex(com.tinkerpop.blueprints.Vertex) DbInfoVertex(org.openntf.domino.graph2.builtin.DbInfoVertex) DProxyVertex(org.openntf.domino.graph2.impl.DProxyVertex) DProxyVertex(org.openntf.domino.graph2.impl.DProxyVertex) EdgeFrame(com.tinkerpop.frames.EdgeFrame) DEdgeFrame(org.openntf.domino.graph2.builtin.DEdgeFrame) ArrayList(java.util.ArrayList) CaseInsensitiveString(org.openntf.domino.types.CaseInsensitiveString) CaseInsensitiveString(org.openntf.domino.types.CaseInsensitiveString) DVertexFrame(org.openntf.domino.graph2.builtin.DVertexFrame) DVertexFrame(org.openntf.domino.graph2.builtin.DVertexFrame) VertexFrame(com.tinkerpop.frames.VertexFrame) ViewVertex(org.openntf.domino.graph2.builtin.ViewVertex) DEdgeFrame(org.openntf.domino.graph2.builtin.DEdgeFrame) JsonJavaObject(com.ibm.commons.util.io.json.JsonJavaObject) JsonObject(com.ibm.commons.util.io.json.JsonObject) DEdge(org.openntf.domino.graph2.impl.DEdge) Edge(com.tinkerpop.blueprints.Edge) DEdge(org.openntf.domino.graph2.impl.DEdge)

Example 18 with VertexFrame

use of com.tinkerpop.frames.VertexFrame in project org.openntf.domino by OpenNTF.

the class JsonGraphWriter method outObject.

@Override
public void outObject(Object paramObject) throws IOException, JsonException {
    // + (paramObject == null ? "NULL" : paramObject.getClass().getName()));
    try {
        if (paramObject != null) {
            Class<?> objClass = paramObject.getClass();
            IJsonWriterAdapter adapter = factory_.getJsonWriterAdapter(objClass);
            if (adapter != null) {
                paramObject = adapter.toJson(paramObject);
            }
        }
        if (paramObject == null) {
            super.outNull();
        // } else if (paramObject instanceof Term) {
        // JsonSearchAdapter adapter = new JsonSearchAdapter(graph_, (Term) paramObject, parameters_,
        // isCollectionRoute_);
        // super.outObject(adapter);
        // } else if (paramObject instanceof Value) {
        // JsonSearchAdapter adapter = new JsonSearchAdapter(graph_, (Value) paramObject, parameters_,
        // isCollectionRoute_);
        // super.outObject(adapter);
        // } else if (paramObject instanceof RichTextReference) {
        // JsonSearchAdapter adapter = new JsonSearchAdapter(graph_, (RichTextReference) paramObject, parameters_,
        // isCollectionRoute_);
        // super.outObject(adapter);
        } else if (paramObject instanceof EdgeFrame) {
            JsonFrameAdapter adapter = new JsonFrameAdapter(graph_, (EdgeFrame) paramObject, parameters_, isCollectionRoute_);
            super.outObject(adapter);
        } else if (paramObject instanceof VertexFrame) {
            JsonFrameAdapter adapter = new JsonFrameAdapter(graph_, (VertexFrame) paramObject, parameters_, isCollectionRoute_);
            super.outObject(adapter);
        } else if (paramObject instanceof Class<?>) {
            String className = ((Class<?>) paramObject).getName();
            super.outStringLiteral(className);
        } else if (paramObject instanceof RichTextItem) {
            outRichTextItem((RichTextItem) paramObject);
        } else if (paramObject instanceof Enum) {
            String className = ((Enum<?>) paramObject).getClass().getName();
            String enumName = ((Enum<?>) paramObject).name();
        } else if (paramObject instanceof NoteCoordinate) {
            String nc = ((NoteCoordinate) paramObject).toString();
            super.outStringLiteral(nc);
        } else if (paramObject instanceof org.openntf.domino.impl.View.DominoColumnInfo) {
            String itemName = ((org.openntf.domino.impl.View.DominoColumnInfo) paramObject).getItemName();
            super.outStringLiteral(itemName);
        } else if (paramObject instanceof Set) {
            // System.out.println("TEMP DEBUG outObject received a Set");
            outArrayLiteral(((Set) paramObject).toArray());
        } else if (paramObject instanceof DateTime) {
            outDateLiteral((DateTime) paramObject);
        } else if (paramObject instanceof DateRange) {
            outDateRangeLiteral((DateRange) paramObject);
        } else if (paramObject instanceof NoteCoordinate) {
            outNoteCoordinate((NoteCoordinate) paramObject);
        } else if (paramObject instanceof Throwable) {
            outException((Throwable) paramObject);
        } else {
            // Class<?> clazz = paramObject.getClass();
            // String name = clazz.getName();
            super.outObject(paramObject);
        }
    } catch (UserAccessException uae) {
        throw uae;
    } catch (RuntimeException re) {
        throw re;
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
Also used : NoteCoordinate(org.openntf.domino.big.impl.NoteCoordinate) EdgeFrame(com.tinkerpop.frames.EdgeFrame) Set(java.util.Set) JsonFrameAdapter(org.openntf.domino.rest.resources.frames.JsonFrameAdapter) IJsonWriterAdapter(org.openntf.domino.rest.json.JsonGraphFactory.IJsonWriterAdapter) UserAccessException(org.openntf.domino.exceptions.UserAccessException) DateTime(org.openntf.domino.DateTime) DateRange(org.openntf.domino.DateRange) VertexFrame(com.tinkerpop.frames.VertexFrame) RichTextItem(org.openntf.domino.RichTextItem)

Example 19 with VertexFrame

use of com.tinkerpop.frames.VertexFrame in project org.openntf.domino by OpenNTF.

the class AbstractIncidenceHandler method processVertexIncidence.

@SuppressWarnings({ "rawtypes", "unchecked" })
public Object processVertexIncidence(final Annotation annotation, final Method method, final Object[] arguments, final FramedGraph framedGraph, final Vertex vertex) {
    Direction dir = Direction.BOTH;
    String label = "";
    boolean unique = false;
    if (annotation instanceof Adjacency) {
        dir = ((Adjacency) annotation).direction();
        label = ((Adjacency) annotation).label();
    } else if (annotation instanceof AdjacencyUnique) {
        dir = ((AdjacencyUnique) annotation).direction();
        label = ((AdjacencyUnique) annotation).label();
        unique = true;
    } else if (annotation instanceof Incidence) {
        dir = ((Incidence) annotation).direction();
        label = ((Incidence) annotation).label();
    } else if (annotation instanceof IncidenceUnique) {
        dir = ((IncidenceUnique) annotation).direction();
        label = ((IncidenceUnique) annotation).label();
        unique = true;
    }
    if (ClassUtilities.isGetMethod(method)) {
        Class<?> returnType = method.getReturnType();
        if (Iterable.class.isAssignableFrom(returnType)) {
            DEdgeList edgeList = (DEdgeList) vertex.getEdges(dir, label);
            edgeList.setUnique(unique);
            return new FramedEdgeList(framedGraph, vertex, edgeList, ClassUtilities.getGenericClass(method));
        } else if (Edge.class.isAssignableFrom(returnType)) {
            Iterator<Edge> it = vertex.getEdges(dir, label).iterator();
            if (it.hasNext()) {
                return it.next();
            } else {
                return null;
            }
        } else {
            Iterator<Edge> it = vertex.getEdges(dir, label).iterator();
            if (it.hasNext()) {
                Edge e = it.next();
                return framedGraph.frame(e, returnType);
            } else {
                return null;
            }
        }
    } else if (AnnotationUtilities.isFindMethod(method)) {
        Vertex newVertex;
        Edge resultEdge = null;
        newVertex = ((VertexFrame) arguments[0]).asVertex();
        resultEdge = findEdge(annotation, framedGraph, vertex, newVertex);
        if (resultEdge != null) {
            return framedGraph.frame(resultEdge, method.getReturnType());
        }
    } else if (AnnotationUtilities.isCountMethod(method)) {
        return countEdges(annotation, vertex);
    } else if (ClassUtilities.isAddMethod(method)) {
        Vertex newVertex;
        Edge resultEdge = null;
        newVertex = ((VertexFrame) arguments[0]).asVertex();
        if (unique) {
            resultEdge = findEdge(annotation, framedGraph, vertex, newVertex);
        }
        if (resultEdge == null) {
            String replicaid = null;
            if (framedGraph instanceof DFramedTransactionalGraph) {
                DElementStore store = ((DFramedTransactionalGraph) framedGraph).getElementStore(method.getReturnType());
                long rawkey = store.getStoreKey();
                replicaid = NoteCoordinate.Utils.getReplidFromLong(rawkey);
            }
            resultEdge = addEdge(annotation, framedGraph, vertex, newVertex, replicaid);
        }
        return framedGraph.frame(resultEdge, method.getReturnType());
    } else if (ClassUtilities.isRemoveMethod(method)) {
        framedGraph.removeEdge(((EdgeFrame) arguments[0]).asEdge());
        return null;
    }
    return null;
}
Also used : DVertex(org.openntf.domino.graph2.DVertex) Vertex(com.tinkerpop.blueprints.Vertex) DFramedTransactionalGraph(org.openntf.domino.graph2.impl.DFramedTransactionalGraph) DElementStore(org.openntf.domino.graph2.DElementStore) Direction(com.tinkerpop.blueprints.Direction) Incidence(com.tinkerpop.frames.Incidence) VertexFrame(com.tinkerpop.frames.VertexFrame) Iterator(java.util.Iterator) Adjacency(com.tinkerpop.frames.Adjacency) DEdgeList(org.openntf.domino.graph2.DEdgeList) Edge(com.tinkerpop.blueprints.Edge)

Example 20 with VertexFrame

use of com.tinkerpop.frames.VertexFrame in project org.openntf.domino by OpenNTF.

the class FramedVertexList method applyFilter.

public FramedVertexList<T> applyFilter(final String key, final Object value) {
    DVertexList vertList = new DVertexList((DVertex) sourceVertex_);
    if (this.size() > 0) {
        for (VertexFrame vertex : this) {
            try {
                if ("@type".equals(key)) {
                    if (DGraphUtils.isType(vertex, TypeUtils.toString(value))) {
                        vertList.add((DVertex) vertex.asVertex());
                    }
                } else {
                    Object vertexVal = DGraphUtils.getFramedProperty(getGraph(), vertex, key);
                    if (vertexVal instanceof Collection) {
                        for (Object rawVal : (Collection) vertexVal) {
                            if (value.equals(TypeUtils.toString(rawVal))) {
                                vertList.add((DVertex) vertex.asVertex());
                            }
                        }
                    } else {
                        if (value.equals(TypeUtils.toString(vertexVal))) {
                            vertList.add((DVertex) vertex.asVertex());
                        }
                    }
                }
            } catch (Throwable t) {
                t.printStackTrace();
            }
        }
    }
    FramedVertexList result = new FramedVertexList(getGraph(), sourceVertex_, vertList, this.kind);
    return result;
}
Also used : VertexFrame(com.tinkerpop.frames.VertexFrame) Collection(java.util.Collection) DVertexList(org.openntf.domino.graph2.impl.DVertexList)

Aggregations

VertexFrame (com.tinkerpop.frames.VertexFrame)22 EdgeFrame (com.tinkerpop.frames.EdgeFrame)14 DVertexFrame (org.openntf.domino.graph2.builtin.DVertexFrame)13 JsonJavaObject (com.ibm.commons.util.io.json.JsonJavaObject)12 CaseInsensitiveString (org.openntf.domino.types.CaseInsensitiveString)12 Vertex (com.tinkerpop.blueprints.Vertex)11 UserAccessException (org.openntf.domino.exceptions.UserAccessException)9 DEdgeFrame (org.openntf.domino.graph2.builtin.DEdgeFrame)9 LinkedHashMap (java.util.LinkedHashMap)8 Edge (com.tinkerpop.blueprints.Edge)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 JsonObject (com.ibm.commons.util.io.json.JsonObject)6 Method (java.lang.reflect.Method)6 NoteCoordinate (org.openntf.domino.big.NoteCoordinate)6 DVertex (org.openntf.domino.graph2.impl.DVertex)6 List (java.util.List)5 DbInfoVertex (org.openntf.domino.graph2.builtin.DbInfoVertex)5 ViewVertex (org.openntf.domino.graph2.builtin.ViewVertex)5 DEdge (org.openntf.domino.graph2.impl.DEdge)5