List of usage examples for com.google.gwt.http.client URL encode
public static String encode(String decodedURL)
From source file:org.freemedsoftware.gwt.client.screen.UserManagementScreen.java
License:Open Source License
public void retrieveAllUsers() { if (Util.getProgramMode() == ProgramMode.STUBBED) { // Do nothing } else if (Util.getProgramMode() == ProgramMode.JSONRPC) { // Use JSON-RPC to retrieve the data String[] params = {};//from www . j av a2 s . c o m RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(Util.getJsonRequest("org.freemedsoftware.api.UserInterface.GetRecords", params))); try { builder.sendRequest(null, new RequestCallback() { public void onError(Request request, Throwable ex) { GWT.log(request.toString(), ex); } @SuppressWarnings("unchecked") public void onResponseReceived(Request request, Response response) { if (response.getStatusCode() == 200) { HashMap<String, String>[] data = (HashMap<String, String>[]) JsonUtil.shoehornJson( JSONParser.parseStrict(response.getText()), "HashMap<String,String>[]"); if (data != null) { wUsers.clearData(); wUsers.loadData(data); } } } }); } catch (RequestException e) { // nothing here right now } } else if (Util.getProgramMode() == ProgramMode.NORMAL) { // Use GWT-RPC to retrieve the data // TODO: Create that stuff } }
From source file:org.freemedsoftware.gwt.client.screen.UserManagementScreen.java
License:Open Source License
public void getACLGroups() { if (Util.getProgramMode() == ProgramMode.STUBBED) { // Do nothing } else if (Util.getProgramMode() == ProgramMode.JSONRPC) { // Use JSON-RPC to retrieve the data String[] params = {};/*from www. j a v a 2s. c o m*/ RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(Util.getJsonRequest("org.freemedsoftware.module.ACL.userGroups", params))); try { builder.sendRequest(null, new RequestCallback() { public void onError(Request request, Throwable ex) { GWT.log(request.toString(), ex); } public void onResponseReceived(Request request, Response response) { if (response.getStatusCode() == 200) { String[][] data = (String[][]) JsonUtil .shoehornJson(JSONParser.parseStrict(response.getText()), "String[][]"); if (data != null) { addACLGroup(data); } } } }); } catch (RequestException e) { // nothing here right now } } else if (Util.getProgramMode() == ProgramMode.NORMAL) { // Use GWT-RPC to retrieve the data // TODO: Create that stuff } }
From source file:org.freemedsoftware.gwt.client.screen.UserManagementScreen.java
License:Open Source License
public void getUserDetails(final Integer userId) { if (Util.getProgramMode() == ProgramMode.STUBBED) { // Do nothing } else if (Util.getProgramMode() == ProgramMode.JSONRPC) { // Use JSON-RPC to retrieve the data String[] params = { JsonUtil.jsonify(userId) }; RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(Util.getJsonRequest("org.freemedsoftware.api.UserInterface.GetRecord", params))); try {//from ww w . j a v a 2 s . c o m builder.sendRequest(null, new RequestCallback() { public void onError(Request request, Throwable ex) { GWT.log(request.toString(), ex); } @SuppressWarnings("unchecked") public void onResponseReceived(Request request, Response response) { if (response.getStatusCode() == 200) { HashMap<String, String> data = (HashMap<String, String>) JsonUtil.shoehornJson( JSONParser.parseStrict(response.getText()), "HashMap<String,String>"); if (data != null) { tbUsername.setText(data.get("username")); tbDescription.setText(data.get("userdescrip")); tbUserFirstName.setText(data.get("userfname")); tbUserLastName.setText(data.get("userlname")); tbUserMiddleName.setText(data.get("usermname")); tbUserTitle.setWidgetValue(data.get("usertitle")); lbUserType.setWidgetValue(data.get("usertype")); if (data.get("usertype") != null && data.get("usertype").equalsIgnoreCase("phy")) { lbActualPhysician.setValue(Integer.parseInt(data.get("userrealphy"))); lbActualPhysician.setVisible(true); } if (data.get("userfac") != null && data.get("userfac").length() > 0) { String[] userFacilities = data.get("userfac").split(","); for (int i = 0; i < userFacilities.length; i++) { Integer id = Integer.parseInt(userFacilities[i]); CheckBox checkBox = facilitiesCheckBoxesMap.get(id); if (checkBox != null) checkBox.setValue(true); } } addUserButton.setText(_("Modify User")); changePasswordLink.setVisible(true); tbPassword.setEnabled(false); tbPasswordverify.setEnabled(false); deleteUserButton.setVisible(true); copyButton.setVisible(true); } } } }); } catch (RequestException e) { // nothing here right now } } else if (Util.getProgramMode() == ProgramMode.NORMAL) { // Use GWT-RPC to retrieve the data // TODO: Create that stuff } }
From source file:org.freemedsoftware.gwt.client.screen.UserManagementScreen.java
License:Open Source License
public void getUserGroup(final Integer userId) { aclSelectedGroupsIdsList.clear();/*w w w . ja va 2 s . c o m*/ if (Util.getProgramMode() == ProgramMode.STUBBED) { // Do nothing } else if (Util.getProgramMode() == ProgramMode.JSONRPC) { // Use JSON-RPC to retrieve the data String[] params = { JsonUtil.jsonify(userId) }; RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(Util.getJsonRequest("org.freemedsoftware.module.ACL.GetUserGroups", params))); try { builder.sendRequest(null, new RequestCallback() { public void onError(Request request, Throwable ex) { GWT.log(request.toString(), ex); } public void onResponseReceived(Request request, Response response) { if (response.getStatusCode() == 200) { String[] data = (String[]) JsonUtil .shoehornJson(JSONParser.parseStrict(response.getText()), "String[]"); if (data != null) { Integer groupId = null; for (int i = 0; i < data.length; i++) { groupId = Integer.parseInt(data[i]); CheckBox checkBox = aclGroupsCheckBoxesMap.get(groupId); checkBox.setValue(true); aclSelectedGroupsIdsList.add(groupId); } } } } }); } catch (RequestException e) { // nothing here right now } } else if (Util.getProgramMode() == ProgramMode.NORMAL) { // Use GWT-RPC to retrieve the data // TODO: Create that stuff } }
From source file:org.freemedsoftware.gwt.client.SystemNotifications.java
License:Open Source License
/** * Asynchronously poll for new system notifications *///from w w w . ja v a 2 s .co m public boolean poll() { JsonUtil.debug("SystemNotifications.poll() called"); // if (mutexStatus) { // JsonUtil.debug("mutexStatus indicates run in progress."); // return false; // } mutexStatus = true; if (Util.getProgramMode() == ProgramMode.STUBBED) { // Nothing. Do nothing. mutexStatus = false; return true; } else if (Util.getProgramMode() == ProgramMode.JSONRPC) { // JSON-RPC String[] params = { Long.toString(mutexTimestamp) }; RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(Util .getJsonRequest("org.freemedsoftware.module.SystemNotifications.GetFromTimestamp", params))); try { builder.sendRequest(null, new RequestCallback() { public void onError(Request request, Throwable ex) { Util.showErrorMsg("SystemNotifications", _("Failed to get system notifications.")); } @SuppressWarnings("unchecked") public void onResponseReceived(Request request, Response response) { if (200 == response.getStatusCode()) { if (response.getText().compareToIgnoreCase("false") != 0) { if (response.getText().trim().equalsIgnoreCase(AppConstants.INVALID_SESSION)) { Util.logout(new Command() { @Override public void execute() { stop(); } }); mutexStatus = false; return; } HashMap<String, String>[] r = (HashMap<String, String>[]) JsonUtil.shoehornJson( JSONParser.parseStrict(response.getText()), "HashMap<String,String>[]"); if (r != null) { if (r.length > 0) { // Update our working timestamp try { mutexTimestamp = Long.parseLong(r[0].get("timestamp")); JsonUtil.debug("SystemNotifications(): Received timestamp " + r[0].get("timestamp")); JsonUtil.debug( "SystemNotifications(): Parsed timestamp as " + mutexTimestamp); } catch (Exception ex) { JsonUtil.debug( "SystemNotifications(): Exception parsing mutex timestamp" + r[0].get("timestamp")); } for (int iter = 0; iter < r.length; iter++) { handleNotification(r[iter]); } } } } else { JsonUtil.debug("SystemNotifications(): Received dummy response from JSON backend"); } } else { Util.showErrorMsg("SystemNotifications", _("Failed to get system notifications.")); } // Release mutex mutexStatus = false; } }); } catch (RequestException e) { Util.showErrorMsg("SystemNotifications", _("Failed to get system notifications.")); } } else { // GWT-RPC } return true; }
From source file:org.freemedsoftware.gwt.client.Util.java
License:Open Source License
public static void login(String username, String password, String location, final CustomCommand whenDone, final CustomCommand whenFail) { List<String> paramList = new ArrayList<String>(); paramList.add(username);// w ww . ja v a2 s . co m paramList.add(password); if (location != null) paramList.add(location); RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(Util.getJsonRequest("org.freemedsoftware.public.Login.Validate", (String[]) paramList.toArray(new String[0])))); try { builder.sendRequest(null, new RequestCallback() { public void onError(Request request, Throwable ex) { Window.alert(ex.toString()); } public void onResponseReceived(Request request, Response response) { if (200 == response.getStatusCode()) { String res = (String) JsonUtil.shoehornJson(JSONParser.parseStrict(response.getText()), "String"); if (res == null) res = response.getText().trim(); if (res.compareToIgnoreCase("true") == 0) { whenDone.execute(null); } else if (res.compareToIgnoreCase("false") == 0) { whenFail.execute(AppConstants.INVALID_USER); } else if (res.compareToIgnoreCase(AppConstants.NOT_IN_FACILITY) == 0) whenFail.execute(AppConstants.NOT_IN_FACILITY); } else { whenFail.execute(AppConstants.INVALID_RESPONSE); } } }); } catch (RequestException e) { whenFail.execute(AppConstants.INVALID_RESPONSE); } }
From source file:org.freemedsoftware.gwt.client.Util.java
License:Open Source License
/** * Logout of the system and pop up a login dialog. * /*from w ww. j a v a 2 s .c om*/ * @param state */ public static void logout(final Command onSuccess) { if (Util.getProgramMode() == ProgramMode.STUBBED) { } else if (Util.getProgramMode() == ProgramMode.JSONRPC) { String[] params = {}; RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(Util.getJsonRequest("org.freemedsoftware.public.Login.Logout", params))); try { builder.sendRequest(null, new RequestCallback() { public void onError(com.google.gwt.http.client.Request request, Throwable ex) { GWT.log("Exception", ex); Window.alert(_("Failed to log out.")); } public void onResponseReceived(com.google.gwt.http.client.Request request, com.google.gwt.http.client.Response response) { if (200 == response.getStatusCode()) { // closeAllTabs(); if (onSuccess != null) onSuccess.execute(); CurrentState.getMainScreen().setVisible(false); UIObject.setVisible(RootPanel.get("loginScreenOuter").getElement(), true); CurrentState.getFreemedInterface().getLoginDialog().center(); CurrentState.getFreemedInterface().getLoginDialog().setFocusToPasswordField(); } else { Window.alert(_("Failed to log out.")); } } }); } catch (RequestException e) { GWT.log("Exception", e); Window.alert("Failed to log out."); } } else { try { LoginAsync service = (LoginAsync) Util.getProxy("org.freemedsoftware.gwt.client.Public.Login"); service.Logout(new AsyncCallback<Void>() { public void onSuccess(Void r) { CurrentState.getMainScreen().hide(); UIObject.setVisible(RootPanel.get("loginScreenOuter").getElement(), true); CurrentState.getFreemedInterface().getLoginDialog().center(); } public void onFailure(Throwable t) { Window.alert("Failed to log out."); } }); } catch (Exception e) { Window.alert("Could not create proxy for Login"); } } }
From source file:org.freemedsoftware.gwt.client.Util.java
License:Open Source License
/** * Calls server method/*w w w . ja v a 2s.c o m*/ * * @param package - package name * * @param module * - module name * * @param method * - method name * * @param paramsList * - list of parameters of any type or multi-type * * @param requestCallback * - calls its onError & jsonifiedData function on getting * response from server * * @param responseType * - type of response e.g * Integer,HashMap<String,String>,String[],String[][] etc */ @SuppressWarnings("rawtypes") private static void callServerMethod(final String packageName, final String className, final String method, final List paramsList, final CustomRequestCallback requestCallback, final String responseType, Method requestMethod) { if (Util.getProgramMode() == ProgramMode.STUBBED) { // TODO: STUBBED } else if (Util.getProgramMode() == ProgramMode.JSONRPC) { // JSON-RPC String params = ""; List<String> paramsStr = new ArrayList<String>(); if (paramsList != null) { int i = 0; Iterator iterator = paramsList.iterator(); while (iterator.hasNext()) { Object object = iterator.next(); if (requestMethod == RequestBuilder.GET) paramsStr.add(JsonUtil.jsonify(object)); else { if (params.length() > 0) params += "&"; params += "param" + i++ + "=" + JsonUtil.jsonify(object); } } } String methodURL = packageName + "." + className + "." + method; RequestBuilder builder = null; if (requestMethod == RequestBuilder.POST) { builder = new RequestBuilder(requestMethod, URL.encode(Util.getJsonRequest(methodURL))); builder.setHeader("Content-type", "application/x-www-form-urlencoded"); builder.setHeader("Content-length", params.length() + ""); builder.setHeader("Connection", "close"); } else { builder = new RequestBuilder(requestMethod, URL.encode(Util.getJsonRequest(methodURL, paramsStr.toArray(new String[0])))); } try { builder.sendRequest(params, new RequestCallback() { public void onError(Request request, Throwable ex) { if (requestCallback != null) requestCallback.onError(); } public void onResponseReceived(Request request, Response response) { if (requestCallback != null) { if (200 == response.getStatusCode()) { Object result = JsonUtil.shoehornJson(JSONParser.parseStrict(response.getText()), responseType); requestCallback.jsonifiedData(result); } else requestCallback.onError(); } } }); } catch (RequestException e) { } } else { // GWT-RPC } }
From source file:org.freemedsoftware.gwt.client.widget.ActionItemsBox.java
License:Open Source License
@SuppressWarnings({ "rawtypes", "unchecked" }) public void retrieveData() { if (Util.getProgramMode() == ProgramMode.STUBBED) { // Runs in STUBBED MODE => Feed with Sample Data HashMap<String, String>[] sampleData = getSampleData(); loadData(sampleData);//from w ww . j a v a 2 s.c om } else if (Util.getProgramMode() == ProgramMode.JSONRPC) { // Use JSON-RPC to retrieve the data String[] actionsParams = {}; if (patientId != null) { List params = new ArrayList(); params.add(patientId.toString()); actionsParams = (String[]) params.toArray(new String[0]); } RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode( Util.getJsonRequest("org.freemedsoftware.api.ActionItems.getActionItemsCount", actionsParams))); try { builder.sendRequest(null, new RequestCallback() { @Override public void onError(Request request, Throwable ex) { GWT.log(request.toString(), ex); } @Override public void onResponseReceived(Request request, Response response) { if (response.getStatusCode() == 200) { Integer data = (Integer) JsonUtil .shoehornJson(JSONParser.parseStrict(response.getText()), "Integer"); if (data != null) { JsonUtil.debug("Action Items count from server is:" + data); loadCounter(data); } } } }); } catch (RequestException e) { // nothing here right now } actionItemsTable.showloading(true); // Get data RequestBuilder dataBuilder = new RequestBuilder(RequestBuilder.POST, URL.encode( Util.getJsonRequest("org.freemedsoftware.api.ActionItems.getActionItems", actionsParams))); try { dataBuilder.sendRequest(null, new RequestCallback() { @Override public void onError(Request request, Throwable ex) { GWT.log(request.toString(), ex); } @Override public void onResponseReceived(Request request, Response response) { if (response.getStatusCode() == 200) { HashMap<String, String>[] data = (HashMap<String, String>[]) JsonUtil.shoehornJson( JSONParser.parseStrict(response.getText()), "HashMap<String,String>[]"); if (data != null && data.length > 0) { setResult(data); loadData(data); } else actionItemsTable.showloading(false); } } }); } catch (RequestException e) { actionItemsTable.showloading(false); // nothing here right now } } else if (Util.getProgramMode() == ProgramMode.NORMAL) { // Use GWT-RPC to retrieve the data // TODO: Create that stuff } }
From source file:org.freemedsoftware.gwt.client.widget.CustomModuleWidget.java
License:Open Source License
protected void loadSuggestions(String req, final Request r, final Callback cb) { if (Util.getProgramMode() == ProgramMode.STUBBED) { // Handle in a stubbed sort of way List<SuggestOracle.Suggestion> items = new ArrayList<SuggestOracle.Suggestion>(); map.clear();//from w ww .j a v a 2 s.co m addKeyValuePair(items, new String("Hackenbush, Hugo Z"), new String("1")); addKeyValuePair(items, new String("Firefly, Rufus T"), new String("2")); cb.onSuggestionsReady(r, new SuggestOracle.Response(items)); } else if (Util.getProgramMode() == ProgramMode.JSONRPC) { String[] params = { req }; RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(Util.getJsonRequest("org.freemedsoftware." + moduleName, params))); try { builder.sendRequest(null, new RequestCallback() { public void onError(com.google.gwt.http.client.Request request, Throwable ex) { } @SuppressWarnings("unchecked") public void onResponseReceived(com.google.gwt.http.client.Request request, com.google.gwt.http.client.Response response) { if (Util.checkValidSessionResponse(response.getText())) { if (200 == response.getStatusCode()) { HashMap<String, String> result = (HashMap<String, String>) JsonUtil.shoehornJson( JSONParser.parseStrict(response.getText()), "HashMap<String,String>"); if (result != null) { Set<String> keys = result.keySet(); Iterator<String> iter = keys.iterator(); List<SuggestOracle.Suggestion> items = new ArrayList<SuggestOracle.Suggestion>(); map.clear(); while (iter.hasNext()) { final String key = (String) iter.next(); final String val = (String) result.get(key); addKeyValuePair(items, val, key); } cb.onSuggestionsReady(r, new SuggestOracle.Response(items)); } else // if no result then set value to 0 setValue(0); } else { GWT.log("Result " + response.getStatusText(), null); } } } }); } catch (RequestException e) { GWT.log("Exception thrown: ", e); } } else { ModuleInterfaceAsync service = null; try { service = ((ModuleInterfaceAsync) Util .getProxy("org.freemedsoftware.gwt.client.Api.ModuleInterface")); } catch (Exception e) { } service.ModuleSupportPicklistMethod(moduleName, req, new AsyncCallback<HashMap<String, String>>() { public void onSuccess(HashMap<String, String> result) { Set<String> keys = result.keySet(); Iterator<String> iter = keys.iterator(); List<SuggestOracle.Suggestion> items = new ArrayList<SuggestOracle.Suggestion>(); map.clear(); while (iter.hasNext()) { final String key = (String) iter.next(); final String val = (String) result.get(key); addKeyValuePair(items, val, key); } cb.onSuggestionsReady(r, new SuggestOracle.Response(items)); } public void onFailure(Throwable t) { GWT.log("Exception thrown: ", t); } }); } }