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