Exemplo n.º 1
0
  public DetailsPresenter(EventBus eventBus, DetailsView detailsView) {
    super(eventBus);
    this.view = detailsView;
    this.diagram = null;
    this.databaseObject = null;
    this.tabsPresenter = TabsFactory.getDetailsTabs(eventBus);

    this.view.setPresenter(this);

    // Needed because the view implementation will be listening to all the OverviewPanels for
    // required data
    DataRequiredListener.getDataRequiredListener().setDataRequiredHandler(this);

    // Needed because the view implementation will be listening to all the DetailsPanel for instance
    // selected
    InstanceSelectedListener.getInstanceSelectedListener().setInstanceSelectedHandler(this);
  }
Exemplo n.º 2
0
  @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>());
    }
  }
Exemplo n.º 3
0
  @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);
    }
  }