1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.service.impl;
16  
17  import com.liferay.portal.kernel.exception.PortalException;
18  import com.liferay.portal.kernel.exception.SystemException;
19  import com.liferay.portal.model.UserIdMapper;
20  import com.liferay.portal.service.base.UserIdMapperLocalServiceBaseImpl;
21  
22  import java.util.List;
23  
24  /**
25   * <a href="UserIdMapperLocalServiceImpl.java.html"><b><i>View Source</i></b>
26   * </a>
27   *
28   * @author Brian Wing Shun Chan
29   */
30  public class UserIdMapperLocalServiceImpl
31      extends UserIdMapperLocalServiceBaseImpl {
32  
33      public void deleteUserIdMappers(long userId) throws SystemException {
34          userIdMapperPersistence.removeByUserId(userId);
35      }
36  
37      public UserIdMapper getUserIdMapper(long userId, String type)
38          throws PortalException, SystemException {
39  
40          return userIdMapperPersistence.findByU_T(userId, type);
41      }
42  
43      public UserIdMapper getUserIdMapperByExternalUserId(
44              String type, String externalUserId)
45          throws PortalException, SystemException {
46  
47          return userIdMapperPersistence.findByT_E(type, externalUserId);
48      }
49  
50      public List<UserIdMapper> getUserIdMappers(long userId)
51          throws SystemException {
52  
53          return userIdMapperPersistence.findByUserId(userId);
54      }
55  
56      public UserIdMapper updateUserIdMapper(
57              long userId, String type, String description, String externalUserId)
58          throws SystemException {
59  
60          UserIdMapper userIdMapper = userIdMapperPersistence.fetchByU_T(
61              userId, type);
62  
63          if (userIdMapper == null) {
64              long userIdMapperId = counterLocalService.increment();
65  
66              userIdMapper = userIdMapperPersistence.create(userIdMapperId);
67          }
68  
69          userIdMapper.setUserId(userId);
70          userIdMapper.setType(type);
71          userIdMapper.setDescription(description);
72          userIdMapper.setExternalUserId(externalUserId);
73  
74          userIdMapperPersistence.update(userIdMapper, false);
75  
76          return userIdMapper;
77      }
78  
79  }