Coverage Report - org.kuali.student.core.workflow.ui.server.gwt.WorkflowRpcGwtServlet
 
Classes in this File Line Coverage Branch Coverage Complexity
WorkflowRpcGwtServlet
0%
0/253
0%
0/138
5.889
 
 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.IdentityService;
 24  
 import org.kuali.rice.kim.service.PermissionService;
 25  
 import org.kuali.student.common.ui.client.service.exceptions.OperationFailedException;
 26  
 import org.kuali.student.common.util.security.SecurityUtils;
 27  
 import org.kuali.student.core.rice.StudentIdentityConstants;
 28  
 import org.kuali.student.core.rice.StudentWorkflowConstants.ActionRequestType;
 29  
 import org.kuali.student.core.rice.authorization.PermissionType;
 30  
 import org.kuali.student.core.workflow.ui.client.service.WorkflowRpcService;
 31  
 
 32  
 import com.google.gwt.user.server.rpc.RemoteServiceServlet;
 33  
 
 34  0
 public class WorkflowRpcGwtServlet extends RemoteServiceServlet implements WorkflowRpcService {
 35  
 
 36  
         private static final long serialVersionUID = 1L;
 37  
 
 38  0
         final Logger LOG = Logger.getLogger(WorkflowRpcGwtServlet.class);
 39  
         
 40  
         private SimpleDocumentActionsWebService simpleDocService;
 41  
     private WorkflowUtility workflowUtilityService;
 42  
         private IdentityService identityService;
 43  
         private PermissionService permissionService;
 44  
 
 45  
         @Override
 46  
         public Boolean acknowledgeDocumentWithId(String workflowId) throws OperationFailedException {
 47  
                 try{
 48  
                         //get a user name
 49  0
             String username= SecurityUtils.getCurrentUserId();
 50  
 
 51  0
                 StandardResponse stdResp = getSimpleDocService().acknowledge(workflowId, username, "");
 52  
 
 53  0
                 if(stdResp==null||StringUtils.isNotBlank(stdResp.getErrorMessage())){
 54  0
                         throw new OperationFailedException("Error found acknowledging document: " + stdResp.getErrorMessage());
 55  
                 }
 56  
 
 57  0
                 }catch(OperationFailedException e){
 58  0
             LOG.error("Error acknowledging Document with workflow id:" + workflowId, e);
 59  0
             throw new OperationFailedException("Could not acknowledge");
 60  0
                 }
 61  0
         return Boolean.valueOf(true);
 62  
         }
 63  
 
 64  
         @Override
 65  
         public Boolean adhocRequest(String workflowId, String recipientPrincipalId,
 66  
                         ActionRequestType requestType, String annotation) throws OperationFailedException {
 67  
 
 68  
         try {
 69  
             //Get a user name
 70  0
             String username = SecurityUtils.getCurrentUserId();
 71  
 
 72  0
             String fyiAnnotation = "";
 73  0
             String approveAnnotation = "";
 74  0
             String ackAnnotation = "";
 75  
 
 76  0
             if (ActionRequestType.FYI.equals(requestType)) {
 77  0
                 StandardResponse stdResp = getSimpleDocService().requestAdHocFyiToPrincipal(workflowId,recipientPrincipalId, username, fyiAnnotation);
 78  0
                 if (stdResp == null || StringUtils.isNotBlank(stdResp.getErrorMessage())) {
 79  0
                     throw new OperationFailedException("Error found in Adhoc FYI: " + stdResp.getErrorMessage());
 80  
                 }
 81  
             }
 82  0
             if (ActionRequestType.APPROVE.equals(requestType)) {
 83  0
                 StandardResponse stdResp = getSimpleDocService().requestAdHocApproveToPrincipal(workflowId, recipientPrincipalId,username, approveAnnotation);
 84  0
                 if (stdResp == null || StringUtils.isNotBlank(stdResp.getErrorMessage())) {
 85  0
                     throw new OperationFailedException("Error found in Adhoc Approve: " + stdResp.getErrorMessage());
 86  
                 }
 87  
             }
 88  0
             if (ActionRequestType.ACKNOWLEDGE.equals(requestType)) {
 89  0
                 StandardResponse stdResp = getSimpleDocService().requestAdHocAckToPrincipal(workflowId,recipientPrincipalId,username, ackAnnotation);
 90  0
                 if (stdResp == null || StringUtils.isNotBlank(stdResp.getErrorMessage())) {
 91  0
                     throw new OperationFailedException("Error found in Adhoc Ack: " + stdResp.getErrorMessage());
 92  
                 }
 93  
             }
 94  
 
 95  0
         } catch (Exception e) {
 96  0
             LOG.error("Error adhoc routing",e);
 97  0
             throw new OperationFailedException("Could not adhoc route");
 98  0
         }
 99  0
         return  Boolean.valueOf(true);
 100  
         }
 101  
 
 102  
         @Override
 103  
         public Boolean approveDocumentWithId(String workflowId) throws OperationFailedException {
 104  
 
 105  
                 try{
 106  
             //get a user name
 107  0
             String username = SecurityUtils.getCurrentUserId();
 108  0
             StandardResponse stdResp = getSimpleDocService().approve(workflowId, username, null, null, "");
 109  0
             if(stdResp==null||StringUtils.isNotBlank(stdResp.getErrorMessage())){
 110  0
                         throw new OperationFailedException("Error found approving document: " + stdResp.getErrorMessage());
 111  
                 }
 112  
 
 113  0
                 }catch(Exception e){
 114  0
             LOG.error("Error approving document",e);
 115  0
             return Boolean.FALSE;
 116  0
                 }
 117  0
         return Boolean.TRUE;
 118  
         }
 119  
 
 120  
     @Override
 121  
     public Boolean blanketApproveDocumentWithId(String workflowId) throws OperationFailedException {
 122  
 
 123  
         try{
 124  
             //get a user name
 125  0
             String username = SecurityUtils.getCurrentUserId();
 126  0
             StandardResponse stdResp = getSimpleDocService().blanketApprove(workflowId, username, null, null, "");
 127  0
             if(stdResp==null||StringUtils.isNotBlank(stdResp.getErrorMessage())){
 128  0
                 throw new OperationFailedException("Error found blanket approving document: " + stdResp.getErrorMessage());
 129  
             }
 130  
 
 131  0
         }catch(Exception e){
 132  0
             LOG.error("Error blanket approving document",e);
 133  0
             return Boolean.FALSE;
 134  0
         }
 135  0
         return Boolean.TRUE;
 136  
     }
 137  
 
 138  
         @Override
 139  
         public Boolean disapproveDocumentWithId(String workflowId) {
 140  
 
 141  
                 try{
 142  
             //get a user name
 143  0
             String username = SecurityUtils.getCurrentUserId();
 144  0
                 String disapproveComment = "Disapproved";
 145  
 
 146  0
                 StandardResponse stdResp = getSimpleDocService().disapprove(workflowId, username, disapproveComment);
 147  0
                 if(stdResp==null||StringUtils.isNotBlank(stdResp.getErrorMessage())){
 148  0
                         LOG.error("Error  disapproving document: " + stdResp.getErrorMessage());
 149  0
                         return Boolean.FALSE;
 150  
                 }
 151  0
                 }catch(Exception e){
 152  0
             LOG.error("Error disapproving document",e);
 153  0
             return Boolean.FALSE;
 154  0
                 }
 155  0
                 return Boolean.TRUE;
 156  
         }
 157  
 
 158  
         @Override
 159  
         public Boolean fyiDocumentWithId(String workflowId) {
 160  
                 try{
 161  
             //get a user name
 162  0
             String username = SecurityUtils.getCurrentUserId();
 163  
 
 164  0
                 StandardResponse stdResp = getSimpleDocService().fyi(workflowId, username);
 165  0
                 if(stdResp==null||StringUtils.isNotBlank(stdResp.getErrorMessage())){
 166  0
                         LOG.error("Error FYIing document: " + stdResp.getErrorMessage());
 167  0
                         return Boolean.FALSE;
 168  
                 }
 169  0
                 }catch(Exception e){
 170  0
             LOG.error("Error FYIing document",e);
 171  0
             return Boolean.FALSE;
 172  0
                 }
 173  0
                 return Boolean.TRUE;
 174  
         }
 175  
 
 176  
         @Override
 177  
         public Boolean withdrawDocumentWithId(String workflowId) {
 178  0
         if(simpleDocService==null){
 179  0
                 LOG.error("Workflow Service is unavailable");
 180  0
                 return Boolean.FALSE;
 181  
         }
 182  
 
 183  
                 try{
 184  0
             String username = SecurityUtils.getCurrentUserId();
 185  0
                         KimPrincipalInfo systemPrincipal = getIdentityService().getPrincipalByPrincipalName(StudentIdentityConstants.SYSTEM_USER_PRINCIPAL_NAME);
 186  0
                         if (systemPrincipal == null) {
 187  0
                                 throw new RuntimeException("Cannot find principal for system user principal name: " + StudentIdentityConstants.SYSTEM_USER_PRINCIPAL_NAME);
 188  
                         }
 189  0
                         String annotation = "Document was withdrawn by " + username;
 190  
 
 191  0
                         StandardResponse stdResp = simpleDocService.superUserDisapprove(workflowId, systemPrincipal.getPrincipalId(), null, null, annotation);
 192  0
                 if(stdResp==null||StringUtils.isNotBlank(stdResp.getErrorMessage())) {
 193  0
                         LOG.error("Error withdrawing document: " + stdResp.getErrorMessage());
 194  0
                         return Boolean.FALSE;
 195  
                 }
 196  0
                 }catch(Exception e){
 197  0
             LOG.error("Error withdrawing document",e);
 198  0
             return Boolean.FALSE;
 199  0
                 }
 200  0
                 return Boolean.TRUE;
 201  
         }
 202  
         
 203  
         @Override
 204  
         public Boolean returnDocumentWithId(String workflowId, String nodeName) {
 205  
 
 206  
         try{
 207  
             //get the current user username
 208  0
             String username = SecurityUtils.getCurrentUserId();
 209  0
             StandardResponse stdResp = getSimpleDocService().returnToPreviousNode(workflowId, username, "", nodeName);
 210  0
             if(stdResp==null||StringUtils.isNotBlank(stdResp.getErrorMessage())){
 211  0
                 throw new OperationFailedException("Error found approving document: " + stdResp.getErrorMessage());
 212  
             }
 213  
 
 214  0
         }catch(Exception e){
 215  0
             LOG.error("Error approving document",e);
 216  0
             return Boolean.FALSE;
 217  0
         }
 218  0
         return Boolean.TRUE;
 219  
         }
 220  
 
 221  
     public List<String> getPreviousRouteNodeNames(String workflowId) throws OperationFailedException {
 222  
         try {
 223  0
             String[] nodeNames = getWorkflowUtilityService().getPreviousRouteNodeNames(Long.parseLong(workflowId));
 224  0
             return Arrays.asList(nodeNames);
 225  0
         } catch (Exception e) {
 226  0
             LOG.error("Error approving document",e);
 227  0
             throw new OperationFailedException("Error getting previous node names");
 228  
         }
 229  
     }
 230  
 
 231  
         @Override
 232  
         public String getActionsRequested(String workflowId) throws OperationFailedException {
 233  
         try{
 234  0
                     if(null==workflowId || workflowId.isEmpty()){
 235  0
                             LOG.info("No workflow id was provided.");
 236  0
                             return "";
 237  
                     }
 238  
 
 239  
             //get a user name
 240  0
             String principalId = SecurityUtils.getCurrentUserId();
 241  
 
 242  
                     //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"
 243  0
             LOG.debug("Calling action requested with user:"+principalId+" and workflowId:" + workflowId);
 244  
 
 245  0
             Map<String,String> results = new HashMap<String,String>();
 246  0
             AttributeSet kewActionsRequested = getWorkflowUtilityService().getActionsRequested(principalId, Long.parseLong(workflowId));
 247  0
             for (String key : kewActionsRequested.keySet()) {
 248  0
                     if ("true".equalsIgnoreCase(kewActionsRequested.get(key))) {
 249  0
                             results.put(key,"true");
 250  
                     }
 251  
             }
 252  
 
 253  
             //Use StringBuilder to avoid using string concatenations in the for loop.
 254  0
             StringBuilder actionsRequestedBuffer = new StringBuilder();
 255  
 
 256  0
             DocumentDetailDTO docDetail = getWorkflowUtilityService().getDocumentDetail(Long.parseLong(workflowId));
 257  
 
 258  0
             for(Map.Entry<String,String> entry:results.entrySet()){
 259  
                     // if saved or initiated status... must show only 'complete' button
 260  0
                     if (KEWConstants.ROUTE_HEADER_SAVED_CD.equals(docDetail.getDocRouteStatus()) || KEWConstants.ROUTE_HEADER_INITIATED_CD.equals(docDetail.getDocRouteStatus())) {
 261  
                             // show only complete button if complete or approve code in this doc status
 262  0
                             if ( (KEWConstants.ACTION_REQUEST_COMPLETE_REQ.equals(entry.getKey()) || KEWConstants.ACTION_REQUEST_APPROVE_REQ.equals(entry.getKey())) && ("true".equals(entry.getValue())) ) {
 263  0
                                     actionsRequestedBuffer.append("S");
 264  0
                         actionsRequestedBuffer.append("C");
 265  
                             }
 266  
                             // if not Complete or Approve code then show the standard buttons
 267  
                             else {
 268  0
                                 if("true".equals(entry.getValue())){
 269  0
                                         actionsRequestedBuffer.append(entry.getKey());
 270  
                                 }
 271  
                             }
 272  
                     }
 273  
                     else {
 274  0
                         if("true".equals(entry.getValue())){
 275  0
                                 actionsRequestedBuffer.append(entry.getKey());
 276  
                         // show the return to previous button if there is a COMPLETE or APPROVE action request
 277  0
                         if ( (KEWConstants.ACTION_REQUEST_COMPLETE_REQ.equals(entry.getKey()) || KEWConstants.ACTION_REQUEST_APPROVE_REQ.equals(entry.getKey())) && ("true".equals(entry.getValue())) ) {
 278  0
                             actionsRequestedBuffer.append("R");
 279  
                         }
 280  
                         }
 281  
                     }
 282  
             }
 283  
 
 284  0
             String docTypeName = getWorkflowUtilityService().getDocumentType(docDetail.getDocTypeId()).getName();
 285  
             // if user can withdraw document then add withdraw button
 286  0
             AttributeSet permDetails = new AttributeSet();
 287  0
             permDetails.put(StudentIdentityConstants.DOCUMENT_TYPE_NAME,docTypeName);
 288  0
             permDetails.put(StudentIdentityConstants.ROUTE_STATUS_CODE,docDetail.getDocRouteStatus());
 289  0
             if (getPermissionService().isAuthorizedByTemplateName(principalId, 
 290  
                             PermissionType.WITHDRAW.getPermissionNamespace(), 
 291  
                             PermissionType.WITHDRAW.getPermissionTemplateName(), permDetails, 
 292  
                             new AttributeSet(StudentIdentityConstants.DOCUMENT_NUMBER,workflowId))) {
 293  0
                     LOG.info("User '" + principalId + "' is allowed to Withdraw the Document");
 294  0
                     actionsRequestedBuffer.append("W");
 295  
             }
 296  
 
 297  0
             Map<String,String> permDetails2 = new HashMap<String,String>();
 298  0
             permDetails2.put(StudentIdentityConstants.DOCUMENT_TYPE_NAME,docTypeName);
 299  0
             permDetails2.put(StudentIdentityConstants.ROUTE_STATUS_CODE,docDetail.getDocRouteStatus());
 300  
             // first check permission with no node name
 301  0
             boolean canBlanketApprove = getPermissionService().isAuthorizedByTemplateName(principalId, 
 302  
                     PermissionType.BLANKET_APPROVE.getPermissionNamespace(), 
 303  
                     PermissionType.BLANKET_APPROVE.getPermissionTemplateName(), new AttributeSet(permDetails2), 
 304  
                     new AttributeSet(StudentIdentityConstants.DOCUMENT_NUMBER,workflowId));
 305  0
             for (String nodeName : getCurrentActiveNodeNames(docDetail.getRouteHeaderId())) {
 306  0
                 if (canBlanketApprove) {
 307  0
                     break;
 308  
                 }
 309  0
                 AttributeSet newSet = new AttributeSet(permDetails2);
 310  0
                 newSet.put(StudentIdentityConstants.ROUTE_NODE_NAME, nodeName);
 311  0
                 canBlanketApprove = getPermissionService().isAuthorizedByTemplateName(principalId, 
 312  
                         PermissionType.BLANKET_APPROVE.getPermissionNamespace(), 
 313  
                         PermissionType.BLANKET_APPROVE.getPermissionTemplateName(), newSet, 
 314  
                         new AttributeSet(StudentIdentityConstants.DOCUMENT_NUMBER,workflowId));
 315  0
             }
 316  0
             if (canBlanketApprove) {
 317  0
                 LOG.info("User '" + principalId + "' is allowed to Blanket Approve the Document");
 318  0
                 actionsRequestedBuffer.append("B");
 319  
             }
 320  
 
 321  0
             return actionsRequestedBuffer.toString();
 322  0
         } catch (Exception e) {
 323  0
                 LOG.error("Error getting actions Requested",e);
 324  0
             throw new OperationFailedException("Error getting actions Requested");
 325  
         }
 326  
         }
 327  
 
 328  
         protected List<String> getCurrentActiveNodeNames(Long routeHeaderId) throws OperationFailedException, WorkflowException {
 329  0
         List<String> currentActiveNodeNames = new ArrayList<String>();
 330  0
         RouteNodeInstanceDTO[] nodeInstances = getWorkflowUtilityService().getActiveNodeInstances(routeHeaderId);
 331  0
         for (RouteNodeInstanceDTO routeNodeInstanceDTO : nodeInstances) {
 332  0
             currentActiveNodeNames.add(routeNodeInstanceDTO.getName());
 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.getCurrentUserId();
 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.getCurrentUserId();
 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.getCurrentUserId();
 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(getPermissionService().isAuthorizedByTemplateName(SecurityUtils.getCurrentUserId(), 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 = getPermissionService().isAuthorizedByTemplateName(SecurityUtils.getCurrentUserId(), 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(IdentityService identityService) {
 521  0
                 this.identityService = identityService;
 522  0
         }
 523  
 
 524  
         public IdentityService 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  
 
 532  
         public void setPermissionService(PermissionService permissionService) {
 533  0
                 this.permissionService = permissionService;
 534  0
         }
 535  
 
 536  
         public PermissionService getPermissionService()throws OperationFailedException{
 537  0
                 if(permissionService==null){
 538  0
                 throw new OperationFailedException("Permission Service is unavailable");
 539  
         }
 540  
 
 541  0
                 return permissionService;
 542  
         }
 543  
 }