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 java.util.ArrayList;
19 import java.util.Collections;
20 import java.util.List;
21
22 import org.apache.commons.lang.StringUtils;
23 import org.kuali.rice.kew.api.identity.Id;
24 import org.kuali.rice.kew.api.identity.PrincipalName;
25 import org.kuali.rice.kew.api.rule.RoleName;
26 import org.kuali.rice.kew.engine.RouteContext;
27 import org.kuali.rice.kew.workgroup.GroupNameId;
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 public class MockRole extends UnqualifiedRoleAttribute {
44 private static final RoleName ROLE = new RoleName(MockRole.class.getName(), "List of authentication ids", "List of authentication ids");
45 private static final List<RoleName> ROLES;
46 static {
47 ArrayList<RoleName> roles = new ArrayList<RoleName>(1);
48 roles.add(ROLE);
49 ROLES = Collections.unmodifiableList(roles);
50 }
51
52 public MockRole() {
53 super(ROLES);
54 }
55
56
57
58
59
60 @Override
61 protected boolean isValidRoleName(String roleName) {
62 return true;
63 }
64
65 @Override
66 protected ResolvedQualifiedRole resolveRole(RouteContext routeContext, String roleName) {
67 String[] ids = roleName.split("[,\\s+]");
68 ResolvedQualifiedRole rqr = new ResolvedQualifiedRole();
69 for (String id: ids) {
70 String type = "user";
71 String[] components = id.split(":", 2);
72 if (components.length > 1 && !StringUtils.isEmpty(components[0])) {
73 type = components[0].trim();
74 }
75 Id recipientId;
76 if ("user".equals(type)) {
77 recipientId = new PrincipalName(id);
78 } else if ("group".equals(type)) {
79 recipientId = new GroupNameId(id);
80 } else {
81 throw new RuntimeException("Unknown role recipient type: '" + type + "'. Must be 'user' or 'group'.");
82 }
83 rqr.getRecipients().add(recipientId);
84 }
85 rqr.setQualifiedRoleLabel("Recipients from parsing mock role: " + roleName);
86 rqr.setAnnotation("Recipients from parsing mock role: " + roleName);
87 return rqr;
88 }
89 }