001    /**
002     * Copyright (c) 2000-2010 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.security.permission.ActionKeys;
021    import com.liferay.portal.service.base.EmailAddressServiceBaseImpl;
022    import com.liferay.portal.service.permission.CommonPermissionUtil;
023    
024    import java.util.List;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     * @author Alexander Chow
029     */
030    public class EmailAddressServiceImpl extends EmailAddressServiceBaseImpl {
031    
032            public EmailAddress addEmailAddress(
033                            String className, long classPK, String address, int typeId,
034                            boolean primary)
035                    throws PortalException, SystemException {
036    
037                    CommonPermissionUtil.check(
038                            getPermissionChecker(), className, classPK, ActionKeys.UPDATE);
039    
040                    return emailAddressLocalService.addEmailAddress(
041                            getUserId(), className, classPK, address, typeId, primary);
042            }
043    
044            public void deleteEmailAddress(long emailAddressId)
045                    throws PortalException, SystemException {
046    
047                    EmailAddress emailAddress = emailAddressPersistence.findByPrimaryKey(
048                            emailAddressId);
049    
050                    CommonPermissionUtil.check(
051                            getPermissionChecker(), emailAddress.getClassNameId(),
052                            emailAddress.getClassPK(), ActionKeys.UPDATE);
053    
054                    emailAddressLocalService.deleteEmailAddress(emailAddressId);
055            }
056    
057            public EmailAddress getEmailAddress(long emailAddressId)
058                    throws PortalException, SystemException {
059    
060                    EmailAddress emailAddress = emailAddressPersistence.findByPrimaryKey(
061                            emailAddressId);
062    
063                    CommonPermissionUtil.check(
064                            getPermissionChecker(), emailAddress.getClassNameId(),
065                            emailAddress.getClassPK(), ActionKeys.VIEW);
066    
067                    return emailAddress;
068            }
069    
070            public List<EmailAddress> getEmailAddresses(String className, long classPK)
071                    throws PortalException, SystemException {
072    
073                    CommonPermissionUtil.check(
074                            getPermissionChecker(), className, classPK, ActionKeys.VIEW);
075    
076                    return emailAddressLocalService.getEmailAddresses(
077                            getUser().getCompanyId(), className, classPK);
078            }
079    
080            public EmailAddress updateEmailAddress(
081                            long emailAddressId, String address, int typeId, boolean primary)
082                    throws PortalException, SystemException {
083    
084                    EmailAddress emailAddress = emailAddressPersistence.findByPrimaryKey(
085                            emailAddressId);
086    
087                    CommonPermissionUtil.check(
088                            getPermissionChecker(), emailAddress.getClassNameId(),
089                            emailAddress.getClassPK(), ActionKeys.UPDATE);
090    
091                    return emailAddressLocalService.updateEmailAddress(
092                            emailAddressId, address, typeId, primary);
093            }
094    
095    }