1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.service.impl;
16  
17  import com.liferay.portal.kernel.exception.PortalException;
18  import com.liferay.portal.kernel.exception.SystemException;
19  import com.liferay.portal.model.EmailAddress;
20  import com.liferay.portal.security.permission.ActionKeys;
21  import com.liferay.portal.service.base.EmailAddressServiceBaseImpl;
22  import com.liferay.portal.service.permission.CommonPermissionUtil;
23  
24  import java.util.List;
25  
26  /**
27   * <a href="EmailAddressServiceImpl.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Brian Wing Shun Chan
30   * @author Alexander Chow
31   */
32  public class EmailAddressServiceImpl extends EmailAddressServiceBaseImpl {
33  
34      public EmailAddress addEmailAddress(
35              String className, long classPK, String address, int typeId,
36              boolean primary)
37          throws PortalException, SystemException {
38  
39          CommonPermissionUtil.check(
40              getPermissionChecker(), className, classPK, ActionKeys.UPDATE);
41  
42          return emailAddressLocalService.addEmailAddress(
43              getUserId(), className, classPK, address, typeId, primary);
44      }
45  
46      public void deleteEmailAddress(long emailAddressId)
47          throws PortalException, SystemException {
48  
49          EmailAddress emailAddress = emailAddressPersistence.findByPrimaryKey(
50              emailAddressId);
51  
52          CommonPermissionUtil.check(
53              getPermissionChecker(), emailAddress.getClassNameId(),
54              emailAddress.getClassPK(), ActionKeys.UPDATE);
55  
56          emailAddressLocalService.deleteEmailAddress(emailAddressId);
57      }
58  
59      public EmailAddress getEmailAddress(long emailAddressId)
60          throws PortalException, SystemException {
61  
62          EmailAddress emailAddress = emailAddressPersistence.findByPrimaryKey(
63              emailAddressId);
64  
65          CommonPermissionUtil.check(
66              getPermissionChecker(), emailAddress.getClassNameId(),
67              emailAddress.getClassPK(), ActionKeys.VIEW);
68  
69          return emailAddress;
70      }
71  
72      public List<EmailAddress> getEmailAddresses(String className, long classPK)
73          throws PortalException, SystemException {
74  
75          CommonPermissionUtil.check(
76              getPermissionChecker(), className, classPK, ActionKeys.VIEW);
77  
78          return emailAddressLocalService.getEmailAddresses(
79              getUser().getCompanyId(), className, classPK);
80      }
81  
82      public EmailAddress updateEmailAddress(
83              long emailAddressId, String address, int typeId, boolean primary)
84          throws PortalException, SystemException {
85  
86          EmailAddress emailAddress = emailAddressPersistence.findByPrimaryKey(
87              emailAddressId);
88  
89          CommonPermissionUtil.check(
90              getPermissionChecker(), emailAddress.getClassNameId(),
91              emailAddress.getClassPK(), ActionKeys.UPDATE);
92  
93          return emailAddressLocalService.updateEmailAddress(
94              emailAddressId, address, typeId, primary);
95      }
96  
97  }