001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.routetemplate;
018:
019: import java.util.ArrayList;
020: import java.util.List;
021:
022: import edu.iu.uis.eden.Id;
023: import edu.iu.uis.eden.engine.RouteContext;
024: import edu.iu.uis.eden.exception.EdenUserNotFoundException;
025: import edu.iu.uis.eden.plugin.attributes.RoleAttribute;
026: import edu.iu.uis.eden.routeheader.DocumentContent;
027:
028: /**
029: * Generic base class that implements common functionality to simplify implementing
030: * a RoleAttribute. This includes a standard qualified role name String format and simplified
031: * template methods, as well as a generic attribute content model.
032: *
033: * <p>Control flow:</p>
034: *
035: * <ol>
036: * <li>{@link #getQualifiedRoleNames(String, DocumentContent)}
037: * <ol>
038: * <li>{@link #generateQualifiedRoleNames(String, DocumentContent)}
039: * <ol>
040: * <li>{@link #getRoleNameQualifiers(String, DocumentContent)}</li>
041: * </ol>
042: * </li>
043: * </ol>
044: * </li>
045: * <li>{@link #resolveQualifiedRole(RouteContext, String, String)}
046: * <ol>
047: * <li>{@link #resolveQualifiedRole(RouteContext, QualifiedRoleName)}
048: * <ol>
049: * <li>{@link #resolveRecipients(RouteContext, QualifiedRoleName)}</li>
050: * <li>{@link #getLabelForQualifiedRoleName(QualifiedRoleName)}</li>
051: * </ol>
052: * </li>
053: * </ol>
054: * </li>
055: * </ol>
056: *
057: * @author Aaron Hamid (arh14 at cornell dot edu)
058: */
059: public abstract class GenericRoleAttribute extends
060: GenericWorkflowAttribute implements RoleAttribute {
061: public GenericRoleAttribute() {
062: super (null);
063: }
064:
065: public GenericRoleAttribute(String uniqueName) {
066: super (uniqueName);
067: }
068:
069: public boolean isMatch(DocumentContent docContent,
070: List<RuleExtension> ruleExtensions) {
071: // FIXME: ok, this MUST return true, as it IS evaluated (don't know why)
072: // maybe investigate only calling isMatch on rule attributes as it doesn't seem that
073: // matching is relevant for role attributes...is it?
074: // throw new UnsupportedOperationException("Role attributes do not implement isMatch");
075: return true;
076: }
077:
078: public List<String> getQualifiedRoleNames(String roleName,
079: DocumentContent documentContent)
080: throws EdenUserNotFoundException {
081: List<QualifiedRoleName> qualifiedRoleNames = generateQualifiedRoleNames(
082: roleName, documentContent);
083: if (qualifiedRoleNames == null) {
084: return null;
085: }
086: List<String> q = new ArrayList<String>(qualifiedRoleNames
087: .size());
088: for (QualifiedRoleName qrn : qualifiedRoleNames) {
089: q.add(qrn.encode());
090: }
091: return q;
092: }
093:
094: /**
095: * Template method responsible for producing a list of QualifiedRoleName objects. Default implementation
096: * calls {@link #getRoleNameQualifiers(String, DocumentContent)}
097: */
098: protected List<QualifiedRoleName> generateQualifiedRoleNames(
099: String roleName, DocumentContent documentContent)
100: throws EdenUserNotFoundException {
101: List<String> qualifiers = getRoleNameQualifiers(roleName,
102: documentContent);
103: if (qualifiers == null) {
104: qualifiers = new ArrayList<String>(0);
105: }
106: List<QualifiedRoleName> qualifiedRoleNames = new ArrayList<QualifiedRoleName>(
107: qualifiers.size());
108: for (String qualifier : qualifiers) {
109: qualifiedRoleNames.add(new QualifiedRoleName(roleName,
110: qualifier));
111: }
112: return qualifiedRoleNames;
113: }
114:
115: /**
116: * Template method responsible for producing qualifiers for a role name
117: */
118: protected List<String> getRoleNameQualifiers(String roleName,
119: DocumentContent documentContent)
120: throws EdenUserNotFoundException {
121: return null;
122: }
123:
124: public ResolvedQualifiedRole resolveQualifiedRole(
125: RouteContext routeContext, String roleName,
126: String qualifiedRoleName) throws EdenUserNotFoundException {
127: QualifiedRoleName qrn = QualifiedRoleName
128: .parse(qualifiedRoleName);
129: return resolveQualifiedRole(routeContext, qrn);
130: }
131:
132: /**
133: * Template method that delegates to {@link #resolveRecipients(RouteContext, QualifiedRoleName)} and
134: * {@link #getLabelForQualifiedRoleName(QualifiedRoleName)
135: */
136: protected ResolvedQualifiedRole resolveQualifiedRole(
137: RouteContext routeContext,
138: QualifiedRoleName qualifiedRoleName)
139: throws EdenUserNotFoundException {
140: List<Id> recipients = resolveRecipients(routeContext,
141: qualifiedRoleName);
142: ResolvedQualifiedRole rqr = new ResolvedQualifiedRole(
143: getLabelForQualifiedRoleName(qualifiedRoleName),
144: recipients); // default to no annotation...
145: return rqr;
146: }
147:
148: protected String getLabelForQualifiedRoleName(
149: QualifiedRoleName qualifiedRoleName) {
150: // do what everybody else does and just use the base role name
151: return qualifiedRoleName.getBaseRoleName();
152: }
153:
154: /**
155: * Template method for subclasses to implement
156: */
157: protected List<Id> resolveRecipients(RouteContext routeContext,
158: QualifiedRoleName qualifiedRoleName)
159: throws EdenUserNotFoundException {
160: return null;
161: }
162: }
|