示例#1
0
  public void getMessages() {

    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(URLGET));

    try {
      Request request =
          builder.sendRequest(
              null,
              new RequestCallback() {
                public void onError(Request request, Throwable exception) {}

                public void onResponseReceived(Request request, Response response) {
                  if (200 == response.getStatusCode()) {
                    IResponse serverResponse = decodeJSON(response.getText());
                    processResponse(serverResponse);

                  } else {

                    Window.alert("Messages couldn't  been recieved");
                  }
                }
              });
    } catch (RequestException e) {
      // Couldn't connect to server
    }
  }
  public static void retrieveAncestors(final Event event, final PathHandler handler) {
    String url = "/ReactomeRESTfulAPI/RESTfulWS/queryEventAncestors/" + event.getDbId();
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url);
    requestBuilder.setHeader("Accept", "application/json");
    try {
      requestBuilder.sendRequest(
          null,
          new RequestCallback() {
            @Override
            public void onResponseReceived(Request request, Response response) {
              try {
                JSONArray list = JSONParser.parseStrict(response.getText()).isArray();
                Ancestors ancestors = new Ancestors(list);
                List<Path> paths =
                    getPathsWithoutOrphanPathways(ancestors.getPathsContaining(event));
                handler.onPathsRetrieved(paths);
              } catch (Exception ex) {
                // ToDo: Look into new Error Handling
              }
            }

            @Override
            public void onError(Request request, Throwable exception) {
              // ToDo: Look into new Error Handling
            }
          });
    } catch (RequestException ex) {
      // ToDo: Look into new Error Handling
    }
  }
示例#3
0
  public static void fbLogin(String profileId) throws RequestException {
    RequestBuilder builder =
        new RequestBuilder(
            RequestBuilder.POST, "http://localhost:8080/j_spring_service_security_check");
    builder.setHeader("Content-type", "application/x-www-form-urlencoded");
    builder.sendRequest(
        "profile_id=" + profileId + "&service_name=facebook",
        new RequestCallback() {
          @Override
          public void onResponseReceived(Request request, Response response) {
            if (response.getStatusCode() < 400) {
              History.newItem("photo");
            }
          }

          @Override
          public void onError(Request request, Throwable exception) {
            return;
          }
        });
  }
