1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.student.enrollment.class2.appointment.util; |
18 | |
|
19 | |
|
20 | |
import org.kuali.student.r2.common.dto.TimeAmountInfo; |
21 | |
import org.kuali.student.r2.common.dto.TimeOfDayInfo; |
22 | |
import org.kuali.student.r2.core.appointment.dto.AppointmentSlotRuleInfo; |
23 | |
|
24 | |
import java.util.ArrayList; |
25 | |
import java.util.List; |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | 0 | public class AppointmentSlotRuleTypeConversion { |
33 | |
|
34 | 0 | public static int SECOND_IN_MILLIS = 1000; |
35 | 0 | public static int MINUTE_IN_SECS = 60; |
36 | 0 | public static int HOUR_IN_MINUTES = 60; |
37 | 0 | public static String DELIMITER = ";"; |
38 | |
|
39 | |
|
40 | |
|
41 | |
public static AppointmentSlotRuleInfo convToAppointmentSlotRuleInfo(String slotRuleTypeCode){ |
42 | 0 | AppointmentSlotRuleInfo slotRule = new AppointmentSlotRuleInfo(); |
43 | 0 | String[] codeWords = slotRuleTypeCode.split(";"); |
44 | 0 | String weekDaysArray[] = codeWords[0].split(","); |
45 | 0 | if(weekDaysArray.length >0){ |
46 | 0 | List<Integer> weekdays = new ArrayList<Integer>(); |
47 | 0 | for (String s : weekDaysArray) { |
48 | 0 | weekdays.add(Integer.parseInt(s)); |
49 | |
} |
50 | 0 | slotRule.setWeekdays(weekdays); |
51 | |
} |
52 | |
|
53 | 0 | slotRule.setStartTimeOfDay(convertToTimeOfDayInfo(convertToMilliSecs(codeWords[1]))); |
54 | 0 | slotRule.setEndTimeOfDay(convertToTimeOfDayInfo(convertToMilliSecs(codeWords[2]))); |
55 | 0 | slotRule.setSlotStartInterval(convertToTimeAmountInfo(codeWords[3],Integer.parseInt(codeWords[4]))); |
56 | 0 | slotRule.setSlotDuration(convertToTimeAmountInfo(codeWords[5],Integer.parseInt(codeWords[6]))); |
57 | 0 | return slotRule; |
58 | |
} |
59 | |
|
60 | |
|
61 | |
public static String convTotAppointmentSlotRuleCode(AppointmentSlotRuleInfo slotRuleInfo){ |
62 | 0 | String slotRule = ""; |
63 | 0 | StringBuilder tempSlotRule = new StringBuilder(); |
64 | |
|
65 | 0 | if(slotRuleInfo != null){ |
66 | 0 | if(slotRuleInfo.getWeekdays() != null){ |
67 | |
|
68 | 0 | List<Integer> weekdays = slotRuleInfo.getWeekdays(); |
69 | 0 | for (Integer day : weekdays) { |
70 | 0 | if (tempSlotRule.length() > 0) { |
71 | 0 | tempSlotRule.append(","); |
72 | |
} |
73 | 0 | tempSlotRule.append(day); |
74 | |
} |
75 | |
} |
76 | 0 | tempSlotRule.append(DELIMITER + convertToMins(slotRuleInfo.getStartTimeOfDay().getMilliSeconds())); |
77 | 0 | tempSlotRule.append(DELIMITER + convertToMins(slotRuleInfo.getEndTimeOfDay().getMilliSeconds())); |
78 | 0 | tempSlotRule.append(DELIMITER + slotRuleInfo.getSlotStartInterval().getAtpDurationTypeKey()); |
79 | 0 | tempSlotRule.append(DELIMITER + slotRuleInfo.getSlotStartInterval().getTimeQuantity()); |
80 | 0 | tempSlotRule.append(DELIMITER + slotRuleInfo.getSlotDuration().getAtpDurationTypeKey()); |
81 | 0 | tempSlotRule.append(DELIMITER + slotRuleInfo.getSlotDuration().getTimeQuantity()); |
82 | 0 | slotRule = tempSlotRule.toString(); |
83 | |
} |
84 | 0 | return slotRule; |
85 | |
} |
86 | |
|
87 | |
private static TimeOfDayInfo convertToTimeOfDayInfo(Long time) { |
88 | 0 | if(time == null){ |
89 | 0 | return null; |
90 | |
} |
91 | 0 | TimeOfDayInfo info = new TimeOfDayInfo(); |
92 | 0 | info.setMilliSeconds(time); |
93 | 0 | return info; |
94 | |
} |
95 | |
|
96 | |
private static TimeAmountInfo convertToTimeAmountInfo(String typeKey, Integer quantity) { |
97 | 0 | if ((typeKey == null) && (quantity == null)) { |
98 | 0 | return null; |
99 | |
} |
100 | 0 | TimeAmountInfo info = new TimeAmountInfo(); |
101 | 0 | info.setAtpDurationTypeKey(typeKey); |
102 | 0 | if (quantity != null) { |
103 | 0 | info.setTimeQuantity(quantity); |
104 | |
} |
105 | 0 | return info; |
106 | |
} |
107 | |
|
108 | |
private static Long convertToMilliSecs(String time_in_mins){ |
109 | 0 | Long time_in_millis = 0L; |
110 | 0 | time_in_millis = Long.parseLong(time_in_mins) * MINUTE_IN_SECS * SECOND_IN_MILLIS; |
111 | |
|
112 | 0 | return time_in_millis; |
113 | |
} |
114 | |
|
115 | |
private static String convertToMins(Long milliSecs){ |
116 | 0 | String time_in_mins = ""; |
117 | |
|
118 | 0 | int temp = (int)(milliSecs/(SECOND_IN_MILLIS * MINUTE_IN_SECS)); |
119 | 0 | time_in_mins = String.valueOf(temp); |
120 | |
|
121 | 0 | return time_in_mins; |
122 | |
} |
123 | |
|
124 | |
} |