1   /**
2    * Copyright (c) 2000-2010 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   *
12   *
13   */
14  
15  package com.liferay.portlet.enterpriseadmin.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.User;
22  import com.liferay.portal.service.UserLocalServiceUtil;
23  
24  import javax.portlet.RenderResponse;
25  
26  /**
27   * <a href="UserGroupChecker.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Brian Wing Shun Chan
30   */
31  public class UserGroupChecker extends RowChecker {
32  
33      public UserGroupChecker(RenderResponse renderResponse, Group group) {
34          super(renderResponse);
35  
36          _group = group;
37      }
38  
39      public boolean isChecked(Object obj) {
40          User user = null;
41  
42          if (obj instanceof User) {
43              user = (User)obj;
44          }
45          else if (obj instanceof Object[]) {
46              user = (User)((Object[])obj)[0];
47          }
48          else {
49              throw new IllegalArgumentException(obj + " is not a User");
50          }
51  
52          try {
53              return UserLocalServiceUtil.hasGroupUser(
54                  _group.getGroupId(), user.getUserId());
55          }
56          catch (Exception e) {
57              _log.error(e);
58  
59              return false;
60          }
61      }
62  
63      private static Log _log = LogFactoryUtil.getLog(UserGroupChecker.class);
64  
65      private Group _group;
66  
67  }