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.service.AcademicCalendarService;
25 import org.kuali.student.enrollment.class2.acal.form.CalendarSearchForm;
26 import org.kuali.student.enrollment.class2.acal.util.CalendarConstants;
27 import org.kuali.student.mock.utilities.TestHelper;
28 import org.kuali.student.r2.common.constants.CommonServiceConstants;
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.class1.state.dto.StateInfo;
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
43
44
45
46
47
48 @Deprecated
49 public class AtpStateKeyValues extends UifKeyValuesFinderBase implements Serializable {
50
51 private static final long serialVersionUID = 1L;
52
53 private transient AcademicCalendarService acalService;
54
55 private static List<StateInfo> holidayStates;
56
57 private static List<StateInfo> acalStates;
58
59 private static List<StateInfo> termStates;
60
61
62 @Override
63 public List<KeyValue> getKeyValues(ViewModel model) {
64 CalendarSearchForm form = (CalendarSearchForm)model;
65 String atpType = form.getCalendarType();
66
67 List<KeyValue> keyValues = new ArrayList<KeyValue>();
68
69
70 try {
71 List<StateInfo> states = null;
72
73 if(atpType.equals(CalendarConstants.HOLIDAYCALENDER)){
74 states = getHolidayStates();
75 }else if(atpType.equals(CalendarConstants.ACADEMICCALENDER)) {
76 states = getAcalStates();
77 }else if(atpType.equals(CalendarConstants.TERM)){
78 states = getTermStates();
79 }
80
81 for (StateInfo state : states) {
82 ConcreteKeyValue keyValue = new ConcreteKeyValue();
83 keyValue.setKey(state.getKey());
84 keyValue.setValue(state.getName());
85 keyValues.add(keyValue);
86 }
87 } catch (Exception e) {
88 throw new RuntimeException(e);
89 }
90
91 return keyValues;
92 }
93
94 public List<StateInfo> getHolidayStates() throws InvalidParameterException, MissingParameterException, PermissionDeniedException, OperationFailedException {
95 if(holidayStates == null) {
96
97 ContextInfo context = TestHelper.getContext1();
98
99 holidayStates = Collections.unmodifiableList(getAcalService().getHolidayCalendarStates(context));
100 }
101 return holidayStates;
102 }
103
104 public List<StateInfo> getAcalStates() throws InvalidParameterException, MissingParameterException, PermissionDeniedException, OperationFailedException {
105 if(acalStates == null) {
106
107 ContextInfo context = TestHelper.getContext1();
108
109 acalStates = Collections.unmodifiableList(getAcalService().getAcademicCalendarStates(context));
110 }
111
112 return acalStates;
113 }
114
115 public List<StateInfo> getTermStates() throws InvalidParameterException, MissingParameterException, PermissionDeniedException, OperationFailedException {
116 if(termStates == null) {
117
118 ContextInfo context = TestHelper.getContext1();
119
120 termStates = Collections.unmodifiableList(getAcalService().getTermStates(context));
121 }
122 return termStates;
123 }
124
125 public AcademicCalendarService getAcalService() {
126 if(acalService == null) {
127 acalService = (AcademicCalendarService) GlobalResourceLoader.getService(new QName(CommonServiceConstants.REF_OBJECT_URI_GLOBAL_PREFIX + "acal", "AcademicCalendarService"));
128 }
129 return this.acalService;
130 }
131 }