001    /**
002     * Copyright (c) 2000-2013 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.portal.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.model.UserIdMapper;
020    import com.liferay.portal.service.base.UserIdMapperLocalServiceBaseImpl;
021    
022    import java.util.List;
023    
024    /**
025     * @author Brian Wing Shun Chan
026     */
027    public class UserIdMapperLocalServiceImpl
028            extends UserIdMapperLocalServiceBaseImpl {
029    
030            @Override
031            public void deleteUserIdMappers(long userId) throws SystemException {
032                    userIdMapperPersistence.removeByUserId(userId);
033            }
034    
035            @Override
036            public UserIdMapper getUserIdMapper(long userId, String type)
037                    throws PortalException, SystemException {
038    
039                    return userIdMapperPersistence.findByU_T(userId, type);
040            }
041    
042            @Override
043            public UserIdMapper getUserIdMapperByExternalUserId(
044                            String type, String externalUserId)
045                    throws PortalException, SystemException {
046    
047                    return userIdMapperPersistence.findByT_E(type, externalUserId);
048            }
049    
050            @Override
051            public List<UserIdMapper> getUserIdMappers(long userId)
052                    throws SystemException {
053    
054                    return userIdMapperPersistence.findByUserId(userId);
055            }
056    
057            @Override
058            public UserIdMapper updateUserIdMapper(
059                            long userId, String type, String description, String externalUserId)
060                    throws SystemException {
061    
062                    UserIdMapper userIdMapper = userIdMapperPersistence.fetchByU_T(
063                            userId, type);
064    
065                    if (userIdMapper == null) {
066                            long userIdMapperId = counterLocalService.increment();
067    
068                            userIdMapper = userIdMapperPersistence.create(userIdMapperId);
069                    }
070    
071                    userIdMapper.setUserId(userId);
072                    userIdMapper.setType(type);
073                    userIdMapper.setDescription(description);
074                    userIdMapper.setExternalUserId(externalUserId);
075    
076                    userIdMapperPersistence.update(userIdMapper);
077    
078                    return userIdMapper;
079            }
080    
081    }