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.Iterator;
020: import java.util.List;
021:
022: import edu.iu.uis.eden.EdenConstants;
023: import edu.iu.uis.eden.actionitem.ActionItem;
024: import edu.iu.uis.eden.actionrequests.ActionRequestValue;
025: import edu.iu.uis.eden.exception.EdenUserNotFoundException;
026: import edu.iu.uis.eden.exception.InvalidActionTakenException;
027: import edu.iu.uis.eden.routeheader.DocumentRouteHeaderValue;
028: import edu.iu.uis.eden.user.WorkflowUser;
029: import edu.iu.uis.eden.util.Utilities;
030: import edu.iu.uis.eden.workgroup.Workgroup;
031:
032: /**
033: * This is the inverse of the {@link TakeWorkgroupAuthority} action. This puts the document back
034: * in all the peoples action lists that have the document routed to them.
035: *
036: * @author rkirkend
037: */
038: public class ReleaseWorkgroupAuthority extends ActionTakenEvent {
039:
040: private Workgroup workgroup;
041:
042: /**
043: * @param routeHeader
044: * @param user
045: */
046: public ReleaseWorkgroupAuthority(
047: DocumentRouteHeaderValue routeHeader, WorkflowUser user) {
048: super (routeHeader, user);
049: super
050: .setActionTakenCode(EdenConstants.ACTION_TAKEN_RELEASE_WORKGROUP_AUTHORITY_CD);
051: }
052:
053: /**
054: * @param routeHeader
055: * @param user
056: * @param annotation
057: * @param workgroup
058: */
059: public ReleaseWorkgroupAuthority(
060: DocumentRouteHeaderValue routeHeader, WorkflowUser user,
061: String annotation, Workgroup workgroup) {
062: super (routeHeader, user, annotation);
063: this .workgroup = workgroup;
064: super
065: .setActionTakenCode(EdenConstants.ACTION_TAKEN_RELEASE_WORKGROUP_AUTHORITY_CD);
066: }
067:
068: /* (non-Javadoc)
069: * @see edu.iu.uis.eden.actions.ActionTakenEvent#validateActionRules()
070: */
071: @Override
072: public String validateActionRules()
073: throws EdenUserNotFoundException {
074: if (workgroup == null) {
075: return "User cannot Release Workgroup Authority without a given workgroup";
076: } else {
077: return performReleaseWorkgroupAuthority(true);
078: }
079: }
080:
081: public void recordAction() throws InvalidActionTakenException,
082: EdenUserNotFoundException {
083: String error = performReleaseWorkgroupAuthority(false);
084: if (!Utilities.isEmpty(error)) {
085: throw new InvalidActionTakenException(error);
086: }
087: }
088:
089: private String performReleaseWorkgroupAuthority(
090: boolean forValidationOnly) throws EdenUserNotFoundException {
091: if (!workgroup.hasMember(getUser())) {
092: return (getUser().getAuthenticationUserId()
093: + " not a member of workgroup " + workgroup
094: .getDisplayName());
095: }
096:
097: List actionRequests = getActionRequestService()
098: .findPendingByDoc(getRouteHeaderId());
099: //List groupRequestsToActivate = new ArrayList();//requests for this group that need action items
100: for (Iterator iter = actionRequests.iterator(); iter.hasNext();) {
101: ActionRequestValue actionRequest = (ActionRequestValue) iter
102: .next();
103: //we left the group active from take authority action. pending havent been normally activated yet
104: if (actionRequest.isWorkgroupRequest()
105: && actionRequest.isActive()
106: && actionRequest.getWorkgroupId()
107: .equals(
108: workgroup.getWorkflowGroupId()
109: .getGroupId())) {
110: if (actionRequest.getActionItems().size() == 1) {
111: ActionItem actionItem = (ActionItem) actionRequest
112: .getActionItems().get(0);
113: if (!actionItem.getWorkflowId().equals(
114: getUser().getWorkflowId())) {
115: return "User attempting to release workgroup authority did not take it.";
116: } else if (!forValidationOnly) {
117: actionRequest
118: .setStatus(EdenConstants.ACTION_REQUEST_INITIALIZED);//to circumvent check in service during activation
119: getActionRequestService().activateRequest(
120: actionRequest);
121: }
122: }
123: }
124: }
125: return "";
126: }
127: }
|