View Javadoc

1   /**
2    * Copyright 2005-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * A Struts ActionForm for the {@link StatsAction}.
35   *
36   * @see StatsAction
37   *
38   * @author Kuali Rice Team (rice.collab@kuali.org)
39   */
40  public class StatsForm extends KualiForm {
41  
42  	private static final long serialVersionUID = 4587377779133823858L;
43  	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      private String methodToCall = "";
61      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      // KULRICE-3137: Added a backLocation parameter similar to the one from lookups.
70      private String backLocation;
71      
72  	public StatsForm() {
73          stats = new Stats();
74      }
75  
76  	/**
77  	 * Retrieves the "returnLocation" parameter after calling "populate" on the superclass.
78  	 * 
79  	 * @see org.kuali.rice.krad.web.struts.form.KualiForm#populate(javax.servlet.http.HttpServletRequest)
80  	 */
81  	@Override
82  	public void populate(HttpServletRequest request) {
83  		super.populate(request);
84  		
85          if (getParameter(request, KRADConstants.RETURN_LOCATION_PARAMETER) != null) {
86              setBackLocation(getParameter(request, KRADConstants.RETURN_LOCATION_PARAMETER));
87          }
88  	}
89  	
90      public void determineBeginDate() {
91          SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT + TIME_FORMAT);
92  
93          beginningDate = null;
94          try {
95              if (getBegDate() == null || getBegDate().trim().equals("")) {
96                  beginningDate = dateFormat.parse(DEFAULT_BEGIN_DATE + BEG_DAY_TIME);
97              } else {
98                  beginningDate = dateFormat.parse(getBegDate() + BEG_DAY_TIME);
99              }
100 
101             dateFormat = new SimpleDateFormat(DATE_FORMAT);
102             begDate = dateFormat.format(beginningDate);
103         } catch (ParseException e) {
104             //parse error caught in validate methods
105         } finally {
106             if (beginningDate == null) {
107                 try {
108                     beginningDate = dateFormat.parse(DEFAULT_BEGIN_DATE + BEG_DAY_TIME);
109                 } catch (ParseException e) {
110                     throw new RuntimeException("Default Begin Date format incorrect");
111                 }
112             }
113         }
114     }
115 
116     public void determineEndDate() {
117         SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT + TIME_FORMAT);
118 
119         endingDate = null;
120         try {
121             if (getEndDate() == null || getEndDate().trim().equals("")) {
122                 endingDate = dateFormat.parse(DEFAULT_END_DATE + END_DAY_TIME);
123             } else {
124                 endingDate = dateFormat.parse(getEndDate() + END_DAY_TIME);
125             }
126 
127             dateFormat = new SimpleDateFormat(DATE_FORMAT);
128             endDate = dateFormat.format(endingDate);
129         } catch (ParseException e) {
130             //parse error caught in validate methods
131         } finally {
132             if (endingDate == null) {
133                 try {
134                     endingDate = dateFormat.parse(DEFAULT_END_DATE + END_DAY_TIME);
135                 } catch (ParseException e) {
136                     throw new RuntimeException("Default End Date format incorrect");
137                 }
138             }
139         }
140     }
141 
142     public Map makePerUnitOfTimeDropDownMap() {
143 
144         Map dropDownMap = new HashMap();
145         dropDownMap.put(DAY_TIME_UNIT, KewApiConstants.DAILY_UNIT);
146         dropDownMap.put(WEEK_TIME_UNIT, KewApiConstants.WEEKLY_UNIT);
147         dropDownMap.put(MONTH_TIME_UNIT, KewApiConstants.MONTHLY_UNIT);
148         dropDownMap.put(YEAR_TIME_UNIT, KewApiConstants.YEARLY_UNIT);
149         return dropDownMap;
150 
151     }
152 
153     public void validateDates() {
154         LOG.debug("validate()");
155 
156         //this.validateDate(BEGIN_DATE, this.getBegDate(), "general.error.fieldinvalid");
157         //this.validateDate(END_DATE, this.getEndDate(), "general.error.fieldinvalid");
158         if (getBegDate() != null && getBegDate().length() != 0) {
159             try {
160                 new SimpleDateFormat(DATE_FORMAT + TIME_FORMAT).parse(getBegDate().trim()+END_DAY_TIME);
161             } catch (ParseException e) {
162                 GlobalVariables.getMessageMap().putError(BEGIN_DATE, "general.error.fieldinvalid", "Begin Date");
163             }
164         }
165         if (getEndDate() != null && getEndDate().length() != 0) {
166             try {
167                 new SimpleDateFormat(DATE_FORMAT + TIME_FORMAT).parse(getEndDate().trim()+END_DAY_TIME);
168             } catch (ParseException e) {
169                 GlobalVariables.getMessageMap().putError(END_DATE, "general.error.fieldinvalid", "End Date");
170             }
171         }
172     }
173 
174     public Stats getStats() {
175         return stats;
176     }
177 
178     public void setStats(Stats stats) {
179         this.stats = stats;
180     }
181 
182     public String getCanceledLabel() {
183         return KewApiConstants.ROUTE_HEADER_CANCEL_LABEL;
184     }
185 
186     public String getDisapprovedLabel() {
187         return KewApiConstants.ROUTE_HEADER_DISAPPROVED_LABEL;
188     }
189 
190     public String getEnrouteLabel() {
191         return KewApiConstants.ROUTE_HEADER_ENROUTE_LABEL;
192     }
193 
194     public String getExceptionLabel() {
195         return KewApiConstants.ROUTE_HEADER_EXCEPTION_LABEL;
196     }
197 
198     public String getFinalLabel() {
199         return KewApiConstants.ROUTE_HEADER_FINAL_LABEL;
200     }
201 
202     public String getInitiatedLabel() {
203         return KewApiConstants.ROUTE_HEADER_INITIATED_LABEL;
204     }
205 
206     public String getProcessedLabel() {
207         return KewApiConstants.ROUTE_HEADER_PROCESSED_LABEL;
208     }
209 
210     public String getSavedLabel() {
211         return KewApiConstants.ROUTE_HEADER_SAVED_LABEL;
212     }
213 
214     public String getAvgActionsPerTimeUnit() {
215         return avgActionsPerTimeUnit;
216     }
217 
218     public void setAvgActionsPerTimeUnit(String string) {
219         avgActionsPerTimeUnit = string;
220     }
221 
222     public String getBegDate() {
223         return begDate;
224     }
225 
226     public void setBegDate(String begDate) {
227         this.begDate = begDate;
228     }
229 
230     public String getEndDate() {
231         return endDate;
232     }
233 
234     public void setEndDate(String endDate) {
235         this.endDate = endDate;
236     }
237 
238     public String getMethodToCall() {
239         return methodToCall;
240     }
241 
242     public void setMethodToCall(String methodToCall) {
243         this.methodToCall = methodToCall;
244     }
245 
246     public Date getBeginningDate() {
247         return beginningDate;
248     }
249 
250     public void setBeginningDate(Date beginningDate) {
251         this.beginningDate = beginningDate;
252     }
253 
254     public Date getEndingDate() {
255         return endingDate;
256     }
257 
258     public void setEndingDate(Date endingDate) {
259         this.endingDate = endingDate;
260     }
261 
262     public String getDayTimeUnit() {
263         return DAY_TIME_UNIT;
264     }
265 
266     public String getMonthTimeUnit() {
267         return MONTH_TIME_UNIT;
268     }
269 
270     public String getWeekTimeUnit() {
271         return WEEK_TIME_UNIT;
272     }
273 
274     public String getYearTimeUnit() {
275         return YEAR_TIME_UNIT;
276     }
277 
278 	public String getBackLocation() {
279 		return this.backLocation;
280 	}
281 
282 	public void setBackLocation(String backLocation) {
283 		this.backLocation = backLocation;
284 	}
285     
286 }