Search in sources :

Example 21 with NoteCoordinate

use of org.openntf.domino.big.NoteCoordinate in project org.openntf.domino by OpenNTF.

the class FramedResource method processJsonUpdate.

@SuppressWarnings("unlikely-arg-type")
private void processJsonUpdate(final JsonJavaObject jsonItems, final DFramedTransactionalGraph graph, final JsonGraphWriter writer, final ParamMap pm, final boolean isPut) throws JsonException, IOException {
    Map<CaseInsensitiveString, Object> cisMap = new HashMap<CaseInsensitiveString, Object>();
    for (String jsonKey : jsonItems.keySet()) {
        CaseInsensitiveString cis = new CaseInsensitiveString(jsonKey);
        cisMap.put(cis, jsonItems.get(jsonKey));
    }
    List<String> ids = pm.get(Parameters.ID);
    boolean commit = true;
    if (ids.size() == 0) {
    // TODO no id
    } else {
        JsonFrameAdapter adapter = null;
        for (String id : ids) {
            NoteCoordinate nc = NoteCoordinate.Utils.getNoteCoordinate(id.trim());
            Object element = graph.getElement(nc, null);
            if (element instanceof EdgeFrame) {
                adapter = new JsonFrameAdapter(graph, (EdgeFrame) element, null, false);
            } else if (element instanceof VertexFrame) {
                adapter = new JsonFrameAdapter(graph, (VertexFrame) element, null, false);
            } else if (element == null) {
                throw new RuntimeException("Cannot force a metaversalid through REST API. Requested URL: " + ODAGraphService.getCurrentRequest().getRequestURI());
            } else {
                throw new RuntimeException(// TODO
                "TODO. Requested URL: " + ODAGraphService.getCurrentRequest().getRequestURI());
            }
            Iterator<String> frameProperties = adapter.getJsonProperties();
            CaseInsensitiveString actionName = null;
            CaseInsensitiveString preactionName = null;
            List<Object> actionArguments = null;
            for (CaseInsensitiveString cis : cisMap.keySet()) {
                if (cis.equals("%preaction")) {
                    preactionName = new CaseInsensitiveString(String.valueOf(cisMap.get(cis)));
                }
                if (cis.equals("%args")) {
                    Object result = cisMap.get(cis);
                    if (result instanceof List) {
                        actionArguments = (List) result;
                    }
                }
            }
            if (preactionName != null) {
                if (actionArguments != null) {
                    commit = adapter.runAction(preactionName, actionArguments);
                } else {
                    commit = adapter.runAction(preactionName);
                }
            }
            if (commit) {
                while (frameProperties.hasNext()) {
                    CaseInsensitiveString key = new CaseInsensitiveString(frameProperties.next());
                    if (!key.startsWith("@") && !key.startsWith("%")) {
                        Object value = cisMap.get(key);
                        if (value != null) {
                            adapter.putJsonProperty(key.toString(), value);
                            cisMap.remove(key);
                        } else if (isPut) {
                            adapter.putJsonProperty(key.toString(), value);
                        }
                    }
                }
                for (CaseInsensitiveString cis : cisMap.keySet()) {
                    if (cis.equals("%action")) {
                        actionName = new CaseInsensitiveString(String.valueOf(cisMap.get(cis)));
                    } else if (!cis.startsWith("@") && !cis.startsWith("%")) {
                        Object value = cisMap.get(cis);
                        if (value != null) {
                            adapter.putJsonProperty(cis.toString(), value);
                        }
                    }
                }
                adapter.updateReadOnlyProperties();
                if (actionName != null) {
                    if (actionArguments != null) {
                        commit = adapter.runAction(actionName, actionArguments);
                    } else {
                        commit = adapter.runAction(actionName);
                    }
                }
            }
            writer.outObject(element);
        }
        if (commit) {
            graph.commit();
        } else {
            graph.rollback();
        }
    }
}
Also used : NoteCoordinate(org.openntf.domino.big.NoteCoordinate) DEdgeFrame(org.openntf.domino.graph2.builtin.DEdgeFrame) EdgeFrame(com.tinkerpop.frames.EdgeFrame) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) CaseInsensitiveString(org.openntf.domino.types.CaseInsensitiveString) CaseInsensitiveString(org.openntf.domino.types.CaseInsensitiveString) DVertexFrame(org.openntf.domino.graph2.builtin.DVertexFrame) VertexFrame(com.tinkerpop.frames.VertexFrame) JsonJavaObject(com.ibm.commons.util.io.json.JsonJavaObject) List(java.util.List) ArrayList(java.util.ArrayList)

Example 22 with NoteCoordinate

use of org.openntf.domino.big.NoteCoordinate in project org.openntf.domino by OpenNTF.

the class DElementIterable method removeAll.

