View Javadoc

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