001    /**
002     * Copyright (c) 2000-2011 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.model.User;
021    import com.liferay.portal.security.permission.ActionKeys;
022    import com.liferay.portal.service.base.PhoneServiceBaseImpl;
023    import com.liferay.portal.service.permission.CommonPermissionUtil;
024    
025    import java.util.List;
026    
027    /**
028     * @author Brian Wing Shun Chan
029     */
030    public class PhoneServiceImpl extends PhoneServiceBaseImpl {
031    
032            public Phone addPhone(
033                            String className, long classPK, String number, String extension,
034                            int typeId, boolean primary)
035                    throws PortalException, SystemException {
036    
037                    CommonPermissionUtil.check(
038                            getPermissionChecker(), className, classPK, ActionKeys.UPDATE);
039    
040                    return phoneLocalService.addPhone(
041                            getUserId(), className, classPK, number, extension, typeId,
042                            primary);
043            }
044    
045            public void deletePhone(long phoneId)
046                    throws PortalException, SystemException {
047    
048                    Phone phone = phonePersistence.findByPrimaryKey(phoneId);
049    
050                    CommonPermissionUtil.check(
051                            getPermissionChecker(), phone.getClassNameId(), phone.getClassPK(),
052                            ActionKeys.UPDATE);
053    
054                    phoneLocalService.deletePhone(phoneId);
055            }
056    
057            public Phone getPhone(long phoneId)
058                    throws PortalException, SystemException {
059    
060                    Phone phone = phonePersistence.findByPrimaryKey(phoneId);
061    
062                    CommonPermissionUtil.check(
063                            getPermissionChecker(), phone.getClassNameId(), phone.getClassPK(),
064                            ActionKeys.VIEW);
065    
066                    return phone;
067            }
068    
069            public List<Phone> getPhones(String className, long classPK)
070                    throws PortalException, SystemException {
071    
072                    CommonPermissionUtil.check(
073                            getPermissionChecker(), className, classPK, ActionKeys.VIEW);
074    
075                    User user = getUser();
076    
077                    return phoneLocalService.getPhones(
078                            user.getCompanyId(), className, classPK);
079            }
080    
081            public Phone updatePhone(
082                            long phoneId, String number, String extension, int typeId,
083                            boolean primary)
084                    throws PortalException, SystemException {
085    
086                    Phone phone = phonePersistence.findByPrimaryKey(phoneId);
087    
088                    CommonPermissionUtil.check(
089                            getPermissionChecker(), phone.getClassNameId(), phone.getClassPK(),
090                            ActionKeys.UPDATE);
091    
092                    return phoneLocalService.updatePhone(
093                            phoneId, number, extension, typeId, primary);
094            }
095    
096    }