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.actions;
018:
019: import java.util.ArrayList;
020: import java.util.Collection;
021: import java.util.Iterator;
022: import java.util.List;
023:
024: import edu.iu.uis.eden.EdenConstants;
025: import edu.iu.uis.eden.KEWServiceLocator;
026: import edu.iu.uis.eden.actionitem.ActionItem;
027: import edu.iu.uis.eden.actionlist.ActionListService;
028: import edu.iu.uis.eden.actionrequests.ActionRequestValue;
029: import edu.iu.uis.eden.exception.EdenUserNotFoundException;
030: import edu.iu.uis.eden.exception.InvalidActionTakenException;
031: import edu.iu.uis.eden.routeheader.DocumentRouteHeaderValue;
032: import edu.iu.uis.eden.user.WorkflowUser;
033: import edu.iu.uis.eden.util.Utilities;
034: import edu.iu.uis.eden.workgroup.Workgroup;
035:
036: /**
037: * Removes all workgroup action items for a document from everyone's action list except the person
038: * who took the workgroup authority
039: *
040: * @author rkirkend
041: *
042: */
043: public class TakeWorkgroupAuthority extends ActionTakenEvent {
044: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
045: .getLogger(TakeWorkgroupAuthority.class);
046:
047: private Workgroup workgroup;
048:
049: /**
050: * @param routeHeader
051: * @param user
052: */
053: public TakeWorkgroupAuthority(DocumentRouteHeaderValue routeHeader,
054: WorkflowUser user) {
055: super (routeHeader, user);
056: super
057: .setActionTakenCode(EdenConstants.ACTION_TAKEN_TAKE_WORKGROUP_AUTHORITY_CD);
058: }
059:
060: /**
061: * @param routeHeader
062: * @param user
063: * @param annotation
064: * @param workgroup
065: */
066: public TakeWorkgroupAuthority(DocumentRouteHeaderValue routeHeader,
067: WorkflowUser user, String annotation, Workgroup workgroup) {
068: super (routeHeader, user, annotation);
069: this .workgroup = workgroup;
070: super
071: .setActionTakenCode(EdenConstants.ACTION_TAKEN_TAKE_WORKGROUP_AUTHORITY_CD);
072: }
073:
074: /* (non-Javadoc)
075: * @see edu.iu.uis.eden.actions.ActionTakenEvent#requireInitiatorCheck()
076: */
077: @Override
078: protected boolean requireInitiatorCheck() {
079: // TODO Auto-generated method stub
080: return false;
081: }
082:
083: /* (non-Javadoc)
084: * @see edu.iu.uis.eden.actions.ActionTakenEvent#validateActionRules()
085: */
086: @Override
087: public String validateActionRules()
088: throws EdenUserNotFoundException {
089: String super Error = super .validateActionTakenRules();
090: if (!Utilities.isEmpty(super Error)) {
091: return super Error;
092: }
093: if ((workgroup != null) && (!workgroup.hasMember(getUser()))) {
094: return (getUser().getAuthenticationUserId()
095: + " not a member of workgroup " + workgroup
096: .getDisplayName());
097: }
098: return "";
099: }
100:
101: public void recordAction() throws InvalidActionTakenException,
102: EdenUserNotFoundException {
103:
104: String errorMessage = validateActionRules();
105: if (!Utilities.isEmpty(errorMessage)) {
106: throw new InvalidActionTakenException(errorMessage);
107: }
108: // if (! workgroup.hasMember(getUser())) {
109: // throw new InvalidActionTakenException(getUser().getAuthenticationUserId() + " not a member of workgroup " + workgroup.getDisplayName());
110: // }
111:
112: List documentRequests = getActionRequestService()
113: .findPendingByDoc(getRouteHeaderId());
114: List workgroupRequests = new ArrayList();
115: for (Iterator iter = documentRequests.iterator(); iter
116: .hasNext();) {
117: ActionRequestValue actionRequest = (ActionRequestValue) iter
118: .next();
119: if (actionRequest.isWorkgroupRequest()
120: && actionRequest.getWorkgroup()
121: .getWorkflowGroupId().getGroupId().equals(
122: workgroup.getWorkflowGroupId()
123: .getGroupId())) {
124: workgroupRequests.add(actionRequest);
125: }
126: }
127:
128: saveActionTaken(findDelegatorForActionRequests(workgroupRequests));
129: notifyActionTaken(this .actionTaken);
130:
131: ActionListService actionListService = KEWServiceLocator
132: .getActionListService();
133: Collection actionItems = actionListService
134: .findByRouteHeaderId(getRouteHeaderId());
135: for (Iterator iter = actionItems.iterator(); iter.hasNext();) {
136: ActionItem actionItem = (ActionItem) iter.next();
137: //delete all requests for this workgroup on this document not to this user
138: if (actionItem.isWorkgroupItem()
139: && actionItem.getWorkgroupId()
140: .equals(
141: workgroup.getWorkflowGroupId()
142: .getGroupId())
143: && !actionItem.getWorkflowId().equals(
144: getUser().getWorkflowId())) {
145: actionListService.deleteActionItem(actionItem);
146: }
147: }
148: }
149: }
|