001    /**
002     * Copyright (c) 2000-present 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.security.permission.ActionKeys;
019    import com.liferay.portal.model.Phone;
020    import com.liferay.portal.model.User;
021    import com.liferay.portal.service.ServiceContext;
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            @Override
033            public Phone addPhone(
034                            String className, long classPK, String number, String extension,
035                            long typeId, boolean primary, ServiceContext serviceContext)
036                    throws PortalException {
037    
038                    CommonPermissionUtil.check(
039                            getPermissionChecker(), className, classPK, ActionKeys.UPDATE);
040    
041                    return phoneLocalService.addPhone(
042                            getUserId(), className, classPK, number, extension, typeId, primary,
043                            serviceContext);
044            }
045    
046            @Override
047            public void deletePhone(long phoneId) throws PortalException {
048                    Phone phone = phonePersistence.findByPrimaryKey(phoneId);
049    
050                    CommonPermissionUtil.check(
051                            getPermissionChecker(), phone.getClassNameId(), phone.getClassPK(),
052                            ActionKeys.UPDATE);
053    
054                    phoneLocalService.deletePhone(phone);
055            }
056    
057            @Override
058            public Phone getPhone(long phoneId) throws PortalException {
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            @Override
069            public List<Phone> getPhones(String className, long classPK)
070                    throws PortalException {
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            @Override
082            public Phone updatePhone(
083                            long phoneId, String number, String extension, long typeId,
084                            boolean primary)
085                    throws PortalException {
086    
087                    Phone phone = phonePersistence.findByPrimaryKey(phoneId);
088    
089                    CommonPermissionUtil.check(
090                            getPermissionChecker(), phone.getClassNameId(), phone.getClassPK(),
091                            ActionKeys.UPDATE);
092    
093                    return phoneLocalService.updatePhone(
094                            phoneId, number, extension, typeId, primary);
095            }
096    
097    }