001/**
002 * Copyright 2005-2016 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.kcb.deliverer.impl;
017
018import java.util.HashMap;
019import java.util.LinkedHashMap;
020
021import org.apache.commons.lang.StringUtils;
022import org.apache.log4j.Logger;
023import org.kuali.rice.kcb.bo.MessageDelivery;
024import org.kuali.rice.kcb.deliverer.MessageDeliverer;
025import org.kuali.rice.kcb.exception.ErrorList;
026import org.kuali.rice.kcb.api.exception.MessageDeliveryException;
027import org.kuali.rice.kcb.api.exception.MessageDismissalException;
028
029/**
030 * This class is responsible for describing the SMS delivery mechanism for
031 * the system.  It is not yet fully implemented - this class is just a stub.
032 * @author Kuali Rice Team (rice.collab@kuali.org)
033 */
034public class SMSMessageDeliverer implements MessageDeliverer {
035    private static Logger LOG = Logger.getLogger(SMSMessageDeliverer.class);
036
037    private static final String MOBILE_NUMBER = "sms_mobile_number";
038
039    /**
040     * Constructs a SMSMessageDeliverer.java.
041     */
042    public SMSMessageDeliverer() {
043    }
044
045    /**
046     * @see org.kuali.rice.kcb.deliverer.MessageDeliverer#deliver(org.kuali.rice.kcb.bo.MessageDelivery)
047     */
048    public void deliver(MessageDelivery messageDelivery) throws MessageDeliveryException {
049    }
050
051    /**
052     * @see org.kuali.rice.ken.deliverer.NotificationMessageDeliverer#autoRemoveMessageDelivery(org.kuali.rice.ken.bo.NotificationMessageDelivery)
053     */
054    /*public void autoRemoveMessageDelivery(NotificationMessageDelivery messageDelivery) throws NotificationAutoRemoveException {
055        // we can't remove an sms message once it has been sent
056    }*/
057
058    /**
059     * @see MessageDeliverer#dismiss(MessageDelivery, String, String)
060     */
061    public void dismiss(MessageDelivery messageDelivery, String user, String cause) throws MessageDismissalException {
062        // we can't remove an sms message once it has been sent
063    }
064
065    /**
066     * @see org.kuali.rice.kcb.deliverer.MessageDeliverer#getDescription()
067     */
068    public String getDescription() {
069        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.";
070    }
071
072    /**
073     * @see org.kuali.rice.kcb.deliverer.MessageDeliverer#getName()
074     */
075    public String getName() {
076        return "SMS";
077    }
078
079    /**
080     * @see org.kuali.rice.kcb.deliverer.MessageDeliverer#getTitle()
081     */
082    public String getTitle() {
083        return "SMS Message Delivery";
084    }
085
086    /**
087     * This implementation returns an address field.
088     * @see org.kuali.rice.kcb.deliverer.MessageDeliverer#getPreferenceKeys()
089     */
090    public LinkedHashMap getPreferenceKeys() {
091        LinkedHashMap<String, String> prefKeys = new LinkedHashMap<String, String>();
092        prefKeys.put(MOBILE_NUMBER, "Mobile Phone Number (\"555-555-5555\")");
093        return prefKeys;
094    }
095
096    /**
097     * @see org.kuali.rice.kcb.deliverer.MessageDeliverer#validatePreferenceValues(java.util.HashMap)
098     */
099    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}