001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.rolesadmin.search;
016    
017    import com.liferay.portal.kernel.dao.search.RowChecker;
018    import com.liferay.portal.model.Role;
019    import com.liferay.portal.service.ResourceBlockLocalServiceUtil;
020    import com.liferay.portal.service.ResourcePermissionLocalServiceUtil;
021    import com.liferay.portal.service.ResourceTypePermissionLocalServiceUtil;
022    
023    import javax.portlet.PortletResponse;
024    
025    /**
026     * @author Jorge Ferrer
027     * @author Connor McKay
028     */
029    public class ResourceActionRowChecker extends RowChecker {
030    
031            public ResourceActionRowChecker(PortletResponse portletResponse) {
032                    super(portletResponse);
033            }
034    
035            @Override
036            public boolean isChecked(Object obj) {
037                    try {
038                            return doIsChecked(obj);
039                    }
040                    catch (Exception e) {
041                            return false;
042                    }
043            }
044    
045            protected boolean doIsChecked(Object obj) throws Exception {
046                    Object[] objArray = (Object[])obj;
047    
048                    Role role = (Role)objArray[0];
049                    String actionId = (String)objArray[1];
050                    String resourceName = (String)objArray[2];
051                    Integer scope = (Integer)objArray[4];
052    
053                    if (ResourceBlockLocalServiceUtil.isSupported(resourceName)) {
054                            return ResourceTypePermissionLocalServiceUtil.
055                                    hasEitherScopePermission(
056                                            role.getCompanyId(), resourceName, role.getRoleId(),
057                                            actionId);
058                    }
059    
060                    return
061                            ResourcePermissionLocalServiceUtil.hasScopeResourcePermission(
062                                    role.getCompanyId(), resourceName, scope, role.getRoleId(),
063                                    actionId);
064            }
065    
066    }