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