View Javadoc

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