|
|
@@ -2,6 +2,10 @@ package es.uv.saic.web;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStreamReader;
|
|
|
+import java.net.HttpURLConnection;
|
|
|
+import java.net.URI;
|
|
|
+import java.net.http.HttpClient;
|
|
|
+import java.net.http.HttpResponse;
|
|
|
import java.sql.SQLException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
@@ -9,6 +13,7 @@ import java.util.List;
|
|
|
import jakarta.mail.MessagingException;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.context.i18n.LocaleContextHolder;
|
|
|
import org.springframework.security.access.annotation.Secured;
|
|
|
import org.springframework.security.core.Authentication;
|
|
|
@@ -21,6 +26,10 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
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.Datasource;
|
|
|
import es.uv.saic.domain.IndicadorEnquesta;
|
|
|
import es.uv.saic.domain.IndicadorEnquestaTmp;
|
|
|
@@ -50,6 +59,9 @@ public class DataController {
|
|
|
|
|
|
@Autowired
|
|
|
private DatasourceService das;
|
|
|
+
|
|
|
+ @Value("${saic.url.domain}")
|
|
|
+ private String uri;
|
|
|
|
|
|
// GET que carga la interfaz relacionada con toda la importación de datos
|
|
|
@GetMapping("/data/import")
|
|
|
@@ -110,11 +122,44 @@ public class DataController {
|
|
|
// GET para mostrar el formulario de busqueda de datos
|
|
|
@GetMapping("/data/current")
|
|
|
@Secured({"ROLE_ADMIN", "ROLE_TESTER"})
|
|
|
- public String current(Model model, Authentication auth) throws IOException {
|
|
|
- List<Organ> centres = os.getActiveCentres();
|
|
|
- List<Organ> titulacions = os.getTitulacions();
|
|
|
- model.addAttribute("centres", centres);
|
|
|
- model.addAttribute("titulacions", titulacions);
|
|
|
+ public String current(Model model, Authentication auth) throws IOException {
|
|
|
+ URI uriobjUri = URI.create(uri + "/getActiveCentres");
|
|
|
+ URI uriobjUri2 = URI.create(uri + "/getTitulacions");
|
|
|
+
|
|
|
+ try {
|
|
|
+ HttpClient httpClient = HttpClient.newHttpClient();
|
|
|
+ java.net.http.HttpRequest request = java.net.http.HttpRequest.newBuilder()
|
|
|
+ .uri(uriobjUri)
|
|
|
+ .GET()
|
|
|
+ .build();
|
|
|
+
|
|
|
+ HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
+
|
|
|
+ HttpClient httpClient2 = HttpClient.newHttpClient();
|
|
|
+ java.net.http.HttpRequest request2 = java.net.http.HttpRequest.newBuilder()
|
|
|
+ .uri(uriobjUri2)
|
|
|
+ .GET()
|
|
|
+ .build();
|
|
|
+
|
|
|
+ HttpResponse<String> response2 = httpClient2.send(request2, HttpResponse.BodyHandlers.ofString());
|
|
|
+
|
|
|
+ // Create the json with the response body
|
|
|
+ if (response.statusCode() == HttpURLConnection.HTTP_OK) {
|
|
|
+ ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
|
+ // Convert JSON array to List<Organ>
|
|
|
+ List<Organ> centres = mapper.readValue(response.body(), new TypeReference<List<Organ>>() {});
|
|
|
+ List<Organ> titulacions = mapper.readValue(response2.body(), new TypeReference<List<Organ>>() {});
|
|
|
+
|
|
|
+ model.addAttribute("centres", centres);
|
|
|
+ model.addAttribute("titulacions", titulacions);
|
|
|
+ } else {
|
|
|
+ System.err.println("Failed to load centres. HTTP error code: " + response.statusCode());
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.err.println("Failed to load centres: " + e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
return "dataCurrent";
|
|
|
}
|
|
|
|