|
|
@@ -20,32 +20,8 @@ import es.uv.saic.service.EmailService;
|
|
|
public class StatsController {
|
|
|
|
|
|
@Autowired
|
|
|
- private SessionRegistry sessionRegistry;
|
|
|
-
|
|
|
- @Autowired
|
|
|
private EmailService emailService;
|
|
|
|
|
|
- public static class ActiveSession {
|
|
|
- private String id;
|
|
|
- private String username;
|
|
|
- private String fullName;
|
|
|
- private String npi;
|
|
|
- private String lastRequest;
|
|
|
- private boolean expired;
|
|
|
- public void setId(String id) {this.id = id;}
|
|
|
- public void setUsername(String username) {this.username = username;}
|
|
|
- public void setFullName(String fullName) {this.fullName = fullName;}
|
|
|
- public void setNpi(String npi) {this.npi = npi;}
|
|
|
- public void setExpired(boolean expired) {this.expired = expired;}
|
|
|
- public void setLastRequest(String lastRequest) {this.lastRequest = lastRequest;}
|
|
|
- public String getId() {return this.id;}
|
|
|
- public String getUsername() {return this.username;}
|
|
|
- public String getFullName() {return this.fullName;}
|
|
|
- public String getNpi() {return this.npi;}
|
|
|
- public boolean getExpired() {return this.expired;}
|
|
|
- public String getLastRequest() {return this.lastRequest;}
|
|
|
- }
|
|
|
-
|
|
|
public static class PendingEmail{
|
|
|
private String username;
|
|
|
private String fullName;
|
|
|
@@ -58,47 +34,9 @@ public class StatsController {
|
|
|
public String getEmail() {return this.email;}
|
|
|
|
|
|
}
|
|
|
-
|
|
|
- /*
|
|
|
- * Renders the admin stats page
|
|
|
- *
|
|
|
- * @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")
|
|
|
- public HashMap<String, Object> getStats() {
|
|
|
- HashMap<String, Object> model = new HashMap<>();
|
|
|
- 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.put("activeSessions", allLoggedUsers);
|
|
|
- model.put("totalActiveSessions", totalActiveSessions);
|
|
|
- model.put("totalExpiredSessions", totalExpiredSessions);
|
|
|
-
|
|
|
+
|
|
|
+ @GetMapping("/admin/get/pendingEmails")
|
|
|
+ public List<PendingEmail> getPendingEmails() {
|
|
|
List<PendingEmail> pendingEmails = new ArrayList<PendingEmail>();
|
|
|
for(Email e : emailService.getPendingQueue()) {
|
|
|
PendingEmail p = new PendingEmail();
|
|
|
@@ -107,7 +45,7 @@ public class StatsController {
|
|
|
p.setEmail(e.getUsusari().getEmail());
|
|
|
pendingEmails.add(p);
|
|
|
}
|
|
|
- model.put("pendingEmails", pendingEmails);
|
|
|
- return model;
|
|
|
+
|
|
|
+ return pendingEmails;
|
|
|
}
|
|
|
}
|