|
|
@@ -3,17 +3,15 @@ package es.uv.saic.web;
|
|
|
import java.math.BigInteger;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Comparator;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
|
|
|
-import jakarta.servlet.http.HttpSession;
|
|
|
-
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.security.core.Authentication;
|
|
|
-import org.springframework.stereotype.Controller;
|
|
|
-import org.springframework.ui.Model;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import es.uv.saic.domain.DummyDataTransfer;
|
|
|
import es.uv.saic.domain.Instancia;
|
|
|
@@ -31,7 +29,7 @@ import es.uv.saic.service.UsuariService;
|
|
|
import es.uv.saic.service.UsuarisRolService;
|
|
|
|
|
|
// Render the supervision page and handle supervision searches
|
|
|
-@Controller
|
|
|
+@RestController
|
|
|
public class SupervisionController {
|
|
|
|
|
|
@Autowired
|
|
|
@@ -55,15 +53,17 @@ public class SupervisionController {
|
|
|
* @param session The HTTP session
|
|
|
* @return The name of the view to render
|
|
|
*/
|
|
|
- @GetMapping("/supervision")
|
|
|
- public String supervisionForm(Model model, Authentication auth, HttpSession session) {
|
|
|
-
|
|
|
+ @PostMapping("/supervision")
|
|
|
+ public HashMap<String, Object> supervisionForm(@RequestParam String usuario, @RequestBody SupervisionSearchParams ssp) {
|
|
|
+ HashMap<String, Object> model = new HashMap<>();
|
|
|
+ Usuari u = us.findByUsername(usuario);
|
|
|
+
|
|
|
List<DummyDataTransfer> supervisable_procs = new ArrayList<DummyDataTransfer>();
|
|
|
List<DummyDataTransfer> supervisable_years = new ArrayList<DummyDataTransfer>();
|
|
|
List<DummyDataTransfer> supervisable_orgs = new ArrayList<DummyDataTransfer>();
|
|
|
List<DummyDataTransfer> supervisable_cents = new ArrayList<DummyDataTransfer>();
|
|
|
|
|
|
- if(urs.isGrantedUser((Usuari) auth.getPrincipal())){ // Admin o UQ
|
|
|
+ if(u.isGranted()){ // Admin o UQ
|
|
|
List<Instancia> i_list = is.findAll();
|
|
|
for(Instancia inst : i_list) {
|
|
|
DummyDataTransfer p = new DummyDataTransfer();
|
|
|
@@ -124,12 +124,12 @@ public class SupervisionController {
|
|
|
supervisable_evs.add(c);
|
|
|
}
|
|
|
supervisable_cents.sort(Comparator.comparing(a -> a.getText()));
|
|
|
- model.addAttribute("granted", true);
|
|
|
- model.addAttribute("sup_evs", supervisable_evs);
|
|
|
- model.addAttribute("sup_cents", supervisable_cents);
|
|
|
+ model.put("granted", true);
|
|
|
+ model.put("sup_evs", supervisable_evs);
|
|
|
+ model.put("sup_cents", supervisable_cents);
|
|
|
}
|
|
|
else { // Otros
|
|
|
- List<BigInteger> i_list = this.us.getSupervisableProcessos(urs.findActiveRols(((Usuari) auth.getPrincipal())));
|
|
|
+ List<BigInteger> i_list = this.us.getSupervisableProcessos(urs.findActiveRols((u)));
|
|
|
for(BigInteger id : i_list) {
|
|
|
Instancia inst = is.findByID(id);
|
|
|
DummyDataTransfer p = new DummyDataTransfer();
|
|
|
@@ -173,25 +173,25 @@ public class SupervisionController {
|
|
|
o.setText2(org.getNomVal());
|
|
|
o.setValue(0);
|
|
|
supervisable_orgs.add(o);
|
|
|
- model.addAttribute("granted", false);
|
|
|
+ model.put("granted", false);
|
|
|
}
|
|
|
|
|
|
supervisable_orgs.sort(Comparator.comparing(a -> a.getText()));
|
|
|
|
|
|
- model.addAttribute("sup_procs", supervisable_procs);
|
|
|
- model.addAttribute("sup_years", supervisable_years);
|
|
|
- model.addAttribute("sup_orgs", supervisable_orgs);
|
|
|
+ model.put("sup_procs", supervisable_procs);
|
|
|
+ model.put("sup_years", supervisable_years);
|
|
|
+ model.put("sup_orgs", supervisable_orgs);
|
|
|
|
|
|
- if(session.getAttribute("searchParams") != null) {
|
|
|
- SupervisionSearchParams ssp = (SupervisionSearchParams) session.getAttribute("searchParams");
|
|
|
- model.addAttribute("restore", ssp);
|
|
|
- session.removeAttribute("searchParams");
|
|
|
+ if(ssp != null) {
|
|
|
+ model.put("restore", ssp);
|
|
|
+ model.put("removeAttribute", "searchParams");;
|
|
|
}
|
|
|
else {
|
|
|
- model.addAttribute("restore", null);
|
|
|
+ model.put("restore", null);
|
|
|
}
|
|
|
|
|
|
- return "supervision";
|
|
|
+ model.put("redirect", "supervision");
|
|
|
+ return model;
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -209,20 +209,23 @@ public class SupervisionController {
|
|
|
* @return The name of the view to render
|
|
|
*/
|
|
|
@PostMapping("/supervision/search")
|
|
|
- public String supervisionSearch(Model model, Authentication auth,
|
|
|
+ public HashMap<String, Object> supervisionSearch(
|
|
|
@RequestParam(name="centers[]", required=false) List<Integer> centres,
|
|
|
@RequestParam("years[]") List<Integer> cursos,
|
|
|
@RequestParam("titulations[]") List<Integer> titulacions,
|
|
|
@RequestParam(name="procedures[]", required=false) List<String> procediments,
|
|
|
@RequestParam(name="evidences[]", required=false) List<String> evidencies,
|
|
|
@RequestParam(name="searchType", required=false) String searchType,
|
|
|
- HttpSession session) {
|
|
|
- session.setAttribute("location", "supervision");
|
|
|
- if(centres == null) { centres = us.getSupervisableCentres((Usuari) auth.getPrincipal()); }
|
|
|
- this.loadResults(model, auth, centres, titulacions, cursos, procediments, evidencies, searchType);
|
|
|
- session.setAttribute("searchParams", new SupervisionSearchParams(centres, titulacions, cursos, procediments, evidencies, searchType));
|
|
|
-
|
|
|
- return "supervisionProcedures";
|
|
|
+ @RequestParam String usuari) {
|
|
|
+ HashMap<String, Object> model = new HashMap<>();
|
|
|
+ Usuari u = us.findByUsername(usuari);
|
|
|
+
|
|
|
+ model.put("location", "supervision");
|
|
|
+ if(centres == null) { centres = us.getSupervisableCentres(u); }
|
|
|
+ this.loadResults(model, u, centres, titulacions, cursos, procediments, evidencies, searchType);
|
|
|
+ model.put("searchParams", new SupervisionSearchParams(centres, titulacions, cursos, procediments, evidencies, searchType));
|
|
|
+ model.put("redirect", "supervisionProcedures");
|
|
|
+ return model;
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -234,14 +237,17 @@ public class SupervisionController {
|
|
|
* @return The name of the view to render
|
|
|
*/
|
|
|
@GetMapping("/supervision/search")
|
|
|
- public String restoreSearch(Model model, Authentication auth, HttpSession session) {
|
|
|
- session.setAttribute("location", "supervision");
|
|
|
- if(session.getAttribute("searchParams") != null) {
|
|
|
- SupervisionSearchParams ssp = (SupervisionSearchParams) session.getAttribute("searchParams");
|
|
|
- this.loadResults(model, auth, ssp.getCentres(), ssp.getTitulacions(), ssp.getCursos(), ssp.getProcediments(), ssp.getEvidencies(), ssp.getSearchType());
|
|
|
+ public HashMap<String, Object> restoreSearch(@RequestBody String usuari, @RequestParam SupervisionSearchParams ssp) {
|
|
|
+ HashMap<String, Object> model = new HashMap<>();
|
|
|
+ Usuari u = us.findByUsername(usuari);
|
|
|
+
|
|
|
+ model.put("location", "supervision");
|
|
|
+ if(ssp != null) {
|
|
|
+ this.loadResults(model, u, ssp.getCentres(), ssp.getTitulacions(), ssp.getCursos(), ssp.getProcediments(), ssp.getEvidencies(), ssp.getSearchType());
|
|
|
}
|
|
|
-
|
|
|
- return "supervisionProcedures";
|
|
|
+ model.put("redirect", "supervisionProcedures");
|
|
|
+
|
|
|
+ return model;
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -256,7 +262,7 @@ public class SupervisionController {
|
|
|
* @param evidencies The selected evidences
|
|
|
* @param searchType The type of search (by procedures or evidences)
|
|
|
*/
|
|
|
- public void loadResults(Model model, Authentication auth, List<Integer> centres, List<Integer> titulacions,
|
|
|
+ public void loadResults(HashMap<String, Object> model, Usuari u, List<Integer> centres, List<Integer> titulacions,
|
|
|
List<Integer> cursos, List<String> procediments, List<String> evidencies, String searchType) {
|
|
|
List<InstanciaTransfer> plist = new ArrayList<InstanciaTransfer>();
|
|
|
List<BigInteger> supervisables;
|
|
|
@@ -310,11 +316,11 @@ public class SupervisionController {
|
|
|
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);
|
|
|
+ model.put("procedure_list", plist);
|
|
|
}
|
|
|
|
|
|
}
|