@Secured({"ROLE_ADMIN"})
 @RequestMapping("/admin/{guestId}")
 public ModelAndView showUserApiKeys(@PathVariable("guestId") long guestId) {
   ModelAndView mav = getAdminModel();
   mav.addObject("subview", "allConnectors");
   final Guest guest = guestService.getGuestById(guestId);
   final List<ApiKey> apiKeys = guestService.getApiKeys(guest.getId());
   mav.addObject("username", guest.username);
   mav.addObject("guestId", guest.getId());
   mav.addObject("connectorInstanceModels", getConnectorInstanceModels(apiKeys));
   return mav;
 }
 @Secured({"ROLE_ADMIN"})
 @RequestMapping("/admin/{guestId}/{apiKeyId}")
 public ModelAndView showConnectorInstanceDetails(
     @PathVariable("guestId") long guestId, @PathVariable("apiKeyId") long apiKeyId) {
   ModelAndView mav = getAdminModel();
   mav.addObject("subview", "connectorDetails");
   final ApiKey apiKey = guestService.getApiKey(apiKeyId);
   final Map<String, Object> connectorInstanceModel =
       connectorInstanceModelFactory.createConnectorInstanceModel(apiKey);
   final Guest guest = guestService.getGuestById(guestId);
   final List<ApiUpdate> lastUpdates = connectorUpdateService.getUpdates(apiKey, 100, 0);
   mav.addObject("guest", guest);
   mav.addObject("guestId", guest.getId());
   mav.addObject("apiKeyId", apiKeyId);
   mav.addObject("apiKey", apiKey);
   mav.addObject("attributes", guestService.getApiKeyAttributes(apiKeyId));
   mav.addObject("connectorInstanceModel", connectorInstanceModel);
   mav.addObject("lastUpdates", lastUpdates);
   mav.addObject("liveServerUUIDs", connectorUpdateService.getLiveServerUUIDs());
   List<UpdateWorkerTask> scheduledTasks = getScheduledTasks(apiKey);
   mav.addObject("scheduledTasks", scheduledTasks);
   return mav;
 }
  @Secured({"ROLE_ADMIN"})
  @RequestMapping(value = {"/admin"})
  public ModelAndView admin(
      HttpServletResponse response,
      @RequestParam(value = "page", required = false, defaultValue = "1") int page,
      @RequestParam(value = "pageSize", required = false, defaultValue = "20") int pageSize)
      throws Exception {
    response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
    response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
    response.setDateHeader("Expires", 0);
    ModelAndView mav = new ModelAndView("admin/index");

    long totalGuests = jpaDaoService.executeNativeQuery("SELECT count(*) from Guest");

    // If pageSize is too small, set to default of 20
    if (pageSize <= 0) pageSize = 20;

    // Limit range of page to be >=1 and <= lastPage)
    int lastPage =
        ((int) totalGuests) % pageSize == 0
            ? ((int) totalGuests) / pageSize
            : ((int) totalGuests) / pageSize + 1;
    if (page < 1) page = 1;
    else if (page > lastPage) page = lastPage;

    final int offset = (page - 1) * pageSize;
    final List<Guest> allGuests =
        jpaDaoService.executeQueryWithLimitAndOffset(
            "SELECT guest FROM Guest guest", pageSize, offset, Guest.class);
    // get scheduled updateWorkerTasks for the current subset of users
    final List<UpdateWorkerTask> tasks = connectorUpdateService.getAllScheduledUpdateWorkerTasks();

    mav.addObject("allGuests", allGuests);
    mav.addObject("release", env.get("release"));
    final List<ConnectorInfo> connectors = systemService.getConnectors();
    mav.addObject("subview", "connectorHealthDashboard");
    mav.addObject("connectors", connectors);
    List<Map.Entry<Guest, List<List<ApiKey>>>> rows =
        new ArrayList<Map.Entry<Guest, List<List<ApiKey>>>>();
    ValueHolder synching = getSynchingUpdateWorkerTasks();

    long consumerTriggerRepeatInterval = Long.valueOf(env.get("consumer.trigger.repeatInterval"));
    ValueHolder due = getDueUpdateWorkerWorkerTasks(tasks, consumerTriggerRepeatInterval);
    ValueHolder overdue = getOverdueUpdateWorkerWorkerTasks(tasks, consumerTriggerRepeatInterval);

    for (Guest guest : allGuests) {
      List<List<ApiKey>> guestApiKeys = new ArrayList<List<ApiKey>>();
      for (ConnectorInfo connector : connectors) {
        final List<ApiKey> apiKeys =
            guestService.getApiKeys(guest.getId(), Connector.fromValue(connector.api));
        guestApiKeys.add(apiKeys);
      }
      final Map.Entry<Guest, List<List<ApiKey>>> guestListEntry =
          new AbstractMap.SimpleEntry<Guest, List<List<ApiKey>>>(guest, guestApiKeys);
      rows.add(guestListEntry);
    }
    mav.addObject("totalGuests", totalGuests);
    mav.addObject("fromGuest", offset);
    mav.addObject("toGuest", offset + allGuests.size());
    mav.addObject("page", page);
    mav.addObject("pageSize", pageSize);
    mav.addObject("synching", synching);
    mav.addObject("tasksDue", due);
    mav.addObject("tasksOverdue", overdue);
    mav.addObject("rows", rows);
    mav.addObject("serverUUID", connectorUpdateService.getLiveServerUUIDs().toString());
    return mav;
  }