Search in sources :

Example 1 with ViewVertex

use of org.openntf.domino.graph2.builtin.ViewVertex in project org.openntf.domino by OpenNTF.

the class DElementStore method removeEdge.

/*public Element getElement_OLD(final Object id, final Class<? extends Element> type) throws IllegalStateException {
			Element result = null;
			Element chk = getCachedElement(id, Element.class);
			if (chk != null) {
				result = chk;
			} else {
				boolean isProxiedSource = false;
				Object delegate = null;
				if (id instanceof NoteCoordinate && isProxied()) {
					NoteCoordinate nc = (NoteCoordinate) id;
					if (getStoreKey().equals(nc.getReplicaLong())) {
						//this is a request for a vertex out of the proxied store, not the proxy itself
						Database db = (Database) getStoreDelegate();
						String unid = nc.getUNID();
						delegate = db.getDocumentByUNID(unid, true);
						if (delegate != null) {
							isProxiedSource = true;
						}
					}
				}
				if (delegate == null) {
					Object localkey = localizeKey(id);
					delegate = findElementDelegate(localkey);
				}
				if (delegate != null) {
					if (delegate instanceof Element) {
						result = (Element) delegate;
					} else if (delegate instanceof Document) {
						if (isProxiedSource) {
							DVertex vertex = new DVertex(getConfiguration().getGraph(), (Document) delegate);
							result = vertex;
						} else if (((Document) delegate).hasItem("$Index") || ((Document) delegate).hasItem("$Collation")) {
							DVertex vertex = new DVertex(getConfiguration().getGraph(), (Document) delegate);
							result = vertex;
						} else {
							Object typeChk = ((Document) delegate).get(org.openntf.domino.graph2.DElement.TYPE_FIELD);
							String strChk = org.openntf.domino.utils.TypeUtils.toString(typeChk);
							if (org.openntf.domino.graph2.DVertex.GRAPH_TYPE_VALUE.equals(strChk)) {
								DVertex vertex = new DVertex(getConfiguration().getGraph(), (Document) delegate);
								result = vertex;
							} else if (org.openntf.domino.graph2.DEdge.GRAPH_TYPE_VALUE.equals(strChk)) {
								DEdge edge = new DEdge(getConfiguration().getGraph(), (Document) delegate);
								result = edge;
							} else {
								DVertex vertex = new DVertex(getConfiguration().getGraph(), (Document) delegate);
								result = vertex;
							}
						}
					} else if (delegate instanceof ViewEntry) {
						if (id instanceof ViewEntryCoordinate) {
							ViewEntryCoordinate vec = (ViewEntryCoordinate) id;
							String entryType = vec.getEntryType();
							if (entryType.startsWith("E")) {
								DEdge edge = new DEntryEdge(getConfiguration().getGraph(), (ViewEntry) delegate, (ViewEntryCoordinate) id, this);
								result = edge;
							} else if (entryType.startsWith("V")) {
								ViewEntry entry = (ViewEntry) delegate;
								if (entry.isCategory()) {
									Map<String, Object> delegateMap = new LinkedHashMap<String, Object>();
									delegateMap.put("value", entry.getCategoryValue());
									delegateMap.put("position", entry.getPosition());
									delegateMap.put("noteid", entry.getNoteID());
									DCategoryVertex vertex = new DCategoryVertex(getConfiguration().getGraph(), delegateMap,
											entry.getParentView());
									vertex.delegateKey_ = vec;
									result = vertex;
								} else {
									System.out.println("TEMP DEBUG ViewVertex entry is not a category");
								}
							}
						} else {
							System.out.println("TEMP DEBUG ViewEntry's id is not a ViewEntryCoordinate. It's a " + id.getClass().getName());
						}
					}
					getElementCache().put(result.getId(), result);
					getKeyMap().put(id, (NoteCoordinate) result.getId()); //TODO shouldn't force NoteCoordinate, but it covers all current use cases
				}
			}
			return result;
		}*/
// @Override
// public Element getElement(final Object id) throws IllegalStateException {
// return getElement(id, Element.class);
// }
// @Override
// public Edge getEdge(final Object id) {
// return (Edge) getElement(id, Edge.class);
// }
@Override
public void removeEdge(final Edge edge) {
    if (edge instanceof DEdge) {
        if (org.openntf.domino.ViewEntry.class.equals(((DEdge) edge).getDelegateType())) {
            throw new UnsupportedOperationException("ViewEntry edges cannot be removed.");
        }
    }
    startTransaction(edge);
    Vertex in = edge.getVertex(Direction.IN);
    if (in != null) {
        ((DVertex) in).removeEdge(edge);
    }
    Vertex out = edge.getVertex(Direction.OUT);
    if (out != null) {
        ((DVertex) out).removeEdge(edge);
    }
    removeCache(edge);
    ((DEdge) edge)._remove();
}
Also used : ViewVertex(org.openntf.domino.graph2.builtin.ViewVertex) CategoryVertex(org.openntf.domino.graph2.builtin.CategoryVertex) Vertex(com.tinkerpop.blueprints.Vertex) DbInfoVertex(org.openntf.domino.graph2.builtin.DbInfoVertex)

Example 2 with ViewVertex

use of org.openntf.domino.graph2.builtin.ViewVertex in project org.openntf.domino by OpenNTF.

the class JsonSearchAdapter method getJsonProperty.

