1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.ken.kew; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.Collections; |
20 | |
import java.util.List; |
21 | |
import java.util.Map; |
22 | |
|
23 | |
import javax.xml.xpath.XPathExpressionException; |
24 | |
|
25 | |
import org.apache.log4j.Logger; |
26 | |
import org.kuali.rice.kew.api.WorkflowRuntimeException; |
27 | |
import org.kuali.rice.kew.engine.RouteContext; |
28 | |
import org.kuali.rice.kew.identity.Id; |
29 | |
import org.kuali.rice.kew.routeheader.DocumentContent; |
30 | |
import org.kuali.rice.kew.rule.GenericRoleAttribute; |
31 | |
import org.kuali.rice.kew.rule.QualifiedRoleName; |
32 | |
import org.kuali.rice.kew.rule.Role; |
33 | |
import org.kuali.rice.kew.rule.RuleExtension; |
34 | |
import org.kuali.rice.kew.identity.PrincipalName; |
35 | |
import org.kuali.rice.kew.workgroup.GroupNameId; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
public class ChannelReviewerRoleAttribute extends GenericRoleAttribute { |
45 | 0 | private static final Logger LOG = Logger.getLogger(ChannelReviewerRoleAttribute.class); |
46 | |
private static final List<Role> SUPPORTED_ROLES; |
47 | |
|
48 | |
static { |
49 | 0 | Role reviewerRole = new Role(ChannelReviewerRoleAttribute.class, "reviewers", "Reviewers"); |
50 | 0 | List<Role> tmp = new ArrayList<Role>(1); |
51 | 0 | tmp.add(reviewerRole); |
52 | 0 | SUPPORTED_ROLES = Collections.unmodifiableList(tmp); |
53 | 0 | } |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
public ChannelReviewerRoleAttribute() { |
59 | 0 | super("channelReviewers"); |
60 | 0 | LOG.info("CHANNEL REVIEWER ROLE ATTRIBUTE CONSTRUCTOR"); |
61 | 0 | } |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
@Override |
67 | |
public boolean isMatch(DocumentContent docContent, List<RuleExtension> ruleExtensions) { |
68 | 0 | LOG.info("CHANNEL REVIEWER ROLE ATTRIBUTE IS MATCH"); |
69 | 0 | return super.isMatch(docContent, ruleExtensions); |
70 | |
} |
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
@Override |
76 | |
public Map<String, String> getProperties() { |
77 | 0 | LOG.info("CHANNEL REVIEWER ROLE ATTRIBUTE GETPROPERTIES"); |
78 | |
|
79 | 0 | return null; |
80 | |
} |
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
public List<Role> getRoleNames() { |
86 | 0 | LOG.info("CHANNEL REVIEWER ROLE ATTRIBUTE CALLED ROLENAMES"); |
87 | 0 | return SUPPORTED_ROLES; |
88 | |
} |
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
@Override |
94 | |
public List<String> getQualifiedRoleNames(String roleName, DocumentContent documentContent) { |
95 | 0 | List<String> qrn = new ArrayList<String>(1); |
96 | 0 | qrn.add(roleName); |
97 | 0 | return qrn; |
98 | |
} |
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
@Override |
106 | |
protected List<Id> resolveRecipients(RouteContext routeContext, QualifiedRoleName qualifiedRoleName) { |
107 | 0 | LOG.info("CHANNEL REVIEWER ROLE ATTRIBUTE CALLED"); |
108 | 0 | List<Id> ids = new ArrayList<Id>(); |
109 | |
|
110 | 0 | LOG.info("DOC CONTENT:" + routeContext.getDocumentContent().getDocContent()); |
111 | 0 | LOG.info("ATTR CONTENT:" + routeContext.getDocumentContent().getAttributeContent()); |
112 | 0 | DocumentContent dc = routeContext.getDocumentContent(); |
113 | |
List<Map<String, String>> attrs; |
114 | |
try { |
115 | 0 | attrs = content.parseContent(dc.getAttributeContent()); |
116 | 0 | } catch (XPathExpressionException xpee) { |
117 | 0 | throw new WorkflowRuntimeException("Error parsing ChannelReviewer role attribute content", xpee); |
118 | 0 | } |
119 | |
|
120 | 0 | if (attrs.size() > 0) { |
121 | 0 | Map<String, String> values = attrs.get(0); |
122 | 0 | if (values != null) { |
123 | |
|
124 | 0 | for (Map.Entry<String, String> entry: values.entrySet()) { |
125 | 0 | String name = entry.getKey(); |
126 | 0 | String value = entry.getValue(); |
127 | 0 | LOG.info("Entry: " + name + "=" + value); |
128 | |
Id id; |
129 | 0 | if (name.startsWith("user")) { |
130 | 0 | LOG.info("Adding user: " + value); |
131 | 0 | id = new PrincipalName(value); |
132 | 0 | ids.add(id); |
133 | 0 | } else if (name.startsWith("group")) { |
134 | 0 | LOG.info("Adding group: " + value); |
135 | 0 | id = new GroupNameId(value); |
136 | 0 | ids.add(id); |
137 | |
} else { |
138 | 0 | LOG.error("Invalid attribute value: " + name + "=" + value); |
139 | |
} |
140 | 0 | } |
141 | |
} |
142 | 0 | } else { |
143 | 0 | LOG.debug("No attribute content found for ChannelReviewerRoleAttribute"); |
144 | |
} |
145 | |
|
146 | 0 | LOG.info("Returning ids: " + ids.size()); |
147 | 0 | return ids; |
148 | |
} |
149 | |
} |