|
|
@@ -2,23 +2,21 @@ 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;
|
|
|
-import org.springframework.security.access.annotation.Secured;
|
|
|
-import org.springframework.security.core.Authentication;
|
|
|
import org.springframework.security.core.session.SessionInformation;
|
|
|
import org.springframework.security.core.session.SessionRegistry;
|
|
|
-import org.springframework.stereotype.Controller;
|
|
|
-import org.springframework.ui.Model;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import es.uv.saic.domain.Email;
|
|
|
import es.uv.saic.domain.Usuari;
|
|
|
import es.uv.saic.service.EmailService;
|
|
|
|
|
|
// Controller to handle admin statistics page
|
|
|
-@Controller
|
|
|
+@RestController
|
|
|
public class StatsController {
|
|
|
|
|
|
@Autowired
|
|
|
@@ -69,13 +67,13 @@ public class StatsController {
|
|
|
* @return The name of the view to render
|
|
|
*/
|
|
|
@GetMapping("/admin/stats")
|
|
|
- @Secured({"ROLE_ADMIN"})
|
|
|
- public String getStats(Model model, Authentication auth) {
|
|
|
-
|
|
|
+ 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) {
|
|
|
@@ -97,9 +95,9 @@ public class StatsController {
|
|
|
allLoggedUsers.add(s);
|
|
|
}
|
|
|
}
|
|
|
- model.addAttribute("activeSessions", allLoggedUsers);
|
|
|
- model.addAttribute("totalActiveSessions", totalActiveSessions);
|
|
|
- model.addAttribute("totalExpiredSessions", totalExpiredSessions);
|
|
|
+ model.put("activeSessions", allLoggedUsers);
|
|
|
+ model.put("totalActiveSessions", totalActiveSessions);
|
|
|
+ model.put("totalExpiredSessions", totalExpiredSessions);
|
|
|
|
|
|
List<PendingEmail> pendingEmails = new ArrayList<PendingEmail>();
|
|
|
for(Email e : emailService.getPendingQueue()) {
|
|
|
@@ -109,11 +107,8 @@ public class StatsController {
|
|
|
p.setEmail(e.getUsusari().getEmail());
|
|
|
pendingEmails.add(p);
|
|
|
}
|
|
|
- model.addAttribute("pendingEmails", pendingEmails);
|
|
|
-
|
|
|
- return "adminStats";
|
|
|
+ model.put("pendingEmails", pendingEmails);
|
|
|
+ model.put("redirect", "adminStats");
|
|
|
+ return model;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}
|