@Override
public boolean removeAll(final Collection<?> c) {
    List<NoteCoordinate> nclist = new ArrayList<NoteCoordinate>();
    for (Object raw : c) {
        if (raw instanceof Element) {
            Element e = (Element) raw;
            Object rawid = e.getId();
            if (rawid instanceof NoteCoordinate) {
                nclist.add((NoteCoordinate) rawid);
            }
        }
    }
    return index_.removeAll(nclist);
}
Also used : NoteCoordinate(org.openntf.domino.big.NoteCoordinate) Element(com.tinkerpop.blueprints.Element) ArrayList(java.util.ArrayList)

Example 23 with NoteCoordinate

use of org.openntf.domino.big.NoteCoordinate in project org.openntf.domino by OpenNTF.

the class DElementIterable method retainAll.

@Override
public boolean retainAll(final Collection<?> c) {
    List<NoteCoordinate> nclist = new ArrayList<NoteCoordinate>();
    for (Object raw : c) {
        if (raw instanceof Element) {
            Element e = (Element) raw;
            Object rawid = e.getId();
            if (rawid instanceof NoteCoordinate) {
                nclist.add((NoteCoordinate) rawid);
            }
        }
    }
    return index_.retainAll(nclist);
}
Also used : NoteCoordinate(org.openntf.domino.big.NoteCoordinate) Element(com.tinkerpop.blueprints.Element) ArrayList(java.util.ArrayList)

Example 24 with NoteCoordinate

use of org.openntf.domino.big.NoteCoordinate in project org.openntf.domino by OpenNTF.

the class DElementStore method getEdgeIds.

protected List<NoteCoordinate> getEdgeIds(final String formulaFilter) {
    FastTable<NoteCoordinate> result = new FastTable<NoteCoordinate>();
    Object raw = getStoreDelegate();
    if (raw instanceof Database) {
        Database db = (Database) raw;
        NoteCollection nc = db.createNoteCollection(false);
        nc.setSelectDocuments(true);
        nc.setSelectionFormula(formulaFilter);
        nc.buildCollection();
        for (String noteid : nc) {
            result.add(NoteCoordinate.Utils.getNoteCoordinate(nc, noteid));
        }
    } else {
        // TODO NTF implement alternative
        throw new IllegalStateException("Non-Domino implementations not yet available");
    }
    return result;
}
Also used : NoteCoordinate(org.openntf.domino.big.NoteCoordinate) NoteCollection(org.openntf.domino.NoteCollection) FastTable(javolution.util.FastTable) Database(org.openntf.domino.Database)

Example 25 with NoteCoordinate

use of org.openntf.domino.big.NoteCoordinate in project org.openntf.domino by OpenNTF.

the class DElementStore method getEdgeIds.

// @Override
// public Set<Edge> getCachedEdges() {
// FastSet<Edge> result = new FastSet<Edge>();
// for (Element elem : getElementCache().values()) {
// if (elem instanceof Edge) {
// result.add((Edge) elem);
// }
// }
// return result.unmodifiable();
// }
protected List<NoteCoordinate> getEdgeIds() {
    FastTable<NoteCoordinate> result = new FastTable<NoteCoordinate>();
    Object raw = getStoreDelegate();
    if (raw instanceof Database) {
        Database db = (Database) raw;
        NoteCollection nc = db.createNoteCollection(false);
        nc.setSelectDocuments(true);
        nc.setSelectionFormula(org.openntf.domino.graph2.DEdge.FORMULA_FILTER);
        nc.buildCollection();
        for (String noteid : nc) {
            result.add(NoteCoordinate.Utils.getNoteCoordinate(nc, noteid));
        }
    } else {
        // TODO NTF implement alternative
        throw new IllegalStateException("Non-Domino implementations not yet available");
    }
    return result;
}
Also used : NoteCoordinate(org.openntf.domino.big.NoteCoordinate) NoteCollection(org.openntf.domino.NoteCollection) FastTable(javolution.util.FastTable) Database(org.openntf.domino.Database)

Aggregations

NoteCoordinate (org.openntf.domino.big.NoteCoordinate)31 CaseInsensitiveString (org.openntf.domino.types.CaseInsensitiveString)9 Database (org.openntf.domino.Database)8 ArrayList (java.util.ArrayList)7 LinkedHashMap (java.util.LinkedHashMap)7 UserAccessException (org.openntf.domino.exceptions.UserAccessException)7 JsonJavaObject (com.ibm.commons.util.io.json.JsonJavaObject)6 Element (com.tinkerpop.blueprints.Element)6 VertexFrame (com.tinkerpop.frames.VertexFrame)6 HashMap (java.util.HashMap)6 NoteCollection (org.openntf.domino.NoteCollection)6 JsonException (com.ibm.commons.util.io.json.JsonException)5 Edge (com.tinkerpop.blueprints.Edge)5 EdgeFrame (com.tinkerpop.frames.EdgeFrame)5 IOException (java.io.IOException)5 WebApplicationException (javax.ws.rs.WebApplicationException)5 DVertexFrame (org.openntf.domino.graph2.builtin.DVertexFrame)5 List (java.util.List)4 FastTable (javolution.util.FastTable)4 Document (org.openntf.domino.Document)4