Coverage Report - org.kuali.student.enrollment.class2.registration.dto.MeetingScheduleWrapper
 
Classes in this File Line Coverage Branch Coverage Complexity
MeetingScheduleWrapper
0%
0/97
0%
0/32
1.696
 
 1  
 package org.kuali.student.enrollment.class2.registration.dto;
 2  
 
 3  
 import org.apache.commons.lang.StringUtils;
 4  
 import org.kuali.student.r2.common.dto.MeetingScheduleInfo;
 5  
 
 6  
 import java.io.Serializable;
 7  
 import java.text.DateFormatSymbols;
 8  
 import java.util.*;
 9  
 
 10  
 public class MeetingScheduleWrapper implements Serializable {
 11  
     private static final long serialVersionUID = 1L;
 12  
 
 13  
     private MeetingScheduleInfo meetingSchedule;
 14  
 
 15  
     private String courseTitle;
 16  
     private String courseOfferingCode;
 17  
     private List<String> days;
 18  
     private String startTime;
 19  
     private String endTime;
 20  
     private String itemId;
 21  
     private String timeTypeName;
 22  
     private String regGroupTimesJsObject;
 23  
 
 24  0
     public MeetingScheduleWrapper() {
 25  0
         this.days = new ArrayList<String>();
 26  0
     }
 27  
 
 28  
     public MeetingScheduleWrapper(MeetingScheduleInfo meetingSchedule) {
 29  0
         this();
 30  0
         this.meetingSchedule = meetingSchedule;
 31  
         // timePeriods string should be in format "TU,TH;1130,1330"
 32  0
         String timePeriods = getMeetingSchedule().getScheduleId();
 33  0
         String[] timePeriodsSplit = StringUtils.splitPreserveAllTokens(timePeriods, ";");
 34  0
         Collections.addAll(days, StringUtils.split(timePeriodsSplit[0], ","));
 35  0
         String[] timesArray = StringUtils.split(timePeriodsSplit[1], ",");
 36  0
         this.startTime = timesArray[0];
 37  0
         this.endTime = timesArray[1];
 38  0
     }
 39  
 
 40  
     public MeetingScheduleInfo getMeetingSchedule() {
 41  0
         return meetingSchedule;
 42  
     }
 43  
 
 44  
     public void setMeetingSchedule(MeetingScheduleInfo meetingSchedule) {
 45  0
         this.meetingSchedule = meetingSchedule;
 46  0
     }
 47  
 
 48  
     public String getCourseTitle() {
 49  0
         return courseTitle;
 50  
     }
 51  
 
 52  
     public void setCourseTitle(String courseTitle) {
 53  0
         this.courseTitle = courseTitle;
 54  0
     }
 55  
 
 56  
     public String getCourseOfferingCode() {
 57  0
         return courseOfferingCode;
 58  
     }
 59  
 
 60  
     public void setCourseOfferingCode(String courseOfferingCode) {
 61  0
         this.courseOfferingCode = courseOfferingCode;
 62  0
     }
 63  
 
 64  
     public List<String> getDays() {
 65  0
         return days;
 66  
     }
 67  
 
 68  
     public void setDays(List<String> days) {
 69  0
         this.days = days;
 70  0
     }
 71  
 
 72  
     public String getStartTime() {
 73  0
         return startTime;
 74  
     }
 75  
 
 76  
     public void setStartTime(String startTime) {
 77  0
         this.startTime = startTime;
 78  0
     }
 79  
 
 80  
     public String getEndTime() {
 81  0
         return endTime;
 82  
     }
 83  
 
 84  
     public void setEndTime(String endTime) {
 85  0
         this.endTime = endTime;
 86  0
     }
 87  
 
 88  
     public String getJsScheduleObject() {
 89  0
         String daysArray = "[";
 90  0
         for (String day : getDays()) {
 91  0
             daysArray = daysArray + "'" + day + "',";
 92  
         }
 93  0
         daysArray = StringUtils.removeEnd(daysArray, ",") + "]";
 94  0
         String st = startTime.trim();
 95  0
         String et = endTime.trim();
 96  0
         if (st.length() == 3) {
 97  0
             st = "0" + st;
 98  
         }
 99  0
         if (et.length() == 3) {
 100  0
             et = "0" + et;
 101  
         }
 102  0
         if (itemId == null) {
 103  0
             itemId = "";
 104  
         }
 105  0
         if (timeTypeName == null) {
 106  0
             timeTypeName = "";
 107  
         }
 108  
 
 109  0
         return "{timeId:'" + itemId + "', timeType:'" + timeTypeName + "', days:" + daysArray + ", startTime: '" + st + "', endTime: '" + et
 110  
                 + "', name: '" + courseOfferingCode + " " + courseTitle + "', displayableTime:'"+getDisplayableTime()+"' }";
 111  
     }
 112  
 
 113  
     public String getDisplayableTime() {
 114  
         //return human readable time format
 115  0
         StringBuilder builder = new StringBuilder();
 116  0
         for (String day : getDays()) {
 117  0
             if (StringUtils.isNotBlank(builder.toString())) {
 118  0
                 builder.append(",");
 119  
             }
 120  0
             builder.append(day);
 121  
         }
 122  
 
 123  0
         String hrStart = startTime.trim();
 124  0
         String hrEnd = endTime.trim();
 125  
 
 126  0
         hrStart = convertToStandardTime(hrStart);
 127  0
         hrEnd = convertToStandardTime(hrEnd);
 128  
 
 129  
         //Shorten string length if applicable
 130  
         //international ampm symbols
 131  0
         Locale usersLocale = Locale.getDefault();
 132  0
         DateFormatSymbols dfs = new DateFormatSymbols(usersLocale);
 133  0
         String ampm[] = dfs.getAmPmStrings();
 134  0
         String am = ampm[Calendar.AM];
 135  0
         String pm = ampm[Calendar.PM];
 136  0
         if (hrStart.endsWith(am) && hrEnd.endsWith(am)) {
 137  0
             hrStart = hrStart.replace(am, "");
 138  
 
 139  0
         } else if (hrStart.endsWith(pm) && hrEnd.endsWith(pm)) {
 140  0
             hrStart = hrStart.replace(pm, "");
 141  
         }
 142  
 
 143  0
         return hrStart + "-" + hrEnd + " | " + builder.toString();
 144  
     }
 145  
 
 146  
     private String convertToStandardTime(String time) {
 147  
         String minutes;
 148  
         String hours;
 149  0
         if (time.length() == 3) {
 150  0
             hours = time.substring(0, 1);
 151  0
             minutes = time.substring(1);
 152  
         } else {
 153  0
             hours = time.substring(0, 2);
 154  0
             minutes = time.substring(2);
 155  
         }
 156  
 
 157  0
         int hour = Integer.parseInt(hours);
 158  0
         boolean isPM = false;
 159  0
         if (hour > 12) {
 160  0
             hour = hour - 12;
 161  0
             isPM = true;
 162  0
         } else if (hour == 12) {
 163  0
             isPM = true;
 164  0
         } else if (hour == 0) {
 165  0
             hour = 12;
 166  
         }
 167  
 
 168  
         //international ampm symbols
 169  0
         Locale usersLocale = Locale.getDefault();
 170  0
         DateFormatSymbols dfs = new DateFormatSymbols(usersLocale);
 171  0
         String ampm[] = dfs.getAmPmStrings();
 172  0
         String am = ampm[Calendar.AM];
 173  0
         String pm = ampm[Calendar.PM];
 174  
 
 175  0
         hours = "" + hour;
 176  0
         if (isPM) {
 177  0
             time = hours + ":" + minutes + pm;
 178  
         } else {
 179  0
             time = hours + ":" + minutes + am;
 180  
         }
 181  
 
 182  0
         return time;
 183  
     }
 184  
 
 185  
     public String getItemId() {
 186  0
         return itemId;
 187  
     }
 188  
 
 189  
     public void setItemId(String itemId) {
 190  0
         this.itemId = itemId;
 191  0
     }
 192  
 
 193  
     public String getTimeTypeName() {
 194  0
         return timeTypeName;
 195  
     }
 196  
 
 197  
     public void setTimeTypeName(String timeTypeName) {
 198  0
         this.timeTypeName = timeTypeName;
 199  0
     }
 200  
 
 201  
     public String getRegGroupTimesJsObject() {
 202  0
         return regGroupTimesJsObject;
 203  
     }
 204  
 
 205  
     public void setRegGroupTimesJsObject(String regGroupTimesJsObject) {
 206  0
         this.regGroupTimesJsObject = regGroupTimesJsObject;
 207  0
     }
 208  
 }