001    /**
002     * Copyright (c) 2000-2011 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.portal.workflow;
016    
017    import com.liferay.portal.kernel.workflow.WorkflowTaskManagerUtil;
018    import com.liferay.portal.model.Portlet;
019    import com.liferay.portal.security.permission.PermissionChecker;
020    
021    /**
022     * @author Miguel Pastor
023     */
024    public class MyWorkflowTasksControlPanelEntry
025            extends WorkflowControlPanelEntry {
026    
027            @Override
028            public boolean isVisible(
029                            PermissionChecker permissionChecker, Portlet portlet)
030                    throws Exception {
031    
032                    long companyId = permissionChecker.getCompanyId();
033                    long userId = permissionChecker.getUserId();
034    
035                    if (WorkflowTaskManagerUtil.getWorkflowTaskCountByUser(
036                                    companyId, userId, Boolean.FALSE) > 0) {
037    
038                            return true;
039                    }
040    
041                    if (WorkflowTaskManagerUtil.getWorkflowTaskCountByUser(
042                                    companyId, userId, Boolean.TRUE) > 0) {
043    
044                            return true;
045                    }
046    
047                    if (WorkflowTaskManagerUtil.getWorkflowTaskCountByUserRoles(
048                                    companyId, userId, Boolean.FALSE) > 0) {
049    
050                            return true;
051                    }
052    
053                    if (WorkflowTaskManagerUtil.getWorkflowTaskCountByUserRoles(
054                                    companyId, userId, Boolean.TRUE) > 0) {
055    
056                            return true;
057                    }
058    
059                    return false;
060            }
061    
062    }