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