|
@@ -6,6 +6,11 @@ import java.io.FileNotFoundException;
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
|
import java.math.BigInteger;
|
|
import java.math.BigInteger;
|
|
|
|
|
+import java.net.HttpURLConnection;
|
|
|
|
|
+import java.net.URI;
|
|
|
|
|
+import java.net.http.HttpClient;
|
|
|
|
|
+import java.net.http.HttpRequest;
|
|
|
|
|
+import java.net.http.HttpResponse;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -27,22 +32,23 @@ import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
|
|
|
|
+import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
|
|
+import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
+
|
|
|
import es.uv.saic.domain.Document;
|
|
import es.uv.saic.domain.Document;
|
|
|
import es.uv.saic.domain.Indicador;
|
|
import es.uv.saic.domain.Indicador;
|
|
|
import es.uv.saic.domain.InstanciaTasca;
|
|
import es.uv.saic.domain.InstanciaTasca;
|
|
|
import es.uv.saic.domain.Organ;
|
|
import es.uv.saic.domain.Organ;
|
|
|
import es.uv.saic.domain.Proces;
|
|
import es.uv.saic.domain.Proces;
|
|
|
import es.uv.saic.domain.Tasca;
|
|
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.IndicadorEnquestaValorDTO;
|
|
|
|
|
+import es.uv.saic.dto.PdfDTO;
|
|
|
|
|
+import es.uv.saic.dto.TascaDTO;
|
|
|
import es.uv.saic.dto.TascaInformeTransferDTO;
|
|
import es.uv.saic.dto.TascaInformeTransferDTO;
|
|
|
-import es.uv.saic.service.DocumentService;
|
|
|
|
|
-import es.uv.saic.service.IndicadorEnquestaService;
|
|
|
|
|
-import es.uv.saic.service.IndicadorService;
|
|
|
|
|
-import es.uv.saic.service.InstanciaTascaService;
|
|
|
|
|
-import es.uv.saic.service.OrganService;
|
|
|
|
|
import es.uv.saic.service.PlantillaService;
|
|
import es.uv.saic.service.PlantillaService;
|
|
|
-import es.uv.saic.service.ProcesService;
|
|
|
|
|
-import es.uv.saic.service.TascaService;
|
|
|
|
|
import fr.opensagres.xdocreport.core.XDocReportException;
|
|
import fr.opensagres.xdocreport.core.XDocReportException;
|
|
|
import fr.opensagres.xdocreport.core.io.internal.ByteArrayOutputStream;
|
|
import fr.opensagres.xdocreport.core.io.internal.ByteArrayOutputStream;
|
|
|
import fr.opensagres.xdocreport.document.IXDocReport;
|
|
import fr.opensagres.xdocreport.document.IXDocReport;
|
|
@@ -56,31 +62,10 @@ import fr.opensagres.xdocreport.template.formatter.FieldsMetadata;
|
|
|
|
|
|
|
|
@Controller
|
|
@Controller
|
|
|
public class DownloadController {
|
|
public class DownloadController {
|
|
|
-
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private InstanciaTascaService its;
|
|
|
|
|
-
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private IndicadorEnquestaService ies;
|
|
|
|
|
-
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private TascaService ts;
|
|
|
|
|
-
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private IndicadorService is;
|
|
|
|
|
-
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private ProcesService ps;
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private PlantillaService pls;
|
|
private PlantillaService pls;
|
|
|
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private OrganService os;
|
|
|
|
|
-
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private DocumentService ds;
|
|
|
|
|
-
|
|
|
|
|
@Value("${saic.data.filePath}")
|
|
@Value("${saic.data.filePath}")
|
|
|
private String filePath;
|
|
private String filePath;
|
|
|
|
|
|
|
@@ -95,7 +80,9 @@ public class DownloadController {
|
|
|
|
|
|
|
|
@Value("${saic.data.templates.logoPath}")
|
|
@Value("${saic.data.templates.logoPath}")
|
|
|
private String logoPath;
|
|
private String logoPath;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+ @Value("${saic.url.domain}")
|
|
|
|
|
+ private String uri;
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
|
* Download a file associated with a task instance
|
|
* Download a file associated with a task instance
|
|
@@ -107,7 +94,7 @@ public class DownloadController {
|
|
|
@GetMapping(value="/download/{fileName}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
|
|
@GetMapping(value="/download/{fileName}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
|
|
|
@ResponseBody
|
|
@ResponseBody
|
|
|
public FileSystemResource download(Model model, @PathVariable("fileName") BigInteger idInstanciaTasca, HttpServletResponse response) throws FileNotFoundException {
|
|
public FileSystemResource download(Model model, @PathVariable("fileName") BigInteger idInstanciaTasca, HttpServletResponse response) throws FileNotFoundException {
|
|
|
- InstanciaTasca i = its.findById(idInstanciaTasca);
|
|
|
|
|
|
|
+ InstanciaTasca i = findByIdTasca(idInstanciaTasca);
|
|
|
FileSystemResource r = null;
|
|
FileSystemResource r = null;
|
|
|
if(i.getTasca().getTipus().getTipus() == 22){
|
|
if(i.getTasca().getTipus().getTipus() == 22){
|
|
|
r = new FileSystemResource(i.getEvidencia());
|
|
r = new FileSystemResource(i.getEvidencia());
|
|
@@ -128,7 +115,7 @@ public class DownloadController {
|
|
|
|
|
|
|
|
return r;
|
|
return r;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
/*
|
|
/*
|
|
|
* Download a document by its ID
|
|
* Download a document by its ID
|
|
|
* @param model
|
|
* @param model
|
|
@@ -139,7 +126,7 @@ public class DownloadController {
|
|
|
@GetMapping(value="/download/document/{id}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
|
|
@GetMapping(value="/download/document/{id}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
|
|
|
@ResponseBody
|
|
@ResponseBody
|
|
|
public FileSystemResource downloadDocument(Model model, @PathVariable("id") Integer idDocument, HttpServletResponse response) throws FileNotFoundException {
|
|
public FileSystemResource downloadDocument(Model model, @PathVariable("id") Integer idDocument, HttpServletResponse response) throws FileNotFoundException {
|
|
|
- Document document = ds.findById(idDocument);
|
|
|
|
|
|
|
+ Document document = findByIdDocument(idDocument);
|
|
|
FileSystemResource file = new FileSystemResource(document.getRuta());
|
|
FileSystemResource file = new FileSystemResource(document.getRuta());
|
|
|
if(!file.exists()) {
|
|
if(!file.exists()) {
|
|
|
FileNotFoundException e = new FileNotFoundException("No se ha podido encontrar el archivo solicitado");
|
|
FileNotFoundException e = new FileNotFoundException("No se ha podido encontrar el archivo solicitado");
|
|
@@ -150,7 +137,7 @@ public class DownloadController {
|
|
|
response.setHeader("Content-Disposition", "attachment; filename="+file.getFilename());
|
|
response.setHeader("Content-Disposition", "attachment; filename="+file.getFilename());
|
|
|
return file;
|
|
return file;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
/*
|
|
/*
|
|
|
* Download the latest report for a given process and degree
|
|
* Download the latest report for a given process and degree
|
|
|
* @param model
|
|
* @param model
|
|
@@ -164,9 +151,9 @@ public class DownloadController {
|
|
|
public FileSystemResource downloadReport(Model model, @PathVariable("t") Integer idTitulacio, @PathVariable("p") String nomProces,
|
|
public FileSystemResource downloadReport(Model model, @PathVariable("t") Integer idTitulacio, @PathVariable("p") String nomProces,
|
|
|
HttpServletResponse response) throws IOException, XDocReportException {
|
|
HttpServletResponse response) throws IOException, XDocReportException {
|
|
|
|
|
|
|
|
- Organ titulacio = os.findByID("T", idTitulacio);
|
|
|
|
|
|
|
+ Organ titulacio = findByIDOrgan("T", idTitulacio);
|
|
|
|
|
|
|
|
- TascaInformeTransferDTO it = its.getLastByProcName(nomProces, titulacio.getId().getLugar(),
|
|
|
|
|
|
|
+ TascaInformeTransferDTO it = getLastByProcName(nomProces, titulacio.getId().getLugar(),
|
|
|
titulacio.getOrgan().getId().getLugar(),
|
|
titulacio.getOrgan().getId().getLugar(),
|
|
|
titulacio.getOrgan().getTambit());
|
|
titulacio.getOrgan().getTambit());
|
|
|
|
|
|
|
@@ -178,9 +165,9 @@ public class DownloadController {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return new FileSystemResource(this.fileNotFound);
|
|
return new FileSystemResource(this.fileNotFound);
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
/*
|
|
/*
|
|
|
* Download a populated template for a given task instance
|
|
* Download a populated template for a given task instance
|
|
|
* @param model
|
|
* @param model
|
|
@@ -193,7 +180,7 @@ public class DownloadController {
|
|
|
public byte[] downloadTemplate(Model model, @PathVariable("id") BigInteger idTascai, HttpServletResponse response) throws IOException, XDocReportException {
|
|
public byte[] downloadTemplate(Model model, @PathVariable("id") BigInteger idTascai, HttpServletResponse response) throws IOException, XDocReportException {
|
|
|
XDocReportRegistry.getRegistry().clear();
|
|
XDocReportRegistry.getRegistry().clear();
|
|
|
String reportId = "none";
|
|
String reportId = "none";
|
|
|
- InstanciaTasca it = its.findById(idTascai);
|
|
|
|
|
|
|
+ InstanciaTasca it = findByIdTasca(idTascai);
|
|
|
Tasca tasca = it.getTasca();
|
|
Tasca tasca = it.getTasca();
|
|
|
|
|
|
|
|
/* Check if specific template exists */
|
|
/* Check if specific template exists */
|
|
@@ -244,7 +231,7 @@ public class DownloadController {
|
|
|
if(tasca.getTipus().getTipus() == 14) { // Iterable template task
|
|
if(tasca.getTipus().getTipus() == 14) { // Iterable template task
|
|
|
List<Organ> titulacions = new ArrayList<Organ>();
|
|
List<Organ> titulacions = new ArrayList<Organ>();
|
|
|
Integer ambit = idTitulacio/(int)1000;
|
|
Integer ambit = idTitulacio/(int)1000;
|
|
|
- titulacions = os.getTitulacionsByTypeCentre(it.getInstancia().getOrgan().getOrgan().getId().getLugar(), ambit);
|
|
|
|
|
|
|
+ titulacions = getTitulacionsByTypeCentre(it.getInstancia().getOrgan().getOrgan().getId().getLugar(), ambit);
|
|
|
List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
|
|
List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
|
|
|
for(Organ x : titulacions) {
|
|
for(Organ x : titulacions) {
|
|
|
HashMap<String, String> t = getTemplateDataArray(x.getId().getLugar(), idCentre, proces.getCursAvaluat());
|
|
HashMap<String, String> t = getTemplateDataArray(x.getId().getLugar(), idCentre, proces.getCursAvaluat());
|
|
@@ -265,7 +252,7 @@ public class DownloadController {
|
|
|
return out.toByteArray();
|
|
return out.toByteArray();
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
/*
|
|
/*
|
|
|
* Populate the template data into the context
|
|
* Populate the template data into the context
|
|
|
* @param idTitulacio The ID of the degree
|
|
* @param idTitulacio The ID of the degree
|
|
@@ -278,7 +265,7 @@ public class DownloadController {
|
|
|
/* Indicadores del data warehouse */
|
|
/* Indicadores del data warehouse */
|
|
|
try {
|
|
try {
|
|
|
List<Indicador> indicadores;
|
|
List<Indicador> indicadores;
|
|
|
- indicadores = this.is.getFromTitulacion(idTitulacio, curs);
|
|
|
|
|
|
|
+ indicadores = getFromTitulacion(idTitulacio, curs);
|
|
|
for(Indicador i : indicadores) {
|
|
for(Indicador i : indicadores) {
|
|
|
context.put(i.getIndicador(), i.getValor());
|
|
context.put(i.getIndicador(), i.getValor());
|
|
|
}
|
|
}
|
|
@@ -287,7 +274,7 @@ public class DownloadController {
|
|
|
|
|
|
|
|
/* Indicadores de encuestas */
|
|
/* Indicadores de encuestas */
|
|
|
List<IndicadorEnquestaValorDTO> enquestesT;
|
|
List<IndicadorEnquestaValorDTO> enquestesT;
|
|
|
- enquestesT = this.ies.getAllInds(idTitulacio, idCentre, curs);
|
|
|
|
|
|
|
+ enquestesT = getAllInds(idTitulacio, idCentre, curs);
|
|
|
|
|
|
|
|
for(IndicadorEnquestaValorDTO i : enquestesT) {
|
|
for(IndicadorEnquestaValorDTO i : enquestesT) {
|
|
|
String indicador = i.getAmbit().equals("t") ? (i.getEnquesta()+"_"+i.getIndicador()) : (i.getEnquesta()+"_"+i.getIndicador()+"_"+i.getAmbit());
|
|
String indicador = i.getAmbit().equals("t") ? (i.getEnquesta()+"_"+i.getIndicador()) : (i.getEnquesta()+"_"+i.getIndicador()+"_"+i.getAmbit());
|
|
@@ -296,7 +283,7 @@ public class DownloadController {
|
|
|
context.put(indicador, formatValue(i.getValor()));
|
|
context.put(indicador, formatValue(i.getValor()));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
/*
|
|
/*
|
|
|
* Format a value for template insertion
|
|
* Format a value for template insertion
|
|
|
* @param v The value to format
|
|
* @param v The value to format
|
|
@@ -336,7 +323,7 @@ public class DownloadController {
|
|
|
/* Indicadores del data warehouse */
|
|
/* Indicadores del data warehouse */
|
|
|
try {
|
|
try {
|
|
|
List<Indicador> indicadores;
|
|
List<Indicador> indicadores;
|
|
|
- indicadores = this.is.getFromTitulacion(idTitulacio, curs);
|
|
|
|
|
|
|
+ indicadores = getFromTitulacion(idTitulacio, curs);
|
|
|
for(Indicador i : indicadores) {
|
|
for(Indicador i : indicadores) {
|
|
|
info.put(i.getIndicador(), i.getValor());
|
|
info.put(i.getIndicador(), i.getValor());
|
|
|
}
|
|
}
|
|
@@ -345,7 +332,7 @@ public class DownloadController {
|
|
|
|
|
|
|
|
/* Indicadores de encuestas */
|
|
/* Indicadores de encuestas */
|
|
|
List<IndicadorEnquestaValorDTO> enquestesT;
|
|
List<IndicadorEnquestaValorDTO> enquestesT;
|
|
|
- enquestesT = this.ies.getAllInds(idTitulacio, idCentre, curs);
|
|
|
|
|
|
|
+ enquestesT = getAllInds(idTitulacio, idCentre, curs);
|
|
|
|
|
|
|
|
for(IndicadorEnquestaValorDTO i : enquestesT) {
|
|
for(IndicadorEnquestaValorDTO i : enquestesT) {
|
|
|
String indicador = i.getAmbit().equals("t") ? (i.getEnquesta()+"_"+i.getIndicador()) : (i.getEnquesta()+"_"+i.getIndicador()+"_"+i.getAmbit());
|
|
String indicador = i.getAmbit().equals("t") ? (i.getEnquesta()+"_"+i.getIndicador()) : (i.getEnquesta()+"_"+i.getIndicador()+"_"+i.getAmbit());
|
|
@@ -375,10 +362,10 @@ public class DownloadController {
|
|
|
XDocReportRegistry.getRegistry().clear();
|
|
XDocReportRegistry.getRegistry().clear();
|
|
|
String reportId = "none";
|
|
String reportId = "none";
|
|
|
|
|
|
|
|
- Tasca tasca = this.ts.getByProcesTascap(idProces, idTascap);
|
|
|
|
|
- Proces proces= this.ps.findByID(idProces);
|
|
|
|
|
- Organ titulacio = this.os.findByID("T", idTitulacio);
|
|
|
|
|
- Organ centre = this.os.findByID("C", idCentre);
|
|
|
|
|
|
|
+ Tasca tasca = getByProcesTascap(idProces, idTascap);
|
|
|
|
|
+ Proces proces = findByIDProces(idProces);
|
|
|
|
|
+ Organ titulacio = findByIDOrgan("T", idTitulacio);
|
|
|
|
|
+ Organ centre = findByIDOrgan("C", idCentre);
|
|
|
Integer ambit = idTitulacio/(int)1000;
|
|
Integer ambit = idTitulacio/(int)1000;
|
|
|
|
|
|
|
|
/* Check if specific template exists */
|
|
/* Check if specific template exists */
|
|
@@ -417,7 +404,7 @@ public class DownloadController {
|
|
|
|
|
|
|
|
if(tasca.getTipus().getTipus() == 14) { // Iterable template task
|
|
if(tasca.getTipus().getTipus() == 14) { // Iterable template task
|
|
|
List<Organ> titulacions = new ArrayList<Organ>();
|
|
List<Organ> titulacions = new ArrayList<Organ>();
|
|
|
- titulacions = os.getTitulacionsByTypeCentre(centre.getId().getLugar(), ambit);
|
|
|
|
|
|
|
+ titulacions = getTitulacionsByTypeCentre(centre.getId().getLugar(), ambit);
|
|
|
List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
|
|
List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
|
|
|
for(Organ x : titulacions) {
|
|
for(Organ x : titulacions) {
|
|
|
HashMap<String, String> t = getTemplateDataArray(x.getId().getLugar(), idCentre, proces.getCursAvaluat());
|
|
HashMap<String, String> t = getTemplateDataArray(x.getId().getLugar(), idCentre, proces.getCursAvaluat());
|
|
@@ -438,7 +425,7 @@ public class DownloadController {
|
|
|
return out.toByteArray();
|
|
return out.toByteArray();
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
/*
|
|
/*
|
|
|
* Test endpoint to generate a populated template for a given degree and evidence (Type of task)
|
|
* Test endpoint to generate a populated template for a given degree and evidence (Type of task)
|
|
|
* @param model
|
|
* @param model
|
|
@@ -458,8 +445,8 @@ public class DownloadController {
|
|
|
XDocReportRegistry.getRegistry().clear();
|
|
XDocReportRegistry.getRegistry().clear();
|
|
|
String reportId = "none";
|
|
String reportId = "none";
|
|
|
|
|
|
|
|
- Organ titulacio = this.os.findByID("T", idTitulacio);
|
|
|
|
|
- Organ centre = this.os.findByID("C", idCentre);
|
|
|
|
|
|
|
+ Organ titulacio = findByIDOrgan("T", idTitulacio);
|
|
|
|
|
+ Organ centre = findByIDOrgan("C", idCentre);
|
|
|
Integer ambit = idTitulacio/(int)1000;
|
|
Integer ambit = idTitulacio/(int)1000;
|
|
|
|
|
|
|
|
/* Check if specific template exists */
|
|
/* Check if specific template exists */
|
|
@@ -500,7 +487,7 @@ public class DownloadController {
|
|
|
|
|
|
|
|
if(tipusTasca == 14) { // Iterable template task
|
|
if(tipusTasca == 14) { // Iterable template task
|
|
|
List<Organ> titulacions = new ArrayList<Organ>();
|
|
List<Organ> titulacions = new ArrayList<Organ>();
|
|
|
- titulacions = os.getTitulacionsByTypeCentre(centre.getId().getLugar(), ambit);
|
|
|
|
|
|
|
+ titulacions = getTitulacionsByTypeCentre(centre.getId().getLugar(), ambit);
|
|
|
List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
|
|
List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
|
|
|
for(Organ x : titulacions) {
|
|
for(Organ x : titulacions) {
|
|
|
HashMap<String, String> t = getTemplateDataArray(x.getId().getLugar(), idCentre, curs);
|
|
HashMap<String, String> t = getTemplateDataArray(x.getId().getLugar(), idCentre, curs);
|
|
@@ -532,7 +519,7 @@ public class DownloadController {
|
|
|
@GetMapping(value="/pdf/download/{idTascai}")
|
|
@GetMapping(value="/pdf/download/{idTascai}")
|
|
|
@ResponseBody
|
|
@ResponseBody
|
|
|
public byte[] downloadTemplatePdf(Model model, @PathVariable("idTascai") BigInteger idTascai, HttpServletResponse response) throws IOException, InterruptedException {
|
|
public byte[] downloadTemplatePdf(Model model, @PathVariable("idTascai") BigInteger idTascai, HttpServletResponse response) throws IOException, InterruptedException {
|
|
|
- InstanciaTasca it = its.findById(idTascai);
|
|
|
|
|
|
|
+ InstanciaTasca it = findByIdTasca(idTascai);
|
|
|
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\""+it.getIdInstanciaTasca()+".pdf\"");
|
|
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\""+it.getIdInstanciaTasca()+".pdf\"");
|
|
|
response.setHeader(HttpHeaders.CONTENT_TYPE, "application/pdf");
|
|
response.setHeader(HttpHeaders.CONTENT_TYPE, "application/pdf");
|
|
|
return pls.toPDF(it.getText(), Optional.of(idTascai));
|
|
return pls.toPDF(it.getText(), Optional.of(idTascai));
|
|
@@ -551,7 +538,293 @@ public class DownloadController {
|
|
|
@RequestParam("content") String content, @RequestParam("idtascai") Optional<BigInteger> idtascai) throws IOException, InterruptedException {
|
|
@RequestParam("content") String content, @RequestParam("idtascai") Optional<BigInteger> idtascai) throws IOException, InterruptedException {
|
|
|
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"borrador.pdf\"");
|
|
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"borrador.pdf\"");
|
|
|
response.setHeader(HttpHeaders.CONTENT_TYPE, "application/pdf");
|
|
response.setHeader(HttpHeaders.CONTENT_TYPE, "application/pdf");
|
|
|
- return pls.toPDF(content, idtascai);
|
|
|
|
|
|
|
+ return toPDF(content, idtascai);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private TascaInformeTransferDTO getLastByProcName(String nomProces, Integer lugar, Integer lugar2, String tambit) {
|
|
|
|
|
+ URI uriObj = URI.create(uri + "/getLastByProcName");
|
|
|
|
|
+ ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
|
|
|
+ TascaInformeTransferDTO tascaInformeTransferDTO = null;
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ TascaDTO TascaDTO = new TascaDTO(nomProces, lugar, lugar2, tambit);
|
|
|
|
|
+ String requestBody = mapper.writeValueAsString(TascaDTO);
|
|
|
|
|
+ HttpClient httpClient = HttpClient.newHttpClient();
|
|
|
|
|
+ HttpRequest request = HttpRequest.newBuilder()
|
|
|
|
|
+ .uri(uriObj)
|
|
|
|
|
+ .header("Content-Type", "application/json")
|
|
|
|
|
+ .POST(HttpRequest.BodyPublishers.ofString(requestBody))
|
|
|
|
|
+ .build();
|
|
|
|
|
+
|
|
|
|
|
+ HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
|
|
+
|
|
|
|
|
+ if (response.statusCode() == HttpURLConnection.HTTP_OK) {
|
|
|
|
|
+ tascaInformeTransferDTO = mapper.readValue(response.body(), new TypeReference<TascaInformeTransferDTO>() {});
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+ System.err.println("Failed to find enquesta by Curs, Ambit, Estudi. HTTP error code: " + response.statusCode());
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return tascaInformeTransferDTO;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private InstanciaTasca findByIdTasca(BigInteger idInstanciaTasca) {
|
|
|
|
|
+ URI uriObj = URI.create(uri + "/instanciatasca/" + idInstanciaTasca);
|
|
|
|
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
+ InstanciaTasca instanciaTasca = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ HttpClient httpClient = HttpClient.newHttpClient();
|
|
|
|
|
+ HttpRequest request = HttpRequest.newBuilder()
|
|
|
|
|
+ .uri(uriObj)
|
|
|
|
|
+ .GET()
|
|
|
|
|
+ .build();
|
|
|
|
|
+
|
|
|
|
|
+ HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
|
|
+
|
|
|
|
|
+ if (response.statusCode() == HttpURLConnection.HTTP_OK) {
|
|
|
|
|
+ instanciaTasca = mapper.readValue(response.body(), new TypeReference<InstanciaTasca>() {});
|
|
|
|
|
+ } else {
|
|
|
|
|
+ System.err.println("Failed to find InstanciaTasca by ID. HTTP error code: " + response.statusCode());
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return instanciaTasca;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<IndicadorEnquestaValorDTO> getAllInds(Integer idTitulacio, Integer idCentre, Integer curs) {
|
|
|
|
|
+ URI uriObj = URI.create(uri + "/allInds2");
|
|
|
|
|
+ ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
|
|
|
+ List<IndicadorEnquestaValorDTO> list = null;
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ IndicadorEnquestaDTO IndicadorEnquestaDTO = new IndicadorEnquestaDTO(idTitulacio, idCentre, curs);
|
|
|
|
|
+ String requestBody = mapper.writeValueAsString(IndicadorEnquestaDTO);
|
|
|
|
|
+ HttpClient httpClient = HttpClient.newHttpClient();
|
|
|
|
|
+ HttpRequest request = HttpRequest.newBuilder()
|
|
|
|
|
+ .uri(uriObj)
|
|
|
|
|
+ .header("Content-Type", "application/json")
|
|
|
|
|
+ .POST(HttpRequest.BodyPublishers.ofString(requestBody))
|
|
|
|
|
+ .build();
|
|
|
|
|
+
|
|
|
|
|
+ HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
|
|
+
|
|
|
|
|
+ if (response.statusCode() == HttpURLConnection.HTTP_OK) {
|
|
|
|
|
+ list = mapper.readValue(response.body(), new TypeReference<List<IndicadorEnquestaValorDTO>>() {});
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+ System.err.println("Failed to get all IndicadorsEnquestaValorDTO. HTTP error code: " + response.statusCode());
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return list;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Tasca getByProcesTascap(Integer idProces, Integer idTascap) {
|
|
|
|
|
+ URI uriObj = URI.create(uri + "/getByProcesTascap/" + idProces + "/" + idTascap);
|
|
|
|
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
+ Tasca tasca = null;
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+
|
|
|
|
|
+ HttpClient httpClient = HttpClient.newHttpClient();
|
|
|
|
|
+ HttpRequest request = HttpRequest.newBuilder()
|
|
|
|
|
+ .uri(uriObj)
|
|
|
|
|
+ .GET()
|
|
|
|
|
+ .build();
|
|
|
|
|
+
|
|
|
|
|
+ HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
|
|
+
|
|
|
|
|
+ if (response.statusCode() == HttpURLConnection.HTTP_OK) {
|
|
|
|
|
+ tasca = mapper.readValue(response.body(), new TypeReference<Tasca>() {});
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+ System.err.println("Failed to get Tasca. HTTP error code: " + response.statusCode());
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return tasca;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ private List<Indicador> getFromTitulacion(Integer idTitulacio, Integer curs) {
|
|
|
|
|
+ URI uriObj = URI.create(uri + "/getFromTitulacio/" + idTitulacio + "/" + curs);
|
|
|
|
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
+ List<Indicador> inds = new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+
|
|
|
|
|
+ HttpClient httpClient = HttpClient.newHttpClient();
|
|
|
|
|
+ HttpRequest request = HttpRequest.newBuilder()
|
|
|
|
|
+ .uri(uriObj)
|
|
|
|
|
+ .GET()
|
|
|
|
|
+ .build();
|
|
|
|
|
+
|
|
|
|
|
+ HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
|
|
+
|
|
|
|
|
+ if (response.statusCode() == HttpURLConnection.HTTP_OK) {
|
|
|
|
|
+ inds = mapper.readValue(response.body(), new TypeReference<List<Indicador>>() {});
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+ System.err.println("Failed to getFromTitulacion. HTTP error code: " + response.statusCode());
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return inds;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Proces findByIDProces(Integer idProces) {
|
|
|
|
|
+ URI uriObj = URI.create(uri + "/proces/" + idProces);
|
|
|
|
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
+ Proces proces = null;
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+
|
|
|
|
|
+ HttpClient httpClient = HttpClient.newHttpClient();
|
|
|
|
|
+ HttpRequest request = HttpRequest.newBuilder()
|
|
|
|
|
+ .uri(uriObj)
|
|
|
|
|
+ .GET()
|
|
|
|
|
+ .build();
|
|
|
|
|
+
|
|
|
|
|
+ HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
|
|
+
|
|
|
|
|
+ if (response.statusCode() == HttpURLConnection.HTTP_OK) {
|
|
|
|
|
+ proces = mapper.readValue(response.body(), new TypeReference<Proces>() {});
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+ System.err.println("Failed to find proces byID. HTTP error code: " + response.statusCode());
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return proces;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private Organ findByIDOrgan(String tlugar, Integer idTitulacio) {
|
|
|
|
|
+ URI uriObj = URI.create(uri + "/proces/" + tlugar + "/" + idTitulacio);
|
|
|
|
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
+ Organ organ = null;
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+
|
|
|
|
|
+ HttpClient httpClient = HttpClient.newHttpClient();
|
|
|
|
|
+ HttpRequest request = HttpRequest.newBuilder()
|
|
|
|
|
+ .uri(uriObj)
|
|
|
|
|
+ .GET()
|
|
|
|
|
+ .build();
|
|
|
|
|
+
|
|
|
|
|
+ HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
|
|
+
|
|
|
|
|
+ if (response.statusCode() == HttpURLConnection.HTTP_OK) {
|
|
|
|
|
+ organ = mapper.readValue(response.body(), new TypeReference<Organ>() {});
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+ System.err.println("Failed to find proces byID. HTTP error code: " + response.statusCode());
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return organ;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<Organ> getTitulacionsByTypeCentre(Integer lugar, Integer ambit) {
|
|
|
|
|
+ URI uriObj = URI.create(uri + "/getTitulacionsByTypeCentre/" + lugar + "/" + ambit);
|
|
|
|
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
+ List<Organ> organs = new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+
|
|
|
|
|
+ HttpClient httpClient = HttpClient.newHttpClient();
|
|
|
|
|
+ HttpRequest request = HttpRequest.newBuilder()
|
|
|
|
|
+ .uri(uriObj)
|
|
|
|
|
+ .GET()
|
|
|
|
|
+ .build();
|
|
|
|
|
+
|
|
|
|
|
+ HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
|
|
+
|
|
|
|
|
+ if (response.statusCode() == HttpURLConnection.HTTP_OK) {
|
|
|
|
|
+ organs = mapper.readValue(response.body(), new TypeReference<List<Organ>>() {});
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+ System.err.println("Failed to find proces byID. HTTP error code: " + response.statusCode());
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return organs;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
+ private Document findByIdDocument(Integer idDocument) {
|
|
|
|
|
+ URI uriObj = URI.create(uri + "/document/" + idDocument);
|
|
|
|
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
+ Document document = null;
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+
|
|
|
|
|
+ HttpClient httpClient = HttpClient.newHttpClient();
|
|
|
|
|
+ HttpRequest request = HttpRequest.newBuilder()
|
|
|
|
|
+ .uri(uriObj)
|
|
|
|
|
+ .GET()
|
|
|
|
|
+ .build();
|
|
|
|
|
+
|
|
|
|
|
+ HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
|
|
+
|
|
|
|
|
+ if (response.statusCode() == HttpURLConnection.HTTP_OK) {
|
|
|
|
|
+ document = mapper.readValue(response.body(), new TypeReference<Document>() {});
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+ System.err.println("Failed to find proces byID. HTTP error code: " + response.statusCode());
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return document;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private byte[] toPDF(String content, Optional<BigInteger> idtascai) {
|
|
|
|
|
+ URI uriObj = URI.create(uri + "/toPDF/");
|
|
|
|
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
+ byte[] pdf = null;
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ PdfDTO pdfDTO = new PdfDTO(content, idtascai);
|
|
|
|
|
+ String requestBody = mapper.writeValueAsString(pdfDTO);
|
|
|
|
|
+
|
|
|
|
|
+ HttpClient httpClient = HttpClient.newHttpClient();
|
|
|
|
|
+ HttpRequest request = HttpRequest.newBuilder()
|
|
|
|
|
+ .uri(uriObj)
|
|
|
|
|
+ .header("Content-Type", "application/json")
|
|
|
|
|
+ .POST(HttpRequest.BodyPublishers.ofString(requestBody))
|
|
|
|
|
+ .build();
|
|
|
|
|
+
|
|
|
|
|
+ HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
|
|
+
|
|
|
|
|
+ if (response.statusCode() == HttpURLConnection.HTTP_OK) {
|
|
|
|
|
+ pdf = mapper.readValue(response.body(), new TypeReference<byte[]>() {});
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+ System.err.println("Failed to find proces byID. HTTP error code: " + response.statusCode());
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return pdf;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|