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