@SuppressWarnings("unlikely-arg-type")
@Override
public Object getJsonProperty(final String paramKey) {
    Object result = null;
    Object frame = getFrame();
    if (frame != null) {
        CaseInsensitiveString key = new CaseInsensitiveString(paramKey);
        if (key.equals("@id")) {
            if (frame instanceof VertexFrame) {
                result = ((VertexFrame) frame).asVertex().getId().toString();
            } else if (frame instanceof EdgeFrame) {
                result = ((EdgeFrame) frame).asEdge().getId().toString();
            }
        } else if (key.equals("@proxyid")) {
            if (frame instanceof VertexFrame) {
                Vertex v = ((VertexFrame) frame).asVertex();
                if (v instanceof DProxyVertex) {
                    result = ((DProxyVertex) v).getProperty(DProxyVertex.PROXY_ITEM, String.class);
                }
            }
        } else if (key.equals("@debug")) {
            Map<String, String> debugMap = new LinkedHashMap<String, String>();
            debugMap.put("frameIdentity", String.valueOf(System.identityHashCode(this)));
            if (frame instanceof VertexFrame) {
                Vertex v = ((VertexFrame) frame).asVertex();
                debugMap.put("vertexIdentity", String.valueOf(System.identityHashCode(v)));
            } else if (frame instanceof EdgeFrame) {
                Edge e = ((EdgeFrame) frame).asEdge();
                debugMap.put("edgeIdentity", String.valueOf(System.identityHashCode(e)));
            }
            result = debugMap;
        } else if (key.equals("@type")) {
            if (frame instanceof VertexFrame) {
                result = type_;
            } else if (frame instanceof EdgeFrame) {
                result = type_;
            }
        } else if (key.equals("@in") && frame instanceof EdgeFrame) {
            if (getInProperties() == null) {
                // why not just make a frame adapter with the vertex?
                // because that's another I/O operation. We already have the
                // information needed to
                DEdge dedge = (DEdge) ((EdgeFrame) frame).asEdge();
                Map<String, String> minProps = new LinkedHashMap<String, String>();
                minProps.put("@id", dedge.getVertexId(Direction.IN).toString());
                Class<?> inType = graph_.getTypeRegistry().getInType(type_);
                if (inType == null) {
                    minProps.put("@type", "Vertex");
                } else {
                    minProps.put("@type", inType.getName());
                }
                result = minProps;
            } else {
                ParamMap inMap = new ParamMap();
                inMap.put(Parameters.PROPS, CaseInsensitiveString.toStrings(getInProperties()));
                if (getIncludeEdges()) {
                    inMap.put(Parameters.EDGES, EMPTY_STRINGS);
                }
                if (getIncludeCounts()) {
                    inMap.put(Parameters.COUNTS, EMPTY_STRINGS);
                }
                Method inMethod = graph_.getTypeRegistry().getIn(type_);
                if (inMethod != null) {
                    try {
                        Object raw = inMethod.invoke(frame, (Object[]) null);
                        if (raw instanceof Term) {
                            result = new JsonSearchAdapter(graph_, (Term) raw, inMap, isCollectionRoute_);
                        } else if (raw instanceof Value) {
                            result = new JsonSearchAdapter(graph_, (Value) raw, inMap, isCollectionRoute_);
                        } else if (raw instanceof RichTextReference) {
                            result = new JsonSearchAdapter(graph_, (RichTextReference) raw, inMap, isCollectionRoute_);
                        } else if (raw instanceof VertexFrame) {
                            result = new JsonFrameAdapter(graph_, (VertexFrame) raw, inMap, isCollectionRoute_);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        } else if (key.equals("@out") && frame instanceof EdgeFrame) {
            if (getOutProperties() == null) {
                // why not just make a frame adapter with the vertex?
                // because that's another I/O operation. We already have the
                // information needed to
                DEdge dedge = (DEdge) ((EdgeFrame) frame).asEdge();
                Map<String, String> minProps = new LinkedHashMap<String, String>();
                minProps.put("@id", dedge.getVertexId(Direction.OUT).toString());
                Class<?> outType = graph_.getTypeRegistry().getOutType(type_);
                if (outType == null) {
                    minProps.put("@type", "Vertex");
                } else {
                    minProps.put("@type", outType.getName());
                }
                result = minProps;
            } else {
                ParamMap outMap = new ParamMap();
                outMap.put(Parameters.PROPS, CaseInsensitiveString.toStrings(getOutProperties()));
                if (getIncludeEdges()) {
                    outMap.put(Parameters.EDGES, EMPTY_STRINGS);
                }
                if (getIncludeCounts()) {
                    outMap.put(Parameters.COUNTS, EMPTY_STRINGS);
                }
                Method outMethod = graph_.getTypeRegistry().getOut(type_);
                if (outMethod != null) {
                    try {
                        Object raw = outMethod.invoke(frame, (Object[]) null);
                        if (raw instanceof Term) {
                            result = new JsonSearchAdapter(graph_, (Term) raw, outMap, isCollectionRoute_);
                        } else if (raw instanceof Value) {
                            result = new JsonSearchAdapter(graph_, (Value) raw, outMap, isCollectionRoute_);
                        } else if (raw instanceof RichTextReference) {
                            result = new JsonSearchAdapter(graph_, (RichTextReference) raw, outMap, isCollectionRoute_);
                        } else if (raw instanceof VertexFrame) {
                            result = new JsonFrameAdapter(graph_, (VertexFrame) raw, outMap, isCollectionRoute_);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        } else if (key.equals("@edges")) {
            Map<String, Integer> edgeCounts = new LinkedHashMap<String, Integer>();
            Set<CaseInsensitiveString> counterKeys = getCounters().keySet();
            for (CaseInsensitiveString label : counterKeys) {
                Method crystal = getCounters().get(label);
                if (crystal != null) {
                    try {
                        Object raw = crystal.invoke(getFrame(), (Object[]) null);
                        if (raw instanceof Integer) {
                            edgeCounts.put(label.toString(), (Integer) raw);
                        } else {
                        }
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                } else {
                }
            }
            result = edgeCounts;
        } else if (key.equals("@actions")) {
            List<CaseInsensitiveString> actionList = new ArrayList<CaseInsensitiveString>();
            Set<CaseInsensitiveString> actionNames = getActions().keySet();
            for (CaseInsensitiveString name : actionNames) {
                actionList.add(name);
            }
            result = actionList;
        } else if (key.startsWith("@counts")) {
            String label = key.toString().substring("@counts".length());
            Method crystal = getCounters().get(new CaseInsensitiveString(label));
            if (crystal != null) {
                try {
                    Object raw = crystal.invoke(getFrame(), (Object[]) null);
                    if (raw instanceof Integer) {
                        result = raw;
                    } else {
                    }
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            } else {
            }
        } else if (key.equals("@columninfo")) {
            if (frame instanceof ViewVertex) {
                Map<String, String> columnInfo = new LinkedHashMap<String, String>();
                if (frame instanceof ViewVertex) {
                    View view = ((ViewVertex) frame).asView();
                    for (ViewColumn column : view.getColumns()) {
                        String progName = column.getItemName();
                        String title = column.getTitle();
                        columnInfo.put(progName, title);
                    }
                } else {
                    System.err.println("Frame is not a ViewVertex. It is " + DGraphUtils.findInterface(frame));
                }
                return columnInfo;
            }
        } else if (key.equals("@viewinfo")) {
            if (frame instanceof DbInfoVertex) {
                List viewInfo = ((DbInfoVertex) frame).getViewInfo();
                return viewInfo;
            }
        } else if (key.startsWith("#") && frame instanceof VertexFrame) {
            CharSequence label = key.subSequence(1, key.length());
            Method crystal = getIncidences().get(label);
            if (crystal != null) {
                try {
                    result = crystal.invoke(frame, (Object[]) null);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
                if (result != null) {
                    if (!(result instanceof Iterable)) {
                        if (result instanceof EdgeFrame) {
                            Vertex v = ((VertexFrame) frame).asVertex();
                            List<Edge> edges = new org.openntf.domino.graph2.impl.DEdgeList((DVertex) v);
                            edges.add(((EdgeFrame) result).asEdge());
                            result = new FramedEdgeList(getGraph(), ((VertexFrame) frame).asVertex(), edges, crystal.getReturnType());
                        }
                    }
                    if (getIncludeVertices()) {
                        if (result instanceof DEdgeList) {
                            result = ((DEdgeList) result).toVertexList();
                        } else if (result instanceof FramedEdgeList) {
                            result = ((FramedEdgeList<?>) result).toVertexList();
                        } else {
                            System.err.println("TEMP DEBUG: Expected a DEdgeList but got a " + result.getClass().getName());
                        }
                    }
                    if (getFilterKeys() != null && !isCollectionRoute_) {
                        List<CharSequence> filterKeys = getFilterKeys();
                        List<CharSequence> filterValues = getFilterValues();
                        Map<CharSequence, Set<CharSequence>> filterMap = new HashMap<CharSequence, Set<CharSequence>>();
                        for (int i = 0; i < filterKeys.size(); i++) {
                            String curkey = filterKeys.get(i).toString();
                            String curvalue = filterValues.get(i).toString();
                            if (Value.REPLICA_KEY.equalsIgnoreCase(curkey)) {
                                Set<CharSequence> replicas = filterMap.get(Value.REPLICA_KEY);
                                if (replicas == null) {
                                    replicas = new HashSet<CharSequence>();
                                    filterMap.put(Value.REPLICA_KEY, replicas);
                                }
                                replicas.add(new CaseInsensitiveString(curvalue));
                            } else if (Value.FORM_KEY.equalsIgnoreCase(curkey)) {
                                Set<CharSequence> forms = filterMap.get(Value.FORM_KEY);
                                if (forms == null) {
                                    forms = new HashSet<CharSequence>();
                                    filterMap.put(Value.FORM_KEY, forms);
                                }
                                forms.add(new CaseInsensitiveString(curvalue));
                            } else if (Value.FIELD_KEY.equalsIgnoreCase(curkey)) {
                                Set<CharSequence> forms = filterMap.get(Value.FIELD_KEY);
                                if (forms == null) {
                                    forms = new HashSet<CharSequence>();
                                    filterMap.put(Value.FIELD_KEY, forms);
                                }
                                forms.add(new CaseInsensitiveString(curvalue));
                            }
                        }
                        if (result instanceof FramedVertexList) {
                            // this should always be the case
                            FramedVertexList fvl = (FramedVertexList) result;
                            List<Vertex> vertList = new ArrayList<Vertex>();
                            FramedVertexList filterList = new FramedVertexList<VertexFrame>(fvl.getGraph(), fvl.getSourceVertex(), vertList, null);
                            for (Object raw : fvl) {
                                if (raw instanceof Value) {
                                    Map hits = ((Value) raw).getHits(filterMap);
                                    if (hits.size() > 0) {
                                        filterList.add((Value) raw);
                                    }
                                } else if (raw instanceof RichTextReference) {
                                    if (((RichTextReference) raw).isFilterMatch(filterMap)) {
                                        filterList.add((RichTextReference) raw);
                                    }
                                }
                            }
                            result = filterList;
                        }
                    }
                    if (getStartsValues() != null) {
                        if (result instanceof DEdgeEntryList) {
                            ((DEdgeEntryList) result).initEntryList(getStartsValues());
                        } else if (result instanceof FramedEdgeList) {
                            ((FramedEdgeList) result).applyFilter("lookup", getStartsValues());
                        }
                    }
                    if (getFilterValues() != null && getFilterKeys() == null) {
                        if (result instanceof DEdgeEntryList) {
                            ((DEdgeEntryList) result).filterEntryList(getFilterValues());
                        } else if (result instanceof FramedEdgeList) {
                            ((FramedEdgeList) result).applyFilter("filter", getFilterValues());
                        }
                    }
                    if (getOrderBys() != null) {
                        if (result instanceof FramedEdgeList) {
                            result = ((FramedEdgeList<?>) result).sortBy(getOrderBys(), getDescending());
                        } else if (result instanceof FramedVertexList) {
                            result = ((FramedVertexList<?>) result).sortBy(getOrderBys(), getDescending());
                        }
                    }
                    if (getStart() >= 0) {
                        if (getCount() > 0) {
                            int end = getStart() + getCount();
                            if (result instanceof FramedEdgeList) {
                                // System.out.println("TEMP DEBUG Sublisting
                                // a FramedEdgeList...");
                                int size = ((FramedEdgeList<?>) result).size();
                                result = ((FramedEdgeList<?>) result).subList(getStart(), (end > size ? size : end));
                            } else if (result instanceof FramedVertexList) {
                                int size = ((FramedVertexList<?>) result).size();
                                result = ((FramedVertexList<?>) result).subList(getStart(), (end > size ? size : end));
                            } else if (result instanceof DEdgeEntryList) {
                                // System.out.println("TEMP DEBUG Sublisting
                                // a DEdgeEntryList...");
                                int size = ((DEdgeEntryList) result).size();
                                result = ((DEdgeEntryList) result).subList(getStart() + 1, (end > size ? size : end));
                            }
                        } else {
                            if (result instanceof FramedEdgeList) {
                                result = ((FramedEdgeList<?>) result).subList(getStart(), ((FramedEdgeList<?>) result).size());
                            } else if (result instanceof FramedVertexList) {
                                result = ((FramedVertexList<?>) result).subList(getStart(), ((FramedVertexList<?>) result).size());
                            } else if (result instanceof DEdgeEntryList) {
                                // System.out.println("TEMP DEBUG Sublisting
                                // a DEdgeEntryList...");
                                result = ((DEdgeEntryList) result).subList(getStart() + 1, ((DEdgeEntryList) result).size());
                            }
                        }
                    }
                    if (result instanceof FramedVertexList) {
                        ParamMap listMap = new ParamMap();
                        if (getIncludeEdges()) {
                            listMap.put(Parameters.EDGES, EMPTY_STRINGS);
                        }
                        if (getIncludeCounts()) {
                            listMap.put(Parameters.COUNTS, EMPTY_STRINGS);
                        }
                        listMap.put(Parameters.PROPS, CaseInsensitiveString.toStrings(this.getProperties()));
                        listMap.put(Parameters.HIDEPROPS, CaseInsensitiveString.toStrings(this.getHideProperties()));
                        result = new JsonFrameListAdapter(getGraph(), (FramedVertexList<?>) result, listMap, isCollectionRoute_);
                    }
                }
            } else {
            // NTF actually, this is a perfectly normal outcome.
            }
        } else {
            Method crystal = getGetters().get(key);
            if (crystal != null) {
                try {
                    result = crystal.invoke(frame, (Object[]) null);
                } catch (UserAccessException uae) {
                    throw uae;
                } catch (Throwable t) {
                    if (frame instanceof EdgeFrame) {
                        result = ((EdgeFrame) frame).asEdge().getProperty(paramKey);
                    } else if (frame instanceof VertexFrame) {
                        result = ((VertexFrame) frame).asVertex().getProperty(paramKey);
                    } else {
                        System.err.println("Trying to get property " + paramKey + " from an object " + frame.getClass().getName());
                    }
                }
            } else {
                if (frame instanceof ViewVertex.Contains) {
                    result = ((EdgeFrame) frame).asEdge().getProperty(paramKey);
                } else if (frame instanceof VertexFrame) {
                    result = ((VertexFrame) frame).asVertex().getProperty(paramKey);
                } else if (frame instanceof EdgeFrame) {
                    result = ((EdgeFrame) frame).asEdge().getProperty(paramKey);
                } else {
                    System.err.println("No method found for key " + paramKey);
                }
            }
        }
    } else {
        System.err.println("Unable to get property " + paramKey + " on a null object");
    }
    return result;
}
Also used : ParamMap(org.openntf.domino.rest.service.Parameters.ParamMap) CaseInsensitiveString(org.openntf.domino.types.CaseInsensitiveString) LinkedHashMap(java.util.LinkedHashMap) RichTextReference(org.openntf.domino.graph2.builtin.search.RichTextReference) DbInfoVertex(org.openntf.domino.graph2.builtin.DbInfoVertex) FramedEdgeList(org.openntf.domino.graph2.annotations.FramedEdgeList) ArrayList(java.util.ArrayList) DEdgeEntryList(org.openntf.domino.graph2.impl.DEdgeEntryList) DEdgeList(org.openntf.domino.graph2.DEdgeList) FramedVertexList(org.openntf.domino.graph2.annotations.FramedVertexList) List(java.util.List) DEdgeList(org.openntf.domino.graph2.DEdgeList) HashSet(java.util.HashSet) DProxyVertex(org.openntf.domino.graph2.impl.DProxyVertex) DVertex(org.openntf.domino.graph2.impl.DVertex) Method(java.lang.reflect.Method) Term(org.openntf.domino.graph2.builtin.search.Term) FramedEdgeList(org.openntf.domino.graph2.annotations.FramedEdgeList) UserAccessException(org.openntf.domino.exceptions.UserAccessException) CaseInsensitiveString(org.openntf.domino.types.CaseInsensitiveString) Value(org.openntf.domino.graph2.builtin.search.Value) JsonJavaObject(com.ibm.commons.util.io.json.JsonJavaObject) JsonObject(com.ibm.commons.util.io.json.JsonObject) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ParamMap(org.openntf.domino.rest.service.Parameters.ParamMap) 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) HashSet(java.util.HashSet) Set(java.util.Set) JsonFrameAdapter(org.openntf.domino.rest.resources.frames.JsonFrameAdapter) ViewColumn(org.openntf.domino.ViewColumn) FramedVertexList(org.openntf.domino.graph2.annotations.FramedVertexList) JsonFrameListAdapter(org.openntf.domino.rest.resources.frames.JsonFrameListAdapter) ViewVertex(org.openntf.domino.graph2.builtin.ViewVertex) EdgeFrame(com.tinkerpop.frames.EdgeFrame) DEdgeFrame(org.openntf.domino.graph2.builtin.DEdgeFrame) View(org.openntf.domino.View) UserAccessException(org.openntf.domino.exceptions.UserAccessException) DVertexFrame(org.openntf.domino.graph2.builtin.DVertexFrame) VertexFrame(com.tinkerpop.frames.VertexFrame) DEdgeEntryList(org.openntf.domino.graph2.impl.DEdgeEntryList) DEdge(org.openntf.domino.graph2.impl.DEdge) Edge(com.tinkerpop.blueprints.Edge) DEdge(org.openntf.domino.graph2.impl.DEdge)

Example 3 with ViewVertex

use of org.openntf.domino.graph2.builtin.ViewVertex in project org.openntf.domino by OpenNTF.

the class JsonFrameAdapter method getJsonProperties.

@Override
public Iterator<String> getJsonProperties() {
    // System.out
    // .println("TEMP DEBUG getting Json properties list for a frame of type
    // "
    // + frame_.getClass().getName());
    List<String> result = new ArrayList<String>();
    // if (getActionsParam() != null) {
    // for (CharSequence cis : getActionsParam()) {
    // result.add("%" + cis.toString());
    // }
    // }
    result.add("@id");
    result.add("@type");
    result.add("@editable");
    if (getIncludeDebug()) {
        result.add("@debug");
    }
    if (getFrame() instanceof VertexFrame) {
        result.add("@versions");
    }
    Collection<CharSequence> props = getProperties();
    if (props == null) {
        // NoteCoordinate nc = (NoteCoordinate)
        // ((VertexFrame)frame_).asVertex().getId();
        props = new ArrayList<CharSequence>();
        props.addAll(getGetters().keySet());
        Class<?> klazz = frame_.getClass();
        boolean incl = isInclusive(klazz);
        // }
        if (props == null || props.size() < 5 || incl) {
            if (frame_ instanceof DVertexFrame) {
                try {
                    Set<String> raw = ((DVertexFrame) frame_).asVertex().getPropertyKeys();
                    // Set<CharSequence> raw = ((DVertexFrame) frame_).asMap().keySet();
                    // System.out.println("TEMP DEBUG raw vertex has " + raw.size() + " properties");
                    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());
    // System.out.println("Adding " + 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");
        result.add("@label");
    }
    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());
        }
    }
    // System.out.println("TEMP DEBUG getting properties for a " + DGraphUtils.getInterfaceList(frame) + " -- " + Strings.getString(result, ","));
    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 4 with ViewVertex

use of org.openntf.domino.graph2.builtin.ViewVertex in project org.openntf.domino by OpenNTF.

the class JsonFrameAdapter method getJsonProperty.

@SuppressWarnings("unlikely-arg-type")
@Override
public Object getJsonProperty(final String paramKey) {
    Object result = null;
    Object frame = getFrame();
    if (frame != null) {
        CaseInsensitiveString key = new CaseInsensitiveString(paramKey);
        if (key.equals("@id")) {
            if (frame instanceof VertexFrame) {
                Vertex v = ((VertexFrame) frame).asVertex();
                // if (v instanceof DProxyVertex) {
                // result = ((DProxyVertex)v).getProxyDelegate().getId().toString();
                // } else {
                result = String.valueOf(v.getId());
            // }
            } else if (frame instanceof EdgeFrame) {
                result = String.valueOf(((EdgeFrame) frame).asEdge().getId());
            }
        } else if (key.equals("@editable")) {
            if (frame instanceof VertexFrame) {
                result = ((DVertex) ((VertexFrame) frame).asVertex()).isEditable();
            } else if (frame instanceof EdgeFrame) {
                result = ((DEdge) ((EdgeFrame) frame).asEdge()).isEditable();
            }
        } else if (key.equals("@proxyid")) {
            // System.out.println("TEMP DEBUG @proxyid requested");
            if (frame instanceof VertexFrame) {
                Vertex v = ((VertexFrame) frame).asVertex();
                if (v instanceof DProxyVertex) {
                    result = ((DProxyVertex) v).getProperty(DProxyVertex.PROXY_ITEM, String.class);
                }
            }
        } else if (key.equals("@versions")) {
            if (frame instanceof VertexFrame) {
                try {
                    Vertex v = ((VertexFrame) frame).asVertex();
                    Object id = v.getId();
                    Session sess = Factory.getSession(SessionType.CURRENT);
                    Document doc = sess.getDocumentByMetaversalID(id.toString());
                    if (doc != null) {
                        Database db = doc.getAncestorDatabase();
                        List<DocumentBackupContributor> contributors = Factory.findApplicationServices(DocumentBackupContributor.class);
                        if (contributors != null) {
                            for (DocumentBackupContributor contributor : contributors) {
                                Optional<List<Date>> dates = contributor.getRevisionDates(db, doc.getUniversalID());
                                if (dates.isPresent()) {
                                    result = dates.get();
                                    break;
                                }
                            }
                        }
                    }
                } catch (Throwable t) {
                    t.printStackTrace();
                }
            }
            if (result == null) {
                List<String> resultList = new ArrayList<String>();
                resultList.add("N/A");
                result = resultList;
            }
        } else if (key.equals("@debug")) {
            Map<String, String> debugMap = new LinkedHashMap<String, String>();
            debugMap.put("frameIdentity", String.valueOf(System.identityHashCode(this)));
            if (frame instanceof VertexFrame) {
                Vertex v = ((VertexFrame) frame).asVertex();
                debugMap.put("vertexIdentity", String.valueOf(System.identityHashCode(v)));
            } else if (frame instanceof EdgeFrame) {
                Edge e = ((EdgeFrame) frame).asEdge();
                debugMap.put("vertexIdentity", String.valueOf(System.identityHashCode(e)));
            }
            result = debugMap;
        } else if (key.equals("@type")) {
            if (frame instanceof VertexFrame) {
                result = type_;
            } else if (frame instanceof EdgeFrame) {
                result = type_;
            }
        } else if (key.equals("@label")) {
            if (frame instanceof EdgeFrame) {
                Edge e = ((EdgeFrame) frame).asEdge();
                result = e.getLabel();
            }
        } else if (key.equals("@in") && frame instanceof EdgeFrame) {
            if (getInProperties() == null) {
                // why not just make a frame adapter with the vertex?
                // because that's another I/O operation. We already have the
                // information needed to
                DEdge dedge = (DEdge) ((EdgeFrame) frame).asEdge();
                Map<String, String> minProps = new LinkedHashMap<String, String>();
                minProps.put("@id", dedge.getVertexId(Direction.IN).toString());
                Class<?> inType = graph_.getTypeRegistry().getInType(type_);
                if (inType == null) {
                    minProps.put("@type", "Vertex");
                } else {
                    minProps.put("@type", inType.getName());
                }
                result = minProps;
            } else {
                ParamMap inMap = new ParamMap();
                inMap.put(Parameters.PROPS, CaseInsensitiveString.toStrings(getInProperties()));
                if (getIncludeEdges()) {
                    inMap.put(Parameters.EDGES, EMPTY_STRINGS);
                }
                if (getIncludeCounts()) {
                    inMap.put(Parameters.COUNTS, EMPTY_STRINGS);
                }
                Method inMethod = graph_.getTypeRegistry().getIn(type_);
                if (inMethod != null) {
                    try {
                        Object raw = inMethod.invoke(frame, (Object[]) null);
                        if (raw instanceof VertexFrame) {
                            VertexFrame inFrame = (VertexFrame) raw;
                            result = new JsonFrameAdapter(graph_, inFrame, inMap, isCollectionRoute_);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                } else {
                    System.out.println("In method not found for type: " + type_.getName());
                }
            }
        } else if (key.equals("@out") && frame instanceof EdgeFrame) {
            if (getOutProperties() == null) {
                // why not just make a frame adapter with the vertex?
                // because that's another I/O operation. We already have the
                // information needed to
                DEdge dedge = (DEdge) ((EdgeFrame) frame).asEdge();
                Map<String, String> minProps = new LinkedHashMap<String, String>();
                minProps.put("@id", dedge.getVertexId(Direction.OUT).toString());
                Class<?> outType = graph_.getTypeRegistry().getOutType(type_);
                if (outType == null) {
                    minProps.put("@type", "Vertex");
                } else {
                    minProps.put("@type", outType.getName());
                }
                result = minProps;
            } else {
                ParamMap outMap = new ParamMap();
                outMap.put(Parameters.PROPS, CaseInsensitiveString.toStrings(getOutProperties()));
                if (getIncludeEdges()) {
                    outMap.put(Parameters.EDGES, EMPTY_STRINGS);
                }
                if (getIncludeCounts()) {
                    outMap.put(Parameters.COUNTS, EMPTY_STRINGS);
                }
                Method outMethod = graph_.getTypeRegistry().getOut(type_);
                if (outMethod != null) {
                    try {
                        Object raw = outMethod.invoke(frame, (Object[]) null);
                        if (raw instanceof VertexFrame) {
                            VertexFrame outFrame = (VertexFrame) raw;
                            result = new JsonFrameAdapter(graph_, outFrame, outMap, isCollectionRoute_);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        } else if (key.equals("@edges")) {
            Map<String, Integer> edgeCounts = new LinkedHashMap<String, Integer>();
            Set<CaseInsensitiveString> counterKeys = getCounters().keySet();
            // " edge types");
            for (CaseInsensitiveString label : counterKeys) {
                Method crystal = getCounters().get(label);
                if (crystal != null) {
                    // key);
                    try {
                        Object raw = crystal.invoke(getFrame(), (Object[]) null);
                        if (raw instanceof Integer) {
                            edgeCounts.put(label.toString(), (Integer) raw);
                        } else {
                        }
                    } catch (IllegalArgumentException iae) {
                        System.out.println("TEMP DEBUG Attempting to invoke " + crystal.getDeclaringClass().getName() + "." + crystal.getName() + " on an " + getFrame().getClass().getName() + " (" + DGraphUtils.getInterfaceList(getFrame()) + ")");
                        throw new RuntimeException(iae);
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                } else {
                // System.out.println("TEMP DEBUG No method found for
                // key "
                // + key);
                }
            }
            result = edgeCounts;
        } else if (key.equals("@actions")) {
            List<CaseInsensitiveString> actionList = new ArrayList<CaseInsensitiveString>();
            Set<CaseInsensitiveString> actionNames = getActions().keySet();
            for (CaseInsensitiveString name : actionNames) {
                actionList.add(name);
            }
            result = actionList;
        } else if (key.startsWith("@counts")) {
            String label = key.toString().substring("@counts".length());
            Method crystal = getCounters().get(new CaseInsensitiveString(label));
            if (crystal != null) {
                try {
                    Object raw = crystal.invoke(getFrame(), (Object[]) null);
                    if (raw instanceof Integer) {
                        result = raw;
                    } else {
                    // System.out.println("TEMP DEBUG Invokation of a
                    // counter resulted in a "
                    // + (raw == null ? "null" :
                    // raw.getClass().getName()));
                    }
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            } else {
            // System.out.println("TEMP DEBUG No method found for key "
            // + label);
            }
        } else if (key.equals("@columninfo")) {
            if (frame instanceof ViewVertex) {
                Map<String, String> columnInfo = new LinkedHashMap<String, String>();
                if (frame instanceof ViewVertex) {
                    View view = ((ViewVertex) frame).asView();
                    if (view != null) {
                        try {
                            for (ViewColumn column : view.getColumns()) {
                                String progName = column.getItemName();
                                String title = column.getTitle();
                                columnInfo.put(progName, title);
                            }
                        } catch (Throwable t) {
                            columnInfo.put("@error", "Unable to access column information");
                        }
                    }
                } else {
                    System.err.println("Frame is not a ViewVertex. It is " + DGraphUtils.findInterface(frame));
                }
                return columnInfo;
            }
        } else if (key.equals("@viewinfo")) {
            if (frame instanceof DbInfoVertex) {
                List viewInfo = ((DbInfoVertex) frame).getViewInfo();
                return viewInfo;
            }
        } else if (key.startsWith("#") && frame instanceof VertexFrame) {
            CharSequence label = key.subSequence(1, key.length());
            Method crystal = getIncidences().get(label);
            if (crystal != null) {
                try {
                    result = crystal.invoke(frame, (Object[]) null);
                } catch (IllegalArgumentException iae) {
                    throw new RuntimeException(iae.getMessage() + " where the expect call is " + crystal.getDeclaringClass().getName() + "." + crystal.getName() + " but the object is " + DGraphUtils.getInterfaceList(frame));
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
                if (result != null) {
                    if (!(result instanceof Iterable)) {
                        if (result instanceof EdgeFrame) {
                            Vertex v = ((VertexFrame) frame).asVertex();
                            List<Edge> edges = new org.openntf.domino.graph2.impl.DEdgeList((DVertex) v);
                            edges.add(((EdgeFrame) result).asEdge());
                            result = new FramedEdgeList(getGraph(), ((VertexFrame) frame).asVertex(), edges, crystal.getReturnType());
                        }
                    }
                    if (getIncludeVertices()) {
                        // EdgeList into VertexList");
                        if (result instanceof DEdgeList) {
                            result = ((DEdgeList) result).toVertexList();
                        } else if (result instanceof FramedEdgeList) {
                            result = ((FramedEdgeList<?>) result).toVertexList();
                        } else {
                            System.err.println("TEMP DEBUG: Expected a DEdgeList but got a " + result.getClass().getName());
                        }
                    }
                    if (getFilterKeys() != null && !isCollectionRoute_) {
                        if (result instanceof DEdgeList) {
                            // System.out.println("TEMP DEBUG: Applying
                            // a filter to a DEdgeList");
                            List<CharSequence> filterKeys = getFilterKeys();
                            List<CharSequence> filterValues = getFilterValues();
                            for (int i = 0; i < filterKeys.size(); i++) {
                                result = ((DEdgeList) result).applyFilter(filterKeys.get(i).toString(), filterValues.get(i).toString());
                            }
                        } else if (result instanceof DVertexList) {
                            // System.out.println("TEMP DEBUG: Applying
                            // a filter to a DVertexList");
                            List<CharSequence> filterKeys = getFilterKeys();
                            List<CharSequence> filterValues = getFilterValues();
                            for (int i = 0; i < filterKeys.size(); i++) {
                                result = ((DVertexList) result).applyFilter(filterKeys.get(i).toString(), filterValues.get(i).toString());
                            }
                        } else if (result instanceof FramedEdgeList) {
                            // System.out.println("TEMP DEBUG: Applying
                            // a filter to a FramedEdgeList");
                            List<CharSequence> filterKeys = getFilterKeys();
                            List<CharSequence> filterValues = getFilterValues();
                            for (int i = 0; i < filterKeys.size(); i++) {
                                result = ((FramedEdgeList<?>) result).applyFilter(filterKeys.get(i).toString(), filterValues.get(i).toString());
                            }
                        } else if (result instanceof FramedVertexList) {
                            List<CharSequence> filterKeys = getFilterKeys();
                            List<CharSequence> filterValues = getFilterValues();
                            for (int i = 0; i < filterKeys.size(); i++) {
                                String curkey = filterKeys.get(i).toString();
                                String curvalue = filterValues.get(i).toString();
                                // System.out.println("TEMP DEBUG:
                                // Applying a filter to a
                                // FramedVertexList - "
                                // + curkey + ":" + curvalue);
                                result = ((FramedVertexList<?>) result).applyFilter(curkey, curvalue);
                            }
                        }
                    }
                    if (getStartsValues() != null) {
                        // + result.getClass().getName());
                        if (result instanceof DEdgeEntryList) {
                            ((DEdgeEntryList) result).initEntryList(getStartsValues());
                        } else if (result instanceof FramedEdgeList) {
                            ((FramedEdgeList) result).applyFilter("lookup", getStartsValues());
                        }
                    }
                    if (getFilterValues() != null && getFilterKeys() == null) {
                        if (result instanceof DEdgeEntryList) {
                            // System.out.println("TEMP DEBUG filtering a
                            // DEdgeEntryList");
                            ((DEdgeEntryList) result).filterEntryList(getFilterValues());
                        } else if (result instanceof FramedEdgeList) {
                            ((FramedEdgeList) result).applyFilter("filter", getFilterValues());
                        }
                    }
                    if (getOrderBys() != null) {
                        if (result instanceof FramedEdgeList) {
                            // System.out.println("Ordering an edge
                            // list");
                            result = ((FramedEdgeList<?>) result).sortBy(getOrderBys(), getDescending());
                        } else if (result instanceof FramedVertexList) {
                            // System.out.println("Ordering a vertex
                            // list");
                            result = ((FramedVertexList<?>) result).sortBy(getOrderBys(), getDescending());
                        }
                    }
                    if (getStart() >= 0) {
                        // + " for a " + result.getClass().getName());
                        if (getCount() > 0) {
                            int end = getStart() + getCount();
                            if (result instanceof FramedEdgeList) {
                                // System.out.println("TEMP DEBUG Sublisting
                                // a FramedEdgeList...");
                                int size = ((FramedEdgeList<?>) result).size();
                                result = ((FramedEdgeList<?>) result).subList(getStart(), (end > size ? size : end));
                            } else if (result instanceof FramedVertexList) {
                                int size = ((FramedVertexList<?>) result).size();
                                result = ((FramedVertexList<?>) result).subList(getStart(), (end > size ? size : end));
                            } else if (result instanceof DEdgeEntryList) {
                                // System.out.println("TEMP DEBUG Sublisting
                                // a DEdgeEntryList...");
                                int size = ((DEdgeEntryList) result).size();
                                result = ((DEdgeEntryList) result).subList(getStart(), (end > size ? size : end));
                            }
                        } else {
                            if (result instanceof FramedEdgeList) {
                                result = ((FramedEdgeList<?>) result).subList(getStart(), ((FramedEdgeList<?>) result).size());
                            } else if (result instanceof FramedVertexList) {
                                result = ((FramedVertexList<?>) result).subList(getStart(), ((FramedVertexList<?>) result).size());
                            } else if (result instanceof DEdgeEntryList) {
                                // System.out.println("TEMP DEBUG Sublisting
                                // a DEdgeEntryList...");
                                result = ((DEdgeEntryList) result).subList(getStart() + 1, ((DEdgeEntryList) result).size());
                            }
                        }
                    }
                    // }
                    if (result instanceof FramedVertexList) {
                        ParamMap listMap = new ParamMap();
                        if (getIncludeEdges()) {
                            listMap.put(Parameters.EDGES, EMPTY_STRINGS);
                        }
                        if (getIncludeCounts()) {
                            listMap.put(Parameters.COUNTS, EMPTY_STRINGS);
                        }
                        listMap.put(Parameters.PROPS, CaseInsensitiveString.toStrings(this.getProperties()));
                        listMap.put(Parameters.HIDEPROPS, CaseInsensitiveString.toStrings(this.getHideProperties()));
                        result = new JsonFrameListAdapter(getGraph(), (FramedVertexList<?>) result, listMap, isCollectionRoute_);
                    }
                }
            } else {
            // NTF actually, this is a perfectly normal outcome.
            // System.err.println("No edge method found for label " +
            // label + " in a VertexFrame of type "
            // + DGraphUtils.findInterface(frame) + " with id "
            // + ((VertexFrame) frame).asVertex().getId());
            }
        } else {
            // System.out.println("TEMP DEBUG finding property " + key);
            Method crystal = getGetters().get(key);
            if (crystal != null) {
                try {
                    result = crystal.invoke(frame, (Object[]) null);
                } catch (UserAccessException uae) {
                    throw uae;
                } catch (Throwable t) {
                    if (frame instanceof EdgeFrame) {
                        result = ((EdgeFrame) frame).asEdge().getProperty(paramKey);
                    } else if (frame instanceof VertexFrame) {
                        result = ((VertexFrame) frame).asVertex().getProperty(paramKey);
                    } else {
                        System.err.println("Trying to get property " + paramKey + " from an object " + frame.getClass().getName());
                    }
                }
            } else {
                if (frame instanceof ViewVertex.Contains) {
                    result = ((EdgeFrame) frame).asEdge().getProperty(paramKey);
                } else if (frame instanceof VertexFrame) {
                    result = ((VertexFrame) frame).asVertex().getProperty(paramKey);
                } else if (frame instanceof EdgeFrame) {
                    result = ((EdgeFrame) frame).asEdge().getProperty(paramKey);
                } else {
                    System.err.println("No method found for key " + paramKey);
                }
            }
        }
    } else {
        System.err.println("Unable to get property " + paramKey + " on a null object");
    }
    return result;
}
Also used : ParamMap(org.openntf.domino.rest.service.Parameters.ParamMap) ArrayList(java.util.ArrayList) CaseInsensitiveString(org.openntf.domino.types.CaseInsensitiveString) Document(org.openntf.domino.Document) LinkedHashMap(java.util.LinkedHashMap) DbInfoVertex(org.openntf.domino.graph2.builtin.DbInfoVertex) Database(org.openntf.domino.Database) FramedEdgeList(org.openntf.domino.graph2.annotations.FramedEdgeList) ArrayList(java.util.ArrayList) DEdgeEntryList(org.openntf.domino.graph2.impl.DEdgeEntryList) DEdgeList(org.openntf.domino.graph2.DEdgeList) DVertexList(org.openntf.domino.graph2.impl.DVertexList) FramedVertexList(org.openntf.domino.graph2.annotations.FramedVertexList) List(java.util.List) DEdgeList(org.openntf.domino.graph2.DEdgeList) DProxyVertex(org.openntf.domino.graph2.impl.DProxyVertex) Optional(java.util.Optional) DVertex(org.openntf.domino.graph2.impl.DVertex) Method(java.lang.reflect.Method) FramedEdgeList(org.openntf.domino.graph2.annotations.FramedEdgeList) UserAccessException(org.openntf.domino.exceptions.UserAccessException) CaseInsensitiveString(org.openntf.domino.types.CaseInsensitiveString) JsonJavaObject(com.ibm.commons.util.io.json.JsonJavaObject) JsonObject(com.ibm.commons.util.io.json.JsonObject) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ParamMap(org.openntf.domino.rest.service.Parameters.ParamMap) 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) Set(java.util.Set) ViewColumn(org.openntf.domino.ViewColumn) FramedVertexList(org.openntf.domino.graph2.annotations.FramedVertexList) ViewVertex(org.openntf.domino.graph2.builtin.ViewVertex) DVertexList(org.openntf.domino.graph2.impl.DVertexList) EdgeFrame(com.tinkerpop.frames.EdgeFrame) DEdgeFrame(org.openntf.domino.graph2.builtin.DEdgeFrame) View(org.openntf.domino.View) Date(java.util.Date) UserAccessException(org.openntf.domino.exceptions.UserAccessException) DVertexFrame(org.openntf.domino.graph2.builtin.DVertexFrame) VertexFrame(com.tinkerpop.frames.VertexFrame) DEdgeEntryList(org.openntf.domino.graph2.impl.DEdgeEntryList) DocumentBackupContributor(org.openntf.domino.contributor.DocumentBackupContributor) DEdge(org.openntf.domino.graph2.impl.DEdge) Edge(com.tinkerpop.blueprints.Edge) DEdge(org.openntf.domino.graph2.impl.DEdge) Session(org.openntf.domino.Session)

Example 5 with ViewVertex

use of org.openntf.domino.graph2.builtin.ViewVertex 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)

Aggregations

Vertex (com.tinkerpop.blueprints.Vertex)5 DbInfoVertex (org.openntf.domino.graph2.builtin.DbInfoVertex)5 ViewVertex (org.openntf.domino.graph2.builtin.ViewVertex)5 JsonJavaObject (com.ibm.commons.util.io.json.JsonJavaObject)4 JsonObject (com.ibm.commons.util.io.json.JsonObject)4 Edge (com.tinkerpop.blueprints.Edge)4 EdgeFrame (com.tinkerpop.frames.EdgeFrame)4 VertexFrame (com.tinkerpop.frames.VertexFrame)4 ArrayList (java.util.ArrayList)4 DEdgeFrame (org.openntf.domino.graph2.builtin.DEdgeFrame)4 DVertexFrame (org.openntf.domino.graph2.builtin.DVertexFrame)4 DEdge (org.openntf.domino.graph2.impl.DEdge)4 DProxyVertex (org.openntf.domino.graph2.impl.DProxyVertex)4 DVertex (org.openntf.domino.graph2.impl.DVertex)4 CaseInsensitiveString (org.openntf.domino.types.CaseInsensitiveString)4 Method (java.lang.reflect.Method)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2