Пример #1
0
  @RequestMapping(method = RequestMethod.GET, value = "/obtenerFichero/{id}/{tipo}")
  public ResponseEntity<EncapsuladorFileSW> obtenerFichero(
      @PathVariable("id") Long id, @PathVariable("tipo") String tipo, HttpServletRequest request) {
    String path;
    String caracterSeparador = getServicioConfiguracionGeneral().getCaracterSeparadorCSV();
    FuenteDto fuenteDto = gestorCUFuente.carga(id);
    String fich = "";
    if (tipo.equals(TiposFuente.CSV.getId())) {
      path = getServicioConfiguracionGeneral().getPathCsv();
      fich = fuenteDto.getFich_csv_gml();
    } else if (tipo.equals(TiposFuente.GML.getId())) {
      path = getServicioConfiguracionGeneral().getPathGml();
      fich = fuenteDto.getFich_csv_gml();
    } else if (tipo.equals(TiposFuente.SHAPEFILE.getId())) {
      path = getServicioConfiguracionGeneral().getPathShapefile();
      fich = fuenteDto.getFich_shp();
    } else {
      path = null;
      fich = "";
    }

    String realPath = getPathRealAplicacion(request, path);

    RandomAccessFile f = null;
    try {
      File file = new File(realPath + fuenteDto.getId() + "/" + fich);

      f = new RandomAccessFile(file, "r");
      byte[] contenido = new byte[(int) f.length()];
      f.read(contenido);

      EncapsuladorFileSW encapsuladorFich = new EncapsuladorFileSW();
      encapsuladorFich.setFich(contenido);
      encapsuladorFich.setNombre(fich);
      ResponseEntity<EncapsuladorFileSW> respuesta =
          new ResponseEntity<EncapsuladorFileSW>(encapsuladorFich, HttpStatus.OK);
      return respuesta;
    } catch (FileNotFoundException e) {
      log.error("Fichero: " + fich + " no encontrado para descarga");
      return new ResponseEntity<EncapsuladorFileSW>(new EncapsuladorFileSW(), HttpStatus.OK);
    } catch (Exception e) {
      log.error("Se ha producido un error al acceder al fichero: " + fich);
      return new ResponseEntity<EncapsuladorFileSW>(new EncapsuladorFileSW(), HttpStatus.OK);
    } finally {
      try {
        if (f != null) f.close();
      } catch (IOException e) {
        log.error("No se pudo cerrar la conexion con el fichero");
      }
    }
  }
Пример #2
0
  @RequestMapping(method = RequestMethod.GET, value = "/fuenteCatalogo")
  public ResponseEntity<FuenteDto> cargaFuenteCatalogo() {
    FuenteDto fuenteCatalogo;
    FuenteDto fuenteDto = new FuenteDto();
    fuenteDto.setEsCatalogoInterno((short) 1);
    Date data;
    String strData;
    try {

      strData = getServicioConfiguracionGeneral().getCatalogoData();
      data = UtilFecha.multiParse(strData);
      fuenteDto.setFechaRegistro(data);
      fuenteDto.setNombre(getServicioConfiguracionGeneral().getCatalogoNome());
      fuenteDto.setInfoConexion(getServicioConfiguracionGeneral().getCatalogoUrl());
      fuenteDto.setPassword(getServicioConfiguracionGeneral().getCatalogoPass());
      fuenteDto.setUsuario(getServicioConfiguracionGeneral().getCatalogoUser());
      fuenteDto.setId(0);
    } catch (Exception e) {
      log.error("Error excetion ERROR_PARAM_CONFIG ");
      fuenteDto.setNombre(ERROR_PARAM_CONFIG);
    }
    return new ResponseEntity<FuenteDto>(fuenteDto, responseHeaders, HttpStatus.OK);
  }
Пример #3
0
  @RequestMapping(method = RequestMethod.GET, value = "/cargaFuenteInterna/{idUsuarioCreador}")
  public ResponseEntity<FuenteDto> CargaCatalogo(
      @PathVariable("idUsuarioCreador") Long idUsuarioCreador) {

    FuenteDto fuenteCatalogo;
    FuenteDto fuenteDto = new FuenteDto();
    fuenteDto.setEsCatalogoInterno((short) 1);
    Date data;
    String strData;
    try {

      strData = getServicioConfiguracionGeneral().getCatalogoData();
      data = UtilFecha.multiParse(strData);
      fuenteDto.setFechaRegistro(data);
      fuenteDto.setNombre(getServicioConfiguracionGeneral().getCatalogoNome());
      fuenteDto.setInfoConexion(getServicioConfiguracionGeneral().getCatalogoUrl());
      fuenteDto.setPassword(getServicioConfiguracionGeneral().getCatalogoPass());
      fuenteDto.setUsuario(getServicioConfiguracionGeneral().getCatalogoUser());
      fuenteDto.setId(0);
    } catch (Exception e) {
      log.error("Error excetion ERROR_PARAM_CONFIG ");
      fuenteDto.setNombre(ERROR_PARAM_CONFIG);
      return new ResponseEntity<FuenteDto>(fuenteDto, responseHeaders, HttpStatus.OK);
    }

    try {

      if (fuenteDto.getNombre().isEmpty()
          || fuenteDto.getInfoConexion().isEmpty()
          || data == null) {
        log.error("Error parametros vacions " + ERROR_PARAM_CONFIG + strData);
        fuenteDto.setNombre(ERROR_PARAM_CONFIG);
        return new ResponseEntity<FuenteDto>(fuenteDto, responseHeaders, HttpStatus.OK);
      } else {
        // comprobamos si existe la fuente con los datos del fichero de
        // configuración despliegue.properties en BD
        fuenteCatalogo = gestorCUFuente.existeFuenteCatalogo(fuenteDto);

        // sino existe la fuente la insertamos en la DB
        if (fuenteCatalogo == null || fuenteCatalogo.getId() == 0) {
          fuenteCatalogo = gestorCUFuente.gardaFuenteCatalogo(fuenteDto, idUsuarioCreador);
        }
      }
    } catch (Exception e) {
      log.error("Error segunda exception fuente vacia");
      return new ResponseEntity<FuenteDto>(new FuenteDto(), responseHeaders, HttpStatus.OK);
    }
    log.debug("EXITO al cargar la fuente: " + fuenteCatalogo.getNombre());
    return new ResponseEntity<FuenteDto>(fuenteCatalogo, responseHeaders, HttpStatus.OK);
  }