1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.student.enrollment.class2.courseoffering.service.impl;
18
19 import org.apache.commons.lang.StringUtils;
20 import org.kuali.rice.krad.inquiry.InquirableImpl;
21 import org.kuali.student.enrollment.class2.courseoffering.dto.ActivityOfferingWrapper;
22 import org.kuali.student.enrollment.class2.courseoffering.dto.CourseOfferingEditWrapper;
23 import org.kuali.student.enrollment.class2.courseoffering.dto.FormatOfferingWrapper;
24 import org.kuali.student.enrollment.class2.courseoffering.dto.OfferingInstructorWrapper;
25 import org.kuali.student.enrollment.class2.courseoffering.dto.OrganizationInfoWrapper;
26 import org.kuali.student.enrollment.class2.courseoffering.util.CourseOfferingConstants;
27 import org.kuali.student.enrollment.class2.courseoffering.util.CourseOfferingManagementUtil;
28 import org.kuali.student.enrollment.class2.courseoffering.util.CourseOfferingViewHelperUtil;
29 import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingInfo;
30 import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingCrossListingInfo;
31 import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingInfo;
32 import org.kuali.student.enrollment.courseoffering.dto.FormatOfferingInfo;
33 import org.kuali.student.enrollment.courseoffering.dto.OfferingInstructorInfo;
34 import org.kuali.student.r2.common.dto.ContextInfo;
35 import org.kuali.student.r2.common.util.ContextUtils;
36 import org.kuali.student.r2.common.util.constants.CourseOfferingServiceConstants;
37 import org.kuali.student.r2.common.util.constants.LprServiceConstants;
38 import org.kuali.student.r2.common.util.constants.LuServiceConstants;
39 import org.kuali.student.r2.core.acal.dto.TermInfo;
40 import org.kuali.student.r2.core.class1.state.dto.StateInfo;
41 import org.kuali.student.r2.core.class1.type.dto.TypeInfo;
42 import org.kuali.student.r2.core.organization.dto.OrgInfo;
43 import org.kuali.student.r2.core.scheduling.dto.ScheduleRequestSetInfo;
44 import org.kuali.student.r2.lum.course.dto.CourseInfo;
45 import org.kuali.student.r2.lum.course.service.assembler.CourseAssemblerConstants;
46 import org.kuali.student.r2.lum.lrc.dto.ResultValuesGroupInfo;
47 import org.kuali.student.r2.lum.util.constants.LrcServiceConstants;
48
49 import java.util.ArrayList;
50 import java.util.Arrays;
51 import java.util.HashSet;
52 import java.util.List;
53 import java.util.Map;
54 import java.util.Set;
55
56
57
58
59
60
61 public class CourseOfferingEditInquirableImpl extends InquirableImpl {
62
63 @Override
64 public Object retrieveDataObject(Map<String, String> parameters) {
65 ContextInfo contextInfo = ContextUtils.createDefaultContextInfo();
66
67 String coInfoId = parameters.get("coInfo.id");
68 if(coInfoId == null || "".equals(coInfoId)){
69 coInfoId = parameters.get("id");
70 }
71 if(coInfoId == null || "".equals(coInfoId)){
72 coInfoId = parameters.get("currentCourseOfferingWrapper.courseOfferingId");
73 }
74 if(coInfoId == null || "".equals(coInfoId)){
75 coInfoId = parameters.get("courseOfferingId");
76 }
77
78
79 try {
80 CourseOfferingInfo coInfo = CourseOfferingManagementUtil.getCourseOfferingService().getCourseOffering(coInfoId, contextInfo);
81
82
83 CourseInfo courseInfo = CourseOfferingManagementUtil.getCourseService().getCourse(coInfo.getCourseId(), contextInfo);
84
85 CourseOfferingEditWrapper formObject = new CourseOfferingEditWrapper(coInfo);
86
87 formObject.setCourse(courseInfo);
88
89
90 List<FormatOfferingInfo> formatOfferingInfos = CourseOfferingManagementUtil.getCourseOfferingService().getFormatOfferingsByCourseOffering(coInfoId, contextInfo);
91 List<FormatOfferingWrapper> foList = new ArrayList<FormatOfferingWrapper>();
92 for (FormatOfferingInfo fo : formatOfferingInfos){
93 FormatOfferingWrapper wrapper = new FormatOfferingWrapper();
94 wrapper.setFormatOfferingInfo(fo);
95 wrapper.setCourseOfferingWrapper(formObject);
96
97
98 if (!StringUtils.isEmpty(fo.getFinalExamLevelTypeKey()) && StringUtils.equals(formObject.getFinalExamDriver(), LuServiceConstants.LU_EXAM_DRIVER_AO_KEY)) {
99 wrapper.setFinalExamUI(CourseOfferingManagementUtil.getTypeService().getType(fo.getFinalExamLevelTypeKey(), contextInfo).getName());
100 } else {
101 wrapper.setFinalExamUI(" ");
102 }
103
104 foList.add(wrapper);
105 }
106 formObject.setFormatOfferingList(foList);
107 TermInfo term = CourseOfferingManagementUtil.getAcademicCalendarService().getTerm(coInfo.getTermId(), contextInfo);
108 formObject.setTermName(term.getName());
109
110
111 List<OfferingInstructorInfo> offeringInstructorInfos = coInfo.getInstructors();
112 List<OfferingInstructorWrapper> instructorList = new ArrayList<OfferingInstructorWrapper>();
113
114 for (OfferingInstructorInfo offeringInstructorInfo : offeringInstructorInfos) {
115 OfferingInstructorWrapper instructor = new OfferingInstructorWrapper();
116 instructor.setOfferingInstructorInfo(offeringInstructorInfo);
117 if (offeringInstructorInfo.getTypeKey().equals(LprServiceConstants.INSTRUCTOR_MAIN_TYPE_KEY)) {
118
119 instructor.setTypeName("Instructor");
120 } else if (offeringInstructorInfo.getTypeKey().equals(LprServiceConstants.INSTRUCTOR_ASSISTANT_TYPE_KEY)) {
121
122 instructor.setTypeName("Teaching Assistant");
123
124
125 }
126 instructorList.add(instructor);
127 }
128 formObject.setInstructors(instructorList);
129
130
131 List<OrganizationInfoWrapper> orgList = new ArrayList<OrganizationInfoWrapper>();
132 if(coInfo.getUnitsDeploymentOrgIds() != null){
133 for(String orgId: coInfo.getUnitsDeploymentOrgIds()){
134 OrgInfo orgInfo = CourseOfferingManagementUtil.getOrganizationService().getOrg(orgId, contextInfo);
135 orgList.add(new OrganizationInfoWrapper(orgInfo));
136 }
137 }
138 formObject.setOrganizationNames(orgList);
139
140 List<String> studentRegOptions = new ArrayList<String>();
141 List<String> crsGradingOptions = new ArrayList<String>();
142 if (coInfo.getCourseId() != null && courseInfo != null) {
143 List<String> gradingOptions = courseInfo.getGradingOptions();
144 Set<String> regOpts = new HashSet<String>(Arrays.asList(CourseOfferingServiceConstants.ALL_STUDENT_REGISTRATION_OPTION_TYPE_KEYS));
145 for (String gradingOption : gradingOptions) {
146 if (regOpts.contains(gradingOption)) {
147 studentRegOptions.add(gradingOption);
148 } else {
149 crsGradingOptions.add(gradingOption);
150 }
151 }
152
153 if("true".equals(courseInfo.getAttributeValue(CourseAssemblerConstants.COURSE_RESULT_COMP_ATTR_AUDIT))){
154 studentRegOptions.add(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_AUDIT);
155 }
156 }
157
158 studentRegOptions = coInfo.getStudentRegistrationGradingOptions();
159
160 formObject.setStudentRegOptions(studentRegOptions);
161 formObject.setCrsGradingOptions(crsGradingOptions);
162
163
164 String selectedStudentRegOpts = "";
165 if (studentRegOptions != null) {
166 ResultValuesGroupInfo rvg;
167 StringBuilder sbStudentRegOpts = new StringBuilder();
168 for(String studentGradingOption : studentRegOptions) {
169 rvg = CourseOfferingManagementUtil.getLrcService().getResultValuesGroup(studentGradingOption, contextInfo);
170 if (null != rvg) {
171 sbStudentRegOpts.append(rvg.getName());
172 } else {
173 sbStudentRegOpts.append(studentGradingOption);
174 }
175 sbStudentRegOpts.append("; ");
176 }
177 selectedStudentRegOpts = sbStudentRegOpts.toString();
178 }
179 if (selectedStudentRegOpts.isEmpty()) {
180 selectedStudentRegOpts = CourseOfferingConstants.COURSEOFFERING_TEXT_STD_REG_OPTS_EMPTY;
181 }
182 else {
183 selectedStudentRegOpts = selectedStudentRegOpts.substring(0, selectedStudentRegOpts.length() - 2);
184 }
185 formObject.setSelectedStudentRegOpts(selectedStudentRegOpts);
186
187
188
189
190 if(formObject.getAlternateCOCodes()!=null) {
191 formObject.getAlternateCOCodes().clear();
192 }
193 for (CourseOfferingCrossListingInfo crossListingInfo : coInfo.getCrossListings()){
194 if(formObject.getAlternateCOCodes()!=null){
195 formObject.getAlternateCOCodes().add(crossListingInfo.getCode());
196 }
197 }
198
199
200 if (formObject.isUseFinalExamMatrix()) {
201 formObject.setUseFinalExamMatrixUI(CourseOfferingConstants.COURSEOFFERING_TEXT_USE_FINAL_EXAM_MATRIX);
202 } else {
203 formObject.setUseFinalExamMatrixUI(CourseOfferingConstants.COURSEOFFERING_TEXT_NOT_USE_FINAL_EXAM_MATRIX);
204 }
205
206
207 loadActivityOfferingsByCourseOffering(coInfo, formObject);
208 return formObject;
209 } catch (Exception e) {
210 throw new RuntimeException(e);
211 }
212 }
213
214 private void loadActivityOfferingsByCourseOffering(CourseOfferingInfo theCourseOfferingInfo, CourseOfferingEditWrapper formObject) throws Exception {
215 String courseOfferingId = theCourseOfferingInfo.getId();
216 List<ActivityOfferingInfo> activityOfferingInfoList;
217 List<ActivityOfferingWrapper> activityOfferingWrapperList;
218
219 try {
220 activityOfferingInfoList = CourseOfferingManagementUtil.getCourseOfferingService().getActivityOfferingsByCourseOffering(courseOfferingId, ContextUtils.createDefaultContextInfo());
221 activityOfferingWrapperList = new ArrayList<ActivityOfferingWrapper>(activityOfferingInfoList.size());
222
223 for (ActivityOfferingInfo info : activityOfferingInfoList) {
224 ActivityOfferingWrapper aoWrapper = convertAOInfoToWrapper_Simple(info);
225 activityOfferingWrapperList.add(aoWrapper);
226 }
227 } catch (Exception e) {
228 throw new RuntimeException(String.format("Could not load AOs for course offering [%s].", courseOfferingId), e);
229 }
230 formObject.setAoWrapperList(activityOfferingWrapperList);
231 }
232
233 private ActivityOfferingWrapper convertAOInfoToWrapper_Simple(ActivityOfferingInfo aoInfo) throws Exception{
234
235 ActivityOfferingWrapper aoWrapper = new ActivityOfferingWrapper(aoInfo);
236
237 ContextInfo contextInfo = ContextUtils.createDefaultContextInfo();
238
239 StateInfo state = CourseOfferingManagementUtil.getStateService().getState(aoInfo.getStateKey(), contextInfo);
240 aoWrapper.setStateName(state.getName());
241
242 TypeInfo typeInfo = CourseOfferingManagementUtil.getTypeService().getType(aoInfo.getTypeKey(), contextInfo);
243 aoWrapper.setTypeName(typeInfo.getName());
244
245 FormatOfferingInfo fo = CourseOfferingManagementUtil.getCourseOfferingService().getFormatOffering(aoInfo.getFormatOfferingId(), contextInfo);
246 aoWrapper.setFormatOffering(fo);
247
248 OfferingInstructorInfo displayInstructor = CourseOfferingViewHelperUtil.findDisplayInstructor(aoInfo.getInstructors());
249
250 if(displayInstructor != null) {
251 aoWrapper.setFirstInstructorDisplayName(displayInstructor.getPersonName());
252 }
253
254
255 List<OfferingInstructorInfo> instructorInfos = aoInfo.getInstructors();
256 if (instructorInfos != null) {
257 for (OfferingInstructorInfo offeringInstructorInfo : instructorInfos) {
258 aoWrapper.setInstructorDisplayNames(offeringInstructorInfo.getPersonName(), true);
259 }
260 }
261
262
263 List<ScheduleRequestSetInfo> scheduleRequestSetInfoList = CourseOfferingManagementUtil.getSchedulingService().getScheduleRequestSetsByRefObject(CourseOfferingServiceConstants.REF_OBJECT_URI_ACTIVITY_OFFERING,
264 aoInfo.getId(), contextInfo);
265
266 if(scheduleRequestSetInfoList != null && scheduleRequestSetInfoList.size() > 0) {
267 StringBuilder sb = new StringBuilder();
268 if (!scheduleRequestSetInfoList.isEmpty()){
269 for(ScheduleRequestSetInfo coloSet : scheduleRequestSetInfoList) {
270 List<ActivityOfferingInfo> aoList = CourseOfferingManagementUtil.getCourseOfferingService().getActivityOfferingsByIds(coloSet.getRefObjectIds(), contextInfo);
271 for(ActivityOfferingInfo coloActivity : aoList) {
272 if (!StringUtils.equals(coloActivity.getId(),aoInfo.getId())){
273 sb.append(coloActivity.getCourseOfferingCode() + " " + coloActivity.getActivityCode() + "<br>");
274 }
275 }
276 }
277 aoWrapper.setColocatedAoInfo(sb.toString());
278 }
279 }
280
281
282
283 TermInfo term;
284 TermInfo subTerm;
285 aoWrapper.setHasSubTerms(false);
286 aoWrapper.setSubTermName("None");
287 aoWrapper.setSubTermId("");
288
289 List<TermInfo> terms = CourseOfferingManagementUtil.getAcademicCalendarService().getContainingTerms(aoInfo.getTermId(), contextInfo);
290 if (terms == null || terms.isEmpty()) {
291 term = CourseOfferingManagementUtil.getAcademicCalendarService().getTerm(aoWrapper.getAoInfo().getTermId(), contextInfo);
292
293 List<TermInfo> subTerms = CourseOfferingManagementUtil.getAcademicCalendarService().getIncludedTermsInTerm(aoWrapper.getAoInfo().getTermId(), contextInfo);
294 if(!subTerms.isEmpty()) {
295 aoWrapper.setHasSubTerms(true);
296 }
297 } else {
298 subTerm = CourseOfferingManagementUtil.getAcademicCalendarService().getTerm(aoInfo.getTermId(), contextInfo);
299 term = terms.get(0);
300 aoWrapper.setHasSubTerms(true);
301 aoWrapper.setSubTermId(subTerm.getId());
302 TypeInfo subTermType = CourseOfferingManagementUtil.getTypeService().getType(subTerm.getTypeKey(), contextInfo);
303 aoWrapper.setSubTermName(subTermType.getName());
304 aoWrapper.setTermStartEndDate(CourseOfferingManagementUtil.getTermStartEndDate(subTerm.getId(), subTerm));
305 }
306 aoWrapper.setTerm(term);
307 if (term != null) {
308 aoWrapper.setTermName(term.getName());
309 }
310 aoWrapper.setTermDisplayString(CourseOfferingManagementUtil.getTermDisplayString(aoInfo.getTermId(), term));
311 return aoWrapper;
312 }
313
314 }