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.Iterator;
021: import java.util.List;
022:
023: import org.kuali.rice.definition.ObjectDefinition;
024: import org.kuali.rice.resourceloader.GlobalResourceLoader;
025:
026: import edu.iu.uis.eden.EdenConstants;
027: import edu.iu.uis.eden.KEWServiceLocator;
028: import edu.iu.uis.eden.WorkflowPersistable;
029: import edu.iu.uis.eden.actionrequests.ActionRequestValue;
030: import edu.iu.uis.eden.exception.EdenUserNotFoundException;
031: import edu.iu.uis.eden.exception.WorkflowException;
032: import edu.iu.uis.eden.plugin.attributes.RoleAttribute;
033: import edu.iu.uis.eden.user.UserService;
034: import edu.iu.uis.eden.user.WorkflowUser;
035: import edu.iu.uis.eden.user.WorkflowUserId;
036: import edu.iu.uis.eden.util.Utilities;
037: import edu.iu.uis.eden.workgroup.WorkflowGroupId;
038: import edu.iu.uis.eden.workgroup.Workgroup;
039: import edu.iu.uis.eden.workgroup.WorkgroupService;
040:
041: /**
042: * A model bean representing the responsibility of a user, workgroup, or role
043: * to perform some action on a document. Used by the rule system to
044: * identify the appropriate responsibile parties to generate
045: * {@link ActionRequestValue}s to.
046: *
047: * @author rkirkend
048: * @author jhopf
049: * @author ewestfal
050: */
051: public class RuleResponsibility implements WorkflowPersistable {
052:
053: private static final long serialVersionUID = -1565688857123316797L;
054: private Long ruleResponsibilityKey;
055: private Long responsibilityId;
056: private Long ruleBaseValuesId;
057: private String actionRequestedCd;
058: private String ruleResponsibilityName;
059: private String ruleResponsibilityType;
060: private Integer lockVerNbr;
061: private Integer priority;
062: private String approvePolicy;
063:
064: private RuleBaseValues ruleBaseValues;
065: private List delegationRules = new ArrayList();
066:
067: public WorkflowUser getWorkflowUser()
068: throws EdenUserNotFoundException {
069: if (isUsingWorkflowUser()) {
070: return ((UserService) KEWServiceLocator
071: .getService(KEWServiceLocator.USER_SERVICE))
072: .getWorkflowUser(new WorkflowUserId(
073: ruleResponsibilityName));
074: }
075: return null;
076: }
077:
078: public Workgroup getWorkgroup() throws EdenUserNotFoundException {
079: if (isUsingWorkgroup()) {
080: return ((WorkgroupService) KEWServiceLocator
081: .getService(KEWServiceLocator.WORKGROUP_SRV))
082: .getWorkgroup(new WorkflowGroupId(new Long(
083: ruleResponsibilityName)));
084: }
085: return null;
086: }
087:
088: public String getRole() {
089: if (isUsingRole()) {
090: return ruleResponsibilityName;
091: }
092: return null;
093: }
094:
095: public String getResolvedRoleName() {
096: if (isUsingRole()) {
097: return getRole().substring(getRole().indexOf("!") + 1,
098: getRole().length());
099: }
100: return null;
101: }
102:
103: public RoleAttribute resolveRoleAttribute()
104: throws WorkflowException {
105: if (isUsingRole()) {
106: String attributeName = getRole().substring(0,
107: getRole().indexOf("!"));
108: return (RoleAttribute) GlobalResourceLoader
109: .getResourceLoader().getObject(
110: new ObjectDefinition(attributeName));
111: }
112: return null;
113: }
114:
115: public boolean isUsingRole() {
116: return (ruleResponsibilityName != null
117: && ruleResponsibilityType != null && ruleResponsibilityType
118: .equals(EdenConstants.RULE_RESPONSIBILITY_ROLE_ID));
119: }
120:
121: public boolean isUsingWorkflowUser() {
122: return (ruleResponsibilityName != null
123: && !ruleResponsibilityName.trim().equals("")
124: && ruleResponsibilityType != null && ruleResponsibilityType
125: .equals(EdenConstants.RULE_RESPONSIBILITY_WORKFLOW_ID));
126: }
127:
128: public boolean isUsingWorkgroup() {
129: return (ruleResponsibilityName != null
130: && !ruleResponsibilityName.trim().equals("")
131: && ruleResponsibilityType != null && ruleResponsibilityType
132: .equals(EdenConstants.RULE_RESPONSIBILITY_WORKGROUP_ID));
133: }
134:
135: public Long getRuleBaseValuesId() {
136: return ruleBaseValuesId;
137: }
138:
139: public void setRuleBaseValuesId(Long ruleBaseValuesId) {
140: this .ruleBaseValuesId = ruleBaseValuesId;
141: }
142:
143: public RuleBaseValues getRuleBaseValues() {
144: return ruleBaseValues;
145: }
146:
147: public void setRuleBaseValues(RuleBaseValues ruleBaseValues) {
148: this .ruleBaseValues = ruleBaseValues;
149: }
150:
151: public String getActionRequestedCd() {
152: return actionRequestedCd;
153: }
154:
155: public void setActionRequestedCd(String actionRequestedCd) {
156: this .actionRequestedCd = actionRequestedCd;
157: }
158:
159: public Integer getLockVerNbr() {
160: return lockVerNbr;
161: }
162:
163: public void setLockVerNbr(Integer lockVerNbr) {
164: this .lockVerNbr = lockVerNbr;
165: }
166:
167: public Long getRuleResponsibilityKey() {
168: return ruleResponsibilityKey;
169: }
170:
171: public void setRuleResponsibilityKey(Long ruleResponsibilityId) {
172: this .ruleResponsibilityKey = ruleResponsibilityId;
173: }
174:
175: public Integer getPriority() {
176: return priority;
177: }
178:
179: public void setPriority(Integer priority) {
180: this .priority = priority;
181: }
182:
183: public String getApprovePolicy() {
184: return approvePolicy;
185: }
186:
187: public void setApprovePolicy(String approvePolicy) {
188: this .approvePolicy = approvePolicy;
189: }
190:
191: public Object copy(boolean preserveKeys) {
192: RuleResponsibility ruleResponsibilityClone = new RuleResponsibility();
193: ruleResponsibilityClone.setApprovePolicy(getApprovePolicy());
194: if (actionRequestedCd != null) {
195: ruleResponsibilityClone.setActionRequestedCd(new String(
196: actionRequestedCd));
197: }
198: if (ruleResponsibilityKey != null && preserveKeys) {
199: ruleResponsibilityClone.setRuleResponsibilityKey(new Long(
200: ruleResponsibilityKey.longValue()));
201: }
202:
203: if (responsibilityId != null) {
204: ruleResponsibilityClone.setResponsibilityId(new Long(
205: responsibilityId.longValue()));
206: }
207:
208: if (ruleResponsibilityName != null) {
209: ruleResponsibilityClone
210: .setRuleResponsibilityName(new String(
211: ruleResponsibilityName));
212: }
213: if (ruleResponsibilityType != null) {
214: ruleResponsibilityClone
215: .setRuleResponsibilityType(new String(
216: ruleResponsibilityType));
217: }
218: if (priority != null) {
219: ruleResponsibilityClone.setPriority(new Integer(priority
220: .intValue()));
221: }
222: if (delegationRules != null) {
223: for (Iterator iter = delegationRules.iterator(); iter
224: .hasNext();) {
225: RuleDelegation delegation = (RuleDelegation) iter
226: .next();
227: RuleDelegation delegationClone = (RuleDelegation) delegation
228: .copy(preserveKeys);
229: delegationClone
230: .setRuleResponsibility(ruleResponsibilityClone);
231: ruleResponsibilityClone.getDelegationRules().add(
232: delegationClone);
233:
234: }
235: }
236: return ruleResponsibilityClone;
237: }
238:
239: public String getRuleResponsibilityName() {
240: return ruleResponsibilityName;
241: }
242:
243: public void setRuleResponsibilityName(String ruleResponsibilityName) {
244: this .ruleResponsibilityName = ruleResponsibilityName;
245: }
246:
247: public String getRuleResponsibilityType() {
248: return ruleResponsibilityType;
249: }
250:
251: public void setRuleResponsibilityType(String ruleResponsibilityType) {
252: this .ruleResponsibilityType = ruleResponsibilityType;
253: }
254:
255: public Long getResponsibilityId() {
256: return responsibilityId;
257: }
258:
259: public void setResponsibilityId(Long responsibilityId) {
260: this .responsibilityId = responsibilityId;
261: }
262:
263: public boolean isDelegating() {
264: return !getDelegationRules().isEmpty();
265: }
266:
267: public List getDelegationRules() {
268: return delegationRules;
269: }
270:
271: public void setDelegationRules(List delegationRules) {
272: this .delegationRules = delegationRules;
273: }
274:
275: public RuleDelegation getDelegationRule(int index) {
276: while (getDelegationRules().size() <= index) {
277: RuleDelegation ruleDelegation = new RuleDelegation();
278: ruleDelegation.setRuleResponsibility(this );
279: ruleDelegation
280: .setDelegationRuleBaseValues(new RuleBaseValues());
281: getDelegationRules().add(ruleDelegation);
282: }
283: return (RuleDelegation) getDelegationRules().get(index);
284: }
285:
286: public boolean equals(Object o) {
287: if (o == null)
288: return false;
289: if (!(o instanceof RuleResponsibility))
290: return false;
291: RuleResponsibility pred = (RuleResponsibility) o;
292: return Utilities.equals(ruleResponsibilityName, pred
293: .getRuleResponsibilityName())
294: && Utilities.equals(actionRequestedCd, pred
295: .getActionRequestedCd())
296: && Utilities.equals(priority, pred.getPriority())
297: && Utilities.equals(approvePolicy, pred
298: .getApprovePolicy());
299: }
300:
301: public String toString() {
302: return "[RuleResponsibility:" + " responsibilityId="
303: + responsibilityId + ", ruleResponsibilityKey="
304: + ruleResponsibilityKey + ", ruleResponsibilityName="
305: + ruleResponsibilityName + ", ruleResponsibilityType="
306: + ruleResponsibilityType + ", ruleBaseValuesId="
307: + ruleBaseValuesId + ", actionRequestedCd="
308: + actionRequestedCd + ", priority=" + priority
309: + ", approvePolicy=" + approvePolicy + ", lockVerNbr="
310: + lockVerNbr + "]";
311: }
312: }
|