コード例 #1
0
  @Override
  public void annotate(
      final IBioPortalTextminingRequestCompleted completionCallback,
      String source,
      String textContent,
      String include,
      String exclude)
      throws IllegalArgumentException {
    String url =
        GWT.getModuleBaseURL()
            + "nif/annotate?format=json&content="
            + URL.encode(textContent)
            + "&url="
            + source
            + "&categoriesIn="
            + include
            + "&categoriesOut="
            + exclude;
    if (!_application.isHostedMode())
      url =
          ApplicationUtils.getUrlBase(GWT.getModuleBaseURL())
              + "nif/annotate?format=json&content="
              + URL.encode(textContent)
              + "&url="
              + source
              + "&categoriesIn="
              + include
              + "&categoriesOut="
              + exclude;

    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
    builder.setTimeoutMillis(10000);
    try {
      Request request =
          builder.sendRequest(
              null,
              new RequestCallback() {
                public void onError(Request request, Throwable exception) {
                  if (exception instanceof RequestTimeoutException) {
                    _application
                        .getLogger()
                        .exception(
                            this,
                            "Couldn't reach NIF annotator (timeout) " + exception.getMessage());
                    completionCallback.textMiningNotCompleted("Timeout");
                  } else {
                    _application
                        .getLogger()
                        .exception(this, "Couldn't retrieve NIF annotator JSON");
                    completionCallback.textMiningNotCompleted();
                  }
                }

                public void onResponseReceived(Request request, Response response) {
                  if (200 == response.getStatusCode()) {
                    JsAnnotationSet set = (JsAnnotationSet) parseJson(response.getText());
                    completionCallback.returnTextminingResults(set);
                  } else if (503 == response.getStatusCode()) {
                    _application.getLogger().exception(this, "503: " + response.getText());
                    completionCallback.textMiningNotCompleted("Couldn't run Nif Annotator (503)");
                  } else {
                    _application
                        .getLogger()
                        .exception(this, response.getStatusCode() + ": " + response.getText());
                    completionCallback.textMiningNotCompleted(
                        "Couldn't run Nif Annotator " + response.getStatusCode());
                  }
                }
              });
    } catch (RequestException e) {
      _application.getLogger().exception(this, "Couldn't retrieve NIF annotator JSON");
      completionCallback.textMiningNotCompleted();
    }
  }
