Beispiel #1
1
  /**
   * Search datasets containg param text in the metadata
   *
   * @param query The query object
   * @param limit maximum results to return
   * @param offset search begins from offset
   * @throws JackanException on error
   */
  public synchronized SearchResults<CkanDataset> searchDatasets(
      CkanQuery query, int limit, int offset) {

    StringBuilder params = new StringBuilder();

    params.append("rows=").append(limit).append("&start=").append(offset);

    if (query.getText().length() > 0) {
      params.append("&q=");
      params.append(urlEncode(query.getText()));
    }

    StringBuilder fq = new StringBuilder();
    String fqPrefix = "";

    fqPrefix = appendNamesList(fqPrefix, "groups", query.getGroupNames(), fq);
    fqPrefix = appendNamesList(fqPrefix, "organization", query.getOrganizationNames(), fq);
    fqPrefix = appendNamesList(fqPrefix, "tags", query.getTagNames(), fq);
    fqPrefix = appendNamesList(fqPrefix, "license_id", query.getLicenseIds(), fq);

    if (fq.length() > 0) {
      params.append("&fq=").append(urlEncode(fq.insert(0, "(").append(")").toString()));
    }

    DatasetSearchResponse dsr;
    dsr = getHttp(DatasetSearchResponse.class, "/api/3/action/package_search?" + params.toString());

    if (dsr.success) {
      for (CkanDataset ds : dsr.result.getResults()) {
        for (CkanResource cr : ds.getResources()) {
          cr.setPackageId(ds.getId());
        }
      }
    }

    return dsr.result;
  }
Beispiel #2
0
 /**
  * @param idOrName either the dataset name (i.e. laghi-monitorati-trento) or the the
  *     alphanumerical id (i.e. 96b8aae4e211f3e5a70cdbcbb722264256ae2e7d)
  * @throws JackanException on error
  */
 public synchronized CkanDataset getDataset(String idOrName) {
   CkanDataset cd =
       getHttp(DatasetResponse.class, "/api/3/action/package_show", "id", idOrName).result;
   for (CkanResource cr : cd.getResources()) {
     cr.setPackageId(cd.getId());
   }
   return cd;
 }
Beispiel #3
0
  /**
   * Creates CkanDataset on the server
   *
   * @param dataset data set with a given parameters
   * @return the newly created dataset
   * @throws JackanException
   */
  public synchronized CkanDataset createDataset(CkanDataset dataset) {

    logger.warning("TODO 0.4 CREATION OF FULL DATASETS IS EXPERIMENTAL!");

    checkNotNull(dataset);

    if (ckanToken == null) {
      throw new JackanException(
          "Tried to create dataset" + dataset.getName() + ", but ckan token was not set!");
    }

    ObjectMapper objectMapper = CkanClient.getObjectMapper();
    String json = null;
    try {
      json = objectMapper.writeValueAsString(dataset);
    } catch (IOException e) {
      throw new JackanException("Couldn't serialize the provided CkanDatasetMinimized!", this, e);
    }
    DatasetResponse datasetresponse =
        postHttp(
            DatasetResponse.class,
            "/api/3/action/package_create",
            json,
            ContentType.APPLICATION_JSON);
    return datasetresponse.result;
  }