1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.student.enrollment.class2.courseoffering.keyvalue;
18
19 import org.apache.commons.lang.StringUtils;
20 import org.kuali.rice.core.api.util.ConcreteKeyValue;
21 import org.kuali.rice.core.api.util.KeyValue;
22 import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
23 import org.kuali.rice.krad.uif.view.ViewModel;
24 import org.kuali.student.enrollment.class2.courseoffering.util.CourseOfferingManagementUtil;
25 import org.kuali.student.enrollment.class2.courseoffering.form.CourseOfferingManagementForm;
26 import org.kuali.student.enrollment.class2.courseoffering.dto.ActivityOfferingClusterWrapper;
27 import org.kuali.student.enrollment.class2.courseoffering.util.CourseOfferingResourceLoader;
28 import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
29 import org.kuali.student.r2.common.util.ContextUtils;
30 import org.kuali.student.r2.core.class1.type.service.TypeService;
31 import org.kuali.student.r2.lum.course.service.CourseService;
32
33 import java.io.Serializable;
34 import java.util.ArrayList;
35 import java.util.List;
36
37
38
39
40
41
42 public class ClustersForCreateAOKeyValues extends UifKeyValuesFinderBase implements Serializable {
43 @Override
44 public List<KeyValue> getKeyValues(ViewModel model) {
45 List<KeyValue> keyValues = new ArrayList<KeyValue>();
46 FormatsForCreateAOKeyValues formatsForCreateAOKeyValues = new FormatsForCreateAOKeyValues();
47 CourseOfferingManagementForm coForm = (CourseOfferingManagementForm) model;
48 String formatOfferingId = coForm.getFormatOfferingIdForNewAO();
49 coForm.setHasAOCluster(false);
50
51 if (StringUtils.isEmpty(formatOfferingId)) {
52
53 if (coForm.getFoId2aoTypeMap().isEmpty()) {
54 return keyValues;
55 }
56 formatOfferingId = formatsForCreateAOKeyValues.getFirstKey(model);
57 }
58
59 if (!StringUtils.isEmpty(formatOfferingId)) {
60 try {
61
62 List<ActivityOfferingClusterWrapper> clusters = new ArrayList<ActivityOfferingClusterWrapper>();
63 for (ActivityOfferingClusterWrapper cluster : coForm.getClusterResultList()) {
64 if (StringUtils.isEmpty(formatOfferingId) || formatOfferingId.equals(cluster.getFormatOfferingId())) {
65 clusters.add(cluster);
66 }
67 }
68
69
70 if (!clusters.isEmpty()) {
71 for (ActivityOfferingClusterWrapper cluster : clusters) {
72 keyValues.add(new ConcreteKeyValue(cluster.getAoCluster().getId()==null?"":cluster.getAoCluster().getId(), cluster.getAoCluster().getPrivateName()));
73 coForm.setHasAOCluster(true);
74 }
75 } else {
76 keyValues.add(new ConcreteKeyValue("", CourseOfferingManagementUtil.getCourseOfferingServiceFacade().getDefaultClusterNamePerCO(coForm.getCurrentCourseOfferingWrapper().getCourseOfferingId(), ContextUtils.getContextInfo())));
77 }
78 } catch (Exception e) {
79 throw new RuntimeException(e);
80 }
81 }
82
83 return keyValues;
84 }
85
86 protected CourseService getCourseService() {
87 return CourseOfferingResourceLoader.loadCourseService();
88 }
89
90 protected TypeService getTypeService() {
91 return CourseOfferingResourceLoader.loadTypeService();
92 }
93
94 protected CourseOfferingService getCourseOfferingService() {
95 return CourseOfferingResourceLoader.loadCourseOfferingService();
96 }
97
98
99 }