|
|
@@ -1,19 +1,12 @@
|
|
|
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.HttpRequest;
|
|
|
-import java.net.http.HttpResponse;
|
|
|
import java.sql.SQLException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
import jakarta.mail.MessagingException;
|
|
|
|
|
|
-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;
|
|
|
@@ -26,34 +19,28 @@ 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;
|
|
|
import es.uv.saic.domain.Usuari;
|
|
|
import es.uv.saic.dto.EnquestaDTO;
|
|
|
import es.uv.saic.dto.ImportDTO;
|
|
|
import es.uv.saic.dto.IndicadorEnquestaTmpDup;
|
|
|
-import es.uv.saic.dto.OrganDTOImp;
|
|
|
import es.uv.saic.dto.TablaDTO;
|
|
|
+import es.uv.saic.feign.CoreClient;
|
|
|
+import es.uv.saic.feign.DataClient;
|
|
|
|
|
|
@Controller
|
|
|
public class DataController {
|
|
|
|
|
|
- @Value("${saic.url.domain}")
|
|
|
- private String uriCore;
|
|
|
-
|
|
|
- @Value("${saic.url.data.domain}")
|
|
|
- private String uriData;
|
|
|
+ private CoreClient cc;
|
|
|
+
|
|
|
+ private DataClient dc;
|
|
|
|
|
|
// GET que carga la interfaz relacionada con toda la importación de datos
|
|
|
@GetMapping("/data/import")
|
|
|
@Secured({"ROLE_ADMIN", "ROLE_TESTER"})
|
|
|
public String renderImport(Model model, Authentication auth) {
|
|
|
- List<Datasource> sources = findAll("import");
|
|
|
+ List<Datasource> sources = dc.renderImport();
|
|
|
for(Datasource d : sources){
|
|
|
d.setConn(null);
|
|
|
}
|
|
|
@@ -73,28 +60,8 @@ public class DataController {
|
|
|
String locale = LocaleContextHolder.getLocale().getLanguage();
|
|
|
ImportDTO importDto = new ImportDTO(file, tipus, (Usuari)auth.getPrincipal(), enquesta, ambit, estudi, locale, delim, clau, ignoredColumns, dbOrigen, vista, curs, dstCurs);
|
|
|
|
|
|
- URI uriobjUri = URI.create(uriData + "/data/import");
|
|
|
- ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
|
-
|
|
|
try {
|
|
|
- String requestBody = mapper.writeValueAsString(importDto);
|
|
|
-
|
|
|
- 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) {
|
|
|
- return response.body();
|
|
|
- } else {
|
|
|
- System.err.println("Failed to import document. HTTP error code: " + response.statusCode());
|
|
|
- }
|
|
|
-
|
|
|
+ return dc.uploadFile(importDto);
|
|
|
} catch (Exception e) {
|
|
|
System.err.println("Failed to find Document: " + e.getMessage());
|
|
|
}
|
|
|
@@ -109,37 +76,14 @@ public class DataController {
|
|
|
@ResponseBody
|
|
|
public String delete(Model model, Authentication auth, @RequestParam String enquesta,
|
|
|
@RequestParam Integer curs, @RequestParam String ambit, @RequestParam String estudi) throws IOException {
|
|
|
-
|
|
|
- URI uriobj = URI.create(uriCore + "/delete/ByEnquestaCursAmbitEstudi");
|
|
|
- String retval = "";
|
|
|
|
|
|
- try {
|
|
|
- ObjectMapper objectMapper = new ObjectMapper();
|
|
|
- EnquestaDTO enquestaDTO = new EnquestaDTO(enquesta, curs, ambit, estudi);
|
|
|
- String requestBody = objectMapper.writeValueAsString(enquestaDTO);
|
|
|
-
|
|
|
- HttpClient httpClient = HttpClient.newHttpClient();
|
|
|
- HttpRequest request = HttpRequest.newBuilder()
|
|
|
- .uri(uriobj)
|
|
|
- .header("Content-Type", "application/json")
|
|
|
- .method("DELETE", HttpRequest.BodyPublishers.ofString(requestBody))
|
|
|
- .build();
|
|
|
-
|
|
|
- HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
+ String retval = "";
|
|
|
+ EnquestaDTO enquestaDTO = new EnquestaDTO(enquesta, curs, ambit, estudi);
|
|
|
+
|
|
|
+ Integer r = cc.deleteByEnquestaCursAmbitEstudi(enquestaDTO);
|
|
|
+ String locale = LocaleContextHolder.getLocale().getLanguage();
|
|
|
+ retval = locale.equals("es") ? "[INFO] Se han eliminado "+r+" registros" : "[INFO] S'han esborrat "+r+" registres";
|
|
|
|
|
|
- // Create the json with the response body
|
|
|
- if (response.statusCode() == HttpURLConnection.HTTP_OK) {
|
|
|
- String r = response.body();
|
|
|
- String locale = LocaleContextHolder.getLocale().getLanguage();
|
|
|
- retval = locale.equals("es") ? "[INFO] Se han eliminado "+r+" registros" : "[INFO] S'han esborrat "+r+" registres";
|
|
|
- } 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 retval;
|
|
|
}
|
|
|
|
|
|
@@ -147,68 +91,18 @@ public class DataController {
|
|
|
@PostMapping("/data/show")
|
|
|
@Secured({"ROLE_ADMIN", "ROLE_TESTER"})
|
|
|
@ResponseBody
|
|
|
- public List<IndicadorEnquestaTmp> show(Model model, Authentication auth, @RequestParam String enquesta,
|
|
|
+ public List<IndicadorEnquesta> show(Model model, Authentication auth, @RequestParam String enquesta,
|
|
|
@RequestParam Integer curs, @RequestParam String ambit, @RequestParam String estudi) throws IOException {
|
|
|
- URI uriobj = URI.create(uriCore + "/findByEnquestaCursAmbitEstudi");
|
|
|
- List<IndicadorEnquestaTmp> inds = new ArrayList<IndicadorEnquestaTmp>();
|
|
|
- ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
|
EnquestaDTO enquestaDTO = new EnquestaDTO(enquesta, curs, ambit, estudi);
|
|
|
|
|
|
- try {
|
|
|
- String requestBody = mapper.writeValueAsString(enquestaDTO);
|
|
|
-
|
|
|
- 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) {
|
|
|
- inds = mapper.readValue(response.body(), new TypeReference<List<IndicadorEnquestaTmp>>() {});
|
|
|
-
|
|
|
- } else {
|
|
|
- System.err.println("Failed to find enquesta by Curs, Ambit, Estudi. HTTP error code: " + response.statusCode());
|
|
|
- }
|
|
|
-
|
|
|
- } catch (Exception e) {
|
|
|
- System.err.println("Failed to find enquesta by Curs, Ambit, Estudi: " + e.getMessage());
|
|
|
- }
|
|
|
- return inds;
|
|
|
+ return cc.findByEnquestaCursAmbitEstudi(enquestaDTO);
|
|
|
}
|
|
|
|
|
|
// 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 {
|
|
|
- URI uriobj = URI.create(uriCore + "/getTitulacionsWithCentre");
|
|
|
-
|
|
|
- try {
|
|
|
- HttpClient httpClient = HttpClient.newHttpClient();
|
|
|
- HttpRequest request = HttpRequest.newBuilder()
|
|
|
- .uri(uriobj)
|
|
|
- .GET()
|
|
|
- .build();
|
|
|
-
|
|
|
- HttpResponse<String> response = httpClient.send(request, 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<OrganDTOImp> centres = mapper.readValue(response.body(), new TypeReference<List<OrganDTOImp>>() {});
|
|
|
-
|
|
|
- model.addAttribute("data", centres);
|
|
|
- } 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());
|
|
|
- }
|
|
|
-
|
|
|
+ model.addAttribute("data", cc.getTitulacionsWithCentre());
|
|
|
return "dataCurrent";
|
|
|
}
|
|
|
|
|
|
@@ -225,35 +119,7 @@ public class DataController {
|
|
|
@ResponseBody
|
|
|
public List<IndicadorEnquestaTmpDup> check(Model model, Authentication auth,
|
|
|
@RequestParam String enquesta, @PathVariable Integer type) throws IOException {
|
|
|
- URI uriobjUri = URI.create(uriData + "/data/check/" + type);
|
|
|
- ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
|
- List<IndicadorEnquestaTmpDup> inds = null;
|
|
|
-
|
|
|
- try {
|
|
|
- String requestBody = mapper.writeValueAsString(enquesta);
|
|
|
-
|
|
|
- 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) {
|
|
|
- inds = mapper.readValue(response.body(), new TypeReference<List<IndicadorEnquestaTmpDup>>() {});
|
|
|
- } else {
|
|
|
- System.err.println("Failed to import document. HTTP error code: " + response.statusCode());
|
|
|
- }
|
|
|
-
|
|
|
- } catch (Exception e) {
|
|
|
- System.err.println("Failed to find Document: " + e.getMessage());
|
|
|
- }
|
|
|
-
|
|
|
- return inds;
|
|
|
-
|
|
|
+ return dc.check(enquesta, type);
|
|
|
}
|
|
|
|
|
|
// POST que soluciona problemas de integridad que puedan tener los datos
|
|
|
@@ -263,34 +129,11 @@ public class DataController {
|
|
|
public Integer fixIntegrityIssues(Model model, Authentication auth,
|
|
|
@RequestParam String enquesta, @PathVariable String deleteFrom) throws IOException {
|
|
|
|
|
|
- URI uriobj = null;
|
|
|
if(deleteFrom.equals("current")) {
|
|
|
- uriobj = URI.create(uriCore + "/delete/current/" + enquesta);
|
|
|
+ return cc.deleteFromCurrent(enquesta);
|
|
|
}
|
|
|
else if(deleteFrom.equals("new")) {
|
|
|
- uriobj = URI.create(uriCore + "/delete/pending/" + enquesta);
|
|
|
- } else {
|
|
|
- return 0;
|
|
|
- }
|
|
|
-
|
|
|
- try {
|
|
|
- HttpClient httpClient = HttpClient.newHttpClient();
|
|
|
- HttpRequest request = HttpRequest.newBuilder()
|
|
|
- .uri(uriobj)
|
|
|
- .DELETE()
|
|
|
- .build();
|
|
|
-
|
|
|
- HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
-
|
|
|
- // Create the json with the response body
|
|
|
- if (response.statusCode() == HttpURLConnection.HTTP_OK) {
|
|
|
- return Integer.parseInt(response.body());
|
|
|
- } else {
|
|
|
- System.err.println("Failed to fix integrity by delete current/duplicated." +
|
|
|
- " HTTP error code: " + response.statusCode());
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ return cc.deleteFromPending(enquesta);
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
@@ -301,29 +144,7 @@ public class DataController {
|
|
|
@Secured({"ROLE_ADMIN", "ROLE_TESTER"})
|
|
|
@ResponseBody
|
|
|
public Integer fixDuplicatesIssues(Model model, Authentication auth, @RequestParam String enquesta) throws IOException {
|
|
|
- URI uriobj = URI.create(uriCore + "/delete/duplicates/" + enquesta);
|
|
|
-
|
|
|
- try {
|
|
|
- HttpClient httpClient = HttpClient.newHttpClient();
|
|
|
- HttpRequest request = HttpRequest.newBuilder()
|
|
|
- .uri(uriobj)
|
|
|
- .DELETE()
|
|
|
- .build();
|
|
|
-
|
|
|
- HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
-
|
|
|
- // Create the json with the response body
|
|
|
- if (response.statusCode() == HttpURLConnection.HTTP_OK) {
|
|
|
- return Integer.parseInt(response.body());
|
|
|
- } else {
|
|
|
- System.err.println("Failed to delete duplicates from " + enquesta + "." +
|
|
|
- " HTTP error code: " + response.statusCode());
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- return 0;
|
|
|
+ return cc.deleteDuplicates(enquesta);
|
|
|
}
|
|
|
|
|
|
// POST que consolida los datos pasadas por la encuesta
|
|
|
@@ -331,7 +152,7 @@ public class DataController {
|
|
|
@Secured({"ROLE_ADMIN", "ROLE_TESTER"})
|
|
|
@ResponseBody
|
|
|
public Integer consolidate(Model model, Authentication auth, @RequestParam String enquesta) throws IOException {
|
|
|
- return byEnquesta("consolidate", enquesta);
|
|
|
+ return dc.countByEnquesta(enquesta);
|
|
|
}
|
|
|
|
|
|
// POST que comprueba los datos a partir de la encuesta
|
|
|
@@ -339,7 +160,7 @@ public class DataController {
|
|
|
@Secured({"ROLE_ADMIN", "ROLE_TESTER"})
|
|
|
@ResponseBody
|
|
|
public Integer countByEnquesta(Model model, Authentication auth, @RequestParam String enquesta) throws IOException {
|
|
|
- return byEnquesta("count", enquesta);
|
|
|
+ return dc.countByEnquesta(enquesta);
|
|
|
}
|
|
|
|
|
|
// POST para mostrar los datos en columnas
|
|
|
@@ -348,30 +169,11 @@ public class DataController {
|
|
|
@ResponseBody
|
|
|
public List<String> listTableColumns(Model model, Authentication auth, @RequestParam Integer dbOrigen, @RequestParam String vista) {
|
|
|
String locale = LocaleContextHolder.getLocale().getLanguage();
|
|
|
- URI uriobjUri = URI.create(uriData + "/data/view/columns");
|
|
|
- ObjectMapper mapper = new ObjectMapper();
|
|
|
List<String> list = null;
|
|
|
|
|
|
try {
|
|
|
TablaDTO tablaDTO = new TablaDTO(dbOrigen, vista, locale);
|
|
|
- String requestBody = mapper.writeValueAsString(tablaDTO);
|
|
|
-
|
|
|
-
|
|
|
- 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) {
|
|
|
- list = mapper.readValue(response.body(), new TypeReference<List<String>>() {});
|
|
|
- } else {
|
|
|
- System.err.println("Failed to load table. HTTP error code: " + response.statusCode());
|
|
|
- }
|
|
|
+ return dc.listTableColumns(tablaDTO);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
System.err.println("Failed to load table: " + e.getMessage());
|
|
|
@@ -386,31 +188,7 @@ public class DataController {
|
|
|
@ResponseBody
|
|
|
public List<IndicadorEnquesta> show(Model model, Authentication auth, @PathVariable Integer ruct,
|
|
|
@PathVariable Integer curs) throws IOException {
|
|
|
-
|
|
|
- URI uriobj = URI.create(uriCore + "/getAllIndsByRuct/" + ruct.toString() + "/" + curs);
|
|
|
- List<IndicadorEnquesta> inds = new ArrayList<IndicadorEnquesta>();
|
|
|
- ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
|
-
|
|
|
- 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<IndicadorEnquesta>>() {});
|
|
|
- } else {
|
|
|
- System.err.println("Failed to load List<IndicadorEnquesta>. HTTP response code: " + response.statusCode());
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- System.err.println("Error al encontrar el ruct " + ruct + " curso: " + curs);
|
|
|
- }
|
|
|
-
|
|
|
- return inds;
|
|
|
+ return cc.getAllIndsByRuct(ruct, curs);
|
|
|
}
|
|
|
|
|
|
// POST que muestra los datos del curso actual
|
|
|
@@ -423,39 +201,15 @@ public class DataController {
|
|
|
|
|
|
List<IndicadorEnquesta> inds = new ArrayList<IndicadorEnquesta>();
|
|
|
EnquestaDTO enquestaDTO = new EnquestaDTO(enquesta, curs, ambit, estudi, centre, titulacio);
|
|
|
- URI uriobj = null;
|
|
|
- ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);;
|
|
|
-
|
|
|
+
|
|
|
if(ambit.equals("U")) {
|
|
|
- uriobj = URI.create(uriCore + "/findByEnquestaCursAmbitEstudi");
|
|
|
+ inds = cc.findByEnquestaCursAmbitEstudi(enquestaDTO);
|
|
|
}
|
|
|
else if(ambit.equals("C")) {
|
|
|
- uriobj = URI.create(uriCore + "/findByEnquestaCursAmbitEstudiCentre");
|
|
|
+ inds = cc.findByEnquestaCursAmbitEstudiCentre(enquestaDTO);
|
|
|
}
|
|
|
if(ambit.equals("T")) {
|
|
|
- uriobj = URI.create(uriCore + "/findByEnquestaCursAmbitEstudiCentreTitulacio");
|
|
|
- }
|
|
|
-
|
|
|
- try {
|
|
|
- String requestBody = mapper.writeValueAsString(enquestaDTO);
|
|
|
- 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) {
|
|
|
- inds = mapper.readValue(response.body(), new TypeReference<List<IndicadorEnquesta>>() {});
|
|
|
-
|
|
|
- } else {
|
|
|
- System.err.println("Failed to find enquesta by Curs, Ambit, Estudi. HTTP error code: " + response.statusCode());
|
|
|
- }
|
|
|
-
|
|
|
- } catch (Exception e) {
|
|
|
- System.err.println("Failed to find enquesta by Curs, Ambit, Estudi: " + e.getMessage());
|
|
|
+ inds = cc.findByEnquestaCursAmbitEstudiCentreTitulacio(enquestaDTO);
|
|
|
}
|
|
|
|
|
|
return inds;
|
|
|
@@ -465,61 +219,6 @@ public class DataController {
|
|
|
@Secured({"ROLE_ADMIN", "ROLE_TESTER"})
|
|
|
@ResponseBody
|
|
|
public List<Datasource> getDatasources(Model model, Authentication auth) throws IOException {
|
|
|
- return findAll("sources");
|
|
|
- }
|
|
|
-
|
|
|
- private List<Datasource> findAll(String uString) {
|
|
|
- URI uriObj = URI.create(uriData + "/data/" + uString);
|
|
|
- ObjectMapper mapper = new ObjectMapper();
|
|
|
- List<Datasource> dList = 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) {
|
|
|
- dList = mapper.readValue(response.body(), new TypeReference<List<Datasource>>() {});
|
|
|
- } else {
|
|
|
- System.err.println("Failed to check integrity of IndicadorEnquestaTmpDup by enquesta. HTTP error code: " + response.statusCode());
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- return dList;
|
|
|
- }
|
|
|
-
|
|
|
- private Integer byEnquesta(String uString, String enquesta) {
|
|
|
-
|
|
|
- URI uriobjUri = URI.create(uriData + "/data/" + uString);
|
|
|
-
|
|
|
- try {
|
|
|
-
|
|
|
- HttpClient httpClient = HttpClient.newHttpClient();
|
|
|
- HttpRequest request = HttpRequest.newBuilder()
|
|
|
- .uri(uriobjUri)
|
|
|
- .header("Content-Type", "application/json")
|
|
|
- .POST(HttpRequest.BodyPublishers.ofString(enquesta))
|
|
|
- .build();
|
|
|
-
|
|
|
- HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
-
|
|
|
- // Create the json with the response body
|
|
|
- if (response.statusCode() == HttpURLConnection.HTTP_OK) {
|
|
|
- return Integer.parseInt(response.body());
|
|
|
- } else {
|
|
|
- System.err.println("Failed to /data/ " + uString + ". HTTP error code: " + response.statusCode());
|
|
|
- }
|
|
|
-
|
|
|
- } catch (Exception e) {
|
|
|
- System.err.println("Failed to /data/ " + uString + ": " + e.getMessage());
|
|
|
- return 0;
|
|
|
- }
|
|
|
-
|
|
|
- return 0;
|
|
|
+ return dc.getDatasources();
|
|
|
}
|
|
|
}
|