|
|
@@ -21,9 +21,11 @@ import jakarta.servlet.http.HttpServletResponse;
|
|
|
import org.apache.commons.io.FilenameUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.boot.actuate.autoconfigure.observation.ObservationProperties.Http;
|
|
|
import org.springframework.core.io.FileSystemResource;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
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;
|
|
|
@@ -46,7 +48,7 @@ import es.uv.saic.dto.CategoriaDTO;
|
|
|
import es.uv.saic.dto.IndicadorEnquestaDTO;
|
|
|
import es.uv.saic.dto.IndicadorEnquestaValorDTO;
|
|
|
import es.uv.saic.dto.PdfDTO;
|
|
|
-import es.uv.saic.dto.TascaDTO;
|
|
|
+import es.uv.saic.dto.ProcesDTO;
|
|
|
import es.uv.saic.dto.TascaInformeTransferDTO;
|
|
|
import es.uv.saic.service.PlantillaService;
|
|
|
import fr.opensagres.xdocreport.core.XDocReportException;
|
|
|
@@ -84,6 +86,12 @@ public class DownloadController {
|
|
|
@Value("${saic.url.domain}")
|
|
|
private String uri;
|
|
|
|
|
|
+ @Value("${saic.url.docs.domain}")
|
|
|
+ private String uriDocs;
|
|
|
+
|
|
|
+ private final HttpClient httpClient = HttpClient.newHttpClient();
|
|
|
+ private final ObjectMapper mapper = new ObjectMapper();
|
|
|
+
|
|
|
/*
|
|
|
* Download a file associated with a task instance
|
|
|
* @param model
|
|
|
@@ -93,28 +101,29 @@ 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);
|
|
|
- FileSystemResource r = null;
|
|
|
- if(i.getTasca().getTipus().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());
|
|
|
- }
|
|
|
-
|
|
|
- if(!r.exists()) {
|
|
|
- FileNotFoundException e = new FileNotFoundException("No se ha podido encontrar el archivo solicitado");
|
|
|
- e.setStackTrace(new StackTraceElement[0]);
|
|
|
- throw e;
|
|
|
- }
|
|
|
+ public FileSystemResource download(Model model, @PathVariable("fileName") BigInteger idInstanciaTasca) throws FileNotFoundException {
|
|
|
+ FileSystemResource file = null;
|
|
|
+ try {
|
|
|
+ HttpRequest request = HttpRequest.newBuilder()
|
|
|
+ .uri(URI.create(uriDocs + "/download/" + idInstanciaTasca))
|
|
|
+ .header("Content-Type", "application/json")
|
|
|
+ .GET()
|
|
|
+ .build();
|
|
|
+
|
|
|
+ HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
+ if (response.statusCode() == HttpURLConnection.HTTP_OK){
|
|
|
+ file = mapper.readValue(response.body(), new TypeReference<FileSystemResource>(){});
|
|
|
+
|
|
|
+ } else {
|
|
|
+ System.err.println("Failed to download the files. HTTP error code: " + response.statusCode());
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
|
|
|
- return r;
|
|
|
- }
|
|
|
+ return file;
|
|
|
+ }
|
|
|
|
|
|
/*
|
|
|
* Download a document by its ID
|
|
|
@@ -125,16 +134,26 @@ 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 {
|
|
|
- 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;
|
|
|
- }
|
|
|
-
|
|
|
- response.setHeader("Content-Disposition", "attachment; filename="+file.getFilename());
|
|
|
+ public FileSystemResource downloadDocument(Model model, @PathVariable("id") Integer idDocument) throws FileNotFoundException {
|
|
|
+ FileSystemResource file = null;
|
|
|
+ try {
|
|
|
+ HttpRequest request = HttpRequest.newBuilder()
|
|
|
+ .uri(URI.create(uriDocs + "/download/document/" + idDocument))
|
|
|
+ .header("Content-Type", "application/json")
|
|
|
+ .GET()
|
|
|
+ .build();
|
|
|
+
|
|
|
+ HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
+ if (response.statusCode() == HttpURLConnection.HTTP_OK){
|
|
|
+ file = mapper.readValue(response.body(), new TypeReference<FileSystemResource>(){});
|
|
|
+
|
|
|
+ } else {
|
|
|
+ System.err.println("Failed to download the files. HTTP error code: " + response.statusCode());
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
return file;
|
|
|
}
|
|
|
|
|
|
@@ -148,23 +167,27 @@ 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,
|
|
|
- HttpServletResponse response) throws IOException, XDocReportException {
|
|
|
-
|
|
|
- Organ titulacio = findByIDOrgan("T", idTitulacio);
|
|
|
-
|
|
|
- TascaInformeTransferDTO it = getLastByProcName(nomProces, titulacio.getId().getLugar(),
|
|
|
- titulacio.getOrgan().getId().getLugar(),
|
|
|
- titulacio.getOrgan().getTambit());
|
|
|
-
|
|
|
- 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());
|
|
|
+ public FileSystemResource downloadReport(Model model, @PathVariable("t") Integer idTitulacio, @PathVariable("p") String nomProces) throws IOException, XDocReportException {
|
|
|
+ FileSystemResource file = null;
|
|
|
+ try {
|
|
|
+ HttpRequest request = HttpRequest.newBuilder()
|
|
|
+ .uri(URI.create(uriDocs + "/download/report/" + idTitulacio + "/" + nomProces))
|
|
|
+ .header("Content-Type", "application/json")
|
|
|
+ .GET()
|
|
|
+ .build();
|
|
|
+
|
|
|
+ HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
+ if (response.statusCode() == HttpURLConnection.HTTP_OK){
|
|
|
+ file = mapper.readValue(response.body(), new TypeReference<FileSystemResource>(){});
|
|
|
+
|
|
|
+ } else {
|
|
|
+ System.err.println("Failed to download the report. HTTP error code: " + response.statusCode());
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- return new FileSystemResource(this.fileNotFound);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return file;
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -177,171 +200,27 @@ 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 {
|
|
|
- XDocReportRegistry.getRegistry().clear();
|
|
|
- String reportId = "none";
|
|
|
- InstanciaTasca it = findByIdTasca(idTascai);
|
|
|
- Tasca 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) {
|
|
|
- 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) {
|
|
|
- File f = new File(this.templatePath+"/T2/"+tasca.getCodiEvidencia().replace(".", "_")+".docx");
|
|
|
- if(f.exists() && !f.isDirectory()) {
|
|
|
- templatePath = this.templatePath+"/T2/"+tasca.getCodiEvidencia().replace(".", "_")+".docx";
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- 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;
|
|
|
- }
|
|
|
-
|
|
|
- InputStream in = new FileInputStream(f);
|
|
|
- IXDocReport report = XDocReportRegistry.getRegistry().loadReport(in, reportId, TemplateEngineKind.Velocity);
|
|
|
- FieldsMetadata metadata = new FieldsMetadata();
|
|
|
- metadata.addFieldAsImage("logo");
|
|
|
- report.setFieldsMetadata(metadata);
|
|
|
- IContext context = report.createContext();
|
|
|
- IImageProvider img;
|
|
|
- if(new File(this.logoPath+"C"+Integer.toString(it.getInstancia().getCentre())+".png").exists()) {
|
|
|
- img = new FileImageProvider(new File(this.logoPath+"C"+Integer.toString(it.getInstancia().getCentre())+".png"));
|
|
|
- }
|
|
|
- else {
|
|
|
- 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));
|
|
|
-
|
|
|
- Proces proces = it.getInstancia().getProces();
|
|
|
- Integer idCentre = it.getInstancia().getCentre();
|
|
|
-
|
|
|
- if(tasca.getTipus().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);
|
|
|
- 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());
|
|
|
- t.put("titulacio", x.getNomCas());
|
|
|
- data.add(t);
|
|
|
- }
|
|
|
- context.put("data", data);
|
|
|
- getTemplateData(idTitulacio, idCentre, proces.getCursAvaluat(), context);
|
|
|
- }
|
|
|
- else { // NO iterable template task
|
|
|
- getTemplateData(idTitulacio, idCentre, proces.getCursAvaluat(), context);
|
|
|
- }
|
|
|
-
|
|
|
- ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
|
- report.process(context, out);
|
|
|
- response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\""+tasca.getCodiEvidencia()+".docx\"");
|
|
|
+ public byte[] downloadTemplate(Model model, @PathVariable("id") BigInteger idTascai) throws IOException, XDocReportException {
|
|
|
+ byte[] file = null;
|
|
|
+ try {
|
|
|
+ HttpRequest request = HttpRequest.newBuilder()
|
|
|
+ .uri(URI.create(uriDocs + "/download/template/" + idTascai))
|
|
|
+ .header("Content-Type", "application/json")
|
|
|
+ .GET()
|
|
|
+ .build();
|
|
|
|
|
|
- return out.toByteArray();
|
|
|
-
|
|
|
- }
|
|
|
+ HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
+ if (response.statusCode() == HttpURLConnection.HTTP_OK){
|
|
|
+ file = mapper.readValue(response.body(), new TypeReference<byte[]>(){});
|
|
|
|
|
|
- /*
|
|
|
- * Populate the template data into the context
|
|
|
- * @param idTitulacio The ID of the degree
|
|
|
- * @param idCentre The ID of the center
|
|
|
- * @param curs The academic year
|
|
|
- * @param context The IContext to populate
|
|
|
- */
|
|
|
- private void getTemplateData(Integer idTitulacio, Integer idCentre, Integer curs, IContext context) {
|
|
|
-
|
|
|
- /* Indicadores del data warehouse */
|
|
|
- try {
|
|
|
- List<Indicador> indicadores;
|
|
|
- indicadores = getFromTitulacion(idTitulacio, curs);
|
|
|
- for(Indicador i : indicadores) {
|
|
|
- context.put(i.getIndicador(), i.getValor());
|
|
|
+ } else {
|
|
|
+ System.err.println("Failed to download the template. HTTP error code: " + response.statusCode());
|
|
|
}
|
|
|
- }
|
|
|
- catch(Exception e) { }
|
|
|
-
|
|
|
- /* Indicadores de encuestas */
|
|
|
- List<IndicadorEnquestaValorDTO> enquestesT;
|
|
|
- enquestesT = getAllInds(idTitulacio, idCentre, curs);
|
|
|
-
|
|
|
- for(IndicadorEnquestaValorDTO i : enquestesT) {
|
|
|
- String indicador = i.getAmbit().equals("t") ? (i.getEnquesta()+"_"+i.getIndicador()) : (i.getEnquesta()+"_"+i.getIndicador()+"_"+i.getAmbit());
|
|
|
- indicador = i.getTipus().equals("avg") ? indicador : (indicador += "_"+i.getTipus());
|
|
|
- indicador = i.getCursd() == null ? indicador : (indicador += "_"+i.getCursd());
|
|
|
- context.put(indicador, formatValue(i.getValor()));
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- /*
|
|
|
- * Format a value for template insertion
|
|
|
- * @param v The value to format
|
|
|
- * @return The formatted value
|
|
|
- */
|
|
|
- private String formatValue(String v) {
|
|
|
- if(v == null) return "";
|
|
|
- if(v.equals("NP")) return "NP";
|
|
|
- if(v.isEmpty() | v.isBlank()) {
|
|
|
- return "";
|
|
|
- }
|
|
|
-
|
|
|
- try{
|
|
|
- return String.format("%.2f", Float.parseFloat(v)).replace(",", ".");
|
|
|
- }
|
|
|
- catch(NumberFormatException e){ }
|
|
|
-
|
|
|
- try{
|
|
|
- return Integer.toString(Integer.parseInt(v));
|
|
|
- }
|
|
|
- catch(NumberFormatException e){ }
|
|
|
-
|
|
|
- return v;
|
|
|
- }
|
|
|
-
|
|
|
- /*
|
|
|
- * Get template data as a HashMap
|
|
|
- * @param idTitulacio The ID of the degree
|
|
|
- * @param idCentre The ID of the center
|
|
|
- * @param curs The academic year
|
|
|
- * @return A HashMap containing the template data
|
|
|
- */
|
|
|
- private HashMap<String, String> getTemplateDataArray(Integer idTitulacio, Integer idCentre, Integer curs) {
|
|
|
-
|
|
|
- HashMap<String, String> info = new HashMap<String, String>();
|
|
|
-
|
|
|
- /* Indicadores del data warehouse */
|
|
|
- try {
|
|
|
- List<Indicador> indicadores;
|
|
|
- indicadores = getFromTitulacion(idTitulacio, curs);
|
|
|
- for(Indicador i : indicadores) {
|
|
|
- info.put(i.getIndicador(), i.getValor());
|
|
|
- }
|
|
|
- }
|
|
|
- catch(Exception e) { }
|
|
|
-
|
|
|
- /* Indicadores de encuestas */
|
|
|
- List<IndicadorEnquestaValorDTO> enquestesT;
|
|
|
- enquestesT = getAllInds(idTitulacio, idCentre, curs);
|
|
|
-
|
|
|
- for(IndicadorEnquestaValorDTO i : enquestesT) {
|
|
|
- String indicador = i.getAmbit().equals("t") ? (i.getEnquesta()+"_"+i.getIndicador()) : (i.getEnquesta()+"_"+i.getIndicador()+"_"+i.getAmbit());
|
|
|
- indicador = i.getTipus().equals("avg") ? indicador : (indicador += "_"+i.getTipus());
|
|
|
- indicador = i.getCursd() == null ? indicador : (indicador += "_"+i.getCursd());
|
|
|
- info.put(indicador, formatValue(i.getValor()));
|
|
|
- }
|
|
|
-
|
|
|
- return info;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return file;
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -357,73 +236,28 @@ 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,
|
|
|
- @PathVariable("idTascap") Integer idTascap, @PathVariable("idProces") Integer idProces, HttpServletResponse response)
|
|
|
+ @PathVariable("idTascap") Integer idTascap, @PathVariable("idProces") Integer idProces)
|
|
|
throws IOException, XDocReportException {
|
|
|
- XDocReportRegistry.getRegistry().clear();
|
|
|
- String reportId = "none";
|
|
|
-
|
|
|
- Tasca tasca = getByProcesTascap(idProces, idTascap);
|
|
|
- Proces proces = findByIDProces(idProces);
|
|
|
- Organ titulacio = findByIDOrgan("T", idTitulacio);
|
|
|
- Organ centre = findByIDOrgan("C", idCentre);
|
|
|
- Integer ambit = idTitulacio/(int)1000;
|
|
|
-
|
|
|
- /* Check if specific template exists */
|
|
|
- String templatePath = this.templatePath+tasca.getCodiEvidencia().replace(".", "_")+".docx";
|
|
|
- if(titulacio.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(titulacio.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";
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- InputStream in = new FileInputStream(new File(templatePath));
|
|
|
- IXDocReport report = XDocReportRegistry.getRegistry().loadReport(in, reportId, TemplateEngineKind.Velocity);
|
|
|
- FieldsMetadata metadata = new FieldsMetadata();
|
|
|
- metadata.addFieldAsImage("logo");
|
|
|
- report.setFieldsMetadata(metadata);
|
|
|
- IContext context = report.createContext();
|
|
|
- IImageProvider img;
|
|
|
- if(new File(this.logoPath+"C"+Integer.toString(idCentre)+".png").exists()) {
|
|
|
- img = new FileImageProvider(new File(this.logoPath+"C"+Integer.toString(idCentre)+".png"));
|
|
|
- }
|
|
|
- else {
|
|
|
- img = new FileImageProvider(new File(this.logoPath+"C0.png"));
|
|
|
- }
|
|
|
- context.put("logo", img);
|
|
|
- context.put("centre", centre.getNomVal());
|
|
|
- context.put("titulacio", titulacio.getNomVal());
|
|
|
- context.put("curs", Integer.toString(proces.getCursAvaluat()-1)+" - "+Integer.toString(proces.getCursAvaluat()));
|
|
|
- context.put("curs_anterior", Integer.toString(proces.getCursAvaluat()-2)+" - "+Integer.toString(proces.getCursAvaluat()-1));
|
|
|
-
|
|
|
- if(tasca.getTipus().getTipus() == 14) { // Iterable template task
|
|
|
- List<Organ> titulacions = new ArrayList<Organ>();
|
|
|
- titulacions = getTitulacionsByTypeCentre(centre.getId().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());
|
|
|
- t.put("titulacio", x.getNomCas());
|
|
|
- data.add(t);
|
|
|
+ byte[] file = null;
|
|
|
+ try {
|
|
|
+ HttpRequest request = HttpRequest.newBuilder()
|
|
|
+ .uri(URI.create(uriDocs + "/test/template/" + idTitulacio + "/" + idCentre + "/" + idProces + "/" + idTascap))
|
|
|
+ .header("Content-Type", "application/json")
|
|
|
+ .GET()
|
|
|
+ .build();
|
|
|
+
|
|
|
+ HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
+ if (response.statusCode() == HttpURLConnection.HTTP_OK){
|
|
|
+ file = mapper.readValue(response.body(), new TypeReference<byte[]>(){});
|
|
|
+
|
|
|
+ } else {
|
|
|
+ System.err.println("Failed to download the test template. HTTP error code: " + response.statusCode());
|
|
|
}
|
|
|
- context.put("data", data);
|
|
|
- getTemplateData(idTitulacio, idCentre, proces.getCursAvaluat(), context);
|
|
|
- }
|
|
|
- else { // NO iterable template task
|
|
|
- getTemplateData(idTitulacio, idCentre, proces.getCursAvaluat(), context);
|
|
|
- }
|
|
|
-
|
|
|
- ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
|
- report.process(context, out);
|
|
|
- response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\""+tasca.getCodiEvidencia()+".docx\"");
|
|
|
|
|
|
- return out.toByteArray();
|
|
|
-
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return file;
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -440,73 +274,27 @@ 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,
|
|
|
- @PathVariable("evidencia") String evidencia, @PathVariable("curs") Integer curs, @PathVariable("tipusTasca") Integer tipusTasca,
|
|
|
- HttpServletResponse response) throws IOException, XDocReportException {
|
|
|
- XDocReportRegistry.getRegistry().clear();
|
|
|
- String reportId = "none";
|
|
|
-
|
|
|
- Organ titulacio = findByIDOrgan("T", idTitulacio);
|
|
|
- Organ centre = findByIDOrgan("C", idCentre);
|
|
|
- Integer ambit = idTitulacio/(int)1000;
|
|
|
-
|
|
|
- /* Check if specific template exists */
|
|
|
- String templatePath = this.templatePath+evidencia.replace(".", "_").replace(" (G)", "").replace(" (M)", "")+".docx";
|
|
|
- if(idTitulacio < 2000 | idTitulacio == 1) {
|
|
|
- File f = new File(this.templatePath+"/T1/"+evidencia.replace(".", "_").replace(" (G)", "").replace(" (M)", "")+".docx");
|
|
|
- if(f.exists() && !f.isDirectory()) {
|
|
|
- templatePath = this.templatePath+"/T1/"+evidencia.replace(".", "_").replace(" (G)", "").replace(" (M)", "")+".docx";
|
|
|
- }
|
|
|
- ambit = 1;
|
|
|
- }
|
|
|
- else if((idTitulacio >= 2000 & idTitulacio < 3000) | idTitulacio == 2) {
|
|
|
- File f = new File(this.templatePath+"/T2/"+evidencia.replace(".", "_").replace(" (G)", "").replace(" (M)", "")+".docx");
|
|
|
- if(f.exists() && !f.isDirectory()) {
|
|
|
- templatePath = this.templatePath+"/T2/"+evidencia.replace(".", "_").replace(" (G)", "").replace(" (M)", "")+".docx";
|
|
|
- }
|
|
|
- ambit = 2;
|
|
|
- }
|
|
|
-
|
|
|
- InputStream in = new FileInputStream(new File(templatePath));
|
|
|
- IXDocReport report = XDocReportRegistry.getRegistry().loadReport(in, reportId, TemplateEngineKind.Velocity);
|
|
|
- FieldsMetadata metadata = new FieldsMetadata();
|
|
|
- metadata.addFieldAsImage("logo");
|
|
|
- report.setFieldsMetadata(metadata);
|
|
|
- IContext context = report.createContext();
|
|
|
- IImageProvider img;
|
|
|
- if(new File(this.logoPath+"C"+Integer.toString(idCentre)+".png").exists()) {
|
|
|
- img = new FileImageProvider(new File(this.logoPath+"C"+Integer.toString(idCentre)+".png"));
|
|
|
- }
|
|
|
- else {
|
|
|
- img = new FileImageProvider(new File(this.logoPath+"C0.png"));
|
|
|
- }
|
|
|
- context.put("logo", img);
|
|
|
- context.put("centre", centre.getNomVal());
|
|
|
- context.put("titulacio", titulacio.getNomVal());
|
|
|
- context.put("curs", Integer.toString(curs-1)+" - "+Integer.toString(curs));
|
|
|
- context.put("curs_anterior", Integer.toString(curs-2)+" - "+Integer.toString(curs-1));
|
|
|
-
|
|
|
- if(tipusTasca == 14) { // Iterable template task
|
|
|
- List<Organ> titulacions = new ArrayList<Organ>();
|
|
|
- titulacions = getTitulacionsByTypeCentre(centre.getId().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, curs);
|
|
|
- t.put("titulacio", x.getNomCas());
|
|
|
- data.add(t);
|
|
|
+ @PathVariable("evidencia") String evidencia, @PathVariable("curs") Integer curs, @PathVariable("tipusTasca") Integer tipusTasca) throws IOException, XDocReportException {
|
|
|
+ byte[] file = null;
|
|
|
+ try {
|
|
|
+ HttpRequest request = HttpRequest.newBuilder()
|
|
|
+ .uri(URI.create(uriDocs + "/test/template2/" + idTitulacio + "/" + idCentre + "/" + evidencia + "/" + curs + "/" + tipusTasca))
|
|
|
+ .header("Content-Type", "application/json")
|
|
|
+ .GET()
|
|
|
+ .build();
|
|
|
+
|
|
|
+ HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
+ if (response.statusCode() == HttpURLConnection.HTTP_OK){
|
|
|
+ file = mapper.readValue(response.body(), new TypeReference<byte[]>(){});
|
|
|
+
|
|
|
+ } else {
|
|
|
+ System.err.println("Failed to download the test template. HTTP error code: " + response.statusCode());
|
|
|
}
|
|
|
- context.put("data", data);
|
|
|
- getTemplateData(idTitulacio, idCentre, curs, context);
|
|
|
- }
|
|
|
- else { // NO iterable template task
|
|
|
- getTemplateData(idTitulacio, idCentre, curs, context);
|
|
|
- }
|
|
|
-
|
|
|
- ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
|
- report.process(context, out);
|
|
|
- response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\""+evidencia+".docx\"");
|
|
|
|
|
|
- return out.toByteArray();
|
|
|
-
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return file;
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -518,11 +306,27 @@ 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);
|
|
|
- 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));
|
|
|
+ public byte[] downloadTemplatePdf(Model model, @PathVariable("idTascai") BigInteger idTascai) throws IOException, InterruptedException {
|
|
|
+ byte[] file = null;
|
|
|
+ try {
|
|
|
+ HttpRequest request = HttpRequest.newBuilder()
|
|
|
+ .uri(URI.create(uriDocs + "/pdf/download/" + idTascai))
|
|
|
+ .header("Content-Type", "application/json")
|
|
|
+ .GET()
|
|
|
+ .build();
|
|
|
+
|
|
|
+ HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
+ if (response.statusCode() == HttpURLConnection.HTTP_OK){
|
|
|
+ file = mapper.readValue(response.body(), new TypeReference<byte[]>(){});
|
|
|
+
|
|
|
+ } else {
|
|
|
+ System.err.println("Failed to download the test template PDF. HTTP error code: " + response.statusCode());
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return file;
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -534,297 +338,29 @@ public class DownloadController {
|
|
|
*/
|
|
|
@PostMapping(value="/pdf/preview")
|
|
|
@ResponseBody
|
|
|
- public byte[] downloadTemplatePdf(Model model, HttpServletResponse response,
|
|
|
+ public byte[] downloadTemplatePdf(Model model,
|
|
|
@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_TYPE, "application/pdf");
|
|
|
- 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;
|
|
|
-
|
|
|
+ byte[] file = null;
|
|
|
+ PdfDTO pdf = new PdfDTO(content, idtascai);
|
|
|
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();
|
|
|
+ String requestBody = mapper.writeValueAsString(pdf);
|
|
|
+ HttpRequest request = HttpRequest.newBuilder()
|
|
|
+ .uri(URI.create(uriDocs + "/pdf/preview"))
|
|
|
+ .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>>() {});
|
|
|
+ HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
+ if (response.statusCode() == HttpURLConnection.HTTP_OK){
|
|
|
+ file = mapper.readValue(response.body(), new TypeReference<byte[]>(){});
|
|
|
|
|
|
} else {
|
|
|
- System.err.println("Failed to find proces byID. HTTP error code: " + response.statusCode());
|
|
|
+ System.err.println("Failed to preview the PDF. 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;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return file;
|
|
|
}
|
|
|
}
|