1 | |
package org.kuali.student.core.workflow.ui.server.gwt; |
2 | |
|
3 | |
import java.util.ArrayList; |
4 | |
import java.util.Arrays; |
5 | |
import java.util.HashMap; |
6 | |
import java.util.List; |
7 | |
import java.util.Map; |
8 | |
|
9 | |
import org.apache.commons.lang.StringUtils; |
10 | |
import org.apache.log4j.Logger; |
11 | |
import org.kuali.rice.kew.dto.DocumentContentDTO; |
12 | |
import org.kuali.rice.kew.dto.DocumentDetailDTO; |
13 | |
import org.kuali.rice.kew.dto.DocumentTypeDTO; |
14 | |
import org.kuali.rice.kew.dto.RouteNodeInstanceDTO; |
15 | |
import org.kuali.rice.kew.exception.WorkflowException; |
16 | |
import org.kuali.rice.kew.service.WorkflowUtility; |
17 | |
import org.kuali.rice.kew.util.KEWConstants; |
18 | |
import org.kuali.rice.kew.webservice.DocumentResponse; |
19 | |
import org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService; |
20 | |
import org.kuali.rice.kew.webservice.StandardResponse; |
21 | |
import org.kuali.rice.kim.bo.entity.dto.KimPrincipalInfo; |
22 | |
import org.kuali.rice.kim.bo.types.dto.AttributeSet; |
23 | |
import org.kuali.rice.kim.service.IdentityManagementService; |
24 | |
import org.kuali.student.common.ui.client.service.exceptions.OperationFailedException; |
25 | |
import org.kuali.student.common.util.security.SecurityUtils; |
26 | |
import org.kuali.student.core.rice.StudentIdentityConstants; |
27 | |
import org.kuali.student.core.rice.StudentWorkflowConstants.ActionRequestType; |
28 | |
import org.kuali.student.core.rice.authorization.PermissionType; |
29 | |
import org.kuali.student.core.workflow.ui.client.service.WorkflowRpcService; |
30 | |
|
31 | |
import com.google.gwt.user.server.rpc.RemoteServiceServlet; |
32 | |
|
33 | 0 | public class WorkflowRpcGwtServlet extends RemoteServiceServlet implements WorkflowRpcService { |
34 | |
|
35 | |
private static final long serialVersionUID = 1L; |
36 | |
|
37 | 0 | final Logger LOG = Logger.getLogger(WorkflowRpcGwtServlet.class); |
38 | |
|
39 | |
private SimpleDocumentActionsWebService simpleDocService; |
40 | |
private WorkflowUtility workflowUtilityService; |
41 | |
private IdentityManagementService identityService; |
42 | |
private IdentityManagementService permissionService; |
43 | |
|
44 | |
@Override |
45 | |
public Boolean acknowledgeDocumentWithId(String workflowId) throws OperationFailedException { |
46 | |
try{ |
47 | |
|
48 | 0 | String username= SecurityUtils.getCurrentUserId(); |
49 | |
|
50 | 0 | StandardResponse stdResp = getSimpleDocService().acknowledge(workflowId, username, ""); |
51 | |
|
52 | 0 | if(stdResp==null||StringUtils.isNotBlank(stdResp.getErrorMessage())){ |
53 | 0 | throw new OperationFailedException("Error found acknowledging document: " + stdResp.getErrorMessage()); |
54 | |
} |
55 | |
|
56 | 0 | }catch(OperationFailedException e){ |
57 | 0 | LOG.error("Error acknowledging Document with workflow id:" + workflowId, e); |
58 | 0 | throw new OperationFailedException("Could not acknowledge"); |
59 | 0 | } |
60 | 0 | return Boolean.valueOf(true); |
61 | |
} |
62 | |
|
63 | |
@Override |
64 | |
public Boolean adhocRequest(String workflowId, String recipientPrincipalId, |
65 | |
ActionRequestType requestType, String annotation) throws OperationFailedException { |
66 | |
|
67 | |
try { |
68 | |
|
69 | 0 | String username = SecurityUtils.getCurrentUserId(); |
70 | |
|
71 | 0 | String fyiAnnotation = ""; |
72 | 0 | String approveAnnotation = ""; |
73 | 0 | String ackAnnotation = ""; |
74 | |
|
75 | 0 | if (ActionRequestType.FYI.equals(requestType)) { |
76 | 0 | StandardResponse stdResp = getSimpleDocService().requestAdHocFyiToPrincipal(workflowId,recipientPrincipalId, username, fyiAnnotation); |
77 | 0 | if (stdResp == null || StringUtils.isNotBlank(stdResp.getErrorMessage())) { |
78 | 0 | throw new OperationFailedException("Error found in Adhoc FYI: " + stdResp.getErrorMessage()); |
79 | |
} |
80 | |
} |
81 | 0 | if (ActionRequestType.APPROVE.equals(requestType)) { |
82 | 0 | StandardResponse stdResp = getSimpleDocService().requestAdHocApproveToPrincipal(workflowId, recipientPrincipalId,username, approveAnnotation); |
83 | 0 | if (stdResp == null || StringUtils.isNotBlank(stdResp.getErrorMessage())) { |
84 | 0 | throw new OperationFailedException("Error found in Adhoc Approve: " + stdResp.getErrorMessage()); |
85 | |
} |
86 | |
} |
87 | 0 | if (ActionRequestType.ACKNOWLEDGE.equals(requestType)) { |
88 | 0 | StandardResponse stdResp = getSimpleDocService().requestAdHocAckToPrincipal(workflowId,recipientPrincipalId,username, ackAnnotation); |
89 | 0 | if (stdResp == null || StringUtils.isNotBlank(stdResp.getErrorMessage())) { |
90 | 0 | throw new OperationFailedException("Error found in Adhoc Ack: " + stdResp.getErrorMessage()); |
91 | |
} |
92 | |
} |
93 | |
|
94 | 0 | } catch (Exception e) { |
95 | 0 | LOG.error("Error adhoc routing",e); |
96 | 0 | throw new OperationFailedException("Could not adhoc route"); |
97 | 0 | } |
98 | 0 | return Boolean.valueOf(true); |
99 | |
} |
100 | |
|
101 | |
@Override |
102 | |
public Boolean approveDocumentWithId(String workflowId) throws OperationFailedException { |
103 | |
|
104 | |
try{ |
105 | |
|
106 | 0 | String username = SecurityUtils.getCurrentUserId(); |
107 | 0 | StandardResponse stdResp = getSimpleDocService().approve(workflowId, username, null, null, ""); |
108 | 0 | if(stdResp==null||StringUtils.isNotBlank(stdResp.getErrorMessage())){ |
109 | 0 | throw new OperationFailedException("Error found approving document: " + stdResp.getErrorMessage()); |
110 | |
} |
111 | |
|
112 | 0 | }catch(Exception e){ |
113 | 0 | LOG.error("Error approving document",e); |
114 | 0 | return Boolean.FALSE; |
115 | 0 | } |
116 | 0 | return Boolean.TRUE; |
117 | |
} |
118 | |
|
119 | |
@Override |
120 | |
public Boolean blanketApproveDocumentWithId(String workflowId) throws OperationFailedException { |
121 | |
|
122 | |
try{ |
123 | |
|
124 | 0 | String username = SecurityUtils.getCurrentUserId(); |
125 | 0 | StandardResponse stdResp = getSimpleDocService().blanketApprove(workflowId, username, null, null, ""); |
126 | 0 | if(stdResp==null||StringUtils.isNotBlank(stdResp.getErrorMessage())){ |
127 | 0 | throw new OperationFailedException("Error found blanket approving document: " + stdResp.getErrorMessage()); |
128 | |
} |
129 | |
|
130 | 0 | }catch(Exception e){ |
131 | 0 | LOG.error("Error blanket approving document",e); |
132 | 0 | return Boolean.FALSE; |
133 | 0 | } |
134 | 0 | return Boolean.TRUE; |
135 | |
} |
136 | |
|
137 | |
@Override |
138 | |
public Boolean disapproveDocumentWithId(String workflowId) { |
139 | |
|
140 | |
try{ |
141 | |
|
142 | 0 | String username = SecurityUtils.getCurrentUserId(); |
143 | 0 | String disapproveComment = "Disapproved"; |
144 | |
|
145 | 0 | StandardResponse stdResp = getSimpleDocService().disapprove(workflowId, username, disapproveComment); |
146 | 0 | if(stdResp==null||StringUtils.isNotBlank(stdResp.getErrorMessage())){ |
147 | 0 | LOG.error("Error disapproving document: " + stdResp.getErrorMessage()); |
148 | 0 | return Boolean.FALSE; |
149 | |
} |
150 | 0 | }catch(Exception e){ |
151 | 0 | LOG.error("Error disapproving document",e); |
152 | 0 | return Boolean.FALSE; |
153 | 0 | } |
154 | 0 | return Boolean.TRUE; |
155 | |
} |
156 | |
|
157 | |
@Override |
158 | |
public Boolean fyiDocumentWithId(String workflowId) { |
159 | |
try{ |
160 | |
|
161 | 0 | String username = SecurityUtils.getCurrentUserId(); |
162 | |
|
163 | 0 | StandardResponse stdResp = getSimpleDocService().fyi(workflowId, username); |
164 | 0 | if(stdResp==null||StringUtils.isNotBlank(stdResp.getErrorMessage())){ |
165 | 0 | LOG.error("Error FYIing document: " + stdResp.getErrorMessage()); |
166 | 0 | return Boolean.FALSE; |
167 | |
} |
168 | 0 | }catch(Exception e){ |
169 | 0 | LOG.error("Error FYIing document",e); |
170 | 0 | return Boolean.FALSE; |
171 | 0 | } |
172 | 0 | return Boolean.TRUE; |
173 | |
} |
174 | |
|
175 | |
@Override |
176 | |
public Boolean withdrawDocumentWithId(String workflowId) { |
177 | 0 | if(simpleDocService==null){ |
178 | 0 | LOG.error("Workflow Service is unavailable"); |
179 | 0 | return Boolean.FALSE; |
180 | |
} |
181 | |
|
182 | |
try{ |
183 | 0 | String username = SecurityUtils.getCurrentUserId(); |
184 | 0 | KimPrincipalInfo systemPrincipal = getIdentityService().getPrincipalByPrincipalName(StudentIdentityConstants.SYSTEM_USER_PRINCIPAL_NAME); |
185 | 0 | if (systemPrincipal == null) { |
186 | 0 | throw new RuntimeException("Cannot find principal for system user principal name: " + StudentIdentityConstants.SYSTEM_USER_PRINCIPAL_NAME); |
187 | |
} |
188 | 0 | String annotation = "Document was withdrawn by " + username; |
189 | |
|
190 | 0 | StandardResponse stdResp = simpleDocService.superUserDisapprove(workflowId, systemPrincipal.getPrincipalId(), null, null, annotation); |
191 | 0 | if(stdResp==null||StringUtils.isNotBlank(stdResp.getErrorMessage())) { |
192 | 0 | LOG.error("Error withdrawing document: " + stdResp.getErrorMessage()); |
193 | 0 | return Boolean.FALSE; |
194 | |
} |
195 | 0 | }catch(Exception e){ |
196 | 0 | LOG.error("Error withdrawing document",e); |
197 | 0 | return Boolean.FALSE; |
198 | 0 | } |
199 | 0 | return Boolean.TRUE; |
200 | |
} |
201 | |
|
202 | |
@Override |
203 | |
public Boolean returnDocumentWithId(String workflowId, String nodeName) { |
204 | |
|
205 | |
try{ |
206 | |
|
207 | 0 | String username = SecurityUtils.getCurrentUserId(); |
208 | 0 | StandardResponse stdResp = getSimpleDocService().returnToPreviousNode(workflowId, username, "", nodeName); |
209 | 0 | if(stdResp==null||StringUtils.isNotBlank(stdResp.getErrorMessage())){ |
210 | 0 | throw new OperationFailedException("Error found approving document: " + stdResp.getErrorMessage()); |
211 | |
} |
212 | |
|
213 | 0 | }catch(Exception e){ |
214 | 0 | LOG.error("Error approving document",e); |
215 | 0 | return Boolean.FALSE; |
216 | 0 | } |
217 | 0 | return Boolean.TRUE; |
218 | |
} |
219 | |
|
220 | |
public List<String> getPreviousRouteNodeNames(String workflowId) throws OperationFailedException { |
221 | |
try { |
222 | 0 | String[] nodeNames = getWorkflowUtilityService().getPreviousRouteNodeNames(Long.parseLong(workflowId)); |
223 | 0 | return Arrays.asList(nodeNames); |
224 | 0 | } catch (Exception e) { |
225 | 0 | LOG.error("Error approving document",e); |
226 | 0 | throw new OperationFailedException("Error getting previous node names"); |
227 | |
} |
228 | |
} |
229 | |
|
230 | |
@Override |
231 | |
public String getActionsRequested(String workflowId) throws OperationFailedException { |
232 | |
try{ |
233 | 0 | if(null==workflowId || workflowId.isEmpty()){ |
234 | 0 | LOG.info("No workflow id was provided."); |
235 | 0 | return ""; |
236 | |
} |
237 | |
|
238 | |
|
239 | 0 | String principalId = SecurityUtils.getCurrentUserId(); |
240 | |
|
241 | |
|
242 | 0 | LOG.debug("Calling action requested with user:"+principalId+" and workflowId:" + workflowId); |
243 | |
|
244 | 0 | Map<String,String> results = new HashMap<String,String>(); |
245 | 0 | AttributeSet kewActionsRequested = getWorkflowUtilityService().getActionsRequested(principalId, Long.parseLong(workflowId)); |
246 | 0 | for (String key : kewActionsRequested.keySet()) { |
247 | 0 | if ("true".equalsIgnoreCase(kewActionsRequested.get(key))) { |
248 | 0 | results.put(key,"true"); |
249 | |
} |
250 | |
} |
251 | |
|
252 | |
|
253 | 0 | StringBuilder actionsRequestedBuffer = new StringBuilder(); |
254 | |
|
255 | 0 | DocumentDetailDTO docDetail = getWorkflowUtilityService().getDocumentDetail(Long.parseLong(workflowId)); |
256 | |
|
257 | 0 | for(Map.Entry<String,String> entry:results.entrySet()){ |
258 | |
|
259 | 0 | if (KEWConstants.ROUTE_HEADER_SAVED_CD.equals(docDetail.getDocRouteStatus()) || KEWConstants.ROUTE_HEADER_INITIATED_CD.equals(docDetail.getDocRouteStatus())) { |
260 | |
|
261 | 0 | if ( (KEWConstants.ACTION_REQUEST_COMPLETE_REQ.equals(entry.getKey()) || KEWConstants.ACTION_REQUEST_APPROVE_REQ.equals(entry.getKey())) && ("true".equals(entry.getValue())) ) { |
262 | 0 | actionsRequestedBuffer.append("S"); |
263 | 0 | actionsRequestedBuffer.append("C"); |
264 | |
} |
265 | |
|
266 | |
else { |
267 | 0 | if("true".equals(entry.getValue())){ |
268 | 0 | actionsRequestedBuffer.append(entry.getKey()); |
269 | |
} |
270 | |
} |
271 | |
} |
272 | |
else { |
273 | 0 | if("true".equals(entry.getValue())){ |
274 | 0 | actionsRequestedBuffer.append(entry.getKey()); |
275 | |
|
276 | 0 | if ( (KEWConstants.ACTION_REQUEST_COMPLETE_REQ.equals(entry.getKey()) || KEWConstants.ACTION_REQUEST_APPROVE_REQ.equals(entry.getKey())) && ("true".equals(entry.getValue())) ) { |
277 | 0 | actionsRequestedBuffer.append("R"); |
278 | |
} |
279 | |
} |
280 | |
} |
281 | |
} |
282 | |
|
283 | 0 | String docTypeName = getWorkflowUtilityService().getDocumentType(docDetail.getDocTypeId()).getName(); |
284 | |
|
285 | 0 | AttributeSet permDetails = new AttributeSet(); |
286 | 0 | permDetails.put(StudentIdentityConstants.DOCUMENT_TYPE_NAME,docTypeName); |
287 | 0 | permDetails.put(StudentIdentityConstants.ROUTE_STATUS_CODE,docDetail.getDocRouteStatus()); |
288 | 0 | if (getPermissionService().isAuthorizedByTemplateName(principalId, |
289 | |
PermissionType.WITHDRAW.getPermissionNamespace(), |
290 | |
PermissionType.WITHDRAW.getPermissionTemplateName(), permDetails, |
291 | |
new AttributeSet(StudentIdentityConstants.DOCUMENT_NUMBER,workflowId))) { |
292 | 0 | LOG.info("User '" + principalId + "' is allowed to Withdraw the Document"); |
293 | 0 | actionsRequestedBuffer.append("W"); |
294 | |
} |
295 | |
|
296 | 0 | Map<String,String> permDetails2 = new HashMap<String,String>(); |
297 | 0 | permDetails2.put(StudentIdentityConstants.DOCUMENT_TYPE_NAME,docTypeName); |
298 | 0 | permDetails2.put(StudentIdentityConstants.ROUTE_STATUS_CODE,docDetail.getDocRouteStatus()); |
299 | |
|
300 | 0 | boolean canBlanketApprove = getPermissionService().isAuthorizedByTemplateName(principalId, |
301 | |
PermissionType.BLANKET_APPROVE.getPermissionNamespace(), |
302 | |
PermissionType.BLANKET_APPROVE.getPermissionTemplateName(), new AttributeSet(permDetails2), |
303 | |
new AttributeSet(StudentIdentityConstants.DOCUMENT_NUMBER,workflowId)); |
304 | 0 | for (String nodeName : getCurrentActiveNodeNames(docDetail.getRouteHeaderId())) { |
305 | 0 | if (canBlanketApprove) { |
306 | 0 | break; |
307 | |
} |
308 | 0 | AttributeSet newSet = new AttributeSet(permDetails2); |
309 | 0 | newSet.put(StudentIdentityConstants.ROUTE_NODE_NAME, nodeName); |
310 | 0 | canBlanketApprove = getPermissionService().isAuthorizedByTemplateName(principalId, |
311 | |
PermissionType.BLANKET_APPROVE.getPermissionNamespace(), |
312 | |
PermissionType.BLANKET_APPROVE.getPermissionTemplateName(), newSet, |
313 | |
new AttributeSet(StudentIdentityConstants.DOCUMENT_NUMBER,workflowId)); |
314 | 0 | } |
315 | 0 | if (canBlanketApprove) { |
316 | 0 | LOG.info("User '" + principalId + "' is allowed to Blanket Approve the Document"); |
317 | 0 | actionsRequestedBuffer.append("B"); |
318 | |
} |
319 | |
|
320 | 0 | return actionsRequestedBuffer.toString(); |
321 | 0 | } catch (Exception e) { |
322 | 0 | LOG.error("Error getting actions Requested",e); |
323 | 0 | throw new OperationFailedException("Error getting actions Requested"); |
324 | |
} |
325 | |
} |
326 | |
|
327 | |
protected List<String> getCurrentActiveNodeNames(Long routeHeaderId) throws OperationFailedException, WorkflowException { |
328 | 0 | List<String> currentActiveNodeNames = new ArrayList<String>(); |
329 | 0 | RouteNodeInstanceDTO[] nodeInstances = getWorkflowUtilityService().getActiveNodeInstances(routeHeaderId); |
330 | 0 | for (RouteNodeInstanceDTO routeNodeInstanceDTO : nodeInstances) { |
331 | 0 | currentActiveNodeNames.add(routeNodeInstanceDTO.getName()); |
332 | |
} |
333 | 0 | return currentActiveNodeNames; |
334 | |
} |
335 | |
|
336 | |
@Override |
337 | |
public String getDocumentStatus(String workflowId) |
338 | |
throws OperationFailedException { |
339 | 0 | if (workflowId != null && !workflowId.isEmpty()){ |
340 | |
try { |
341 | 0 | Long documentId = Long.valueOf(workflowId); |
342 | 0 | return workflowUtilityService.getDocumentStatus(documentId); |
343 | 0 | } catch (Exception e) { |
344 | 0 | throw new OperationFailedException("Error getting document status. " + e.getMessage()); |
345 | |
} |
346 | |
} |
347 | |
|
348 | 0 | return null; |
349 | |
} |
350 | |
|
351 | |
@Override |
352 | |
|
353 | |
|
354 | |
|
355 | |
public String getWorkflowIdFromDataId(String workflowDocType, String dataId) throws OperationFailedException { |
356 | 0 | if(null==simpleDocService){ |
357 | 0 | throw new OperationFailedException("Workflow Service is unavailable"); |
358 | |
} |
359 | |
|
360 | |
DocumentDetailDTO docDetail; |
361 | |
try { |
362 | 0 | docDetail = workflowUtilityService.getDocumentDetailFromAppId(workflowDocType, dataId); |
363 | 0 | if(null==docDetail){ |
364 | 0 | LOG.error("Nothing found for id: "+dataId); |
365 | 0 | return null; |
366 | |
} |
367 | 0 | Long workflowId=docDetail.getRouteHeaderId(); |
368 | 0 | return null==workflowId?null:workflowId.toString(); |
369 | 0 | } catch (Exception e) { |
370 | 0 | LOG.error("Call Failed getting workflowId for id: "+dataId, e); |
371 | |
} |
372 | 0 | return null; |
373 | |
} |
374 | |
|
375 | |
|
376 | |
@Override |
377 | |
public String getDataIdFromWorkflowId(String workflowId) throws OperationFailedException { |
378 | 0 | String username = SecurityUtils.getCurrentUserId(); |
379 | |
|
380 | 0 | DocumentResponse docResponse = getSimpleDocService().getDocument(workflowId, username); |
381 | 0 | if(docResponse==null||StringUtils.isNotBlank(docResponse.getErrorMessage())){ |
382 | 0 | throw new OperationFailedException("Error found gettting document: " + docResponse.getErrorMessage()); |
383 | |
} |
384 | |
|
385 | 0 | return docResponse.getAppDocId(); |
386 | |
} |
387 | |
|
388 | |
@Override |
389 | |
public List<String> getWorkflowNodes(String workflowId) |
390 | |
throws OperationFailedException { |
391 | 0 | List<String> routeNodeNames = new ArrayList<String>(); |
392 | |
|
393 | 0 | Long documentId = Long.valueOf(workflowId); |
394 | |
try{ |
395 | 0 | RouteNodeInstanceDTO[] routeNodes = workflowUtilityService.getActiveNodeInstances(documentId); |
396 | 0 | if (routeNodes != null){ |
397 | 0 | for (RouteNodeInstanceDTO routeNodeInstanceDTO : routeNodes) { |
398 | 0 | routeNodeNames.add(routeNodeInstanceDTO.getName()); |
399 | |
} |
400 | |
} |
401 | |
|
402 | 0 | } catch (Exception e) { |
403 | 0 | throw new OperationFailedException(e.getMessage()); |
404 | 0 | } |
405 | |
|
406 | 0 | return routeNodeNames; |
407 | |
} |
408 | |
|
409 | |
@Override |
410 | |
public Boolean submitDocumentWithId(String workflowId) { |
411 | |
try { |
412 | 0 | if(simpleDocService==null){ |
413 | 0 | throw new OperationFailedException("Workflow Service is unavailable"); |
414 | |
} |
415 | |
|
416 | |
|
417 | 0 | String username = SecurityUtils.getCurrentUserId(); |
418 | |
|
419 | |
|
420 | 0 | DocumentDetailDTO docDetail = workflowUtilityService.getDocumentDetail(Long.parseLong(workflowId)); |
421 | 0 | if(docDetail==null){ |
422 | 0 | throw new OperationFailedException("Error found getting document. " ); |
423 | |
} |
424 | 0 | DocumentContentDTO docContent = workflowUtilityService.getDocumentContent(Long.parseLong(workflowId)); |
425 | |
|
426 | 0 | String routeComment = "Routed"; |
427 | |
|
428 | 0 | StandardResponse stdResp = simpleDocService.route(docDetail.getRouteHeaderId().toString(), username, docDetail.getDocTitle(), docContent.getApplicationContent(), routeComment); |
429 | |
|
430 | 0 | if(stdResp==null||StringUtils.isNotBlank(stdResp.getErrorMessage())){ |
431 | 0 | throw new OperationFailedException("Error found routing document: " + stdResp.getErrorMessage()); |
432 | |
} |
433 | |
|
434 | 0 | } catch (Exception e) { |
435 | 0 | LOG.error("Error found routing document",e); |
436 | 0 | return Boolean.FALSE; |
437 | 0 | } |
438 | 0 | return Boolean.TRUE; |
439 | |
} |
440 | |
|
441 | |
@Override |
442 | |
public Boolean cancelDocumentWithId(String workflowId) { |
443 | |
try { |
444 | 0 | if(simpleDocService==null){ |
445 | 0 | throw new OperationFailedException("Workflow Service is unavailable"); |
446 | |
} |
447 | |
|
448 | |
|
449 | 0 | String username = SecurityUtils.getCurrentUserId(); |
450 | 0 | StandardResponse stdResp = simpleDocService.cancel(workflowId, username, ""); |
451 | |
|
452 | 0 | if(stdResp==null||StringUtils.isNotBlank(stdResp.getErrorMessage())){ |
453 | 0 | throw new OperationFailedException("Error found cancelling document: " + stdResp.getErrorMessage()); |
454 | |
} |
455 | |
|
456 | 0 | } catch (Exception e) { |
457 | 0 | LOG.error("Error found routing document",e); |
458 | 0 | return Boolean.FALSE; |
459 | 0 | } |
460 | 0 | return Boolean.TRUE; |
461 | |
} |
462 | |
|
463 | |
@Override |
464 | |
public Boolean isAuthorizedAddReviewer(String docId) throws OperationFailedException{ |
465 | 0 | if (docId != null && (!"".equals(docId.trim()))) { |
466 | 0 | AttributeSet permissionDetails = new AttributeSet(); |
467 | 0 | AttributeSet roleQuals = new AttributeSet(); |
468 | 0 | roleQuals.put(StudentIdentityConstants.DOCUMENT_NUMBER,docId); |
469 | 0 | return Boolean.valueOf(getPermissionService().isAuthorizedByTemplateName(SecurityUtils.getCurrentUserId(), PermissionType.ADD_ADHOC_REVIEWER.getPermissionNamespace(), |
470 | |
PermissionType.ADD_ADHOC_REVIEWER.getPermissionTemplateName(), permissionDetails, roleQuals)); |
471 | |
} |
472 | 0 | return Boolean.FALSE; |
473 | |
} |
474 | |
|
475 | |
public Boolean isAuthorizedRemoveReviewers(String docId) throws OperationFailedException { |
476 | |
try { |
477 | 0 | if (docId != null && (!"".equals(docId.trim()))) { |
478 | 0 | DocumentDetailDTO docDetail = getWorkflowUtilityService().getDocumentDetail(Long.parseLong(docId)); |
479 | 0 | DocumentTypeDTO docType = getWorkflowUtilityService().getDocumentType(docDetail.getDocTypeId()); |
480 | 0 | AttributeSet permissionDetails = new AttributeSet(); |
481 | 0 | permissionDetails.put(StudentIdentityConstants.DOCUMENT_TYPE_NAME,docType.getName()); |
482 | 0 | AttributeSet roleQuals = new AttributeSet(); |
483 | 0 | roleQuals.put(StudentIdentityConstants.DOCUMENT_NUMBER,docId); |
484 | 0 | boolean returnValue = getPermissionService().isAuthorizedByTemplateName(SecurityUtils.getCurrentUserId(), PermissionType.REMOVE_ADHOC_REVIEWERS.getPermissionNamespace(), |
485 | |
PermissionType.REMOVE_ADHOC_REVIEWERS.getPermissionTemplateName(), permissionDetails, roleQuals); |
486 | 0 | return Boolean.valueOf(returnValue); |
487 | |
} |
488 | 0 | return Boolean.FALSE; |
489 | 0 | } catch (WorkflowException e) { |
490 | 0 | LOG.error("Unable to get document information from Workflow for doc id " + docId); |
491 | 0 | throw new OperationFailedException("Unable to get document information from Workflow for doc id " + docId); |
492 | |
} |
493 | |
} |
494 | |
|
495 | |
public void setSimpleDocService(SimpleDocumentActionsWebService simpleDocService) { |
496 | 0 | this.simpleDocService = simpleDocService; |
497 | 0 | } |
498 | |
|
499 | |
public SimpleDocumentActionsWebService getSimpleDocService() throws OperationFailedException{ |
500 | 0 | if(simpleDocService==null){ |
501 | 0 | throw new OperationFailedException("Workflow Simple Document Service is unavailable"); |
502 | |
} |
503 | |
|
504 | 0 | return simpleDocService; |
505 | |
} |
506 | |
|
507 | |
public void setWorkflowUtilityService(WorkflowUtility workflowUtilityService) { |
508 | 0 | this.workflowUtilityService = workflowUtilityService; |
509 | 0 | } |
510 | |
|
511 | |
public WorkflowUtility getWorkflowUtilityService() throws OperationFailedException{ |
512 | 0 | if(workflowUtilityService==null){ |
513 | 0 | throw new OperationFailedException("Workflow Utility Service is unavailable"); |
514 | |
} |
515 | |
|
516 | 0 | return workflowUtilityService; |
517 | |
} |
518 | |
|
519 | |
public void setIdentityService(IdentityManagementService identityService) { |
520 | 0 | this.identityService = identityService; |
521 | 0 | } |
522 | |
|
523 | |
public IdentityManagementService getIdentityService() throws OperationFailedException{ |
524 | 0 | if(identityService==null){ |
525 | 0 | throw new OperationFailedException("Identity Service is unavailable"); |
526 | |
} |
527 | |
|
528 | 0 | return identityService; |
529 | |
} |
530 | |
|
531 | |
public void setPermissionService(IdentityManagementService permissionService) { |
532 | 0 | this.permissionService = permissionService; |
533 | 0 | } |
534 | |
|
535 | |
public IdentityManagementService getPermissionService()throws OperationFailedException{ |
536 | 0 | if(permissionService==null){ |
537 | 0 | throw new OperationFailedException("Permission Service is unavailable"); |
538 | |
} |
539 | |
|
540 | 0 | return permissionService; |
541 | |
} |
542 | |
} |