1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.enrollment.class2.courseoffering.keyvalue; |
17 | |
|
18 | |
import java.io.Serializable; |
19 | |
import java.util.ArrayList; |
20 | |
import java.util.Collections; |
21 | |
import java.util.Comparator; |
22 | |
import java.util.List; |
23 | |
|
24 | |
import javax.xml.namespace.QName; |
25 | |
|
26 | |
import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; |
27 | |
import org.kuali.rice.core.api.util.ConcreteKeyValue; |
28 | |
import org.kuali.rice.core.api.util.KeyValue; |
29 | |
import org.kuali.rice.krad.keyvalues.KeyValuesBase; |
30 | |
import org.kuali.student.common.exceptions.DoesNotExistException; |
31 | |
import org.kuali.student.common.exceptions.InvalidParameterException; |
32 | |
import org.kuali.student.common.exceptions.MissingParameterException; |
33 | |
import org.kuali.student.common.exceptions.OperationFailedException; |
34 | |
import org.kuali.student.core.enumerationmanagement.dto.EnumeratedValueInfo; |
35 | |
import org.kuali.student.core.enumerationmanagement.service.EnumerationManagementService; |
36 | |
|
37 | 0 | public class SubjectAreaKeyValues extends KeyValuesBase implements Serializable { |
38 | |
|
39 | |
private static final long serialVersionUID = 1L; |
40 | |
|
41 | |
private static final String SUBJECT_AREA_ENUM_KEY = "kuali.lu.subjectArea"; |
42 | |
|
43 | |
private EnumerationManagementService enumService; |
44 | 0 | private SubjectAreasComparator subjectAreasComparator = new SubjectAreasComparator(); |
45 | |
|
46 | |
|
47 | |
@Override |
48 | |
public List<KeyValue> getKeyValues() { |
49 | |
|
50 | |
List<EnumeratedValueInfo> subjectAreas; |
51 | |
|
52 | |
try { |
53 | 0 | subjectAreas = getEnumService().getEnumeratedValues(SUBJECT_AREA_ENUM_KEY, null, null, null); |
54 | 0 | Collections.sort(subjectAreas, subjectAreasComparator); |
55 | 0 | } catch (DoesNotExistException e) { |
56 | 0 | throw new RuntimeException("No subject areas found! There should be some in the database", e); |
57 | 0 | } catch (InvalidParameterException e) { |
58 | 0 | throw new RuntimeException(e); |
59 | 0 | } catch (MissingParameterException e) { |
60 | 0 | throw new RuntimeException(e); |
61 | 0 | } catch (OperationFailedException e) { |
62 | 0 | throw new RuntimeException(e); |
63 | 0 | } |
64 | |
|
65 | 0 | List<KeyValue> keyValues = new ArrayList<KeyValue>(); |
66 | |
|
67 | 0 | for(EnumeratedValueInfo e : subjectAreas) { |
68 | 0 | keyValues.add(new ConcreteKeyValue(e.getCode(), e.getValue())); |
69 | |
} |
70 | |
|
71 | 0 | return keyValues; |
72 | |
} |
73 | |
|
74 | |
protected EnumerationManagementService getEnumService() { |
75 | 0 | if(enumService == null) { |
76 | 0 | enumService = (EnumerationManagementService)GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/enumerationmanagement","EnumerationManagementService")); |
77 | |
} |
78 | 0 | return this.enumService; |
79 | |
} |
80 | |
|
81 | 0 | private class SubjectAreasComparator implements Comparator { |
82 | |
|
83 | |
@Override |
84 | |
public int compare(Object o1, Object o2) { |
85 | 0 | if (!(o1 instanceof EnumeratedValueInfo) || !(o2 instanceof EnumeratedValueInfo)) { |
86 | 0 | throw new ClassCastException("Object not of type EnumeratedValueInfo."); |
87 | |
} |
88 | 0 | EnumeratedValueInfo enumeratedValue1 = (EnumeratedValueInfo) o1; |
89 | 0 | EnumeratedValueInfo enumeratedValue2 = (EnumeratedValueInfo) o2; |
90 | |
|
91 | 0 | int result = enumeratedValue1.getValue().compareToIgnoreCase(enumeratedValue2.getValue()); |
92 | 0 | return result; |
93 | |
} |
94 | |
} |
95 | |
} |