Example usage for com.google.gwt.json.client JSONValue isObject

List of usage examples for com.google.gwt.json.client JSONValue isObject

Introduction

In this page you can find the example usage for com.google.gwt.json.client JSONValue isObject.

Prototype

public JSONObject isObject() 

Source Link

Document

Returns non-null if this JSONValue is really a JSONObject.

Usage

From source file:eu.riscoss.client.JsonRiskDataList.java

License:Apache License

public JsonRiskDataList(JSONValue value) {
    this.json = value.isObject();
    if (json == null)
        json = new JSONObject();
    if (json.get("list") != null)
        array = json.get("list").isArray();
    if (array == null)
        array = new JSONArray();
}

From source file:eu.riscoss.client.JsonUtil.java

License:Apache License

public static JSONObject getObject(JSONValue val) {
    if (val == null)
        return NO_OBJECT;
    JSONObject object = val.isObject();
    if (object == null)
        return NO_OBJECT;
    return object;
}

From source file:eu.riscoss.client.JsonUtil.java

License:Apache License

public static JSONObject getObject(JSONValue val, String key) {
    if (val == null)
        return NO_OBJECT;
    JSONObject object = val.isObject();
    if (object == null)
        return NO_OBJECT;
    JSONValue v = object.get(key);/*from w  ww. j a  va2 s  .  co  m*/
    if (v == null)
        return NO_OBJECT;
    if (v.isObject() == null)
        return NO_OBJECT;
    return v.isObject();
}

From source file:eu.riscoss.client.JsonUtil.java

License:Apache License

public static String getValue(JSONValue val, String key, String def) {
    if (val == null)
        return def;
    JSONObject object = val.isObject();
    if (object == null)
        return def;
    JSONValue v = object.get(key);//from w  w w  .ja va  2 s  . c om
    if (v == null)
        return def;
    if (v.isString() == null)
        return def;
    return v.isString().stringValue();
}

From source file:eu.riscoss.client.rdcs.RDCsModule.java

License:Apache License

protected void loadRDCs(JSONValue response) {

    if (response.isObject() == null)
        return;//ww  w .  jav  a  2s.  c om

    int num = 0;
    for (String key : response.isObject().keySet()) {
        JSONObject o = response.isObject().get(key).isObject();
        JSONArray jpn = o.get("params").isArray();
        grid.resize(grid.getRowCount() + jpn.size() + 1, 3);
        //         grid.setWidget( num, 0, new CheckBox() );
        grid.setWidget(num, 1, new Label(key));

        for (int p = 0; p < jpn.size(); p++) {
            num++;
            JSONObject par = jpn.get(p).isObject();
            grid.setWidget(num, 0, new Label(par.get("name").isString().stringValue()));
            TextBox txt = new TextBox();
            if (par.get("def").isString() != null)
                txt.setText(par.get("def").isString().stringValue());
            grid.setWidget(num, 1, txt);
            if ((par.get("desc").isString() != null) & (par.get("ex").isString() != null)) {
                //               txt.setTitle( 
                //                  par.get( "desc" ).isString().stringValue() + " "
                //                  + "Example: " + par.get( "ex" ).isString().stringValue() );
                grid.setWidget(num, 2, new HTML(par.get("desc").isString().stringValue() + "<br>" + "Example: "
                        + par.get("ex").isString().stringValue()));
            }
        }
        num++;
    }

    RootPanel.get().add(grid);

}

From source file:eu.riscoss.client.report.ReportModule.java

License:Apache License

protected void startAnalysisWorkflow(EAnalysisOption opt, JSONObject values) {

    if (values == null)
        values = new JSONObject();

    RiscossJsonClient.runAnalysis(Window.Location.getParameter("target"), Window.Location.getParameter("rc"),
            "full", opt, values, new JsonCallback() {
                @Override//from   w w  w . j  a  va2  s. c om
                public void onFailure(Method method, Throwable exception) {
                    Window.alert(exception.getMessage());
                }

                @Override
                public void onSuccess(Method method, JSONValue response) {
                    //                  Window.alert( "" + response.isObject() );
                    if (response.isObject() == null)
                        return;

                    try {
                        String strResult = JsonUtil.getValue(response, "result",
                                EAnalysisResult.Failure.name());

                        EAnalysisResult result = EAnalysisResult.valueOf(strResult);
                        if (result == null)
                            result = EAnalysisResult.Failure;

                        switch (result) {
                        case DataMissing:
                            showInputForm(response);
                            break;
                        case Done:
                            showResults(response.isObject());
                            break;
                        case Failure:
                            Window.alert("Unexpected failure");
                            break;
                        default:
                            break;
                        }
                    } catch (Exception ex) {
                        Window.alert(ex.getMessage());
                    }
                }
            });

}

From source file:eu.riscoss.client.report.RiskAnalysisReport.java

License:Apache License

