Coverage Report - org.kuali.rice.krms.impl.repository.AgendaTypeValuesFinder
 
Classes in this File Line Coverage Branch Coverage Complexity
AgendaTypeValuesFinder
0%
0/16
0%
0/8
2.333
 
 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.cxf.common.util.StringUtils;
 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.rice.krad.service.KRADServiceLocator;
 23  
 import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
 24  
 import org.kuali.rice.krad.uif.view.ViewModel;
 25  
 import org.kuali.rice.krad.web.form.MaintenanceForm;
 26  
 import org.kuali.rice.krad.web.form.UifFormBase;
 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.List;
 33  
 import java.util.Map;
 34  
 
 35  
 /**
 36  
  * Helper class that returns all agenda types that are valid for a given context.
 37  
  */
 38  0
 public class AgendaTypeValuesFinder extends UifKeyValuesFinderBase {
 39  
 
 40  
     private boolean blankOption;
 41  
 
 42  
     /**
 43  
      * @return the blankOption
 44  
      */
 45  
     public boolean isBlankOption() {
 46  0
         return this.blankOption;
 47  
     }
 48  
 
 49  
     /**
 50  
      * @param blankOption the blankOption to set
 51  
      */
 52  
     public void setBlankOption(boolean blankOption) {
 53  0
         this.blankOption = blankOption;
 54  0
     }
 55  
 
 56  
     @Override
 57  
     public List<KeyValue> getKeyValues(ViewModel model) {
 58  0
         List<KeyValue> keyValues = new ArrayList<KeyValue>();
 59  
 
 60  0
         MaintenanceForm maintenanceForm = (MaintenanceForm) model;
 61  0
         AgendaEditor agendaEditor = ((AgendaEditor) maintenanceForm.getDocument().getNewMaintainableObject().getDataObject());
 62  
 
 63  
         // if we have an agenda w/ a selected context
 64  0
         if (agendaEditor.getAgenda() != null && !StringUtils.isEmpty(agendaEditor.getAgenda().getContextId())) {
 65  
 
 66  
             // key off the contextId
 67  
 
 68  0
             String contextId = agendaEditor.getAgenda().getContextId();
 69  
 
 70  0
             if(blankOption){
 71  0
                 keyValues.add(new ConcreteKeyValue("", ""));
 72  
             }
 73  
 
 74  0
             Map<String, String> criteria = Collections.singletonMap("contextId", contextId);
 75  0
             Collection<ContextValidAgendaBo> contextValidAgendas =
 76  
                     KRADServiceLocator.getBusinessObjectService().findMatchingOrderBy(
 77  
                             ContextValidAgendaBo.class, criteria, "agendaType.name", true
 78  
                     );
 79  
 
 80  0
             for (ContextValidAgendaBo contextValidAgenda : contextValidAgendas) {
 81  0
                 keyValues.add(new ConcreteKeyValue(contextValidAgenda.getAgendaType().getId(), contextValidAgenda.getAgendaType().getName()));
 82  
             }
 83  
         }
 84  
 
 85  0
         return keyValues;
 86  
     }
 87  
 }