1   /**
2    * Copyright (c) 2000-2009 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.log.Log;
28  import com.liferay.portal.kernel.log.LogFactoryUtil;
29  import com.liferay.portal.kernel.mail.MailMessage;
30  import com.liferay.portal.kernel.messaging.DestinationNames;
31  import com.liferay.portal.kernel.messaging.MessageBusUtil;
32  import com.liferay.portal.kernel.util.BooleanWrapper;
33  import com.liferay.portal.kernel.util.LongWrapper;
34  import com.liferay.portal.kernel.util.MethodWrapper;
35  import com.liferay.portal.util.PropsValues;
36  
37  import java.util.List;
38  
39  /**
40   * <a href="MailServiceImpl.java.html"><b><i>View Source</i></b></a>
41   *
42   * @author Brian Wing Shun Chan
43   *
44   */
45  public class MailServiceImpl implements MailService {
46  
47      public void addForward(
48          long companyId, long userId, List<Filter> filters,
49          List<String> emailAddresses, boolean leaveCopy) {
50  
51          if (_log.isDebugEnabled()) {
52              _log.debug("addForward");
53          }
54  
55          MethodWrapper methodWrapper = new MethodWrapper(
56              PropsValues.MAIL_HOOK_IMPL, "addForward",
57              new Object[] {
58                  new LongWrapper(companyId), new LongWrapper(userId), filters,
59                  emailAddresses, new BooleanWrapper(leaveCopy)
60              });
61  
62          MessageBusUtil.sendMessage(DestinationNames.MAIL, methodWrapper);
63      }
64  
65      public void addUser(
66          long companyId, long userId, String password, String firstName,
67          String middleName, String lastName, String emailAddress) {
68  
69          if (_log.isDebugEnabled()) {
70              _log.debug("addUser");
71          }
72  
73          MethodWrapper methodWrapper = new MethodWrapper(
74              PropsValues.MAIL_HOOK_IMPL, "addUser",
75              new Object[] {
76                  new LongWrapper(companyId), new LongWrapper(userId), password,
77                  firstName, middleName, lastName, emailAddress
78              });
79  
80          MessageBusUtil.sendMessage(DestinationNames.MAIL, methodWrapper);
81      }
82  
83      public void addVacationMessage(
84          long companyId, long userId, String emailAddress,
85          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(companyId), new LongWrapper(userId),
95                  emailAddress, vacationMessage
96              });
97  
98          MessageBusUtil.sendMessage(DestinationNames.MAIL, methodWrapper);
99      }
100 
101     public void deleteEmailAddress(long companyId, long userId) {
102         if (_log.isDebugEnabled()) {
103             _log.debug("deleteEmailAddress");
104         }
105 
106         MethodWrapper methodWrapper = new MethodWrapper(
107             PropsValues.MAIL_HOOK_IMPL, "deleteEmailAddress",
108             new Object[] {new LongWrapper(userId)});
109 
110         MessageBusUtil.sendMessage(DestinationNames.MAIL, methodWrapper);
111     }
112 
113     public void deleteUser(long companyId, long userId) {
114         if (_log.isDebugEnabled()) {
115             _log.debug("deleteUser");
116         }
117 
118         MethodWrapper methodWrapper = new MethodWrapper(
119             PropsValues.MAIL_HOOK_IMPL, "deleteUser",
120             new Object[] {new LongWrapper(companyId), new LongWrapper(userId)});
121 
122         MessageBusUtil.sendMessage(DestinationNames.MAIL, methodWrapper);
123     }
124 
125     public void sendEmail(MailMessage mailMessage) {
126         if (_log.isDebugEnabled()) {
127             _log.debug("sendEmail");
128         }
129 
130         MessageBusUtil.sendMessage(DestinationNames.MAIL, mailMessage);
131     }
132 
133     public void updateBlocked(
134         long companyId, long userId, List<String> blocked) {
135 
136         if (_log.isDebugEnabled()) {
137             _log.debug("updateBlocked");
138         }
139 
140         MethodWrapper methodWrapper = new MethodWrapper(
141             PropsValues.MAIL_HOOK_IMPL, "updateBlocked",
142             new Object[] {
143                 new LongWrapper(companyId), new LongWrapper(userId), blocked
144             });
145 
146         MessageBusUtil.sendMessage(DestinationNames.MAIL, methodWrapper);
147     }
148 
149     public void updateEmailAddress(
150         long companyId, long userId, String emailAddress) {
151 
152         if (_log.isDebugEnabled()) {
153             _log.debug("updateEmailAddress");
154         }
155 
156         MethodWrapper methodWrapper = new MethodWrapper(
157             PropsValues.MAIL_HOOK_IMPL, "updateEmailAddress",
158             new Object[] {
159                 new LongWrapper(companyId), new LongWrapper(userId),
160                 emailAddress
161             });
162 
163         MessageBusUtil.sendMessage(DestinationNames.MAIL, methodWrapper);
164     }
165 
166     public void updatePassword(long companyId, long userId, String password) {
167         if (_log.isDebugEnabled()) {
168             _log.debug("updatePassword");
169         }
170 
171         MethodWrapper methodWrapper = new MethodWrapper(
172             PropsValues.MAIL_HOOK_IMPL, "updatePassword",
173             new Object[] {
174                 new LongWrapper(companyId), new LongWrapper(userId), password
175             });
176 
177         MessageBusUtil.sendMessage(DestinationNames.MAIL, methodWrapper);
178     }
179 
180     private static Log _log = LogFactoryUtil.getLog(MailServiceImpl.class);
181 
182 }