Coverage Report - org.kuali.student.enrollment.class2.courseoffering.keyvalue.SubjectAreaKeyValues
 
Classes in this File Line Coverage Branch Coverage Complexity
SubjectAreaKeyValues
0%
0/21
0%
0/4
5.333
SubjectAreaKeyValues$1
N/A
N/A
5.333
SubjectAreaKeyValues$SubjectAreasComparator
0%
0/7
0%
0/4
5.333
 
 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 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  
  * @deprecated This class is leftover from Core Slice. Delete when no longer needed or un deprecate if needed.
 38  
  */
 39  
 @Deprecated
 40  0
 public class SubjectAreaKeyValues extends KeyValuesBase implements Serializable {
 41  
 
 42  
     private static final long serialVersionUID = 1L;
 43  
     
 44  
     private static final String SUBJECT_AREA_ENUM_KEY = "kuali.lu.subjectArea";
 45  
     
 46  
     private EnumerationManagementService enumService;
 47  0
     private SubjectAreasComparator subjectAreasComparator = new SubjectAreasComparator();
 48  
     
 49  
     
 50  
     @Override
 51  
     public List<KeyValue> getKeyValues() {
 52  
         
 53  
         List<EnumeratedValueInfo> subjectAreas;
 54  
         
 55  
         try {
 56  0
             subjectAreas = getEnumService().getEnumeratedValues(SUBJECT_AREA_ENUM_KEY, null, null, null);
 57  0
             Collections.sort(subjectAreas, subjectAreasComparator);
 58  0
         } catch (DoesNotExistException e) {
 59  0
             throw new RuntimeException("No subject areas found! There should be some in the database", e);
 60  0
         } catch (InvalidParameterException e) {
 61  0
             throw new RuntimeException(e);
 62  0
         } catch (MissingParameterException e) {
 63  0
             throw new RuntimeException(e);
 64  0
         } catch (OperationFailedException e) {
 65  0
             throw new RuntimeException(e);
 66  0
         }
 67  
         
 68  0
         List<KeyValue> keyValues = new ArrayList<KeyValue>();
 69  
         
 70  0
         for(EnumeratedValueInfo e : subjectAreas) {
 71  0
             keyValues.add(new ConcreteKeyValue(e.getCode(), e.getValue()));
 72  
         }
 73  
         
 74  0
         return keyValues;
 75  
     }
 76  
     
 77  
     protected EnumerationManagementService getEnumService() {
 78  0
         if(enumService == null) {
 79  0
             enumService = (EnumerationManagementService)GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/enumerationmanagement","EnumerationManagementService"));
 80  
         }
 81  0
         return this.enumService;
 82  
     }
 83  
 
 84  0
     private class SubjectAreasComparator implements Comparator {
 85  
 
 86  
         @Override
 87  
         public int compare(Object o1, Object o2) {
 88  0
             if (!(o1 instanceof EnumeratedValueInfo) || !(o2 instanceof EnumeratedValueInfo)) {
 89  0
                 throw new ClassCastException("Object not of type EnumeratedValueInfo.");
 90  
             }
 91  0
             EnumeratedValueInfo enumeratedValue1 = (EnumeratedValueInfo) o1;
 92  0
             EnumeratedValueInfo enumeratedValue2 = (EnumeratedValueInfo) o2;
 93  
 
 94  0
             int result = enumeratedValue1.getValue().compareToIgnoreCase(enumeratedValue2.getValue());
 95  0
             return result;
 96  
         }
 97  
     }
 98  
 }