Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
GenericRoleAttribute |
|
| 1.5;1.5 |
1 | /** | |
2 | * Copyright 2005-2011 The Kuali Foundation | |
3 | * | |
4 | * Licensed under the Educational Community License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.opensource.org/licenses/ecl2.php | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
16 | package org.kuali.rice.kew.rule; | |
17 | ||
18 | import java.util.ArrayList; | |
19 | import java.util.List; | |
20 | ||
21 | import org.kuali.rice.kew.api.identity.Id; | |
22 | import org.kuali.rice.kew.engine.RouteContext; | |
23 | import org.kuali.rice.kew.routeheader.DocumentContent; | |
24 | ||
25 | ||
26 | /** | |
27 | * Generic base class that implements common functionality to simplify implementing | |
28 | * a RoleAttribute. This includes a standard qualified role name String format and simplified | |
29 | * template methods, as well as a generic attribute content model. | |
30 | * | |
31 | * <p>Control flow:</p> | |
32 | * | |
33 | * <ol> | |
34 | * <li>{@link #getQualifiedRoleNames(String, DocumentContent)} | |
35 | * <ol> | |
36 | * <li>{@link #generateQualifiedRoleNames(String, DocumentContent)} | |
37 | * <ol> | |
38 | * <li>{@link #getRoleNameQualifiers(String, DocumentContent)}</li> | |
39 | * </ol> | |
40 | * </li> | |
41 | * </ol> | |
42 | * </li> | |
43 | * <li>{@link #resolveQualifiedRole(RouteContext, String, String)} | |
44 | * <ol> | |
45 | * <li>{@link #resolveQualifiedRole(RouteContext, QualifiedRoleName)} | |
46 | * <ol> | |
47 | * <li>{@link #resolveRecipients(RouteContext, QualifiedRoleName)}</li> | |
48 | * <li>{@link #getLabelForQualifiedRoleName(QualifiedRoleName)}</li> | |
49 | * </ol> | |
50 | * </li> | |
51 | * </ol> | |
52 | * </li> | |
53 | * </ol> | |
54 | * | |
55 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
56 | */ | |
57 | public abstract class GenericRoleAttribute extends GenericWorkflowAttribute implements RoleAttribute { | |
58 | public GenericRoleAttribute() { | |
59 | 0 | super(null); |
60 | 0 | } |
61 | ||
62 | public GenericRoleAttribute(String uniqueName) { | |
63 | 0 | super(uniqueName); |
64 | 0 | } |
65 | ||
66 | public boolean isMatch(DocumentContent docContent, List<RuleExtensionBo> ruleExtensions) { | |
67 | // FIXME: ok, this MUST return true, as it IS evaluated (don't know why) | |
68 | // maybe investigate only calling isMatch on rule attributes as it doesn't seem that | |
69 | // matching is relevant for role attributes...is it? | |
70 | // throw new UnsupportedOperationException("Role attributes do not implement isMatch"); | |
71 | 0 | return true; |
72 | } | |
73 | ||
74 | public List<String> getQualifiedRoleNames(String roleName, DocumentContent documentContent) { | |
75 | 0 | List<QualifiedRoleName> qualifiedRoleNames = generateQualifiedRoleNames(roleName, documentContent); |
76 | 0 | if (qualifiedRoleNames == null) { |
77 | 0 | return null; |
78 | } | |
79 | 0 | List<String> q = new ArrayList<String>(qualifiedRoleNames.size()); |
80 | 0 | for (QualifiedRoleName qrn: qualifiedRoleNames) { |
81 | 0 | q.add(qrn.encode()); |
82 | } | |
83 | 0 | return q; |
84 | } | |
85 | ||
86 | /** | |
87 | * Template method responsible for producing a list of QualifiedRoleName objects. Default implementation | |
88 | * calls {@link #getRoleNameQualifiers(String, DocumentContent)} | |
89 | */ | |
90 | protected List<QualifiedRoleName> generateQualifiedRoleNames(String roleName, DocumentContent documentContent) { | |
91 | 0 | List<String> qualifiers = getRoleNameQualifiers(roleName, documentContent); |
92 | 0 | if (qualifiers == null) { |
93 | 0 | qualifiers = new ArrayList<String>(0); |
94 | } | |
95 | 0 | List<QualifiedRoleName> qualifiedRoleNames = new ArrayList<QualifiedRoleName>(qualifiers.size()); |
96 | 0 | for (String qualifier: qualifiers) { |
97 | 0 | qualifiedRoleNames.add(new QualifiedRoleName(roleName, qualifier)); |
98 | } | |
99 | 0 | return qualifiedRoleNames; |
100 | } | |
101 | ||
102 | /** | |
103 | * Template method responsible for producing qualifiers for a role name | |
104 | */ | |
105 | protected List<String> getRoleNameQualifiers(String roleName, DocumentContent documentContent) { | |
106 | 0 | return null; |
107 | } | |
108 | ||
109 | public ResolvedQualifiedRole resolveQualifiedRole(RouteContext routeContext, String roleName, String qualifiedRoleName) { | |
110 | 0 | QualifiedRoleName qrn = QualifiedRoleName.parse(qualifiedRoleName); |
111 | 0 | return resolveQualifiedRole(routeContext, qrn); |
112 | } | |
113 | ||
114 | /** | |
115 | * Template method that delegates to {@link #resolveRecipients(RouteContext, QualifiedRoleName)} and | |
116 | * {@link #getLabelForQualifiedRoleName(QualifiedRoleName) | |
117 | */ | |
118 | protected ResolvedQualifiedRole resolveQualifiedRole(RouteContext routeContext, QualifiedRoleName qualifiedRoleName) { | |
119 | 0 | List<Id> recipients = resolveRecipients(routeContext, qualifiedRoleName); |
120 | 0 | ResolvedQualifiedRole rqr = new ResolvedQualifiedRole(getLabelForQualifiedRoleName(qualifiedRoleName), |
121 | recipients | |
122 | ); // default to no annotation... | |
123 | 0 | return rqr; |
124 | } | |
125 | ||
126 | protected String getLabelForQualifiedRoleName(QualifiedRoleName qualifiedRoleName) { | |
127 | // do what everybody else does and just use the base role name | |
128 | 0 | return qualifiedRoleName.getBaseRoleName(); |
129 | } | |
130 | ||
131 | /** | |
132 | * Template method for subclasses to implement | |
133 | */ | |
134 | protected List<Id> resolveRecipients(RouteContext routeContext, QualifiedRoleName qualifiedRoleName) { | |
135 | 0 | return null; |
136 | } | |
137 | } |