1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.rule;
17
18 import org.kuali.rice.kew.api.extension.ExtensionDefinition;
19 import org.kuali.rice.kew.api.rule.RoleName;
20 import org.kuali.rice.kew.api.rule.RuleTemplateAttribute;
21 import org.kuali.rice.kew.framework.KewFrameworkServiceLocator;
22 import org.kuali.rice.kew.framework.rule.attribute.WorkflowRuleAttributeFields;
23 import org.kuali.rice.kew.framework.rule.attribute.WorkflowRuleAttributeHandlerService;
24 import org.kuali.rice.kew.rule.bo.RuleAttribute;
25 import org.kuali.rice.kew.rule.bo.RuleTemplateAttributeBo;
26
27 import java.util.Collections;
28 import java.util.List;
29 import java.util.Map;
30
31
32
33
34
35
36 public class WorkflowRuleAttributeMediatorImpl implements WorkflowRuleAttributeMediator {
37
38 @Override
39 public WorkflowRuleAttributeRows getRuleRows(Map<String, String> parameters, RuleTemplateAttributeBo ruleTemplateAttribute) {
40 required(ruleTemplateAttribute, "ruleTemplateAttribute");
41 if (parameters == null) {
42 parameters = Collections.emptyMap();
43 }
44 RuleAttribute ruleAttribute = ruleTemplateAttribute.getRuleAttribute();
45 ExtensionDefinition extensionDefinition = RuleAttribute.to(ruleAttribute);
46 WorkflowRuleAttributeHandlerService handler = getHandler(extensionDefinition);
47 WorkflowRuleAttributeFields fields = handler.getRuleFields(parameters, extensionDefinition, ruleTemplateAttribute.isRequired());
48 return new WorkflowRuleAttributeRows(fields);
49 }
50
51 @Override
52 public WorkflowRuleAttributeRows getRuleRows(Map<String, String> parameters, RuleTemplateAttribute ruleTemplateAttribute) {
53 required(ruleTemplateAttribute, "ruleTemplateAttribute");
54 if (parameters == null) {
55 parameters = Collections.emptyMap();
56 }
57 ExtensionDefinition extensionDefinition = ruleTemplateAttribute.getRuleAttribute();
58 WorkflowRuleAttributeHandlerService handler = getHandler(extensionDefinition);
59 WorkflowRuleAttributeFields fields = handler.getRuleFields(parameters, extensionDefinition, ruleTemplateAttribute.isRequired());
60 return new WorkflowRuleAttributeRows(fields);
61 }
62
63 @Override
64 public WorkflowRuleAttributeRows getRoutingDataRows(Map<String, String> parameters, RuleTemplateAttributeBo ruleTemplateAttribute) {
65 required(ruleTemplateAttribute, "ruleTemplateAttribute");
66 if (parameters == null) {
67 parameters = Collections.emptyMap();
68 }
69 RuleAttribute ruleAttribute = ruleTemplateAttribute.getRuleAttribute();
70 ExtensionDefinition extensionDefinition = RuleAttribute.to(ruleAttribute);
71 WorkflowRuleAttributeHandlerService handler = getHandler(extensionDefinition);
72 WorkflowRuleAttributeFields fields = handler.getRoutingDataFields(parameters, extensionDefinition, ruleTemplateAttribute.isRequired());
73 return new WorkflowRuleAttributeRows(fields);
74 }
75
76 @Override
77 public WorkflowRuleAttributeRows getRoutingDataRows(Map<String, String> parameters, RuleTemplateAttribute ruleTemplateAttribute) {
78 required(ruleTemplateAttribute, "ruleTemplateAttribute");
79 if (parameters == null) {
80 parameters = Collections.emptyMap();
81 }
82 ExtensionDefinition extensionDefinition = ruleTemplateAttribute.getRuleAttribute();
83 WorkflowRuleAttributeHandlerService handler = getHandler(extensionDefinition);
84 WorkflowRuleAttributeFields fields = handler.getRoutingDataFields(parameters, extensionDefinition, ruleTemplateAttribute.isRequired());
85 return new WorkflowRuleAttributeRows(fields);
86 }
87
88 @Override
89 public WorkflowRuleAttributeRows getSearchRows(Map<String, String> parameters, RuleTemplateAttribute ruleTemplateAttribute) {
90 required(ruleTemplateAttribute, "ruleTemplateAttribute");
91 if (parameters == null) {
92 parameters = Collections.emptyMap();
93 }
94 ExtensionDefinition extensionDefinition = ruleTemplateAttribute.getRuleAttribute();
95 WorkflowRuleAttributeHandlerService handler = getHandler(extensionDefinition);
96 WorkflowRuleAttributeFields fields = handler.getSearchFields(parameters, extensionDefinition, ruleTemplateAttribute.isRequired());
97 return new WorkflowRuleAttributeRows(fields);
98
99 }
100
101 @Override
102 public WorkflowRuleAttributeRows getSearchRows(Map<String, String> parameters, RuleTemplateAttribute ruleTemplateAttribute, boolean required) {
103 required(ruleTemplateAttribute, "ruleTemplateAttribute");
104 if (parameters == null) {
105 parameters = Collections.emptyMap();
106 }
107 ExtensionDefinition extensionDefinition = ruleTemplateAttribute.getRuleAttribute();
108 WorkflowRuleAttributeHandlerService handler = getHandler(extensionDefinition);
109 WorkflowRuleAttributeFields fields = handler.getSearchFields(parameters, extensionDefinition, required);
110 return new WorkflowRuleAttributeRows(fields);
111
112 }
113
114 @Override
115 public List<RoleName> getRoleNames(RuleTemplateAttributeBo ruleTemplateAttribute) {
116 required(ruleTemplateAttribute, "ruleTemplateAttribute");
117 RuleAttribute ruleAttribute = ruleTemplateAttribute.getRuleAttribute();
118 ExtensionDefinition extensionDefinition = RuleAttribute.to(ruleAttribute);
119 WorkflowRuleAttributeHandlerService handler = getHandler(extensionDefinition);
120 return handler.getRoleNames(extensionDefinition);
121 }
122
123 private void required(Object object, String name) {
124 if (object == null) {
125 throw new IllegalArgumentException(name + " must not be null");
126 }
127 }
128
129
130
131
132
133
134
135
136
137
138
139 protected WorkflowRuleAttributeHandlerService getHandler(ExtensionDefinition extensionDefinition) {
140 WorkflowRuleAttributeHandlerService handler =
141 KewFrameworkServiceLocator.getWorkflowRuleAttributeHandlerService(extensionDefinition.getApplicationId());
142 if (handler == null) {
143 throw new IllegalStateException("Failed to locate a WorkflowRuleAttributeHandlerService for the given ExtensionDefinition: " + extensionDefinition);
144 }
145 return handler;
146 }
147
148
149 }