Example usage for com.google.gwt.http.client RequestBuilder sendRequest

List of usage examples for com.google.gwt.http.client RequestBuilder sendRequest

Introduction

In this page you can find the example usage for com.google.gwt.http.client RequestBuilder sendRequest.

Prototype

public Request sendRequest(String requestData, RequestCallback callback) throws RequestException 

Source Link

Document

Sends an HTTP request based on the current builder configuration with the specified data and callback.

Usage

From source file:org.freemedsoftware.gwt.client.screen.PatientScreen.java

License:Open Source License

public void populate() {
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        HashMap<String, String> dummy = new HashMap<String, String>();
        dummy.put("patient_name", "Hackenbush, Hugo Z");
        dummy.put("id", patientId.toString());
        dummy.put("patient_id", "HUGO01");
        dummy.put("ptdob", "1979-08-10");
        dummy.put("address_line_1", "101 Evergreen Terrace");
        dummy.put("address_line_2", "");
        dummy.put("csz", "N Kilt Town, IL 00000");
        dummy.put("pthphone", "8005551212");
        dummy.put("ptwphone", "860KL51212");
        populatePatientInformation(dummy);
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = { patientId.toString() };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(
                Util.getJsonRequest("org.freemedsoftware.api.PatientInterface.PatientInformation", params)));
        try {//from  w ww  .j  av a2 s  . c  o  m
            builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                    Util.showErrorMsg("PatientScreen", _("Failed to retrieve patient information."));
                }

                @SuppressWarnings("unchecked")
                public void onResponseReceived(Request request, Response response) {
                    if (200 == response.getStatusCode()) {
                        HashMap<String, String> r = (HashMap<String, String>) JsonUtil.shoehornJson(
                                JSONParser.parseStrict(response.getText()), "HashMap<String,String>");
                        if (r != null) {
                            populatePatientInformation(r);
                        }
                    } else {
                        Util.showErrorMsg("Patientscreen", _("Failed to retrieve patient information."));
                    }
                }
            });
        } catch (RequestException e) {
            Util.showErrorMsg("Patientscreen", _("Failed to retrieve patient information."));
        }
    } else {
        // Set off async method to get information
        PatientInterfaceAsync service = null;
        try {
            service = (PatientInterfaceAsync) Util
                    .getProxy("org.freemedsoftware.gwt.client.Api.PatientInterface");
        } catch (Exception e) {
            GWT.log("Exception caught: ", e);
        }
        service.PatientInformation(patientId, new AsyncCallback<HashMap<String, String>>() {
            public void onSuccess(HashMap<String, String> pInfo) {
                populatePatientInformation(pInfo);
            }

            public void onFailure(Throwable t) {
                GWT.log("FAILURE: ", t);
                Util.showErrorMsg("Patientscreen", _("Failed to retrieve patient information."));
            }
        });
    }

}

From source file:org.freemedsoftware.gwt.client.screen.PatientSearchScreen.java

License:Open Source License

@SuppressWarnings("unchecked")
protected void refreshSearch() {
    sortableTable.clearData();//from  w ww.  j a v  a2 s. c o  m
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        HashMap<String, String> a = new HashMap<String, String>();
        a.put("last_name", "Hackenbush");
        a.put("first_name", "Hugo");
        a.put("middle_name", "Z");
        a.put("patient_id", "HACK01");
        a.put("date_of_birth", "1979-08-10");
        a.put("age", "28");
        a.put("id", "1");
        List<HashMap<String, String>> l = new ArrayList<HashMap<String, String>>();
        l.add(a);
        sortableTable.loadData((HashMap<String, String>[]) l.toArray(new HashMap<?, ?>[0]));
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        HashMap<String, String> criteria = new HashMap<String, String>();
        criteria.put(wFieldName.getValue(wFieldName.getSelectedIndex()), wFieldValue.getText());

        String[] params = { JsonUtil.jsonify(criteria) };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                URL.encode(Util.getJsonRequest("org.freemedsoftware.api.PatientInterface.Search", params)));
        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 (Util.checkValidSessionResponse(response.getText())) {
                        if (200 == response.getStatusCode()) {
                            HashMap<String, String>[] result = (HashMap<String, String>[]) JsonUtil
                                    .shoehornJson(JSONParser.parseStrict(response.getText()),
                                            "HashMap<String,String>[]");
                            sortableTable.loadData(result);

                        } else {
                            Window.alert(response.toString());
                        }
                    }
                }
            });
        } catch (RequestException e) {
            Window.alert(e.toString());
        }
    } else {
        PatientInterfaceAsync service = null;
        try {
            service = (PatientInterfaceAsync) Util
                    .getProxy("org.freemedsoftware.gwt.client.Api.PatientInterface");
        } catch (Exception e) {
            GWT.log("Caught exception: ", e);
        }

        HashMap<String, String> criteria = new HashMap<String, String>();
        criteria.put(wFieldName.getValue(wFieldName.getSelectedIndex()), wFieldValue.getText());

        service.Search(criteria, new AsyncCallback<HashMap<String, String>[]>() {
            public void onSuccess(HashMap<String, String>[] result) {
                // Log.info("found " + new
                // Integer(r.length).toString() + "
                // results for Search");
                sortableTable.loadData(result);
            }

            public void onFailure(Throwable t) {
                // Log.error("Caught exception: ", t);
            }
        });
    }
}

