List of usage examples for com.google.gwt.json.client JSONValue toString
@Override public abstract String toString();
From source file:org.ow2.proactive_grid_cloud_portal.scheduler.client.json.SchedulerJSONUtils.java
License:Open Source License
/** * @param arr list of tags as a JSON array * @return the list of tags// ww w.j a va2 s . c o m */ public static List<String> getTagsFromJson(String result) throws JSONException { JSONValue val = parseJSON(result); JSONArray arr = val.isArray(); if (arr == null) { throw new JSONException("Expected JSON Array: " + val.toString()); } List<String> tags = new ArrayList<String>(arr.size()); for (int i = 0; i < arr.size(); i++) { tags.add(arr.get(i).isString().stringValue()); } return tags; }
From source file:org.ow2.proactive_grid_cloud_portal.scheduler.client.SchedulerController.java
License:Open Source License
/** * Starts the Timer that will periodically fetch the current scheduler state * from the server end and update the local view *///from w ww . jav a 2s.c o m private void startTimer() { if (this.schedulerTimerUpdate != null) throw new IllegalStateException("There's already a Timer"); this.schedulerTimerUpdate = new Timer() { @Override public void run() { if (!localSessionNum.equals(Cookies.getCookie(LOCAL_SESSION_COOKIE))) { teardown("Duplicate session detected!<br>" + "Another tab or window in this browser is accessing this page."); } SchedulerController.this.updateSchedulerStatus(); executionController.executionStateRevision(false); if (timerUpdate % userFetchTick == 0) { final long t1 = System.currentTimeMillis(); scheduler.getSchedulerUsers(LoginModel.getInstance().getSessionId(), new AsyncCallback<String>() { public void onSuccess(String result) { List<SchedulerUser> users; JSONValue val = parseJSON(result); JSONArray arr = val.isArray(); if (arr == null) { error("Expected JSON Array: " + val.toString()); } users = getUsersFromJson(arr); model.setSchedulerUsers(users); long t = (System.currentTimeMillis() - t1); LogModel.getInstance().logMessage("<span style='color:gray;'>Fetched " + users.size() + " users in " + t + " ms</span>"); } public void onFailure(Throwable caught) { if (!LoginModel.getInstance().isLoggedIn()) return; error("Failed to fetch scheduler users:<br>" + JSONUtils.getJsonErrorMessage(caught)); } }); } if (timerUpdate % statsFetchTick == 0) { final long t1 = System.currentTimeMillis(); scheduler.getStatistics(LoginModel.getInstance().getSessionId(), new AsyncCallback<String>() { public void onFailure(Throwable caught) { String msg = JSONUtils.getJsonErrorMessage(caught); if (!LoginModel.getInstance().isLoggedIn()) return; error("Failed to fetch scheduler stats:<br>" + msg); } public void onSuccess(String result) { HashMap<String, String> stats = new HashMap<String, String>(); JSONObject json = parseJSON(result).isObject(); if (json == null) error("Expected JSON Object: " + result); stats.put("JobSubmittingPeriod", json.get("JobSubmittingPeriod").isString().stringValue()); stats.put("FormattedJobSubmittingPeriod", json.get("FormattedJobSubmittingPeriod").isString().stringValue()); stats.put("MeanJobPendingTime", json.get("MeanJobPendingTime").isString().stringValue()); stats.put("ConnectedUsersCount", json.get("ConnectedUsersCount").isString().stringValue()); stats.put("FinishedTasksCount", json.get("FinishedTasksCount").isString().stringValue()); stats.put("RunningJobsCount", json.get("RunningJobsCount").isString().stringValue()); stats.put("RunningTasksCount", json.get("RunningTasksCount").isString().stringValue()); stats.put("FormattedMeanJobPendingTime", json.get("FormattedMeanJobPendingTime").isString().stringValue()); stats.put("MeanJobExecutionTime", json.get("MeanJobExecutionTime").isString().stringValue()); stats.put("PendingTasksCount", json.get("PendingTasksCount").isString().stringValue()); stats.put("FinishedJobsCount", json.get("FinishedJobsCount").isString().stringValue()); stats.put("TotalTasksCount", json.get("TotalTasksCount").isString().stringValue()); stats.put("FormattedMeanJobExecutionTime", json.get("FormattedMeanJobExecutionTime").isString().stringValue()); stats.put("TotalJobsCount", json.get("TotalJobsCount").isString().stringValue()); stats.put("PendingJobsCount", json.get("PendingJobsCount").isString().stringValue()); model.setSchedulerStatistics(stats); long t = (System.currentTimeMillis() - t1); LogModel.getInstance().logMessage("<span style='color:gray;'>Fetched sched stats: " + result.length() + " chars in " + t + " ms</span>"); } }); final long t2 = System.currentTimeMillis(); scheduler.getStatisticsOnMyAccount(LoginModel.getInstance().getSessionId(), new AsyncCallback<String>() { public void onFailure(Throwable caught) { if (!LoginModel.getInstance().isLoggedIn()) return; error("Failed to fetch account stats:<br>" + JSONUtils.getJsonErrorMessage(caught)); } public void onSuccess(String result) { HashMap<String, String> stats = new HashMap<String, String>(); JSONObject json = parseJSON(result).isObject(); if (json == null) error("Expected JSON Object: " + result); stats.put("TotalTaskCount", json.get("TotalTaskCount").isString().stringValue()); stats.put("TotalJobDuration", json.get("TotalJobDuration").isString().stringValue()); stats.put("TotalJobCount", json.get("TotalJobCount").isString().stringValue()); stats.put("TotalTaskDuration", json.get("TotalTaskDuration").isString().stringValue()); model.setAccountStatistics(stats); long t = (System.currentTimeMillis() - t2); LogModel.getInstance() .logMessage("<span style='color:gray;'>Fetched account stats: " + result.length() + " chars in " + t + " ms</span>"); } }); } timerUpdate++; } }; this.schedulerTimerUpdate.scheduleRepeating(SchedulerConfig.get().getClientRefreshTime()); }
From source file:org.ow2.proactive_grid_cloud_portal.scheduler.client.SchedulerController.java
License:Open Source License
public void getUsersWithJobs() { final long t1 = System.currentTimeMillis(); scheduler.getSchedulerUsersWithJobs(LoginModel.getInstance().getSessionId(), new AsyncCallback<String>() { public void onSuccess(String result) { List<SchedulerUser> users; JSONValue val = parseJSON(result); JSONArray arr = val.isArray(); if (arr == null) { error("Expected JSON Array: " + val.toString()); }/*ww w. j av a2 s.co m*/ users = getUsersFromJson(arr); model.setSchedulerUsersWithJobs(users); long t = (System.currentTimeMillis() - t1); LogModel.getInstance().logMessage("<span style='color:gray;'>Fetched " + users.size() + " users with jobs in " + t + " ms</span>"); } public void onFailure(Throwable caught) { if (!LoginModel.getInstance().isLoggedIn()) return; LogModel.getInstance().logMessage( "Failed to fetch scheduler users with jobs:<br>" + JSONUtils.getJsonErrorMessage(caught)); } }); }
From source file:org.pentaho.ui.database.event.DataHandler.java
License:Open Source License
private void gatherErrors(Response response) { if (response.getStatusCode() == Response.SC_OK && !response.getText().equalsIgnoreCase("null")) { //$NON-NLS-1$ String message = ""; //$NON-NLS-1$ final JSONValue jsonValue = JSONParser.parseStrict(response.getText()); final String keyItems = "items"; //$NON-NLS-1$ final String starter = "* "; //$NON-NLS-1$ if (jsonValue.isObject() != null && jsonValue.isObject().containsKey(keyItems)) { final JSONValue items = jsonValue.isObject().get(keyItems); if (items.isArray() != null) { for (int i = 0; i < items.isArray().size(); i++) { message = message.concat(starter).concat(items.isArray().get(i).isString().stringValue()) .concat(LINE_SEPARATOR); }/* ww w . java2s .c o m*/ } else if (items.isString() != null) { message = message.concat(starter).concat(items.isString().stringValue()).concat(LINE_SEPARATOR); } else { message = message.concat(starter).concat(items.toString()).concat(LINE_SEPARATOR); } } else { message = message.concat(starter).concat(jsonValue.toString()).concat(LINE_SEPARATOR); } showMessage(messages.getString("DataHandler.CHECK_PARAMS_TITLE"), message, false); //$NON-NLS-1$ } else { showMessage(messages.getString("DataHandler.ERROR_MESSAGE_TITLE"), response.getStatusText(), //$NON-NLS-1$ response.getStatusText().length() > 300); } }
From source file:org.sonatype.gwt.client.resource.Representation.java
License:Open Source License
public Representation(JSONValue json) { super(APPLICATION_JSON); this.body = json.toString(); }
From source file:org.spiffyui.client.rest.AuthUtil.java
License:Apache License
private void doLogin(final RESTObjectCallBack<String> callback, JSONValue val, String username, String authUrl) {/*from w w w .j a v a 2 s .c o m*/ RESTility.setTokenServerURL(authUrl); RESTility.setUsername(username); if (val == null) { callback.error(STRINGS.loginDataError("")); MessageUtil.showError(STRINGS.loginDataError("")); return; } JSONObject o = val.isObject(); if (o == null) { callback.error(STRINGS.loginDataError(val.toString())); MessageUtil.showError(STRINGS.loginDataError(val.toString())); return; } RESTility.setUserToken(o.get("Token").isString().stringValue()); RESTility.fireLoginSuccess(); callback.success(o.get("Token").isString().stringValue()); }
From source file:org.spiffyui.client.rest.RESTOptions.java
License:Apache License
/** * <p>//from ww w . ja v a2 s .c om * Set the data for this REST request. * </p> * * <p> * JSON data can only be passed for POST and PUT requests and will be ignored for all * other request methods. * </p> * * @param data the data to send to the server with this request * * @return the RESTOptions bean for method chaining */ public RESTOptions setData(JSONValue data) { if (data != null) { m_data = data.toString(); } else { m_data = null; } return this; }
From source file:org.utgenome.gwt.utgb.client.db.datatype.DataTypeBase.java
License:Apache License
public String toString(JSONValue value) { JSONString s = value.isString();//w w w .j a v a2 s . c om if (s != null) return s.stringValue(); else return value.toString(); }
From source file:org.utgenome.gwt.utgb.client.util.JSONUtil.java
License:Apache License
/** * Get a string value (without double quotation) of JSONString, or other JSON types. * /*from ww w . ja v a 2 s . c o m*/ * @param value * @return */ public static String toStringValue(JSONValue value) { if (value == null) return ""; JSONString str = value.isString(); if (str != null) return str.stringValue(); else return value.toString(); }
From source file:org.vaadin.alump.offlinebuilder.client.offline.OfflineFactory.java
License:Open Source License
protected SharedState decodeState(JSONValue jsonState, SharedState state, ApplicationConnection connection) { SharedState ret;/*from w ww .j a va2 s. c om*/ try { ret = (SharedState) JsonDecoder.decodeValue(new Type(state.getClass().getName(), null), jsonState, state, connection); } catch (Exception e) { logger.log(Level.SEVERE, "JSON State decoding exception", e); logger.warning("Failed to decode state of component with JSON: " + jsonState.toString()); ret = null; } return ret; }