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