Search in sources :

Example 1 with DVertexFrame

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

the class SearchResource method getSearchObject.

@SuppressWarnings("unchecked")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getSearchObject(@Context final UriInfo uriInfo, @PathParam(Routes.NAMESPACE) final String namespace, @Context final Request request) throws JsonException, IOException {
    @SuppressWarnings("rawtypes") DFramedTransactionalGraph graph = this.getGraph(namespace);
    ParamMap pm = Parameters.toParamMap(uriInfo);
    StringWriter sw = new StringWriter();
    JsonGraphWriter writer = new JsonGraphWriter(sw, graph, pm, false, true, false);
    Date lastModified = new Date();
    boolean getLastMod = false;
    try {
        if (pm.get(Parameters.ID) != null) {
            List<String> ids = pm.get(Parameters.ID);
            if (ids.size() == 0) {
                writer.outNull();
            } else if (ids.size() == 1) {
                String id = ids.get(0).trim();
                NoteCoordinate nc = null;
                if (id.startsWith("E")) {
                    nc = ViewEntryCoordinate.Utils.getViewEntryCoordinate(id);
                } else if (id.startsWith("V")) {
                    nc = ViewEntryCoordinate.Utils.getViewEntryCoordinate(id);
                } else {
                    nc = NoteCoordinate.Utils.getNoteCoordinate(id);
                    getLastMod = true;
                }
                Object elem = graph.getElement(nc, null);
                if (elem == null) {
                    throw new WebApplicationException(ErrorHelper.createErrorResponse("Graph element not found for id " + id, Response.Status.NOT_FOUND));
                }
                if (elem instanceof DVertexFrame && getLastMod) {
                    lastModified = ((DVertexFrame) elem).getModified();
                }
                if (elem instanceof DEdgeFrame && getLastMod) {
                    lastModified = ((DEdgeFrame) elem).getModified();
                }
                writer.outObject(elem);
            } else {
                List<Value> valueResults = null;
                List<RichTextReference> rtRefResults = null;
                for (String id : ids) {
                    NoteCoordinate nc = NoteCoordinate.Utils.getNoteCoordinate(id.trim());
                    Object rawterm = graph.getElement(nc, null);
                    // System.out.println("TEMP DEBUG got a " + DGraphUtils.getInterfaceList(rawterm) + " from id " + nc);
                    Term term = null;
                    if (rawterm instanceof Term) {
                        term = (Term) rawterm;
                    } else {
                    // System.out.println("TEMP DEBUG didn't get a Term!");
                    }
                    List<Value> values = term.getValues();
                    // System.out.println("TEMP DEBUG found " + values.size()  + " values for term " + term.getValue() + " in a " + values.getClass().getName());
                    List<RichTextReference> rtRefs = term.getRichTextReferences();
                    // System.out.println("TEMP DEBUG found " + rtRefs.size()  + " rtrefs for term " + term.getValue() + " in a " + rtRefs.getClass().getName());
                    if (valueResults == null) {
                        valueResults = values;
                    } else {
                        valueResults.retainAll(values);
                    // System.out.println("TEMP DEBUG retained " + valueResults.size()  + " values for term " + term.getValue());
                    }
                    if (rtRefResults == null) {
                        rtRefResults = rtRefs;
                    } else {
                        rtRefResults.retainAll(rtRefs);
                    // System.out.println("TEMP DEBUG retained " + rtRefResults.size()  + " rtrefs for term " + term.getValue());
                    }
                }
                List<Object> combinedResults = new ArrayList<Object>();
                combinedResults.addAll(valueResults);
                combinedResults.addAll(rtRefResults);
                writer.outArrayLiteral(combinedResults);
            }
        } else if (pm.getKeys() != null) {
            Class<?> type = Term.class;
            DKeyResolver resolver = graph.getKeyResolver(type);
            List<CharSequence> keys = pm.getKeys();
            if (keys.size() == 0) {
                writer.outNull();
            } else {
                List<Value> valueResults = null;
                List<RichTextReference> rtRefResults = null;
                String key = URLDecoder.decode(String.valueOf(keys.get(0)), "UTF-8");
                String[] array = key.split(" ");
                for (String cur : array) {
                    NoteCoordinate nc = resolver.resolveKey(type, cur);
                    Object rawterm = graph.getElement(nc, null);
                    Term term = null;
                    if (rawterm instanceof Term) {
                        term = (Term) rawterm;
                    } else {
                    }
                    List<Value> values = term.getValues();
                    List<RichTextReference> rtRefs = term.getRichTextReferences();
                    if (valueResults == null) {
                        valueResults = values;
                    } else {
                        valueResults.retainAll(values);
                    }
                    if (rtRefResults == null) {
                        rtRefResults = rtRefs;
                    } else {
                        rtRefResults.retainAll(rtRefs);
                    }
                }
                List<Object> combinedResults = new ArrayList<Object>();
                combinedResults.addAll(valueResults);
                combinedResults.addAll(rtRefResults);
                writer.outArrayLiteral(combinedResults);
            }
            graph.rollback();
        } else {
            // MultivaluedMap<String, String> mvm = uriInfo.getQueryParameters();
            Map<String, Object> jsonMap = new LinkedHashMap<String, Object>();
            jsonMap.put("namespace", namespace);
            jsonMap.put("status", "active");
            writer.outObject(jsonMap);
        }
    } catch (UserAccessException uae) {
        return ErrorHelper.createErrorResponse("User " + Factory.getSession(SessionType.CURRENT).getEffectiveUserName() + " is not authorized to access this resource", Response.Status.UNAUTHORIZED);
    } catch (KeyNotFoundException knfe) {
        ResponseBuilder rb = Response.noContent();
        return rb.build();
    } catch (Exception e) {
        throw new WebApplicationException(ErrorHelper.createErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
    }
    String jsonEntity = sw.toString();
    ResponseBuilder berg = getBuilder(jsonEntity, lastModified, true, request);
    Response response = berg.build();
    return response;
}
Also used : ParamMap(org.openntf.domino.rest.service.Parameters.ParamMap) WebApplicationException(javax.ws.rs.WebApplicationException) JsonGraphWriter(org.openntf.domino.rest.json.JsonGraphWriter) DFramedTransactionalGraph(org.openntf.domino.graph2.impl.DFramedTransactionalGraph) StringWriter(java.io.StringWriter) ArrayList(java.util.ArrayList) List(java.util.List) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) NoteCoordinate(org.openntf.domino.big.NoteCoordinate) DKeyResolver(org.openntf.domino.graph2.DKeyResolver) Term(org.openntf.domino.graph2.builtin.search.Term) UserAccessException(org.openntf.domino.exceptions.UserAccessException) Date(java.util.Date) UserAccessException(org.openntf.domino.exceptions.UserAccessException) KeyNotFoundException(org.openntf.domino.graph2.impl.DEdgeEntryList.KeyNotFoundException) IOException(java.io.IOException) JsonException(com.ibm.commons.util.io.json.JsonException) WebApplicationException(javax.ws.rs.WebApplicationException) DVertexFrame(org.openntf.domino.graph2.builtin.DVertexFrame) Response(javax.ws.rs.core.Response) DEdgeFrame(org.openntf.domino.graph2.builtin.DEdgeFrame) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ParamMap(org.openntf.domino.rest.service.Parameters.ParamMap) KeyNotFoundException(org.openntf.domino.graph2.impl.DEdgeEntryList.KeyNotFoundException) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with DVertexFrame

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

