001    /**
002     * Copyright (c) 2000-2011 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    
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    }