コード例 #2
0
  @Override
  public void searchData(
      final INifDataRequestCompleted completionCallback,
      String textQuery,
      String type,
      String vendor,
      String resource,
      int pageNumber,
      int pageSize)
      throws IllegalArgumentException {

    if (resource.equals("nif-0000-07730-1")) {

      String url =
          GWT.getModuleBaseURL()
              + "nif/data?format=json&resource="
              + resource
              + "&query="
              + URL.encode(textQuery)
              + "&type="
              + URL.encode(type)
              + "&vendor="
              + URL.encode(vendor);
      if (!_application.isHostedMode())
        url =
            ApplicationUtils.getUrlBase(GWT.getModuleBaseURL())
                + "nif/data?format=json&resource="
                + resource
                + "&query="
                + URL.encode(textQuery)
                + "&type="
                + URL.encode(type)
                + "&vendor="
                + URL.encode(vendor);
      RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
      builder.setTimeoutMillis(10000);
      _application.getLogger().debug(this, "Search Data with url" + url);
      try {
        Request request =
            builder.sendRequest(
                null,
                new RequestCallback() {
                  public void onError(Request request, Throwable exception) {
                    if (exception instanceof RequestTimeoutException) {
                      _application
                          .getLogger()
                          .exception(
                              this,
                              "Couldn't reach NIF data search (timeout) " + exception.getMessage());
                      completionCallback.reportException("Timeout");
                    } else {
                      _application
                          .getLogger()
                          .exception(
                              this, "Couldn't retrieve NIF data JSON " + exception.getMessage());
                      completionCallback.reportException();
                    }
                  }

                  public void onResponseReceived(Request request, Response response) {
                    if (200 == response.getStatusCode()) {
                      ArrayList<MGenericResource> data = new ArrayList<MGenericResource>();
                      JsoNifDataSearchResultsWrapper results =
                          (JsoNifDataSearchResultsWrapper) parseJson(response.getText());
                      JsArray<JsoNifDataEntry> res = results.getResults();
                      for (int i = 0; i < res.length(); i++) {
                        JsoNifDataEntry entry = res.get(i);

                        MGenericResource source =
                            ResourcesFactory.createGenericResource(
                                entry.getSourceUri(), entry.getSourceLabel());
                        MGenericResource normalizedResource =
                            _application.getResourcesManager().cacheResource(source);
                        if (source == normalizedResource)
                          _application
                              .getLogger()
                              .debug(
                                  this,
                                  "Resource cache size (after insert): "
                                      + _application.getResourcesManager().getResourceCacheSize());

                        MAntibody antibody =
                            new MAntibody(entry.getUri(), entry.getLabel(), normalizedResource);
                        antibody.setCloneId(entry.getCloneId());
                        antibody.setVendor(entry.getVendor());
                        antibody.setOrganism(entry.getOrganism());
                        antibody.setType(entry.getType());
                        antibody.setCatalog(entry.getCatalog());
                        // antibody.setSource(normalizedResource);
                        data.add(antibody);
                      }
                      _application
                          .getLogger()
                          .debug(this, "Number NIF Data results: " + data.size());
                      completionCallback.returnData(data);
                    } else if (503 == response.getStatusCode()) {
                      _application.getLogger().exception(this, "503: " + response.getText());
                      completionCallback.reportException("Couldn't run Nif data search (503)");
                    } else {
                      _application
                          .getLogger()
                          .exception(this, response.getStatusCode() + ": " + response.getText());
                      completionCallback.reportException(
                          "Couldn't run Nif data search " + response.getStatusCode());
                    }
                  }
                });
      } catch (RequestException e) {
        _application.getLogger().exception(this, "Couldn't retrieve NIF data JSON");
        completionCallback.reportException();
      }
    } else if (resource.equals("nlx_144509-1") || resource.equals("nif-0000-08137-1")) {
      String url =
          GWT.getModuleBaseURL()
              + "nif/data?format=json&resource="
              + resource
              + "&query="
              + URL.encode(textQuery)
              + "&type="
              + URL.encode(type);
      if (!_application.isHostedMode())
        url =
            ApplicationUtils.getUrlBase(GWT.getModuleBaseURL())
                + "nif/data?format=json&resource="
                + resource
                + "&query="
                + URL.encode(textQuery)
                + "&type="
                + URL.encode(type);
      RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
      builder.setTimeoutMillis(10000);
      _application.getLogger().debug(this, "Search NIF resources with url" + url);
      try {
        Request request =
            builder.sendRequest(
                null,
                new RequestCallback() {
                  public void onError(Request request, Throwable exception) {
                    if (exception instanceof RequestTimeoutException) {
                      _application
                          .getLogger()
                          .exception(
                              this,
                              "Couldn't reach NIF resources search (timeout) "
                                  + exception.getMessage());
                      completionCallback.reportException("Timeout");
                    } else {
                      _application
                          .getLogger()
                          .exception(
                              this,
                              "Couldn't retrieve NIF resources JSON " + exception.getMessage());
                      completionCallback.reportException();
                    }
                  }

                  public void onResponseReceived(Request request, Response response) {
                    if (200 == response.getStatusCode()) {
                      ArrayList<MGenericResource> data = new ArrayList<MGenericResource>();
                      JsoNifDataSearchResultsWrapper results =
                          (JsoNifDataSearchResultsWrapper) parseJson(response.getText());
                      JsArray<JsoNifDataEntry> res = results.getResults();
                      for (int i = 0; i < res.length(); i++) {
                        JsoNifDataEntry entry = res.get(i);

                        MGenericResource source =
                            ResourcesFactory.createGenericResource(
                                entry.getSourceUri(), entry.getSourceLabel());
                        _application
                            .getLogger()
                            .debug(
                                this,
                                "Resource cache size: "
                                    + _application.getResourcesManager().getResourceCacheSize());
                        MGenericResource normalizedResource =
                            _application.getResourcesManager().cacheResource(source);
                        _application
                            .getLogger()
                            .debug(
                                this,
                                "Resource cache size: "
                                    + _application.getResourcesManager().getResourceCacheSize());

                        MLinkedResource resource =
                            new MLinkedResource(
                                entry.getUri(), entry.getLabel(), entry.getDescription());
                        resource.setSource(normalizedResource);
                        data.add(resource);
                      }
                      _application
                          .getLogger()
                          .debug(this, "Number NIF resources results: " + data.size());
                      completionCallback.returnData(data);
                    } else if (503 == response.getStatusCode()) {
                      _application.getLogger().exception(this, "503: " + response.getText());
                      completionCallback.reportException("Couldn't run Nif resources search (503)");
                    } else {
                      _application
                          .getLogger()
                          .exception(this, response.getStatusCode() + ": " + response.getText());
                      completionCallback.reportException(
                          "Couldn't run Nif resources search " + response.getStatusCode());
                    }
                  }
                });
      } catch (RequestException e) {
        _application.getLogger().exception(this, "Couldn't retrieve NIF resources JSON");
        completionCallback.reportException();
      }
    }
  }