001    /**
002     * Copyright (c) 2000-2010 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            public void deleteUserIdMappers(long userId) throws SystemException {
031                    userIdMapperPersistence.removeByUserId(userId);
032            }
033    
034            public UserIdMapper getUserIdMapper(long userId, String type)
035                    throws PortalException, SystemException {
036    
037                    return userIdMapperPersistence.findByU_T(userId, type);
038            }
039    
040            public UserIdMapper getUserIdMapperByExternalUserId(
041                            String type, String externalUserId)
042                    throws PortalException, SystemException {
043    
044                    return userIdMapperPersistence.findByT_E(type, externalUserId);
045            }
046    
047            public List<UserIdMapper> getUserIdMappers(long userId)
048                    throws SystemException {
049    
050                    return userIdMapperPersistence.findByUserId(userId);
051            }
052    
053            public UserIdMapper updateUserIdMapper(
054                            long userId, String type, String description, String externalUserId)
055                    throws SystemException {
056    
057                    UserIdMapper userIdMapper = userIdMapperPersistence.fetchByU_T(
058                            userId, type);
059    
060                    if (userIdMapper == null) {
061                            long userIdMapperId = counterLocalService.increment();
062    
063                            userIdMapper = userIdMapperPersistence.create(userIdMapperId);
064                    }
065    
066                    userIdMapper.setUserId(userId);
067                    userIdMapper.setType(type);
068                    userIdMapper.setDescription(description);
069                    userIdMapper.setExternalUserId(externalUserId);
070    
071                    userIdMapperPersistence.update(userIdMapper, false);
072    
073                    return userIdMapper;
074            }
075    
076    }