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                    // User
035    
036                    CyrusUser user = new CyrusUser(userId, password);
037    
038                    CyrusUserUtil.update(user);
039    
040                    // Virtual
041    
042                    CyrusVirtual virtual = new CyrusVirtual(emailAddress, userId);
043    
044                    CyrusVirtualUtil.update(virtual);
045            }
046    
047            public void deleteEmailAddress(long companyId, long userId)
048                    throws SystemException {
049    
050                    CyrusVirtualUtil.removeByUserId(userId);
051            }
052    
053            public void deleteUser(long userId) throws SystemException {
054    
055                    // User
056    
057                    try {
058                            CyrusUserUtil.remove(userId);
059                    }
060                    catch (NoSuchCyrusUserException nscue) {
061                    }
062    
063                    // Virtual
064    
065                    CyrusVirtualUtil.removeByUserId(userId);
066            }
067    
068            public String getBeanIdentifier() {
069                    return _beanIdentifier;
070            }
071    
072            public void setBeanIdentifier(String beanIdentifier) {
073                    _beanIdentifier = beanIdentifier;
074            }
075    
076            public void updateEmailAddress(
077                            long companyId, long userId, String emailAddress)
078                    throws SystemException {
079    
080                    CyrusVirtualUtil.removeByUserId(userId);
081    
082                    CyrusVirtual virtual = new CyrusVirtual(emailAddress, userId);
083    
084                    CyrusVirtualUtil.update(virtual);
085            }
086    
087            public void updatePassword(long companyId, long userId, String password)
088                    throws SystemException {
089    
090                    CyrusUser user = null;
091    
092                    try {
093                            user = CyrusUserUtil.findByPrimaryKey(userId);
094                    }
095                    catch (NoSuchCyrusUserException nscue) {
096                            user = new CyrusUser(userId, password);
097                    }
098    
099                    user.setPassword(password);
100    
101                    CyrusUserUtil.update(user);
102            }
103    
104            private String _beanIdentifier;
105    
106    }