From source file:org.freemedsoftware.gwt.client.screen.PatientsGroupScreen.java

License:Open Source License

public void getGroupAppointments(final Integer groupId, final String groupName) {
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        // TODO: handle stubbed
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = { groupId.toString() };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(
                Util.getJsonRequest("org.freemedsoftware.api.Scheduler.FindGroupAppointmentsDates", params)));
        try {/*from ww w . j  a v  a  2 s  .com*/
            builder.sendRequest(null, new RequestCallback() {
                public void onError(com.google.gwt.http.client.Request request, Throwable ex) {
                    GWT.log("Exception", ex);
                }

                @SuppressWarnings("unchecked")
                public void onResponseReceived(com.google.gwt.http.client.Request request,
                        com.google.gwt.http.client.Response response) {
                    if (200 == response.getStatusCode()) {
                        HashMap<String, String>[] result = (HashMap<String, String>[]) JsonUtil.shoehornJson(
                                JSONParser.parseStrict(response.getText()), "HashMap<String,String>[]");
                        if (result != null && result.length > 0) {
                            groupAppointmentsList = new CustomListBox();
                            for (int i = 0; i < result.length; i++) {
                                groupAppointmentsList.addItem(result[i].get("caldateof"),
                                        result[i].get("id") + ":" + result[i].get("calphysician"));
                            }
                            HorizontalPanel horizontalPanel = new HorizontalPanel();
                            horizontalPanel.add(new Label(_("Select Appointment Date") + ":"));
                            horizontalPanel.add(groupAppointmentsList);
                            groupDetailPanel.add(horizontalPanel);
                        } else {
                        }
                    } else {
                    }
                }
            });
        } catch (RequestException e) {
            GWT.log("Exception", e);
        }
    } else {
        getProxy().GetReports(locale, new AsyncCallback<HashMap<String, String>[]>() {
            public void onSuccess(HashMap<String, String>[] r) {
                patientGroupTable.loadData(r);
            }

            public void onFailure(Throwable t) {
                GWT.log("Exception", t);
            }
        });
    }
}

From source file:org.freemedsoftware.gwt.client.screen.PatientsGroupScreen.java

License:Open Source License

public void populate() {
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        // TODO: handle stubbed
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        patientGroupTable.showloading(true);
        String[] params = { locale };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                URL.encode(Util.getJsonRequest("org.freemedsoftware.module.CalendarGroup.GetAll", params)));
        try {//from  ww  w .  j a va  2  s. c o  m
            builder.sendRequest(null, new RequestCallback() {
                public void onError(com.google.gwt.http.client.Request request, Throwable ex) {
                    GWT.log("Exception", ex);
                }

                @SuppressWarnings("unchecked")
                public void onResponseReceived(com.google.gwt.http.client.Request request,
                        com.google.gwt.http.client.Response response) {
                    if (200 == response.getStatusCode()) {
                        HashMap<String, String>[] result = (HashMap<String, String>[]) JsonUtil.shoehornJson(
                                JSONParser.parseStrict(response.getText()), "HashMap<String,String>[]");
                        if (result != null) {
                            patientGroupTable.clearAllSelections();
                            patientGroupTable.loadData(result);
                        } else {
                            patientGroupTable.showloading(false);
                        }
                    } else {
                    }
                }
            });
        } catch (RequestException e) {
            GWT.log("Exception", e);
        }
    } else {
        getProxy().GetReports(locale, new AsyncCallback<HashMap<String, String>[]>() {
            public void onSuccess(HashMap<String, String>[] r) {
                patientGroupTable.loadData(r);
            }

            public void onFailure(Throwable t) {
                GWT.log("Exception", t);
            }
        });
    }
}

From source file:org.freemedsoftware.gwt.client.screen.PatientsGroupScreen.java

License:Open Source License

