001/**
002 * Copyright 2005-2015 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.kew.superuser.web;
017
018import org.apache.commons.lang.ArrayUtils;
019import org.apache.struts.action.ActionMapping;
020import org.kuali.rice.core.api.util.ConcreteKeyValue;
021import org.kuali.rice.core.api.util.KeyValue;
022import org.kuali.rice.kew.actionrequest.ActionRequestValue;
023import org.kuali.rice.kew.api.KewApiServiceLocator;
024import org.kuali.rice.kew.doctype.bo.DocumentType;
025import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
026import org.kuali.rice.kew.service.KEWServiceLocator;
027import org.kuali.rice.kew.web.KewRoutingKualiForm;
028
029import javax.servlet.http.HttpServletRequest;
030import java.util.ArrayList;
031import java.util.Arrays;
032import java.util.HashSet;
033import java.util.List;
034import java.util.Set;
035
036
037/**
038 * A Struts ActionForm for the {@link SuperUserAction}.
039 *
040 * @author Kuali Rice Team (rice.collab@kuali.org)
041 */
042public class SuperUserForm extends KewRoutingKualiForm {
043
044    private static final long serialVersionUID = 982228198266403397L;
045    private String documentId;
046    private String docHandlerUrl;
047    private Integer routeLevel;
048    private List<String> futureNodeNames = new ArrayList<String>();
049    private String destNodeName;
050    private String returnDestNodeName;
051    private String action;
052    private List<ActionRequestValue> actionRequests = new ArrayList<ActionRequestValue>();
053    private String actionTakenActionRequestId;
054    private String actionTakenNetworkId;
055    private String actionTakenWorkGroupId;
056    private String actionTakenRecipientCode;
057    private boolean authorized;
058    private boolean blanketApprove;
059    private String methodToCall = "";
060    private boolean runPostProcessorLogic = true;
061    private String[] actionRequestRunPostProcessorCheck;
062
063    private String lookupableImplServiceName;
064    private String lookupType;
065
066    private DocumentRouteHeaderValue routeHeader;
067
068    // KULRICE-3035: Added the ability to store the doc search's "returnLocation" property so that the superuser form can create a proper "cancel" button.
069    private String returnLocation;
070    
071    @Override
072        public String getMethodToCall() {
073        return methodToCall;
074    }
075    @Override
076        public void setMethodToCall(String methodToCall) {
077        this.methodToCall = methodToCall;
078    }
079
080    public boolean isBlanketApprove() {
081        return blanketApprove;
082    }
083
084    public void setBlanketApprove(boolean blanketApprove) {
085        this.blanketApprove = blanketApprove;
086    }
087
088    public DocumentRouteHeaderValue getRouteHeader() {
089        return routeHeader;
090    }
091
092    public void setRouteHeader(DocumentRouteHeaderValue routeHeader) {
093        this.routeHeader = routeHeader;
094    }
095
096    public String getDocumentId() {
097        return documentId;
098    }
099
100    public void setDocumentId(String documentId) {
101        this.documentId = documentId;
102    }
103
104    public String getDocHandlerUrl() {
105        return docHandlerUrl;
106    }
107
108    public void setDocHandlerUrl(String docHandlerUrl) {
109        this.docHandlerUrl = docHandlerUrl;
110    }
111
112    public Integer getRouteLevel() {
113        return routeLevel;
114    }
115
116    public void setRouteLevel(Integer routeLevel) {
117        this.routeLevel = routeLevel;
118    }
119
120    public String getAction() {
121        return action;
122    }
123
124    public void setAction(String action) {
125        this.action = action;
126    }
127
128    public List<ActionRequestValue> getActionRequests() {
129        return actionRequests;
130    }
131
132    public void setActionRequests(List<ActionRequestValue> actionRequests) {
133        this.actionRequests = actionRequests;
134    }
135
136    public String getActionTakenActionRequestId() {
137        return actionTakenActionRequestId;
138    }
139
140    public void setActionTakenActionRequestId(String actionTakenActionRequestId) {
141        this.actionTakenActionRequestId = actionTakenActionRequestId;
142    }
143
144    public String getActionTakenNetworkId() {
145        return actionTakenNetworkId;
146    }
147
148    public void setActionTakenNetworkId(String actionTakenNetworkId) {
149        this.actionTakenNetworkId = actionTakenNetworkId;
150    }
151
152    public String getActionTakenWorkGroupId() {
153        return actionTakenWorkGroupId;
154    }
155
156    public void setActionTakenWorkGroupId(String actionTakenWorkGroupId) {
157        this.actionTakenWorkGroupId = actionTakenWorkGroupId;
158    }
159
160    /*public List getRouteLevels() {
161        return routeLevels;
162    }
163
164    public void setRouteLevels(List routeLevels) {
165        this.routeLevels = routeLevels;
166    }*/
167
168    public boolean isAuthorized() {
169        return authorized;
170    }
171
172    public void setAuthorized(boolean authorized) {
173        this.authorized = authorized;
174    }
175
176    @Override
177        public void reset(ActionMapping mapping, HttpServletRequest request){
178        this.futureNodeNames = new ArrayList<String>();
179    }
180
181    public String getActionTakenRecipientCode() {
182        return actionTakenRecipientCode;
183    }
184
185    public void setActionTakenRecipientCode(String actionTakenRecipientCode) {
186        this.actionTakenRecipientCode = actionTakenRecipientCode;
187    }
188
189    public boolean isSUDocument() {
190        if (routeHeader.isStateInitiated() || routeHeader.isStateSaved()) {
191            return false;
192        }
193        return true;
194    }
195
196    public boolean isStateAllowsAction() {
197        if ( routeHeader.isProcessed() || routeHeader.isDisaproved() ) {
198            return false;
199        }
200        return true;
201    }
202
203    public boolean isSuperUserFinalApproveAllowed() {
204        return getDocumentType().getAllowSuperUserFinalApprovalPolicy().getPolicyValue().booleanValue();
205    }
206
207    public boolean isSuperUserFinalApproveAllowedForActionRequest() {
208        if (!isSuperUserFinalApproveAllowed() &&
209            KEWServiceLocator.getRouteNodeService().findFutureNodeNames(getRouteHeader().getDocumentId()).isEmpty()) {
210            return false;
211        } else {
212            return true;
213        }
214    }
215
216    public DocumentType getDocumentType() {
217        return getRouteHeader().getDocumentType();
218    }
219
220    public Set<KeyValue> getPreviousNodes() throws Exception {
221        List<String> nodeNames = KewApiServiceLocator.getWorkflowDocumentService().getPreviousRouteNodeNames(routeHeader.getDocumentId());
222        Set<KeyValue> previousNodes = new HashSet<KeyValue>();
223        for (String nodeName : nodeNames) {
224                        previousNodes.add(new ConcreteKeyValue(nodeName, nodeName));
225                }
226        return previousNodes;
227    }
228
229    public String getDestNodeName() {
230        return destNodeName;
231    }
232    public void setDestNodeName(String previousNodeName) {
233        this.destNodeName = previousNodeName;
234    }
235    public List<String> getFutureNodeNames() {
236        return futureNodeNames;
237    }
238    public void setFutureNodeNames(List<String> futureNodeNames) {
239        this.futureNodeNames = futureNodeNames;
240    }
241    public String getReturnDestNodeName() {
242        return returnDestNodeName;
243    }
244    public void setReturnDestNodeName(String returnDestNodeName) {
245        this.returnDestNodeName = returnDestNodeName;
246    }
247    public String getLookupableImplServiceName() {
248        return lookupableImplServiceName;
249    }
250    public void setLookupableImplServiceName(String lookupableImplServiceName) {
251        this.lookupableImplServiceName = lookupableImplServiceName;
252    }
253    public String getLookupType() {
254        return lookupType;
255    }
256    public void setLookupType(String lookupType) {
257        this.lookupType = lookupType;
258    }
259    public boolean isRunPostProcessorLogic() {
260        return this.runPostProcessorLogic;
261    }
262    public void setRunPostProcessorLogic(boolean runPostProcessorLogic) {
263        this.runPostProcessorLogic = runPostProcessorLogic;
264    }
265    public String[] getActionRequestRunPostProcessorCheck() {
266        return this.actionRequestRunPostProcessorCheck;
267    }
268    public void setActionRequestRunPostProcessorCheck(String[] actionRequestRunPostProcessorCheck) {
269        this.actionRequestRunPostProcessorCheck = actionRequestRunPostProcessorCheck;
270    }
271    public Boolean getActionRequestPostProcessorCheck(String actionRequestId) {
272        return ArrayUtils.contains(getActionRequestRunPostProcessorCheck(), actionRequestId);
273    }
274    public List<String> getActionRequestPostProcessorCheck() {
275        if (getActionRequestRunPostProcessorCheck() == null) {
276            return null;
277        }
278        return Arrays.asList(getActionRequestRunPostProcessorCheck());
279    }
280
281    public String getReturnLocation() {
282        return returnLocation;
283    }
284    public void setReturnLocation(String returnLocation) {
285        this.returnLocation = returnLocation;
286    }
287    public boolean getActionRequestPostProcessorDisplayCheck(){
288        return getDocumentType().getSuPostprocessorOverridePolicy().getPolicyValue().booleanValue();
289    }
290}