|
|
@@ -41,18 +41,11 @@ 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;
|
|
|
@Controller
|
|
|
public class DataController {
|
|
|
|
|
|
@Autowired
|
|
|
private DataService ips;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private IndicadorEnquestaTmpService iets;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private IndicadorEnquestaService ies;
|
|
|
|
|
|
@Autowired
|
|
|
private DatasourceService das;
|
|
|
@@ -141,26 +134,23 @@ public class DataController {
|
|
|
public List<IndicadorEnquestaTmp> show(Model model, Authentication auth, @RequestParam String enquesta,
|
|
|
@RequestParam Integer curs, @RequestParam String ambit, @RequestParam String estudi) throws IOException {
|
|
|
URI uriobjUri = URI.create(uri + "/findByEnquestaCursAmbitEstudi");
|
|
|
- List<IndicadorEnquestaTmp> inds = null;
|
|
|
-
|
|
|
+ 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 {
|
|
|
- ObjectMapper objectMapper = new ObjectMapper();
|
|
|
- EnquestaDTO enquestaDTO = new EnquestaDTO(enquesta, curs, ambit, estudi);
|
|
|
- String requestBody = objectMapper.writeValueAsString(enquestaDTO);
|
|
|
+ String requestBody = mapper.writeValueAsString(enquestaDTO);
|
|
|
|
|
|
HttpClient httpClient = HttpClient.newHttpClient();
|
|
|
HttpRequest request = HttpRequest.newBuilder()
|
|
|
.uri(uriobjUri)
|
|
|
.header("Content-Type", "application/json")
|
|
|
- .method("POST", HttpRequest.BodyPublishers.ofString(requestBody))
|
|
|
+ .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 {
|
|
|
@@ -335,7 +325,7 @@ public class DataController {
|
|
|
@PathVariable Integer curs) throws IOException {
|
|
|
|
|
|
URI uriobjUri = URI.create(uri + "/getAllIndsByRuct/" + ruct.toString() + "/" + curs);
|
|
|
- List<IndicadorEnquesta> inds = null;
|
|
|
+ List<IndicadorEnquesta> inds = new ArrayList<IndicadorEnquesta>();
|
|
|
|
|
|
try {
|
|
|
HttpClient httpClient = HttpClient.newHttpClient();
|
|
|
@@ -369,15 +359,42 @@ public class DataController {
|
|
|
@RequestParam Integer curs, @RequestParam String ambit, @RequestParam String estudi,
|
|
|
@RequestParam Integer centre, @RequestParam Integer titulacio) throws IOException {
|
|
|
List<IndicadorEnquesta> inds = new ArrayList<IndicadorEnquesta>();
|
|
|
+ EnquestaDTO enquestaDTO = new EnquestaDTO(enquesta, curs, ambit, estudi, centre, titulacio);
|
|
|
+ URI uriobjUri = null;
|
|
|
+ ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);;
|
|
|
+
|
|
|
if(ambit.equals("U")) {
|
|
|
- inds = this.ies.findByEnquestaCursAmbitEstudi(enquesta, curs, ambit, estudi);
|
|
|
+ uriobjUri = URI.create(uri + "/findByEnquestaCursAmbitEstudi");
|
|
|
}
|
|
|
else if(ambit.equals("C")) {
|
|
|
- inds = this.ies.findByEnquestaCursAmbitEstudiCentre(enquesta, curs, ambit, estudi, centre);
|
|
|
+ uriobjUri = URI.create(uri + "/findByEnquestaCursAmbitEstudiCentre");
|
|
|
}
|
|
|
if(ambit.equals("T")) {
|
|
|
- inds = this.ies.findByEnquestaCursAmbitEstudiCentreTitulacio(enquesta, curs, ambit, estudi, centre, titulacio);
|
|
|
+ uriobjUri = URI.create(uri + "/findByEnquestaCursAmbitEstudiCentreTitulacio");
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ String requestBody = mapper.writeValueAsString(enquestaDTO);
|
|
|
+ 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());
|
|
|
+
|
|
|
+ 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());
|
|
|
}
|
|
|
+
|
|
|
return inds;
|
|
|
}
|
|
|
|