001    /*
002     * Copyright 2005-2008 The Kuali Foundation
003     * 
004     * 
005     * Licensed under the Educational Community License, Version 2.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/ecl2.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 org.kuali.rice.kew.actions;
018    
019    import org.apache.commons.lang.StringUtils;
020    import org.kuali.rice.kew.actionrequest.ActionRequestValue;
021    
022    
023    /**
024     * Represents a revocation of an AdHoc request.<br><br>
025     * 
026     * If the <code>nodeName</code> property on this object is set, then the system will only
027     * examine pending app-specific requests at nodes with that particular name.  In addition to
028     * this, one of the following 3 parameters is required:<br><br>
029     * 
030     * <ol>
031     *   <li><b>actionRequestId</b> - the ID of the action request to revoke</li>
032     *   <li><b>userId</b> - the ID of the user whose request(s) should be revoked</li>
033     *       <li><b>workgroupId</b> - the ID of the workgroup whose requests(s) should be revoked</li>
034     * </ol>
035     * 
036     * @author Kuali Rice Team (rice.collab@kuali.org)
037     */
038    public class AdHocRevoke implements java.io.Serializable {
039    
040            private static final long serialVersionUID = 8536540010313763068L;
041    
042            private Long actionRequestId;
043            private String nodeName;
044            private String principalId;
045            private String groupId;
046            
047            public AdHocRevoke() {}
048            
049            public Long getActionRequestId() {
050                    return actionRequestId;
051            }
052            public void setActionRequestId(Long actionRequestId) {
053                    this.actionRequestId = actionRequestId;
054            }
055            public String getNodeName() {
056                    return nodeName;
057            }
058            public void setNodeName(String nodeName) {
059                    this.nodeName = nodeName;
060            }
061            public String getPrincipalId() {
062                    return principalId;
063            }
064            public void setPrincipalId(String principalId) {
065                    this.principalId = principalId;
066            }
067                    
068            /**
069             * Determines if the given action request is an ad hoc request which matches this set of criteria.
070             */
071            public boolean matchesActionRequest(ActionRequestValue actionRequest) {
072                    if (!actionRequest.isAdHocRequest()) {
073                            return false;
074                    }
075                    if (getActionRequestId() != null && !getActionRequestId().equals(actionRequest.getActionRequestId()) ){
076                            return false;
077                    }
078                    if (!StringUtils.isEmpty(getNodeName()) && !getNodeName().equals(actionRequest.getNodeInstance().getName())) {
079                            return false;
080                    }
081                    if (getPrincipalId() != null && (!actionRequest.isUserRequest() || !actionRequest.getPrincipalId().equals(getPrincipalId()))) {
082                            return false;
083                    }
084                    if (getGroupId() != null && (!actionRequest.isGroupRequest() || !actionRequest.getGroupId().equals(getGroupId()))) {
085                            return false;
086                    }
087                    return true;
088            }
089    
090            /**
091             * @return the group
092             */
093            public String getGroupId() {
094                    return this.groupId;
095            }
096    
097            /**
098             * @param groupId of the group to set
099             */
100            public void setGroupId(String groupId) {
101                    this.groupId = groupId;
102            }
103            
104    }