001    /**
002     * Copyright (c) 2000-2013 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.ServiceContext;
023    import com.liferay.portal.service.base.PhoneServiceBaseImpl;
024    import com.liferay.portal.service.permission.CommonPermissionUtil;
025    
026    import java.util.List;
027    
028    /**
029     * @author Brian Wing Shun Chan
030     */
031    public class PhoneServiceImpl extends PhoneServiceBaseImpl {
032    
033            /**
034             * @deprecated As of 6.2.0, replaced by {@link #addPhone( String, long,
035             *             String, String, int, boolean, ServiceContext)}
036             */
037            @Override
038            public Phone addPhone(
039                            String className, long classPK, String number, String extension,
040                            int typeId, boolean primary)
041                    throws PortalException, SystemException {
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                            int typeId, boolean primary, ServiceContext serviceContext)
055                    throws PortalException, SystemException {
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)
067                    throws PortalException, SystemException {
068    
069                    Phone phone = phonePersistence.findByPrimaryKey(phoneId);
070    
071                    CommonPermissionUtil.check(
072                            getPermissionChecker(), phone.getClassNameId(), phone.getClassPK(),
073                            ActionKeys.UPDATE);
074    
075                    phoneLocalService.deletePhone(phoneId);
076            }
077    
078            @Override
079            public Phone getPhone(long phoneId)
080                    throws PortalException, SystemException {
081    
082                    Phone phone = phonePersistence.findByPrimaryKey(phoneId);
083    
084                    CommonPermissionUtil.check(
085                            getPermissionChecker(), phone.getClassNameId(), phone.getClassPK(),
086                            ActionKeys.VIEW);
087    
088                    return phone;
089            }
090    
091            @Override
092            public List<Phone> getPhones(String className, long classPK)
093                    throws PortalException, SystemException {
094    
095                    CommonPermissionUtil.check(
096                            getPermissionChecker(), className, classPK, ActionKeys.VIEW);
097    
098                    User user = getUser();
099    
100                    return phoneLocalService.getPhones(
101                            user.getCompanyId(), className, classPK);
102            }
103    
104            @Override
105            public Phone updatePhone(
106                            long phoneId, String number, String extension, int typeId,
107                            boolean primary)
108                    throws PortalException, SystemException {
109    
110                    Phone phone = phonePersistence.findByPrimaryKey(phoneId);
111    
112                    CommonPermissionUtil.check(
113                            getPermissionChecker(), phone.getClassNameId(), phone.getClassPK(),
114                            ActionKeys.UPDATE);
115    
116                    return phoneLocalService.updatePhone(
117                            phoneId, number, extension, typeId, primary);
118            }
119    
120    }