001    /**
002     * Copyright (c) 2000-2012 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.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    }