View Javadoc

1   /*
2    * Copyright 2007-2008 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.kcb.deliverer.impl;
17  
18  import java.util.HashMap;
19  import java.util.LinkedHashMap;
20  
21  import org.apache.commons.lang.StringUtils;
22  import org.apache.log4j.Logger;
23  import org.kuali.rice.kcb.bo.MessageDelivery;
24  import org.kuali.rice.kcb.deliverer.MessageDeliverer;
25  import org.kuali.rice.kcb.exception.ErrorList;
26  import org.kuali.rice.kcb.exception.MessageDeliveryException;
27  import org.kuali.rice.kcb.exception.MessageDismissalException;
28  
29  /**
30   * This class is responsible for describing the SMS delivery mechanism for
31   * the system.  It is not yet fully implemented - this class is just a stub.
32   * @author Kuali Rice Team (rice.collab@kuali.org)
33   */
34  public class SMSMessageDeliverer implements MessageDeliverer {
35      private static Logger LOG = Logger.getLogger(SMSMessageDeliverer.class);
36  
37      private static final String MOBILE_NUMBER = "sms_mobile_number";
38  
39      /**
40       * Constructs a SMSMessageDeliverer.java.
41       */
42      public SMSMessageDeliverer() {
43      }
44  
45      /**
46       * @see org.kuali.rice.kcb.deliverer.MessageDeliverer#deliver(org.kuali.rice.kcb.bo.MessageDelivery)
47       */
48      public void deliver(MessageDelivery messageDelivery) throws MessageDeliveryException {
49      }
50  
51      /**
52       * @see org.kuali.rice.ken.deliverer.NotificationMessageDeliverer#autoRemoveMessageDelivery(org.kuali.rice.ken.bo.NotificationMessageDelivery)
53       */
54      /*public void autoRemoveMessageDelivery(NotificationMessageDelivery messageDelivery) throws NotificationAutoRemoveException {
55  	// we can't remove an sms message once it has been sent
56      }*/
57  
58      /**
59       * @see MessageDeliverer#dismiss(MessageDelivery, String, String)
60       */
61      public void dismiss(MessageDelivery messageDelivery, String user, String cause) throws MessageDismissalException {
62          // we can't remove an sms message once it has been sent
63      }
64  
65      /**
66       * @see org.kuali.rice.kcb.deliverer.MessageDeliverer#getDescription()
67       */
68      public String getDescription() {
69          return "This is the default SMS message delivery type.  Please note that you may incur charges for each SMS message that you receive to your mobile phone.";
70      }
71  
72      /**
73       * @see org.kuali.rice.kcb.deliverer.MessageDeliverer#getName()
74       */
75      public String getName() {
76          return "SMS";
77      }
78  
79      /**
80       * @see org.kuali.rice.kcb.deliverer.MessageDeliverer#getTitle()
81       */
82      public String getTitle() {
83          return "SMS Message Delivery";
84      }
85  
86      /**
87       * This implementation returns an address field.
88       * @see org.kuali.rice.kcb.deliverer.MessageDeliverer#getPreferenceKeys()
89       */
90      public LinkedHashMap getPreferenceKeys() {
91          LinkedHashMap<String, String> prefKeys = new LinkedHashMap<String, String>();
92          prefKeys.put(MOBILE_NUMBER, "Mobile Phone Number (\"555-555-5555\")");
93          return prefKeys;
94      }
95  
96      /**
97       * @see org.kuali.rice.kcb.deliverer.MessageDeliverer#validatePreferenceValues(java.util.HashMap)
98       */
99      public void validatePreferenceValues(HashMap prefs) throws ErrorList {
100         boolean error = false;
101         ErrorList errorList = new ErrorList();
102 
103         if (!prefs.containsKey(getName()+"."+MOBILE_NUMBER)) {
104             errorList.addError("Mobile Phone Number is a required field.");
105             error = true;
106         } else {
107             String mobileNumber = (String) prefs.get(getName()+"."+MOBILE_NUMBER);
108             if(StringUtils.isBlank(mobileNumber)) {
109                 errorList.addError("Mobile Phone Number is a required.");
110                 error = true;
111             }
112         }
113         if (error) throw errorList;
114     }
115 }