|
|
@@ -25,6 +25,9 @@ public class StatsController {
|
|
|
|
|
|
@Autowired
|
|
|
private SessionRegistry sessionRegistry;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private EmailService emailService;
|
|
|
|
|
|
@Autowired
|
|
|
private StatsClient sc;
|
|
|
@@ -69,7 +72,7 @@ public class StatsController {
|
|
|
* @param model The model to pass data to the view
|
|
|
* @param auth The authentication object
|
|
|
* @return The name of the view to render
|
|
|
- */
|
|
|
+ *
|
|
|
@GetMapping("/admin/stats")
|
|
|
@Secured({"ROLE_ADMIN"})
|
|
|
public String getStats(Model model, Authentication auth) {
|
|
|
@@ -82,5 +85,42 @@ public class StatsController {
|
|
|
|
|
|
model.addAllAttributes(response);
|
|
|
return "adminStats";
|
|
|
- }
|
|
|
+ }*/
|
|
|
+
|
|
|
+ @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);
|
|
|
+ model.addAttribute("pendingEmails", sc.getPendingEmails());
|
|
|
+ return "adminStats";
|
|
|
+ }
|
|
|
}
|