the class SessionsByTrack method run.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void run() {
    HashMap<String, String> trackLkup = new HashMap<String, String>();
    trackLkup.put("Special", "Sp");
    trackLkup.put("Strategy/Deployment", "Str");
    trackLkup.put("Administration", "Adm");
    trackLkup.put("Development", "Dev");
    trackLkup.put("Business", "Bus");
    trackLkup.put("Commercial", "Comm");
    long testStartTime = System.nanoTime();
    marktime = System.nanoTime();
    try {
        timelog("Beginning Sessions By Track...");
        FramedGraph<DGraph> graph2 = new ConferenceGraph().getFramedGraph();
        Iterable<Sponsor> sponsors = graph2.getVertices("Level", Level.BRONZE, Sponsor.class);
        for (Sponsor s : sponsors) {
            System.out.println("Sponsor " + s.getName() + " - " + s.getUrl());
        }
        ConferenceGraph graph = new ConferenceGraph();
        for (Entry<String, String> track : trackLkup.entrySet()) {
            System.out.println("Outputting sessions ordered by ID for " + track.getKey());
            Track dev = graph.getFramedGraph().getVertex(track.getValue(), Track.class);
            System.out.println(dev.getDescription());
            Iterable<Presentation> presentations = dev.getIncludesSessions();
            Ordering<DVertexFrame> ord = Ordering.from(new DVertexFrameComparator("SessionID"));
            List<Presentation> presOrdered = ord.sortedCopy(presentations);
            for (Presentation pres : presOrdered) {
                Attendee att = pres.getPresentingAttendees().iterator().next();
                System.out.println(att.getFullname());
                System.out.println(pres.getSessionId() + ": " + pres.getTitle());
            }
        }
        for (Entry<String, String> track : trackLkup.entrySet()) {
            System.out.println("Outputting sessions ordered by Title for " + track.getKey());
            Track dev = graph.getFramedGraph().getVertex(track.getValue(), Track.class);
            Iterable<Presentation> presentations = dev.getIncludesSessions();
            Ordering<DVertexFrame> ord = Ordering.from(new DVertexFrameComparator("SessionTitle"));
            List<Presentation> presOrdered = ord.sortedCopy(presentations);
            for (Presentation pres : presOrdered) {
                System.out.println(pres.getSessionId() + ": " + pres.getTitle());
            }
        }
        System.out.println("OUTPUTTING SORTBY");
        FramedVertexList<Sponsor> sponsors2 = (FramedVertexList<Sponsor>) graph2.getVertices(null, null, Sponsor.class);
        List<CaseInsensitiveString> keys = new ArrayList<CaseInsensitiveString>();
        keys.add(new CaseInsensitiveString("Level"));
        keys.add(new CaseInsensitiveString("Name"));
        sponsors2.sortBy((List<CharSequence>) (List<?>) keys, true);
        for (Sponsor spon : sponsors2) {
            System.out.println(spon.getLevel().name() + " - " + spon.getName());
        }
        // Throws java.lang.ClassCastException: com.sun.proxy.$Proxy11 incompatible with com.tinkerpop.blueprints.Vertex
        // Yet to track down why
        List<Presentation> presentations = Lists.newArrayList(graph.getFramedGraph().getVertices(null, null, Presentation.class));
        // GremlinPipeline pipe = new GremlinPipeline(presentations).outE("PresentedBy").outV().dedup();
        GremlinPipeline pipe = new GremlinPipeline(presentations).outE("PresentedBy");
        List<DEdge> edges = pipe.toList();
        for (DEdge edge : edges) {
            System.out.println(edge.getVertex(Direction.OUT).getId());
        }
    } catch (Throwable t) {
        t.printStackTrace();
    }
    long testEndTime = System.nanoTime();
    System.out.println("Completed " + getClass().getSimpleName() + " run in " + ((testEndTime - testStartTime) / 1000000) + " ms");
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CaseInsensitiveString(org.openntf.domino.types.CaseInsensitiveString) DGraph(org.openntf.domino.graph2.impl.DGraph) FramedVertexList(org.openntf.domino.graph2.annotations.FramedVertexList) FramedVertexList(org.openntf.domino.graph2.annotations.FramedVertexList) ArrayList(java.util.ArrayList) List(java.util.List) GremlinPipeline(com.tinkerpop.gremlin.java.GremlinPipeline) DVertexFrameComparator(org.openntf.domino.graph2.builtin.DVertexFrameComparator) Sponsor(org.openntf.conference.graph.Sponsor) Presentation(org.openntf.conference.graph.Presentation) ConferenceGraph(org.openntf.conference.graph.ConferenceGraph) Attendee(org.openntf.conference.graph.Attendee) CaseInsensitiveString(org.openntf.domino.types.CaseInsensitiveString) DVertexFrame(org.openntf.domino.graph2.builtin.DVertexFrame) Track(org.openntf.conference.graph.Track) DEdge(org.openntf.domino.graph2.DEdge)

Example 3 with DVertexFrame

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

the class FramedResource method getFramedObject.

@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getFramedObject(@Context final UriInfo uriInfo, @PathParam(Routes.NAMESPACE) final String namespace, @Context final Request request) throws JsonException, IOException {
    DFramedTransactionalGraph graph = this.getGraph(namespace);
    ParamMap pm = Parameters.toParamMap(uriInfo);
    if (pm.getVersion() != null) {
        System.out.println("TEMP DEBUG Version number parameter detected " + pm.getVersion().get(0));
    }
    StringWriter sw = new StringWriter();
    JsonGraphWriter writer = new JsonGraphWriter(sw, graph, pm, false, true, false);
    Date lastModified = new Date();
    boolean getLastMod = false;
    try {
        if (pm.get(Parameters.ID) != null) {
            List<String> ids = pm.get(Parameters.ID);
            if (ids.size() == 0) {
                writer.outNull();
            } else if (ids.size() == 1) {
                String id = ids.get(0).trim();
                NoteCoordinate nc = null;
                if (id.startsWith("E")) {
                    nc = ViewEntryCoordinate.Utils.getViewEntryCoordinate(id);
                } else if (id.startsWith("V")) {
                    nc = ViewEntryCoordinate.Utils.getViewEntryCoordinate(id);
                } else {
                    nc = NoteCoordinate.Utils.getNoteCoordinate(id);
                    getLastMod = true;
                // System.out.println("TEMP DEBUG isIcon: " +
                // String.valueOf(nc.isIcon()));
                }
                if (nc == null) {
                // writer.outStringProperty("message", "NoteCoordinate
                // is null for id " + id);
                }
                if (graph == null) {
                // writer.outStringProperty("message", "Graph is null
                // for namespace " + namespace);
                }
                NoteCoordinate versionNC = null;
                if (pm.getVersion() != null) {
                    String versionString = pm.getVersion().get(0).toString();
                    System.out.println("Version parameter detected: " + versionString);
                    SimpleDateFormat sdf = TypeUtils.getDefaultDateFormat();
                    Date versionDate = sdf.parse(versionString);
                    try {
                        Session sess = Factory.getSession(SessionType.CURRENT);
                        Document doc = sess.getDocumentByMetaversalID(nc.toString());
                        Database db = doc.getAncestorDatabase();
                        List<DocumentBackupContributor> contributors = Factory.findApplicationServices(DocumentBackupContributor.class);
                        if (contributors != null) {
                            for (DocumentBackupContributor contributor : contributors) {
                                Optional<Document> versionDoc = contributor.createSidecarDocument(db, doc.getUniversalID(), versionDate);
                                if (versionDoc.isPresent()) {
                                    versionNC = versionDoc.get().getNoteCoordinate();
                                    break;
                                }
                            }
                        }
                    } catch (Throwable t) {
                        t.printStackTrace();
                    }
                }
                Object elem = null;
                if (versionNC != null) {
                    elem = graph.getElement(versionNC, null);
                // System.out.println("Got an element from graph with id " + ((Element)elem).getId());
                } else {
                    elem = graph.getElement(nc, null);
                }
                if (elem == null) {
                    // builder = Response.status(Status.NOT_FOUND);
                    // writer.outStringProperty("currentUsername",
                    // Factory.getSession(SessionType.CURRENT).getEffectiveUserName());
                    // throw new IllegalStateException();
                    Response response = ErrorHelper.createErrorResponse("Graph element not found for id " + String.valueOf(id), Response.Status.NOT_FOUND);
                    throw new WebApplicationException(response);
                }
                try {
                    if (elem instanceof DVertexFrame && getLastMod) {
                        lastModified = ((DVertexFrame) elem).getModified();
                    }
                    if (elem instanceof DEdgeFrame && getLastMod) {
                        lastModified = ((DEdgeFrame) elem).getModified();
                    }
                } catch (UserAccessException uae) {
                    return ErrorHelper.createErrorResponse("User " + Factory.getSession(SessionType.CURRENT).getEffectiveUserName() + " is not authorized to access this resource", Response.Status.UNAUTHORIZED);
                } catch (Exception e) {
                    throw new WebApplicationException(ErrorHelper.createErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
                }
                writer.outObject(elem);
            } else {
                List<Object> maps = new ArrayList<Object>();
                for (String id : ids) {
                    NoteCoordinate nc = NoteCoordinate.Utils.getNoteCoordinate(id.trim());
                    maps.add(graph.getElement(nc, null));
                }
                writer.outArrayLiteral(maps);
            }
        } else if (pm.getKeys() != null) {
            Class<?> type = null;
            if (pm.getTypes() != null) {
                List<CharSequence> types = pm.getTypes();
                String typename = types.get(0).toString();
                type = graph.getTypeRegistry().findClassByName(typename);
            }
            DKeyResolver resolver = graph.getKeyResolver(type);
            List<CharSequence> keys = pm.getKeys();
            if (keys.size() == 0) {
                writer.outNull();
            } else if (keys.size() == 1) {
                CharSequence id = keys.get(0);
                NoteCoordinate nc = resolver.resolveKey(type, URLDecoder.decode(String.valueOf(id), "UTF-8"));
                Object elem = null;
                if (nc != null) {
                    // is null for id " + id);
                    try {
                        elem = graph.getElement(nc);
                    } catch (Exception e) {
                    // NOOP NTF - this is possible and not an error condition. That's why we have .handleMissingKey.
                    }
                }
                if (elem == null) {
                    elem = resolver.handleMissingKey(type, id);
                    if (elem == null) {
                        Response response = ErrorHelper.createErrorResponse("Graph element not found for key " + id, Response.Status.NOT_FOUND);
                        throw new WebApplicationException(response);
                    }
                }
                if (elem instanceof Vertex) {
                    // System.out.println("TEMP DEBUG Framing a vertex of
                    // type "
                    // + elem.getClass().getName());
                    VertexFrame vf = (VertexFrame) graph.frame((Vertex) elem, type);
                    if (vf instanceof DVertexFrame) {
                        lastModified = ((DVertexFrame) vf).getModified();
                    }
                    writer.outObject(vf);
                } else if (elem instanceof Edge) {
                    EdgeFrame ef = (EdgeFrame) graph.frame((Edge) elem, type);
                    if (ef instanceof DEdgeFrame) {
                        lastModified = ((DEdgeFrame) ef).getModified();
                    }
                    writer.outObject(ef);
                }
            } else {
                List<Object> maps = new ArrayList<Object>();
                for (CharSequence id : keys) {
                    NoteCoordinate nc = resolver.resolveKey(type, id);
                    maps.add(graph.getElement(nc, null));
                }
                writer.outArrayLiteral(maps);
            }
            graph.rollback();
        } else {
            MultivaluedMap<String, String> mvm = uriInfo.getQueryParameters();
            for (@SuppressWarnings("unused") String key : mvm.keySet()) {
            // System.out.println("TEMP DEBUG: " + key + ": " +
            // mvm.getFirst(key));
            }
            Map<String, Object> jsonMap = new LinkedHashMap<String, Object>();
            jsonMap.put("namespace", namespace);
            jsonMap.put("status", "active");
            writer.outObject(jsonMap);
        }
    } catch (UserAccessException uae) {
        return ErrorHelper.createErrorResponse("User " + Factory.getSession(SessionType.CURRENT).getEffectiveUserName() + " is not authorized to access this resource", Response.Status.UNAUTHORIZED);
    } catch (KeyNotFoundException knfe) {
        ResponseBuilder rb = Response.noContent();
        return rb.build();
    } catch (Exception e) {
        throw new WebApplicationException(ErrorHelper.createErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
    }
    String jsonEntity = sw.toString();
    ResponseBuilder berg = getBuilder(jsonEntity, lastModified, true, request);
    Response response = berg.build();
    return response;
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) ParamMap(org.openntf.domino.rest.service.Parameters.ParamMap) WebApplicationException(javax.ws.rs.WebApplicationException) JsonGraphWriter(org.openntf.domino.rest.json.JsonGraphWriter) ArrayList(java.util.ArrayList) DFramedTransactionalGraph(org.openntf.domino.graph2.impl.DFramedTransactionalGraph) CaseInsensitiveString(org.openntf.domino.types.CaseInsensitiveString) Document(org.openntf.domino.Document) StringWriter(java.io.StringWriter) Database(org.openntf.domino.Database) List(java.util.List) ArrayList(java.util.ArrayList) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) NoteCoordinate(org.openntf.domino.big.NoteCoordinate) DEdgeFrame(org.openntf.domino.graph2.builtin.DEdgeFrame) EdgeFrame(com.tinkerpop.frames.EdgeFrame) Optional(java.util.Optional) DKeyResolver(org.openntf.domino.graph2.DKeyResolver) UserAccessException(org.openntf.domino.exceptions.UserAccessException) Date(java.util.Date) KeyNotFoundException(org.openntf.domino.graph2.impl.DEdgeEntryList.KeyNotFoundException) JsonException(com.ibm.commons.util.io.json.JsonException) WebApplicationException(javax.ws.rs.WebApplicationException) UserAccessException(org.openntf.domino.exceptions.UserAccessException) IOException(java.io.IOException) DVertexFrame(org.openntf.domino.graph2.builtin.DVertexFrame) Response(javax.ws.rs.core.Response) DVertexFrame(org.openntf.domino.graph2.builtin.DVertexFrame) VertexFrame(com.tinkerpop.frames.VertexFrame) DEdgeFrame(org.openntf.domino.graph2.builtin.DEdgeFrame) JsonJavaObject(com.ibm.commons.util.io.json.JsonJavaObject) DocumentBackupContributor(org.openntf.domino.contributor.DocumentBackupContributor) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) SimpleDateFormat(java.text.SimpleDateFormat) Edge(com.tinkerpop.blueprints.Edge) Map(java.util.Map) ParamMap(org.openntf.domino.rest.service.Parameters.ParamMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) KeyNotFoundException(org.openntf.domino.graph2.impl.DEdgeEntryList.KeyNotFoundException) Session(org.openntf.domino.Session) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with DVertexFrame

use of org.openntf.domino.graph2.builtin.DVertexFrame 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 5 with DVertexFrame

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

the class JsonFrameAdapter 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)

Aggregations

DVertexFrame (org.openntf.domino.graph2.builtin.DVertexFrame)7 DEdgeFrame (org.openntf.domino.graph2.builtin.DEdgeFrame)6 CaseInsensitiveString (org.openntf.domino.types.CaseInsensitiveString)6 JsonJavaObject (com.ibm.commons.util.io.json.JsonJavaObject)5 EdgeFrame (com.tinkerpop.frames.EdgeFrame)5 VertexFrame (com.tinkerpop.frames.VertexFrame)5 ArrayList (java.util.ArrayList)5 JsonObject (com.ibm.commons.util.io.json.JsonObject)4 UserAccessException (org.openntf.domino.exceptions.UserAccessException)4 Edge (com.tinkerpop.blueprints.Edge)3 Vertex (com.tinkerpop.blueprints.Vertex)3 List (java.util.List)3 Document (org.openntf.domino.Document)3 JsonException (com.ibm.commons.util.io.json.JsonException)2 Property (com.tinkerpop.frames.Property)2 IOException (java.io.IOException)2 StringWriter (java.io.StringWriter)2 Method (java.lang.reflect.Method)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2