|
|
@@ -44,6 +44,7 @@ import es.uv.saic.domain.Organ;
|
|
|
import es.uv.saic.domain.Usuari;
|
|
|
import es.uv.saic.dto.EmailDTO;
|
|
|
import es.uv.saic.dto.IndicadorEnquestaTmpDup;
|
|
|
+import es.uv.saic.feing.CoreClient;
|
|
|
import es.uv.saic.domain.Datasource;
|
|
|
|
|
|
|
|
|
@@ -53,8 +54,8 @@ public class DataService {
|
|
|
@Autowired
|
|
|
private DatasourceService dss;
|
|
|
|
|
|
- @Value("${saic.url.core.domain}")
|
|
|
- private String uriCore;
|
|
|
+ @Autowired
|
|
|
+ private CoreClient cc;
|
|
|
|
|
|
private HashMap<String, String> titsMap;
|
|
|
private HashMap<String, String> centresMap;
|
|
|
@@ -380,7 +381,7 @@ public class DataService {
|
|
|
return -1;
|
|
|
}
|
|
|
else {
|
|
|
- Integer i = consolidateByEnquestaAux(enquesta);
|
|
|
+ Integer i = cc.consolidateByEnquesta(enquesta);
|
|
|
deleteByEnquesta(enquesta);
|
|
|
return i;
|
|
|
}
|
|
|
@@ -391,15 +392,15 @@ public class DataService {
|
|
|
}
|
|
|
|
|
|
public List<IndicadorEnquestaTmpDup> checkIntegrity(String enquesta){
|
|
|
- return checkIntegrityAux(enquesta);
|
|
|
+ return cc.checkIntegrity(enquesta);
|
|
|
}
|
|
|
|
|
|
public Integer deleteFromCurrent(String enquesta){
|
|
|
- return deleteFromCurrentAux(enquesta);
|
|
|
+ return cc.deleteFromCurrent(enquesta);
|
|
|
}
|
|
|
|
|
|
public Integer deleteFromPending(String enquesta){
|
|
|
- return deleteFromPendingAux(enquesta);
|
|
|
+ return cc.deleteFromPending(enquesta);
|
|
|
}
|
|
|
|
|
|
private void setColumnsCod(String ambit, List<String> knownColumns, List<String> mandatoryColumns) {
|
|
|
@@ -531,267 +532,32 @@ public class DataService {
|
|
|
}
|
|
|
|
|
|
private Organ findOrgByRuct(Integer ruct) {
|
|
|
- URI uriObj = URI.create(uriCore + "/instanciatasca/" + ruct);
|
|
|
- ObjectMapper mapper = new ObjectMapper();
|
|
|
- Organ organ = 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) {
|
|
|
- organ = mapper.readValue(response.body(), new TypeReference<Organ>() {});
|
|
|
- } else {
|
|
|
- System.err.println("Failed to find Organ by Ruct. HTTP error code: " + response.statusCode());
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- return organ;
|
|
|
+ return cc.getOrgByRuct(ruct);
|
|
|
}
|
|
|
|
|
|
private boolean existsOrg(String tlugar, Integer titulacio) {
|
|
|
- URI uriObj = URI.create(uriCore + "/existOrg/" + tlugar + "/" + titulacio);
|
|
|
- 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) {
|
|
|
- return response.body() == "1" ? true : false;
|
|
|
- } else {
|
|
|
- System.err.println("Failed to find Organ by Ruct. HTTP error code: " + response.statusCode());
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- return false;
|
|
|
+ return cc.existsOrg(tlugar, titulacio);
|
|
|
}
|
|
|
|
|
|
private void deleteByEnquesta(String enquesta) {
|
|
|
- URI uriobj = URI.create(uriCore + "/delete/by/" + 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) {
|
|
|
- System.out.println("Enquesta eliminada correctamente");
|
|
|
- } else {
|
|
|
- System.err.println("Failed to fix integrity by delete current/duplicated." +
|
|
|
- " HTTP error code: " + response.statusCode());
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ cc.deleteByEnquestaC(enquesta);
|
|
|
}
|
|
|
|
|
|
private void save(IndicadorEnquestaTmp ie) {
|
|
|
- URI uriObj = URI.create(uriCore + "/save/");
|
|
|
- ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
|
-
|
|
|
- try {
|
|
|
- String requestBody = mapper.writeValueAsString(ie);
|
|
|
- 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) {
|
|
|
- System.out.println("");
|
|
|
- } else {
|
|
|
- System.err.println("Failed to find save. HTTP error code: " + response.statusCode());
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ cc.save(ie);
|
|
|
}
|
|
|
|
|
|
private List<IndicadorEnquestaTmpDup> checkDuplicatesAux(String enquesta) {
|
|
|
- URI uriObj = URI.create(uriCore + "/checkDuplicates/" + enquesta);
|
|
|
- ObjectMapper mapper = new ObjectMapper();
|
|
|
- List<IndicadorEnquestaTmpDup> inds = 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) {
|
|
|
- inds = mapper.readValue(response.body(), new TypeReference<List<IndicadorEnquestaTmpDup>>() {});
|
|
|
- } else {
|
|
|
- System.err.println("Failed to check duplicates of IndicadorEnquestaTmpDup by enquesta. HTTP error code: " + response.statusCode());
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- return inds;
|
|
|
- }
|
|
|
-
|
|
|
- private Integer deleteFromPendingAux(String enquesta) {
|
|
|
- URI uriobj = URI.create(uriCore + "/delete/pending/" + 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 pending." +
|
|
|
- " HTTP error code: " + response.statusCode());
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- return 0;
|
|
|
+ return cc.checkDuplicates(enquesta);
|
|
|
}
|
|
|
|
|
|
- private Integer deleteFromCurrentAux(String enquesta) {
|
|
|
- URI uriobj = URI.create(uriCore + "/delete/current/" + 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 pending." +
|
|
|
- " HTTP error code: " + response.statusCode());
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- return 0;
|
|
|
- }
|
|
|
-
|
|
|
- private List<IndicadorEnquestaTmpDup> checkIntegrityAux(String enquesta) {
|
|
|
- URI uriObj = URI.create(uriCore + "/checkIntegrity/" + enquesta);
|
|
|
- ObjectMapper mapper = new ObjectMapper();
|
|
|
- List<IndicadorEnquestaTmpDup> inds = 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) {
|
|
|
- inds = mapper.readValue(response.body(), new TypeReference<List<IndicadorEnquestaTmpDup>>() {});
|
|
|
- } else {
|
|
|
- System.err.println("Failed to check integrity of IndicadorEnquestaTmpDup by enquesta. HTTP error code: " + response.statusCode());
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- return inds;
|
|
|
- }
|
|
|
|
|
|
private Integer countByEnquestaAux(String enquesta) {
|
|
|
- URI uriObj = URI.create(uriCore + "/countByEnquesta/" + enquesta);
|
|
|
- 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) {
|
|
|
- return Integer.parseInt(response.body());
|
|
|
- } else {
|
|
|
- System.err.println("Failed to find Organ by Ruct. HTTP error code: " + response.statusCode());
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- return 0;
|
|
|
+ return cc.countByEnquesta(enquesta);
|
|
|
}
|
|
|
|
|
|
- private void sendMail(String string, String string2, String string3) {
|
|
|
+ private void sendMail(String string, String string2, String string3) {
|
|
|
EmailDTO email = new EmailDTO(string, string2, string3);
|
|
|
-
|
|
|
- URI uriObj = URI.create(uriCore + "/sendEmail");
|
|
|
- ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
|
-
|
|
|
- try {
|
|
|
- String requestBody = mapper.writeValueAsString(email);
|
|
|
- HttpClient httpClient = HttpClient.newHttpClient();
|
|
|
- HttpRequest request = HttpRequest.newBuilder()
|
|
|
- .uri(uriObj)
|
|
|
- .header("Content-Type", "application/json")
|
|
|
- .POST(HttpRequest.BodyPublishers.ofString(requestBody))
|
|
|
- .build();
|
|
|
-
|
|
|
- httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private Integer consolidateByEnquestaAux(String enquesta) {
|
|
|
- URI uriObj = URI.create(uriCore + "/consolidateByEnquesta/" + enquesta);
|
|
|
- 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) {
|
|
|
- return Integer.parseInt(response.body());
|
|
|
- } else {
|
|
|
- System.err.println("Failed to find to consolidateByEnquesta. HTTP error code: " + response.statusCode());
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- return 0;
|
|
|
+ cc.sendEmail(email);
|
|
|
}
|
|
|
}
|