View Javadoc

1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kew.superuser.web;
17  
18  import org.apache.commons.lang.ArrayUtils;
19  import org.apache.struts.action.ActionMapping;
20  import org.kuali.rice.core.api.util.ConcreteKeyValue;
21  import org.kuali.rice.core.api.util.KeyValue;
22  import org.kuali.rice.kew.actionrequest.ActionRequestValue;
23  import org.kuali.rice.kew.api.KewApiServiceLocator;
24  import org.kuali.rice.kew.doctype.bo.DocumentType;
25  import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
26  import org.kuali.rice.kew.service.KEWServiceLocator;
27  import org.kuali.rice.kew.web.KewRoutingKualiForm;
28  
29  import javax.servlet.http.HttpServletRequest;
30  import java.util.ArrayList;
31  import java.util.Arrays;
32  import java.util.HashSet;
33  import java.util.List;
34  import java.util.Set;
35  
36  
37  /**
38   * A Struts ActionForm for the {@link SuperUserAction}.
39   *
40   * @author Kuali Rice Team (rice.collab@kuali.org)
41   */
42  public class SuperUserForm extends KewRoutingKualiForm {
43  
44      private static final long serialVersionUID = 982228198266403397L;
45      private String documentId;
46      private String docHandlerUrl;
47      private Integer routeLevel;
48      private List<String> futureNodeNames = new ArrayList<String>();
49      private String destNodeName;
50      private String returnDestNodeName;
51      private String action;
52      private List<ActionRequestValue> actionRequests = new ArrayList<ActionRequestValue>();
53      private String actionTakenActionRequestId;
54      private String actionTakenNetworkId;
55      private String actionTakenWorkGroupId;
56      private String actionTakenRecipientCode;
57      private boolean authorized;
58      private boolean blanketApprove;
59      private String methodToCall = "";
60      private boolean runPostProcessorLogic = true;
61      private String[] actionRequestRunPostProcessorCheck;
62  
63      private String lookupableImplServiceName;
64      private String lookupType;
65  
66      private DocumentRouteHeaderValue routeHeader;
67  
68      // KULRICE-3035: Added the ability to store the doc search's "returnLocation" property so that the superuser form can create a proper "cancel" button.
69      private String returnLocation;
70      
71      @Override
72  	public String getMethodToCall() {
73          return methodToCall;
74      }
75      @Override
76  	public void setMethodToCall(String methodToCall) {
77          this.methodToCall = methodToCall;
78      }
79  
80      public boolean isBlanketApprove() {
81          return blanketApprove;
82      }
83  
84      public void setBlanketApprove(boolean blanketApprove) {
85          this.blanketApprove = blanketApprove;
86      }
87  
88      public DocumentRouteHeaderValue getRouteHeader() {
89          return routeHeader;
90      }
91  
92      public void setRouteHeader(DocumentRouteHeaderValue routeHeader) {
93          this.routeHeader = routeHeader;
94      }
95  
96      public String getDocumentId() {
97          return documentId;
98      }
99  
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 }