@RequestMapping(method = RequestMethod.GET)
  public ModelAndView view(@RequestParam String qName, HttpSession session) {
    ModelAndView mav = new ModelAndView();
    mav.addObject("mainURL", properties.getMainURL());

    Dataset retrievedDataset = this.datasetService.getApprovedDatasetByQName(qName);

    if (retrievedDataset == null) {
      logger.info("El dataset no existe");
      mav.setViewName("redirect:/bin/dataset/error");
      return mav;
    }

    String format = null;
    if (retrievedDataset.getDistribution() != null
        && retrievedDataset.getDistribution().getFormat() != null) {
      format = retrievedDataset.getDistribution().getFormat().toLowerCase();
    }

    DatasetViewDTO dview;
    /*
     * Microsoft Office: doc, docx, xls, xlsx, ppt, pptx, pps; OpenDocument:
     * odt, ods, odp; OpenOffice:sxw, sxc, sxi; Other Formats: wpd, pdf,
     * rtf, txt, html, csv, tsv
     */
    if (format != null
        && (format.endsWith("doc")
            || format.endsWith("docx")
            || format.endsWith("xls")
            || format.endsWith("xlsx")
            || format.endsWith("ppt")
            || format.endsWith("pptx")
            || format.endsWith("pps")
            || format.endsWith("odt")
            || format.endsWith("ods")
            || format.endsWith("odp")
            || format.endsWith("swx")
            || format.endsWith("sxi")
            || format.endsWith("wpd")
            || format.endsWith("pdf")
            || format.endsWith("rtf")
            || format.endsWith("txt")
            || format.endsWith("csv")
            || format.endsWith("tsv"))) {
      dview = new DatasetViewDTO(retrievedDataset, true);
    } else {
      dview = new DatasetViewDTO(retrievedDataset, false);
    }

    mav.addObject("dto", dview);
    String theDate = "";
    /* Se pasa la fecha a un formato entendible por el usuario final */
    String correctDate = dview.getDataset().getModified();
    Scanner scanner = new Scanner(correctDate);
    scanner.useDelimiter("T");
    if (scanner.hasNext()) {
      theDate = scanner.next();
      Scanner scannerDate = new Scanner(theDate);
      scannerDate.useDelimiter("-");
      String year = scannerDate.next();
      String month = scannerDate.next();
      String day = scannerDate.next();
      theDate = year + "-" + month + "-" + day;
    } else {
      logger.error("No se pudo obtener la fecha de la última modificación.");
    }
    mav.addObject("datasetDate", theDate);

    ArgendataUser user = (ArgendataUser) session.getAttribute("user");
    if (user != null && user.isAdmin()) {
      mav.addObject("admin", true);
    } else {
      mav.addObject("admin", false);
    }

    if (user != null) {
      mav.addObject("logged", true);
    } else {
      mav.addObject("logged", false);
    }

    return mav;
  }
  @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();
    }
  }
  @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());
    }
  }