|
|
@@ -6,12 +6,6 @@ import java.io.FileNotFoundException;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
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.nio.file.Files;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
@@ -28,7 +22,6 @@ import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
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;
|
|
|
@@ -36,17 +29,11 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|
|
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;
|
|
|
-import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
-
|
|
|
import es.uv.saic.domain.Document;
|
|
|
import es.uv.saic.domain.Indicador;
|
|
|
-import es.uv.saic.domain.InstanciaTasca;
|
|
|
import es.uv.saic.domain.Organ;
|
|
|
import es.uv.saic.domain.Proces;
|
|
|
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;
|
|
|
@@ -54,6 +41,8 @@ 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.feign.CoreClient;
|
|
|
+import es.uv.saic.service.DocumentService;
|
|
|
import es.uv.saic.service.PlantillaService;
|
|
|
import fr.opensagres.xdocreport.core.XDocReportException;
|
|
|
import fr.opensagres.xdocreport.core.io.internal.ByteArrayOutputStream;
|
|
|
@@ -64,7 +53,6 @@ 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
|
|
|
@@ -72,6 +60,9 @@ public class DownloadController {
|
|
|
|
|
|
@Autowired
|
|
|
private PlantillaService pls;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DocumentService ds;
|
|
|
|
|
|
@Value("${saic.data.filePath}")
|
|
|
private String filePath;
|
|
|
@@ -91,6 +82,9 @@ public class DownloadController {
|
|
|
@Value("${saic.url.core.domain}")
|
|
|
private String uri;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private CoreClient core;
|
|
|
+
|
|
|
/*
|
|
|
* Download a file associated with a task instance
|
|
|
* @param model
|
|
|
@@ -103,7 +97,7 @@ public class DownloadController {
|
|
|
public byte[] download(@PathVariable("fileName") BigInteger idInstanciaTasca, HttpServletResponse response) throws FileNotFoundException {
|
|
|
|
|
|
try {
|
|
|
- InstanciaTascaDTO i = findByIdTasca(idInstanciaTasca);
|
|
|
+ InstanciaTascaDTO i = core.findInstanciaTascaById(idInstanciaTasca);
|
|
|
FileSystemResource file = null;
|
|
|
if(i.getTasca().getTipus() == 22){
|
|
|
file = new FileSystemResource(i.getEvidencia());
|
|
|
@@ -140,7 +134,7 @@ public class DownloadController {
|
|
|
@GetMapping(value="/download/document/{id}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
|
|
|
@ResponseBody
|
|
|
public ResponseEntity<FileSystemResource> downloadDocument(@PathVariable("id") Integer idDocument, HttpServletResponse response) throws FileNotFoundException {
|
|
|
- Document document = findByIdDocument(idDocument);
|
|
|
+ Document document = ds.findById(idDocument);
|
|
|
FileSystemResource file = new FileSystemResource(document.getRuta());
|
|
|
if(!file.exists()) {
|
|
|
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
|
|
|
@@ -163,11 +157,12 @@ public class DownloadController {
|
|
|
public ResponseEntity<FileSystemResource> downloadReport(@PathVariable("t") Integer idTitulacio, @PathVariable("p") String nomProces,
|
|
|
HttpServletResponse response) throws IOException, XDocReportException {
|
|
|
|
|
|
- Organ titulacio = findByIDOrgan("T", idTitulacio);
|
|
|
+ Organ titulacio = core.findOrganById("T", idTitulacio);
|
|
|
|
|
|
- TascaInformeTransferDTO it = getLastByProcName(nomProces, titulacio.getId().getLugar(),
|
|
|
+ ProcesDTO procesDTO = new ProcesDTO(nomProces, titulacio.getId().getLugar(),
|
|
|
titulacio.getOrgan().getId().getLugar(),
|
|
|
titulacio.getOrgan().getTambit());
|
|
|
+ TascaInformeTransferDTO it = core.getLastByProcName(procesDTO);
|
|
|
|
|
|
if(it != null) {
|
|
|
if((new File(this.filePath+it.getEvidencia())).exists()) {
|
|
|
@@ -192,7 +187,7 @@ public class DownloadController {
|
|
|
public byte[] downloadTemplate(@PathVariable("id") BigInteger idTascai, HttpServletResponse response) throws IOException, XDocReportException {
|
|
|
XDocReportRegistry.getRegistry().clear();
|
|
|
String reportId = "none";
|
|
|
- InstanciaTascaDTO it = findByIdTasca(idTascai);
|
|
|
+ InstanciaTascaDTO it = core.findInstanciaTascaById(idTascai);
|
|
|
TascaDTO tasca = it.getTasca();
|
|
|
|
|
|
/* Check if specific template exists */
|
|
|
@@ -240,7 +235,7 @@ public class DownloadController {
|
|
|
if(tasca.getTipus() == 14) { // Iterable template task
|
|
|
List<Organ> titulacions = new ArrayList<Organ>();
|
|
|
Integer ambit = idTitulacio/(int)1000;
|
|
|
- titulacions = getTitulacionsByTypeCentre(it.getInstancia().getLugar(), ambit);
|
|
|
+ titulacions = core.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, it.getInstancia().getCursAvaluat());
|
|
|
@@ -274,7 +269,7 @@ public class DownloadController {
|
|
|
/* Indicadores del data warehouse */
|
|
|
try {
|
|
|
List<Indicador> indicadores;
|
|
|
- indicadores = getFromTitulacion(idTitulacio, curs);
|
|
|
+ indicadores = core.getFromTitulacion(idTitulacio, curs);
|
|
|
for(Indicador i : indicadores) {
|
|
|
context.put(i.getIndicador(), i.getValor());
|
|
|
}
|
|
|
@@ -283,7 +278,8 @@ public class DownloadController {
|
|
|
|
|
|
/* Indicadores de encuestas */
|
|
|
List<IndicadorEnquestaValorDTO> enquestesT;
|
|
|
- enquestesT = getAllInds(idTitulacio, idCentre, curs);
|
|
|
+ IndicadorEnquestaDTO iEnquestaDTO = new IndicadorEnquestaDTO(idTitulacio, idCentre, curs);
|
|
|
+ enquestesT = core.getAllInds2(iEnquestaDTO);
|
|
|
|
|
|
for(IndicadorEnquestaValorDTO i : enquestesT) {
|
|
|
String indicador = i.getAmbit().equals("t") ? (i.getEnquesta()+"_"+i.getIndicador()) : (i.getEnquesta()+"_"+i.getIndicador()+"_"+i.getAmbit());
|
|
|
@@ -332,7 +328,7 @@ public class DownloadController {
|
|
|
/* Indicadores del data warehouse */
|
|
|
try {
|
|
|
List<Indicador> indicadores;
|
|
|
- indicadores = getFromTitulacion(idTitulacio, curs);
|
|
|
+ indicadores = core.getFromTitulacion(idTitulacio, curs);
|
|
|
for(Indicador i : indicadores) {
|
|
|
info.put(i.getIndicador(), i.getValor());
|
|
|
}
|
|
|
@@ -341,7 +337,8 @@ public class DownloadController {
|
|
|
|
|
|
/* Indicadores de encuestas */
|
|
|
List<IndicadorEnquestaValorDTO> enquestesT;
|
|
|
- enquestesT = getAllInds(idTitulacio, idCentre, curs);
|
|
|
+ IndicadorEnquestaDTO iEnquestaDTO = new IndicadorEnquestaDTO(idTitulacio, idCentre, curs);
|
|
|
+ enquestesT = core.getAllInds2(iEnquestaDTO);
|
|
|
|
|
|
for(IndicadorEnquestaValorDTO i : enquestesT) {
|
|
|
String indicador = i.getAmbit().equals("t") ? (i.getEnquesta()+"_"+i.getIndicador()) : (i.getEnquesta()+"_"+i.getIndicador()+"_"+i.getAmbit());
|
|
|
@@ -371,10 +368,10 @@ public class DownloadController {
|
|
|
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);
|
|
|
+ Tasca tasca = core.getByProcesTascap(idProces, idTascap);
|
|
|
+ Proces proces = core.finProcesdById(idProces);
|
|
|
+ Organ titulacio = core.findOrganById("T", idTitulacio);
|
|
|
+ Organ centre = core.findOrganById("C", idCentre);
|
|
|
Integer ambit = idTitulacio/(int)1000;
|
|
|
|
|
|
/* Check if specific template exists */
|
|
|
@@ -413,7 +410,7 @@ public class DownloadController {
|
|
|
|
|
|
if(tasca.getTipus().getTipus() == 14) { // Iterable template task
|
|
|
List<Organ> titulacions = new ArrayList<Organ>();
|
|
|
- titulacions = getTitulacionsByTypeCentre(centre.getId().getLugar(), ambit);
|
|
|
+ titulacions = core.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());
|
|
|
@@ -453,8 +450,8 @@ public class DownloadController {
|
|
|
XDocReportRegistry.getRegistry().clear();
|
|
|
String reportId = "none";
|
|
|
|
|
|
- Organ titulacio = findByIDOrgan("T", idTitulacio);
|
|
|
- Organ centre = findByIDOrgan("C", idCentre);
|
|
|
+ Organ titulacio = core.findOrganById("T", idTitulacio);
|
|
|
+ Organ centre = core.findOrganById("C", idCentre);
|
|
|
Integer ambit = idTitulacio/(int)1000;
|
|
|
|
|
|
/* Check if specific template exists */
|
|
|
@@ -495,7 +492,7 @@ public class DownloadController {
|
|
|
|
|
|
if(tipusTasca == 14) { // Iterable template task
|
|
|
List<Organ> titulacions = new ArrayList<Organ>();
|
|
|
- titulacions = getTitulacionsByTypeCentre(centre.getId().getLugar(), ambit);
|
|
|
+ titulacions = core.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);
|
|
|
@@ -527,7 +524,7 @@ public class DownloadController {
|
|
|
@GetMapping(value="/pdf/download/{idTascai}")
|
|
|
@ResponseBody
|
|
|
public byte[] downloadTemplatePdf(@PathVariable("idTascai") BigInteger idTascai, HttpServletResponse response) throws IOException, InterruptedException {
|
|
|
- InstanciaTascaDTO it = findByIdTasca(idTascai);
|
|
|
+ InstanciaTascaDTO it = core.findInstanciaTascaById(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));
|
|
|
@@ -546,293 +543,6 @@ public class DownloadController {
|
|
|
@RequestBody PdfDTO pdf) throws IOException, InterruptedException {
|
|
|
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"borrador.pdf\"");
|
|
|
response.setHeader(HttpHeaders.CONTENT_TYPE, "application/pdf");
|
|
|
- return toPDF(pdf.getContent(), pdf.getIdtascai());
|
|
|
- }
|
|
|
-
|
|
|
- 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 {
|
|
|
- ProcesDTO ProcesDTO = new ProcesDTO(nomProces, lugar, lugar2, tambit);
|
|
|
- String requestBody = mapper.writeValueAsString(ProcesDTO);
|
|
|
- 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 InstanciaTascaDTO findByIdTasca(BigInteger idInstanciaTasca) {
|
|
|
- URI uriObj = URI.create(uri + "/instanciatasca/" + idInstanciaTasca);
|
|
|
- ObjectMapper mapper = new ObjectMapper();
|
|
|
- InstanciaTascaDTO 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<InstanciaTascaDTO>() {});
|
|
|
- } 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;
|
|
|
+ return pls.toPDF(pdf.getContent(), pdf.getIdtascai());
|
|
|
}
|
|
|
}
|