|
|
@@ -9,6 +9,7 @@ import java.nio.file.Paths;
|
|
|
import java.sql.Timestamp;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
@@ -29,6 +30,9 @@ import org.springframework.web.bind.annotation.PathVariable;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import es.uv.saic.domain.Instancia;
|
|
|
@@ -47,7 +51,7 @@ import es.uv.saic.feign.PlantillaClient;
|
|
|
import es.uv.saic.service.*;
|
|
|
|
|
|
|
|
|
-@Controller
|
|
|
+@RestController
|
|
|
public class ProceduresController {
|
|
|
|
|
|
private final ProcesService procesService;
|
|
|
@@ -70,13 +74,7 @@ public class ProceduresController {
|
|
|
ProceduresController(ProcesService procesService) {
|
|
|
this.procesService = procesService;
|
|
|
}
|
|
|
-
|
|
|
- /* Redirect root to /procedures */
|
|
|
- @GetMapping("/")
|
|
|
- public void getRoot(Model model, Authentication auth, HttpSession session, HttpServletResponse response) throws IOException {
|
|
|
- response.sendRedirect("/procedures");
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
/*
|
|
|
* Load the list of active procedure instances for the logged-in user
|
|
|
*
|
|
|
@@ -86,15 +84,16 @@ public class ProceduresController {
|
|
|
* @param _new Optional parameter to indicate a new access
|
|
|
* @return The name of the view to render
|
|
|
*/
|
|
|
- @GetMapping("/procedures")
|
|
|
- public String getActiveInstances(Model model, Authentication auth, HttpSession session, @RequestParam(required = false) String _new) {
|
|
|
-
|
|
|
+ @PostMapping("/procedures")
|
|
|
+ public HashMap<String, Object> getActiveInstances(@RequestParam(required = false) String _new, @RequestParam String usuari) {
|
|
|
+ HashMap<String, Object> model = new HashMap<>();
|
|
|
+
|
|
|
if(_new != null) {
|
|
|
- model.addAttribute("new_access", true);
|
|
|
+ model.put("new_access", true);
|
|
|
}
|
|
|
- session.setAttribute("location", "procedures");
|
|
|
+ model.put("location", "procedures");
|
|
|
|
|
|
- Usuari u = (Usuari)auth.getPrincipal();
|
|
|
+ Usuari u = us.findByUsername(usuari);
|
|
|
List<InstanciaTransfer> plist = new ArrayList<InstanciaTransfer>();
|
|
|
Instancia i;
|
|
|
InstanciaTransfer it;
|
|
|
@@ -135,11 +134,12 @@ public class ProceduresController {
|
|
|
it.setDescTascaActivaVal(itt.getTasca().getDescripcioVal());
|
|
|
it.setIdTascapActiva(itt.getTasca().getIdTascap());
|
|
|
it.setTascaActivaExpired(itt.getTasca().isExpired());
|
|
|
- it.setTascaActivaAssignedToUser(its.isUserAuthorized(((Usuari)auth.getPrincipal()), itt.getIdInstanciaTasca()));
|
|
|
+ it.setTascaActivaAssignedToUser(its.isUserAuthorized(u, itt.getIdInstanciaTasca()));
|
|
|
plist.add(it);
|
|
|
}
|
|
|
- model.addAttribute("procedure_list", plist);
|
|
|
- return "procedures";
|
|
|
+ model.put("procedure_list", plist);
|
|
|
+ model.put("redirect", "procedures");
|
|
|
+ return model;
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -152,16 +152,15 @@ public class ProceduresController {
|
|
|
* @return The name of the view to render
|
|
|
*/
|
|
|
@GetMapping("/procedure/{id}")
|
|
|
- public String getInstance(Model model, Authentication auth, HttpSession session, @PathVariable BigInteger id) {
|
|
|
- if(session.getAttribute("location") != null) {
|
|
|
- model.addAttribute("location", session.getAttribute("location"));
|
|
|
- }
|
|
|
- else {
|
|
|
- session.setAttribute("location", "procedures");
|
|
|
- model.addAttribute("location", "procedures");
|
|
|
- }
|
|
|
- this.loadProcedure(model, auth, id);
|
|
|
- return "procedure";
|
|
|
+ public HashMap<String, Object> getInstance(@RequestParam String location, @PathVariable BigInteger id, @RequestParam String usuari) {
|
|
|
+ HashMap<String, Object> model = new HashMap<>();
|
|
|
+ Usuari u = us.findByUsername(usuari);
|
|
|
+
|
|
|
+ model.put("location", !location.equals(null) ? location : "procedures");
|
|
|
+
|
|
|
+ this.loadProcedure(model, u, id);
|
|
|
+ model.put("redirect", "procedure");
|
|
|
+ return model;
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -181,17 +180,19 @@ public class ProceduresController {
|
|
|
*/
|
|
|
@PostMapping("/procedure/files/{id}")
|
|
|
@ResponseBody
|
|
|
- public String updateInstanciaTascaEvidencia(Model model, Authentication auth, HttpSession session, @PathVariable BigInteger id, @RequestParam Map<String,String> params,
|
|
|
- @RequestParam(required = true) List<MultipartFile> evidencias) throws IllegalStateException, IOException {
|
|
|
- session.setAttribute("location", "procedures");
|
|
|
- model.addAttribute("location", "procedures");
|
|
|
+ public HashMap<String, Object> updateInstanciaTascaEvidencia(@RequestParam String location, @PathVariable BigInteger id, @RequestParam Map<String,String> params,
|
|
|
+ @RequestParam(required = true) List<MultipartFile> evidencias, @RequestParam String usuari) throws IllegalStateException, IOException {
|
|
|
+ HashMap<String, Object> model = new HashMap<>();
|
|
|
+ Usuari u = us.findByUsername(usuari);
|
|
|
+
|
|
|
+ model.put("location", "procedures");
|
|
|
InstanciaTasca it = its.findById(new BigInteger(params.get("taskid")));
|
|
|
|
|
|
/* Tipos de tarea permitidas */
|
|
|
final Set<Integer> suitable = Set.of(1, 12, 14);
|
|
|
|
|
|
boolean newTask = (suitable.contains(it.getTasca().getTipus().getTipus())) && it.getEstat().equals("E") &&
|
|
|
- (((Usuari)auth.getPrincipal()).isAdmin() || ((Usuari)auth.getPrincipal()).isGranted());
|
|
|
+ (u.isAdmin() || u.isGranted());
|
|
|
|
|
|
if(suitable.contains(it.getTasca().getTipus().getTipus())) { // Evidencia iterable
|
|
|
String fileName = "";
|
|
|
@@ -215,12 +216,13 @@ public class ProceduresController {
|
|
|
evidencia.transferTo(new File(filePath+fileName));
|
|
|
}
|
|
|
else {
|
|
|
- return "0";
|
|
|
+ model.put("ammount", "0");
|
|
|
+ return model;
|
|
|
}
|
|
|
|
|
|
if(newTask){
|
|
|
InstanciaTasca itNew = new InstanciaTasca();
|
|
|
- itNew.setUsuari((Usuari)auth.getPrincipal());
|
|
|
+ itNew.setUsuari(u);
|
|
|
itNew.setDataFet(new Date(System.currentTimeMillis()));
|
|
|
itNew.setData(new Date(System.currentTimeMillis()));
|
|
|
itNew.setEstat("E");
|
|
|
@@ -234,11 +236,11 @@ public class ProceduresController {
|
|
|
else {
|
|
|
it.setEvidencia(fileName);
|
|
|
it.setEstat("E");
|
|
|
- this.saveChanges(model, auth, session, it);
|
|
|
+ this.saveChanges(u, it);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- return Integer.toString(evidencias.size());
|
|
|
+ model.put("ammount", Integer.toString(evidencias.size()));
|
|
|
+ return model;
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -253,11 +255,12 @@ public class ProceduresController {
|
|
|
* @return The name of the view to render
|
|
|
*/
|
|
|
@PostMapping("/procedure/{id}")
|
|
|
- public String updateInstanciaTasca(Model model, Authentication auth, HttpSession session, @PathVariable BigInteger id, @RequestParam Map<String,String> params,
|
|
|
- @RequestParam(required = false) List<MultipartFile> evidencias) throws IllegalStateException, IOException, InterruptedException {
|
|
|
-
|
|
|
- session.setAttribute("location", "procedures");
|
|
|
- model.addAttribute("location", "procedures");
|
|
|
+ public HashMap<String, Object> updateInstanciaTasca(@RequestParam String location, @PathVariable BigInteger id, @RequestParam Map<String,String> params,
|
|
|
+ @RequestParam(required = false) List<MultipartFile> evidencias, @RequestParam String usuari) throws IllegalStateException, IOException, InterruptedException {
|
|
|
+ HashMap<String, Object> model = new HashMap<>();
|
|
|
+ Usuari u = us.findByUsername(usuari);
|
|
|
+
|
|
|
+ model.put("location", "procedures");
|
|
|
|
|
|
// Update task instance
|
|
|
InstanciaTasca it = its.findById(new BigInteger(params.get("taskid")));
|
|
|
@@ -279,9 +282,10 @@ public class ProceduresController {
|
|
|
it.setEstat("E");
|
|
|
}
|
|
|
|
|
|
- this.saveChanges(model, auth, session, it);
|
|
|
- this.loadProcedure(model, auth, id);
|
|
|
- return "procedure";
|
|
|
+ this.saveChanges(u, it);
|
|
|
+ this.loadProcedure(model, u, id);
|
|
|
+ model.put("redirect", "procedure");
|
|
|
+ return model;
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -292,8 +296,8 @@ public class ProceduresController {
|
|
|
* @param session HttpSession
|
|
|
* @param it InstanciaTasca to save
|
|
|
*/
|
|
|
- public void saveChanges(Model model, Authentication auth, HttpSession session, InstanciaTasca it) {
|
|
|
- this.its.saveChanges((Usuari)auth.getPrincipal(), it);
|
|
|
+ public void saveChanges(Usuari u, InstanciaTasca it) {
|
|
|
+ this.its.saveChanges(u, it);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -310,18 +314,16 @@ public class ProceduresController {
|
|
|
*/
|
|
|
@PostMapping("/procedure/save/{id}")
|
|
|
@ResponseBody
|
|
|
- public String saveDraft(Model model, Authentication auth, HttpSession session, @PathVariable BigInteger id, @RequestParam String text,
|
|
|
- @RequestParam boolean manual) {
|
|
|
- if(session.getAttribute("location") != null) {
|
|
|
- model.addAttribute("location", session.getAttribute("location"));
|
|
|
- }
|
|
|
- else {
|
|
|
- session.setAttribute("location", "procedures");
|
|
|
- model.addAttribute("location", "procedures");
|
|
|
- }
|
|
|
+ public HashMap<String, Object> saveDraft(@RequestParam String location, @PathVariable BigInteger id, @RequestParam String text,
|
|
|
+ @RequestParam boolean manual, @RequestParam String usuari) {
|
|
|
+ HashMap<String, Object> model = new HashMap<>();
|
|
|
+ Usuari u = us.findByUsername(usuari);
|
|
|
+
|
|
|
+ model.put("location", !location.equals(null) ? location : "procedures");
|
|
|
+
|
|
|
InstanciaTasca it = its.findById(id);
|
|
|
it.setText(text);
|
|
|
- it.setUsuari((Usuari)auth.getPrincipal());
|
|
|
+ it.setUsuari(u);
|
|
|
it.setDataMod(new Date(System.currentTimeMillis()));
|
|
|
its.save(it);
|
|
|
if(manual){
|
|
|
@@ -335,7 +337,8 @@ public class ProceduresController {
|
|
|
this.itsver.save(itv);
|
|
|
}
|
|
|
|
|
|
- return String.format("%1$td/%1$tm/%1$tY %1$tH:%1$tM:%1$tS", it.getDataMod());
|
|
|
+ model.put("date", String.format("%1$td/%1$tm/%1$tY %1$tH:%1$tM:%1$tS", it.getDataMod()));
|
|
|
+ return model;
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -345,7 +348,7 @@ public class ProceduresController {
|
|
|
* @param id Instancia ID Instance to load
|
|
|
* @return The name of the view to render
|
|
|
*/
|
|
|
- public void loadProcedure(Model model, Authentication auth, BigInteger id) {
|
|
|
+ public void loadProcedure(HashMap<String, Object> model, Usuari usuari, BigInteger id) {
|
|
|
Instancia i = is.findByID(id);
|
|
|
InstanciaTransfer inst = new InstanciaTransfer();
|
|
|
inst.setIdInstancia(i.getIdInstancia());
|
|
|
@@ -372,7 +375,7 @@ public class ProceduresController {
|
|
|
inst.setCentreVal(i.getOrgan().getOrgan().getNomVal());
|
|
|
inst.setRuct(i.getOrgan().getRuct());
|
|
|
}
|
|
|
- model.addAttribute("instance", inst);
|
|
|
+ model.put("instance", inst);
|
|
|
|
|
|
List<InstanciaTascaTransfer> tasks = new ArrayList<InstanciaTascaTransfer>();
|
|
|
Boolean active;
|
|
|
@@ -444,13 +447,13 @@ public class ProceduresController {
|
|
|
else {
|
|
|
itt.setUsuariFet("");
|
|
|
}
|
|
|
- itt.setAssignedToUser(its.isUserAuthorized(((Usuari)auth.getPrincipal()), itt.getIdInstanciaTasca()));
|
|
|
+ itt.setAssignedToUser(its.isUserAuthorized(usuari, itt.getIdInstanciaTasca()));
|
|
|
itt.setOldEvidences(its.findOlderByProces(it.getInstancia().getCentre(), it.getInstancia().getTitulacio(), it.getInstancia().getProces().getNomProces(), i.getProces().getCursActivacio()));
|
|
|
itt.setVersions(its.findOlderVersions(it.getInstancia().getIdInstancia(), it.getTasca().getIdTasca(), it.getVersion()));
|
|
|
tasks.add(itt);
|
|
|
}
|
|
|
- model.addAttribute("tasks", tasks);
|
|
|
- model.addAttribute("flow", this.getFlowDiagram(i.getProces()));
|
|
|
+ model.put("tasks", tasks);
|
|
|
+ model.put("flow", this.getFlowDiagram(i.getProces()));
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -462,11 +465,13 @@ public class ProceduresController {
|
|
|
* @return The name of the view to render
|
|
|
*/
|
|
|
@GetMapping("/procedure/drafts/{id}")
|
|
|
- public String getDrafts(Model model, Authentication auth, HttpSession session, @PathVariable BigInteger id) {
|
|
|
+ public HashMap<String, Object> getDrafts(@PathVariable BigInteger id) {
|
|
|
+ HashMap<String, Object> model = new HashMap<>();
|
|
|
List<InstanciaTascaVer> itvs = this.itsver.findByIdInstanciaTasca(id);
|
|
|
- model.addAttribute("versions", itvs);
|
|
|
- model.addAttribute("idInstanciaTasca", id);
|
|
|
- return "procedure_versions";
|
|
|
+ model.put("versions", itvs);
|
|
|
+ model.put("idInstanciaTasca", id);
|
|
|
+ model.put("redirect", "procedure_versions");
|
|
|
+ return model;
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -480,9 +485,8 @@ public class ProceduresController {
|
|
|
*/
|
|
|
@GetMapping("/procedure/draft/{id}")
|
|
|
@ResponseBody
|
|
|
- public InstanciaTascaVer getDraft(Model model, Authentication auth, HttpSession session, @PathVariable BigInteger id, @RequestParam Timestamp dataMod) {
|
|
|
- InstanciaTascaVer itv = this.itsver.findById(id, dataMod);
|
|
|
- return itv;
|
|
|
+ public InstanciaTascaVer getDraft(@PathVariable BigInteger id, @RequestParam Timestamp dataMod) {
|
|
|
+ return this.itsver.findById(id, dataMod);
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -496,7 +500,7 @@ public class ProceduresController {
|
|
|
*/
|
|
|
@PostMapping("/procedure/draft/{id}")
|
|
|
@ResponseBody
|
|
|
- public String restoreDraft(Model model, Authentication auth, HttpSession session, @PathVariable BigInteger id, @RequestParam Timestamp dataMod) {
|
|
|
+ public String restoreDraft(@PathVariable BigInteger id, @RequestParam Timestamp dataMod) {
|
|
|
try{
|
|
|
InstanciaTascaVer itv = this.itsver.findById(id, dataMod);
|
|
|
InstanciaTasca it = this.its.findById(id);
|