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.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    
026    /**
027     * @author Alexander Chow
028     */
029    public class CyrusServiceImpl implements CyrusService, IdentifiableBean {
030    
031            public void addUser(long userId, String emailAddress, String password)
032                    throws SystemException {
033    
034                    CyrusUser cyrusUser = new CyrusUser(userId, password);
035    
036                    CyrusUserUtil.update(cyrusUser);
037    
038                    CyrusVirtual cyrusVirtual = new CyrusVirtual(emailAddress, userId);
039    
040                    CyrusVirtualUtil.update(cyrusVirtual);
041            }
042    
043            public void deleteEmailAddress(long companyId, long userId)
044                    throws SystemException {
045    
046                    CyrusVirtualUtil.removeByUserId(userId);
047            }
048    
049            public void deleteUser(long userId) throws SystemException {
050                    try {
051                            CyrusUserUtil.remove(userId);
052                    }
053                    catch (NoSuchCyrusUserException nscue) {
054                    }
055    
056                    CyrusVirtualUtil.removeByUserId(userId);
057            }
058    
059            public String getBeanIdentifier() {
060                    return _beanIdentifier;
061            }
062    
063            public void setBeanIdentifier(String beanIdentifier) {
064                    _beanIdentifier = beanIdentifier;
065            }
066    
067            public void updateEmailAddress(
068                            long companyId, long userId, String emailAddress)
069                    throws SystemException {
070    
071                    CyrusVirtualUtil.removeByUserId(userId);
072    
073                    CyrusVirtual cyrusVirtual = new CyrusVirtual(emailAddress, userId);
074    
075                    CyrusVirtualUtil.update(cyrusVirtual);
076            }
077    
078            public void updatePassword(long companyId, long userId, String password)
079                    throws SystemException {
080    
081                    CyrusUser cyrusUser = null;
082    
083                    try {
084                            cyrusUser = CyrusUserUtil.findByPrimaryKey(userId);
085                    }
086                    catch (NoSuchCyrusUserException nscue) {
087                            cyrusUser = new CyrusUser(userId, password);
088                    }
089    
090                    cyrusUser.setPassword(password);
091    
092                    CyrusUserUtil.update(cyrusUser);
093            }
094    
095            private String _beanIdentifier;
096    
097    }