001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }