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.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            @Override
034            public EmailAddress addEmailAddress(
035                            String className, long classPK, String address, int typeId,
036                            boolean primary)
037                    throws PortalException, SystemException {
038    
039                    CommonPermissionUtil.check(
040                            getPermissionChecker(), className, classPK, ActionKeys.UPDATE);
041    
042                    return emailAddressLocalService.addEmailAddress(
043                            getUserId(), className, classPK, address, typeId, primary);
044            }
045    
046            @Override
047            public void deleteEmailAddress(long emailAddressId)
048                    throws PortalException, SystemException {
049    
050                    EmailAddress emailAddress = emailAddressPersistence.findByPrimaryKey(
051                            emailAddressId);
052    
053                    CommonPermissionUtil.check(
054                            getPermissionChecker(), emailAddress.getClassNameId(),
055                            emailAddress.getClassPK(), ActionKeys.UPDATE);
056    
057                    emailAddressLocalService.deleteEmailAddress(emailAddressId);
058            }
059    
060            @Override
061            public EmailAddress getEmailAddress(long emailAddressId)
062                    throws PortalException, SystemException {
063    
064                    EmailAddress emailAddress = emailAddressPersistence.findByPrimaryKey(
065                            emailAddressId);
066    
067                    CommonPermissionUtil.check(
068                            getPermissionChecker(), emailAddress.getClassNameId(),
069                            emailAddress.getClassPK(), ActionKeys.VIEW);
070    
071                    return emailAddress;
072            }
073    
074            @Override
075            public List<EmailAddress> getEmailAddresses(String className, long classPK)
076                    throws PortalException, SystemException {
077    
078                    CommonPermissionUtil.check(
079                            getPermissionChecker(), className, classPK, ActionKeys.VIEW);
080    
081                    User user = getUser();
082    
083                    return emailAddressLocalService.getEmailAddresses(
084                            user.getCompanyId(), className, classPK);
085            }
086    
087            @Override
088            public EmailAddress updateEmailAddress(
089                            long emailAddressId, String address, int typeId, boolean primary)
090                    throws PortalException, SystemException {
091    
092                    EmailAddress emailAddress = emailAddressPersistence.findByPrimaryKey(
093                            emailAddressId);
094    
095                    CommonPermissionUtil.check(
096                            getPermissionChecker(), emailAddress.getClassNameId(),
097                            emailAddress.getClassPK(), ActionKeys.UPDATE);
098    
099                    return emailAddressLocalService.updateEmailAddress(
100                            emailAddressId, address, typeId, primary);
101            }
102    
103    }