Coverage Report - org.kuali.rice.kew.rule.bo.RoleNameValuesFinder
 
Classes in this File Line Coverage Branch Coverage Complexity
RoleNameValuesFinder
0%
0/17
0%
0/10
7
 
 1  
 /*
 2  
  * Copyright 2007-2009 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.kew.rule.bo;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.List;
 20  
 
 21  
 import org.kuali.rice.core.api.exception.RiceRuntimeException;
 22  
 import org.kuali.rice.core.util.ConcreteKeyValue;
 23  
 import org.kuali.rice.core.util.KeyValue;
 24  
 import org.kuali.rice.kew.rule.Role;
 25  
 import org.kuali.rice.kew.rule.RuleBaseValues;
 26  
 import org.kuali.rice.kew.rule.RuleDelegation;
 27  
 import org.kuali.rice.kns.util.KNSGlobalVariables;
 28  
 import org.kuali.rice.kns.web.struts.form.KualiMaintenanceForm;
 29  
 import org.kuali.rice.krad.bo.PersistableBusinessObject;
 30  
 import org.kuali.rice.kns.document.MaintenanceDocument;
 31  
 import org.kuali.rice.krad.keyvalues.KeyValuesBase;
 32  
 import org.kuali.rice.krad.util.GlobalVariables;
 33  
 
 34  
 /**
 35  
  * A values finder for generating a list of Role names that can be selected for a given RuleTemplate.
 36  
  * 
 37  
  * This is dependant on the template selected on the maintenance document so it needs to use
 38  
  * GlobalVariables to get a reference to the KualiForm so it can examine the business object
 39  
  * and extract the role names from the RuleTemplate.
 40  
  * 
 41  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 42  
  */
 43  0
 public class RoleNameValuesFinder extends KeyValuesBase {
 44  
         
 45  
         @Override
 46  
         public List<KeyValue> getKeyValues() {
 47  0
                 List<KeyValue> roleNames = new ArrayList<KeyValue>();
 48  0
                 if (KNSGlobalVariables.getKualiForm() != null && KNSGlobalVariables.getKualiForm() instanceof KualiMaintenanceForm) {
 49  0
                         KualiMaintenanceForm form = (KualiMaintenanceForm)KNSGlobalVariables.getKualiForm();
 50  0
                         MaintenanceDocument document = (MaintenanceDocument)form.getDocument();
 51  0
                         PersistableBusinessObject businessObject = document.getNewMaintainableObject().getBusinessObject();
 52  0
                         RuleBaseValues rule = null;
 53  0
                         if (businessObject instanceof RuleBaseValues) {
 54  0
                                 rule = (RuleBaseValues)businessObject;
 55  0
                         } else if (businessObject instanceof RuleDelegation) {
 56  0
                                 rule = ((RuleDelegation)businessObject).getDelegationRuleBaseValues();
 57  
                         } else {
 58  0
                                 throw new RiceRuntimeException("Cannot locate RuleBaseValues business object on maintenance document.  Business Object was " + businessObject);
 59  
                         }
 60  0
                         RuleTemplate ruleTemplate = rule.getRuleTemplate();
 61  0
                         List<Role> roles = ruleTemplate.getRoles();
 62  0
                         for (Role role : roles) {
 63  0
                                 roleNames.add(new ConcreteKeyValue(role.getName(), role.getLabel()));
 64  
                         }
 65  
                 }
 66  0
                 return roleNames;
 67  
         }
 68  
 
 69  
 }