Coverage Report - org.kuali.rice.ken.service.impl.NotificationWorkflowDocumentServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
NotificationWorkflowDocumentServiceImpl
0%
0/32
0%
0/10
2.2
 
 1  
 /*
 2  
  * Copyright 2007 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.ken.service.impl;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.ken.bo.NotificationMessageDelivery;
 20  
 import org.kuali.rice.ken.document.kew.NotificationWorkflowDocument;
 21  
 import org.kuali.rice.ken.service.NotificationMessageContentService;
 22  
 import org.kuali.rice.ken.service.NotificationWorkflowDocumentService;
 23  
 import org.kuali.rice.ken.util.NotificationConstants;
 24  
 import org.kuali.rice.kew.dto.ActionRequestDTO;
 25  
 import org.kuali.rice.kew.dto.WorkflowIdDTO;
 26  
 import org.kuali.rice.kew.exception.WorkflowException;
 27  
 import org.kuali.rice.kew.service.WorkflowDocument;
 28  
 import org.kuali.rice.kew.util.KEWConstants;
 29  
 import org.kuali.rice.kim.bo.entity.KimPrincipal;
 30  
 import org.kuali.rice.kim.service.KIMServiceLocator;
 31  
 
 32  
 
 33  
 /**
 34  
  * This class is responsible for interacting with KEW - this is the default implementation that leverages the KEW client API.
 35  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 36  
  */
 37  
 public class NotificationWorkflowDocumentServiceImpl implements NotificationWorkflowDocumentService {
 38  0
     private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
 39  
         .getLogger(NotificationWorkflowDocumentServiceImpl.class);
 40  
 
 41  
     private NotificationMessageContentService messageContentService;
 42  
 
 43  
     /**
 44  
      * Constructs a NotificationWorkflowDocumentServiceImpl instance.
 45  
      * @param messageContentService
 46  
      */
 47  0
     public NotificationWorkflowDocumentServiceImpl(NotificationMessageContentService messageContentService) {
 48  0
         this.messageContentService = messageContentService;
 49  0
     }
 50  
 
 51  
     /**
 52  
      * Implements by instantiating a NotificationWorkflowDocument, which in turn interacts with Workflow to set it up with an initiator of the
 53  
      * passed in user id.
 54  
      * @see org.kuali.rice.ken.service.NotificationWorkflowDocumentService#createAndAdHocRouteNotificationWorkflowDocument(org.kuali.rice.ken.bo.NotificationMessageDelivery, java.lang.String, java.lang.String, java.lang.String)
 55  
      */
 56  
     public Long createAndAdHocRouteNotificationWorkflowDocument(NotificationMessageDelivery messageDelivery, String initiatorUserId,
 57  
             String recipientUserId, String annotation) throws WorkflowException {
 58  
         // obtain a workflow user object first
 59  0
         WorkflowIdDTO initiator = new WorkflowIdDTO(initiatorUserId);
 60  
 
 61  
         // now construct the workflow document, which will interact with workflow
 62  0
         NotificationWorkflowDocument document = new NotificationWorkflowDocument(initiator);
 63  
 
 64  
         // this is our loose foreign key to our message delivery record in notification
 65  0
         document.getRouteHeader().setAppDocId(messageDelivery.getId().toString());
 66  
         //document.setAppDocId(messageDelivery.getId().toString());
 67  
 
 68  
         // now add the content of the notification as XML to the document
 69  0
         document.setApplicationContent(messageContentService.generateNotificationMessage(messageDelivery.getNotification(), messageDelivery.getUserRecipientId()));
 70  
 
 71  0
         if (!StringUtils.isBlank(messageDelivery.getNotification().getTitle())) {
 72  0
             document.setTitle(messageDelivery.getNotification().getTitle());
 73  
         } else {
 74  0
             LOG.error("Encountered notification with no title set: Message Delivery #" + messageDelivery.getId() + ", Notification #" + messageDelivery.getNotification().getId());
 75  
         }
 76  
 
 77  
         // now set up the ad hoc route
 78  
         String actionRequested;
 79  0
         if(NotificationConstants.DELIVERY_TYPES.ACK.equals(messageDelivery.getNotification().getDeliveryType())) {
 80  0
             actionRequested = NotificationConstants.KEW_CONSTANTS.ACK_AD_HOC_ROUTE;
 81  
         } else {
 82  0
             actionRequested = NotificationConstants.KEW_CONSTANTS.FYI_AD_HOC_ROUTE;
 83  
         }
 84  
 
 85  
         // Clarification of ad hoc route call
 86  
         // param 1 - actionRequested will be either ACK or FYI
 87  
         // param 2 - annotation is whatever text we pass in to describe the transaction - this will be system generated
 88  
         // param 3 - recipient is the person who will receive this request
 89  
         // param 4 - this is the responsibilityParty (a.k.a the system that produced this request), so we'll put the producer name in there
 90  
         // param 5 - this is the "force action" requests - if set to true, this will be delivered to the recipients list regardless of
 91  
         //           whether the recipient has already taken action on this request; in our case, this doesn't really apply at this point in time,
 92  
         //           so we'll set to true just to be safe
 93  0
         KimPrincipal principal = KIMServiceLocator.getIdentityManagementService().getPrincipalByPrincipalName(recipientUserId);
 94  0
         document.adHocRouteDocumentToPrincipal(actionRequested, annotation, principal.getPrincipalId(),
 95  
                 messageDelivery.getNotification().getProducer().getName(), true);
 96  
 
 97  
         // now actually route it along its way
 98  0
         document.routeDocument(annotation);
 99  
 
 100  0
         return document.getRouteHeaderId();
 101  
     }
 102  
 
 103  
     /**
 104  
      * This service method is implemented by constructing a NotificationWorkflowDocument using the pre-existing document Id
 105  
      * that is passed in.
 106  
      * @see org.kuali.rice.ken.service.NotificationWorkflowDocumentService#findNotificationWorkflowDocumentByDocumentId(java.lang.String, java.lang.Long)
 107  
      */
 108  
     public NotificationWorkflowDocument getNotificationWorkflowDocumentByDocumentId(String initiatorUserId, Long workflowDocumentId) throws WorkflowException {
 109  
         // construct the workflow id value object
 110  0
         WorkflowIdDTO initiator = new WorkflowIdDTO(initiatorUserId);
 111  
 
 112  
         // now return the actual document instance
 113  
         // this handles going out and getting the workflow document
 114  0
         return new NotificationWorkflowDocument(initiator, workflowDocumentId);
 115  
     }
 116  
 
 117  
     /**
 118  
      * @see org.kuali.rice.ken.service.NotificationWorkflowDocumentService#clearAllFyisAndAcknowledgeNotificationWorkflowDocument(java.lang.String, org.kuali.rice.ken.document.kew.NotificationWorkflowDocument, java.lang.String)
 119  
      */
 120  
     public void clearAllFyisAndAcknowledgeNotificationWorkflowDocument(String initiatorUserId, NotificationWorkflowDocument workflowDocument, String annotation) throws WorkflowException {
 121  0
         ActionRequestDTO[] reqs = workflowDocument.getActionRequests();
 122  0
         for(int i = 0; i < reqs.length; i++) {
 123  0
             LOG.info("Action Request[" + i + "] = " + reqs[i].getActionRequested());
 124  0
             if(reqs[i].getActionRequested().equals(KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ)) {
 125  0
                 workflowDocument.acknowledge(annotation);
 126  0
             } else if(reqs[i].getActionRequested().equals(KEWConstants.ACTION_REQUEST_FYI_REQ)) {
 127  0
                 workflowDocument.logDocumentAction(annotation);
 128  0
                 workflowDocument.clearFYI();
 129  
             } else {
 130  0
                 throw new WorkflowException("Invalid notification action request in workflow document (" + workflowDocument.getRouteHeaderId().toString() + ") was encountered.  Should be either an acknowledge or fyi and was not.");
 131  
             }
 132  
         }
 133  0
     }
 134  
 
 135  
     /**
 136  
      * @see org.kuali.rice.ken.service.NotificationWorkflowDocumentService#terminateWorkflowDocument(org.kuali.rice.kew.service.WorkflowDocument)
 137  
      */
 138  
     public void terminateWorkflowDocument(WorkflowDocument document) throws WorkflowException {
 139  0
         document.superUserCancel("terminating document: routeHeaderId=" + document.getRouteHeaderId() + ", appDocId=" + document.getAppDocId());
 140  0
     }
 141  
 }