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