コード例 #1
0
  @Test
  public void datasetStoreTest() {
    try {

      Dataset dataset = DatasetTestFactory.getDataset();
      datasetService.store(dataset);
      Dataset theDataset = datasetService.getApprovedDatasetByName(dataset.getTitleId());

      Assert.assertTrue(dataset.getTitle().equals(theDataset.getTitle()));
      Assert.assertTrue(dataset.getTitleId().equals(theDataset.getTitleId()));
      Assert.assertTrue(dataset.getLicense().equals(theDataset.getLicense()));
      Assert.assertTrue(dataset.getAccessURL().equals(theDataset.getAccessURL()));
      Assert.assertTrue(dataset.getDataQuality().equals(theDataset.getDataQuality()));
      Assert.assertTrue(dataset.getLocation().equals(theDataset.getLocation()));
      Assert.assertTrue(dataset.getModified().equals(theDataset.getModified()));
      Assert.assertTrue(dataset.getDescription().equals(theDataset.getDescription()));
      Assert.assertTrue(dataset.getSpatial().equals(theDataset.getSpatial()));
      Assert.assertTrue(dataset.getTemporal().equals(theDataset.getTemporal()));
      Assert.assertTrue(dataset.getFormat().equals(theDataset.getFormat()));
      Assert.assertTrue(dataset.getPublisherName().equals(theDataset.getPublisherName()));

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #2
0
  @RequestMapping(method = RequestMethod.GET)
  public void exportDatasets(HttpServletRequest request, HttpServletResponse response) {

    response.setContentType("application/octet-stream");

    Iterable<Dataset> listDataset = this.datasetService.getAllApprovedDatasets();

    String text = "";
    for (Dataset d : listDataset) {
      String line = "";
      line = d.getTitle() + ";";
      line += d.getLicense() + ";";
      Set<String> myTags = d.getKeyword();
      for (String s : myTags) {
        line += s + ",";
      }
      line = line.substring(0, line.length() - 1);
      line += ";";
      line += d.getDataQuality() + ";";
      line += d.getModified().substring(0, 10) + ";";
      line += d.getSpatial() + ";";
      line += d.getTemporal() + ";";
      line += d.getPublisherName() + ";";
      line += d.getAccessURL() + ";";
      line += d.getSize() + ";";
      line += d.getFormat() + ";";
      if (d.getDistribution() instanceof Feed) {
        line += "Feed,";
      } else if (d.getDistribution() instanceof WebService) {
        line += "Web Service;";
      } else {
        line += "Download;";
      }
      line += d.getLocation() + ";";
      line += d.getDescription();
      line += "\n";
      text += line;
    }
    response.setHeader("Content-Disposition", "attachment; filename=\"Datasets.csv");
    response.setContentLength(text.length());

    ServletOutputStream out = null;
    try {
      out = response.getOutputStream();
      out.write(text.getBytes());
    } catch (IOException e) {
      logger.error(e.getMessage());
      logger.error(e.getStackTrace());
    }
  }