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