001    /**
002     * Copyright (c) 2000-2010 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.enterpriseadmin.search;
016    
017    import com.liferay.portal.kernel.dao.search.RowChecker;
018    import com.liferay.portal.model.Role;
019    import com.liferay.portal.service.PermissionLocalServiceUtil;
020    import com.liferay.portal.service.ResourcePermissionLocalServiceUtil;
021    import com.liferay.portal.util.PropsValues;
022    
023    import javax.portlet.RenderResponse;
024    
025    /**
026     * @author Jorge Ferrer
027     */
028    public class ResourceActionRowChecker extends RowChecker {
029    
030            public ResourceActionRowChecker(RenderResponse renderResponse) {
031                    super(renderResponse);
032            }
033    
034            public boolean isChecked(Object obj) {
035                    try {
036                            return doIsChecked(obj);
037                    }
038                    catch (Exception e) {
039                            return false;
040                    }
041            }
042    
043            protected boolean doIsChecked(Object obj) throws Exception {
044                    Object[] objArray = (Object[])obj;
045    
046                    Role role = (Role)objArray[0];
047                    String actionId = (String)objArray[1];
048                    String resourceName = (String)objArray[2];
049                    Integer scope = (Integer)objArray[4];
050    
051                    if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 6) {
052                            return
053                                    ResourcePermissionLocalServiceUtil.hasScopeResourcePermission(
054                                            role.getCompanyId(), resourceName, scope, role.getRoleId(),
055                                            actionId);
056                    }
057                    else {
058                            return PermissionLocalServiceUtil.hasRolePermission(
059                                    role.getRoleId(), role.getCompanyId(), resourceName, scope,
060                                    actionId);
061                    }
062            }
063    
064    }