1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portal.service.impl;
21  
22  import com.liferay.portal.PortalException;
23  import com.liferay.portal.SystemException;
24  import com.liferay.portal.model.UserIdMapper;
25  import com.liferay.portal.service.base.UserIdMapperLocalServiceBaseImpl;
26  
27  import java.util.List;
28  
29  /**
30   * <a href="UserIdMapperLocalServiceImpl.java.html"><b><i>View Source</i></b>
31   * </a>
32   *
33   * @author Brian Wing Shun Chan
34   *
35   */
36  public class UserIdMapperLocalServiceImpl
37      extends UserIdMapperLocalServiceBaseImpl {
38  
39      public void deleteUserIdMappers(long userId) throws SystemException {
40          userIdMapperPersistence.removeByUserId(userId);
41      }
42  
43      public UserIdMapper getUserIdMapper(long userId, String type)
44          throws PortalException, SystemException {
45  
46          return userIdMapperPersistence.findByU_T(userId, type);
47      }
48  
49      public UserIdMapper getUserIdMapperByExternalUserId(
50              String type, String externalUserId)
51          throws PortalException, SystemException {
52  
53          return userIdMapperPersistence.findByT_E(type, externalUserId);
54      }
55  
56      public List<UserIdMapper> getUserIdMappers(long userId)
57          throws SystemException {
58  
59          return userIdMapperPersistence.findByUserId(userId);
60      }
61  
62      public UserIdMapper updateUserIdMapper(
63              long userId, String type, String description, String externalUserId)
64          throws SystemException {
65  
66          UserIdMapper userIdMapper = userIdMapperPersistence.fetchByU_T(
67              userId, type);
68  
69          if (userIdMapper == null) {
70              long userIdMapperId = counterLocalService.increment();
71  
72              userIdMapper = userIdMapperPersistence.create(userIdMapperId);
73          }
74  
75          userIdMapper.setUserId(userId);
76          userIdMapper.setType(type);
77          userIdMapper.setDescription(description);
78          userIdMapper.setExternalUserId(externalUserId);
79  
80          userIdMapperPersistence.update(userIdMapper, false);
81  
82          return userIdMapper;
83      }
84  
85  }