001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.model.Phone;
020    import com.liferay.portal.security.permission.ActionKeys;
021    import com.liferay.portal.service.base.PhoneServiceBaseImpl;
022    import com.liferay.portal.service.permission.CommonPermissionUtil;
023    
024    import java.util.List;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     */
029    public class PhoneServiceImpl extends PhoneServiceBaseImpl {
030    
031            public Phone addPhone(
032                            String className, long classPK, String number, String extension,
033                            int typeId, boolean primary)
034                    throws PortalException, SystemException {
035    
036                    CommonPermissionUtil.check(
037                            getPermissionChecker(), className, classPK, ActionKeys.UPDATE);
038    
039                    return phoneLocalService.addPhone(
040                            getUserId(), className, classPK, number, extension, typeId,
041                            primary);
042            }
043    
044            public void deletePhone(long phoneId)
045                    throws PortalException, SystemException {
046    
047                    Phone phone = phonePersistence.findByPrimaryKey(phoneId);
048    
049                    CommonPermissionUtil.check(
050                            getPermissionChecker(), phone.getClassNameId(), phone.getClassPK(),
051                            ActionKeys.UPDATE);
052    
053                    phoneLocalService.deletePhone(phoneId);
054            }
055    
056            public Phone getPhone(long phoneId)
057                    throws PortalException, SystemException {
058    
059                    Phone phone = phonePersistence.findByPrimaryKey(phoneId);
060    
061                    CommonPermissionUtil.check(
062                            getPermissionChecker(), phone.getClassNameId(), phone.getClassPK(),
063                            ActionKeys.VIEW);
064    
065                    return phone;
066            }
067    
068            public List<Phone> getPhones(String className, long classPK)
069                    throws PortalException, SystemException {
070    
071                    CommonPermissionUtil.check(
072                            getPermissionChecker(), className, classPK, ActionKeys.VIEW);
073    
074                    return phoneLocalService.getPhones(
075                            getUser().getCompanyId(), className, classPK);
076            }
077    
078            public Phone updatePhone(
079                            long phoneId, String number, String extension, int typeId,
080                            boolean primary)
081                    throws PortalException, SystemException {
082    
083                    Phone phone = phonePersistence.findByPrimaryKey(phoneId);
084    
085                    CommonPermissionUtil.check(
086                            getPermissionChecker(), phone.getClassNameId(), phone.getClassPK(),
087                            ActionKeys.UPDATE);
088    
089                    return phoneLocalService.updatePhone(
090                            phoneId, number, extension, typeId, primary);
091            }
092    
093    }