/**
   * Loads a name usage and its checklist by the id parameter.
   *
   * @throws NotFoundException if no usage for the given id can be found
   */
  public void loadUsage() {
    if (id == null) {
      throw new NotFoundException("No checklist usage id given");
    }
    NameUsage u = usageService.get(id, getLocale());
    if (u == null) {
      throw new NotFoundException("No usage found with id " + id);
    }
    usage = new NameUsageContainer(u);
    // load checklist
    dataset = datasetService.get(usage.getDatasetKey());
    if (dataset == null) {
      throw new ReferentialIntegrityException(
          NameUsage.class, id, "Missing dataset " + usage.getDatasetKey());
    }

    try {
      metrics = metricsService.get(usage.getDatasetKey());
    } catch (ServiceUnavailableException e) {
      LOG.error("Failed to load checklist metrics for dataset {}", usage.getDatasetKey());
    }

    try {
      numOccurrences =
          occurrenceCubeService.get(new ReadBuilder().at(OccurrenceCube.NUB_KEY, usage.getKey()));
      numGeoreferencedOccurrences =
          occurrenceCubeService.get(
              new ReadBuilder()
                  .at(OccurrenceCube.NUB_KEY, usage.getKey())
                  .at(OccurrenceCube.IS_GEOREFERENCED, true));
    } catch (ServiceUnavailableException e) {
      LOG.error("Failed to load occurrence metrics for usage {}", usage.getKey(), e);
    }
  }
Beispiel #2
0
  @Override
  public String execute() {
    super.execute();
    // replace organisation keys with real names
    lookupFacetTitles(DatasetSearchParameter.HOSTING_ORG, getOrgTitle);
    lookupFacetTitles(DatasetSearchParameter.OWNING_ORG, getOrgTitle);
    lookupFacetTitles(DatasetSearchParameter.TYPE, getDatasetTypeTitle);
    lookupFacetTitles(DatasetSearchParameter.PUBLISHING_COUNTRY, getCountryTitle);

    // populate counts
    for (DatasetSearchResult dsr : getSearchResponse().getResults()) {
      if (DatasetType.OCCURRENCE == dsr.getType()) {
        Long count =
            occurrenceCube.get(new ReadBuilder().at(OccurrenceCube.DATASET_KEY, dsr.getKey()));
        recordCounts.put(dsr.getKey(), count);
      } else if (DatasetType.CHECKLIST == dsr.getType()) {
        // Client response status 204 (Equal to no content) gets converted into NULL
        // See HttpErrorResponseInterceptor.java in gbif-common-ws for more information
        DatasetMetrics metrics = checklistMetricsService.get(dsr.getKey());
        if (metrics != null) {
          recordCounts.put(dsr.getKey(), Long.valueOf(metrics.getUsagesCount()));
        }
      }
    }

    return SUCCESS;
  }