示例#4
0
  private void getAllTreeLessons() {
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URLConstants.JSON_LESSONS);
    try {
      builder.sendRequest(
          null,
          new RequestCallback() {
            public void onError(Request request, Throwable exception) {
              displayError("Couldn't retrieve JSON : " + exception.getMessage());
            }

            public void onResponseReceived(Request request, Response response) {
              if (Response.SC_OK == response.getStatusCode()) {
                buildLessonTree(response);
              } else {
                displayError("Couldn't retrieve JSON (" + response.getStatusText() + ")");
              }
            }
          });
    } catch (RequestException e) {
      displayError("Couldn't retrieve JSON : " + e.getMessage());
    }
  }
  @Override
  public void onReferencesRequired(final Long dbId) {
    String url = "/ReactomeRESTfulAPI/RESTfulWS/queryReferences/" + dbId;
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url);
    requestBuilder.setHeader("Accept", "application/json");
    try {
      requestBuilder.sendRequest(
          null,
          new RequestCallback() {
            @Override
            public void onResponseReceived(Request request, Response response) {
              try {
                JSONArray list = JSONParser.parseStrict(response.getText()).isArray();
                List<LiteratureReference> references = new ArrayList<LiteratureReference>();
                for (int i = 0; i < list.size(); ++i) {
                  JSONObject object = list.get(i).isObject();
                  references.add((LiteratureReference) ModelFactory.getDatabaseObject(object));
                }
                DataRequiredListener.getDataRequiredListener()
                    .setRequiredReferences(dbId, references);
              } catch (Exception ex) {
                // ModelFactoryException, NullPointerException, IllegalArgumentException,
                // JSONException
                MessageObject msgObj =
                    new MessageObject(
                        "The received References object for 'DbId="
                            + dbId
                            + "' is empty or faulty and could not be parsed.\n"
                            + "ERROR: "
                            + ex.getMessage(),
                        getClass(),
                        MessageType.INTERNAL_ERROR);
                eventBus.fireELVEvent(ELVEventType.INTERNAL_MESSAGE, msgObj);
                Console.error(getClass() + " ERROR: " + ex.getMessage());
                DataRequiredListener.getDataRequiredListener()
                    .setRequiredReferences(dbId, new ArrayList<LiteratureReference>());
              }
            }

            @Override
            public void onError(Request request, Throwable exception) {
              if (!GWT.isScript()) {
                Console.error(getClass() + " ERROR: " + exception.getMessage());
              }

              MessageObject msgObj =
                  new MessageObject(
                      "The request for 'DbId="
                          + dbId
                          + "' received an error instead of a valid response.\n"
                          + "ERROR: "
                          + exception.getMessage(),
                      getClass(),
                      MessageType.INTERNAL_ERROR);
              eventBus.fireELVEvent(ELVEventType.INTERNAL_MESSAGE, msgObj);
              DataRequiredListener.getDataRequiredListener()
                  .setRequiredReferences(dbId, new ArrayList<LiteratureReference>());
            }
          });
    } catch (RequestException ex) {
      MessageObject msgObj =
          new MessageObject(
              "The requested references data for 'DbId="
                  + dbId
                  + "' could not be received.\n"
                  + "ERROR: "
                  + ex.getMessage(),
              getClass(),
              MessageType.INTERNAL_ERROR);
      eventBus.fireELVEvent(ELVEventType.INTERNAL_MESSAGE, msgObj);
      Console.error(getClass() + " ERROR: " + ex.getMessage());
      DataRequiredListener.getDataRequiredListener()
          .setRequiredReferences(dbId, new ArrayList<LiteratureReference>());
    }
  }
  @Override
  public void onMoleculeDataRequired(final Molecule molecule) {
    String url = "/ReactomeRESTfulAPI/RESTfulWS/queryById/ReferenceEntity/" + molecule.getDbId();
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url);
    requestBuilder.setHeader("Accept", "application/json");
    try {
      requestBuilder.sendRequest(
          null,
          new RequestCallback() {
            @Override
            public void onResponseReceived(Request request, Response response) {
              try {
                JSONObject json = JSONParser.parseStrict(response.getText()).isObject();
                Molecule molecule =
                    new Molecule(ModelFactory.getDatabaseObject(json).getSchemaClass(), json);

                DataRequiredListener.getDataRequiredListener().setRequiredMoleculeData(molecule);
              } catch (Exception ex) {
                // ModelFactoryException, NullPointerException, IllegalArgumentException,
                // JSONException
                MessageObject msgObj =
                    new MessageObject(
                        "The received object for Molecule '"
                            + molecule.getDisplayName()
                            + "' is empty or faulty and could not be parsed.\n"
                            + "ERROR: "
                            + ex.getMessage(),
                        getClass(),
                        MessageType.INTERNAL_ERROR);
                eventBus.fireELVEvent(ELVEventType.INTERNAL_MESSAGE, msgObj);
                Console.error(getClass() + " ERROR: " + ex.getMessage());
                DataRequiredListener.getDataRequiredListener().setRequiredMoleculeData(molecule);
              }
            }

            @Override
            public void onError(Request request, Throwable exception) {
              if (!GWT.isScript()) {
                Console.error(getClass() + " ERROR: " + exception.getMessage());
              }

              MessageObject msgObj =
                  new MessageObject(
                      "The request for Molecule '"
                          + molecule.getDisplayName()
                          + "' received an error instead of a valid response.\n"
                          + "ERROR: "
                          + exception.getMessage(),
                      getClass(),
                      MessageType.INTERNAL_ERROR);
              eventBus.fireELVEvent(ELVEventType.INTERNAL_MESSAGE, msgObj);
              DataRequiredListener.getDataRequiredListener().setRequiredMoleculeData(molecule);
            }
          });
    } catch (RequestException ex) {
      MessageObject msgObj =
          new MessageObject(
              "The requested detailed data for Molecule \n'"
                  + molecule.getDisplayName()
                  + "' could not be received.\n"
                  + "ERROR: "
                  + ex.getMessage(),
              getClass(),
              MessageType.INTERNAL_ERROR);
      eventBus.fireELVEvent(ELVEventType.INTERNAL_MESSAGE, msgObj);
      Console.error(getClass() + " ERROR: " + ex.getMessage());
      DataRequiredListener.getDataRequiredListener().setRequiredMoleculeData(molecule);
    }
  }
  @Override
  public void onPathRequired(final Event event) {
    /* TODO Testing
    but never used because DataRequiredListener is used by DetailsPanel and there ancestorsRequired is unused */
    final long dbId = event.getDbId();
    String url = "/ReactomeRESTfulAPI/RESTfulWS/queryEventAncestors/" + dbId;
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url);
    requestBuilder.setHeader("Accept", "application/json");
    try {
      requestBuilder.sendRequest(
          null,
          new RequestCallback() {
            @Override
            public void onResponseReceived(Request request, Response response) {
              try {
                JSONArray list = JSONParser.parseStrict(response.getText()).isArray();
                Ancestors ancestors = new Ancestors(list);
                DataRequiredListener.getDataRequiredListener()
                    .setRequiredAncestors(dbId, ancestors);
              } catch (Exception ex) {
                // ModelFactoryException, NullPointerException, IllegalArgumentException,
                // JSONException
                MessageObject msgObj =
                    new MessageObject(
                        "The received object for 'DbId="
                            + event.getDbId()
                            + "' is empty or faulty and could not be parsed into a path or hierarchy.\n"
                            + "ERROR: "
                            + ex.getMessage(),
                        getClass(),
                        MessageType.INTERNAL_ERROR);
                eventBus.fireELVEvent(ELVEventType.INTERNAL_MESSAGE, msgObj);
                Console.error(getClass() + " ERROR: " + ex.getMessage());
              }
            }

            @Override
            public void onError(Request request, Throwable exception) {
              if (!GWT.isScript()) {
                Console.error(getClass() + " ERROR: " + exception.getMessage());
              }

              MessageObject msgObj =
                  new MessageObject(
                      "The PathRequired request for 'DbId="
                          + event.getDbId()
                          + "' received an error instead of a valid response.\n"
                          + "ERROR: "
                          + exception.getMessage(),
                      getClass(),
                      MessageType.INTERNAL_ERROR);
              eventBus.fireELVEvent(ELVEventType.INTERNAL_MESSAGE, msgObj);
            }
          });
    } catch (RequestException ex) {
      MessageObject msgObj =
          new MessageObject(
              "The requested data for 'DbId="
                  + event.getDbId()
                  + "' could not be received.\n"
                  + "ERROR: "
                  + ex.getMessage(),
              getClass(),
              MessageType.INTERNAL_ERROR);
      eventBus.fireELVEvent(ELVEventType.INTERNAL_MESSAGE, msgObj);
      Console.error(getClass() + " ERROR: " + ex.getMessage());
    }
  }
  @Override
  public void onDataRequired(final DatabaseObject databaseObject) {
    final long dbId = databaseObject.getDbId();
    String url = "/ReactomeRESTfulAPI/RESTfulWS/detailedView/DatabaseObject/" + dbId;
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url);
    requestBuilder.setHeader("Accept", "application/json");
    try {
      requestBuilder.sendRequest(
          null,
          new RequestCallback() {
            @Override
            public void onResponseReceived(Request request, Response response) {
              try {
                JSONObject json = JSONParser.parseStrict(response.getText()).isObject();
                DatabaseObject databaseObject = ModelFactory.getDatabaseObject(json);
                DataRequiredListener.getDataRequiredListener()
                    .setRequiredData(dbId, databaseObject);
                eventBus.fireELVEvent(ELVEventType.DETAILED_VIEW_LOADED, databaseObject);
              } catch (Exception ex) {
                // ModelFactoryException, NullPointerException, IllegalArgumentException,
                // JSONException
                MessageObject msgObj =
                    new MessageObject(
                        "The received object for 'DbId="
                            + databaseObject.getDbId()
                            + "' is empty or faulty and could not be parsed.\n"
                            + "ERROR: "
                            + ex.getMessage(),
                        getClass(),
                        MessageType.INTERNAL_ERROR);
                eventBus.fireELVEvent(ELVEventType.INTERNAL_MESSAGE, msgObj);
                Console.error(getClass() + " ERROR: " + ex.getMessage());
              }
            }

            @Override
            public void onError(Request request, Throwable exception) {
              if (!GWT.isScript()) {
                Console.error(getClass() + " ERROR: " + exception.getMessage());
              }

              MessageObject msgObj =
                  new MessageObject(
                      "The request for 'DbId="
                          + databaseObject.getDbId()
                          + "' received an error instead of a valid response.\n"
                          + "ERROR: "
                          + exception.getMessage(),
                      getClass(),
                      MessageType.INTERNAL_ERROR);
              eventBus.fireELVEvent(ELVEventType.INTERNAL_MESSAGE, msgObj);
            }
          });
    } catch (RequestException ex) {
      MessageObject msgObj =
          new MessageObject(
              "The requested data for 'DbId="
                  + databaseObject.getDbId()
                  + "' could not be received.\n"
                  + "ERROR: "
                  + ex.getMessage(),
              getClass(),
              MessageType.INTERNAL_ERROR);
      eventBus.fireELVEvent(ELVEventType.INTERNAL_MESSAGE, msgObj);
      Console.error(getClass() + " ERROR: " + ex.getMessage());
    }
  }
  protected void performOperation(boolean feedback) {
    final String url = GWT.getHostPageBaseURL() + "api/version/softwareUpdates"; // $NON-NLS-1$
    RequestBuilder requestBuilder = getRequestBuilder(RequestBuilder.GET, url);
    requestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    requestBuilder.setHeader("accept", "text/plain");
    try {
      requestBuilder.sendRequest(
          null,
          new RequestCallback() {

            public void onError(Request request, Throwable exception) {
              MessageDialogBox dialogBox =
                  new MessageDialogBox(
                      Messages.getString("softwareUpdates"),
                      Messages.getString("noUpdatesAvailable"),
                      false,
                      false,
                      true); //$NON-NLS-1$ //$NON-NLS-2$
              dialogBox.center();
            }

            public void onResponseReceived(Request request, Response response) {
              Document doc = XMLParser.parse(response.getText());
              NodeList updates = doc.getElementsByTagName("update"); // $NON-NLS-1$
              if (updates.getLength() > 0) {
                FlexTable updateTable = new FlexTable();
                updateTable.setStyleName("backgroundContentTable"); // $NON-NLS-1$
                updateTable.setWidget(
                    0, 0, new Label(Messages.getString("version"))); // $NON-NLS-1$
                updateTable.setWidget(0, 1, new Label(Messages.getString("type"))); // $NON-NLS-1$
                updateTable.setWidget(0, 2, new Label(Messages.getString("os"))); // $NON-NLS-1$
                updateTable.setWidget(0, 3, new Label(Messages.getString("link"))); // $NON-NLS-1$
                updateTable
                    .getCellFormatter()
                    .setStyleName(0, 0, "backgroundContentHeaderTableCell"); // $NON-NLS-1$
                updateTable
                    .getCellFormatter()
                    .setStyleName(0, 1, "backgroundContentHeaderTableCell"); // $NON-NLS-1$
                updateTable
                    .getCellFormatter()
                    .setStyleName(0, 2, "backgroundContentHeaderTableCell"); // $NON-NLS-1$
                updateTable
                    .getCellFormatter()
                    .setStyleName(0, 3, "backgroundContentHeaderTableCellRight"); // $NON-NLS-1$

                for (int i = 0; i < updates.getLength(); i++) {
                  Element updateElement = (Element) updates.item(i);
                  String version = updateElement.getAttribute("version"); // $NON-NLS-1$
                  String type = updateElement.getAttribute("type"); // $NON-NLS-1$
                  String os = updateElement.getAttribute("os"); // $NON-NLS-1$
                  // String title = updateElement.getAttribute("title");
                  String downloadURL =
                      updateElement
                          .getElementsByTagName("downloadurl")
                          .item(0)
                          .toString(); //$NON-NLS-1$
                  downloadURL =
                      downloadURL.substring(
                          downloadURL.indexOf("http"),
                          downloadURL.indexOf("]")); // $NON-NLS-1$ //$NON-NLS-2$
                  updateTable.setWidget(i + 1, 0, new Label(version));
                  updateTable.setWidget(i + 1, 1, new Label(type));
                  updateTable.setWidget(i + 1, 2, new Label(os));
                  updateTable.setWidget(
                      i + 1,
                      3,
                      new HTML(
                          "<A HREF=\""
                              + downloadURL
                              + "\" target=\"_blank\" title=\""
                              + downloadURL
                              + "\">"
                              + Messages.getString("download")
                              + "</A>")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                                          // //$NON-NLS-5$
                  updateTable
                      .getCellFormatter()
                      .setStyleName(i + 1, 0, "backgroundContentTableCell"); // $NON-NLS-1$
                  updateTable
                      .getCellFormatter()
                      .setStyleName(i + 1, 1, "backgroundContentTableCell"); // $NON-NLS-1$
                  updateTable
                      .getCellFormatter()
                      .setStyleName(i + 1, 2, "backgroundContentTableCell"); // $NON-NLS-1$
                  updateTable
                      .getCellFormatter()
                      .setStyleName(i + 1, 3, "backgroundContentTableCellRight"); // $NON-NLS-1$
                  if (i == updates.getLength() - 1) {
                    // last
                    updateTable
                        .getCellFormatter()
                        .setStyleName(i + 1, 0, "backgroundContentTableCellBottom"); // $NON-NLS-1$
                    updateTable
                        .getCellFormatter()
                        .setStyleName(i + 1, 1, "backgroundContentTableCellBottom"); // $NON-NLS-1$
                    updateTable
                        .getCellFormatter()
                        .setStyleName(i + 1, 2, "backgroundContentTableCellBottom"); // $NON-NLS-1$
                    updateTable
                        .getCellFormatter()
                        .setStyleName(
                            i + 1, 3, "backgroundContentTableCellBottomRight"); // $NON-NLS-1$
                  }
                }
                PromptDialogBox versionPromptDialog =
                    new PromptDialogBox(
                        Messages.getString("softwareUpdateAvailable"),
                        Messages.getString("ok"),
                        null,
                        false,
                        true,
                        updateTable); //$NON-NLS-1$ //$NON-NLS-2$
                versionPromptDialog.center();
              } else {
                MessageDialogBox dialogBox =
                    new MessageDialogBox(
                        Messages.getString("softwareUpdates"),
                        Messages.getString("noUpdatesAvailable"),
                        false,
                        false,
                        true); //$NON-NLS-1$ //$NON-NLS-2$
                dialogBox.center();
              }
            }
          });
    } catch (RequestException e) {
      Window.alert(e.getMessage());
      // showError(e);
    }
  }
  @Override
  public void onResourceChosen(final String resource) {
    String url = AnalysisHelper.URL_PREFIX + "/token/" + token + "?page=1&resource=" + resource;
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url);
    requestBuilder.setHeader("Accept", "application/json");
    try {
      requestBuilder.sendRequest(
          null,
          new RequestCallback() {
            @Override
            public void onResponseReceived(Request request, Response response) {
              try {
                AnalysisResult result =
                    AnalysisModelFactory.getModelObject(AnalysisResult.class, response.getText());
                // We have to do this here because there is no name coming from the RESTFul service
                result
                    .getSummary()
                    .setSpeciesName(speciesMap.get(result.getSummary().getSpecies()));
                view.clearSelection();
                view.showResult(result, resource);
                view.selectPathway(selected);
              } catch (AnalysisModelException e) {
                MessageObject msgObj =
                    new MessageObject(
                        "The received object for '"
                            + resource
                            + "' is empty or faulty and could not be parsed.\n"
                            + "ERROR: "
                            + e.getMessage(),
                        getClass(),
                        MessageType.INTERNAL_ERROR);
                eventBus.fireELVEvent(ELVEventType.INTERNAL_MESSAGE, msgObj);
                Console.error(getClass() + " ERROR: " + e.getMessage());
                view.setInitialState();
              }
            }

            @Override
            public void onError(Request request, Throwable exception) {
              // TODO Check before commit - not yet tested
              MessageObject msgObj =
                  new MessageObject(
                      "The request for '"
                          + resource
                          + "' received an error instead of a valid response.\n"
                          + "ERROR: "
                          + exception.getMessage(),
                      getClass(),
                      MessageType.INTERNAL_ERROR);
              eventBus.fireELVEvent(ELVEventType.INTERNAL_MESSAGE, msgObj);
              Console.error(getClass() + " ERROR: " + exception.getMessage());
              view.setInitialState();
            }
          });
    } catch (RequestException ex) {
      MessageObject msgObj =
          new MessageObject(
              "The requested detailed data for '"
                  + resource
                  + "'\nin the Analysis could not be received.\n"
                  + "ERROR: "
                  + ex.getMessage(),
              getClass(),
              MessageType.INTERNAL_ERROR);
      eventBus.fireELVEvent(ELVEventType.INTERNAL_MESSAGE, msgObj);
      Console.error(getClass() + " ERROR: " + ex.getMessage());
      view.setInitialState();
    }
  }