Coverage Report - org.kuali.rice.kew.actionrequest.bo.RuleMaintenanceActionRequestCodeValuesFinder
 
Classes in this File Line Coverage Branch Coverage Complexity
RuleMaintenanceActionRequestCodeValuesFinder
0%
0/15
0%
0/12
9
 
 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.actionrequest.bo;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.List;
 20  
 
 21  
 import org.kuali.rice.core.util.KeyLabelPair;
 22  
 import org.kuali.rice.kew.rule.RuleBaseValues;
 23  
 import org.kuali.rice.kew.rule.RuleTemplateOption;
 24  
 import org.kuali.rice.kew.rule.bo.RuleTemplate;
 25  
 import org.kuali.rice.kew.util.KEWConstants;
 26  
 import org.kuali.rice.kns.document.MaintenanceDocument;
 27  
 import org.kuali.rice.kns.util.GlobalVariables;
 28  
 import org.kuali.rice.kns.web.struts.form.KualiForm;
 29  
 import org.kuali.rice.kns.web.struts.form.KualiMaintenanceForm;
 30  
 
 31  
 /**
 32  
  * A values finder for returning KEW Action Request codes related to Kuali maintenance forms.
 33  
  * 
 34  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 35  
  *
 36  
  */
 37  0
 public class RuleMaintenanceActionRequestCodeValuesFinder extends ActionRequestCodeValuesFinder {
 38  
 
 39  
         /**
 40  
          * @see org.kuali.rice.kns.lookup.keyvalues.KeyValuesFinder#getKeyValues()
 41  
          */
 42  
         public List<KeyLabelPair> getKeyValues() {
 43  0
                 final List<KeyLabelPair> actionRequestCodes = new ArrayList<KeyLabelPair>();
 44  
                 // Acquire the Kuali form, and return the super class' result if the form is not a Kuali maintenance form.
 45  0
                 final KualiForm kForm = GlobalVariables.getKualiForm();
 46  0
                 if (!(kForm instanceof KualiMaintenanceForm)) {
 47  0
                         return super.getKeyValues();
 48  
                 }
 49  
                 // Acquire the Kuali maintenance form's document and its rule template.
 50  0
                 final MaintenanceDocument maintDoc = (MaintenanceDocument) ((KualiMaintenanceForm) kForm).getDocument();
 51  0
                 final RuleTemplate ruleTemplate = ((RuleBaseValues) maintDoc.getNewMaintainableObject().getBusinessObject()).getRuleTemplate();
 52  
                 // Ensure that the rule template is defined.
 53  0
                 if (ruleTemplate == null) {
 54  0
                         throw new RuntimeException("Rule template cannot be null for document ID " + maintDoc.getDocumentNumber());
 55  
                 }
 56  
                 // get the options to check for, as well as their related KEW constants.
 57  0
                 final RuleTemplateOption[] ruleOpts = {ruleTemplate.getAcknowledge(), ruleTemplate.getComplete(),
 58  
                                 ruleTemplate.getApprove(), ruleTemplate.getFyi()};
 59  0
                 final String[] ruleConsts = {KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, KEWConstants.ACTION_REQUEST_COMPLETE_REQ,
 60  
                                 KEWConstants.ACTION_REQUEST_APPROVE_REQ, KEWConstants.ACTION_REQUEST_FYI_REQ};
 61  
                 // Add the rule options to the list if they are not defined (true by default) or if they are explicitly set to true.
 62  0
                 for (int i = 0; i < ruleOpts.length; i++) {
 63  0
                         if (ruleOpts[i] == null || ruleOpts[i].getValue() == null || "true".equals(ruleOpts[i].getValue())) {
 64  0
                                 actionRequestCodes.add(new KeyLabelPair(ruleConsts[i], KEWConstants.ACTION_REQUEST_CODES.get(ruleConsts[i])));
 65  
                         }
 66  
                 }
 67  0
                 return actionRequestCodes;
 68  
         }
 69  
         
 70  
 }