@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.POST)
  public ModelAndView bulkUpload(HttpSession session, BulkUploadForm bulkUploadForm, Errors err) {

    MultipartFile file = null;
    ModelAndView mav = new ModelAndView();

    file = bulkUploadForm.getFile();

    validatorBulkUpload.validate(bulkUploadForm, err);
    if (err.hasErrors()) {
      return mav;
    }

    String error = null;

    if (file.isEmpty()) {

      logger.error("Escriba una ruta valida!");
      error = "Error. El archivo esta vacio.";
      mav.addObject("error", error);
      return mav;
    }

    int count = 0;

    /*
     * Titulo, Licencia, Tags (Separadas con ;),Calidad de la inforamci�n,
     * Modificado, Granularidad Geografica, Granularidad Temporal,
     * Publicante, URL de Acceso, Tamaño, Formato, Tipo de Distribucion,
     * locacion, descripcion
     */

    try {
      InputStream inputStream = file.getInputStream();
      BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));

      String line;

      while ((line = bufferedReader.readLine()) != null) {
        if (line.isEmpty() || line.startsWith("#")) {
          continue; // es comentario o line en blanco
        }

        String[] attrs = line.split(";");

        if (attrs.length < 12) {
          throw new Exception("Linea " + (count + 1) + " mal formada.");
        }
        /* Titulo */
        String title = attrs[0].trim();

        /* Licence */
        String license = attrs[1].trim();

        /* Tags */
        Set<String> tags = new HashSet<String>();
        String[] items = attrs[2].split(",");
        int cantTags = 0;
        logger.debug(items.length);
        while (cantTags < items.length) {
          tags.add(items[cantTags].trim());
          cantTags++;
        }

        /* Quality of the Information */
        String qualityOfInformation = attrs[3].trim();
        if (!(qualityOfInformation.equals("Baja")
            || qualityOfInformation.equals("Media")
            || qualityOfInformation.equals("Alta"))) {
          throw new Exception(
              "Linea " + (count + 1) + " mal formada, calidad de informacion invalida");
        }

        /* Modify */
        String[] sels = attrs[4].split("-");

        if (sels.length < 3) {
          throw new Exception("Fecha invalidad en la linea " + (count + 1));
        }

        String yearModify = sels[0];
        String monthModify = sels[1];
        String dayModify = sels[2];

        dayModify = dayModify.length() == 1 ? "0" + dayModify : dayModify;
        monthModify = monthModify.length() == 1 ? "0" + monthModify : monthModify;

        /*
         * Date fechaModificado = Date.valueOf(anioModificado + "-" +
         * mesModificado + "-" + diaModificado);
         */
        // String fechaModificado = diaModificado + "-" + mesModificado
        // + "-" + anioModificado;
        String dateModify = yearModify + "-" + monthModify + "-" + dayModify + "T23:59:59Z";
        // String fechaModificado = "1995-12-31T23:59:59Z";
        /* Granularidad Geografica */
        String granuGeogra = attrs[5].trim();

        /* Granularidad Temporal */
        String granuTemporal = attrs[6].trim();

        /* Publicante */
        String publicante = attrs[7].trim();
        Organization miPublicante = new Organization();
        miPublicante.setName(publicante);
        miPublicante.setNameId(Parsing.withoutSpecialCharacters(publicante));

        /* URL de Acceso */
        String url = attrs[8].trim();

        /* Tamaño */
        String tamanio = attrs[9].trim();

        /* Formato */
        String formato = attrs[10].trim();

        /* Tipo de Distribucion */
        Distribution distribution;

        String tipoDistribucion = attrs[11].trim();
        if (tipoDistribucion.equals("Feed")) {
          distribution = new Feed();
        } else if (tipoDistribucion.equals("Download")) {
          distribution = new Download();
        } else if (tipoDistribucion.equals("Web Service")) {
          distribution = new WebService();
        } else {
          throw new Exception("Linea " + (count + 1) + " mal formada, tipo informacion invalida");
        }
        distribution.setAccessURL(url);
        distribution.setFormat(formato);
        distribution.setSize(new Integer(tamanio));

        /* Locacion */
        String location = attrs[12].trim();
        if (location.equals("")) {
          location = "Desconocida";
        }

        /* Descripcion */
        String description = "";
        for (int i = 13; i < attrs.length; i++) {
          description = description + attrs[i];
          if (i != attrs.length - 1) {
            description = description + "; ";
          }
        }

        Dataset aDataset =
            new Dataset(
                title,
                description,
                license,
                tags,
                qualityOfInformation,
                dateModify,
                granuGeogra,
                granuTemporal,
                location,
                miPublicante,
                distribution,
                Parsing.withoutSpecialCharacters(title));

        if (!datasetService.existApprovedDataset(title)) {
          datasetService.store(aDataset);
          count++;
        }
      }
    } catch (Exception a) {
      logger.error("Error en la carga masiva.");
      logger.error(a.getMessage(), a);
      error = a.getMessage();
      count = 0;
      mav.addObject("error", error);
    }

    if (count > 0) {
      mav.addObject("info", "Agrego " + count + " dataset's exitosamente.");
    }

    if (count == 0) {
      mav.addObject("info", "No había datasets nuevos para agregar.");
    }
    return mav;
  }