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.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.ResourceConstants;
22  import com.liferay.portal.model.Role;
23  import com.liferay.portal.service.PermissionLocalServiceUtil;
24  
25  import javax.portlet.RenderResponse;
26  
27  /**
28   * <a href="GroupPermissionChecker.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Brian Wing Shun Chan
31   */
32  public class GroupPermissionChecker extends RowChecker {
33  
34      public GroupPermissionChecker(
35          RenderResponse renderResponse, Role role, String resourceName,
36          String actionId) {
37  
38          super(renderResponse);
39  
40          _role = role;
41          _resourceName = resourceName;
42          _actionId = actionId;
43      }
44  
45      public boolean isChecked(Object obj) {
46          Group group = (Group)obj;
47  
48          try {
49              return PermissionLocalServiceUtil.hasRolePermission(
50                  _role.getRoleId(), group.getCompanyId(), _resourceName,
51                  ResourceConstants.SCOPE_GROUP,
52                  String.valueOf(group.getGroupId()), _actionId);
53          }
54          catch (Exception e) {
55              _log.error(e);
56  
57              return false;
58          }
59      }
60  
61      private static Log _log = LogFactoryUtil.getLog(
62          GroupPermissionChecker.class);
63  
64      private Role _role;
65      private String _resourceName;
66      private String _actionId;
67  
68  }