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();
}
}
}
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);
}
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);
}
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;
}
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;
}
Aggregations