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