public ModelAndView getAdminModel() { ModelAndView mav = new ModelAndView("admin/index"); final List<Guest> allGuests = guestService.getAllGuests(); mav.addObject("allGuests", allGuests); mav.addObject("release", env.get("release")); return mav; }
@Secured({"ROLE_ADMIN"}) @RequestMapping(value = {"/admin/fail"}) public ModelAndView getPermanentFailConnectors( HttpServletResponse response, @RequestParam( value = "filter", required = false, defaultValue = "apiKey.reason!='" + ApiKey.PermanentFailReason.NEEDS_REAUTH + "'") String filter, @RequestParam(value = "guestId", required = false) String guestId, @RequestParam(value = "status_0", required = false, defaultValue = "false") boolean statusUp, @RequestParam(value = "status_1", required = false, defaultValue = "false") boolean statusPermanentFail, @RequestParam(value = "status_2", required = false, defaultValue = "false") boolean statusTemporaryFail, @RequestParam(value = "status_3", required = false, defaultValue = "false") boolean statusOverRateLimit) 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); final List<ApiKey.Status> statusFilters = new ArrayList<ApiKey.Status>(); if (statusUp) statusFilters.add(ApiKey.Status.STATUS_UP); if (statusPermanentFail) statusFilters.add(ApiKey.Status.STATUS_PERMANENT_FAILURE); if (statusTemporaryFail) statusFilters.add(ApiKey.Status.STATUS_TRANSIENT_FAILURE); if (statusOverRateLimit) statusFilters.add(ApiKey.Status.STATUS_OVER_RATE_LIMIT); ModelAndView mav = new ModelAndView("admin/permanentFail"); final StringBuffer queryString = new StringBuffer("SELECT apiKey FROM ApiKey apiKey "); StringBuffer whereClause = new StringBuffer(); boolean whereClauseAdded = addPotentialStatusWhereClause(whereClause, statusFilters); if (!StringUtils.isEmpty(guestId)) { addGuestIdClause(whereClause, guestId, whereClauseAdded); whereClauseAdded = true; } if (!StringUtils.isEmpty(filter)) { addFilterClause(whereClause, filter, whereClauseAdded); whereClauseAdded = true; } if (whereClauseAdded) queryString.append(whereClause).append(" "); queryString.append("ORDER BY apiKey.api, apiKey.guestId"); System.out.println(queryString.toString()); final List<ApiKey> apiKeys = jpaDaoService.executeQueryWithLimitAndOffset( queryString.toString(), Integer.MAX_VALUE, 0, ApiKey.class); mav.addObject("statusFilters", statusFilters); mav.addObject("apiKeys", apiKeys); mav.addObject("filter", filter); mav.addObject("guestId", guestId); mav.addObject("release", env.get("release")); return mav; }
@RequestMapping(value = "/test/unit") public ModelAndView unit(HttpServletRequest request) { // check that we're running locally if (!RequestUtils.isDev(request)) { return new ModelAndView("redirect:/welcome"); } ModelAndView mav = new ModelAndView("test/unit"); String release = env.get("release"); mav.addObject("release", release); 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; }