Coverage Report - org.kuali.rice.kew.notification.service.impl.KCBNotificationService
 
Classes in this File Line Coverage Branch Coverage Complexity
KCBNotificationService
0%
0/39
0%
0/12
7.5
 
 1  
 /**
 2  
  * Copyright 2005-2011 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.kew.notification.service.impl;
 17  
 
 18  
 import java.util.List;
 19  
 
 20  
 import javax.xml.namespace.QName;
 21  
 
 22  
 import org.apache.commons.lang.StringUtils;
 23  
 import org.kuali.rice.core.api.config.property.ConfigContext;
 24  
 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
 25  
 import org.kuali.rice.kcb.api.message.MessageDTO;
 26  
 import org.kuali.rice.kcb.api.service.KCBServiceNames;
 27  
 import org.kuali.rice.kcb.api.service.MessagingService;
 28  
 import org.kuali.rice.kcb.util.KCBConstants;
 29  
 import org.kuali.rice.kew.api.WorkflowRuntimeException;
 30  
 import org.kuali.rice.kew.api.action.ActionItem;
 31  
 import org.kuali.rice.kew.api.KewApiConstants;
 32  
 
 33  
 
 34  
 /**
 35  
  * NotificationService implementation that delegates to KCB
 36  
  *
 37  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 38  
  */
 39  0
 public class KCBNotificationService extends DefaultNotificationService {
 40  
     @Override
 41  
     protected void sendNotification(ActionItem actionItem) {
 42  0
         super.sendNotification(actionItem);
 43  
 
 44  0
         String enableKENNotificationValue = ConfigContext.getCurrentContextConfig().getProperty(KewApiConstants.ENABLE_KEN_NOTIFICATION);
 45  0
         boolean enableKENNotification = Boolean.parseBoolean(enableKENNotificationValue);
 46  
         // we only send per-user messages to KCB
 47  0
         if (!enableKENNotification || actionItem.getPrincipalId() != null)
 48  0
             return;
 49  
 
 50  
 
 51  
         // send it off to KCB if available
 52  0
         MessagingService ms = (MessagingService) GlobalResourceLoader.getService(new QName(KCBConstants.SERVICE_NAMESPACE, KCBServiceNames.KCB_MESSAGING));
 53  0
         if (ms == null) {
 54  0
                 LOG.info("Could not locate KCB MessagingService.  Message will not be forwarded to the KCB.");
 55  0
                 return;
 56  
         }
 57  0
         MessageDTO mvo = new MessageDTO();
 58  0
         mvo.setChannel("KEW");
 59  0
         mvo.setContent("i'm a kew notification");
 60  0
         mvo.setContentType("KEW notification");
 61  0
         mvo.setDeliveryType(actionItem.getActionRequestCd());
 62  0
         mvo.setProducer("kew@localhost");
 63  0
         mvo.setTitle(actionItem.getDocLabel() + " - " + actionItem.getDocName() + " - " + actionItem.getDocTitle());
 64  0
         if (StringUtils.isNotBlank(actionItem.getDocHandlerURL())) {
 65  0
                 mvo.setUrl(actionItem.getDocHandlerURL() + "?docId=" + actionItem.getDocumentId());
 66  
         }
 67  0
         mvo.setOriginId(String.valueOf(actionItem.getId()));
 68  
         try {
 69  
             // just assume it's a user at this point...
 70  0
             mvo.setRecipient(actionItem.getPrincipalId());
 71  0
             LOG.debug("Sending message to KCB: " + mvo);
 72  0
             ms.deliver(mvo);
 73  0
         } catch (Exception e) {
 74  0
             throw new WorkflowRuntimeException("could not deliver message to KCB", e);
 75  0
         }
 76  0
     }
 77  
 
 78  
     @Override
 79  
     public void removeNotification(List<ActionItem> actionItems) {
 80  0
             String enableKENNotificationValue = ConfigContext.getCurrentContextConfig().getProperty(KewApiConstants.ENABLE_KEN_NOTIFICATION);
 81  0
         boolean enableKENNotification = Boolean.parseBoolean(enableKENNotificationValue);
 82  0
         if (!enableKENNotification) {
 83  0
                 return;
 84  
         }
 85  0
         MessagingService ms = (MessagingService) GlobalResourceLoader.getService(new QName(KCBConstants.SERVICE_NAMESPACE, KCBServiceNames.KCB_MESSAGING));
 86  
 
 87  0
         for (ActionItem actionItem: actionItems) {
 88  0
                 LOG.debug("Removing KCB messages for action item: " + actionItem.getId() + " " + actionItem.getActionRequestCd() + " " + actionItem.getPrincipalId());
 89  
             try {
 90  
                 // we don't have the action takens at this point...? :(
 91  0
                 ms.removeByOriginId(String.valueOf(actionItem.getId()), null, null);
 92  0
             } catch (Exception e) {
 93  0
                 throw new RuntimeException("could not remove message from KCB", e);
 94  0
             }
 95  
         }
 96  0
     }
 97  
 }