001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.mail.service.impl;
016    
017    import com.liferay.mail.NoSuchCyrusUserException;
018    import com.liferay.mail.model.CyrusUser;
019    import com.liferay.mail.model.CyrusVirtual;
020    import com.liferay.mail.service.CyrusService;
021    import com.liferay.mail.service.persistence.CyrusUserUtil;
022    import com.liferay.mail.service.persistence.CyrusVirtualUtil;
023    import com.liferay.portal.kernel.bean.IdentifiableBean;
024    import com.liferay.portal.kernel.exception.SystemException;
025    import com.liferay.portal.kernel.security.pacl.DoPrivileged;
026    
027    /**
028     * @author Alexander Chow
029     */
030    @DoPrivileged
031    public class CyrusServiceImpl implements CyrusService, IdentifiableBean {
032    
033            @Override
034            public void addUser(long userId, String emailAddress, String password)
035                    throws SystemException {
036    
037                    CyrusUser cyrusUser = new CyrusUser(userId, password);
038    
039                    CyrusUserUtil.update(cyrusUser);
040    
041                    CyrusVirtual cyrusVirtual = new CyrusVirtual(emailAddress, userId);
042    
043                    CyrusVirtualUtil.update(cyrusVirtual);
044            }
045    
046            @Override
047            public void deleteEmailAddress(long companyId, long userId)
048                    throws SystemException {
049    
050                    CyrusVirtualUtil.removeByUserId(userId);
051            }
052    
053            @Override
054            public void deleteUser(long userId) throws SystemException {
055                    try {
056                            CyrusUserUtil.remove(userId);
057                    }
058                    catch (NoSuchCyrusUserException nscue) {
059                    }
060    
061                    CyrusVirtualUtil.removeByUserId(userId);
062            }
063    
064            @Override
065            public String getBeanIdentifier() {
066                    return _beanIdentifier;
067            }
068    
069            @Override
070            public void setBeanIdentifier(String beanIdentifier) {
071                    _beanIdentifier = beanIdentifier;
072            }
073    
074            @Override
075            public void updateEmailAddress(
076                            long companyId, long userId, String emailAddress)
077                    throws SystemException {
078    
079                    CyrusVirtualUtil.removeByUserId(userId);
080    
081                    CyrusVirtual cyrusVirtual = new CyrusVirtual(emailAddress, userId);
082    
083                    CyrusVirtualUtil.update(cyrusVirtual);
084            }
085    
086            @Override
087            public void updatePassword(long companyId, long userId, String password)
088                    throws SystemException {
089    
090                    CyrusUser cyrusUser = null;
091    
092                    try {
093                            cyrusUser = CyrusUserUtil.findByPrimaryKey(userId);
094                    }
095                    catch (NoSuchCyrusUserException nscue) {
096                            cyrusUser = new CyrusUser(userId, password);
097                    }
098    
099                    cyrusUser.setPassword(password);
100    
101                    CyrusUserUtil.update(cyrusUser);
102            }
103    
104            private String _beanIdentifier;
105    
106    }