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