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