public void showGroupInfo(Integer groupId) {
    if (canRead) {
        groupDetailPopup = new Popup();
        groupDetailPanel = new VerticalPanel();
        groupDetailTable = new FlexTable();
        groupDetailPanel.add(groupDetailTable);
        PopupView viewInfo = new PopupView(groupDetailPanel);
        groupDetailPopup.setNewWidget(viewInfo);
        groupDetailPopup.initialize();//from  w w w  .  j  ava  2s  . c  o  m
    } else
        return;
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        // TODO STUBBED MODE STUFF
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = { JsonUtil.jsonify(groupId) };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(
                Util.getJsonRequest("org.freemedsoftware.module.CalendarGroup.GetDetailedRecord", params)));
        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                }

                @SuppressWarnings("unchecked")
                public void onResponseReceived(Request request, Response response) {
                    if (Util.checkValidSessionResponse(response.getText())) {
                        if (200 == response.getStatusCode()) {
                            HashMap<String, String> data = (HashMap<String, String>) JsonUtil.shoehornJson(
                                    JSONParser.parseStrict(response.getText()), "HashMap<String,String>");
                            if (data != null) {
                                diplayGroupDetails(data);

                            }
                        } else {
                        }
                    }
                }
            });
        } catch (RequestException e) {
        }
    } else {
        // TODO NORMAL MODE STUFF
    }
}

From source file:org.freemedsoftware.gwt.client.screen.PatientsGroupScreen.java

License:Open Source License

protected void modifyEntry(Integer groupId) {
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        // TODO STUBBED MODE STUFF
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = { JsonUtil.jsonify(groupId) };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(
                Util.getJsonRequest("org.freemedsoftware.module.CalendarGroup.GetDetailedRecord", params)));
        try {/*from   w w w .  j ava 2  s .com*/
            builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                }

                @SuppressWarnings("unchecked")
                public void onResponseReceived(Request request, Response response) {
                    if (Util.checkValidSessionResponse(response.getText())) {
                        if (200 == response.getStatusCode()) {
                            HashMap<String, String> data = (HashMap<String, String>) JsonUtil.shoehornJson(
                                    JSONParser.parseStrict(response.getText()), "HashMap<String,String>");
                            if (data != null) {
                                groupName.setText(data.get("groupname"));
                                facilityModuleWidget.setValue(Integer.parseInt(data.get("facility")));
                                groupFrequency.setText(data.get("groupfrequency"));
                                groupLength.setText(data.get("grouplength"));
                                String[] groupMembers = data.get("groupmembers").split(",");
                                for (int i = 0; i < groupMembers.length; i++) {
                                    if (i > 3) {
                                        PatientWidget patientWidget = new PatientWidget();
                                        patientWidget.setWidth("300px");
                                        membersPanel.add(patientWidget);
                                        groupMembersListInEntryForm.add(patientWidget);
                                    }
                                    groupMembersListInEntryForm.get(i)
                                            .setValue(Integer.parseInt(groupMembers[i]));
                                }

                            }
                        } else {
                        }
                    }
                }
            });
        } catch (RequestException e) {
        }
    } else {
        // TODO NORMAL MODE STUFF
    }
}

From source file:org.freemedsoftware.gwt.client.screen.PatientsGroupScreen.java

License:Open Source License

public void saveForm() {
    if (validateForm()) {
        // Add callin info
        if (Util.getProgramMode() == ProgramMode.STUBBED) {
            // TODO STUBBED MODE STUFF
        } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
            RequestBuilder builder = null;
            if (btnAdd.getText().equals("Add")) {
                String[] params = { JsonUtil.jsonify(populateHashMap(null)) };
                builder = new RequestBuilder(RequestBuilder.POST, URL
                        .encode(Util.getJsonRequest("org.freemedsoftware.module.CalendarGroup.add", params)));
            } else {
                String[] params = { JsonUtil.jsonify(populateHashMap(selectedEntryId)) };
                builder = new RequestBuilder(RequestBuilder.POST, URL
                        .encode(Util.getJsonRequest("org.freemedsoftware.module.CalendarGroup.mod", params)));

            }/*from   w  w w. ja  v a  2 s . c  o  m*/
            try {
                builder.sendRequest(null, new RequestCallback() {
                    public void onError(Request request, Throwable ex) {
                    }

                    public void onResponseReceived(Request request, Response response) {
                        if (200 == response.getStatusCode()) {
                            Integer r = (Integer) JsonUtil
                                    .shoehornJson(JSONParser.parseStrict(response.getText()), "Integer");
                            if (r != null) {
                                clearForm();
                                populate();
                                Util.showInfoMsg("CalendarGroupScreen", _("Entry successfully added."));
                            } else {
                                r = (Boolean) JsonUtil.shoehornJson(JSONParser.parseStrict(response.getText()),
                                        "Boolean") ? 1 : 0;
                                if (r == 1) {
                                    clearForm();
                                    populate();
                                    Util.showInfoMsg("CalendarGroupScreen", _("Entry successfully modified."));
                                    btnAdd.setText("Add");
                                } else {

                                }
                            }
                        } else {
                            Util.showErrorMsg("CalendarGroupScreen", _("Group form failed."));
                        }
                    }
                });
            } catch (RequestException e) {
            }
        } else if (Util.getProgramMode() == ProgramMode.NORMAL) {
            // TODO GWT WORK
        }
    }
}

