1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.service.impl;
16  
17  import com.liferay.portal.PortalException;
18  import com.liferay.portal.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  }