예제 #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 = "/fuente/{id}")
 public ResponseEntity<FuenteDto> cargaPorId(@PathVariable("id") Long id) {
   return new ResponseEntity<FuenteDto>(gestorCUFuente.carga(id), responseHeaders, HttpStatus.OK);
 }