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.portlet.communities.search;
16  
17  import com.liferay.portal.kernel.dao.search.RowChecker;
18  import com.liferay.portal.kernel.log.Log;
19  import com.liferay.portal.kernel.log.LogFactoryUtil;
20  import com.liferay.portal.model.Group;
21  import com.liferay.portal.model.Role;
22  import com.liferay.portal.model.User;
23  import com.liferay.portal.service.UserGroupRoleLocalServiceUtil;
24  
25  import javax.portlet.RenderResponse;
26  
27  /**
28   * <a href="UserGroupRoleUserChecker.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Jorge Ferrer
31   */
32  public class UserGroupRoleUserChecker extends RowChecker {
33  
34      public UserGroupRoleUserChecker(
35          RenderResponse renderResponse, Group group, Role role) {
36  
37          super(renderResponse);
38  
39          _group = group;
40          _role = role;
41      }
42  
43      public boolean isChecked(Object obj) {
44          User user = (User)obj;
45  
46          try {
47              return UserGroupRoleLocalServiceUtil.hasUserGroupRole(
48                  user.getUserId(), _group.getGroupId(), _role.getRoleId());
49          }
50          catch (Exception e) {
51              _log.error(e);
52  
53              return false;
54          }
55      }
56  
57      private static Log _log = LogFactoryUtil.getLog(
58          UserGroupRoleUserChecker.class);
59  
60      private Role _role;
61      private Group _group;
62  
63  }