1 | |
package org.kuali.student.enrollment.class2.acal.keyvalue; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
import org.apache.commons.lang.StringUtils; |
20 | |
import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; |
21 | |
import org.kuali.rice.core.api.util.ConcreteKeyValue; |
22 | |
import org.kuali.rice.core.api.util.KeyValue; |
23 | |
import org.kuali.rice.krad.keyvalues.KeyValuesBase; |
24 | |
import org.kuali.student.enrollment.acal.dto.AcademicCalendarInfo; |
25 | |
import org.kuali.student.enrollment.acal.dto.TermInfo; |
26 | |
import org.kuali.student.enrollment.acal.service.AcademicCalendarService; |
27 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
28 | |
import org.kuali.student.r2.common.exceptions.*; |
29 | |
import org.kuali.student.r2.common.util.constants.AtpServiceConstants; |
30 | |
|
31 | |
import javax.xml.namespace.QName; |
32 | |
import java.io.Serializable; |
33 | |
import java.util.ArrayList; |
34 | |
import java.util.Calendar; |
35 | |
import java.util.Date; |
36 | |
import java.util.List; |
37 | |
|
38 | |
|
39 | |
@Deprecated |
40 | 0 | public class TermKeyValues extends KeyValuesBase implements Serializable { |
41 | |
|
42 | |
private static final long serialVersionUID = 1L; |
43 | |
|
44 | |
private transient AcademicCalendarService acalService; |
45 | |
|
46 | |
|
47 | |
@Override |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
public List<KeyValue> getKeyValues() { |
57 | |
|
58 | 0 | List<AcademicCalendarInfo> acals = new ArrayList<AcademicCalendarInfo>(); |
59 | 0 | ContextInfo context = new ContextInfo(); |
60 | |
|
61 | |
|
62 | 0 | List<TermInfo> terms = new ArrayList<TermInfo>(); |
63 | |
try { |
64 | 0 | Calendar nowCal = Calendar.getInstance(); |
65 | 0 | nowCal.setTime(new Date()); |
66 | 0 | int year = nowCal.get(Calendar.YEAR); |
67 | 0 | acals.addAll(getAcalService().getAcademicCalendarsByStartYear(year - 1, context)); |
68 | 0 | acals.addAll(getAcalService().getAcademicCalendarsByStartYear(year, context)); |
69 | 0 | acals.addAll(getAcalService().getAcademicCalendarsByStartYear(year+1, context)); |
70 | 0 | for (AcademicCalendarInfo acal : acals) { |
71 | 0 | if (StringUtils.equals(acal.getStateKey(), AtpServiceConstants.ATP_OFFICIAL_STATE_KEY)){ |
72 | 0 | terms.addAll(getAcalService().getTermsForAcademicCalendar(acal.getId(), context)); |
73 | |
} |
74 | |
} |
75 | |
|
76 | |
|
77 | 0 | for (TermInfo term : terms) { |
78 | 0 | if ("testTermId1".equals(term.getId())) { |
79 | 0 | terms.remove(term); |
80 | 0 | terms.add(0, term); |
81 | 0 | break; |
82 | |
} |
83 | |
} |
84 | 0 | } catch (DoesNotExistException e) { |
85 | 0 | throw new RuntimeException("No Terms found for current AcademicCalendar(s)! There should be some in the database.", e); |
86 | 0 | } catch (InvalidParameterException e) { |
87 | 0 | throw new RuntimeException(e); |
88 | 0 | } catch (MissingParameterException e) { |
89 | 0 | throw new RuntimeException(e); |
90 | 0 | } catch (OperationFailedException e) { |
91 | 0 | throw new RuntimeException(e); |
92 | 0 | } catch (PermissionDeniedException e) { |
93 | 0 | throw new RuntimeException(e); |
94 | 0 | } |
95 | |
|
96 | 0 | List<KeyValue> keyValues = new ArrayList<KeyValue>(); |
97 | |
|
98 | 0 | for(TermInfo term : terms) { |
99 | 0 | keyValues.add(new ConcreteKeyValue(term.getId(), term.getName())); |
100 | |
} |
101 | |
|
102 | 0 | return keyValues; |
103 | |
} |
104 | |
|
105 | |
protected AcademicCalendarService getAcalService() { |
106 | 0 | if(acalService == null) { |
107 | 0 | acalService = (AcademicCalendarService) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/acal", "AcademicCalendarService")); |
108 | |
} |
109 | 0 | return this.acalService; |
110 | |
} |
111 | |
} |