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