1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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.portal.service.impl;
24  
25  import com.liferay.portal.PortalException;
26  import com.liferay.portal.SystemException;
27  import com.liferay.portal.model.EmailAddress;
28  import com.liferay.portal.security.permission.ActionKeys;
29  import com.liferay.portal.service.base.EmailAddressServiceBaseImpl;
30  import com.liferay.portal.service.permission.CommonPermissionUtil;
31  
32  import java.util.List;
33  
34  /**
35   * <a href="EmailAddressServiceImpl.java.html"><b><i>View Source</i></b></a>
36   *
37   * @author Brian Wing Shun Chan
38   * @author Alexander Chow
39   */
40  public class EmailAddressServiceImpl extends EmailAddressServiceBaseImpl {
41  
42      public EmailAddress addEmailAddress(
43              String className, long classPK, String address, int typeId,
44              boolean primary)
45          throws PortalException, SystemException {
46  
47          CommonPermissionUtil.check(
48              getPermissionChecker(), className, classPK, ActionKeys.UPDATE);
49  
50          return emailAddressLocalService.addEmailAddress(
51              getUserId(), className, classPK, address, typeId, primary);
52      }
53  
54      public void deleteEmailAddress(long emailAddressId)
55          throws PortalException, SystemException {
56  
57          EmailAddress emailAddress = emailAddressPersistence.findByPrimaryKey(
58              emailAddressId);
59  
60          CommonPermissionUtil.check(
61              getPermissionChecker(), emailAddress.getClassNameId(),
62              emailAddress.getClassPK(), ActionKeys.UPDATE);
63  
64          emailAddressLocalService.deleteEmailAddress(emailAddressId);
65      }
66  
67      public EmailAddress getEmailAddress(long emailAddressId)
68          throws PortalException, SystemException {
69  
70          EmailAddress emailAddress = emailAddressPersistence.findByPrimaryKey(
71              emailAddressId);
72  
73          CommonPermissionUtil.check(
74              getPermissionChecker(), emailAddress.getClassNameId(),
75              emailAddress.getClassPK(), ActionKeys.VIEW);
76  
77          return emailAddress;
78      }
79  
80      public List<EmailAddress> getEmailAddresses(String className, long classPK)
81          throws PortalException, SystemException {
82  
83          CommonPermissionUtil.check(
84              getPermissionChecker(), className, classPK, ActionKeys.VIEW);
85  
86          return emailAddressLocalService.getEmailAddresses(
87              getUser().getCompanyId(), className, classPK);
88      }
89  
90      public EmailAddress updateEmailAddress(
91              long emailAddressId, String address, int typeId, boolean primary)
92          throws PortalException, SystemException {
93  
94          EmailAddress emailAddress = emailAddressPersistence.findByPrimaryKey(
95              emailAddressId);
96  
97          CommonPermissionUtil.check(
98              getPermissionChecker(), emailAddress.getClassNameId(),
99              emailAddress.getClassPK(), ActionKeys.UPDATE);
100 
101         return emailAddressLocalService.updateEmailAddress(
102             emailAddressId, address, typeId, primary);
103     }
104 
105 }