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