protected void getSessionsInformation() {
    RiscossJsonClient.listRiskAnalysisSessions(summary.getTarget(), summary.getRC(), new JsonCallback() {
        @Override//ww  w. ja  v a  2  s. c  om
        public void onFailure(Method method, Throwable exception) {
            Window.alert(exception.getMessage());
        }

        @Override
        public void onSuccess(Method method, JSONValue response) {
            response = response.isObject().get("list");
            count = response.isArray().size();
            CodecRASInfo codec = GWT.create(CodecRASInfo.class);
            if (response.isArray() != null) {
                for (int i = 0; i < response.isArray().size(); i++) {
                    JRASInfo info = codec.decode(response.isArray().get(i));
                    riskSessions.add(info.getId());
                    ++k;
                    RiscossJsonClient.getSessionSummary(info.getId(), new JsonCallback() {
                        int i = k;

                        @Override
                        public void onFailure(Method method, Throwable exception) {
                            Window.alert(exception.getMessage());
                        }

                        @Override
                        public void onSuccess(Method method, JSONValue response) {
                            JsonRiskAnalysis r = new JsonRiskAnalysis(response);
                            nextDate = r.getDate();
                            RiscossJsonClient.getSessionResults(r.getID(), new JsonCallback() {
                                String d = nextDate;

                                @Override
                                public void onFailure(Method method, Throwable exception) {
                                    Window.alert(exception.getMessage());
                                }

                                @Override
                                public void onSuccess(Method method, JSONValue response) {
                                    JSONArray results = response.isObject().get("results").isArray();
                                    ArrayList<Double> values = new ArrayList<>();
                                    for (int s = 0; s < results.isArray().size(); ++s) {
                                        JSONObject v = results.isArray().get(s).isObject();
                                        JsonRiskResult result = new JsonRiskResult(v);
                                        //                                 
                                        switch (result.getDataType()) {
                                        case EVIDENCE: {
                                            values.add(v.get("e").isObject().get("e").isNumber().doubleValue());
                                        }
                                        default:
                                            break;
                                        }
                                    }
                                    Date date = getDate(d);
                                    Info inf = new Info(date, values);
                                    dataList.add(inf);
                                    ++counting;
                                    if (counting == count) {
                                        sortByDate();
                                    }
                                }
                            });
                        }
                    });
                }
            }
        }
    });
}

From source file:eu.riscoss.client.RiscossWebApp.java

License:Apache License

void loadSitemap() {
    RiscossCall.fromCookies().admin().fx("sitemap").get(new JsonCallback() {
        @Override/*www .  j a v  a  2 s  . c o m*/
        public void onSuccess(Method method, JSONValue response) {
            CodecSiteMap codec = GWT.create(CodecSiteMap.class);
            sitemap = codec.decode(response);
            RiscossJsonClient.checkImportFiles(new JsonCallback() {
                @Override
                public void onFailure(Method method, Throwable exception) {
                    Window.alert(exception.getMessage());
                }

                @Override
                public void onSuccess(Method method, JSONValue response) {
                    if (response.isObject().get("confFile").isBoolean().booleanValue())
                        confFileLoaded = true;
                    showUI(sitemap);
                }
            });
        }

        @Override
        public void onFailure(Method method, Throwable exception) {
            Window.alert(exception.getMessage());
        }
    });
}

From source file:eu.riscoss.client.riskanalysis.JsonRiskAnalysis.java

License:Apache License

public JsonRiskAnalysis(JSONValue response) {
    this.json = response.isObject();
    if (json == null)
        json = new JSONObject();
}

From source file:eu.riscoss.client.riskanalysis.RASPanel.java

License:Apache License

