View Javadoc

1   /**
2    * Copyright 2005-2013 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.core.api.exception.RiceIllegalArgumentException;
20  import org.kuali.rice.ken.api.notification.Notification;
21  import org.kuali.rice.ken.api.notification.NotificationResponse;
22  import org.kuali.rice.ken.api.service.SendNotificationService;
23  import org.kuali.rice.ken.bo.NotificationBo;
24  import org.kuali.rice.ken.bo.NotificationResponseBo;
25  import org.kuali.rice.ken.service.NotificationService;
26  import org.kuali.rice.kew.api.WorkflowRuntimeException;
27  
28  /**
29   * This class allows the NotificationService.sendNotification(XML) service 
30   * to be invoked as a web service generically from the bus.
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   */
33  public class SendNotificationServiceKewXmlImpl implements SendNotificationService {
34      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
35      .getLogger(SendNotificationServiceKewXmlImpl.class);
36  
37      private final NotificationService notificationService;
38  
39      /**
40       * Constructs a SendNotificationServiceKewXmlImpl instance.
41       * @param notificationService
42       */
43      public SendNotificationServiceKewXmlImpl(NotificationService notificationService) {
44          this.notificationService = notificationService;
45      }
46  
47      /**
48       * Actually invokes the sendNotification() service method.  The KSB calls 
49       * this.
50       * @see org.kuali.rice.ksb.messaging.service.KSBXMLService#invoke(java.lang.String)
51       */
52      @Override
53      public NotificationResponse invoke(String message) {
54          if (StringUtils.isBlank(message)) {
55              throw new RiceIllegalArgumentException("xml is null or blank");
56          }
57  
58          try {
59             NotificationResponseBo response = notificationService.sendNotification(message);
60             LOG.info(response.getMessage());
61             return NotificationResponseBo.to(response);
62          } catch (Exception e) {
63              throw new WorkflowRuntimeException(e);
64          }
65      }
66  
67      @Override
68      public NotificationResponse sendNotification(Notification notification) {
69          if (null == notification) {
70              throw new RiceIllegalArgumentException("xml is null or blank");
71          }
72  
73          try {
74              NotificationBo notificationBo = NotificationBo.from(notification);
75              NotificationResponseBo response = notificationService.sendNotification(notificationBo);
76              LOG.info(response.getMessage());
77              return NotificationResponseBo.to(response);
78          } catch (Exception e) {
79              throw new IllegalStateException(e);
80          }
81      }
82  }