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 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.r2.common.exceptions.DoesNotExistException;
23 import org.kuali.student.r2.common.util.ContextUtils;
24 import org.kuali.student.r2.core.enumerationmanagement.dto.EnumeratedValueInfo;
25 import org.kuali.student.r2.core.enumerationmanagement.service.EnumerationManagementService;
26
27 import javax.xml.namespace.QName;
28 import java.io.Serializable;
29 import java.util.ArrayList;
30 import java.util.Collections;
31 import java.util.Comparator;
32 import java.util.List;
33
34
35
36
37 @Deprecated
38 public class SubjectAreaKeyValues extends KeyValuesBase implements Serializable {
39
40 private static final long serialVersionUID = 1L;
41
42 private static final String SUBJECT_AREA_ENUM_KEY = "kuali.lu.subjectArea";
43
44 private transient EnumerationManagementService enumService;
45 private transient SubjectAreasComparator subjectAreasComparator = new SubjectAreasComparator();
46
47 @Override
48 public List<KeyValue> getKeyValues() {
49
50 List<EnumeratedValueInfo> subjectAreas;
51
52 try {
53 subjectAreas = getEnumService().getEnumeratedValues(SUBJECT_AREA_ENUM_KEY, null, null, null, ContextUtils.createDefaultContextInfo());
54 Collections.sort(subjectAreas, subjectAreasComparator);
55 } catch (DoesNotExistException e) {
56 throw new RuntimeException("No subject areas found! There should be some in the database", e);
57 } catch (Exception e) {
58 throw new RuntimeException("Error looking up subject areas", e);
59 }
60
61 List<KeyValue> keyValues = new ArrayList<KeyValue>();
62
63 for(EnumeratedValueInfo e : subjectAreas) {
64 keyValues.add(new ConcreteKeyValue(e.getCode(), e.getValue()));
65 }
66
67 return keyValues;
68 }
69
70 protected EnumerationManagementService getEnumService() {
71 if(enumService == null) {
72 enumService = (EnumerationManagementService)GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/enumerationmanagement","EnumerationManagementService"));
73 }
74 return this.enumService;
75 }
76
77 private static class SubjectAreasComparator implements Comparator {
78
79 @Override
80 public int compare(Object o1, Object o2) {
81 if (!(o1 instanceof EnumeratedValueInfo) || !(o2 instanceof EnumeratedValueInfo)) {
82 throw new ClassCastException("Object not of type EnumeratedValueInfo.");
83 }
84 EnumeratedValueInfo enumeratedValue1 = (EnumeratedValueInfo) o1;
85 EnumeratedValueInfo enumeratedValue2 = (EnumeratedValueInfo) o2;
86
87 int result = enumeratedValue1.getValue().compareToIgnoreCase(enumeratedValue2.getValue());
88 return result;
89 }
90 }
91
92 }