001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.stats.web;
018:
019: import java.text.ParseException;
020: import java.text.SimpleDateFormat;
021: import java.util.Date;
022: import java.util.HashMap;
023: import java.util.Map;
024:
025: import javax.servlet.http.HttpServletRequest;
026:
027: import org.apache.struts.Globals;
028: import org.apache.struts.action.ActionErrors;
029: import org.apache.struts.action.ActionForm;
030: import org.apache.struts.action.ActionMapping;
031: import org.apache.struts.action.ActionMessage;
032:
033: import edu.iu.uis.eden.EdenConstants;
034: import edu.iu.uis.eden.stats.Stats;
035:
036: /**
037: * A Struts ActionForm for the {@link StatsAction}.
038: *
039: * @see StatsAction
040: *
041: * @author temay
042: */
043: public class StatsForm extends ActionForm {
044:
045: private static final long serialVersionUID = 4587377779133823858L;
046: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
047: .getLogger(StatsForm.class);
048:
049: public static final String DAY_TIME_UNIT = "DDD";
050: public static final String WEEK_TIME_UNIT = "WW";
051: public static final String MONTH_TIME_UNIT = "MM";
052: public static final String YEAR_TIME_UNIT = "YYYY";
053:
054: public static final String DEFAULT_BEGIN_DATE = "01/01/1900";
055: public static final String DEFAULT_END_DATE = "01/01/2400";
056: public static final String BEG_DAY_TIME = " 00:00";
057: public static final String END_DAY_TIME = " 23:59";
058: public static final String DATE_FORMAT = "MM/dd/yyyy";
059: public static final String TIME_FORMAT = " HH:mm";
060:
061: private Stats stats;
062: private String methodToCall = "";
063: private String avgActionsPerTimeUnit = DAY_TIME_UNIT;
064:
065: private String begDate;
066: private String endDate;
067:
068: private Date beginningDate;
069: private Date endingDate;
070:
071: public StatsForm() {
072: stats = new Stats();
073: }
074:
075: public void determineBeginDate() throws ParseException {
076:
077: SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT
078: + TIME_FORMAT);
079:
080: beginningDate = null;
081:
082: if (getBegDate() == null || getBegDate().trim().equals("")) {
083: beginningDate = dateFormat.parse(DEFAULT_BEGIN_DATE
084: + BEG_DAY_TIME);
085: } else {
086: beginningDate = dateFormat.parse(getBegDate()
087: + BEG_DAY_TIME);
088: }
089:
090: dateFormat = new SimpleDateFormat(DATE_FORMAT);
091: begDate = dateFormat.format(beginningDate);
092: }
093:
094: public void determineEndDate() throws ParseException {
095:
096: SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT
097: + TIME_FORMAT);
098:
099: endingDate = null;
100:
101: if (getEndDate() == null || getEndDate().trim().equals("")) {
102: endingDate = dateFormat.parse(DEFAULT_END_DATE
103: + END_DAY_TIME);
104: } else {
105: endingDate = dateFormat.parse(getEndDate() + END_DAY_TIME);
106: }
107:
108: dateFormat = new SimpleDateFormat(DATE_FORMAT);
109: endDate = dateFormat.format(endingDate);
110: }
111:
112: public Map makePerUnitOfTimeDropDownMap() {
113:
114: Map dropDownMap = new HashMap();
115: dropDownMap.put(DAY_TIME_UNIT, EdenConstants.DAILY_UNIT);
116: dropDownMap.put(WEEK_TIME_UNIT, EdenConstants.WEEKLY_UNIT);
117: dropDownMap.put(MONTH_TIME_UNIT, EdenConstants.MONTHLY_UNIT);
118: dropDownMap.put(YEAR_TIME_UNIT, EdenConstants.YEARLY_UNIT);
119: return dropDownMap;
120:
121: }
122:
123: public ActionErrors validate(ActionMapping mapping,
124: HttpServletRequest request) {
125: LOG.debug("validate()");
126:
127: ActionErrors errors = new ActionErrors();
128:
129: this .validateDate(this .getBegDate(), errors,
130: "error.stats.BegDate");
131: this .validateDate(this .getEndDate(), errors,
132: "error.stats.EndDate");
133:
134: return errors;
135: }
136:
137: private void validateDate(String date, ActionErrors errors,
138: String key) {
139:
140: if (date == null || date.trim().equals(""))
141: return;
142:
143: try {
144: new SimpleDateFormat(DATE_FORMAT).parse(date.trim());
145: } catch (ParseException ex) {
146: errors.add(Globals.ERROR_KEY, new ActionMessage(key, date));
147: }
148: }
149:
150: public Stats getStats() {
151: return stats;
152: }
153:
154: public void setStats(Stats stats) {
155: this .stats = stats;
156: }
157:
158: public String getApprovedLabel() {
159: return EdenConstants.ROUTE_HEADER_APPROVED_LABEL;
160: }
161:
162: public String getCanceledLabel() {
163: return EdenConstants.ROUTE_HEADER_CANCEL_LABEL;
164: }
165:
166: public String getDisapprovedLabel() {
167: return EdenConstants.ROUTE_HEADER_DISAPPROVED_LABEL;
168: }
169:
170: public String getEnrouteLabel() {
171: return EdenConstants.ROUTE_HEADER_ENROUTE_LABEL;
172: }
173:
174: public String getExceptionLabel() {
175: return EdenConstants.ROUTE_HEADER_EXCEPTION_LABEL;
176: }
177:
178: public String getFinalLabel() {
179: return EdenConstants.ROUTE_HEADER_FINAL_LABEL;
180: }
181:
182: public String getInitiatedLabel() {
183: return EdenConstants.ROUTE_HEADER_INITIATED_LABEL;
184: }
185:
186: public String getProcessedLabel() {
187: return EdenConstants.ROUTE_HEADER_PROCESSED_LABEL;
188: }
189:
190: public String getSavedLabel() {
191: return EdenConstants.ROUTE_HEADER_SAVED_LABEL;
192: }
193:
194: public String getAvgActionsPerTimeUnit() {
195: return avgActionsPerTimeUnit;
196: }
197:
198: public void setAvgActionsPerTimeUnit(String string) {
199: avgActionsPerTimeUnit = string;
200: }
201:
202: public String getBegDate() {
203: return begDate;
204: }
205:
206: public void setBegDate(String begDate) {
207: this .begDate = begDate;
208: }
209:
210: public String getEndDate() {
211: return endDate;
212: }
213:
214: public void setEndDate(String endDate) {
215: this .endDate = endDate;
216: }
217:
218: public String getMethodToCall() {
219: return methodToCall;
220: }
221:
222: public void setMethodToCall(String methodToCall) {
223: this .methodToCall = methodToCall;
224: }
225:
226: public Date getBeginningDate() {
227: return beginningDate;
228: }
229:
230: public void setBeginningDate(Date beginningDate) {
231: this .beginningDate = beginningDate;
232: }
233:
234: public Date getEndingDate() {
235: return endingDate;
236: }
237:
238: public void setEndingDate(Date endingDate) {
239: this .endingDate = endingDate;
240: }
241:
242: public String getDayTimeUnit() {
243: return DAY_TIME_UNIT;
244: }
245:
246: public String getMonthTimeUnit() {
247: return MONTH_TIME_UNIT;
248: }
249:
250: public String getWeekTimeUnit() {
251: return WEEK_TIME_UNIT;
252: }
253:
254: public String getYearTimeUnit() {
255: return YEAR_TIME_UNIT;
256: }
257:
258: }
|