1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.mail.service.impl;
24  
25  import com.liferay.mail.model.Filter;
26  import com.liferay.mail.service.MailService;
27  import com.liferay.portal.kernel.mail.MailMessage;
28  import com.liferay.portal.kernel.messaging.DestinationNames;
29  import com.liferay.portal.kernel.messaging.MessageBusUtil;
30  import com.liferay.portal.kernel.util.BooleanWrapper;
31  import com.liferay.portal.kernel.util.LongWrapper;
32  import com.liferay.portal.kernel.util.MethodWrapper;
33  import com.liferay.portal.util.PropsValues;
34  
35  import java.util.List;
36  
37  import org.apache.commons.logging.Log;
38  import org.apache.commons.logging.LogFactory;
39  
40  /**
41   * <a href="MailServiceImpl.java.html"><b><i>View Source</i></b></a>
42   *
43   * @author Brian Wing Shun Chan
44   *
45   */
46  public class MailServiceImpl implements MailService {
47  
48      public void addForward(
49          long userId, List<Filter> filters, List<String> emailAddresses,
50          boolean leaveCopy) {
51  
52          if (_log.isDebugEnabled()) {
53              _log.debug("addForward");
54          }
55  
56          MethodWrapper methodWrapper = new MethodWrapper(
57              PropsValues.MAIL_HOOK_IMPL, "addForward",
58              new Object[] {
59                  new LongWrapper(userId), filters, emailAddresses,
60                  new BooleanWrapper(leaveCopy)
61              });
62  
63          MessageBusUtil.sendMessage(DestinationNames.MAIL, methodWrapper);
64      }
65  
66      public void addUser(
67          long userId, String password, String firstName, String middleName,
68          String lastName, String emailAddress) {
69  
70          if (_log.isDebugEnabled()) {
71              _log.debug("addUser");
72          }
73  
74          MethodWrapper methodWrapper = new MethodWrapper(
75              PropsValues.MAIL_HOOK_IMPL, "addUser",
76              new Object[] {
77                  new LongWrapper(userId), password, firstName, middleName,
78                  lastName, emailAddress
79              });
80  
81          MessageBusUtil.sendMessage(DestinationNames.MAIL, methodWrapper);
82      }
83  
84      public void addVacationMessage(
85          long userId, String emailAddress, String vacationMessage) {
86  
87          if (_log.isDebugEnabled()) {
88              _log.debug("addVacationMessage");
89          }
90  
91          MethodWrapper methodWrapper = new MethodWrapper(
92              PropsValues.MAIL_HOOK_IMPL, "addVacationMessage",
93              new Object[] {
94                  new LongWrapper(userId), emailAddress, vacationMessage
95              });
96  
97          MessageBusUtil.sendMessage(DestinationNames.MAIL, methodWrapper);
98      }
99  
100     public void deleteEmailAddress(long userId) {
101         if (_log.isDebugEnabled()) {
102             _log.debug("deleteEmailAddress");
103         }
104 
105         MethodWrapper methodWrapper = new MethodWrapper(
106             PropsValues.MAIL_HOOK_IMPL, "deleteEmailAddress",
107             new Object[] {new LongWrapper(userId)});
108 
109         MessageBusUtil.sendMessage(DestinationNames.MAIL, methodWrapper);
110     }
111 
112     public void deleteUser(long userId) {
113         if (_log.isDebugEnabled()) {
114             _log.debug("deleteUser");
115         }
116 
117         MethodWrapper methodWrapper = new MethodWrapper(
118             PropsValues.MAIL_HOOK_IMPL, "deleteUser",
119             new Object[] {new LongWrapper(userId)});
120 
121         MessageBusUtil.sendMessage(DestinationNames.MAIL, methodWrapper);
122     }
123 
124     public void sendEmail(MailMessage mailMessage) {
125         if (_log.isDebugEnabled()) {
126             _log.debug("sendEmail");
127         }
128 
129         MessageBusUtil.sendMessage(DestinationNames.MAIL, mailMessage);
130     }
131 
132     public void updateBlocked(long userId, List<String> blocked) {
133         if (_log.isDebugEnabled()) {
134             _log.debug("updateBlocked");
135         }
136 
137         MethodWrapper methodWrapper = new MethodWrapper(
138             PropsValues.MAIL_HOOK_IMPL, "updateBlocked",
139             new Object[] {new LongWrapper(userId), blocked});
140 
141         MessageBusUtil.sendMessage(DestinationNames.MAIL, methodWrapper);
142     }
143 
144     public void updateEmailAddress(long userId, String emailAddress) {
145         if (_log.isDebugEnabled()) {
146             _log.debug("updateEmailAddress");
147         }
148 
149         MethodWrapper methodWrapper = new MethodWrapper(
150             PropsValues.MAIL_HOOK_IMPL, "updateEmailAddress",
151             new Object[] {new LongWrapper(userId), emailAddress});
152 
153         MessageBusUtil.sendMessage(DestinationNames.MAIL, methodWrapper);
154     }
155 
156     public void updatePassword(long userId, String password) {
157         if (_log.isDebugEnabled()) {
158             _log.debug("updatePassword");
159         }
160 
161         MethodWrapper methodWrapper = new MethodWrapper(
162             PropsValues.MAIL_HOOK_IMPL, "updatePassword",
163             new Object[] {new LongWrapper(userId), password});
164 
165         MessageBusUtil.sendMessage(DestinationNames.MAIL, methodWrapper);
166     }
167 
168     private static Log _log = LogFactory.getLog(MailServiceImpl.class);
169 
170 }