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