Coverage Report - org.kuali.rice.core.web.namespace.NamespaceValuesFinder
 
Classes in this File Line Coverage Branch Coverage Complexity
NamespaceValuesFinder
0%
0/13
0%
0/4
2
NamespaceValuesFinder$NamespaceComparator
0%
0/3
N/A
2
 
 1  
 /*
 2  
  * Copyright 2006-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.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/ecl2.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.rice.core.web.namespace;
 17  
 
 18  
 import org.kuali.rice.core.impl.namespace.NamespaceBo;
 19  
 import org.kuali.rice.core.util.ConcreteKeyValue;
 20  
 import org.kuali.rice.core.util.KeyValue;
 21  
 import org.kuali.rice.kns.lookup.keyvalues.KeyValuesBase;
 22  
 import org.kuali.rice.kns.service.KNSServiceLocator;
 23  
 import org.kuali.rice.kns.service.KeyValuesService;
 24  
 
 25  
 import java.util.ArrayList;
 26  
 import java.util.Collections;
 27  
 import java.util.Comparator;
 28  
 import java.util.List;
 29  
 
 30  0
 public class NamespaceValuesFinder extends KeyValuesBase {
 31  
 
 32  
     @Override
 33  
         public List<KeyValue> getKeyValues() {
 34  
 
 35  
         // get a list of all Namespaces
 36  0
         KeyValuesService boService = KNSServiceLocator.getKeyValuesService();
 37  0
         List<NamespaceBo> bos = (List<NamespaceBo>) boService.findAll(NamespaceBo.class);
 38  
         // copy the list of codes before sorting, since we can't modify the results from this method
 39  0
         if ( bos == null ) {
 40  0
                 bos = new ArrayList<NamespaceBo>(0);
 41  
         } else {
 42  0
                 bos = new ArrayList<NamespaceBo>( bos );
 43  
         }
 44  
 
 45  
         // sort using comparator.
 46  0
         Collections.sort(bos, NamespaceComparator.INSTANCE); 
 47  
 
 48  
         // create a new list (code, descriptive-name)
 49  0
         List<KeyValue> labels = new ArrayList<KeyValue>( bos.size() );
 50  0
         labels.add(new ConcreteKeyValue("", ""));
 51  0
         for ( NamespaceBo bo : bos ) {
 52  0
             labels.add( new ConcreteKeyValue(bo.getCode(), bo.getName() ) );
 53  
         }
 54  0
         return labels;
 55  
     }
 56  
 
 57  0
     private static class NamespaceComparator implements Comparator<NamespaceBo> {
 58  0
         public static final Comparator<NamespaceBo> INSTANCE = new NamespaceComparator();
 59  
 
 60  
         @Override
 61  
         public int compare(NamespaceBo o1, NamespaceBo o2) {
 62  0
             return o1.getCode().compareTo( o2.getCode() );
 63  
         }
 64  
     }
 65  
 }