View Javadoc
1   package org.itracker.web.actions.admin;
2   
3   import org.apache.log4j.Level;
4   import org.apache.log4j.Logger;
5   import org.apache.struts.action.ActionForm;
6   import org.apache.struts.action.ActionForward;
7   import org.apache.struts.action.ActionMapping;
8   import org.itracker.core.resources.ITrackerResources;
9   import org.itracker.model.Configuration;
10  import org.itracker.model.util.ReportUtilities;
11  import org.itracker.services.*;
12  import org.itracker.web.actions.base.ItrackerBaseAction;
13  import org.itracker.web.util.ServletContextUtils;
14  import org.itracker.web.util.SessionManager;
15  
16  import javax.servlet.http.HttpServletRequest;
17  import javax.servlet.http.HttpServletResponse;
18  import java.util.*;
19  
20  public class AdminHomeAction extends ItrackerBaseAction {
21  
22      private static final Logger log = Logger.getLogger(AdminHomeAction.class);
23  
24      public ActionForward execute(ActionMapping mapping, ActionForm form,
25                                   HttpServletRequest request, HttpServletResponse response)
26              throws Exception {
27  
28          execSetupJspEnv(request);
29  
30          return mapping.findForward("adminhome");
31      }
32  
33  
34      /**
35       * This utility has to be called for any page forwarding to the admin-home, before forwarding. Else the page will contain no data.
36       */
37      public static void execSetupJspEnv(HttpServletRequest request) {
38          Date time_millies = new Date(System.currentTimeMillis());
39  
40          IssueService issueService = ServletContextUtils.getItrackerServices()
41                  .getIssueService();
42          ReportService reportService = ServletContextUtils.getItrackerServices()
43                  .getReportService();
44          ConfigurationService configurationService = ServletContextUtils.getItrackerServices()
45                  .getConfigurationService();
46          UserService userService = ServletContextUtils.getItrackerServices().getUserService();
47  
48  
49          ProjectService projectService2 = ServletContextUtils
50                  .getItrackerServices().getProjectService();
51  
52          String exportReport = "type=all&reportOutput=XML&reportId="
53                  + ReportUtilities.REPORT_EXPORT_XML;
54  
55          logTimeMillies("execute: looked up services", time_millies, log,
56                  Level.INFO);
57          Integer numberOfWorkflowScripts = configurationService
58                  .getWorkflowScripts().size();
59          request
60                  .setAttribute("numberOfWorkflowScripts",
61                          numberOfWorkflowScripts);
62          logTimeMillies("execute: looked up numberOfWorkflowScripts",
63                  time_millies, log, Level.INFO);
64  
65          ResourceBundle bundle = ITrackerResources.getBundle(ITrackerResources.BASE_LOCALE);
66          Enumeration<String> keysEnum = bundle.getKeys();
67          int i = 0;
68          while (keysEnum.hasMoreElements()) {
69              keysEnum.nextElement();
70              i++;
71          }
72  
73          request.setAttribute("numberDefinedKeys", i);
74          logTimeMillies("execute: looked up numberDefinedKeys", time_millies,
75                  log, Level.INFO);
76  
77          Integer numberOfStatuses = configurationService
78                  .getConfigurationItemsByType(
79                          Configuration.Type.status).size();
80          request.setAttribute("numberOfStatuses", numberOfStatuses);
81          logTimeMillies("execute: looked up numberOfStatuses", time_millies,
82                  log, Level.INFO);
83  
84          Integer numberOfSeverities = configurationService
85                  .getConfigurationItemsByType(
86                          Configuration.Type.severity).size();
87          request.setAttribute("numberOfSeverities", numberOfSeverities);
88          logTimeMillies("execute: looked up numberOfSeverities", time_millies,
89                  log, Level.INFO);
90  
91          Integer numberOfResolutions = configurationService
92                  .getConfigurationItemsByType(
93                          Configuration.Type.resolution).size();
94          request.setAttribute("numberOfResolutions", numberOfResolutions);
95          logTimeMillies("execute: looked up numberOfResolutions", time_millies,
96                  log, Level.INFO);
97  
98          Integer numberOfCustomProjectFields = configurationService
99                  .getCustomFields().size();
100         request.setAttribute("numberOfCustomProjectFields",
101                 numberOfCustomProjectFields);
102         logTimeMillies("execute: looked up numberOfCustomProjectFields",
103                 time_millies, log, Level.INFO);
104 
105         Integer numberofActiveSesssions = SessionManager.getNumActiveSessions();
106 
107         Integer numberUsers = userService.getAllUsers().size();
108 
109         request
110                 .setAttribute("numberofActiveSesssions",
111                         numberofActiveSesssions);
112         request
113                 .setAttribute("numberUsers",
114                         numberUsers);
115 
116         logTimeMillies("execute: looked up numberofActiveSesssions",
117                 time_millies, log, Level.INFO);
118 
119         Long allIssueAttachmentsTotalNumber = issueService
120                 .getAllIssueAttachmentCount();
121         request.setAttribute("allIssueAttachmentsTotalNumber",
122                 allIssueAttachmentsTotalNumber);
123         logTimeMillies("execute: looked up allIssueAttachmentsTotalNumber",
124                 time_millies, log, Level.INFO);
125 
126         Integer numberReports = 0;
127         try {
128             numberReports = reportService.getNumberReports();
129         } catch (Exception e) {
130             log.warn("execSetupJspEnv", e);
131         }
132         request.setAttribute("numberReports",
133                 numberReports);
134         Long numberIssues = issueService.getNumberIssues();
135 
136         // TODO: performance issue when attachments size needs to be calculated
137         // over many issues !
138         // select sum(size)
139         // from IssueAttachment
140         if (allIssueAttachmentsTotalNumber < 500) {
141             Long allIssueAttachmentsTotalSize = issueService
142                     .getAllIssueAttachmentSize();
143             request.setAttribute("allIssueAttachmentsTotalSize",
144                     allIssueAttachmentsTotalSize);
145         } else {
146             request.setAttribute("allIssueAttachmentsTotalSize", -1l);
147         }
148         logTimeMillies("execute: looked up allIssueAttachmentsTotalSize",
149                 time_millies, log, Level.INFO);
150 
151         /* set objects needed to render output in request object */
152         request.setAttribute("projectService", projectService2);
153         request.setAttribute("exportReport", exportReport);
154         request.setAttribute("sizeps", projectService2.getAllProjects().size());
155         request.setAttribute("numberIssues", numberIssues);
156 
157 
158         request.setAttribute("numberAvailableLanguages", configurationService.getNumberAvailableLanguages());
159         logTimeMillies("execute: put services to request", time_millies, log,
160                 Level.INFO);
161 
162         String pageTitleKey = "itracker.web.admin.index.title";
163         String pageTitleArg = "";
164         request.setAttribute("pageTitleKey", pageTitleKey);
165         request.setAttribute("pageTitleArg", pageTitleArg);
166 
167         logTimeMillies("execute: returning", time_millies, log, Level.INFO);
168     }
169 }