|
|
@@ -11,6 +11,7 @@ import java.net.URI;
|
|
|
import java.net.http.HttpClient;
|
|
|
import java.net.http.HttpRequest;
|
|
|
import java.net.http.HttpResponse;
|
|
|
+import java.nio.file.Files;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
@@ -26,13 +27,12 @@ import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
-import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.ui.Model;
|
|
|
+import org.springframework.util.FileCopyUtils;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
-import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
@@ -64,6 +64,7 @@ import fr.opensagres.xdocreport.document.registry.XDocReportRegistry;
|
|
|
import fr.opensagres.xdocreport.template.IContext;
|
|
|
import fr.opensagres.xdocreport.template.TemplateEngineKind;
|
|
|
import fr.opensagres.xdocreport.template.formatter.FieldsMetadata;
|
|
|
+import groovyjarjarantlr4.v4.parse.ANTLRParser.exceptionGroup_return;
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
@@ -99,25 +100,34 @@ public class DownloadController {
|
|
|
*/
|
|
|
@GetMapping(value="/download/{fileName}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
|
|
|
@ResponseBody
|
|
|
- public ResponseEntity<FileSystemResource> download(Model model, @PathVariable("fileName") BigInteger idInstanciaTasca, HttpServletResponse response) throws FileNotFoundException {
|
|
|
- InstanciaTascaDTO i = findByIdTasca(idInstanciaTasca);
|
|
|
- FileSystemResource r = null;
|
|
|
- if(i.getTasca().getTipus() == 22){
|
|
|
- r = new FileSystemResource(i.getEvidencia());
|
|
|
- String extension = "."+FilenameUtils.getExtension(i.getEvidencia());
|
|
|
- String name = "-"+i.getTasca().getNomEvidenciaCas().replace(" ", "_");
|
|
|
- response.setHeader("Content-Disposition", "attachment; filename="+i.getTasca().getCodiEvidencia()+name+extension);
|
|
|
- }
|
|
|
- else{
|
|
|
- r = new FileSystemResource(this.filePath+i.getEvidencia());
|
|
|
- response.setHeader("Content-Disposition", "attachment; filename="+i.getTasca().getCodiEvidencia()+"_"+i.getEvidencia());
|
|
|
- }
|
|
|
+ public byte[] download(@PathVariable("fileName") BigInteger idInstanciaTasca, HttpServletResponse response) throws FileNotFoundException {
|
|
|
|
|
|
- if (!r.exists()) {
|
|
|
- return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
|
|
|
+ try {
|
|
|
+ InstanciaTascaDTO i = findByIdTasca(idInstanciaTasca);
|
|
|
+ FileSystemResource file = null;
|
|
|
+ if(i.getTasca().getTipus() == 22){
|
|
|
+ file = new FileSystemResource(i.getEvidencia());
|
|
|
+ String extension = "."+FilenameUtils.getExtension(i.getEvidencia());
|
|
|
+ String name = "-"+i.getTasca().getNomEvidenciaCas().replace(" ", "_");
|
|
|
+ response.setHeader("Content-Disposition", "attachment; filename="+i.getTasca().getCodiEvidencia()+name+extension);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ file = new FileSystemResource(this.filePath+i.getEvidencia());
|
|
|
+ System.out.println(i.getEvidencia()+".zip");
|
|
|
+ response.setHeader("Content-Disposition", "attachment; filename="+i.getEvidencia());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!file.exists()) {
|
|
|
+ return new FileSystemResource(this.fileNotFound).getInputStream().readAllBytes();
|
|
|
+ }
|
|
|
+
|
|
|
+ response.setContentType("application/zip");
|
|
|
+ return file.getInputStream().readAllBytes();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
|
|
|
- return ResponseEntity.ok(r);
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -129,7 +139,7 @@ public class DownloadController {
|
|
|
*/
|
|
|
@GetMapping(value="/download/document/{id}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
|
|
|
@ResponseBody
|
|
|
- public ResponseEntity<FileSystemResource> downloadDocument(Model model, @PathVariable("id") Integer idDocument, HttpServletResponse response) throws FileNotFoundException {
|
|
|
+ public ResponseEntity<FileSystemResource> downloadDocument(@PathVariable("id") Integer idDocument, HttpServletResponse response) throws FileNotFoundException {
|
|
|
Document document = findByIdDocument(idDocument);
|
|
|
FileSystemResource file = new FileSystemResource(document.getRuta());
|
|
|
if(!file.exists()) {
|
|
|
@@ -150,7 +160,7 @@ public class DownloadController {
|
|
|
*/
|
|
|
@GetMapping(value="/download/report/{t}/{p}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
|
|
|
@ResponseBody
|
|
|
- public ResponseEntity<FileSystemResource> downloadReport(Model model, @PathVariable("t") Integer idTitulacio, @PathVariable("p") String nomProces,
|
|
|
+ public ResponseEntity<FileSystemResource> downloadReport(@PathVariable("t") Integer idTitulacio, @PathVariable("p") String nomProces,
|
|
|
HttpServletResponse response) throws IOException, XDocReportException {
|
|
|
|
|
|
Organ titulacio = findByIDOrgan("T", idTitulacio);
|
|
|
@@ -166,7 +176,7 @@ public class DownloadController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
|
|
|
+ return ResponseEntity.ok(new FileSystemResource(this.filePath+it.getEvidencia()));
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -179,7 +189,7 @@ public class DownloadController {
|
|
|
*/
|
|
|
@GetMapping(value="/download/template/{id}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
|
|
|
@ResponseBody
|
|
|
- public ResponseEntity<byte[]> downloadTemplate(Model model, @PathVariable("id") BigInteger idTascai, HttpServletResponse response) throws IOException, XDocReportException {
|
|
|
+ public byte[] downloadTemplate(@PathVariable("id") BigInteger idTascai, HttpServletResponse response) throws IOException, XDocReportException {
|
|
|
XDocReportRegistry.getRegistry().clear();
|
|
|
String reportId = "none";
|
|
|
InstanciaTascaDTO it = findByIdTasca(idTascai);
|
|
|
@@ -203,7 +213,7 @@ public class DownloadController {
|
|
|
|
|
|
File f = new File(templatePath);
|
|
|
if(!f.exists()) {
|
|
|
- return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
|
|
|
+ return new FileSystemResource(this.fileNotFound).getInputStream().readAllBytes();
|
|
|
}
|
|
|
|
|
|
InputStream in = new FileInputStream(f);
|
|
|
@@ -248,7 +258,7 @@ public class DownloadController {
|
|
|
report.process(context, out);
|
|
|
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\""+tasca.getCodiEvidencia()+".docx\"");
|
|
|
|
|
|
- return ResponseEntity.ok(out.toByteArray());
|
|
|
+ return out.toByteArray();
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -355,7 +365,7 @@ public class DownloadController {
|
|
|
*/
|
|
|
@GetMapping(value="/test/template/{titulacio}/{centre}/{idProces}/{idTascap}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
|
|
|
@ResponseBody
|
|
|
- public ResponseEntity<byte[]> testTemplate(Model model, @PathVariable("titulacio") Integer idTitulacio, @PathVariable("centre") Integer idCentre,
|
|
|
+ public byte[] testTemplate(@PathVariable("titulacio") Integer idTitulacio, @PathVariable("centre") Integer idCentre,
|
|
|
@PathVariable("idTascap") Integer idTascap, @PathVariable("idProces") Integer idProces, HttpServletResponse response)
|
|
|
throws IOException, XDocReportException {
|
|
|
XDocReportRegistry.getRegistry().clear();
|
|
|
@@ -421,8 +431,7 @@ public class DownloadController {
|
|
|
report.process(context, out);
|
|
|
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\""+tasca.getCodiEvidencia()+".docx\"");
|
|
|
|
|
|
- return ResponseEntity.ok(out.toByteArray());
|
|
|
-
|
|
|
+ return out.toByteArray();
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -438,7 +447,7 @@ public class DownloadController {
|
|
|
*/
|
|
|
@GetMapping(value="/test/template2/{titulacio}/{centre}/{evidencia}/{curs}/{tipusTasca}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
|
|
|
@ResponseBody
|
|
|
- public ResponseEntity<byte[]> testTemplate(Model model, @PathVariable("titulacio") Integer idTitulacio, @PathVariable("centre") Integer idCentre,
|
|
|
+ public byte[] testTemplate(Model model, @PathVariable("titulacio") Integer idTitulacio, @PathVariable("centre") Integer idCentre,
|
|
|
@PathVariable("evidencia") String evidencia, @PathVariable("curs") Integer curs, @PathVariable("tipusTasca") Integer tipusTasca,
|
|
|
HttpServletResponse response) throws IOException, XDocReportException {
|
|
|
XDocReportRegistry.getRegistry().clear();
|
|
|
@@ -504,7 +513,7 @@ public class DownloadController {
|
|
|
report.process(context, out);
|
|
|
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\""+evidencia+".docx\"");
|
|
|
|
|
|
- return ResponseEntity.ok(out.toByteArray());
|
|
|
+ return out.toByteArray();
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -517,11 +526,11 @@ public class DownloadController {
|
|
|
*/
|
|
|
@GetMapping(value="/pdf/download/{idTascai}")
|
|
|
@ResponseBody
|
|
|
- public ResponseEntity<byte[]> downloadTemplatePdf(Model model, @PathVariable("idTascai") BigInteger idTascai, HttpServletResponse response) throws IOException, InterruptedException {
|
|
|
+ public byte[] downloadTemplatePdf(@PathVariable("idTascai") BigInteger idTascai, HttpServletResponse response) throws IOException, InterruptedException {
|
|
|
InstanciaTascaDTO it = findByIdTasca(idTascai);
|
|
|
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\""+it.getIdInstanciaTasca()+".pdf\"");
|
|
|
response.setHeader(HttpHeaders.CONTENT_TYPE, "application/pdf");
|
|
|
- return ResponseEntity.ok(pls.toPDF(it.getText(), Optional.of(idTascai)));
|
|
|
+ return pls.toPDF(it.getText(), Optional.of(idTascai));
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -533,11 +542,11 @@ public class DownloadController {
|
|
|
*/
|
|
|
@PostMapping(value="/pdf/preview")
|
|
|
@ResponseBody
|
|
|
- public ResponseEntity<byte[]> downloadTemplatePdf(Model model, HttpServletResponse response,
|
|
|
+ public byte[] downloadTemplatePdf(HttpServletResponse response,
|
|
|
@RequestBody PdfDTO pdf) throws IOException, InterruptedException {
|
|
|
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"borrador.pdf\"");
|
|
|
response.setHeader(HttpHeaders.CONTENT_TYPE, "application/pdf");
|
|
|
- return ResponseEntity.ok(toPDF(pdf.getContent(), pdf.getIdtascai()));
|
|
|
+ return toPDF(pdf.getContent(), pdf.getIdtascai());
|
|
|
}
|
|
|
|
|
|
private TascaInformeTransferDTO getLastByProcName(String nomProces, Integer lugar, Integer lugar2, String tambit) {
|