1 package org.kuali.student.enrollment.class2.courseoffering.util;
2
3 import net.sf.ehcache.CacheManager;
4 import org.apache.commons.lang.StringUtils;
5 import org.kuali.rice.core.api.criteria.Predicate;
6 import org.kuali.rice.core.api.criteria.PredicateFactory;
7 import org.kuali.rice.core.api.criteria.QueryByCriteria;
8 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
9 import org.kuali.rice.kim.api.identity.IdentityService;
10 import org.kuali.rice.kim.api.identity.Person;
11 import org.kuali.rice.kim.api.identity.PersonService;
12 import org.kuali.rice.kim.api.permission.PermissionService;
13 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
14 import org.kuali.rice.krad.uif.UifParameters;
15 import org.kuali.rice.krad.uif.util.ObjectPropertyUtils;
16 import org.kuali.rice.krad.util.GlobalVariables;
17 import org.kuali.rice.krad.util.KRADConstants;
18 import org.kuali.rice.krad.web.form.UifFormBase;
19 import org.kuali.rice.krms.api.KrmsConstants;
20 import org.kuali.rice.krms.api.repository.RuleManagementService;
21 import org.kuali.rice.krms.api.repository.type.KrmsTypeRepositoryService;
22 import org.kuali.student.common.uif.form.KSUifForm;
23 import org.kuali.student.common.uif.util.CommentUtil;
24 import org.kuali.student.common.util.security.ContextUtils;
25 import org.kuali.student.enrollment.batch.BatchScheduler;
26 import org.kuali.student.enrollment.batch.util.BatchSchedulerConstants;
27 import org.kuali.student.enrollment.class2.courseoffering.controller.ControllerTransactionHelper;
28 import org.kuali.student.enrollment.class2.courseoffering.dto.ActivityOfferingClusterWrapper;
29 import org.kuali.student.enrollment.class2.courseoffering.dto.ActivityOfferingWrapper;
30 import org.kuali.student.enrollment.class2.courseoffering.dto.CourseOfferingEditWrapper;
31 import org.kuali.student.enrollment.class2.courseoffering.dto.CourseOfferingListSectionWrapper;
32 import org.kuali.student.enrollment.class2.courseoffering.dto.CourseOfferingWrapper;
33 import org.kuali.student.enrollment.class2.courseoffering.dto.RegistrationGroupWrapper;
34 import org.kuali.student.enrollment.class2.courseoffering.form.CourseOfferingManagementForm;
35 import org.kuali.student.enrollment.class2.courseoffering.form.CreateSocForm;
36 import org.kuali.student.enrollment.class2.courseoffering.form.DevTestWidgetForm;
37 import org.kuali.student.enrollment.class2.courseoffering.form.DiagnoseRolloverForm;
38 import org.kuali.student.enrollment.class2.courseoffering.helper.impl.ActivityOfferingScheduleHelperImpl;
39 import org.kuali.student.enrollment.class2.courseoffering.helper.impl.ExamOfferingScheduleHelperImpl;
40 import org.kuali.student.enrollment.class2.courseoffering.refdata.CluFixer;
41 import org.kuali.student.enrollment.class2.courseoffering.service.CourseOfferingManagementViewHelperService;
42 import org.kuali.student.enrollment.class2.courseoffering.service.CourseOfferingViewHelperService;
43 import org.kuali.student.enrollment.class2.courseoffering.service.CreateSocViewHelperService;
44 import org.kuali.student.enrollment.class2.courseoffering.service.DevTestWidgetViewHelperService;
45 import org.kuali.student.enrollment.class2.courseoffering.service.DiagnoseRolloverViewHelperService;
46 import org.kuali.student.enrollment.class2.courseoffering.service.SeatPoolUtilityService;
47 import org.kuali.student.enrollment.class2.courseoffering.service.facade.CSRServiceFacade;
48 import org.kuali.student.enrollment.class2.courseoffering.service.facade.CourseOfferingServiceFacade;
49 import org.kuali.student.enrollment.class2.courseoffering.service.impl.CourseInfoByTermLookupableImpl;
50 import org.kuali.student.enrollment.class2.courseoffering.service.impl.DefaultOptionKeysService;
51 import org.kuali.student.enrollment.class2.courseoffering.service.impl.DefaultOptionKeysServiceImpl;
52 import org.kuali.student.enrollment.class2.courseoffering.service.impl.SeatPoolUtilityServiceImpl;
53 import org.kuali.student.enrollment.class2.coursewaitlist.service.facade.CourseWaitListServiceFacade;
54 import org.kuali.student.enrollment.class2.coursewaitlist.service.facade.CourseWaitListServiceFacadeConstants;
55 import org.kuali.student.enrollment.class2.examoffering.service.facade.ExamOfferingServiceFacade;
56 import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingClusterInfo;
57 import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingSetInfo;
58 import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingInfo;
59 import org.kuali.student.enrollment.courseoffering.dto.FormatOfferingInfo;
60 import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
61 import org.kuali.student.enrollment.courseofferingset.service.CourseOfferingSetService;
62 import org.kuali.student.enrollment.courseregistration.service.CourseRegistrationService;
63 import org.kuali.student.enrollment.courseseatcount.service.CourseSeatCountService;
64 import org.kuali.student.enrollment.coursewaitlist.service.CourseWaitListService;
65 import org.kuali.student.enrollment.examoffering.service.ExamOfferingService;
66 import org.kuali.student.enrollment.lpr.service.LprService;
67 import org.kuali.student.enrollment.lui.service.LuiService;
68 import org.kuali.student.r2.common.constants.CommonServiceConstants;
69 import org.kuali.student.r2.common.dto.AttributeInfo;
70 import org.kuali.student.r2.common.dto.ContextInfo;
71 import org.kuali.student.r2.common.dto.DtoConstants;
72 import org.kuali.student.r2.common.exceptions.DoesNotExistException;
73 import org.kuali.student.r2.common.util.constants.CourseOfferingServiceConstants;
74 import org.kuali.student.r2.common.util.constants.CourseOfferingSetServiceConstants;
75 import org.kuali.student.r2.common.util.constants.CourseRegistrationServiceConstants;
76 import org.kuali.student.r2.common.util.constants.CourseSeatCountServiceConstants;
77 import org.kuali.student.r2.common.util.constants.ExamOfferingServiceConstants;
78 import org.kuali.student.r2.common.util.constants.LprServiceConstants;
79 import org.kuali.student.r2.common.util.constants.LuiServiceConstants;
80 import org.kuali.student.r2.common.util.date.DateFormatters;
81 import org.kuali.student.r2.core.acal.dto.TermInfo;
82 import org.kuali.student.r2.core.acal.service.AcademicCalendarService;
83 import org.kuali.student.r2.core.atp.dto.AtpInfo;
84 import org.kuali.student.r2.core.atp.service.AtpService;
85 import org.kuali.student.r2.core.class1.state.dto.StateInfo;
86 import org.kuali.student.r2.core.class1.state.service.StateService;
87 import org.kuali.student.r2.core.class1.type.service.TypeService;
88 import org.kuali.student.r2.core.comment.service.CommentService;
89 import org.kuali.student.r2.core.constants.AcademicCalendarServiceConstants;
90 import org.kuali.student.r2.core.constants.CommentServiceConstants;
91 import org.kuali.student.r2.core.constants.FeeServiceConstants;
92 import org.kuali.student.r2.core.constants.PopulationServiceConstants;
93 import org.kuali.student.r2.core.enumerationmanagement.service.EnumerationManagementService;
94 import org.kuali.student.r2.core.fee.service.FeeService;
95 import org.kuali.student.r2.core.organization.dto.OrgInfo;
96 import org.kuali.student.r2.core.organization.service.OrganizationService;
97 import org.kuali.student.r2.core.population.service.PopulationService;
98 import org.kuali.student.r2.core.room.service.RoomService;
99 import org.kuali.student.r2.core.scheduling.service.SchedulingService;
100 import org.kuali.student.r2.core.search.dto.SearchParamInfo;
101 import org.kuali.student.r2.core.search.dto.SearchRequestInfo;
102 import org.kuali.student.r2.core.search.dto.SearchResultCellInfo;
103 import org.kuali.student.r2.core.search.dto.SearchResultInfo;
104 import org.kuali.student.r2.core.search.dto.SearchResultRowInfo;
105 import org.kuali.student.r2.core.search.service.SearchService;
106 import org.kuali.student.r2.lum.clu.service.CluService;
107 import org.kuali.student.r2.lum.course.dto.CourseInfo;
108 import org.kuali.student.r2.lum.course.service.CourseService;
109 import org.kuali.student.r2.lum.lrc.dto.ResultValuesGroupInfo;
110 import org.kuali.student.r2.lum.lrc.service.LRCService;
111 import org.kuali.student.r2.lum.util.constants.CluServiceConstants;
112 import org.kuali.student.r2.lum.util.constants.LrcServiceConstants;
113
114 import javax.xml.namespace.QName;
115 import java.util.ArrayList;
116 import java.util.Arrays;
117 import java.util.Collection;
118 import java.util.Formatter;
119 import java.util.HashMap;
120 import java.util.List;
121 import java.util.Locale;
122 import java.util.Properties;
123
124 import static org.kuali.rice.core.api.criteria.PredicateFactory.equal;
125
126
127
128
129
130
131
132
133 public class CourseOfferingManagementUtil {
134 private static CourseOfferingManagementViewHelperService viewHelperService;
135 private static CourseOfferingViewHelperService coViewHelperService;
136 private static CreateSocViewHelperService socViewHelperService;
137 private static DiagnoseRolloverViewHelperService drViewHelperService;
138 private static DevTestWidgetViewHelperService devTestWidgetViewHelperService;
139 private static OrganizationService organizationService;
140 private static StateService stateService;
141 private static LRCService lrcService;
142 private static TypeService typeService;
143 private static AcademicCalendarService academicCalendarService;
144 private static CourseOfferingServiceFacade courseOfferingServiceFacade;
145 private static CSRServiceFacade csrServiceFacade;
146 private static CourseService courseService;
147 private static CourseOfferingSetService socService;
148 private static AtpService atpService;
149 private static CluService cluService;
150 private static CourseOfferingSetService courseOfferingSetService;
151 private static CourseOfferingService courseOfferingService;
152 private static CourseRegistrationService courseRegistrationService;
153 private static SearchService searchService;
154 private static CourseWaitListServiceFacade courseWaitListServiceFacade;
155 private static ExamOfferingServiceFacade examOfferingServiceFacade;
156 private static ExamOfferingService examOfferingService;
157 private static SchedulingService schedulingService;
158 private static PopulationService populationService;
159 private static CourseWaitListService courseWaitListService;
160 private static DefaultOptionKeysService defaultOptionKeysService;
161 private static RoomService roomService;
162 private static PermissionService permissionService;
163 private static CacheManager cacheManager;
164 private static IdentityService identityService;
165 private static RuleManagementService ruleManagementService;
166 private static LprService lprService;
167 private static FeeService feeService;
168 private static CluFixer cluFixer;
169 private static LuiService luiService = null;
170 private static ControllerTransactionHelper controllerTransactionHelper;
171 private static EnumerationManagementService enumerationManagementService;
172 private static PersonService personService;
173 private static CourseSeatCountService courseSeatCountService;
174 private static KrmsTypeRepositoryService krmsTypeRepositoryService;
175 private static CommentService commentService;
176 private static BatchScheduler batchScheduler;
177
178 private static HashMap<String, String> scheduleStateHm = null;
179
180 public static PersonService getPersonService() {
181 return KimApiServiceLocator.getPersonService();
182 }
183
184 public static EnumerationManagementService getEnumerationManagementService() {
185 if (enumerationManagementService == null) {
186 enumerationManagementService = (EnumerationManagementService) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/enumerationmanagement", "EnumerationManagementService"));
187 }
188 return enumerationManagementService;
189 }
190
191 public static CourseRegistrationService getCourseRegistrationService() {
192 if (courseRegistrationService == null) {
193 courseRegistrationService = (CourseRegistrationService) GlobalResourceLoader.getService(CourseRegistrationServiceConstants.Q_NAME);
194 }
195 return courseRegistrationService;
196 }
197
198 public static ControllerTransactionHelper getControllerTransactionHelper() {
199 if (controllerTransactionHelper == null) {
200 controllerTransactionHelper = GlobalResourceLoader.getService(new QName(CommonServiceConstants.REF_OBJECT_URI_GLOBAL_PREFIX + "controllerTransactionHelper", ControllerTransactionHelper.class.getSimpleName()));
201 }
202
203 return controllerTransactionHelper;
204 }
205
206 public static LuiService getLuiService() {
207 if (luiService == null) {
208 luiService = (LuiService) GlobalResourceLoader.getService(new QName(LuiServiceConstants.NAMESPACE,
209 LuiServiceConstants.SERVICE_NAME_LOCAL_PART));
210 }
211 return luiService;
212 }
213
214 public static CluFixer getCluFixer() {
215 if (cluFixer == null) {
216 cluFixer = (CluFixer) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/cluFixer", "CluFixer"));
217 }
218 return cluFixer;
219 }
220
221 public static FeeService getFeeService() {
222 if (feeService == null) {
223 feeService = (FeeService) GlobalResourceLoader.getService(new QName(FeeServiceConstants.NAMESPACE,
224 FeeServiceConstants.SERVICE_NAME_LOCAL_PART));
225 }
226 return feeService;
227 }
228
229 public static LprService getLprService() {
230 if (lprService == null) {
231 lprService = (LprService) GlobalResourceLoader.getService(new QName(LprServiceConstants.NAMESPACE,
232 LprServiceConstants.SERVICE_NAME_LOCAL_PART));
233 }
234 return lprService;
235 }
236
237 public static RuleManagementService getRuleManagementService() {
238 if (ruleManagementService == null) {
239 ruleManagementService = (RuleManagementService) GlobalResourceLoader.getService(new QName(KrmsConstants.Namespaces.KRMS_NAMESPACE_2_0, "ruleManagementService"));
240 }
241 return ruleManagementService;
242 }
243
244 public static IdentityService getIdentityService() {
245 if (identityService == null) {
246 identityService = KimApiServiceLocator.getIdentityService();
247 }
248 return identityService;
249 }
250
251 public static CacheManager getCacheManager() {
252 if (cacheManager == null) {
253
254 cacheManager = CacheManager.getCacheManager("ks-ehcache");
255 }
256 return cacheManager;
257 }
258
259 public static PermissionService getPermissionService() {
260 if (permissionService == null) {
261 permissionService = KimApiServiceLocator.getPermissionService();
262 }
263 return permissionService;
264 }
265
266 public static RoomService getRoomService() {
267 if (roomService == null) {
268 roomService = CourseOfferingResourceLoader.loadRoomService();
269 }
270 return roomService;
271 }
272
273 public static ActivityOfferingScheduleHelperImpl getScheduleHelper() {
274 return new ActivityOfferingScheduleHelperImpl();
275 }
276
277 public static ExamOfferingScheduleHelperImpl getExamOfferingScheduleHelper() {
278 return new ExamOfferingScheduleHelperImpl();
279 }
280
281 public static SeatPoolUtilityService getSeatPoolUtilityService() {
282 return new SeatPoolUtilityServiceImpl();
283 }
284
285 public static CourseOfferingManagementViewHelperService getViewHelperService(CourseOfferingManagementForm theForm) {
286 if (viewHelperService == null) {
287 viewHelperService = (CourseOfferingManagementViewHelperService) theForm.getViewHelperService();
288 }
289 return viewHelperService;
290 }
291
292 public static CourseOfferingViewHelperService getCoViewHelperService(UifFormBase form) {
293 if (coViewHelperService == null) {
294 coViewHelperService = (CourseOfferingViewHelperService) form.getViewHelperService();
295 }
296 return coViewHelperService;
297 }
298
299 public static CreateSocViewHelperService getSocViewHelperService(CreateSocForm createSocForm) {
300 if (socViewHelperService == null) {
301 socViewHelperService = (CreateSocViewHelperService) createSocForm.getViewHelperService();
302 }
303 return socViewHelperService;
304 }
305
306 public static DiagnoseRolloverViewHelperService getDrViewHelperService(DiagnoseRolloverForm rolloverForm) {
307 if (drViewHelperService == null) {
308 drViewHelperService = (DiagnoseRolloverViewHelperService) rolloverForm.getViewHelperService();
309 }
310 return drViewHelperService;
311 }
312
313 public static DevTestWidgetViewHelperService getDevTestWidgetViewHelperService(DevTestWidgetForm serviceCallForm) {
314 if (devTestWidgetViewHelperService == null) {
315 devTestWidgetViewHelperService = (DevTestWidgetViewHelperService) serviceCallForm.getViewHelperService();
316 }
317 return devTestWidgetViewHelperService;
318 }
319
320 public static OrganizationService getOrganizationService() {
321 if (organizationService == null) {
322 organizationService = (OrganizationService) GlobalResourceLoader.getService(new QName(CommonServiceConstants.REF_OBJECT_URI_GLOBAL_PREFIX + "organization", "OrganizationService"));
323 }
324 return organizationService;
325 }
326
327 public static StateService getStateService() {
328 if (stateService == null) {
329 stateService = CourseOfferingResourceLoader.loadStateService();
330 }
331 return stateService;
332 }
333
334 public static LRCService getLrcService() {
335 if (lrcService == null) {
336 lrcService = CourseOfferingResourceLoader.loadLrcService();
337 }
338 return lrcService;
339 }
340
341 public static TypeService getTypeService() {
342 if (typeService == null) {
343 typeService = CourseOfferingResourceLoader.loadTypeService();
344 }
345 return typeService;
346 }
347
348 public static AcademicCalendarService getAcademicCalendarService() {
349 if (academicCalendarService == null) {
350 academicCalendarService = (AcademicCalendarService) GlobalResourceLoader.getService(new QName(AcademicCalendarServiceConstants.NAMESPACE, AcademicCalendarServiceConstants.SERVICE_NAME_LOCAL_PART));
351 }
352 return academicCalendarService;
353 }
354
355 public static CourseOfferingServiceFacade getCourseOfferingServiceFacade() {
356 if (courseOfferingServiceFacade == null) {
357 courseOfferingServiceFacade = (CourseOfferingServiceFacade) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/courseOfferingServiceFacade", "CourseOfferingServiceFacade"));
358 }
359 return courseOfferingServiceFacade;
360 }
361
362 public static CSRServiceFacade getCsrServiceFacade() {
363 if (csrServiceFacade == null) {
364 csrServiceFacade = (CSRServiceFacade) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/csrServiceFacade", "CSRServiceFacade"));
365 }
366 return csrServiceFacade;
367 }
368
369 public static CourseWaitListServiceFacade getCourseWaitListServiceFacade() {
370 if (courseWaitListServiceFacade == null) {
371 courseWaitListServiceFacade = (CourseWaitListServiceFacade) GlobalResourceLoader.getService(CourseWaitListServiceFacadeConstants.getQName());
372 }
373 return courseWaitListServiceFacade;
374 }
375
376 public static ExamOfferingServiceFacade getExamOfferingServiceFacade() {
377 if (examOfferingServiceFacade == null) {
378 examOfferingServiceFacade = (ExamOfferingServiceFacade) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/examOfferingServiceFacade", "examOfferingServiceFacade"));
379 }
380 return examOfferingServiceFacade;
381 }
382
383 public static ExamOfferingService getExamOfferingService() {
384 if (examOfferingService == null) {
385 examOfferingService = (ExamOfferingService) GlobalResourceLoader.getService(new QName(ExamOfferingServiceConstants.NAMESPACE, ExamOfferingServiceConstants.SERVICE_NAME_LOCAL_PART));
386 }
387 return examOfferingService;
388 }
389
390
391 public static CourseService getCourseService() {
392 if (courseService == null) {
393 courseService = CourseOfferingResourceLoader.loadCourseService();
394 }
395 return courseService;
396 }
397
398 public static CourseOfferingSetService getSocService() {
399 if (socService == null) {
400 socService = CourseOfferingResourceLoader.loadSocService();
401 }
402 return socService;
403 }
404
405 public static AtpService getAtpService() {
406 if (atpService == null) {
407 atpService = CourseOfferingResourceLoader.loadAtpService();
408 }
409 return atpService;
410 }
411
412 public static CluService getCluService() {
413 if (cluService == null) {
414 cluService = CourseOfferingResourceLoader.loadCluService();
415 }
416 return cluService;
417 }
418
419 public static CourseOfferingService getCourseOfferingService() {
420 if (courseOfferingService == null) {
421 courseOfferingService = CourseOfferingResourceLoader.loadCourseOfferingService();
422 }
423 return courseOfferingService;
424 }
425
426 public static CourseOfferingSetService getCourseOfferingSetService() {
427 if (courseOfferingSetService == null) {
428 courseOfferingSetService = (CourseOfferingSetService) GlobalResourceLoader.getService(new QName(CourseOfferingSetServiceConstants.NAMESPACE, CourseOfferingSetServiceConstants.SERVICE_NAME_LOCAL_PART));
429 }
430 return courseOfferingSetService;
431 }
432
433 public static SearchService getSearchService() {
434 if (searchService == null) {
435 searchService = (SearchService) GlobalResourceLoader.getService(new QName(CommonServiceConstants.REF_OBJECT_URI_GLOBAL_PREFIX + "search", SearchService.class.getSimpleName()));
436 }
437 return searchService;
438 }
439
440 public static SchedulingService getSchedulingService() {
441 if (schedulingService == null) {
442 schedulingService = CourseOfferingResourceLoader.loadSchedulingService();
443 }
444 return schedulingService;
445 }
446
447 public static PopulationService getPopulationService() {
448 if (populationService == null) {
449 populationService = (PopulationService) GlobalResourceLoader.getService(new QName(PopulationServiceConstants.NAMESPACE, PopulationServiceConstants.SERVICE_NAME_LOCAL_PART));
450 }
451 return populationService;
452 }
453
454 public static CourseWaitListService getCourseWaitListService() {
455 if (courseWaitListService == null) {
456 courseWaitListService = CourseOfferingResourceLoader.loadCourseWaitlistService();
457 }
458 return courseWaitListService;
459 }
460
461 public static DefaultOptionKeysService getDefaultOptionKeysService() {
462 if (defaultOptionKeysService == null) {
463 defaultOptionKeysService = new DefaultOptionKeysServiceImpl();
464 }
465 return defaultOptionKeysService;
466 }
467
468 public static CourseSeatCountService getCourseSeatCountService() {
469 if (courseSeatCountService == null) {
470 courseSeatCountService =
471 (CourseSeatCountService) GlobalResourceLoader.getService(new QName(CourseSeatCountServiceConstants.NAMESPACE,
472 CourseSeatCountServiceConstants.SERVICE_NAME_LOCAL_PART));
473 }
474 return courseSeatCountService;
475 }
476
477 public static KrmsTypeRepositoryService getKrmsTypeRepositoryService() {
478 if (krmsTypeRepositoryService == null) {
479 krmsTypeRepositoryService = GlobalResourceLoader.getService(new QName(KrmsConstants.Namespaces.KRMS_NAMESPACE_2_0, "krmsTypeRepositoryService"));
480 }
481 return krmsTypeRepositoryService;
482 }
483
484 public static CommentService getCommentService() {
485 if (commentService == null) {
486 commentService = (CommentService) GlobalResourceLoader.getService(new QName(CommentServiceConstants.NAMESPACE, CommentService.class.getSimpleName()));
487 }
488 return commentService;
489 }
490
491 public static BatchScheduler getBatchScheduler() {
492 if (batchScheduler == null) {
493 batchScheduler = GlobalResourceLoader.getService(new QName(BatchSchedulerConstants.NAMESPACE, BatchSchedulerConstants.SERVICE_NAME_LOCAL_PART));
494 }
495 return batchScheduler;
496 }
497
498 public static boolean checkEditViewAuthz(CourseOfferingManagementForm theForm) {
499 Person user = GlobalVariables.getUserSession().getPerson();
500 return theForm.getView().getAuthorizer().canEditView(theForm.getView(), theForm, user);
501 }
502
503 public static void prepareManageAOsModelAndView(CourseOfferingManagementForm form, CourseOfferingListSectionWrapper selectedCO) throws Exception {
504
505 CourseOfferingWrapper currentCOWrapper = new CourseOfferingWrapper(selectedCO.isCrossListed(), selectedCO.getCourseOfferingCode(), selectedCO.getCourseOfferingDesc(), selectedCO.getAlternateCOCodes(), selectedCO.getCourseOfferingId());
506 currentCOWrapper.setOwnerAliases(selectedCO.getOwnerAliases());
507 form.setSubjectCode(selectedCO.getSubjectArea());
508 prepare_AOs_RGs_AOCs_Lists(form, currentCOWrapper);
509 }
510
511 public static void prepare_AOs_RGs_AOCs_Lists(CourseOfferingManagementForm form, CourseOfferingWrapper currentCOWrapper) throws Exception {
512
513
514 try {
515 currentCOWrapper.setExamPeriodId(getExamOfferingServiceFacade().getExamPeriodId(form.getTermInfo().getId(), ContextUtils.createDefaultContextInfo()));
516 } catch (DoesNotExistException e) {
517 }
518
519 currentCOWrapper.setTerm(form.getTermInfo());
520
521 CourseOfferingInfo coInfo = getCourseOfferingService().getCourseOffering(currentCOWrapper.getCourseOfferingId(), ContextUtils.createDefaultContextInfo());
522 currentCOWrapper.setCourseOfferingInfo(coInfo);
523
524
525 if (currentCOWrapper.getOwnerCode() == null || currentCOWrapper.getOwnerCode().equals("")) {
526 for (CourseOfferingListSectionWrapper courseOfferingListSectionWrapper : form.getCourseOfferingResultList()) {
527 if (courseOfferingListSectionWrapper.getCourseOfferingCode().equals(currentCOWrapper.getCourseOfferingCode())) {
528 currentCOWrapper.setOwnerCode(courseOfferingListSectionWrapper.getOwnerCode());
529 break;
530 }
531 }
532 }
533
534 ContextInfo contextInfo = ContextUtils.createDefaultContextInfo();
535 currentCOWrapper.setCommentCount(CommentUtil.getCommentsCount(currentCOWrapper.getCourseOfferingId(), CourseOfferingServiceConstants.REF_OBJECT_URI_COURSE_OFFERING, ContextUtils.createDefaultContextInfo()));
536 List<String> orgIds = coInfo.getUnitsDeploymentOrgIds();
537 if (orgIds != null && !orgIds.isEmpty()) {
538 OrgInfo org = getOrganizationService().getOrg(orgIds.get(0), contextInfo);
539 currentCOWrapper.setCoOwningDeptName(org.getShortName());
540
541 StringBuilder sb = new StringBuilder("");
542 for (String orgId : orgIds) {
543 sb.append(orgId).append(",");
544 }
545 String orgIDs = sb.toString();
546 if (orgIDs.length() > 0) {
547 form.setAdminOrg(orgIDs.substring(0, orgIDs.length() - 1));
548 }
549 }
550
551 form.setCurrentCourseOfferingWrapper(currentCOWrapper);
552 form.setInputCode(currentCOWrapper.getCourseOfferingCode());
553
554 form.setFormatIdForNewAO(null);
555 form.setFormatOfferingIdForNewAO(null);
556 form.setActivityIdForNewAO(null);
557 form.setNoOfActivityOfferings(null);
558 form.setPrivateClusterNamePopover("");
559 form.setPublishedClusterNamePopover("");
560
561 getViewHelperService(form).loadExamOfferingRelations(form);
562
563 getViewHelperService(form).loadPreviousAndNextCourseOffering(form);
564
565 getViewHelperService(form).build_AOs_RGs_AOCs_Lists_For_TheCourseOffering(form);
566
567 CourseOfferingManagementToolbarUtil.processAoToolbarForUser(form.getActivityWrapperList(), form);
568 }
569
570
571
572
573
574 public static Object getSelectedObject(KSUifForm theForm, String actionLink) {
575 String selectedCollectionPath = theForm.getActionParamaterValue(UifParameters.SELECTED_COLLECTION_PATH);
576 if (StringUtils.isBlank(selectedCollectionPath)) {
577 throw new RuntimeException("Selected collection was not set for " + actionLink);
578 }
579
580 int selectedLineIndex = -1;
581 String selectedLine = theForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX);
582 if (StringUtils.isNotBlank(selectedLine)) {
583 selectedLineIndex = Integer.parseInt(selectedLine);
584 }
585
586 if (selectedLineIndex == -1) {
587 throw new RuntimeException("Selected line index was not set");
588 }
589
590 Collection<Object> collection = ObjectPropertyUtils.getPropertyValue(theForm, selectedCollectionPath);
591 Object selectedObject;
592 selectedObject = ((List<Object>) collection).get(selectedLineIndex);
593
594 return selectedObject;
595 }
596
597 public static void reloadCourseOfferings(CourseOfferingManagementForm theForm) throws Exception {
598 getViewHelperService(theForm).loadCourseOfferingsByTermAndCourseCode(theForm.getTermInfo(), theForm.getInputCode(), theForm);
599 CourseOfferingManagementToolbarUtil.processCoToolbarForUser(theForm.getCourseOfferingResultList(), theForm);
600 }
601
602 public static void reloadTheCourseOfferingWithAOs_RGs_Clusters(CourseOfferingManagementForm theForm) throws Exception {
603
604 CourseOfferingInfo theCourseOffering = theForm.getCurrentCourseOfferingWrapper().getCourseOfferingInfo();
605
606 CourseOfferingWrapper coWrapper = new CourseOfferingWrapper(theCourseOffering);
607 getViewHelperService(theForm).build_AOs_RGs_AOCs_Lists_For_TheCourseOffering(theForm);
608
609 getViewHelperService(theForm).loadPreviousAndNextCourseOffering(theForm);
610
611 getViewHelperService(theForm).loadExamOfferingRelations(theForm);
612
613 CourseOfferingManagementToolbarUtil.processAoToolbarForUser(theForm.getActivityWrapperList(), theForm);
614 }
615
616 public static String getGradingOption(String gradingOptionId) throws Exception {
617 String gradingOption = "";
618 if (StringUtils.isNotBlank(gradingOptionId)) {
619 ResultValuesGroupInfo rvg = getLrcService().getResultValuesGroup(gradingOptionId, ContextUtils.createDefaultContextInfo());
620 if (rvg != null && StringUtils.isNotBlank(rvg.getName())) {
621 gradingOption = rvg.getName();
622 }
623 }
624
625 return gradingOption;
626 }
627
628 public static String getOrgNameDescription(String orgShortName) {
629 String shortName = "shortName";
630 String longName = "";
631
632 QueryByCriteria.Builder qBuilder = QueryByCriteria.Builder.create();
633 if (StringUtils.isNotBlank(orgShortName) && !orgShortName.isEmpty()) {
634 qBuilder.setPredicates(PredicateFactory.or(
635 PredicateFactory.equal(shortName, orgShortName)));
636 } else {
637 throw new RuntimeException("Org short name is null!");
638 }
639 try {
640 QueryByCriteria query = qBuilder.build();
641
642 OrganizationService organizationService = getOrganizationService();
643
644 java.util.List<OrgInfo> orgInfos = organizationService.searchForOrgs(query, ContextUtils.createDefaultContextInfo());
645 if (!orgInfos.isEmpty()) {
646 longName = orgInfos.get(0).getLongName();
647 }
648 } catch (Exception e) {
649 throw new RuntimeException("Error! No long name description found.", e);
650 }
651 return longName;
652 }
653
654 public static Properties _buildCOURLParameters(CourseOfferingInfo courseOfferingInfo, String methodToCall) {
655 Properties props = new Properties();
656 props.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, methodToCall);
657 props.put("courseOfferingInfo.id", courseOfferingInfo.getId());
658 props.put(KRADConstants.DATA_OBJECT_CLASS_ATTRIBUTE, CourseOfferingEditWrapper.class.getName());
659 return props;
660 }
661
662 public static boolean _isClusterUniqueWithinCO(CourseOfferingManagementForm form, String courseOfferingId, String privateName) throws Exception {
663 List<String> foIds = new ArrayList<String>();
664
665
666 if (form.getFoId2aoTypeMap() == null || form.getFoId2aoTypeMap().isEmpty()) {
667 List<FormatOfferingInfo> formatOfferingList = getCourseOfferingService().getFormatOfferingsByCourseOffering(courseOfferingId, ContextUtils.createDefaultContextInfo());
668 for (FormatOfferingInfo foInfo : formatOfferingList) {
669 foIds.add(foInfo.getId());
670 }
671 } else {
672 foIds = new ArrayList<String>(form.getFoId2aoTypeMap().keySet());
673 }
674
675
676 if (!foIds.isEmpty()) {
677 QueryByCriteria.Builder qbcBuilder = QueryByCriteria.Builder.create();
678 qbcBuilder.setPredicates(PredicateFactory.and(
679 PredicateFactory.in("formatOfferingId", foIds.toArray()),
680 PredicateFactory.equalIgnoreCase("privateName", privateName)));
681 QueryByCriteria criteria = qbcBuilder.build();
682
683 List<ActivityOfferingClusterInfo> aoClusterList = getCourseOfferingService().searchForActivityOfferingClusters(criteria, ContextUtils.createDefaultContextInfo());
684 return aoClusterList.size() <= 0;
685 }
686
687 return true;
688 }
689
690
691 public static ActivityOfferingClusterInfo _buildEmptyAOCluster(String formatOfferingId, String privateName, String publishedName) {
692 ActivityOfferingClusterInfo emptyCluster = new ActivityOfferingClusterInfo();
693 emptyCluster.setTypeKey(CourseOfferingServiceConstants.AOC_ROOT_TYPE_KEY);
694 emptyCluster.setStateKey(CourseOfferingServiceConstants.AOC_ACTIVE_STATE_KEY);
695 emptyCluster.setPrivateName(privateName);
696 emptyCluster.setName(publishedName);
697 emptyCluster.setFormatOfferingId(formatOfferingId);
698 List<ActivityOfferingSetInfo> activityOfferingSets = new ArrayList<ActivityOfferingSetInfo>();
699 emptyCluster.setActivityOfferingSets(activityOfferingSets);
700 return emptyCluster;
701 }
702
703 public static boolean _clusterForFormatOfferingValidation(FormatOfferingInfo formatOfferingInfo, ContextInfo context) {
704 try {
705 if (formatOfferingInfo.getActivityOfferingTypeKeys() != null && formatOfferingInfo.getActivityOfferingTypeKeys().size() > 1) {
706 return true;
707 } else if (formatOfferingInfo.getActivityOfferingTypeKeys() != null && formatOfferingInfo.getActivityOfferingTypeKeys().size() == 1) {
708 QueryByCriteria.Builder qbcBuilder = QueryByCriteria.Builder.create();
709 qbcBuilder.setPredicates(PredicateFactory.equal("formatOfferingId", formatOfferingInfo.getId()));
710 QueryByCriteria criteria = qbcBuilder.build();
711
712 List<String> aoClusterIds = getCourseOfferingService().searchForActivityOfferingClusterIds(criteria, context);
713 if (aoClusterIds != null && aoClusterIds.size() >= 1) {
714 return false;
715 } else {
716 return true;
717 }
718 } else {
719 return false;
720 }
721 } catch (Exception e) {
722 throw new RuntimeException(e);
723 }
724
725 }
726
727 public static void clearForm(CourseOfferingManagementForm form) throws Exception {
728 form.setAdminOrg(null);
729 form.setCourseOfferingResultList(new ArrayList<CourseOfferingListSectionWrapper>());
730 form.setActivityWrapperList(new ArrayList<ActivityOfferingWrapper>());
731 form.setClusterResultList(new ArrayList<ActivityOfferingClusterWrapper>());
732 form.setRgResultList(new ArrayList<RegistrationGroupWrapper>());
733
734 form.setSelectedToDeleteList(new ArrayList<ActivityOfferingWrapper>());
735 form.setSelectedCoToDeleteList(new ArrayList<CourseOfferingListSectionWrapper>());
736
737 form.setCourseOfferingCopyWrapper(null);
738 form.setFormatOfferingIdForNewAO(null);
739
740 form.setHasMoreThanOneFormat(false);
741 form.setHasMoreThanOneCluster(false);
742 form.setTermInfo(null);
743 form.setSubjectCode(null);
744 form.setSubjectCodeDescription(null);
745
746 form.setFormatIdForNewAO(null);
747 form.setFormatOfferingIdForNewAO(null);
748 form.setActivityIdForNewAO(null);
749 form.setClusterIdForNewAO(null);
750 form.setNoOfActivityOfferings(null);
751
752 form.setCurrentCourseOfferingWrapper(null);
753 form.setPreviousCourseOfferingWrapper(null);
754 form.setNextCourseOfferingWrapper(null);
755
756 form.setSocState(null);
757 form.setSocStateKey(null);
758
759 form.setSelectedIllegalAOInDeletion(false);
760
761 form.setEnableAddButton(false);
762 form.setEnableMoveAOButton(false);
763 form.setEnableAddClusterButton(false);
764
765 }
766
767 public static String getTermStartEndDate(String termId, TermInfo term) {
768
769 StringBuilder stringBuilder = new StringBuilder();
770 Formatter formatter = new Formatter(stringBuilder, Locale.US);
771 String displayString = termId;
772 if (term != null) {
773 String startDate = DateFormatters.MONTH_DAY_YEAR_DATE_FORMATTER.format(term.getStartDate());
774 String endDate = DateFormatters.MONTH_DAY_YEAR_DATE_FORMATTER.format(term.getEndDate());
775 formatter.format("%s - %s", startDate, endDate);
776 displayString = stringBuilder.toString();
777 }
778 return displayString;
779 }
780
781 public static String getTermDisplayString(String termId, TermInfo term) {
782
783 StringBuilder stringBuilder = new StringBuilder();
784 Formatter formatter = new Formatter(stringBuilder, Locale.US);
785 String displayString = termId;
786 if (term != null) {
787 String startDate = DateFormatters.MONTH_DAY_YEAR_DATE_FORMATTER.format(term.getStartDate());
788 String endDate = DateFormatters.MONTH_DAY_YEAR_DATE_FORMATTER.format(term.getEndDate());
789 String termType = term.getName();
790 formatter.format("%s (%s to %s)", termType, startDate, endDate);
791 displayString = stringBuilder.toString();
792 }
793 return displayString;
794 }
795
796 public static CourseOfferingInfo createCourseOfferingInfo(String termId, CourseInfo courseInfo) throws Exception {
797
798 int firstGradingOption = 0;
799 CourseOfferingInfo courseOffering = new CourseOfferingInfo();
800
801 courseOffering.setTermId(termId);
802 courseOffering.setCourseOfferingTitle(courseInfo.getCourseTitle());
803 courseOffering.setCourseId(courseInfo.getId());
804 courseOffering.setCourseCode(courseInfo.getCode());
805 courseOffering.setTypeKey(LuiServiceConstants.COURSE_OFFERING_TYPE_KEY);
806 courseOffering.setStateKey(LuiServiceConstants.LUI_CO_STATE_DRAFT_KEY);
807
808
809 courseOffering.setWaitlistTypeKey(null);
810 courseOffering.setWaitlistLevelTypeKey(null);
811 courseOffering.setCourseOfferingCode(courseInfo.getCode());
812
813
814 if (!courseInfo.getCreditOptions().isEmpty()) {
815 courseOffering.setCreditOptionId(courseInfo.getCreditOptions().get(firstGradingOption).getKey());
816 }
817
818 List<String> courseGradingOptions = new ArrayList<String>(courseInfo.getGradingOptions());
819 if (courseGradingOptions.remove(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_PASSFAIL)) {
820 courseOffering.getStudentRegistrationGradingOptions().add(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_PASSFAIL);
821 }
822 if (courseGradingOptions.remove(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_AUDIT)) {
823 courseOffering.getStudentRegistrationGradingOptions().add(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_AUDIT);
824 }
825
826 if (!courseGradingOptions.isEmpty()) {
827 courseOffering.setGradingOptionId(courseGradingOptions.get(firstGradingOption));
828 }
829
830
831 if (!courseInfo.getAttributes().isEmpty()) {
832 for (AttributeInfo info : courseInfo.getAttributes()) {
833
834 if (info.getKey().equals("finalExamStatus")) {
835 courseOffering.setFinalExamType(convertCourseFinalExamTypeToCourseOfferingFinalExamType(info.getValue()));
836 }
837 }
838 }
839
840 return courseOffering;
841 }
842
843 private static String convertCourseFinalExamTypeToCourseOfferingFinalExamType(String courseFinalExamType) {
844 String sRet = null;
845 if ("STD".equals(courseFinalExamType)) {
846 sRet = CourseOfferingConstants.COURSEOFFERING_FINAL_EXAM_TYPE_STANDARD;
847 } else if ("ALT".equals(courseFinalExamType)) {
848 sRet = CourseOfferingConstants.COURSEOFFERING_FINAL_EXAM_TYPE_ALTERNATE;
849 } else {
850 sRet = CourseOfferingConstants.COURSEOFFERING_FINAL_EXAM_TYPE_NONE;
851 }
852 return sRet;
853 }
854
855 public static TermInfo getTerm(String termCode) {
856
857 int firstTerm = 0;
858
859 QueryByCriteria.Builder qBuilder = QueryByCriteria.Builder.create();
860 List<Predicate> pList = new ArrayList<Predicate>();
861 Predicate p = null;
862
863 qBuilder.setPredicates();
864 if (StringUtils.isNotBlank(termCode)) {
865 p = equal("atpCode", termCode);
866 pList.add(p);
867 }
868 qBuilder.setPredicates(p);
869
870 try {
871 List<TermInfo> terms = getAcademicCalendarService().searchForTerms(qBuilder.build(), ContextUtils.createDefaultContextInfo());
872 if (terms.size() > 1) {
873 return null;
874 } else if (terms.isEmpty()) {
875 return null;
876 }
877 return terms.get(firstTerm);
878 } catch (Exception e) {
879 throw new RuntimeException(e);
880 }
881 }
882
883 public static List<CourseInfo> retrieveMatchingCourses(String courseCode, TermInfo term) {
884
885 int firstTerm = 0;
886 ContextInfo context = ContextUtils.createDefaultContextInfo();
887 CourseInfo returnCourseInfo;
888 String courseId;
889 List<SearchParamInfo> searchParams = new ArrayList<SearchParamInfo>();
890 List<CourseInfo> courseInfoList = new ArrayList<CourseInfo>();
891
892 SearchParamInfo qpv = new SearchParamInfo();
893 qpv.setKey("lu.queryParam.luOptionalType");
894 qpv.getValues().add(CluServiceConstants.CREDIT_COURSE_LU_TYPE_KEY);
895 searchParams.add(qpv);
896
897
898 qpv = new SearchParamInfo();
899 qpv.setKey("lu.queryParam.luOptionalState");
900 qpv.setValues(Arrays.asList(
901 DtoConstants.STATE_ACTIVE,
902 DtoConstants.STATE_SUPERSEDED,
903 DtoConstants.STATE_RETIRED));
904 searchParams.add(qpv);
905
906
907
908
909
910
911 List<AtpInfo> atps;
912 try {
913 atps = getAtpService().getAtpsByCode(term.getCode(), context);
914 } catch (Exception e) {
915 return courseInfoList;
916 }
917 if (atps == null || atps.size() != 1) {
918 return courseInfoList;
919 }
920
921 qpv = new SearchParamInfo();
922 qpv.setKey(CourseInfoByTermLookupableImpl.QueryParamEnum.TERM_START.getQueryKey());
923 qpv.getValues().add(DateFormatters.QUERY_SERVICE_TIMESTAMP_FORMATTER.format(atps.get(firstTerm).getStartDate()));
924 searchParams.add(qpv);
925
926 qpv = new SearchParamInfo();
927 qpv.setKey(CourseInfoByTermLookupableImpl.QueryParamEnum.TERM_END.getQueryKey());
928 qpv.getValues().add(DateFormatters.QUERY_SERVICE_TIMESTAMP_FORMATTER.format(atps.get(firstTerm).getEndDate()));
929 searchParams.add(qpv);
930
931
932 qpv = new SearchParamInfo();
933 qpv.setKey(CourseInfoByTermLookupableImpl.QueryParamEnum.CODE.getQueryKey());
934 qpv.getValues().add(courseCode);
935 searchParams.add(qpv);
936
937 SearchRequestInfo searchRequest = new SearchRequestInfo();
938 searchRequest.setParams(searchParams);
939 searchRequest.setSearchKey("lu.search.courseCodes");
940
941 try {
942 SearchResultInfo searchResult = getCluService().search(searchRequest, ContextUtils.getContextInfo());
943 if (searchResult.getRows().size() > 0) {
944 for (SearchResultRowInfo row : searchResult.getRows()) {
945 List<SearchResultCellInfo> srCells = row.getCells();
946 if (srCells != null && srCells.size() > 0) {
947 for (SearchResultCellInfo cell : srCells) {
948 if ("lu.resultColumn.cluId".equals(cell.getKey())) {
949 courseId = cell.getValue();
950 returnCourseInfo = getCourseService().getCourse(courseId, ContextUtils.getContextInfo());
951 courseInfoList.add(returnCourseInfo);
952 }
953 }
954 }
955 }
956 }
957 } catch (Exception e) {
958 throw new RuntimeException(e);
959 }
960
961 return courseInfoList;
962 }
963
964 public static Properties _buildCOURLParameters(String courseId, String termId, String socId, String methodToCall) {
965 Properties props = new Properties();
966 props.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, methodToCall);
967 props.put(CourseOfferingConstants.COURSE_ID, courseId);
968 props.put(CourseOfferingConstants.TARGET_TERM_ID, termId);
969 props.put(CourseOfferingConstants.SOC_ID, socId);
970 props.put(CourseOfferingConstants.CREATE_COURSEOFFERING, "true");
971 props.put(KRADConstants.DATA_OBJECT_CLASS_ATTRIBUTE, CourseOfferingEditWrapper.class.getName());
972
973 return props;
974 }
975
976 public static HashMap getSchedulingStateAndNameHash() throws Exception {
977 if (scheduleStateHm == null) {
978 scheduleStateHm = new HashMap<String, String>();
979 ContextInfo contextInfo = ContextUtils.getContextInfo();
980
981 List<StateInfo> stateInfoList;
982 try {
983 stateInfoList = getStateService().getStatesByLifecycle(LuiServiceConstants.LUI_AO_SCHEDULING_STATE_LIFECYCLE_KEY, contextInfo);
984 } catch (Exception e) {
985 throw new RuntimeException(e);
986 }
987
988 for (StateInfo stateInfo : stateInfoList) {
989 if (stateInfo != null) {
990 scheduleStateHm.put(stateInfo.getKey(), stateInfo.getName());
991 }
992 }
993 }
994 return scheduleStateHm;
995 }
996
997
998 public static boolean mergeAttribute(List<AttributeInfo> attributes, String attrKey, String attrValue) {
999 AttributeInfo attributeInfo = getAttributeForKey(attributes, attrKey);
1000
1001 if (attributeInfo != null) {
1002 if (StringUtils.equals(attrValue, attributeInfo.getValue())) {
1003 return false;
1004 } else {
1005 attributeInfo.setValue(attrValue);
1006 }
1007 } else {
1008 AttributeInfo newAttr = new AttributeInfo();
1009 newAttr.setKey(attrKey);
1010 newAttr.setValue(attrValue);
1011 attributes.add(newAttr);
1012 }
1013 return true;
1014 }
1015
1016 private static AttributeInfo getAttributeForKey(List<AttributeInfo> attributeInfos, String key) {
1017 for (AttributeInfo info : attributeInfos) {
1018 if (info.getKey().equals(key)) {
1019 return info;
1020 }
1021 }
1022 return null;
1023 }
1024
1025 }