|
@@ -1,6 +1,11 @@
|
|
|
package es.uv.saic.web;
|
|
package es.uv.saic.web;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
|
+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.text.CharacterIterator;
|
|
import java.text.CharacterIterator;
|
|
|
import java.text.ParseException;
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
@@ -37,6 +42,10 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
+import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
|
|
+import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
+
|
|
|
import es.uv.saic.domain.Informe;
|
|
import es.uv.saic.domain.Informe;
|
|
|
import es.uv.saic.domain.InformeProcessos;
|
|
import es.uv.saic.domain.InformeProcessos;
|
|
|
import es.uv.saic.domain.Instancia;
|
|
import es.uv.saic.domain.Instancia;
|
|
@@ -49,9 +58,11 @@ import es.uv.saic.domain.Organ;
|
|
|
import es.uv.saic.domain.Usuari;
|
|
import es.uv.saic.domain.Usuari;
|
|
|
import es.uv.saic.domain.UsuarisRol;
|
|
import es.uv.saic.domain.UsuarisRol;
|
|
|
import es.uv.saic.dto.AnyDimensioDTO;
|
|
import es.uv.saic.dto.AnyDimensioDTO;
|
|
|
|
|
+import es.uv.saic.dto.CategoriaDTO;
|
|
|
import es.uv.saic.dto.CategoriaDocumentDTO;
|
|
import es.uv.saic.dto.CategoriaDocumentDTO;
|
|
|
import es.uv.saic.dto.DimensioInstanciesDTO;
|
|
import es.uv.saic.dto.DimensioInstanciesDTO;
|
|
|
import es.uv.saic.dto.DocumentDTO;
|
|
import es.uv.saic.dto.DocumentDTO;
|
|
|
|
|
+import es.uv.saic.dto.DocumentTmpDTO;
|
|
|
import es.uv.saic.dto.IndicadorDTO;
|
|
import es.uv.saic.dto.IndicadorDTO;
|
|
|
import es.uv.saic.dto.InstanciaDTO;
|
|
import es.uv.saic.dto.InstanciaDTO;
|
|
|
import es.uv.saic.dto.InstanciaGanttDTO;
|
|
import es.uv.saic.dto.InstanciaGanttDTO;
|
|
@@ -99,6 +110,9 @@ public class DashboardController {
|
|
|
|
|
|
|
|
@Value("${saic.url.public}")
|
|
@Value("${saic.url.public}")
|
|
|
private String publicUrl;
|
|
private String publicUrl;
|
|
|
|
|
+
|
|
|
|
|
+ @Value("${saic.url.domain}")
|
|
|
|
|
+ private String uri;
|
|
|
|
|
|
|
|
// GET para cargar el dashboard con toda su información
|
|
// GET para cargar el dashboard con toda su información
|
|
|
@GetMapping("/dashboard")
|
|
@GetMapping("/dashboard")
|
|
@@ -332,7 +346,7 @@ public class DashboardController {
|
|
|
|
|
|
|
|
List<Categoria> catChilds = cs.findByPareTambitAndU(c.getIdCategoria(), o.getTambit());
|
|
List<Categoria> catChilds = cs.findByPareTambitAndU(c.getIdCategoria(), o.getTambit());
|
|
|
for(Categoria cc : catChilds) {
|
|
for(Categoria cc : catChilds) {
|
|
|
- Document doc = ds.findByCategoriaOrgan(cc.getIdCategoria(), o.getId().getLugar(), o.getId().getTlugar());
|
|
|
|
|
|
|
+ Document doc = findByCategoriaOrgan(cc.getIdCategoria(), o.getId().getLugar(), o.getId().getTlugar());
|
|
|
if(doc != null) {
|
|
if(doc != null) {
|
|
|
DocumentDTO docdto = new DocumentDTO(locale.equals("es") ? cc.getNomCas() : cc.getNomVal(),
|
|
DocumentDTO docdto = new DocumentDTO(locale.equals("es") ? cc.getNomCas() : cc.getNomVal(),
|
|
|
doc.getIdDocument().toString(),
|
|
doc.getIdDocument().toString(),
|
|
@@ -352,7 +366,7 @@ public class DashboardController {
|
|
|
|
|
|
|
|
return data;
|
|
return data;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// GET para conseguir el diagrama de gantt a partir del ruct
|
|
// GET para conseguir el diagrama de gantt a partir del ruct
|
|
|
@GetMapping("/dashboard/gantt/{ruct}")
|
|
@GetMapping("/dashboard/gantt/{ruct}")
|
|
|
@ResponseBody
|
|
@ResponseBody
|
|
@@ -422,7 +436,7 @@ public class DashboardController {
|
|
|
|
|
|
|
|
Categoria cat = this.cs.findById(idCategoria);
|
|
Categoria cat = this.cs.findById(idCategoria);
|
|
|
Organ org = this.os.findByID(tlugar, lugar);
|
|
Organ org = this.os.findByID(tlugar, lugar);
|
|
|
- Document doc = this.ds.findByCategoriaOrgan(idCategoria, lugar, tlugar);
|
|
|
|
|
|
|
+ Document doc = findByCategoriaOrgan(idCategoria, lugar, tlugar);
|
|
|
if(doc != null) {
|
|
if(doc != null) {
|
|
|
this.ds.archive(doc);
|
|
this.ds.archive(doc);
|
|
|
}
|
|
}
|
|
@@ -432,12 +446,12 @@ public class DashboardController {
|
|
|
doc.setData(new Date(System.currentTimeMillis()));
|
|
doc.setData(new Date(System.currentTimeMillis()));
|
|
|
doc.setNom(cat.getNomCas());
|
|
doc.setNom(cat.getNomCas());
|
|
|
doc.setVisible(true);
|
|
doc.setVisible(true);
|
|
|
- doc = this.ds.save(doc);
|
|
|
|
|
- String path = this.ds.upload(doc.getIdDocument(), cat.getIdCategoria(), lugar, tlugar, file);
|
|
|
|
|
|
|
+ doc = save(doc);
|
|
|
|
|
+ String path = upload(doc.getIdDocument(), cat.getIdCategoria(), lugar, tlugar, file);
|
|
|
doc.setRuta(path);
|
|
doc.setRuta(path);
|
|
|
- this.ds.save(doc);
|
|
|
|
|
|
|
+ save(doc);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// POST para añadir un documento a un centro cocncreto
|
|
// POST para añadir un documento a un centro cocncreto
|
|
|
@PostMapping("/dashboard/documents/archive")
|
|
@PostMapping("/dashboard/documents/archive")
|
|
|
@ResponseBody
|
|
@ResponseBody
|
|
@@ -669,4 +683,98 @@ public class DashboardController {
|
|
|
return String.format("%.1f %ciB", value / 1024.0, ci.current());
|
|
return String.format("%.1f %ciB", value / 1024.0, ci.current());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private Document findByCategoriaOrgan(Integer idCategoria, Integer lugar, String tlugar) {
|
|
|
|
|
+ Document doc = null;
|
|
|
|
|
+ URI uriobjUri = URI.create(uri + "/findByCategoriaOrgan");
|
|
|
|
|
+ ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ CategoriaDTO categoriaDTO = new CategoriaDTO(idCategoria, lugar, tlugar);
|
|
|
|
|
+ String requestBody = mapper.writeValueAsString(categoriaDTO);
|
|
|
|
|
+
|
|
|
|
|
+ HttpClient httpClient = HttpClient.newHttpClient();
|
|
|
|
|
+ HttpRequest request = HttpRequest.newBuilder()
|
|
|
|
|
+ .uri(uriobjUri)
|
|
|
|
|
+ .header("Content-Type", "application/json")
|
|
|
|
|
+ .POST(HttpRequest.BodyPublishers.ofString(requestBody))
|
|
|
|
|
+ .build();
|
|
|
|
|
+
|
|
|
|
|
+ HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
|
|
+
|
|
|
|
|
+ // Create the json with the response body
|
|
|
|
|
+ if (response.statusCode() == HttpURLConnection.HTTP_OK) {
|
|
|
|
|
+ doc = mapper.readValue(response.body(), new TypeReference<Document>() {});
|
|
|
|
|
+ } else {
|
|
|
|
|
+ System.err.println("Failed to find Document. HTTP error code: " + response.statusCode());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ System.err.println("Failed to find Document: " + e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return doc;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Document save(Document doc) {
|
|
|
|
|
+ URI uriobjUri = URI.create(uri + "/document/save");
|
|
|
|
|
+ ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ String requestBody = mapper.writeValueAsString(doc);
|
|
|
|
|
+
|
|
|
|
|
+ HttpClient httpClient = HttpClient.newHttpClient();
|
|
|
|
|
+ HttpRequest request = HttpRequest.newBuilder()
|
|
|
|
|
+ .uri(uriobjUri)
|
|
|
|
|
+ .header("Content-Type", "application/json")
|
|
|
|
|
+ .POST(HttpRequest.BodyPublishers.ofString(requestBody))
|
|
|
|
|
+ .build();
|
|
|
|
|
+
|
|
|
|
|
+ HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
|
|
+
|
|
|
|
|
+ // Create the json with the response body
|
|
|
|
|
+ if (response.statusCode() == HttpURLConnection.HTTP_OK) {
|
|
|
|
|
+ doc = mapper.readValue(response.body(), new TypeReference<Document>() {});
|
|
|
|
|
+ } else {
|
|
|
|
|
+ System.err.println("Failed to save Document. HTTP error code: " + response.statusCode());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ System.err.println("Failed to save Document: " + e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return doc;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String upload(Integer idDocument, Integer idCategoria, Integer lugar, String tlugar, MultipartFile file) {
|
|
|
|
|
+ URI uriobjUri = URI.create(uri + "/document/upload");
|
|
|
|
|
+ ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
|
|
|
+ HttpResponse<String> response = null;
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ DocumentTmpDTO doc = new DocumentTmpDTO(idDocument, idCategoria, lugar, tlugar, file);
|
|
|
|
|
+ String requestBody = mapper.writeValueAsString(doc);
|
|
|
|
|
+
|
|
|
|
|
+ HttpClient httpClient = HttpClient.newHttpClient();
|
|
|
|
|
+ HttpRequest request = HttpRequest.newBuilder()
|
|
|
|
|
+ .uri(uriobjUri)
|
|
|
|
|
+ .header("Content-Type", "application/json")
|
|
|
|
|
+ .POST(HttpRequest.BodyPublishers.ofString(requestBody))
|
|
|
|
|
+ .build();
|
|
|
|
|
+
|
|
|
|
|
+ response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
|
|
+
|
|
|
|
|
+ // Create the json with the response body
|
|
|
|
|
+ if (response.statusCode() == HttpURLConnection.HTTP_OK) {
|
|
|
|
|
+ return response.body();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ System.err.println("Failed to save Document. HTTP error code: " + response.statusCode());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ System.err.println("Failed to save Document: " + e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return "";
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|