|
|
@@ -5,6 +5,7 @@ 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;
|
|
|
@@ -33,24 +34,20 @@ 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.Organ;
|
|
|
import es.uv.saic.domain.Usuari;
|
|
|
+import es.uv.saic.dto.EnquestaDTO;
|
|
|
import es.uv.saic.dto.IndicadorEnquestaTmpDup;
|
|
|
+import es.uv.saic.dto.OrganDTOImp;
|
|
|
import es.uv.saic.service.DataService;
|
|
|
import es.uv.saic.service.DatasourceService;
|
|
|
import es.uv.saic.service.IndicadorEnquestaService;
|
|
|
import es.uv.saic.service.IndicadorEnquestaTmpService;
|
|
|
-import es.uv.saic.service.OrganService;
|
|
|
-
|
|
|
@Controller
|
|
|
public class DataController {
|
|
|
|
|
|
@Autowired
|
|
|
private DataService ips;
|
|
|
|
|
|
- @Autowired
|
|
|
- private OrganService os;
|
|
|
-
|
|
|
@Autowired
|
|
|
private IndicadorEnquestaTmpService iets;
|
|
|
|
|
|
@@ -103,9 +100,37 @@ 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 {
|
|
|
- String locale = LocaleContextHolder.getLocale().getLanguage();
|
|
|
- String r = Integer.toString(this.iets.deleteByEnquestaCursAmbitEstudi(enquesta, curs, ambit, estudi));
|
|
|
- String retval = locale.equals("es") ? "[INFO] Se han eliminado "+r+" registros" : "[INFO] S'han esborrat "+r+" registres";
|
|
|
+
|
|
|
+ URI uriobjUri = URI.create(uri + "/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(uriobjUri)
|
|
|
+ .header("Content-Type", "application/json")
|
|
|
+ .method("DELETE", 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) {
|
|
|
+ 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;
|
|
|
}
|
|
|
|
|
|
@@ -115,43 +140,61 @@ public class DataController {
|
|
|
@ResponseBody
|
|
|
public List<IndicadorEnquestaTmp> show(Model model, Authentication auth, @RequestParam String enquesta,
|
|
|
@RequestParam Integer curs, @RequestParam String ambit, @RequestParam String estudi) throws IOException {
|
|
|
- List<IndicadorEnquestaTmp> inds = this.iets.findByEnquestaCursAmbitEstudi(enquesta, curs, ambit, estudi);
|
|
|
- return inds;
|
|
|
+ URI uriobjUri = URI.create(uri + "/findByEnquestaCursAmbitEstudi");
|
|
|
+ List<IndicadorEnquestaTmp> inds = null;
|
|
|
+
|
|
|
+ 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(uriobjUri)
|
|
|
+ .header("Content-Type", "application/json")
|
|
|
+ .method("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) {
|
|
|
+ ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
|
+ // Convert JSON array to List<Organ>
|
|
|
+ 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;
|
|
|
}
|
|
|
|
|
|
// 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 uriobjUri = URI.create(uri + "/getActiveCentres");
|
|
|
- URI uriobjUri2 = URI.create(uri + "/getTitulacions");
|
|
|
+ URI uriobjUri = URI.create(uri + "/getTitulacionsWithCentre");
|
|
|
|
|
|
try {
|
|
|
HttpClient httpClient = HttpClient.newHttpClient();
|
|
|
- java.net.http.HttpRequest request = java.net.http.HttpRequest.newBuilder()
|
|
|
+ HttpRequest request = 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>>() {});
|
|
|
+ // Convert JSON array to List<Organ>
|
|
|
+ List<OrganDTOImp> centres = mapper.readValue(response.body(), new TypeReference<List<OrganDTOImp>>() {});
|
|
|
|
|
|
- model.addAttribute("centres", centres);
|
|
|
- model.addAttribute("titulacions", titulacions);
|
|
|
+ model.addAttribute("data", centres);
|
|
|
} else {
|
|
|
System.err.println("Failed to load centres. HTTP error code: " + response.statusCode());
|
|
|
}
|
|
|
@@ -191,12 +234,37 @@ public class DataController {
|
|
|
@ResponseBody
|
|
|
public Integer fixIntegrityIssues(Model model, Authentication auth,
|
|
|
@RequestParam String enquesta, @PathVariable String deleteFrom) throws IOException {
|
|
|
+
|
|
|
+ URI uriobjUri = null;
|
|
|
if(deleteFrom.equals("current")) {
|
|
|
- return this.iets.deleteFromCurrent(enquesta);
|
|
|
+ uriobjUri = URI.create(uri + "/delete/current" + enquesta);
|
|
|
}
|
|
|
else if(deleteFrom.equals("new")) {
|
|
|
- return this.iets.deleteFromPending(enquesta);
|
|
|
+ uriobjUri = URI.create(uri + "/delete/pending" + enquesta);
|
|
|
+ } else {
|
|
|
+ return 0;
|
|
|
}
|
|
|
+
|
|
|
+ try {
|
|
|
+ HttpClient httpClient = HttpClient.newHttpClient();
|
|
|
+ HttpRequest request = HttpRequest.newBuilder()
|
|
|
+ .uri(uriobjUri)
|
|
|
+ .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 0;
|
|
|
}
|
|
|
|
|
|
@@ -205,7 +273,29 @@ public class DataController {
|
|
|
@Secured({"ROLE_ADMIN", "ROLE_TESTER"})
|
|
|
@ResponseBody
|
|
|
public Integer fixDuplicatesIssues(Model model, Authentication auth, @RequestParam String enquesta) throws IOException {
|
|
|
- return this.iets.deleteDuplicates(enquesta);
|
|
|
+ URI uriobjUri = URI.create(uri + "/delete/duplicates/" + enquesta);
|
|
|
+
|
|
|
+ try {
|
|
|
+ HttpClient httpClient = HttpClient.newHttpClient();
|
|
|
+ HttpRequest request = HttpRequest.newBuilder()
|
|
|
+ .uri(uriobjUri)
|
|
|
+ .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;
|
|
|
}
|
|
|
|
|
|
// POST que consolida los datos pasadas por la encuesta
|
|
|
@@ -242,9 +332,32 @@ public class DataController {
|
|
|
@Secured({"ROLE_ADMIN", "ROLE_TESTER"})
|
|
|
@ResponseBody
|
|
|
public List<IndicadorEnquesta> show(Model model, Authentication auth, @PathVariable Integer ruct,
|
|
|
- @PathVariable Integer curs) throws IOException {
|
|
|
- Organ o = os.findByRuct(ruct);
|
|
|
- List<IndicadorEnquesta> inds = this.ies.getAllInds(o, curs);
|
|
|
+ @PathVariable Integer curs) throws IOException {
|
|
|
+
|
|
|
+ URI uriobjUri = URI.create(uri + "/getAllIndsByRuct/" + ruct.toString() + "/" + curs);
|
|
|
+ List<IndicadorEnquesta> inds = null;
|
|
|
+
|
|
|
+ try {
|
|
|
+ HttpClient httpClient = HttpClient.newHttpClient();
|
|
|
+ HttpRequest request = HttpRequest.newBuilder()
|
|
|
+ .uri(uriobjUri)
|
|
|
+ .GET()
|
|
|
+ .build();
|
|
|
+
|
|
|
+ HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
+
|
|
|
+ if (response.statusCode() == HttpURLConnection.HTTP_OK) {
|
|
|
+ ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
|
+
|
|
|
+ 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;
|
|
|
}
|
|
|
|