protected void loadRASSummary(JsonRiskAnalysis ras) {
    sessionSummary = ras;/* w  ww . j  a  v a  2s.co  m*/
    if (panel.getWidget() != null) {
        panel.getWidget().removeFromParent();
    }
    riskConf = ras.getRC();
    entity = ras.getTarget();
    rasName = ras.getName();
    date = ras.getDate();
    RASID = ras.getID();
    currentDate = getDate(date);

    vPanel = new VerticalPanel();
    vPanel.setWidth("100%");
    title = new Label(rasName);
    title.setStyleName("h1");
    title.setWidth("100%");
    vPanel.add(title);
    Grid grid = new Grid(4, 4);
    grid.setCellSpacing(0);
    grid.setCellPadding(0);
    grid.setStyleName("table");

    Label nL = new Label("Name");
    nL.setStyleName("headTable");
    nL.setWidth("130px");
    grid.setWidget(0, 0, nL);
    /*Label rasName = new Label(ras.getName());
    rasName.setStyleName("contentTable");
    rasName.setHeight("100%");
    grid.setWidget(0, 1, rasName);*/
    rasNameBox = new TextBox();
    rasNameBox.setText(ras.getName());
    rasNameBox.setWidth("97%");
    grid.setWidget(0, 1, rasNameBox);

    Label rcL = new Label("Risk configuration");
    rcL.setStyleName("headTable");
    rcL.setWidth("130px");
    grid.setWidget(1, 0, rcL);
    Label rasrc = new Label(ras.getRC());
    rasrc.setStyleName("contentTable");
    grid.setWidget(1, 1, rasrc);

    Label eL = new Label("Target entity");
    eL.setStyleName("headTable");
    eL.setWidth("130px");
    grid.setWidget(2, 0, eL);
    Label rasEntity = new Label(ras.getTarget());
    rasEntity.setStyleName("contentTable");
    grid.setWidget(2, 1, rasEntity);

    {

        Button updateIndicators = new Button("Run data collectors");
        updateIndicators.setStyleName("deleteButton");
        updateIndicators.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                onUpdatedIndicatorsClicked();
            }
        });

    }
    {

        Label aL = new Label("Execution time");
        aL.setStyleName("headTable");
        aL.setWidth("130px");
        grid.setWidget(3, 0, aL);
        Label lastEx = new Label(ras.getDate());
        lastEx.setStyleName("contentTable");
        grid.setWidget(3, 1, lastEx);
    }

    generateButtons();

    vPanel.add(grid);

    VerticalPanel buttonPanel = new VerticalPanel();

    buttons = new HorizontalPanel();
    buttons2 = new HorizontalPanel();
    HorizontalPanel empty = new HorizontalPanel();
    HorizontalPanel empty2 = new HorizontalPanel();
    HorizontalPanel empty3 = new HorizontalPanel();

    buttons.addStyleName("margin-top");
    buttons2.setStyleName("margin-top");
    empty.setWidth("12px");
    empty2.setWidth("12px");
    empty3.setWidth("12px");

    //If RASPanel placed in multi-layer analysis
    if (risk != null) {
        buttons.add(risk.getBack());
        buttons.add(saveRas);
        buttons.add(remove);
        buttons.add(empty);
        buttons.add(mitigation);
        buttons.add(whatIf);
        buttons.add(empty3);
        buttons.add(generateReport);
        buttons2.add(update);
        buttons2.add(run);
        buttons2.add(empty2);
        buttons2.add(backupUpdate);
        buttons2.add(backupRun);
    }
    //If RASPanel placed in browse ras
    else if (rasModule != null) {
        buttons.add(browseBack);
        buttons.add(saveRas);
        buttons.add(browseDelete);
        buttons.add(empty);
        buttons.add(mitigation);
        buttons.add(whatIf);
        buttons.add(empty3);
        buttons.add(generateReport);
        buttons2.add(update);
        buttons2.add(run);
        buttons2.add(empty2);
        buttons2.add(backupUpdate);
        buttons2.add(backupRun);
    }
    //If RASPanel is in entity
    else if (eppg != null && entityB) {
        buttons.add(entityBack);
        buttons.add(saveRas);
        buttons.add(entityDelete);
        buttons.add(empty);
        buttons.add(mitigation);
        buttons.add(whatIf);
        buttons.add(empty3);
        buttons.add(generateReport);
        buttons2.add(update);
        buttons2.add(run);
        buttons2.add(empty2);
        buttons2.add(backupUpdate);
        buttons2.add(backupRun);
    }
    //If RASPanel is in layer
    else {
        buttons.add(layerBack);
        buttons.add(saveRas);
        buttons.add(layerDelete);
        buttons.add(empty);
        buttons.add(mitigation);
        buttons.add(whatIf);
        buttons.add(empty3);
        buttons.add(generateReport);
        buttons2.add(update);
        buttons2.add(run);
        buttons2.add(empty2);
        buttons2.add(backupUpdate);
        buttons2.add(backupRun);
    }
    buttonPanel.add(buttons);
    buttonPanel.add(buttons2);
    checkLastRiskSession();
    vPanel.add(buttonPanel);
    Label resultsTitle = new Label("Risk analysis results");
    resultsTitle.setStyleName("subtitle");
    vPanel.add(resultsTitle);

    vPanel.add(r);
    vPanel.add(mainChart);
    //      vPanel.add(report.asWidget());

    panel.setWidget(vPanel);

    RiscossJsonClient.getSessionResults(selectedRAS, new JsonCallback() {
        @Override
        public void onFailure(Method method, Throwable exception) {
            Window.alert("" + exception);
        }

        @Override
        public void onSuccess(Method method, JSONValue response) {
            try {

                vPanel.remove(mainChart);
                //                     vPanel.remove(report.asWidget());
                r.showResults(sessionSummary, response.isObject());

                if (r.getEvidence()) {
                    Label inputValues = new Label("Input values");
                    inputValues.setStyleName("subtitle");
                    vPanel.add(inputValues);
                    vPanel.add(inputTable);
                    inputDataInfo(response.isObject().get("input"));
                }
            } catch (Exception ex) {
                //               Window.alert( ex.getMessage() + "\n" + response );
            }
        }

    });
    checkIfEntityExists();

}