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.Phone;
20  import com.liferay.portal.security.permission.ActionKeys;
21  import com.liferay.portal.service.base.PhoneServiceBaseImpl;
22  import com.liferay.portal.service.permission.CommonPermissionUtil;
23  
24  import java.util.List;
25  
26  /**
27   * <a href="PhoneServiceImpl.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Brian Wing Shun Chan
30   */
31  public class PhoneServiceImpl extends PhoneServiceBaseImpl {
32  
33      public Phone addPhone(
34              String className, long classPK, String number, String extension,
35              int typeId, boolean primary)
36          throws PortalException, SystemException {
37  
38          CommonPermissionUtil.check(
39              getPermissionChecker(), className, classPK, ActionKeys.UPDATE);
40  
41          return phoneLocalService.addPhone(
42              getUserId(), className, classPK, number, extension, typeId,
43              primary);
44      }
45  
46      public void deletePhone(long phoneId)
47          throws PortalException, SystemException {
48  
49          Phone phone = phonePersistence.findByPrimaryKey(phoneId);
50  
51          CommonPermissionUtil.check(
52              getPermissionChecker(), phone.getClassNameId(), phone.getClassPK(),
53              ActionKeys.UPDATE);
54  
55          phoneLocalService.deletePhone(phoneId);
56      }
57  
58      public Phone getPhone(long phoneId)
59          throws PortalException, SystemException {
60  
61          Phone phone = phonePersistence.findByPrimaryKey(phoneId);
62  
63          CommonPermissionUtil.check(
64              getPermissionChecker(), phone.getClassNameId(), phone.getClassPK(),
65              ActionKeys.VIEW);
66  
67          return phone;
68      }
69  
70      public List<Phone> getPhones(String className, long classPK)
71          throws PortalException, SystemException {
72  
73          CommonPermissionUtil.check(
74              getPermissionChecker(), className, classPK, ActionKeys.VIEW);
75  
76          return phoneLocalService.getPhones(
77              getUser().getCompanyId(), className, classPK);
78      }
79  
80      public Phone updatePhone(
81              long phoneId, String number, String extension, int typeId,
82              boolean primary)
83          throws PortalException, SystemException {
84  
85          Phone phone = phonePersistence.findByPrimaryKey(phoneId);
86  
87          CommonPermissionUtil.check(
88              getPermissionChecker(), phone.getClassNameId(), phone.getClassPK(),
89              ActionKeys.UPDATE);
90  
91          return phoneLocalService.updatePhone(
92              phoneId, number, extension, typeId, primary);
93      }
94  
95  }