Coverage Report - org.kuali.rice.krms.impl.repository.AgendaNamespaceValuesFinder
 
Classes in this File Line Coverage Branch Coverage Complexity
AgendaNamespaceValuesFinder
0%
0/18
0%
0/14
8
 
 1  
 /**
 2  
  * Copyright 2005-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.krms.impl.repository;
 17  
 
 18  
 import org.apache.commons.collections.CollectionUtils;
 19  
 import org.apache.cxf.common.util.StringUtils;
 20  
 import org.kuali.rice.core.api.util.ConcreteKeyValue;
 21  
 import org.kuali.rice.core.api.util.KeyValue;
 22  
 import org.kuali.rice.core.impl.namespace.NamespaceBo;
 23  
 import org.kuali.rice.krad.service.KRADServiceLocator;
 24  
 import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
 25  
 import org.kuali.rice.krad.uif.view.ViewModel;
 26  
 import org.kuali.rice.krad.web.form.MaintenanceForm;
 27  
 import org.kuali.rice.krms.impl.ui.AgendaEditor;
 28  
 
 29  
 import java.util.ArrayList;
 30  
 import java.util.Collection;
 31  
 import java.util.Collections;
 32  
 import java.util.HashMap;
 33  
 import java.util.HashSet;
 34  
 import java.util.List;
 35  
 import java.util.Map;
 36  
 import java.util.Set;
 37  
 
 38  
 /**
 39  
  * Helper class that returns all namespaces that have contexts associated w/ them.
 40  
  */
 41  0
 public class AgendaNamespaceValuesFinder extends UifKeyValuesFinderBase {
 42  
 
 43  
     @Override
 44  
     public List<KeyValue> getKeyValues(ViewModel model) {
 45  0
         List<KeyValue> keyValues = new ArrayList<KeyValue>();
 46  
 
 47  
         // TODO: this is not efficient -- do a smart 'select distinct' and make sure we have a good index!
 48  
 
 49  0
         Collection<ContextBo> contexts = KRADServiceLocator.getBusinessObjectService().findAll(ContextBo.class);
 50  
 
 51  0
         Collection<NamespaceBo> namespaceBos = KRADServiceLocator.getBusinessObjectService().findAll(NamespaceBo.class);
 52  0
         Map<String, String> namespaceCodeToName = new HashMap<String, String>();
 53  0
         if (!CollectionUtils.isEmpty(namespaceBos)) for (NamespaceBo namespaceBo : namespaceBos) {
 54  0
             namespaceCodeToName.put(namespaceBo.getCode(), namespaceBo.getName());
 55  
         }
 56  
 
 57  0
         List<String> namespaceCodes = new ArrayList<String>();
 58  
 
 59  0
         if (!CollectionUtils.isEmpty(contexts)) for (ContextBo context : contexts) {
 60  0
             if (!namespaceCodes.contains(context.getNamespace())) {
 61  
                 // add if not already there
 62  0
                 namespaceCodes.add(context.getNamespace());
 63  
             }
 64  
         }
 65  
 
 66  0
         Collections.sort(namespaceCodes);
 67  
 
 68  0
         for (String namespaceCode : namespaceCodes) {
 69  0
             String namespaceName = namespaceCode;
 70  0
             if (namespaceCodeToName.containsKey(namespaceCode)) { namespaceName = namespaceCodeToName.get(namespaceCode); }
 71  0
             keyValues.add(new ConcreteKeyValue(namespaceCode, namespaceName));
 72  0
         }
 73  
 
 74  0
         return keyValues;
 75  
     }
 76  
 }