001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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    }