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