From source file:org.freemedsoftware.gwt.client.screen.PatientsGroupScreen.java

License:Open Source License

protected void deleteEntry(Integer groupId) {
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        // TODO STUBBED MODE STUFF
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = { JsonUtil.jsonify(groupId) };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                URL.encode(Util.getJsonRequest("org.freemedsoftware.module.CalendarGroup.del", params)));
        try {/*from w  ww  .  j a  v a  2 s .c  o m*/
            builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                    Util.showErrorMsg("CalendarGroupScreen", _("Failed to delete entry."));
                }

                public void onResponseReceived(Request request, Response response) {
                    if (Util.checkValidSessionResponse(response.getText())) {
                        if (200 == response.getStatusCode()) {
                            Boolean r = (Boolean) JsonUtil
                                    .shoehornJson(JSONParser.parseStrict(response.getText()), "Boolean");
                            if (r != null) {
                                Util.showInfoMsg("CalendarGroupScreen", _("Entry deleted."));
                                // populate(tag);
                            }
                        } else {
                            Util.showErrorMsg("CalendarGroupScreen", "Failed to delete entry.");
                        }
                    }
                }
            });
        } catch (RequestException e) {
        }
    } else {
        // TODO NORMAL MODE STUFF
    }
}

From source file:org.freemedsoftware.gwt.client.screen.PatientTagSearchScreen.java

License:Open Source License

/**
 * Perform tag search and pass population data on.
 * //  www .  j a v a2  s .c o m
 * @param t
 *            Textual value of tag being searched.
 */
@SuppressWarnings("unchecked")
public void searchForTag(String t) {
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        List<HashMap<String, String>> results = new ArrayList<HashMap<String, String>>();
        populate((HashMap<String, String>[]) results.toArray(new HashMap<?, ?>[0]));
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        customSortableTable.showloading(true);
        String[] params = { t, JsonUtil.jsonify(Boolean.FALSE) };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL
                .encode(Util.getJsonRequest("org.freemedsoftware.module.PatientTag.SimpleTagSearch", params)));
        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                    GWT.log("Exception", ex);
                }

                public void onResponseReceived(Request request, Response response) {
                    if (200 == response.getStatusCode()) {
                        HashMap<String, String>[] r = (HashMap<String, String>[]) JsonUtil.shoehornJson(
                                JSONParser.parseStrict(response.getText()), "HashMap<String,String>[]");
                        if (r != null) {
                            populate(r);
                        }
                    } else {
                        customSortableTable.showloading(false);
                        GWT.log("Exception", null);
                    }
                }
            });
        } catch (RequestException e) {
            GWT.log("Exception", e);
        }
    } else {
        PatientTagAsync proxy = null;
        try {
            proxy = (PatientTagAsync) Util.getProxy("org.freemedsoftware.gwt.client.Module.PatientTag");
        } catch (Exception ex) {
            GWT.log("Exception", ex);
        }
        proxy.SimpleTagSearch(t, Boolean.FALSE, new AsyncCallback<HashMap<String, String>[]>() {
            public void onSuccess(HashMap<String, String>[] data) {
                populate(data);
            }

            public void onFailure(Throwable t) {
                GWT.log("Exception", t);
            }
        });
    }
}

From source file:org.freemedsoftware.gwt.client.screen.PreferencesScreen.java

License:Open Source License

public void chagePasswordProcess() {
    if (currentPassword.getText().length() > 0 && newPassword.getText().length() > 0
            && newPassword.getText().equals(confirmNewPassword.getText())) {
        if (Util.getProgramMode() == ProgramMode.STUBBED) {
            // TODO stubbed mode goes here
        } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
            String[] params = {};
            RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                    URL.encode(Util.getJsonRequest("org.freemedsoftware.core.User.GetName", params)));
            try {
                builder.sendRequest(null, new RequestCallback() {
                    public void onError(Request request, Throwable ex) {
                        Window.alert(ex.toString());
                    }/* w  w  w . j a va 2 s . c om*/

                    public void onResponseReceived(Request request, Response response) {
                        if (200 == response.getStatusCode()) {
                            validateUser((String) JsonUtil.shoehornJson(response.getText(), "String"),
                                    currentPassword.getText());
                        } else
                            Util.showErrorMsg("PreferencesScreen", _("Password change failed."));
                    }
                });
            } catch (RequestException e) {
                Window.alert(e.getMessage());
            }
        } else {

            // TODO normal mode code goes here
        }
    } else {
        Window.alert(_("Enter correct information to change password."));
    }
}