1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.stats.web; |
17 | |
|
18 | |
import java.text.ParseException; |
19 | |
import java.text.SimpleDateFormat; |
20 | |
import java.util.Date; |
21 | |
import java.util.HashMap; |
22 | |
import java.util.Map; |
23 | |
|
24 | |
import javax.servlet.http.HttpServletRequest; |
25 | |
|
26 | |
import org.kuali.rice.kew.stats.Stats; |
27 | |
import org.kuali.rice.kew.api.KewApiConstants; |
28 | |
import org.kuali.rice.kns.web.struts.form.KualiForm; |
29 | |
import org.kuali.rice.krad.util.GlobalVariables; |
30 | |
import org.kuali.rice.krad.util.KRADConstants; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
public class StatsForm extends KualiForm { |
41 | |
|
42 | |
private static final long serialVersionUID = 4587377779133823858L; |
43 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(StatsForm.class); |
44 | |
private static final String BEGIN_DATE = "begDate"; |
45 | |
private static final String END_DATE = "endDate"; |
46 | |
|
47 | |
public static final String DAY_TIME_UNIT = "DDD"; |
48 | |
public static final String WEEK_TIME_UNIT = "WW"; |
49 | |
public static final String MONTH_TIME_UNIT = "MM"; |
50 | |
public static final String YEAR_TIME_UNIT = "YYYY"; |
51 | |
|
52 | |
public static final String DEFAULT_BEGIN_DATE = "01/01/1900"; |
53 | |
public static final String DEFAULT_END_DATE = "01/01/2400"; |
54 | |
public static final String BEG_DAY_TIME = " 00:00"; |
55 | |
public static final String END_DAY_TIME = " 23:59"; |
56 | |
public static final String DATE_FORMAT = "MM/dd/yyyy"; |
57 | |
public static final String TIME_FORMAT = " HH:mm"; |
58 | |
|
59 | |
private Stats stats; |
60 | 0 | private String methodToCall = ""; |
61 | 0 | private String avgActionsPerTimeUnit = DAY_TIME_UNIT; |
62 | |
|
63 | |
private String begDate; |
64 | |
private String endDate; |
65 | |
|
66 | |
private Date beginningDate; |
67 | |
private Date endingDate; |
68 | |
|
69 | |
|
70 | |
private String backLocation; |
71 | |
|
72 | 0 | public StatsForm() { |
73 | 0 | stats = new Stats(); |
74 | 0 | } |
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
@Override |
82 | |
public void populate(HttpServletRequest request) { |
83 | 0 | super.populate(request); |
84 | |
|
85 | 0 | if (getParameter(request, KRADConstants.RETURN_LOCATION_PARAMETER) != null) { |
86 | 0 | setBackLocation(getParameter(request, KRADConstants.RETURN_LOCATION_PARAMETER)); |
87 | |
} |
88 | 0 | } |
89 | |
|
90 | |
public void determineBeginDate() { |
91 | 0 | SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT + TIME_FORMAT); |
92 | |
|
93 | 0 | beginningDate = null; |
94 | |
try { |
95 | 0 | if (getBegDate() == null || getBegDate().trim().equals("")) { |
96 | 0 | beginningDate = dateFormat.parse(DEFAULT_BEGIN_DATE + BEG_DAY_TIME); |
97 | |
} else { |
98 | 0 | beginningDate = dateFormat.parse(getBegDate() + BEG_DAY_TIME); |
99 | |
} |
100 | |
|
101 | 0 | dateFormat = new SimpleDateFormat(DATE_FORMAT); |
102 | 0 | begDate = dateFormat.format(beginningDate); |
103 | 0 | } catch (ParseException e) { |
104 | |
|
105 | |
} finally { |
106 | 0 | if (beginningDate == null) { |
107 | |
try { |
108 | 0 | beginningDate = dateFormat.parse(DEFAULT_BEGIN_DATE + BEG_DAY_TIME); |
109 | 0 | } catch (ParseException e) { |
110 | 0 | throw new RuntimeException("Default Begin Date format incorrect"); |
111 | 0 | } |
112 | |
} |
113 | |
} |
114 | 0 | } |
115 | |
|
116 | |
public void determineEndDate() { |
117 | 0 | SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT + TIME_FORMAT); |
118 | |
|
119 | 0 | endingDate = null; |
120 | |
try { |
121 | 0 | if (getEndDate() == null || getEndDate().trim().equals("")) { |
122 | 0 | endingDate = dateFormat.parse(DEFAULT_END_DATE + END_DAY_TIME); |
123 | |
} else { |
124 | 0 | endingDate = dateFormat.parse(getEndDate() + END_DAY_TIME); |
125 | |
} |
126 | |
|
127 | 0 | dateFormat = new SimpleDateFormat(DATE_FORMAT); |
128 | 0 | endDate = dateFormat.format(endingDate); |
129 | 0 | } catch (ParseException e) { |
130 | |
|
131 | |
} finally { |
132 | 0 | if (endingDate == null) { |
133 | |
try { |
134 | 0 | endingDate = dateFormat.parse(DEFAULT_END_DATE + END_DAY_TIME); |
135 | 0 | } catch (ParseException e) { |
136 | 0 | throw new RuntimeException("Default End Date format incorrect"); |
137 | 0 | } |
138 | |
} |
139 | |
} |
140 | 0 | } |
141 | |
|
142 | |
public Map makePerUnitOfTimeDropDownMap() { |
143 | |
|
144 | 0 | Map dropDownMap = new HashMap(); |
145 | 0 | dropDownMap.put(DAY_TIME_UNIT, KewApiConstants.DAILY_UNIT); |
146 | 0 | dropDownMap.put(WEEK_TIME_UNIT, KewApiConstants.WEEKLY_UNIT); |
147 | 0 | dropDownMap.put(MONTH_TIME_UNIT, KewApiConstants.MONTHLY_UNIT); |
148 | 0 | dropDownMap.put(YEAR_TIME_UNIT, KewApiConstants.YEARLY_UNIT); |
149 | 0 | return dropDownMap; |
150 | |
|
151 | |
} |
152 | |
|
153 | |
public void validateDates() { |
154 | 0 | LOG.debug("validate()"); |
155 | |
|
156 | |
|
157 | |
|
158 | 0 | if (getBegDate() != null && getBegDate().length() != 0) { |
159 | |
try { |
160 | 0 | new SimpleDateFormat(DATE_FORMAT + TIME_FORMAT).parse(getBegDate().trim()+END_DAY_TIME); |
161 | 0 | } catch (ParseException e) { |
162 | 0 | GlobalVariables.getMessageMap().putError(BEGIN_DATE, "general.error.fieldinvalid", "Begin Date"); |
163 | 0 | } |
164 | |
} |
165 | 0 | if (getEndDate() != null && getEndDate().length() != 0) { |
166 | |
try { |
167 | 0 | new SimpleDateFormat(DATE_FORMAT + TIME_FORMAT).parse(getEndDate().trim()+END_DAY_TIME); |
168 | 0 | } catch (ParseException e) { |
169 | 0 | GlobalVariables.getMessageMap().putError(END_DATE, "general.error.fieldinvalid", "End Date"); |
170 | 0 | } |
171 | |
} |
172 | 0 | } |
173 | |
|
174 | |
public Stats getStats() { |
175 | 0 | return stats; |
176 | |
} |
177 | |
|
178 | |
public void setStats(Stats stats) { |
179 | 0 | this.stats = stats; |
180 | 0 | } |
181 | |
|
182 | |
public String getCanceledLabel() { |
183 | 0 | return KewApiConstants.ROUTE_HEADER_CANCEL_LABEL; |
184 | |
} |
185 | |
|
186 | |
public String getDisapprovedLabel() { |
187 | 0 | return KewApiConstants.ROUTE_HEADER_DISAPPROVED_LABEL; |
188 | |
} |
189 | |
|
190 | |
public String getEnrouteLabel() { |
191 | 0 | return KewApiConstants.ROUTE_HEADER_ENROUTE_LABEL; |
192 | |
} |
193 | |
|
194 | |
public String getExceptionLabel() { |
195 | 0 | return KewApiConstants.ROUTE_HEADER_EXCEPTION_LABEL; |
196 | |
} |
197 | |
|
198 | |
public String getFinalLabel() { |
199 | 0 | return KewApiConstants.ROUTE_HEADER_FINAL_LABEL; |
200 | |
} |
201 | |
|
202 | |
public String getInitiatedLabel() { |
203 | 0 | return KewApiConstants.ROUTE_HEADER_INITIATED_LABEL; |
204 | |
} |
205 | |
|
206 | |
public String getProcessedLabel() { |
207 | 0 | return KewApiConstants.ROUTE_HEADER_PROCESSED_LABEL; |
208 | |
} |
209 | |
|
210 | |
public String getSavedLabel() { |
211 | 0 | return KewApiConstants.ROUTE_HEADER_SAVED_LABEL; |
212 | |
} |
213 | |
|
214 | |
public String getAvgActionsPerTimeUnit() { |
215 | 0 | return avgActionsPerTimeUnit; |
216 | |
} |
217 | |
|
218 | |
public void setAvgActionsPerTimeUnit(String string) { |
219 | 0 | avgActionsPerTimeUnit = string; |
220 | 0 | } |
221 | |
|
222 | |
public String getBegDate() { |
223 | 0 | return begDate; |
224 | |
} |
225 | |
|
226 | |
public void setBegDate(String begDate) { |
227 | 0 | this.begDate = begDate; |
228 | 0 | } |
229 | |
|
230 | |
public String getEndDate() { |
231 | 0 | return endDate; |
232 | |
} |
233 | |
|
234 | |
public void setEndDate(String endDate) { |
235 | 0 | this.endDate = endDate; |
236 | 0 | } |
237 | |
|
238 | |
public String getMethodToCall() { |
239 | 0 | return methodToCall; |
240 | |
} |
241 | |
|
242 | |
public void setMethodToCall(String methodToCall) { |
243 | 0 | this.methodToCall = methodToCall; |
244 | 0 | } |
245 | |
|
246 | |
public Date getBeginningDate() { |
247 | 0 | return beginningDate; |
248 | |
} |
249 | |
|
250 | |
public void setBeginningDate(Date beginningDate) { |
251 | 0 | this.beginningDate = beginningDate; |
252 | 0 | } |
253 | |
|
254 | |
public Date getEndingDate() { |
255 | 0 | return endingDate; |
256 | |
} |
257 | |
|
258 | |
public void setEndingDate(Date endingDate) { |
259 | 0 | this.endingDate = endingDate; |
260 | 0 | } |
261 | |
|
262 | |
public String getDayTimeUnit() { |
263 | 0 | return DAY_TIME_UNIT; |
264 | |
} |
265 | |
|
266 | |
public String getMonthTimeUnit() { |
267 | 0 | return MONTH_TIME_UNIT; |
268 | |
} |
269 | |
|
270 | |
public String getWeekTimeUnit() { |
271 | 0 | return WEEK_TIME_UNIT; |
272 | |
} |
273 | |
|
274 | |
public String getYearTimeUnit() { |
275 | 0 | return YEAR_TIME_UNIT; |
276 | |
} |
277 | |
|
278 | |
public String getBackLocation() { |
279 | 0 | return this.backLocation; |
280 | |
} |
281 | |
|
282 | |
public void setBackLocation(String backLocation) { |
283 | 0 | this.backLocation = backLocation; |
284 | 0 | } |
285 | |
|
286 | |
} |