Example #1
0
 public boolean contains(Event event) {
   for (Event aux : this.path) {
     if (aux.equals(event)) {
       return true;
     }
   }
   return false;
 }
  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
    }
  }
  @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());
    }
  }