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.model.Phone;
019    import com.liferay.portal.model.User;
020    import com.liferay.portal.security.permission.ActionKeys;
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            /**
033             * @deprecated As of 6.2.0, replaced by {@link #addPhone(String, long,
034             *             String, String, int, boolean, ServiceContext)}
035             */
036            @Deprecated
037            @Override
038            public Phone addPhone(
039                            String className, long classPK, String number, String extension,
040                            long typeId, boolean primary)
041                    throws PortalException {
042    
043                    CommonPermissionUtil.check(
044                            getPermissionChecker(), className, classPK, ActionKeys.UPDATE);
045    
046                    return phoneLocalService.addPhone(
047                            getUserId(), className, classPK, number, extension, typeId,
048                            primary);
049            }
050    
051            @Override
052            public Phone addPhone(
053                            String className, long classPK, String number, String extension,
054                            long typeId, boolean primary, ServiceContext serviceContext)
055                    throws PortalException {
056    
057                    CommonPermissionUtil.check(
058                            getPermissionChecker(), className, classPK, ActionKeys.UPDATE);
059    
060                    return phoneLocalService.addPhone(
061                            getUserId(), className, classPK, number, extension, typeId, primary,
062                            serviceContext);
063            }
064    
065            @Override
066            public void deletePhone(long phoneId) throws PortalException {
067                    Phone phone = phonePersistence.findByPrimaryKey(phoneId);
068    
069                    CommonPermissionUtil.check(
070                            getPermissionChecker(), phone.getClassNameId(), phone.getClassPK(),
071                            ActionKeys.UPDATE);
072    
073                    phoneLocalService.deletePhone(phone);
074            }
075    
076            @Override
077            public Phone getPhone(long phoneId) throws PortalException {
078                    Phone phone = phonePersistence.findByPrimaryKey(phoneId);
079    
080                    CommonPermissionUtil.check(
081                            getPermissionChecker(), phone.getClassNameId(), phone.getClassPK(),
082                            ActionKeys.VIEW);
083    
084                    return phone;
085            }
086    
087            @Override
088            public List<Phone> getPhones(String className, long classPK)
089                    throws PortalException {
090    
091                    CommonPermissionUtil.check(
092                            getPermissionChecker(), className, classPK, ActionKeys.VIEW);
093    
094                    User user = getUser();
095    
096                    return phoneLocalService.getPhones(
097                            user.getCompanyId(), className, classPK);
098            }
099    
100            @Override
101            public Phone updatePhone(
102                            long phoneId, String number, String extension, long typeId,
103                            boolean primary)
104                    throws PortalException {
105    
106                    Phone phone = phonePersistence.findByPrimaryKey(phoneId);
107    
108                    CommonPermissionUtil.check(
109                            getPermissionChecker(), phone.getClassNameId(), phone.getClassPK(),
110                            ActionKeys.UPDATE);
111    
112                    return phoneLocalService.updatePhone(
113                            phoneId, number, extension, typeId, primary);
114            }
115    
116    }