Coverage Report - org.kuali.student.enrollment.uif.control.ScheduleControl
 
Classes in this File Line Coverage Branch Coverage Complexity
ScheduleControl
0%
0/89
0%
0/40
1.952
ScheduleControl$dayTypes
0%
0/1
N/A
1.952
 
 1  
 package org.kuali.student.enrollment.uif.control;
 2  
 
 3  
 import org.apache.commons.lang.StringUtils;
 4  
 import org.kuali.rice.krad.uif.control.ControlBase;
 5  
 import org.kuali.rice.krad.uif.element.Header;
 6  
 
 7  
 import java.text.DateFormatSymbols;
 8  
 import java.util.ArrayList;
 9  
 import java.util.Calendar;
 10  
 import java.util.List;
 11  
 import java.util.Locale;
 12  
 
 13  
 /* Copyright 2011 The Kuali Foundation
 14  
  *
 15  
  * Licensed under the Educational Community License, Version 1.0 (the
 16  
  * "License"); you may not use this file except in compliance with the License.
 17  
  * You may obtain a copy of the License at
 18  
  *
 19  
  * http://www.opensource.org/licenses/ecl1.php
 20  
  *
 21  
  * Unless required by applicable law or agreed to in writing, software
 22  
  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 23  
  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 24  
  * License for the specific language governing permissions and limitations under
 25  
  * the License.
 26  
  */
 27  0
 public class ScheduleControl extends ControlBase {
 28  
     private Header header;
 29  
     private List<String> days;
 30  
     private List<String> times;
 31  
     private boolean sundayFirst;
 32  
     //arbitrary defaults for start and endtime
 33  0
     private Integer startTime = 5;
 34  0
     private Integer endTime = 20;
 35  
     private boolean useLetterKeys;
 36  
     private boolean omitWeekend;
 37  
     private boolean omitAMPMSuffix;
 38  
     private boolean militaryTime;
 39  
     private String dayType;
 40  
 
 41  
 
 42  0
     public static class dayTypes {
 43  
         public static final String ONE_LETTER = "ONE_LETTER";
 44  
         public static final String TWO_LETTER = "TWO_LETTER";
 45  
         public static final String SHORT = "SHORT";
 46  
         public static final String FULL = "FULL";
 47  
     }
 48  
 
 49  
     private static final String ZEROS = ":00";
 50  
 
 51  
     public String getScheduleOptions() {
 52  0
         return "{" +
 53  
                 "sundayFirst: " + sundayFirst + ", " +
 54  
                 "startTime: " + startTime + ", " +
 55  
                 "endTime: " + endTime + ", " +
 56  
                 "useLetterKeys: " + useLetterKeys + ", " +
 57  
                 "omitWeekend: " + omitWeekend +
 58  
                 "}";
 59  
     }
 60  
 
 61  
     public List<String> getDays() {
 62  
         //International - based on locale
 63  0
         Locale usersLocale = Locale.getDefault();
 64  
 
 65  0
         DateFormatSymbols dfs = new DateFormatSymbols(usersLocale);
 66  0
         String weekdays[] = dfs.getWeekdays();
 67  0
         days = new ArrayList<String>(8);
 68  0
         days.add("&nbsp;");
 69  
 
 70  0
         if (StringUtils.isEmpty(dayType) || dayType.equalsIgnoreCase(dayTypes.FULL) ||
 71  
                 dayType.equalsIgnoreCase(dayTypes.SHORT)) {
 72  
 
 73  0
             if (StringUtils.isEmpty(dayType)) {
 74  
                 //default when not set is short
 75  0
                 dayType = dayTypes.SHORT;
 76  
             }
 77  
 
 78  0
             if (dayType.equalsIgnoreCase(dayTypes.SHORT)) {
 79  0
                 weekdays = dfs.getShortWeekdays();
 80  
             }
 81  
 
 82  0
             days.add(weekdays[Calendar.MONDAY]);
 83  0
             days.add(weekdays[Calendar.TUESDAY]);
 84  0
             days.add(weekdays[Calendar.WEDNESDAY]);
 85  0
             days.add(weekdays[Calendar.THURSDAY]);
 86  0
             days.add(weekdays[Calendar.FRIDAY]);
 87  
 
 88  0
             if (sundayFirst && !omitWeekend) {
 89  0
                 days.add(0, weekdays[Calendar.SUNDAY]);
 90  0
                 days.add(weekdays[Calendar.SATURDAY]);
 91  0
             } else if (!omitWeekend) {
 92  0
                 days.add(weekdays[Calendar.SATURDAY]);
 93  0
                 days.add(weekdays[Calendar.SUNDAY]);
 94  
             }
 95  0
         } else if (dayType.equalsIgnoreCase(dayTypes.ONE_LETTER) ||
 96  
                 dayType.equalsIgnoreCase(dayTypes.TWO_LETTER)) {
 97  
 
 98  0
             int end = 1;
 99  0
             if (dayType.equalsIgnoreCase(dayTypes.TWO_LETTER)) {
 100  0
                 end = 2;
 101  
             }
 102  
 
 103  0
             days.add(weekdays[Calendar.MONDAY].substring(0, end));
 104  0
             days.add(weekdays[Calendar.TUESDAY].substring(0, end));
 105  0
             days.add(weekdays[Calendar.WEDNESDAY].substring(0, end));
 106  0
             days.add(weekdays[Calendar.THURSDAY].substring(0, end));
 107  0
             days.add(weekdays[Calendar.FRIDAY].substring(0, end));
 108  
 
 109  0
             if (sundayFirst && !omitWeekend) {
 110  0
                 days.add(0, weekdays[Calendar.SUNDAY].substring(0, end));
 111  0
                 days.add(weekdays[Calendar.SATURDAY].substring(0, end));
 112  0
             } else if (!omitWeekend) {
 113  0
                 days.add(weekdays[Calendar.SATURDAY].substring(0, end));
 114  0
                 days.add(weekdays[Calendar.SUNDAY].substring(0, end));
 115  
             }
 116  
         }
 117  0
         return days;
 118  
     }
 119  
 
 120  
     public List<String> getTimes() {
 121  
 
 122  0
         String am = "";
 123  0
         String pm = "";
 124  0
         if (!omitAMPMSuffix) {
 125  
             //international ampm symbols
 126  0
             Locale usersLocale = Locale.getDefault();
 127  0
             DateFormatSymbols dfs = new DateFormatSymbols(usersLocale);
 128  0
             String ampm[] = dfs.getAmPmStrings();
 129  0
             am = ampm[Calendar.AM];
 130  0
             pm = ampm[Calendar.PM];
 131  
         }
 132  
 
 133  0
         times = new ArrayList<String>();
 134  
 
 135  0
         for (int i = startTime; i < endTime; i++) {
 136  0
             if (!militaryTime) {
 137  0
                 if (i > 12) {
 138  0
                     times.add("" + (i - 12) + ZEROS + pm);
 139  
                 }
 140  0
                 else if (i == 12){
 141  0
                     times.add("" + i + ZEROS + pm);
 142  
                 }
 143  0
                 else if (i == 0) {
 144  0
                     times.add("12" + ZEROS + am);
 145  
                 } else {
 146  0
                     times.add("" + i + ZEROS + am);
 147  
                 }
 148  
 
 149  
             } else {
 150  0
                 times.add("" + i + ZEROS);
 151  
             }
 152  
         }
 153  
 
 154  0
         return times;
 155  
     }
 156  
 
 157  
     public boolean isSundayFirst() {
 158  0
         return sundayFirst;
 159  
     }
 160  
 
 161  
     public void setSundayFirst(boolean sundayFirst) {
 162  0
         this.sundayFirst = sundayFirst;
 163  0
     }
 164  
 
 165  
     public boolean isUseLetterKeys() {
 166  0
         return useLetterKeys;
 167  
     }
 168  
 
 169  
     public void setUseLetterKeys(boolean useLetterKeys) {
 170  0
         this.useLetterKeys = useLetterKeys;
 171  0
     }
 172  
 
 173  
     public boolean isOmitWeekend() {
 174  0
         return omitWeekend;
 175  
     }
 176  
 
 177  
     public void setOmitWeekend(boolean omitWeekend) {
 178  0
         this.omitWeekend = omitWeekend;
 179  0
     }
 180  
 
 181  
     public String getDayType() {
 182  0
         return dayType;
 183  
     }
 184  
 
 185  
     public void setDayType(String dayType) {
 186  0
         this.dayType = dayType;
 187  0
     }
 188  
 
 189  
     public Integer getStartTime() {
 190  0
         return startTime;
 191  
     }
 192  
 
 193  
     public void setStartTime(Integer startTime) {
 194  0
         this.startTime = startTime;
 195  0
     }
 196  
 
 197  
     public Integer getEndTime() {
 198  0
         return endTime;
 199  
     }
 200  
 
 201  
     public void setEndTime(Integer endTime) {
 202  0
         this.endTime = endTime;
 203  0
     }
 204  
 
 205  
     public boolean isOmitAMPMSuffix() {
 206  0
         return omitAMPMSuffix;
 207  
     }
 208  
 
 209  
     public void setOmitAMPMSuffix(boolean omitAMPMSuffix) {
 210  0
         this.omitAMPMSuffix = omitAMPMSuffix;
 211  0
     }
 212  
 
 213  
     public boolean isMilitaryTime() {
 214  0
         return militaryTime;
 215  
     }
 216  
 
 217  
     public void setMilitaryTime(boolean militaryTime) {
 218  0
         this.militaryTime = militaryTime;
 219  0
     }
 220  
 
 221  
     public Header getHeader() {
 222  0
         return header;
 223  
     }
 224  
 
 225  
     public void setHeader(Header header) {
 226  0
         this.header = header;
 227  0
     }
 228  
 }