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