|
|
@@ -23,14 +23,18 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.core.io.FileSystemResource;
|
|
|
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.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;
|
|
|
|
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
|
@@ -45,7 +49,9 @@ import es.uv.saic.domain.Tasca;
|
|
|
import es.uv.saic.dto.CategoriaDTO;
|
|
|
import es.uv.saic.dto.IndicadorEnquestaDTO;
|
|
|
import es.uv.saic.dto.IndicadorEnquestaValorDTO;
|
|
|
+import es.uv.saic.dto.InstanciaTascaDTO;
|
|
|
import es.uv.saic.dto.PdfDTO;
|
|
|
+import es.uv.saic.dto.ProcesDTO;
|
|
|
import es.uv.saic.dto.TascaDTO;
|
|
|
import es.uv.saic.dto.TascaInformeTransferDTO;
|
|
|
import es.uv.saic.service.PlantillaService;
|
|
|
@@ -60,7 +66,7 @@ import fr.opensagres.xdocreport.template.TemplateEngineKind;
|
|
|
import fr.opensagres.xdocreport.template.formatter.FieldsMetadata;
|
|
|
|
|
|
|
|
|
-@Controller
|
|
|
+@RestController
|
|
|
public class DownloadController {
|
|
|
|
|
|
@Autowired
|
|
|
@@ -81,7 +87,7 @@ public class DownloadController {
|
|
|
@Value("${saic.data.templates.logoPath}")
|
|
|
private String logoPath;
|
|
|
|
|
|
- @Value("${saic.url.domain}")
|
|
|
+ @Value("${saic.url.core.domain}")
|
|
|
private String uri;
|
|
|
|
|
|
/*
|
|
|
@@ -93,10 +99,10 @@ public class DownloadController {
|
|
|
*/
|
|
|
@GetMapping(value="/download/{fileName}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
|
|
|
@ResponseBody
|
|
|
- public FileSystemResource download(Model model, @PathVariable("fileName") BigInteger idInstanciaTasca, HttpServletResponse response) throws FileNotFoundException {
|
|
|
- InstanciaTasca i = findByIdTasca(idInstanciaTasca);
|
|
|
+ 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().getTipus() == 22){
|
|
|
+ if(i.getTasca().getTipus() == 22){
|
|
|
r = new FileSystemResource(i.getEvidencia());
|
|
|
String extension = "."+FilenameUtils.getExtension(i.getEvidencia());
|
|
|
String name = "-"+i.getTasca().getNomEvidenciaCas().replace(" ", "_");
|
|
|
@@ -107,13 +113,11 @@ public class DownloadController {
|
|
|
response.setHeader("Content-Disposition", "attachment; filename="+i.getTasca().getCodiEvidencia()+"_"+i.getEvidencia());
|
|
|
}
|
|
|
|
|
|
- if(!r.exists()) {
|
|
|
- FileNotFoundException e = new FileNotFoundException("No se ha podido encontrar el archivo solicitado");
|
|
|
- e.setStackTrace(new StackTraceElement[0]);
|
|
|
- throw e;
|
|
|
+ if (!r.exists()) {
|
|
|
+ return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
|
|
|
}
|
|
|
|
|
|
- return r;
|
|
|
+ return ResponseEntity.ok(r);
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -125,17 +129,15 @@ public class DownloadController {
|
|
|
*/
|
|
|
@GetMapping(value="/download/document/{id}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
|
|
|
@ResponseBody
|
|
|
- public FileSystemResource downloadDocument(Model model, @PathVariable("id") Integer idDocument, HttpServletResponse response) throws FileNotFoundException {
|
|
|
+ public ResponseEntity<FileSystemResource> downloadDocument(Model model, @PathVariable("id") Integer idDocument, HttpServletResponse response) throws FileNotFoundException {
|
|
|
Document document = findByIdDocument(idDocument);
|
|
|
FileSystemResource file = new FileSystemResource(document.getRuta());
|
|
|
if(!file.exists()) {
|
|
|
- FileNotFoundException e = new FileNotFoundException("No se ha podido encontrar el archivo solicitado");
|
|
|
- e.setStackTrace(new StackTraceElement[0]);
|
|
|
- throw e;
|
|
|
+ return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
|
|
|
}
|
|
|
|
|
|
response.setHeader("Content-Disposition", "attachment; filename="+file.getFilename());
|
|
|
- return file;
|
|
|
+ return ResponseEntity.ok(file);
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -148,7 +150,7 @@ public class DownloadController {
|
|
|
*/
|
|
|
@GetMapping(value="/download/report/{t}/{p}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
|
|
|
@ResponseBody
|
|
|
- public FileSystemResource downloadReport(Model model, @PathVariable("t") Integer idTitulacio, @PathVariable("p") String nomProces,
|
|
|
+ public ResponseEntity<FileSystemResource> downloadReport(Model model, @PathVariable("t") Integer idTitulacio, @PathVariable("p") String nomProces,
|
|
|
HttpServletResponse response) throws IOException, XDocReportException {
|
|
|
|
|
|
Organ titulacio = findByIDOrgan("T", idTitulacio);
|
|
|
@@ -160,11 +162,11 @@ public class DownloadController {
|
|
|
if(it != null) {
|
|
|
if((new File(this.filePath+it.getEvidencia())).exists()) {
|
|
|
response.setHeader("Content-Disposition", "attachment; filename="+Integer.toString(idTitulacio)+"_"+nomProces+".pdf");
|
|
|
- return new FileSystemResource(this.filePath+it.getEvidencia());
|
|
|
+ return ResponseEntity.ok(new FileSystemResource(this.filePath+it.getEvidencia()));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return new FileSystemResource(this.fileNotFound);
|
|
|
+ return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -177,22 +179,22 @@ public class DownloadController {
|
|
|
*/
|
|
|
@GetMapping(value="/download/template/{id}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
|
|
|
@ResponseBody
|
|
|
- public byte[] downloadTemplate(Model model, @PathVariable("id") BigInteger idTascai, HttpServletResponse response) throws IOException, XDocReportException {
|
|
|
+ public ResponseEntity<byte[]> downloadTemplate(Model model, @PathVariable("id") BigInteger idTascai, HttpServletResponse response) throws IOException, XDocReportException {
|
|
|
XDocReportRegistry.getRegistry().clear();
|
|
|
String reportId = "none";
|
|
|
- InstanciaTasca it = findByIdTasca(idTascai);
|
|
|
- Tasca tasca = it.getTasca();
|
|
|
+ InstanciaTascaDTO it = findByIdTasca(idTascai);
|
|
|
+ TascaDTO tasca = it.getTasca();
|
|
|
|
|
|
/* Check if specific template exists */
|
|
|
Integer idTitulacio = it.getInstancia().getTitulacio();
|
|
|
String templatePath = this.templatePath+tasca.getCodiEvidencia().replace(".", "_")+".docx";
|
|
|
- if(it.getInstancia().getOrgan().getTambit().equals("G") | idTitulacio == 1) {
|
|
|
+ if(it.getInstancia().getTambit().equals("G") | idTitulacio == 1) {
|
|
|
File f = new File(this.templatePath+"/T1/"+tasca.getCodiEvidencia().replace(".", "_")+".docx");
|
|
|
if(f.exists() && !f.isDirectory()) {
|
|
|
templatePath = this.templatePath+"/T1/"+tasca.getCodiEvidencia().replace(".", "_")+".docx";
|
|
|
}
|
|
|
}
|
|
|
- else if(it.getInstancia().getOrgan().getTambit().equals("M") | idTitulacio == 2) {
|
|
|
+ else if(it.getInstancia().getTambit().equals("M") | idTitulacio == 2) {
|
|
|
File f = new File(this.templatePath+"/T2/"+tasca.getCodiEvidencia().replace(".", "_")+".docx");
|
|
|
if(f.exists() && !f.isDirectory()) {
|
|
|
templatePath = this.templatePath+"/T2/"+tasca.getCodiEvidencia().replace(".", "_")+".docx";
|
|
|
@@ -201,9 +203,7 @@ public class DownloadController {
|
|
|
|
|
|
File f = new File(templatePath);
|
|
|
if(!f.exists()) {
|
|
|
- FileNotFoundException e = new FileNotFoundException("No se ha encontrado la plantilla "+tasca.getCodiEvidencia()+".docx");
|
|
|
- e.setStackTrace(new StackTraceElement[0]);
|
|
|
- throw e;
|
|
|
+ return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
|
|
|
}
|
|
|
|
|
|
InputStream in = new FileInputStream(f);
|
|
|
@@ -220,36 +220,35 @@ public class DownloadController {
|
|
|
img = new FileImageProvider(new File(this.logoPath+"C0.png"));
|
|
|
}
|
|
|
context.put("logo", img);
|
|
|
- context.put("centre", it.getInstancia().getOrgan().getOrgan().getNomVal());
|
|
|
- context.put("titulacio", it.getInstancia().getOrgan().getNomCas());
|
|
|
- context.put("curs", Integer.toString(it.getInstancia().getProces().getCursAvaluat()-1)+" - "+Integer.toString(it.getInstancia().getProces().getCursAvaluat()));
|
|
|
- context.put("curs_anterior", Integer.toString(it.getInstancia().getProces().getCursAvaluat()-2)+" - "+Integer.toString(it.getInstancia().getProces().getCursAvaluat()-1));
|
|
|
+ context.put("centre", it.getInstancia().getNomval());
|
|
|
+ context.put("titulacio", it.getInstancia().getNomcas());
|
|
|
+ context.put("curs", Integer.toString(it.getInstancia().getCursAvaluat()-1)+" - "+Integer.toString(it.getInstancia().getCursAvaluat()));
|
|
|
+ context.put("curs_anterior", Integer.toString(it.getInstancia().getCursAvaluat()-2)+" - "+Integer.toString(it.getInstancia().getCursAvaluat()-1));
|
|
|
|
|
|
- Proces proces = it.getInstancia().getProces();
|
|
|
Integer idCentre = it.getInstancia().getCentre();
|
|
|
|
|
|
- if(tasca.getTipus().getTipus() == 14) { // Iterable template task
|
|
|
+ if(tasca.getTipus() == 14) { // Iterable template task
|
|
|
List<Organ> titulacions = new ArrayList<Organ>();
|
|
|
Integer ambit = idTitulacio/(int)1000;
|
|
|
- titulacions = getTitulacionsByTypeCentre(it.getInstancia().getOrgan().getOrgan().getId().getLugar(), ambit);
|
|
|
+ titulacions = getTitulacionsByTypeCentre(it.getInstancia().getLugar(), ambit);
|
|
|
List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
|
|
|
for(Organ x : titulacions) {
|
|
|
- HashMap<String, String> t = getTemplateDataArray(x.getId().getLugar(), idCentre, proces.getCursAvaluat());
|
|
|
+ HashMap<String, String> t = getTemplateDataArray(x.getId().getLugar(), idCentre, it.getInstancia().getCursAvaluat());
|
|
|
t.put("titulacio", x.getNomCas());
|
|
|
data.add(t);
|
|
|
}
|
|
|
context.put("data", data);
|
|
|
- getTemplateData(idTitulacio, idCentre, proces.getCursAvaluat(), context);
|
|
|
+ getTemplateData(idTitulacio, idCentre, it.getInstancia().getCursAvaluat(), context);
|
|
|
}
|
|
|
else { // NO iterable template task
|
|
|
- getTemplateData(idTitulacio, idCentre, proces.getCursAvaluat(), context);
|
|
|
+ getTemplateData(idTitulacio, idCentre, it.getInstancia().getCursAvaluat(), context);
|
|
|
}
|
|
|
|
|
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
|
report.process(context, out);
|
|
|
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\""+tasca.getCodiEvidencia()+".docx\"");
|
|
|
|
|
|
- return out.toByteArray();
|
|
|
+ return ResponseEntity.ok(out.toByteArray());
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -356,7 +355,7 @@ public class DownloadController {
|
|
|
*/
|
|
|
@GetMapping(value="/test/template/{titulacio}/{centre}/{idProces}/{idTascap}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
|
|
|
@ResponseBody
|
|
|
- public byte[] testTemplate(Model model, @PathVariable("titulacio") Integer idTitulacio, @PathVariable("centre") Integer idCentre,
|
|
|
+ public ResponseEntity<byte[]> testTemplate(Model model, @PathVariable("titulacio") Integer idTitulacio, @PathVariable("centre") Integer idCentre,
|
|
|
@PathVariable("idTascap") Integer idTascap, @PathVariable("idProces") Integer idProces, HttpServletResponse response)
|
|
|
throws IOException, XDocReportException {
|
|
|
XDocReportRegistry.getRegistry().clear();
|
|
|
@@ -422,7 +421,7 @@ public class DownloadController {
|
|
|
report.process(context, out);
|
|
|
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\""+tasca.getCodiEvidencia()+".docx\"");
|
|
|
|
|
|
- return out.toByteArray();
|
|
|
+ return ResponseEntity.ok(out.toByteArray());
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -439,7 +438,7 @@ public class DownloadController {
|
|
|
*/
|
|
|
@GetMapping(value="/test/template2/{titulacio}/{centre}/{evidencia}/{curs}/{tipusTasca}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
|
|
|
@ResponseBody
|
|
|
- public byte[] testTemplate(Model model, @PathVariable("titulacio") Integer idTitulacio, @PathVariable("centre") Integer idCentre,
|
|
|
+ public ResponseEntity<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();
|
|
|
@@ -505,7 +504,7 @@ public class DownloadController {
|
|
|
report.process(context, out);
|
|
|
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\""+evidencia+".docx\"");
|
|
|
|
|
|
- return out.toByteArray();
|
|
|
+ return ResponseEntity.ok(out.toByteArray());
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -518,11 +517,11 @@ public class DownloadController {
|
|
|
*/
|
|
|
@GetMapping(value="/pdf/download/{idTascai}")
|
|
|
@ResponseBody
|
|
|
- public byte[] downloadTemplatePdf(Model model, @PathVariable("idTascai") BigInteger idTascai, HttpServletResponse response) throws IOException, InterruptedException {
|
|
|
- InstanciaTasca it = findByIdTasca(idTascai);
|
|
|
+ public ResponseEntity<byte[]> downloadTemplatePdf(Model model, @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 pls.toPDF(it.getText(), Optional.of(idTascai));
|
|
|
+ return ResponseEntity.ok(pls.toPDF(it.getText(), Optional.of(idTascai)));
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -534,11 +533,11 @@ public class DownloadController {
|
|
|
*/
|
|
|
@PostMapping(value="/pdf/preview")
|
|
|
@ResponseBody
|
|
|
- public byte[] downloadTemplatePdf(Model model, HttpServletResponse response,
|
|
|
- @RequestParam("content") String content, @RequestParam("idtascai") Optional<BigInteger> idtascai) throws IOException, InterruptedException {
|
|
|
+ public ResponseEntity<byte[]> downloadTemplatePdf(Model model, 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 toPDF(content, idtascai);
|
|
|
+ return ResponseEntity.ok(toPDF(pdf.getContent(), pdf.getIdtascai()));
|
|
|
}
|
|
|
|
|
|
private TascaInformeTransferDTO getLastByProcName(String nomProces, Integer lugar, Integer lugar2, String tambit) {
|
|
|
@@ -547,8 +546,8 @@ public class DownloadController {
|
|
|
TascaInformeTransferDTO tascaInformeTransferDTO = null;
|
|
|
|
|
|
try {
|
|
|
- TascaDTO TascaDTO = new TascaDTO(nomProces, lugar, lugar2, tambit);
|
|
|
- String requestBody = mapper.writeValueAsString(TascaDTO);
|
|
|
+ ProcesDTO ProcesDTO = new ProcesDTO(nomProces, lugar, lugar2, tambit);
|
|
|
+ String requestBody = mapper.writeValueAsString(ProcesDTO);
|
|
|
HttpClient httpClient = HttpClient.newHttpClient();
|
|
|
HttpRequest request = HttpRequest.newBuilder()
|
|
|
.uri(uriObj)
|
|
|
@@ -571,10 +570,10 @@ public class DownloadController {
|
|
|
return tascaInformeTransferDTO;
|
|
|
}
|
|
|
|
|
|
- private InstanciaTasca findByIdTasca(BigInteger idInstanciaTasca) {
|
|
|
+ private InstanciaTascaDTO findByIdTasca(BigInteger idInstanciaTasca) {
|
|
|
URI uriObj = URI.create(uri + "/instanciatasca/" + idInstanciaTasca);
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
- InstanciaTasca instanciaTasca = null;
|
|
|
+ InstanciaTascaDTO instanciaTasca = null;
|
|
|
try {
|
|
|
HttpClient httpClient = HttpClient.newHttpClient();
|
|
|
HttpRequest request = HttpRequest.newBuilder()
|
|
|
@@ -585,7 +584,7 @@ public class DownloadController {
|
|
|
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
|
|
|
if (response.statusCode() == HttpURLConnection.HTTP_OK) {
|
|
|
- instanciaTasca = mapper.readValue(response.body(), new TypeReference<InstanciaTasca>() {});
|
|
|
+ instanciaTasca = mapper.readValue(response.body(), new TypeReference<InstanciaTascaDTO>() {});
|
|
|
} else {
|
|
|
System.err.println("Failed to find InstanciaTasca by ID. HTTP error code: " + response.statusCode());
|
|
|
}
|