Search in sources :

Example 1 with WindowCommand

use of org.olat.core.gui.control.pushpoll.WindowCommand in project openolat by klemens.

the class AjaxController method pushJSON.

private void pushJSON(WindowCommand wc, Writer writer) throws IOException {
    Command c = wc.getCommand();
    String winId = wc.getWindowBackOffice().getWindow().getDispatchID();
    try {
        writer.append("{\"w\":\"").append(winId).append("\",\"cmd\":").append(Integer.toString(c.getCommand())).append(",\"cda\":");
        c.getSubJSON().write(writer);
        c.getSubJSON().toString(2);
        writer.append("}");
    } catch (JSONException e) {
        throw new AssertException("json exception:", e);
    }
}
Also used : AssertException(org.olat.core.logging.AssertException) WindowCommand(org.olat.core.gui.control.pushpoll.WindowCommand) JSONException(org.json.JSONException)

Example 2 with WindowCommand

use of org.olat.core.gui.control.pushpoll.WindowCommand in project openolat by klemens.

the class AjaxController method getAndClearJSON.

/**
 * @param moreCmds a List of WindowCommand objects
 * @return
 */
private JSONObject getAndClearJSON(boolean clear) {
    JSONObject root = new JSONObject();
    try {
        if (Settings.isDebuging()) {
            long time = System.currentTimeMillis();
            root.put("time", time);
        }
        synchronized (windowcommands) {
            // o_clusterOK by:fj
            // handle all windowcommands now, create json
            int sum = windowcommands.size();
            // number of commands: 0..n
            root.put("cmdcnt", sum);
            if (sum > 0) {
                JSONArray ja = new JSONArray();
                root.put("cmds", ja);
                // treat commands waiting for the poll
                for (int i = 0; i < sum; i++) {
                    WindowCommand wc = windowcommands.get(i);
                    JSONObject jo = createJSON(wc);
                    ja.put(jo);
                }
                if (clear) {
                    windowcommands.clear();
                }
            }
        }
        return root;
    } catch (JSONException e) {
        throw new AssertException("wrong data put into json object", e);
    }
}
Also used : AssertException(org.olat.core.logging.AssertException) JSONObject(org.json.JSONObject) WindowCommand(org.olat.core.gui.control.pushpoll.WindowCommand) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) HistoryPoint(org.olat.core.id.context.HistoryPoint)

Example 3 with WindowCommand

use of org.olat.core.gui.control.pushpoll.WindowCommand in project OpenOLAT by OpenOLAT.

the class AjaxController method createJSON.

private JSONObject createJSON(WindowCommand wc) {
    Command c = wc.getCommand();
    WindowBackOffice wbo = wc.getWindowBackOffice();
    String winId = wbo.getWindow().getDispatchID();
    JSONObject jo = new JSONObject();
    try {
        jo.put("cmd", c.getCommand());
        jo.put("w", winId);
        jo.put("cda", c.getSubJSON());
        return jo;
    } catch (JSONException e) {
        throw new AssertException("json exception:", e);
    }
}
Also used : AssertException(org.olat.core.logging.AssertException) JSONObject(org.json.JSONObject) WindowCommand(org.olat.core.gui.control.pushpoll.WindowCommand) WindowBackOffice(org.olat.core.gui.control.WindowBackOffice) JSONException(org.json.JSONException)

Example 4 with WindowCommand

use of org.olat.core.gui.control.pushpoll.WindowCommand in project OpenOLAT by OpenOLAT.

the class AjaxController method pushJSON.

private void pushJSON(WindowCommand wc, Writer writer) throws IOException {
    Command c = wc.getCommand();
    String winId = wc.getWindowBackOffice().getWindow().getDispatchID();
    try {
        writer.append("{\"w\":\"").append(winId).append("\",\"cmd\":").append(Integer.toString(c.getCommand())).append(",\"cda\":");
        c.getSubJSON().write(writer);
        c.getSubJSON().toString(2);
        writer.append("}");
    } catch (JSONException e) {
        throw new AssertException("json exception:", e);
    }
}
Also used : AssertException(org.olat.core.logging.AssertException) WindowCommand(org.olat.core.gui.control.pushpoll.WindowCommand) JSONException(org.json.JSONException)

Example 5 with WindowCommand

use of org.olat.core.gui.control.pushpoll.WindowCommand in project OpenOLAT by OpenOLAT.

the class AjaxController method pushJSONAndClear.

public void pushJSONAndClear(UserRequest ureq, Writer writer) throws IOException {
    synchronized (windowcommands) {
        // o_clusterOK by:fj
        // handle all windowcommands now, create json
        writer.append("{\"cmds\":[");
        int sum = windowcommands.size();
        if (sum > 0) {
            // treat commands waiting for the poll
            for (int i = 0; i < sum; i++) {
                if (i != 0)
                    writer.append(",");
                WindowCommand wc = windowcommands.get(i);
                pushJSON(wc, writer);
            }
        }
        writer.append("],\"cmdcnt\":").append(Integer.toString(sum));
        appendBusinessPathInfos(ureq, writer);
        writer.append("}");
        windowcommands.clear();
    }
}
Also used : WindowCommand(org.olat.core.gui.control.pushpoll.WindowCommand) HistoryPoint(org.olat.core.id.context.HistoryPoint)

Aggregations

WindowCommand (org.olat.core.gui.control.pushpoll.WindowCommand)8 JSONException (org.json.JSONException)6 AssertException (org.olat.core.logging.AssertException)6 JSONObject (org.json.JSONObject)4 HistoryPoint (org.olat.core.id.context.HistoryPoint)4 JSONArray (org.json.JSONArray)2 WindowBackOffice (org.olat.core.gui.control.WindowBackOffice)2