1 | |
package org.kuali.student.enrollment.class2.registration.form; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
import org.apache.commons.lang.StringUtils; |
20 | |
import org.kuali.rice.krad.web.form.UifFormBase; |
21 | |
import org.kuali.student.enrollment.class2.registration.dto.ActivityOfferingWrapper; |
22 | |
import org.kuali.student.enrollment.class2.registration.dto.CourseOfferingWrapper; |
23 | |
import org.kuali.student.enrollment.class2.registration.dto.MeetingScheduleWrapper; |
24 | |
import org.kuali.student.enrollment.class2.registration.dto.RegistrationGroupWrapper; |
25 | |
import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingInfo; |
26 | |
import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingInfo; |
27 | |
import org.kuali.student.enrollment.courseregistration.dto.*; |
28 | |
import org.kuali.student.r2.common.dto.MeetingScheduleInfo; |
29 | |
import org.kuali.student.r2.common.util.constants.LuiPersonRelationServiceConstants; |
30 | |
|
31 | |
import java.util.ArrayList; |
32 | |
import java.util.HashMap; |
33 | |
import java.util.List; |
34 | |
import java.util.Map; |
35 | |
|
36 | |
public class RegistrationForm extends UifFormBase { |
37 | |
|
38 | |
private static final long serialVersionUID = 2554632701931313545L; |
39 | |
|
40 | |
private String termKey; |
41 | |
private String subjectArea; |
42 | |
private String courseOfferingCode; |
43 | |
private List<CourseOfferingWrapper> courseOfferingWrappers; |
44 | |
|
45 | |
private List<CourseRegistrationInfo> courseRegistrations; |
46 | |
private Map<String,RegistrationGroupWrapper> registrationGroupWrappersById; |
47 | |
|
48 | |
private RegRequestInfo regRequest; |
49 | |
|
50 | |
public RegistrationForm(){ |
51 | 0 | super(); |
52 | 0 | this.courseRegistrations = new ArrayList<CourseRegistrationInfo>(); |
53 | 0 | this.registrationGroupWrappersById = new HashMap<String,RegistrationGroupWrapper>(); |
54 | 0 | } |
55 | |
|
56 | |
public String getTermId() { |
57 | 0 | return termKey; |
58 | |
} |
59 | |
|
60 | |
public void setTermId(String termKey) { |
61 | 0 | this.termKey = termKey; |
62 | 0 | } |
63 | |
|
64 | |
public String getSubjectArea() { |
65 | 0 | return subjectArea; |
66 | |
} |
67 | |
|
68 | |
public void setSubjectArea(String subjectArea) { |
69 | 0 | this.subjectArea = subjectArea; |
70 | 0 | } |
71 | |
|
72 | |
public String getCourseOfferingCode() { |
73 | 0 | return courseOfferingCode; |
74 | |
} |
75 | |
|
76 | |
public void setCourseOfferingCode(String courseOfferingCode) { |
77 | 0 | this.courseOfferingCode = courseOfferingCode; |
78 | 0 | } |
79 | |
|
80 | |
public List<CourseOfferingWrapper> getCourseOfferingWrappers() { |
81 | 0 | return courseOfferingWrappers; |
82 | |
} |
83 | |
|
84 | |
public void setCourseOfferingWrappers(List<CourseOfferingWrapper> courseOfferingWrappers) { |
85 | 0 | this.courseOfferingWrappers = courseOfferingWrappers; |
86 | 0 | } |
87 | |
|
88 | |
public List<CourseRegistrationInfo> getCourseRegistrations() { |
89 | 0 | return courseRegistrations; |
90 | |
} |
91 | |
|
92 | |
public void setCourseRegistrations(List<CourseRegistrationInfo> courseRegistrations) { |
93 | 0 | this.courseRegistrations = courseRegistrations; |
94 | 0 | } |
95 | |
|
96 | |
public Map<String, RegistrationGroupWrapper> getRegistrationGroupWrappersById() { |
97 | 0 | return registrationGroupWrappersById; |
98 | |
} |
99 | |
|
100 | |
public void setRegistrationGroupWrappersById(Map<String, RegistrationGroupWrapper> registrationGroupWrappersById) { |
101 | 0 | this.registrationGroupWrappersById = registrationGroupWrappersById; |
102 | 0 | } |
103 | |
|
104 | |
public RegRequestInfo getRegRequest() { |
105 | 0 | return regRequest; |
106 | |
} |
107 | |
|
108 | |
public void setRegRequest(RegRequestInfo regRequest) { |
109 | 0 | this.regRequest = regRequest; |
110 | 0 | } |
111 | |
|
112 | |
protected List<MeetingScheduleWrapper> getRegisteredCourses() { |
113 | 0 | List<MeetingScheduleWrapper> meetingScheduleWrappers = new ArrayList<MeetingScheduleWrapper>(); |
114 | 0 | if(getCourseRegistrations() != null){ |
115 | |
|
116 | 0 | for (CourseRegistrationInfo courseRegistrationInfo : getCourseRegistrations()) { |
117 | |
|
118 | 0 | CourseOfferingInfo courseOfferingInfo = (CourseOfferingInfo) courseRegistrationInfo.getCourseOffering(); |
119 | 0 | RegGroupRegistrationInfo regGroupRegistrationInfo = courseRegistrationInfo.getRegGroupRegistration(); |
120 | 0 | if(regGroupRegistrationInfo.getStateKey().equals(LuiPersonRelationServiceConstants.REGISTERED_STATE_KEY)){ |
121 | 0 | for (ActivityRegistrationInfo activityRegistrationInfo : regGroupRegistrationInfo.getActivityRegistrations()) { |
122 | 0 | ActivityOfferingInfo activityOfferingInfo = activityRegistrationInfo.getActivityOffering(); |
123 | |
|
124 | 0 | List<MeetingScheduleInfo> list = new ArrayList<MeetingScheduleInfo> (); |
125 | 0 | for (MeetingScheduleInfo info : list) { |
126 | 0 | MeetingScheduleWrapper meetingScheduleWrapper = new MeetingScheduleWrapper(info); |
127 | 0 | meetingScheduleWrapper.setCourseOfferingCode(courseOfferingInfo.getCourseOfferingCode()); |
128 | 0 | meetingScheduleWrapper.setCourseTitle(courseOfferingInfo.getCourseOfferingTitle()); |
129 | 0 | meetingScheduleWrapper.setItemId(regGroupRegistrationInfo.getId()); |
130 | |
|
131 | 0 | String key = activityOfferingInfo.getTypeKey(); |
132 | 0 | String name = key.substring(key.lastIndexOf(".") + 1); |
133 | 0 | name = String.format( "%s%s", Character.toUpperCase(name.charAt(0)), name.substring(1)); |
134 | 0 | meetingScheduleWrapper.setTimeTypeName(name); |
135 | 0 | meetingScheduleWrappers.add(meetingScheduleWrapper); |
136 | 0 | } |
137 | 0 | } |
138 | |
} |
139 | 0 | } |
140 | |
} |
141 | 0 | return meetingScheduleWrappers; |
142 | |
} |
143 | |
|
144 | |
protected List<MeetingScheduleWrapper> getCartCourses() { |
145 | 0 | List<MeetingScheduleWrapper> meetingScheduleWrappers = new ArrayList<MeetingScheduleWrapper>(); |
146 | 0 | if(getRegRequest() != null){ |
147 | |
|
148 | 0 | for (RegRequestItemInfo regRequestItemInfo : getRegRequest().getRegRequestItems()) { |
149 | |
|
150 | 0 | String regGroupId = (StringUtils.isNotBlank(regRequestItemInfo.getNewRegGroupId())) ? regRequestItemInfo.getNewRegGroupId() : regRequestItemInfo.getExistingRegGroupId(); |
151 | |
|
152 | 0 | RegistrationGroupWrapper regGroupWrapper = getRegistrationGroupWrappersById().get(regGroupId); |
153 | |
|
154 | 0 | if (regGroupWrapper == null) { |
155 | 0 | throw new RuntimeException("Cannot find RegistrationGroup in RegistrationForm for registrationGroupId: " + regGroupId); |
156 | |
} |
157 | |
|
158 | 0 | for (ActivityOfferingWrapper activityOfferingWrapper : regGroupWrapper.getActivityOfferingWrappers()) { |
159 | 0 | for(MeetingScheduleWrapper meetingScheduleWrapper: activityOfferingWrapper.getMeetingScheduleWrappers()){ |
160 | 0 | meetingScheduleWrapper.setItemId(regRequestItemInfo.getId()); |
161 | 0 | meetingScheduleWrapper.setTimeTypeName(activityOfferingWrapper.getTypeName()); |
162 | 0 | meetingScheduleWrappers.add(meetingScheduleWrapper); |
163 | |
} |
164 | |
} |
165 | 0 | } |
166 | |
} |
167 | 0 | return meetingScheduleWrappers; |
168 | |
} |
169 | |
|
170 | |
protected String getJsArray(List<MeetingScheduleWrapper> meetingScheduleInfos) { |
171 | 0 | StringBuilder builder = new StringBuilder(); |
172 | 0 | for(MeetingScheduleWrapper course: meetingScheduleInfos){ |
173 | 0 | if (StringUtils.isNotBlank(builder.toString())) { |
174 | 0 | builder.append(","); |
175 | |
} |
176 | 0 | builder.append(course.getJsScheduleObject()); |
177 | |
} |
178 | 0 | return "[" + builder.toString() + "]"; |
179 | |
} |
180 | |
|
181 | 0 | public void setRegisteredCoursesJsArray(String temp){} |
182 | |
public String getRegisteredCoursesJsArray(){ |
183 | 0 | return getJsArray(getRegisteredCourses()); |
184 | |
} |
185 | |
|
186 | |
public String getCartCoursesJsArray() { |
187 | 0 | return getJsArray(getCartCourses()); |
188 | |
} |
189 | |
|
190 | |
} |