|
|
@@ -2,6 +2,7 @@ package es.uv.saic.web;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -15,6 +16,7 @@ import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
|
import es.uv.saic.domain.Email;
|
|
|
import es.uv.saic.domain.Usuari;
|
|
|
+import es.uv.saic.feign.StatsClient;
|
|
|
import es.uv.saic.service.EmailService;
|
|
|
|
|
|
// Controller to handle admin statistics page
|
|
|
@@ -25,7 +27,7 @@ public class StatsController {
|
|
|
private SessionRegistry sessionRegistry;
|
|
|
|
|
|
@Autowired
|
|
|
- private EmailService emailService;
|
|
|
+ private StatsClient sc;
|
|
|
|
|
|
public static class ActiveSession {
|
|
|
private String id;
|
|
|
@@ -71,49 +73,14 @@ public class StatsController {
|
|
|
@GetMapping("/admin/stats")
|
|
|
@Secured({"ROLE_ADMIN"})
|
|
|
public String getStats(Model model, Authentication auth) {
|
|
|
-
|
|
|
- final List<Object> allPrincipals = sessionRegistry.getAllPrincipals();
|
|
|
- List<ActiveSession> allLoggedUsers = new ArrayList<ActiveSession>();
|
|
|
- int totalActiveSessions = 0;
|
|
|
- int totalExpiredSessions = 0;
|
|
|
- for(Object principal : allPrincipals) {
|
|
|
- final List<SessionInformation> allSessions = sessionRegistry.getAllSessions(principal, true);
|
|
|
- for(final SessionInformation session : allSessions) {
|
|
|
- final ActiveSession s = new ActiveSession();
|
|
|
- if(session.isExpired()) {
|
|
|
- totalExpiredSessions++;
|
|
|
- }
|
|
|
- else {
|
|
|
- totalActiveSessions++;
|
|
|
- }
|
|
|
- Usuari x = ((Usuari)principal);
|
|
|
- s.setId(Integer.toString(session.hashCode()));
|
|
|
- s.setExpired(session.isExpired());
|
|
|
- SimpleDateFormat sdt = new SimpleDateFormat("dd-mm-yyyy HH:mm:ss");
|
|
|
- s.setLastRequest(sdt.format(session.getLastRequest()));
|
|
|
- s.setUsername(x.getUsuari());
|
|
|
- s.setFullName(x.getNom() + " " + x.getCognoms());
|
|
|
- s.setNpi("");
|
|
|
- allLoggedUsers.add(s);
|
|
|
- }
|
|
|
- }
|
|
|
- model.addAttribute("activeSessions", allLoggedUsers);
|
|
|
- model.addAttribute("totalActiveSessions", totalActiveSessions);
|
|
|
- model.addAttribute("totalExpiredSessions", totalExpiredSessions);
|
|
|
-
|
|
|
- List<PendingEmail> pendingEmails = new ArrayList<PendingEmail>();
|
|
|
- for(Email e : emailService.getPendingQueue()) {
|
|
|
- PendingEmail p = new PendingEmail();
|
|
|
- p.setUsername(e.getUsusari().getUsuari());
|
|
|
- p.setFullName(e.getUsusari().getNom()+ " " +e.getUsusari().getCognoms());
|
|
|
- p.setEmail(e.getUsusari().getEmail());
|
|
|
- pendingEmails.add(p);
|
|
|
- }
|
|
|
- model.addAttribute("pendingEmails", pendingEmails);
|
|
|
-
|
|
|
- return "adminStats";
|
|
|
- }
|
|
|
-
|
|
|
+ HashMap<String, Object> response =
|
|
|
+ sc.getStats();
|
|
|
|
|
|
-
|
|
|
+ if (response != null && response.get("redirect") != null) {
|
|
|
+ model.addAllAttributes(response);
|
|
|
+ return response.get("redirect").toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ return "401";
|
|
|
+ }
|
|
|
}
|