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.EmailAddress;
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.EmailAddressServiceBaseImpl;
023    import com.liferay.portal.service.permission.CommonPermissionUtil;
024    
025    import java.util.List;
026    
027    /**
028     * @author Brian Wing Shun Chan
029     * @author Alexander Chow
030     */
031    public class EmailAddressServiceImpl extends EmailAddressServiceBaseImpl {
032    
033            /**
034             * @deprecated As of 6.2.0, replaced by {@link #addEmailAddress(String,
035             *             long, String, int, boolean, ServiceContext)}
036             */
037            @Deprecated
038            @Override
039            public EmailAddress addEmailAddress(
040                            String className, long classPK, String address, int typeId,
041                            boolean primary)
042                    throws PortalException {
043    
044                    CommonPermissionUtil.check(
045                            getPermissionChecker(), className, classPK, ActionKeys.UPDATE);
046    
047                    return emailAddressLocalService.addEmailAddress(
048                            getUserId(), className, classPK, address, typeId, primary);
049            }
050    
051            @Override
052            public EmailAddress addEmailAddress(
053                            String className, long classPK, String address, int typeId,
054                            boolean primary, ServiceContext serviceContext)
055                    throws PortalException {
056    
057                    CommonPermissionUtil.check(
058                            getPermissionChecker(), className, classPK, ActionKeys.UPDATE);
059    
060                    return emailAddressLocalService.addEmailAddress(
061                            getUserId(), className, classPK, address, typeId, primary,
062                            serviceContext);
063            }
064    
065            @Override
066            public void deleteEmailAddress(long emailAddressId) throws PortalException {
067                    EmailAddress emailAddress = emailAddressPersistence.findByPrimaryKey(
068                            emailAddressId);
069    
070                    CommonPermissionUtil.check(
071                            getPermissionChecker(), emailAddress.getClassNameId(),
072                            emailAddress.getClassPK(), ActionKeys.UPDATE);
073    
074                    emailAddressLocalService.deleteEmailAddress(emailAddress);
075            }
076    
077            @Override
078            public EmailAddress getEmailAddress(long emailAddressId)
079                    throws PortalException {
080    
081                    EmailAddress emailAddress = emailAddressPersistence.findByPrimaryKey(
082                            emailAddressId);
083    
084                    CommonPermissionUtil.check(
085                            getPermissionChecker(), emailAddress.getClassNameId(),
086                            emailAddress.getClassPK(), ActionKeys.VIEW);
087    
088                    return emailAddress;
089            }
090    
091            @Override
092            public List<EmailAddress> getEmailAddresses(String className, long classPK)
093                    throws PortalException {
094    
095                    CommonPermissionUtil.check(
096                            getPermissionChecker(), className, classPK, ActionKeys.VIEW);
097    
098                    User user = getUser();
099    
100                    return emailAddressLocalService.getEmailAddresses(
101                            user.getCompanyId(), className, classPK);
102            }
103    
104            @Override
105            public EmailAddress updateEmailAddress(
106                            long emailAddressId, String address, int typeId, boolean primary)
107                    throws PortalException {
108    
109                    EmailAddress emailAddress = emailAddressPersistence.findByPrimaryKey(
110                            emailAddressId);
111    
112                    CommonPermissionUtil.check(
113                            getPermissionChecker(), emailAddress.getClassNameId(),
114                            emailAddress.getClassPK(), ActionKeys.UPDATE);
115    
116                    return emailAddressLocalService.updateEmailAddress(
117                            emailAddressId, address, typeId, primary);
118            }
119    
120    }