1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.student.enrollment.class2.acal.keyvalue; |
18 | |
|
19 | |
import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; |
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.acal.constants.AcademicCalendarServiceConstants; |
25 | |
import org.kuali.student.enrollment.acal.service.AcademicCalendarService; |
26 | |
import org.kuali.student.enrollment.class2.acal.dto.AcalEventWrapper; |
27 | |
import org.kuali.student.enrollment.class2.acal.form.AcademicCalendarForm; |
28 | |
import org.kuali.student.mock.utilities.TestHelper; |
29 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
30 | |
import org.kuali.student.r2.common.exceptions.InvalidParameterException; |
31 | |
import org.kuali.student.r2.common.exceptions.MissingParameterException; |
32 | |
import org.kuali.student.r2.common.exceptions.OperationFailedException; |
33 | |
import org.kuali.student.r2.common.exceptions.PermissionDeniedException; |
34 | |
import org.kuali.student.r2.core.type.dto.TypeInfo; |
35 | |
|
36 | |
import javax.xml.namespace.QName; |
37 | |
import java.io.Serializable; |
38 | |
import java.util.ArrayList; |
39 | |
import java.util.Collections; |
40 | |
import java.util.List; |
41 | |
|
42 | 0 | public class AcalEventTypeKeyValues extends UifKeyValuesFinderBase implements Serializable { |
43 | |
|
44 | |
private static final long serialVersionUID = 1L; |
45 | |
|
46 | |
private transient AcademicCalendarService acalService; |
47 | |
|
48 | |
private static List<TypeInfo> acalEventTypes; |
49 | |
|
50 | |
public List<KeyValue> getKeyValues(ViewModel model) { |
51 | 0 | List<KeyValue> keyValues = new ArrayList<KeyValue>(); |
52 | 0 | List<String> alreadyAddedTypes = new ArrayList(); |
53 | |
|
54 | 0 | AcademicCalendarForm acalForm = (AcademicCalendarForm)model; |
55 | |
|
56 | 0 | for (AcalEventWrapper eventWrapper : acalForm.getEvents()){ |
57 | 0 | alreadyAddedTypes.add(eventWrapper.getEventTypeKey()); |
58 | |
} |
59 | |
|
60 | |
|
61 | 0 | ConcreteKeyValue topKeyValue = new ConcreteKeyValue(); |
62 | 0 | topKeyValue.setKey(""); |
63 | 0 | topKeyValue.setValue("Select Event Type"); |
64 | 0 | keyValues.add(topKeyValue); |
65 | |
|
66 | |
try { |
67 | 0 | List<TypeInfo> types = getAcalEventTypes(); |
68 | 0 | for (TypeInfo type : types) { |
69 | 0 | if (!alreadyAddedTypes.contains(type.getKey())){ |
70 | 0 | ConcreteKeyValue keyValue = new ConcreteKeyValue(); |
71 | 0 | keyValue.setKey(type.getKey()); |
72 | 0 | keyValue.setValue(type.getName()); |
73 | 0 | keyValues.add(keyValue); |
74 | 0 | } |
75 | |
} |
76 | 0 | } catch (Exception e) { |
77 | 0 | throw new RuntimeException(e); |
78 | 0 | } |
79 | |
|
80 | 0 | return keyValues; |
81 | |
} |
82 | |
|
83 | |
private List<TypeInfo> getAcalEventTypes() throws InvalidParameterException, MissingParameterException, PermissionDeniedException, OperationFailedException { |
84 | 0 | if(acalEventTypes == null) { |
85 | |
|
86 | 0 | ContextInfo context = TestHelper.getContext1(); |
87 | |
|
88 | 0 | acalEventTypes = Collections.unmodifiableList(getAcalService().getAcalEventTypes(context)); |
89 | |
} |
90 | 0 | return acalEventTypes; |
91 | |
} |
92 | |
|
93 | |
public AcademicCalendarService getAcalService() { |
94 | 0 | if(acalService == null) { |
95 | 0 | acalService = (AcademicCalendarService) GlobalResourceLoader.getService(new QName(AcademicCalendarServiceConstants.NAMESPACE, AcademicCalendarServiceConstants.SERVICE_NAME_LOCAL_PART)); |
96 | |
} |
97 | 0 | return this.acalService; |
98 | |
} |
99 | |
} |