1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
35
36
37
38
39 public class RuleMaintenanceActionRequestCodeValuesFinder extends ActionRequestCodeValuesFinder {
40
41
42
43
44 @Override
45 public List<KeyValue> getKeyValues() {
46 final List<KeyValue> actionRequestCodes = new ArrayList<KeyValue>();
47
48 final KualiForm kForm = KNSGlobalVariables.getKualiForm();
49 if (!(kForm instanceof KualiMaintenanceForm)) {
50 return super.getKeyValues();
51 }
52
53 final MaintenanceDocument maintDoc = (MaintenanceDocument) ((KualiMaintenanceForm) kForm).getDocument();
54 final RuleTemplate ruleTemplate = ((RuleBaseValues) maintDoc.getNewMaintainableObject().getBusinessObject()).getRuleTemplate();
55
56 if (ruleTemplate == null) {
57 throw new RuntimeException("Rule template cannot be null for document ID " + maintDoc.getDocumentNumber());
58 }
59
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
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 }