1 | |
package org.kuali.student.enrollment.class2.courseoffering.keyvalue; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
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.keyvalues.KeyValuesBase; |
23 | |
import org.kuali.student.enrollment.acal.dto.AcademicCalendarInfo; |
24 | |
import org.kuali.student.enrollment.acal.dto.TermInfo; |
25 | |
import org.kuali.student.enrollment.acal.service.AcademicCalendarService; |
26 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
27 | |
import org.kuali.student.r2.common.exceptions.*; |
28 | |
|
29 | |
import javax.xml.namespace.QName; |
30 | |
import java.io.Serializable; |
31 | |
import java.util.ArrayList; |
32 | |
import java.util.Calendar; |
33 | |
import java.util.Date; |
34 | |
import java.util.List; |
35 | |
|
36 | |
|
37 | 0 | public class TermKeyValues extends KeyValuesBase implements Serializable { |
38 | |
|
39 | |
private static final long serialVersionUID = 1L; |
40 | |
|
41 | |
private transient AcademicCalendarService acalService; |
42 | |
|
43 | |
|
44 | |
@Override |
45 | |
public List<KeyValue> getKeyValues() { |
46 | |
|
47 | |
List<AcademicCalendarInfo> acals; |
48 | 0 | ContextInfo context = ContextInfo.newInstance(); |
49 | |
|
50 | |
|
51 | 0 | List<TermInfo> terms = new ArrayList<TermInfo>(); |
52 | |
try { |
53 | 0 | Calendar nowCal = Calendar.getInstance(); |
54 | 0 | nowCal.setTime(new Date()); |
55 | 0 | int year = nowCal.get(Calendar.YEAR); |
56 | 0 | acals = getAcalService().getAcademicCalendarsByStartYear(year, context); |
57 | 0 | for (AcademicCalendarInfo acal : acals) { |
58 | 0 | terms.addAll(getAcalService().getTermsForAcademicCalendar(acal.getKey(), context)); |
59 | |
} |
60 | 0 | } catch (DoesNotExistException e) { |
61 | 0 | throw new RuntimeException("No Terms found for current AcademicCalendar(s)! There should be some in the database.", e); |
62 | 0 | } catch (InvalidParameterException e) { |
63 | 0 | throw new RuntimeException(e); |
64 | 0 | } catch (MissingParameterException e) { |
65 | 0 | throw new RuntimeException(e); |
66 | 0 | } catch (OperationFailedException e) { |
67 | 0 | throw new RuntimeException(e); |
68 | 0 | } catch (PermissionDeniedException e) { |
69 | 0 | throw new RuntimeException(e); |
70 | 0 | } |
71 | |
|
72 | 0 | List<KeyValue> keyValues = new ArrayList<KeyValue>(); |
73 | |
|
74 | 0 | for(TermInfo term : terms) { |
75 | 0 | keyValues.add(new ConcreteKeyValue(term.getKey(), term.getName())); |
76 | |
} |
77 | |
|
78 | 0 | return keyValues; |
79 | |
} |
80 | |
|
81 | |
protected AcademicCalendarService getAcalService() { |
82 | 0 | if(acalService == null) { |
83 | 0 | acalService = (AcademicCalendarService) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/acal", "AcademicCalendarService")); |
84 | |
} |
85 | 0 | return this.acalService; |
86 | |
} |
87 | |
} |