Coverage Report - org.kuali.student.enrollment.class2.acal.dto.HolidayWrapper
 
Classes in this File Line Coverage Branch Coverage Complexity
HolidayWrapper
0%
0/52
0%
0/16
1.867
 
 1  
 /**
 2  
  * Copyright 2012 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 14  
  *
 15  
  */
 16  
 package org.kuali.student.enrollment.class2.acal.dto;
 17  
 
 18  
 import org.apache.commons.lang.BooleanUtils;
 19  
 import org.apache.commons.lang.StringUtils;
 20  
 import org.kuali.student.enrollment.acal.dto.HolidayInfo;
 21  
 
 22  
 import java.util.Date;
 23  
 
 24  
 /**
 25  
  * @author Kuali Student Team
 26  
  */
 27  0
 public class HolidayWrapper extends TimeSetWrapper implements Comparable<HolidayWrapper> {
 28  
 
 29  
     private String typeName;
 30  
     private HolidayInfo holidayInfo;
 31  
     private boolean instructional;
 32  
     private String typeKey;
 33  
 
 34  0
     public HolidayWrapper(){
 35  0
         holidayInfo = new HolidayInfo();
 36  0
         setAllDay(true);
 37  0
         setInstructional(false);
 38  0
         setDateRange(false);
 39  0
     }
 40  
 
 41  0
     public HolidayWrapper(HolidayInfo holidayInfo){
 42  0
         this.setHolidayInfo(holidayInfo);
 43  0
         this.setStartDate(holidayInfo.getStartDate());
 44  0
         this.setEndDate(holidayInfo.getEndDate());
 45  0
         this.setAllDay(holidayInfo.getIsAllDay());
 46  0
         this.setDateRange(holidayInfo.getIsDateRange());
 47  0
         this.setTypeKey(holidayInfo.getTypeKey());
 48  0
         this.setInstructional(holidayInfo.getIsInstructionalDay());
 49  0
         buildDateAndTime();
 50  0
     }
 51  
 
 52  
     public String getTypeName() {
 53  0
         return typeName;
 54  
     }
 55  
 
 56  
     public void setTypeName(String typeName) {
 57  0
         this.typeName = typeName;
 58  0
     }
 59  
 
 60  
     public HolidayInfo getHolidayInfo() {
 61  0
         return holidayInfo;
 62  
     }
 63  
 
 64  
     public void setHolidayInfo(HolidayInfo holidayInfo) {
 65  
 
 66  
         // check the flags against the values in the DTO
 67  0
         this.setAllDay(holidayInfo.getIsAllDay());
 68  0
         this.setDateRange(holidayInfo.getIsDateRange());
 69  0
         this.setInstructional(holidayInfo.getIsInstructionalDay());
 70  
 
 71  0
         this.holidayInfo = holidayInfo;
 72  0
     }
 73  
 
 74  
     //This is for UI display purpose
 75  
     public String getIsNonInstructional(){
 76  0
         if (holidayInfo != null){
 77  0
             return StringUtils.capitalize(BooleanUtils.toStringYesNo(!holidayInfo.getIsInstructionalDay()));
 78  
         }
 79  0
         return StringUtils.capitalize(BooleanUtils.toStringYesNo(true));
 80  
     }
 81  
 
 82  
     public boolean isInstructional() {
 83  0
         return instructional;
 84  
     }
 85  
 
 86  
     public void setInstructional(boolean instructional) {
 87  0
         this.instructional = instructional;
 88  0
     }
 89  
 
 90  
     public String getTypeKey() {
 91  0
         return typeKey;
 92  
     }
 93  
 
 94  
     public void setTypeKey(String typeKey) {
 95  0
         this.typeKey = typeKey;
 96  0
     }
 97  
 
 98  
 
 99  
     /**
 100  
      * Allow Collections.sort() to sort by startDate & endDate
 101  
      */
 102  
     public int compareTo(HolidayWrapper holidayToCompare) {
 103  0
         int compareValue = compareDates(this.getStartDate(), holidayToCompare.getStartDate());
 104  0
         if (compareValue == 0) {
 105  
             // startDates are equal so compare endDates
 106  0
             compareValue = compareDates(this.getEndDate(), holidayToCompare.getEndDate());
 107  
         }
 108  0
         return compareValue;
 109  
     }
 110  
 
 111  
     private int compareDates(Date thisDate, Date compareToDate) {
 112  
         // unfortunately, Date.before() & .after() are not null friendly
 113  
 
 114  0
         if (null == thisDate) {
 115  0
             if (null == compareToDate) {
 116  0
                 return 0; // both dates are null and therefore equal
 117  
             }
 118  0
             return -1; // compare-date is later than this-date (which is null)
 119  
         }
 120  
 
 121  0
         if (null == compareToDate) {
 122  0
             return 1; // this-date (which is valid) is after the compare-date (which is null)
 123  
         }
 124  
 
 125  
         // safe to use .before() and .after() methods to do the comparison
 126  0
         if (thisDate.before(compareToDate)) {
 127  0
             return -1;
 128  
         }
 129  0
         if (thisDate.after(compareToDate)) {
 130  0
             return 1;
 131  
         }
 132  0
         return 0; // dates are equal
 133  
     }
 134  
 
 135  
     //This is for UI display purpose
 136  
     public String getStartDateUI(){
 137  0
         return formatStartDateUI(holidayInfo.getStartDate());
 138  
     }
 139  
 
 140  
     //This is for UI display purpose
 141  
     public String getEndDateUI(){
 142  0
         return formatEndDateUI(holidayInfo.getEndDate());
 143  
     }
 144  
 
 145  
 }