Coverage Report - org.kuali.rice.kew.webservice.impl.SimpleDocumentActionsWebServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
SimpleDocumentActionsWebServiceImpl
0%
0/400
0%
0/62
2.561
 
 1  
 /*
 2  
  * Copyright 2005-2007 The Kuali Foundation
 3  
  * 
 4  
  * 
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  * 
 9  
  * http://www.opensource.org/licenses/ecl2.php
 10  
  * 
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.kuali.rice.kew.webservice.impl;
 18  
 
 19  
 import java.sql.Timestamp;
 20  
 import java.text.DateFormat;
 21  
 import java.text.SimpleDateFormat;
 22  
 import java.util.ArrayList;
 23  
 import java.util.Calendar;
 24  
 import java.util.GregorianCalendar;
 25  
 import java.util.List;
 26  
 
 27  
 import javax.jws.WebService;
 28  
 
 29  
 import org.apache.commons.lang.StringUtils;
 30  
 import org.kuali.rice.core.framework.persistence.jdbc.sql.SQLUtils;
 31  
 import org.kuali.rice.kew.dto.AdHocRevokeDTO;
 32  
 import org.kuali.rice.kew.dto.NoteDTO;
 33  
 import org.kuali.rice.kew.dto.RouteHeaderDTO;
 34  
 import org.kuali.rice.kew.exception.WorkflowException;
 35  
 import org.kuali.rice.kew.exception.WorkflowServiceErrorException;
 36  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 37  
 import org.kuali.rice.kew.service.WorkflowDocument;
 38  
 import org.kuali.rice.kew.service.WorkflowInfo;
 39  
 import org.kuali.rice.kew.util.KEWConstants;
 40  
 import org.kuali.rice.kew.util.KEWWebServiceConstants;
 41  
 import org.kuali.rice.kew.webservice.DocumentResponse;
 42  
 import org.kuali.rice.kew.webservice.ErrorResponse;
 43  
 import org.kuali.rice.kew.webservice.NoteDetail;
 44  
 import org.kuali.rice.kew.webservice.NoteResponse;
 45  
 import org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService;
 46  
 import org.kuali.rice.kew.webservice.StandardResponse;
 47  
 import org.kuali.rice.kew.webservice.UserInRouteLogResponse;
 48  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 49  
 import org.kuali.rice.kim.bo.Person;
 50  
 
 51  
 
 52  
 /**
 53  
  * Implementation of the SimpleDocumentActionsWebService
 54  
  *
 55  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 56  
  */
 57  
 @WebService(endpointInterface = KEWWebServiceConstants.SimpleDocumentActionsWebService.INTERFACE_CLASS,
 58  
         serviceName = KEWWebServiceConstants.SimpleDocumentActionsWebService.WEB_SERVICE_NAME,
 59  
         portName = KEWWebServiceConstants.SimpleDocumentActionsWebService.WEB_SERVICE_PORT,
 60  
         targetNamespace = KEWWebServiceConstants.MODULE_TARGET_NAMESPACE)
 61  0
 public class SimpleDocumentActionsWebServiceImpl implements SimpleDocumentActionsWebService {
 62  
 
 63  
         /**
 64  
          * <ol>
 65  
          * <li>Create a WorkflowDocument based on the docId and principalId passed in</li>
 66  
          * <li>Acknowledge the document with the passed in annotation</li>
 67  
          * <li>Return the standard set of return values.</li>
 68  
          * </ol>
 69  
          *
 70  
          * @param docId KEW document id of the document to acknowledge
 71  
          * @param principalId principal id of the user who is acknowledging the document
 72  
          * @param annotation a comment associated with this request
 73  
          * @return Map including the standard set of return values
 74  
          *
 75  
          * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#acknowledge(java.lang.String, java.lang.String, java.lang.String)
 76  
          */
 77  
         @Override
 78  
         public StandardResponse acknowledge(String docId, String principalId, String annotation) {
 79  
         StandardResponse results;
 80  
 
 81  
                try {
 82  0
                         WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId);
 83  
 
 84  0
                         workflowDocument.acknowledge(annotation);
 85  0
                         results = createResults(workflowDocument);
 86  0
                 } catch (WorkflowException e) {
 87  0
                         results = createErrorResults("Workflow Error: " + e.getLocalizedMessage());
 88  0
                 }
 89  
 
 90  0
                 return results;
 91  
         }
 92  
 
 93  
         /**
 94  
          * <ol>
 95  
          * <li>Create a WorkflowDocument based on the docId and principalId passed in</li>
 96  
          * <li>Set the docTitle and docContent if they are passed in</li>
 97  
          * <li>Approve the document with the passed in annotation</li>
 98  
          * <li>Return the standard set of return values</li>
 99  
          * </ol>
 100  
          *
 101  
          * @param docId KEW document id of the document to approve
 102  
          * @param principalId principal id of the user who is approving the document
 103  
          * @param docTitle title for this document
 104  
          * @param docContent xml content for this document
 105  
          * @param annotation a comment associated with this request
 106  
          * @return Map including the standard set of return values
 107  
          *
 108  
          * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#approve(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 109  
          */
 110  
         @Override
 111  
         public StandardResponse approve(String docId, String principalId, String docTitle,
 112  
                         String docContent, String annotation) {
 113  
           //Map<String, Object> results;
 114  
         StandardResponse results;
 115  
 
 116  
                try {
 117  0
                         WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId, docTitle, docContent);
 118  
 
 119  0
                         workflowDocument.approve(annotation);
 120  0
                         results = createResults(workflowDocument);
 121  0
                 } catch (WorkflowException e) {
 122  0
                         results = createErrorResults("Workflow Error: " + e.getLocalizedMessage());
 123  0
                 }
 124  
 
 125  0
                 return results;
 126  
         }
 127  
 
 128  
         /**
 129  
          * <ol>
 130  
          * <li>Create a WorkflowDocument based on the docId and principalId passed in</li>
 131  
          * <li>Set the docTitle and docContent if they are passed in</li>
 132  
          * <li>Blanket Approve the document with the passed in annotation</li>
 133  
          * <li>Return the standard set of return values</li>
 134  
          * </ol>
 135  
          *
 136  
          * Blanket Approval means all future approval requests will be satisfied
 137  
          * Can only be performed by a super user.
 138  
          *
 139  
          * @param docId KEW document id of the document to blanket approve
 140  
          * @param principalId principal id of the user who is blanket approving the document
 141  
          * @param docTitle title for this document
 142  
          * @param docContent xml content for this document
 143  
          * @param annotation a comment associated with this request
 144  
          * @return Map including the standard set of return values
 145  
          *
 146  
          * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#blanketApprove(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 147  
          */
 148  
         @Override
 149  
         public StandardResponse blanketApprove(String docId, String principalId, String docTitle,
 150  
                         String docContent, String annotation) {
 151  
           //Map<String, Object> results;
 152  
         StandardResponse results;
 153  
 
 154  
                try {
 155  0
                         WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId, docTitle, docContent);
 156  
 
 157  0
                         workflowDocument.blanketApprove(annotation);
 158  0
                         results = createResults(workflowDocument);
 159  0
                 } catch (WorkflowException e) {
 160  0
                         results = createErrorResults("Workflow Error: " + e.getLocalizedMessage());
 161  0
                 }
 162  
 
 163  0
                 return results;
 164  
         }
 165  
 
 166  
         /**
 167  
          * <ol>
 168  
          * <li>Create a WorkflowDocument based on the docId and principalId passed in</li>
 169  
          * <li>Cancel the document with the passed in annotation</li>
 170  
          * <li>Return the standard set of return values</li>
 171  
          * </ol>
 172  
          *
 173  
          * @param docId KEW document id of the document to cancel
 174  
          * @param principalId principal id of the user who is canceling the document
 175  
          * @param annotation a comment associated with this request
 176  
          * @return Map including the standard set of return values
 177  
          * 
 178  
          * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#cancel(java.lang.String, java.lang.String, java.lang.String)
 179  
          */
 180  
         @Override
 181  
         public StandardResponse cancel(String docId, String principalId, String annotation) {
 182  
                 //Map<String, Object> results;
 183  
             StandardResponse results;
 184  
                try {
 185  0
                         WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId);
 186  
 
 187  0
                         workflowDocument.cancel(annotation);
 188  0
                         results = createResults(workflowDocument);
 189  0
                 } catch (WorkflowException e) {
 190  0
                         results = createErrorResults("Workflow Error: " + e.getLocalizedMessage());
 191  0
                 }
 192  
 
 193  0
                 return results;
 194  
         }
 195  
 
 196  
         /**
 197  
          * <ol>
 198  
          * <li>Create a WorkflowDocument with the docType and principalId passed in</li>
 199  
          * <li>Set the document title to be the docTitle that was passed in</li
 200  
          * <li>Save the Routing data (Route Header info)</li>
 201  
          * <li>Return the standard set of return values and the docId of the newly created document</li>
 202  
          * </ol>
 203  
          *
 204  
          * @param initiatorPrincipalId principal id of the document initiator
 205  
          * @param appDocId application specific document id
 206  
          * @param docType KEW document type for the document to be created
 207  
          * @param docTitle title for this document
 208  
          * @return Map including the standard set of return values and the docId of the newly created document
 209  
          *
 210  
          * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#create(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 211  
          */
 212  
         @Override
 213  
         public DocumentResponse create(String initiatorPrincipalId, String appDocId, String docType,
 214  
                         String docTitle) {
 215  
 
 216  
             // Map<String, Object> results;
 217  
         StandardResponse results;
 218  
 
 219  0
                 String docId = "";
 220  
 
 221  
                 try {
 222  0
                         WorkflowDocument workflowDocument = WorkflowDocument.createDocument(initiatorPrincipalId, docType);
 223  0
                         workflowDocument.setTitle(docTitle);
 224  0
                         workflowDocument.setAppDocId(appDocId);
 225  0
                         workflowDocument.saveRoutingData();
 226  
 
 227  0
                         results = createResults(workflowDocument);
 228  0
                         if (workflowDocument.getDocumentId() != null) {
 229  0
                                 docId = workflowDocument.getDocumentId();
 230  
                         }
 231  0
                 DocumentResponse docResponse = new DocumentResponse(results);
 232  0
                 docResponse.setDocId(docId);
 233  0
                 docResponse.setDocContent(workflowDocument.getApplicationContent());
 234  0
                 docResponse.setTitle(workflowDocument.getTitle());
 235  0
                 docResponse.setNotes(new ArrayList<NoteDetail>());
 236  0
             if (workflowDocument.isApprovalRequested()) {
 237  0
                 docResponse.setActionRequested(KEWConstants.ACTION_REQUEST_APPROVE_REQ_LABEL);
 238  0
             } else if (workflowDocument.isAcknowledgeRequested()) {
 239  0
                 docResponse.setActionRequested(KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ_LABEL);
 240  0
             } else if (workflowDocument.isFYIRequested()) {
 241  0
                 docResponse.setActionRequested(KEWConstants.ACTION_REQUEST_FYI_REQ_LABEL);
 242  0
             } else if (workflowDocument.isCompletionRequested()) {
 243  
                 // TODO: how do we want to handle a "Complete" request?
 244  0
                 docResponse.setActionRequested(KEWConstants.ACTION_REQUEST_COMPLETE_REQ_LABEL);
 245  
             }
 246  0
                 return docResponse;
 247  0
                 } catch (WorkflowException e) {
 248  0
                         results = createErrorResults("Workflow Error: " + e.getLocalizedMessage());
 249  0
                 DocumentResponse docResponse = new DocumentResponse(results);
 250  0
                 docResponse.setDocId(docId);
 251  0
                 return docResponse;
 252  
                 }
 253  
         }
 254  
 
 255  
         /**
 256  
           * <ol>
 257  
          * <li>Create a WorkflowDocument based on the docId and principalId passed in</li>
 258  
          * <li>Disapprove the document with the passed in annotation</li>
 259  
          * <li>Return the standard set of return values</li>
 260  
          * </ol>
 261  
          *
 262  
          * @param docId KEW document id of the document to disapprove
 263  
          * @param principalId principal id of the user who is disapproving the document
 264  
          * @param annotation a comment associated with this request
 265  
          * @return Map including the standard set of return values
 266  
          *
 267  
          * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#disapprove(java.lang.String, java.lang.String, java.lang.String)
 268  
          */
 269  
         @Override
 270  
         public StandardResponse disapprove(String docId, String principalId, String annotation) {
 271  
 //      Map<String, Object> results;
 272  
         StandardResponse results;
 273  
 
 274  
                try {
 275  0
                         WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId);
 276  
 
 277  0
                         workflowDocument.disapprove(annotation);
 278  0
                         results = createResults(workflowDocument);
 279  0
                 } catch (WorkflowException e) {
 280  0
                         results = createErrorResults("Workflow Error: " + e.getLocalizedMessage());
 281  0
                 }
 282  
 
 283  0
                 return results;
 284  
         }
 285  
 
 286  
         /**
 287  
           * <ol>
 288  
          * <li>Create a WorkflowDocument based on the docId and principalId passed in</li>
 289  
          * <li>Clear the FYI request on the document</li>
 290  
          * <li>Return the standard set of return values</li>
 291  
          * </ol>
 292  
          *
 293  
          * @param docId KEW document id of the document to acknowledge
 294  
          * @param principalId principal id of the user who is acknowledging the document
 295  
          * @return Map including the standard set of return values
 296  
          *
 297  
          * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#fyi(java.lang.String, java.lang.String)
 298  
          */
 299  
         @Override
 300  
         public StandardResponse fyi(String docId, String principalId) {
 301  
 //                Map<String, Object> results;
 302  
             StandardResponse results;
 303  
             
 304  
                try {
 305  0
                         WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId);
 306  
 
 307  0
                         workflowDocument.fyi();
 308  0
                         results = createResults(workflowDocument);
 309  0
                 } catch (WorkflowException e) {
 310  0
                         results = createErrorResults("Workflow Error: " + e.getLocalizedMessage());
 311  0
                 }
 312  
 
 313  0
                 return results;
 314  
         }
 315  
 
 316  
         /**
 317  
           * <ol>
 318  
          * <li>Create a WorkflowDocument based on the docId and principalId passed in</li>
 319  
          * <li>Get the document content and the action requested (Approve, Acknowledge, etc) of the user</li>
 320  
          * <li>Return the standard set of return values, the docContent, the title,
 321  
          * and the actionRequested</li>
 322  
          * </ol>
 323  
          *
 324  
          * @param docId KEW document id of the document to retrieve information about
 325  
          * @param principalId principal id of the user to retrieve the document for
 326  
          * @return Map including the standard set of return values, the xml document content,
 327  
          * the action requested ( Approve, Acknowledge, Fyi, Complete ) and an array of Maps
 328  
          * containing the following for each Note (author, noteId, timestamp, noteText).
 329  
          *
 330  
          * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#getDocument(java.lang.String, java.lang.String)
 331  
          */
 332  
         @Override
 333  
         public DocumentResponse getDocument(String docId, String principalId) {
 334  
 //                Map<String, Object> results;
 335  
                 StandardResponse results;
 336  0
             List<NoteDetail> noteDetails = new ArrayList<NoteDetail>(0);
 337  0
                 String actionRequested = "";
 338  0
                 String docContent = "";
 339  0
                 String title = "";
 340  
 
 341  
                 try {
 342  0
                         WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId);
 343  0
                         RouteHeaderDTO routeHeader = workflowDocument.getRouteHeader();
 344  
 
 345  0
                         if (routeHeader == null) {
 346  0
                                 results = createErrorResults("Error: NULL Route Header");
 347  
                         } else {
 348  0
                                 results = createStandardResults(routeHeader);
 349  0
                                 docContent = workflowDocument.getApplicationContent();
 350  0
                                 title = workflowDocument.getTitle();
 351  0
                                 List notes = workflowDocument.getNoteList();
 352  0
                                 noteDetails = buildNoteDetails(notes);
 353  
 
 354  0
                                 if (routeHeader.isApproveRequested()) {
 355  0
                                         actionRequested = KEWConstants.ACTION_REQUEST_APPROVE_REQ_LABEL;
 356  0
                                 } else if (routeHeader.isAckRequested()) {
 357  0
                                         actionRequested = KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ_LABEL;
 358  0
                                 } else if (routeHeader.isFyiRequested()) {
 359  0
                                         actionRequested = KEWConstants.ACTION_REQUEST_FYI_REQ_LABEL;
 360  0
                                 } else if (routeHeader.isCompleteRequested()) {
 361  
                                         // TODO: how do we want to handle a "Complete" request?
 362  0
                                         actionRequested = KEWConstants.ACTION_REQUEST_COMPLETE_REQ_LABEL;
 363  
                                 }
 364  
                         }
 365  0
                 } catch (WorkflowException e) {
 366  0
                         results = createErrorResults("Workflow Error: " + e.getLocalizedMessage());
 367  0
                 }
 368  
 
 369  0
                 DocumentResponse docResponse = new DocumentResponse(results);
 370  
                 
 371  
 //                results.put(DOC_CONTENT_LABEL, docContent);
 372  
 //                results.put(TITLE_LABEL, title);
 373  
 //                results.put(NOTES_LABEL, noteDetails);
 374  
 //                results.put(ACTION_REQUESTED_LABEL, actionRequested);
 375  
 
 376  0
                 docResponse.setDocId(docId);
 377  0
                 docResponse.setDocContent(docContent);
 378  0
                 docResponse.setTitle(title);
 379  0
                 docResponse.setNotes(noteDetails);
 380  0
                 docResponse.setActionRequested(actionRequested);
 381  
                 
 382  0
                 return docResponse;
 383  
         }
 384  
 
 385  
         /**
 386  
            * <ol>
 387  
          * <li>Create a new WorkflowInfo object</li>
 388  
          * <li>Call isUserAuthenticatedByRouteLog on the WorkflowInfo object to see if the user is in the route log</li>
 389  
          * <li>Return True/False and an error message if any</li>
 390  
          * </ol>
 391  
          * Useful for security purposes (if return is False, user shouldn't
 392  
          * be able to see the document unless it's public.)
 393  
          *
 394  
          * Call isUserAuthenticatedByRouteLog with true for the lookFuture parameter so that
 395  
          * we will check future workflow requests as well as currently outstanding requests.
 396  
          *
 397  
          * @param docId KEW document id of the document to check
 398  
          * @param principalId principal id of the user to check
 399  
          * @return Map containing True/False for isUserInRouteLog and an error message if
 400  
          * a problem occured
 401  
          *
 402  
          * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#isUserInRouteLog(java.lang.String, java.lang.String)
 403  
          */
 404  
         @Override
 405  
         public UserInRouteLogResponse isUserInRouteLog(String docId, String principalId) {
 406  
                 //Map<String, Object> results = new HashMap<String, Object>(6);
 407  
                 
 408  0
             UserInRouteLogResponse results = new UserInRouteLogResponse();
 409  0
             String errorMessage = "";
 410  0
                 boolean isUserInRouteLog = false;
 411  0
                 WorkflowInfo info = new WorkflowInfo();
 412  
                 try {
 413  0
                         isUserInRouteLog = info.isUserAuthenticatedByRouteLog(docId, principalId, true);
 414  0
                 } catch (NumberFormatException e) {
 415  0
                         errorMessage = "Invalid (non-numeric) docId";
 416  0
                 } catch (WorkflowException e) {
 417  0
                         errorMessage = "Workflow Error: " + e.getLocalizedMessage();
 418  0
                 }
 419  
                 
 420  0
                 results.setIsUserInRouteLog(String.valueOf(isUserInRouteLog));
 421  0
                 results.setErrorMessage(errorMessage);
 422  0
                 return results;
 423  
         }
 424  
 
 425  
         /**
 426  
           * <ol>
 427  
          * <li>Create a WorkflowDocument based on the docId and principalId passed in</li>
 428  
          * <li>Add the adhoc acknowlege request (app specific route) to the passed in group with the passed in annotation</li>
 429  
          * <li>Return the standard set of return values</li>
 430  
          * </ol>
 431  
          *
 432  
          * @param docId KEW document id of the document to create the adhoc request for
 433  
          * @param principalId principal id of the user who is making this request
 434  
          * @param recipientGroupId workgroupId of the group to create this request for
 435  
          * @param annotation a comment associated with this request
 436  
          * @return Map including the standard set of return values
 437  
          *
 438  
          * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#requestAdHocAckToGroup(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 439  
          */
 440  
         @Override
 441  
         public StandardResponse requestAdHocAckToGroup(String docId, String principalId,
 442  
                         String recipientGroupId, String annotation) {
 443  0
                 return requestAdHocToGroup(docId, principalId, recipientGroupId, annotation, KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ_LABEL);
 444  
         }
 445  
 
 446  
         /**
 447  
           * <ol>
 448  
          * <li>Create a WorkflowDocument based on the docId and principalId passed in</li>
 449  
          * <li>Add the adhoc acknowlege request (app specific route) to the passed in user with the passed in annotation</li>
 450  
          * <li>Return the standard set of return values</li>
 451  
          * </ol>
 452  
          *
 453  
          * @param docId KEW document id of the document to create the adhoc request for
 454  
          * @param principalId principal id of the user who is making this request
 455  
          * @param recipientPrincipalId principal id of the user for whom the request is being created
 456  
          * @param annotation a comment associated with this request
 457  
          * @return Map including the standard set of return values
 458  
          */
 459  
         @Override
 460  
         public StandardResponse requestAdHocAckToPrincipal(String docId, String principalId,
 461  
                         String recipientPrincipalId, String annotation) {
 462  0
                 return requestAdHocToPrincipal(docId, principalId, recipientPrincipalId, annotation, KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ_LABEL);
 463  
         }
 464  
 
 465  
         /**
 466  
           * <ol>
 467  
          * <li>Create a WorkflowDocument based on the docId and principalId passed in</li>
 468  
          * <li>Add the adhoc approve request (app specific route) to the passed in group with the passed in annotation</li>
 469  
          * <li>Return the standard set of return values</li>
 470  
          * </ol>
 471  
          *
 472  
          * @param docId KEW document id of the document to create the adhoc request for
 473  
          * @param principalId principal id of the user who is making this request
 474  
          * @param recipientGroupId workgroupId of the group to create this request for
 475  
          * @param annotation a comment associated with this request
 476  
          * @return Map including the standard set of return values
 477  
          *
 478  
          * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#requestAdHocApproveToGroup(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 479  
          */
 480  
         @Override
 481  
         public StandardResponse requestAdHocApproveToGroup(String docId, String principalId,
 482  
                         String recipientGroupId, String annotation) {
 483  0
                 return requestAdHocToGroup(docId, principalId, recipientGroupId, annotation, KEWConstants.ACTION_REQUEST_APPROVE_REQ, KEWConstants.ACTION_REQUEST_APPROVE_REQ_LABEL);
 484  
         }
 485  
 
 486  
         /**
 487  
           * <ol>
 488  
          * <li>Create a WorkflowDocument based on the docId and principalId passed in</li>
 489  
          * <li>Add the adhoc approve request (app specific route) to the passed in user with the passed in annotation</li>
 490  
          * <li>Return the standard set of return values</li>
 491  
          * </ol>
 492  
          *
 493  
          * @param docId KEW document id of the document to create the adhoc request for
 494  
          * @param principalId principal id of the user who is making this request
 495  
          * @param recipientPrincipalId principal id of the user for whom the request is being created
 496  
          * @param annotation a comment associated with this request
 497  
          * @return Map including the standard set of return values
 498  
          */
 499  
         @Override
 500  
         public StandardResponse requestAdHocApproveToPrincipal(String docId, String principalId,
 501  
                         String recipientPrincipalId, String annotation) {
 502  
 
 503  0
                 return requestAdHocToPrincipal(docId, principalId, recipientPrincipalId, annotation, KEWConstants.ACTION_REQUEST_APPROVE_REQ, KEWConstants.ACTION_REQUEST_APPROVE_REQ_LABEL);
 504  
         }
 505  
 
 506  
         /**
 507  
           * <ol>
 508  
          * <li>Create a WorkflowDocument based on the docId and principalId passed in</li>
 509  
          * <li>Add the adhoc fyi request (app specific route) to the passed in group with the passed in annotation</li>
 510  
          * <li>Return the standard set of return values</li>
 511  
          * </ol>
 512  
          *
 513  
          * @param docId KEW document id of the document to create the adhoc request for
 514  
          * @param principalId principal id of the user who is making this request
 515  
          * @param recipientGroupId workgroupId of the group to create this request for
 516  
          * @param annotation a comment associated with this request
 517  
          * @return Map including the standard set of return values
 518  
          *
 519  
          * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#requestAdHocFyiToGroup(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 520  
          */
 521  
         @Override
 522  
         public StandardResponse requestAdHocFyiToGroup(String docId, String principalId, String recipientGroupId, String annotation) {
 523  0
                 return requestAdHocToGroup(docId, principalId, recipientGroupId, annotation, KEWConstants.ACTION_REQUEST_FYI_REQ, KEWConstants.ACTION_REQUEST_FYI_REQ_LABEL);
 524  
         }
 525  
 
 526  
         /**
 527  
           * <ol>
 528  
          * <li>Create a WorkflowDocument based on the docId and principalId passed in</li>
 529  
          * <li>Add the adhoc fyi request (app specific route) to the passed in user with the passed in annotation</li>
 530  
          * <li>Return the standard set of return values</li>
 531  
          * </ol>
 532  
          *
 533  
          * @param docId KEW document id of the document to create the adhoc request for
 534  
          * @param principalId principal id of the user who is making this request
 535  
          * @param recipientPrincipalId principal id of the user for whom the request is being created
 536  
          * @param annotation a comment associated with this request
 537  
          * @return Map including the standard set of return values
 538  
          */
 539  
         @Override
 540  
         public StandardResponse requestAdHocFyiToPrincipal(String docId, String principalId,
 541  
                         String recipientPrincipalId, String annotation) {
 542  0
                 return requestAdHocToPrincipal(docId, principalId, recipientPrincipalId, annotation, KEWConstants.ACTION_REQUEST_FYI_REQ, KEWConstants.ACTION_REQUEST_FYI_REQ_LABEL);
 543  
         }
 544  
 
 545  
         /**
 546  
          * Create the adhoc request for the specified group.
 547  
          *
 548  
           * @param docId KEW document id of the document to create the adhoc request for
 549  
          * @param principalId principal id of the user who is making this request
 550  
          * @param recipientGroupId workflowid of the group for whom the request is being created
 551  
          * @param annotation a comment associated with this request
 552  
          * @param actionRequested the action for this adhoc request ( A)pprove, aK)nowledge, F)yi )
 553  
          * @param responsibilityDesc description of the type of responsibility for this request
 554  
          * @return Map including the standard set of return values
 555  
          */
 556  
         private StandardResponse requestAdHocToGroup(String docId, String principalId,
 557  
                         String groupId, String annotation, String actionRequested, String responsibilityDesc) {
 558  
 //      Map<String, Object> results;
 559  
         StandardResponse results;
 560  
 
 561  
                try {
 562  0
                         WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId);
 563  0
                         workflowDocument.adHocRouteDocumentToGroup(actionRequested, annotation, groupId, responsibilityDesc, true);
 564  0
                         results = createResults(workflowDocument);
 565  0
                 } catch (WorkflowException e) {
 566  0
                         results = createErrorResults("Workflow Error: " + e.getLocalizedMessage());
 567  0
                 }
 568  
 
 569  0
                 return results;
 570  
         }
 571  
 
 572  
         /**
 573  
          * Create the adhoc request for the specified user.
 574  
          *
 575  
           * @param docId KEW document id of the document to create the adhoc request for
 576  
          * @param principalId principal id of the user who is making this request
 577  
          * @param recipientPrincipalId principal id of the user for whom the request is being created
 578  
          * @param annotation a comment associated with this request
 579  
          * @param actionRequested the action for this adhoc request ( A)pprove, aK)nowledge, F)yi )
 580  
          * @param responsibilityDesc description of the type of responsibility for this request
 581  
          * @return Map including the standard set of return values
 582  
          */
 583  
         private StandardResponse requestAdHocToPrincipal(String docId, String principalId,
 584  
                         String recipientPrincipalId, String annotation, String actionRequested, String responsibilityDesc) {
 585  
             StandardResponse results;            
 586  
                try {
 587  0
                         WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId);
 588  0
                         workflowDocument.adHocRouteDocumentToPrincipal(actionRequested, annotation, recipientPrincipalId, responsibilityDesc, true);
 589  0
                         results = createResults(workflowDocument);
 590  0
                 } catch (WorkflowException e) {
 591  0
                         results = createErrorResults("Workflow Error: " + e.getLocalizedMessage());
 592  0
                 }
 593  0
                 return results;
 594  
         }
 595  
 
 596  
         /**
 597  
          * <ol>
 598  
          * <li>Create a WorkflowDocument based on the docId and principalId passed in</li>
 599  
          * <li>Set the docTitle and docContent if they are passed in</li>
 600  
          * <li>Route the document with the passed in annotation</li>
 601  
          * <li>Return the standard set of return values.</li>
 602  
          * </ol>
 603  
          *
 604  
          * @param docId KEW document id of the document to route
 605  
          * @param principalId principal id of the user who is routing the document
 606  
          * @param docTitle title for this document
 607  
          * @param docContent xml content for this document
 608  
          * @param annotation a comment associated with this request
 609  
          * @return Map including the standard set of return values
 610  
          *
 611  
          * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#route(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 612  
          */
 613  
         @Override
 614  
         public StandardResponse route(String docId, String principalId, String docTitle,
 615  
                         String docContent, String annotation) {
 616  
 
 617  
                 //Map<String, Object> results;
 618  
             StandardResponse results;
 619  
             
 620  
                try {
 621  0
                         WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId, docTitle, docContent);
 622  
 
 623  0
                         workflowDocument.routeDocument(annotation);
 624  0
                         results = createResults(workflowDocument);
 625  0
                 } catch (WorkflowException e) {
 626  0
                         results = createErrorResults("Workflow Error: " + e.getLocalizedMessage());
 627  0
                 }
 628  
 
 629  0
                 return results;
 630  
         }
 631  
 
 632  
         /**
 633  
           * <ol>
 634  
          * <li>Create a WorkflowDocument based on the docId and principalId passed in</li>
 635  
          * <li>Set the docTitle if it was passed in</li>
 636  
          * <li>Save the document with the passed in annotation (keep in user's action list)</li>
 637  
          * <li>Return the standard set of return values.</li>
 638  
          * </ol>
 639  
          *
 640  
          * @param docId KEW document id of the document to save
 641  
          * @param principalId principal id of the user who is saving the document
 642  
          * @param docTitle title for this document
 643  
          * @param docContent xml content for this document
 644  
          * @param annotation a comment associated with this request
 645  
          * @return Map including the standard set of return values
 646  
          *
 647  
          * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#save(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 648  
          */
 649  
         @Override
 650  
         public StandardResponse save(String docId, String principalId, String docTitle, String docContent, String annotation) {
 651  
             StandardResponse results;
 652  
             
 653  
                 try {
 654  0
                         WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId, docTitle, docContent);
 655  0
                         workflowDocument.saveDocument(annotation);
 656  0
                         results = createResults(workflowDocument);
 657  0
                 } catch (WorkflowException e) {
 658  0
                         results = createErrorResults("Workflow Error: " + e.getLocalizedMessage());
 659  0
                 }
 660  
 
 661  0
                 return results;
 662  
         }
 663  
 
 664  
         /**
 665  
          * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#saveDocumentContent(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 666  
          */
 667  
         @Override
 668  
         public StandardResponse saveDocumentContent(String docId, String principalId, String docTitle, String docContent) {
 669  
             StandardResponse results;
 670  
             
 671  
                 try {
 672  0
                         WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId, docTitle, docContent);
 673  0
                         workflowDocument.saveRoutingData();
 674  0
                         results = createResults(workflowDocument);
 675  0
                 } catch (WorkflowException e) {
 676  0
                         results = createErrorResults("Workflow Error: " + e.getLocalizedMessage());
 677  0
                 }
 678  
 
 679  0
                 return results;
 680  
         }
 681  
 
 682  
         /**
 683  
      * Add a note to this KEW document.
 684  
      *
 685  
          * @param docId KEW document id of the document to add the note to
 686  
          * @param principalId principal id of the user who is adding the note
 687  
      * @param noteText text of the note
 688  
      * @return Map containing relevant note information (author, noteId, timestamp, noteText)
 689  
      * along with an error message (if any)
 690  
          *
 691  
          * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#addNote(java.lang.String, java.lang.String, java.lang.String)
 692  
      */
 693  
     @Override
 694  
         public NoteResponse addNote(String docId, String principalId, String noteText) {
 695  
 //                Map<String, Object> results = new HashMap<String, Object>(5);
 696  0
                 NoteResponse results = new NoteResponse();
 697  
                 
 698  0
                 String author = "";
 699  0
                 String noteId = "";
 700  0
                 String timestamp = "";
 701  0
                 String resultsNoteText = "";
 702  0
                 String errorMessage = "";
 703  
 
 704  
 //                results.put(ERROR_MESSAGE_LABEL, "");
 705  
 
 706  0
                 results.setErrorMessage("");
 707  
                 
 708  
                 try {
 709  0
                         WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId);
 710  
 
 711  
                         // setup note
 712  0
                         NoteDTO noteVO = new NoteDTO();
 713  0
                         noteVO.setNoteAuthorWorkflowId(principalId);
 714  0
                         noteVO.setNoteCreateDate(new GregorianCalendar());
 715  0
                         noteVO.setNoteText(noteText);
 716  0
                         noteVO.setDocumentId(workflowDocument.getDocumentId());
 717  0
                         workflowDocument.updateNote(noteVO);
 718  
 
 719  
                         //TODO: is this necessary?
 720  0
                         workflowDocument.saveRoutingData();
 721  0
                         RouteHeaderDTO routeHeader = workflowDocument.getRouteHeader();
 722  
 
 723  
                         //TODO: do we need to return the standard result set?
 724  
                         //results = createResults(workflowDocument);
 725  
 
 726  0
                         noteVO = routeHeader.getNotes()[routeHeader.getNotes().length-1];
 727  
 
 728  
                         // return note info
 729  0
                         Person person = KimApiServiceLocator.getPersonService().getPerson(noteVO.getNoteAuthorWorkflowId());
 730  0
                         author = person.getName();
 731  0
                         noteId = noteVO.getNoteId().toString();
 732  0
                         timestamp = formatCalendar(noteVO.getNoteCreateDate());
 733  0
                         resultsNoteText = noteVO.getNoteText();
 734  0
                 } catch (WorkflowException e) {
 735  0
                         errorMessage = "Workflow Error: " + e.getLocalizedMessage();
 736  0
                 }
 737  0
                 results.setAuthor(author);
 738  0
                 results.setNoteId(noteId);
 739  0
                 results.setTimestamp(timestamp);
 740  0
                 results.setNoteText(resultsNoteText);
 741  0
                 results.setErrorMessage(errorMessage);
 742  
                 
 743  0
                 return results;
 744  
     }
 745  
 
 746  
     /**
 747  
      * Update an existing note to this KEW document.
 748  
      *
 749  
          * @param docId KEW document id of the document to update the note for
 750  
          * @param noteId the id of the note to update
 751  
          * @param principalId principal id of the user who is updating the note
 752  
      * @param noteText text of the note if changed
 753  
      * @return Map containing relevant note information (author, noteId, timestamp, noteText)
 754  
      * along with an error message (if any)
 755  
          *
 756  
          * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#updateNote(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 757  
      */
 758  
     @Override
 759  
         public NoteResponse updateNote(String docId, String noteId, String principalId, String noteText) {
 760  
 //                Map<String, Object> results = new HashMap<String, Object>(5);
 761  0
                 String author = "";
 762  0
                 String resultsNoteId = "";
 763  0
                 String timestamp = "";
 764  0
                 String resultsNoteText = "";
 765  0
                 String errorMessage = "";
 766  
 
 767  
                 try {
 768  0
                         WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId);
 769  0
                         RouteHeaderDTO routeHeader = workflowDocument.getRouteHeader();
 770  
 
 771  
                         // setup note
 772  0
                         NoteDTO noteVO = getNote(routeHeader.getNotes(), noteId);
 773  0
                         noteVO.setNoteText(noteText);
 774  0
                         workflowDocument.updateNote(noteVO);
 775  
 
 776  
                         //TODO: is this necessary?
 777  0
                         workflowDocument.saveRoutingData();
 778  0
                         routeHeader = workflowDocument.getRouteHeader();
 779  
 
 780  
                         //TODO: do we need to return the standard result set?
 781  
                         //results = createResults(workflowDocument);
 782  
 
 783  0
                         noteVO = getNote(routeHeader.getNotes(), noteId);
 784  
 
 785  0
                         if (noteVO == null) {
 786  0
                                 errorMessage = "Error retrieving note for id [" + noteId + "].";
 787  
                         } else {
 788  
                                 // return note info
 789  0
                                 Person person = KimApiServiceLocator.getPersonService().getPerson(noteVO.getNoteAuthorWorkflowId());
 790  0
                                 author = person.getName();
 791  0
                                 resultsNoteId = noteVO.getNoteId().toString();
 792  0
                                 timestamp = formatCalendar(noteVO.getNoteCreateDate());
 793  0
                                 resultsNoteText = noteVO.getNoteText();
 794  
                         }
 795  0
                 } catch (WorkflowException e) {
 796  0
                         errorMessage = "Workflow Error: " + e.getLocalizedMessage();
 797  0
                 }
 798  
 
 799  0
                 NoteResponse results = new NoteResponse();
 800  
 
 801  0
                 results.setAuthor(author);
 802  0
                 results.setNoteId(resultsNoteId);
 803  0
                 results.setTimestamp(timestamp);
 804  0
                 results.setNoteText(resultsNoteText);
 805  0
                 results.setErrorMessage(errorMessage);
 806  
                 
 807  0
                 return results;
 808  
     }
 809  
 
 810  
     /**
 811  
      * Delete an existing note.
 812  
      *
 813  
          * @param docId KEW document id of the document to delete the note from
 814  
      * @param noteId the id of the note to delete
 815  
          * @param principalId principal id of the user who is deleting the note
 816  
      * @return Map containing an error message if any
 817  
          *
 818  
          * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#deleteNote(java.lang.String, java.lang.String, java.lang.String)
 819  
      */
 820  
     @Override
 821  
         public ErrorResponse deleteNote(String docId, String noteId, String principalId) {
 822  
                 //Map<String, Object> results = new HashMap<String, Object>(1);
 823  
                 
 824  0
         ErrorResponse results = new ErrorResponse();
 825  
         
 826  0
         String errorMessage = "";
 827  
 
 828  
                 try {
 829  0
                         WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId);
 830  0
                         RouteHeaderDTO routeHeader = workflowDocument.getRouteHeader();
 831  
 
 832  
                         // setup note
 833  0
                         NoteDTO noteVO = getNote(routeHeader.getNotes(), noteId);
 834  0
                         workflowDocument.deleteNote(noteVO);
 835  
 
 836  
                         //TODO: is this necessary?
 837  0
                         workflowDocument.saveRoutingData();
 838  
 
 839  
 ////              update notes database based on notes and notesToDelete arrays in routeHeaderVO
 840  
 //                DTOConverter.updateNotes(routeHeader, routeHeader.getDocumentId());
 841  0
                 } catch (WorkflowException e) {
 842  0
                         errorMessage = "Workflow Error: " + e.getLocalizedMessage();
 843  0
                 }
 844  
                 //results.put(ERROR_MESSAGE_LABEL, errorMessage);
 845  
 
 846  0
                 results.setErrorMessage(errorMessage);
 847  
                 
 848  0
                 return results;
 849  
     }
 850  
 
 851  
         /**
 852  
          * Return a KEW document to a previous route node.  This method should
 853  
          * be used with caution.
 854  
          *
 855  
          * @param docId KEW document id of the document that is being returned
 856  
          * @param principalId principal id of the user who is returning the doc
 857  
          * @param annotation a comment associated with this request
 858  
      * @param nodeName name of the route node to return to
 859  
          * @return Map including the standard set of return values
 860  
          *
 861  
          * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#returnToPreviousNode(java.lang.String, java.lang.String)
 862  
          */
 863  
     @Override
 864  
         public StandardResponse returnToPreviousNode(String docId, String principalId, String annotation, String nodeName) {
 865  0
             return returnToPreviousNodeWithUpdates(docId, principalId, annotation, nodeName, null, null);
 866  
     }
 867  
 
 868  
         /**
 869  
          * Return a KEW document to a previous route node.  This method should
 870  
          * be used with caution.
 871  
          *
 872  
          * @param docId KEW document id of the document that is being returned
 873  
          * @param principalId principal id of the user who is returning the doc
 874  
          * @param annotation a comment associated with this request
 875  
      * @param nodeName name of the route node to return to
 876  
          * @param docTitle title for this document
 877  
          * @param docContent xml content for this document
 878  
          * @return Map including the standard set of return values
 879  
          *
 880  
          * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#returnToPreviousNode(java.lang.String, java.lang.String)
 881  
          */
 882  
     @Override
 883  
         public StandardResponse returnToPreviousNodeWithUpdates(String docId, String principalId, String annotation, String nodeName, String docTitle, String docContent) {
 884  
         StandardResponse results;
 885  
         
 886  
                try {
 887  0
                         WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId, docTitle, docContent);
 888  
 
 889  0
                         workflowDocument.returnToPreviousNode(annotation, nodeName);
 890  0
                         results = createResults(workflowDocument);
 891  0
                 } catch (WorkflowException e) {
 892  0
                         results = createErrorResults("Workflow Error: " + e.getLocalizedMessage());
 893  0
                 }
 894  
 
 895  0
                 return results;
 896  
     }
 897  
 
 898  
     /**
 899  
      * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#revokeAdHocRequestsByNodeName(java.lang.String,
 900  
      *      java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 901  
      */
 902  
     @Override
 903  
         public StandardResponse revokeAdHocRequestsByNodeName(String docId, String principalId, String docTitle, String docContent, String nodeName, String annotation) {
 904  
         StandardResponse results;
 905  
 
 906  
         try {
 907  0
             WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId, docTitle, docContent);
 908  0
             AdHocRevokeDTO revokeDTO = new AdHocRevokeDTO();
 909  0
             revokeDTO.setNodeName(nodeName);
 910  0
             workflowDocument.revokeAdHocRequests(revokeDTO, annotation);
 911  0
             results = createResults(workflowDocument);
 912  0
         } catch (WorkflowException e) {
 913  0
             results = createErrorResults("Workflow Error: " + e.getLocalizedMessage());
 914  0
         }
 915  
 
 916  0
         return results;
 917  
     }
 918  
 
 919  
     /**
 920  
      * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#revokeAdHocRequestsByPrincipalId(java.lang.String,
 921  
      *      java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 922  
      */
 923  
     @Override
 924  
         public StandardResponse revokeAdHocRequestsByPrincipalId(String docId, String principalId, String docTitle, String docContent, String adhocPrincipalId, String annotation) {
 925  
         StandardResponse results;
 926  
 
 927  
         try {
 928  0
             WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId, docTitle, docContent);
 929  0
             AdHocRevokeDTO revokeDTO = new AdHocRevokeDTO();
 930  0
             revokeDTO.setPrincipalId(adhocPrincipalId);
 931  0
             workflowDocument.revokeAdHocRequests(revokeDTO, annotation);
 932  0
             results = createResults(workflowDocument);
 933  0
         } catch (WorkflowException e) {
 934  0
             results = createErrorResults("Workflow Error: " + e.getLocalizedMessage());
 935  0
         }
 936  
 
 937  0
         return results;
 938  
     }
 939  
 
 940  
     /**
 941  
      * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#revokeAdHocRequestsByGroupId(java.lang.String,
 942  
      *      java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 943  
      */
 944  
     @Override
 945  
         public StandardResponse revokeAdHocRequestsByGroupId(String docId, String principalId, String docTitle, String docContent, String groupId, String annotation) {
 946  
         StandardResponse results;
 947  
 
 948  
         try {
 949  0
             WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId, docTitle, docContent);
 950  0
             AdHocRevokeDTO revokeDTO = new AdHocRevokeDTO();
 951  0
             revokeDTO.setGroupId(groupId);
 952  0
             workflowDocument.revokeAdHocRequests(revokeDTO, annotation);
 953  0
             results = createResults(workflowDocument);
 954  0
         } catch (WorkflowException e) {
 955  0
             results = createErrorResults("Workflow Error: " + e.getLocalizedMessage());
 956  0
         }
 957  
 
 958  0
         return results;
 959  
     }
 960  
 
 961  
     /**
 962  
      * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#revokeAdHocRequestsByActionRequestId(java.lang.String,
 963  
      *      java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 964  
      */
 965  
     public StandardResponse revokeAdHocRequestsByActionRequestId(String docId, String principalId, String docTitle, String docContent, String actionRequestId, String annotation) {
 966  
         StandardResponse results;
 967  
 
 968  
         try {
 969  0
             WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId, docTitle, docContent);
 970  0
             AdHocRevokeDTO revokeDTO = new AdHocRevokeDTO();
 971  0
             revokeDTO.setActionRequestId(Long.valueOf(actionRequestId));
 972  0
             workflowDocument.revokeAdHocRequests(revokeDTO, annotation);
 973  0
             results = createResults(workflowDocument);
 974  0
         } catch (WorkflowException e) {
 975  0
             results = createErrorResults("Workflow Error: " + e.getLocalizedMessage());
 976  0
         }
 977  
 
 978  0
         return results;
 979  
     }
 980  
 
 981  
     /**
 982  
      * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#superUserApprove(java.lang.String,
 983  
      *      java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 984  
      */
 985  
     public StandardResponse superUserApprove(String docId, String superUserPrincipalId, String docTitle, String docContent, String annotation) {
 986  
         StandardResponse results;
 987  
 
 988  
         try {
 989  0
             WorkflowDocument workflowDocument = setupWorkflowDocument(docId, superUserPrincipalId, docTitle, docContent);
 990  
 
 991  0
             workflowDocument.superUserApprove(annotation);
 992  0
             results = createResults(workflowDocument);
 993  0
         } catch (WorkflowServiceErrorException e) {
 994  0
             results = createErrorResults("Workflow Error: " + e.getLocalizedMessage());
 995  0
         } catch (WorkflowException e) {
 996  0
             results = createErrorResults("Workflow Error: " + e.getLocalizedMessage());
 997  0
         }
 998  
 
 999  0
         return results;
 1000  
     }
 1001  
 
 1002  
     /**
 1003  
      * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#superUserDisapprove(java.lang.String,
 1004  
      *      java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 1005  
      */
 1006  
     public StandardResponse superUserDisapprove(String docId, String superUserPrincipalId, String docTitle, String docContent, String annotation) {
 1007  
         StandardResponse results;
 1008  
 
 1009  
         try {
 1010  0
             WorkflowDocument workflowDocument = setupWorkflowDocument(docId, superUserPrincipalId, docTitle, docContent);
 1011  
 
 1012  0
             workflowDocument.superUserDisapprove(annotation);
 1013  0
             results = createResults(workflowDocument);
 1014  0
         } catch (WorkflowServiceErrorException e) {
 1015  0
             results = createErrorResults("Workflow Error: " + e.getLocalizedMessage());
 1016  0
         } catch (WorkflowException e) {
 1017  0
             results = createErrorResults("Workflow Error: " + e.getLocalizedMessage());
 1018  0
         }
 1019  
 
 1020  0
         return results;
 1021  
     }
 1022  
 
 1023  
     /**
 1024  
      * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#superUserCancel(java.lang.String,
 1025  
      *      java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 1026  
      */
 1027  
     public StandardResponse superUserCancel(String docId, String superUserPrincipalId, String docTitle, String docContent, String annotation) {
 1028  
         StandardResponse results;
 1029  
 
 1030  
         try {
 1031  0
             WorkflowDocument workflowDocument = setupWorkflowDocument(docId, superUserPrincipalId, docTitle, docContent);
 1032  
 
 1033  0
             workflowDocument.superUserCancel(annotation);
 1034  0
             results = createResults(workflowDocument);
 1035  0
         } catch (WorkflowServiceErrorException e) {
 1036  0
             results = createErrorResults("Workflow Error: " + e.getLocalizedMessage());
 1037  0
         } catch (WorkflowException e) {
 1038  0
             results = createErrorResults("Workflow Error: " + e.getLocalizedMessage());
 1039  0
         }
 1040  
 
 1041  0
         return results;
 1042  
     }
 1043  
 
 1044  
     public StandardResponse superUserReturnToPrevious(String docId, String superUserPrincipalId, String docTitle, String docContent, String nodeName, String annotation) {
 1045  
         StandardResponse results;
 1046  
 
 1047  
         try {
 1048  
             // verify that the doc id has been sent in correctly
 1049  0
             if (StringUtils.isBlank(docId)) {
 1050  0
                 throw new WorkflowException("Invalid Parameter: docId is required but was blank");
 1051  
             }
 1052  
             // if the docTitle or docContent has been updated then update it with a saveRoutingData call
 1053  0
             if (StringUtils.isNotEmpty(docTitle) || StringUtils.isNotEmpty(docContent)) {
 1054  0
                 WorkflowDocument workflowDocument = setupWorkflowDocument(docId, superUserPrincipalId, docTitle, docContent);
 1055  0
                 workflowDocument.saveRoutingData();
 1056  
             }
 1057  
             // perform the return to previous
 1058  0
             KEWServiceLocator.getWorkflowDocumentActionsService().superUserReturnToPreviousNode(superUserPrincipalId, docId, nodeName, annotation);
 1059  
             // refetch the WorkflowDocument after the return to previous is completed
 1060  0
             results = createResults(WorkflowDocument.loadDocument(superUserPrincipalId, docId));
 1061  0
         } catch (WorkflowServiceErrorException e) {
 1062  0
             results = createErrorResults("Workflow Error: " + e.getLocalizedMessage());
 1063  0
         } catch (WorkflowException e) {
 1064  0
             results = createErrorResults("Workflow Error: " + e.getLocalizedMessage());
 1065  0
         }
 1066  
 
 1067  0
         return results;
 1068  
     }
 1069  
 
 1070  
     private NoteDTO getNote(NoteDTO[] notes, String noteId) {
 1071  0
             NoteDTO note = null;
 1072  
 
 1073  0
             if (notes != null){
 1074  0
                     for (NoteDTO note2 : notes) {
 1075  0
                             if (note2.getNoteId().toString().equals(noteId)) {
 1076  0
                                     note = note2;
 1077  0
                                     break;
 1078  
                             }
 1079  
                     }
 1080  
             }
 1081  
 
 1082  0
             return note;
 1083  
     }
 1084  
 
 1085  
     /**
 1086  
          * Convenience method to setup workflow document without title or content.
 1087  
          *
 1088  
          * @param docId KEW document id for the document to setup
 1089  
          * @param principalId KEW principal id for the user associated with this document
 1090  
          * @return populated WorkflowDocument object
 1091  
          * @throws WorkflowException if something goes wrong
 1092  
          */
 1093  
         private WorkflowDocument setupWorkflowDocument(String docId, String principalId) throws WorkflowException {
 1094  0
                 return setupWorkflowDocument(docId, principalId, null, null);
 1095  
         }
 1096  
 
 1097  
         /**
 1098  
          * Instantiate and setup the WorkflowDocument object.
 1099  
          *
 1100  
          * @param docId KEW document id for the document to setup
 1101  
          * @param principalId KEW principal id for the user associated with this document
 1102  
          * @param docTitle title for this document
 1103  
          * @param docContent xml content for this document
 1104  
          * @return populated WorkflowDocument object
 1105  
          * @throws WorkflowException if something goes wrong
 1106  
          */
 1107  
         private WorkflowDocument setupWorkflowDocument(String docId, String principalId, String docTitle, String docContent) throws WorkflowException {
 1108  0
                 WorkflowDocument workflowDocument = WorkflowDocument.loadDocument(principalId, docId);
 1109  0
                 if (StringUtils.isNotEmpty(docTitle)) {
 1110  0
                         workflowDocument.setTitle(docTitle);
 1111  
                 }
 1112  0
                 if (StringUtils.isNotEmpty(docContent)) {
 1113  0
                         workflowDocument.setApplicationContent(docContent);
 1114  
                 }
 1115  0
                 return workflowDocument;
 1116  
         }
 1117  
 
 1118  
         /**
 1119  
          * Create the note details result set.
 1120  
          *
 1121  
          * @param notes List of notes to build details Map array for
 1122  
          * @return Map[] containing note details
 1123  
          * @throws WorkflowException if an error occurs retrieving user display name
 1124  
          */
 1125  
         private List<NoteDetail> buildNoteDetails(List notes) throws WorkflowException {
 1126  
                 List<NoteDetail> noteDetails;
 1127  
 
 1128  0
                 if (notes == null) {
 1129  0
                         noteDetails = new ArrayList<NoteDetail>(0);
 1130  
                 } else {
 1131  0
                         noteDetails = new ArrayList<NoteDetail>(notes.size());
 1132  0
                         for (int i=0;i<notes.size();i++) {
 1133  
                                 //Map<String, String> noteDetail = new HashMap<String, String>(4);
 1134  
 
 1135  0
                             NoteDetail noteDetail = new NoteDetail();
 1136  0
                                 NoteDTO note = (NoteDTO)notes.get(i);
 1137  
                                 //author, noteId, timestamp, noteText
 1138  0
                                 Person person = KimApiServiceLocator.getPersonService().getPerson(note.getNoteAuthorWorkflowId());
 1139  0
                                 noteDetail.setAuthor(person.getName());
 1140  0
                                 noteDetail.setId(note.getNoteId().toString());
 1141  0
                                 noteDetail.setTimestamp(formatCalendar(note.getNoteCreateDate()));
 1142  0
                                 noteDetail.setNoteText(note.getNoteText());
 1143  
                                 
 1144  0
                                 noteDetails.add(noteDetail);
 1145  
                         }
 1146  
                 }
 1147  
 
 1148  0
                 return noteDetails;
 1149  
         }
 1150  
 
 1151  
 
 1152  
         /**
 1153  
          * Create the result set, either the standard results or error results
 1154  
          * if the routeHeader is null.
 1155  
          *
 1156  
          * @param workflowDocument WorkflowDocument used to get route header info
 1157  
          * @return Map containing results of the call (either standard or error version)
 1158  
          */
 1159  
         private StandardResponse createResults(WorkflowDocument workflowDocument) {
 1160  
                 //Map<String, Object> results;
 1161  
 
 1162  
             StandardResponse response;
 1163  
             
 1164  0
                 RouteHeaderDTO routeHeader = workflowDocument.getRouteHeader();
 1165  
 
 1166  0
                 if (routeHeader == null) {
 1167  0
                         response = createErrorResults("Error: NULL Route Header");
 1168  
                 } else {
 1169  0
                         response = createStandardResults(routeHeader);
 1170  
                 }
 1171  
 
 1172  0
                 return response;
 1173  
         }
 1174  
 
 1175  
         /**
 1176  
          * Create the standard result set with only the error message populated.
 1177  
          *
 1178  
          * @param errorMessage the message describing what error occured in the KEW engine
 1179  
          * @return Map containing the standard result set with only the error message populated
 1180  
          */
 1181  
         private StandardResponse createErrorResults(String errorMessage) {
 1182  0
             StandardResponse response = new StandardResponse();
 1183  0
             response.setDocStatus("");
 1184  0
             response.setCreateDate("");
 1185  0
             response.setInitiatorPrincipalId("");
 1186  0
             response.setRoutedByPrincipalId("");
 1187  0
             response.setAppDocId("");
 1188  0
             response.setInitiatorName("");
 1189  0
             response.setRoutedByUserName("");
 1190  0
             response.setErrorMessage(errorMessage);
 1191  
                 
 1192  0
             return response;
 1193  
         }
 1194  
 
 1195  
         /**
 1196  
          * Create the standard result set populated with values contained in the
 1197  
          * documents route header.
 1198  
          *
 1199  
          * @param routeHeader RouteHeaderVO for this document
 1200  
          * @return Map containing the standard result set populated with values contained in the
 1201  
          * documents route header.
 1202  
          */
 1203  
         private StandardResponse createStandardResults(RouteHeaderDTO routeHeader) {
 1204  0
                 String docStatus = "";
 1205  0
                 String createDate = "";
 1206  0
                 String initiatorPrincipalId = "";
 1207  0
         String routedByPrincipalId = "";
 1208  0
                 String appDocId = "";
 1209  0
                 String initiatorName = "";
 1210  0
         String routedByUserName = "";
 1211  0
                 String errorMessage = "";
 1212  
 
 1213  0
                 if (routeHeader == null) {
 1214  0
                         errorMessage = "Error: NULL Route Header";
 1215  
                 } else {
 1216  0
                         if (routeHeader.getDocRouteStatus() == null) {
 1217  0
                                 errorMessage = "Error: NULL Route Status; ";
 1218  
                         } else {
 1219  0
                                 docStatus = routeHeader.getDocRouteStatus();
 1220  
                         }
 1221  
 
 1222  0
                         if (routeHeader.getDateCreated() == null) {
 1223  0
                                 errorMessage += "Error: NULL Date Created; ";
 1224  
                         } else {
 1225  0
                                 createDate = formatCalendar(routeHeader.getDateCreated());
 1226  
                         }
 1227  
 
 1228  0
                         if (routeHeader.getInitiatorPrincipalId() == null) {
 1229  0
                                 errorMessage += "Error: NULL Initiator; ";
 1230  
                         } else {
 1231  0
                                 initiatorPrincipalId = routeHeader.getInitiatorPrincipalId();
 1232  0
                                 Person initiator = KimApiServiceLocator.getPersonService().getPerson(initiatorPrincipalId);
 1233  0
                                 if (initiator != null) {
 1234  0
                                     initiatorName = initiator.getName();
 1235  
                                 }
 1236  
                         }
 1237  
 
 1238  0
             if (routeHeader.getRoutedByPrincipalId() == null) {
 1239  
                 // of the document has been routed, but there is no routed-by user, that is an error
 1240  0
                 if (KEWConstants.ROUTE_HEADER_ENROUTE_CD.equals(routeHeader.getDocRouteStatus())) {
 1241  0
                         errorMessage += "Error: NULL routedBy user; ";
 1242  
                 }
 1243  
             } else {
 1244  0
                 routedByPrincipalId = routeHeader.getRoutedByPrincipalId();
 1245  0
                 Person routedByUser = KimApiServiceLocator.getPersonService().getPerson(initiatorPrincipalId);
 1246  0
                 if (routedByUser != null) {
 1247  0
                     routedByUserName = routedByUser.getName();
 1248  
                 }
 1249  
             }
 1250  
 
 1251  0
                         if (routeHeader.getAppDocId() != null) {
 1252  0
                                 appDocId = routeHeader.getAppDocId();
 1253  
                         }
 1254  
                 }
 1255  
 
 1256  
                 //Map<String, Object> results = new HashMap<String, Object>(6);
 1257  0
                 StandardResponse response = new StandardResponse();
 1258  
 
 1259  
 //                results.put(DOC_STATUS_LABEL, docStatus);
 1260  
 //                results.put(CREATE_DATE_LABEL, createDate);
 1261  
 //                results.put(INITIATOR_ID_LABEL, initiatorPrincipalId);
 1262  
 //        results.put(ROUTED_BY_USER_ID_LABEL, routedByprincipalId);
 1263  
 //                results.put(APP_DOC_ID_LABEL, appDocId);
 1264  
 //                results.put(INITIATOR_NAME_LABEL, initiatorName);
 1265  
 //        results.put(ROUTED_BY_USER_NAME_LABEL, routedByUserName);
 1266  
 //                results.put(ERROR_MESSAGE_LABEL, errorMessage);
 1267  
 
 1268  0
                 response.setDocStatus(docStatus);
 1269  0
                 response.setCreateDate(createDate);
 1270  0
                 response.setInitiatorPrincipalId(initiatorPrincipalId);
 1271  0
                 response.setRoutedByPrincipalId(routedByPrincipalId);
 1272  0
                 response.setAppDocId(appDocId);
 1273  0
                 response.setInitiatorName(initiatorName);
 1274  0
                 response.setRoutedByUserName(routedByUserName);
 1275  0
                 response.setErrorMessage(errorMessage);
 1276  
                 
 1277  0
                 return response;
 1278  
         }
 1279  
 
 1280  
 
 1281  
         /**
 1282  
          * Format a String date based on a given Calendar object.
 1283  
          *
 1284  
          * @param calendar Calendar date to format
 1285  
          * @return String formatted date
 1286  
          */
 1287  
         private String formatCalendar(Calendar calendar) {
 1288  0
                 String formattedDate = "";
 1289  
 
 1290  0
                 DateFormat dateFormat = new SimpleDateFormat();
 1291  0
                 Timestamp dateCreated = SQLUtils.convertCalendar(calendar);
 1292  0
                 formattedDate = dateFormat.format(dateCreated);
 1293  
 
 1294  0
                 return formattedDate;
 1295  
         }
 1296  
 
 1297  
 }