View Javadoc

1   /*
2    * Copyright 2007 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 1.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl1.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * @deprecated This class is leftover from Core Slice. Delete when no longer needed or un deprecate if needed.
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  }