@RequestMapping(method = RequestMethod.POST)
  public ModelAndView add(DatasetForm datasetEntryForm, Errors errors, HttpSession session) {
    ModelAndView mav = new ModelAndView();

    validatorDataEntry.validate(datasetEntryForm, errors);
    if (errors.hasErrors()) {
      logger.error("Errores en la validacion del formulario");
      mav.addObject("privateKey", properties.getReCaptchaPrivateKey());
      mav.addObject("publicKey", properties.getReCaptchaPublicKey());
      mav.setViewName("dataset/add");
      return mav;
    }

    PreDataset aDataset = datasetEntryForm.build();

    // the resource's length will be calculated later on a separate thread.
    aDataset.setSize(0);

    ArgendataUser user = (ArgendataUser) session.getAttribute("user");

    if (!aDataset.getDistribution().equals("Download")) {
      aDataset.setFormat("");
      aDataset.setSize(0);
    }

    if (!user.isAdmin()) {
      try {
        aDataset.setSize(getResourceLength(aDataset));
        datasetService.store(aDataset);
      } catch (Exception e) {
        logger.error("No se pudo agregar el dataset al store relacional");
        logger.error(e.getMessage(), e);
        mav.setViewName("redirect:../static/error");
        return mav;
      }

      mav.setViewName("redirect:../user/home?state=1");
    } else {
      Dataset readyDataset = aDataset.toNoRelationalDataset();

      try {
        datasetService.store(readyDataset);
      } catch (Exception e) {
        logger.error("No se pudo agregar el dataset al store semántico");
        logger.error(e.getMessage(), e);
        mav.setViewName("redirect:../static/error");

        return mav;
      }

      mav.setViewName("redirect:../search/searchDataHome");
    }

    asyncResourceLength(aDataset, user.isAdmin());

    return mav;
  }
  @RequestMapping(method = RequestMethod.GET)
  public ModelAndView add(HttpSession session) {
    ModelAndView mav = new ModelAndView();

    ArgendataUser user = (ArgendataUser) session.getAttribute("user");

    DatasetForm dForm = new DatasetForm();

    dForm.setUsername(user.getUsername());

    mav.addObject("privateKey", properties.getReCaptchaPrivateKey());
    mav.addObject("publicKey", properties.getReCaptchaPublicKey());

    mav.addObject(dForm);

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