Example usage for com.google.gwt.core.client JsonUtils unsafeEval

List of usage examples for com.google.gwt.core.client JsonUtils unsafeEval

Introduction

In this page you can find the example usage for com.google.gwt.core.client JsonUtils unsafeEval.

Prototype

public static native <T extends JavaScriptObject> T unsafeEval(String json) ;

Source Link

Document

Evaluates a JSON expression using eval() .

Usage

From source file:org.obiba.opal.web.gwt.app.client.magma.table.view.ViewWhereModalView.java

License:Open Source License

@Override
public void showError(String message, @Nullable FormField group) {
    if (Strings.isNullOrEmpty(message))
        return;/*from  w  w w . j  av  a2 s  . co  m*/

    dialog.closeAlerts();
    String msg = message;
    try {
        ClientErrorDto errorDto = JsonUtils.unsafeEval(message);
        msg = errorDto.getStatus();
    } catch (Exception ignored) {
    }

    if (group == null) {
        dialog.addAlert(msg, AlertType.ERROR);
    } else
        dialog.addAlert(msg, AlertType.ERROR, whereGroup);
}

From source file:org.obiba.opal.web.gwt.app.client.presenter.ResourceRequestPresenter.java

License:Open Source License

public void setErrorCodes(Integer... codes) {
    ResponseCodeCallback internalCallback = new ResponseCodeCallback() {

        @Override//  w  w w .j  a v a2s. c o  m
        public void onResponseCode(Request request, Response response) {
            getView().failed();

            if (response.getText() != null && response.getText().length() != 0) {
                try {
                    ClientErrorDto errorDto = JsonUtils.unsafeEval(response.getText());
                    getView().showErrorMessage(errorDto.getStatus());
                } catch (Exception e) {
                    // Should never get here!
                    getView().showErrorMessage("Internal Error");
                }
            } else {
                getView().showErrorMessage("Unknown Error");
            }

            if (callback != null) {
                callback.onResponseCode(request, response);
            }
        }
    };

    if (codes != null) {
        for (int code : codes) {
            requestBuilder.withCallback(code, internalCallback);
        }
    }
}

From source file:org.obiba.opal.web.gwt.app.client.support.ClientErrorDtos.java

License:Open Source License

/**
 * Given a ClientErrorDto JSON string, returns the ClientErrorDto's <code>status</code> field (i.e., the error message
 * key).//from  w ww.  j  a  v a 2  s  .  c  o m
 *
 * @param jsonClientErrorDto ClientErrorDto JSON string
 * @return status field of the ClientErrorDto
 */
public static String getStatus(String jsonClientErrorDto) {
    String errorStatus = null;
    if (jsonClientErrorDto != null && jsonClientErrorDto.length() != 0) {
        try {
            ClientErrorDto errorDto = JsonUtils.unsafeEval(jsonClientErrorDto);
            errorStatus = errorDto.getStatus();
        } catch (Exception ex) {
            // Should never get here!
            errorStatus = "InternalError";
        }
    } else {
        errorStatus = "UnknownError";
    }

    return errorStatus;
}

From source file:org.obiba.opal.web.gwt.app.client.support.ErrorResponseMessageBuilder.java

License:Open Source License

private ClientErrorDto getClientDtoError() {

    if (hasResponseText()) {
        try {//from w w w . j  av a 2  s  . com
            return JsonUtils.unsafeEval(httpResponse.getText());
        } catch (IllegalArgumentException e) {
            // a NULL will be return to get the default message
        }
    }

    return null;
}

From source file:org.obiba.opal.web.gwt.app.client.ui.VariableSuggestOracle.java

License:Open Source License

@Override
public void requestSuggestions(final Request request, final Callback callback) {
    String prefix = "";
    originalQuery = request.getQuery();//from  w w w  .j a  v a 2  s  .c om

    if (datasource != null) {
        prefix = "datasource:" + datasource + " ";
    }
    if (table != null) {
        prefix += "table:" + table + " ";
    }

    if (originalQuery == null || originalQuery.trim().isEmpty())
        return;

    final String query = prefix + getOriginalQuery();

    UriBuilder ub = UriBuilder.create().segment("datasources", "variables", "_search")//
            .query("query", query)//
            .query("field", "name", "field", "datasource", "field", "table", "field", "label", "field",
                    "label-en");

    // Get candidates from search words.
    ResourceRequestBuilderFactory.<QueryResultDto>newBuilder().forResource(ub.build()).get()
            .withCallback(com.google.gwt.http.client.Response.SC_BAD_REQUEST, ResponseCodeCallback.NO_OP)//
            .withCallback(new ResourceCallback<QueryResultDto>() {
                @Override
                public void onResource(com.google.gwt.http.client.Response response, QueryResultDto resource) {
                    if (response.getStatusCode() == com.google.gwt.http.client.Response.SC_OK) {
                        QueryResultDto resultDto = JsonUtils.unsafeEval(response.getText());

                        suggestions = new ArrayList<VariableSuggestion>();
                        if (resultDto.getHitsArray() != null && resultDto.getHitsArray().length() > 0) {
                            for (int i = 0; i < resultDto.getHitsArray().length(); i++) {
                                ItemFieldsDto itemDto = (ItemFieldsDto) resultDto.getHitsArray().get(i)
                                        .getExtension("Search.ItemFieldsDto.item");

                                JsArray<EntryDto> fields = itemDto.getFieldsArray();
                                Map<String, String> attributes = new HashMap<String, String>();
                                for (int j = 0; j < fields.length(); j++) {
                                    if ("label-en".equals(fields.get(j).getKey())
                                            || "label".equals(fields.get(j).getKey())
                                                    && !attributes.containsKey("label")) {
                                        attributes.put("label", fields.get(j).getValue());
                                    } else {
                                        attributes.put(fields.get(j).getKey(), fields.get(j).getValue());
                                    }
                                }

                                suggestions.add(convertToFormattedSuggestions(query, attributes));
                            }
                        }

                        // Convert candidates to suggestions.
                        Response r = new Response(suggestions);
                        callback.onSuggestionsReady(request, r);
                    }
                }

            })//
            .withCallback(com.google.gwt.http.client.Response.SC_SERVICE_UNAVAILABLE,
                    new ResponseCodeCallback() {
                        @Override
                        public void onResponseCode(com.google.gwt.http.client.Request request,
                                com.google.gwt.http.client.Response response) {
                            eventBus.fireEvent(
                                    NotificationEvent.newBuilder().warn("SearchServiceUnavailable").build());
                        }
                    })
            .send();

}