|
@@ -0,0 +1,106 @@
|
|
|
|
|
+package es.uv.saic.web;
|
|
|
|
|
+
|
|
|
|
|
+import java.math.BigInteger;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
+
|
|
|
|
|
+import com.fasterxml.jackson.databind.JsonMappingException;
|
|
|
|
|
+import com.fasterxml.jackson.databind.JsonNode;
|
|
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
+import com.fasterxml.jackson.databind.SerializationFeature;
|
|
|
|
|
+
|
|
|
|
|
+import es.uv.saic.domain.InstanciaTasca;
|
|
|
|
|
+import es.uv.saic.domain.Tasca;
|
|
|
|
|
+import es.uv.saic.domain.InstanciaTascaRepository.TascaInformeTransfer;
|
|
|
|
|
+import es.uv.saic.service.InstanciaTascaService;
|
|
|
|
|
+import es.uv.saic.service.TascaService;
|
|
|
|
|
+
|
|
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+@RestController
|
|
|
|
|
+public class TascaController {
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ TascaService tascaService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ InstanciaTascaService instanciaTascaService;
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/instanciatasca/{id}")
|
|
|
|
|
+ public ResponseEntity<String> findInstanciaTascaById(@PathVariable("id") BigInteger id) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ InstanciaTasca instanciatasca = instanciaTascaService.findById(id);
|
|
|
|
|
+
|
|
|
|
|
+ if (instanciatasca != null){
|
|
|
|
|
+ final ObjectMapper mapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
|
|
|
|
|
+
|
|
|
|
|
+ String response = mapper.writeValueAsString(instanciatasca);
|
|
|
|
|
+
|
|
|
|
|
+ return ResponseEntity.ok(response);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return ResponseEntity.badRequest().body("La instancia esta vacia");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ return ResponseEntity.badRequest().body("Error al obtener la instancia por el id:" + e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/getLastByProcName")
|
|
|
|
|
+ public ResponseEntity<String> getLastByProcName(@RequestBody String json) {
|
|
|
|
|
+ JsonNode jsonNode = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ jsonNode = com.fasterxml.jackson.databind.json.JsonMapper.builder().build().readTree(json);
|
|
|
|
|
+
|
|
|
|
|
+ String nomProces = jsonNode.get("nomProces").asText();
|
|
|
|
|
+ Integer lugar = jsonNode.get("lugar").asInt();
|
|
|
|
|
+ Integer lugarOrgan = jsonNode.get("lugarOrgan").asInt();
|
|
|
|
|
+ String organAmbit = jsonNode.get("organAmbit").asText();
|
|
|
|
|
+
|
|
|
|
|
+ TascaInformeTransfer tit = instanciaTascaService.getLastByProcName(nomProces, lugar, lugarOrgan, organAmbit);
|
|
|
|
|
+
|
|
|
|
|
+ final ObjectMapper mapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
|
|
|
|
|
+
|
|
|
|
|
+ String response = mapper.writeValueAsString(tit);
|
|
|
|
|
+
|
|
|
|
|
+ return ResponseEntity.ok(response);
|
|
|
|
|
+ } catch (JsonMappingException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ return ResponseEntity.badRequest().body("Error al mapear el JSON: " + e.getMessage());
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ return ResponseEntity.badRequest().body("Error al obtener la última tarea a partir del procedimiento: " + e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/getByProcesTascap")
|
|
|
|
|
+ public ResponseEntity<String> getByProcesTascap(@RequestBody String json) {
|
|
|
|
|
+ JsonNode jsonNode = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ jsonNode = com.fasterxml.jackson.databind.json.JsonMapper.builder().build().readTree(json);
|
|
|
|
|
+
|
|
|
|
|
+ Integer idProces = jsonNode.get("idProces").asInt();
|
|
|
|
|
+ Integer idTascap = jsonNode.get("idTascap").asInt();
|
|
|
|
|
+
|
|
|
|
|
+ Tasca tasca = tascaService.getByProcesTascap(idProces, idTascap);
|
|
|
|
|
+
|
|
|
|
|
+ final ObjectMapper mapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
|
|
|
|
|
+
|
|
|
|
|
+ String response = mapper.writeValueAsString(tasca);
|
|
|
|
|
+
|
|
|
|
|
+ return ResponseEntity.ok(response);
|
|
|
|
|
+ } catch (JsonMappingException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ return ResponseEntity.badRequest().body("Error al mapear el JSON: " + e.getMessage());
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ return ResponseEntity.badRequest().body("Error al obtener la tasca: " + e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|