001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.workflow;
029
030import org.opencms.ade.publish.shared.CmsWorkflow;
031import org.opencms.file.CmsResource;
032import org.opencms.main.OpenCms;
033
034import java.util.List;
035
036/**
037 * Set of workflow resources, and an optional workflow.<p>
038 */
039public class CmsWorkflowResources {
040
041    /** Override workflow. */
042    private CmsWorkflow m_overrideWorkflow;
043
044    /** The workflow resources. */
045    private List<CmsResource> m_workflowResources;
046
047    /** If set, there are too many resources, and the value contains the approximate amount of resources. */
048    private Integer m_tooManyCount;
049
050    /**
051     * Creates new instance.<p>
052     *
053     * @param workflowResources the workflow resources
054     * @param overrideWorkflow the workflow to override the selected workflow
055     * @param tooManyCount null if there are not too many resources, otherwise the approximate resource count
056     */
057    public CmsWorkflowResources(
058        List<CmsResource> workflowResources,
059        CmsWorkflow overrideWorkflow,
060        Integer tooManyCount) {
061
062        m_workflowResources = workflowResources;
063        m_overrideWorkflow = overrideWorkflow;
064        m_tooManyCount = tooManyCount;
065    }
066
067    /**
068     * Gets a number that can be used as a lower bound for the number of publish resources if the list is too big (bigger than the workflow manager's resource limit).
069     *
070     * @return a lower bound for the number of publish resources
071     */
072    public int getLowerBoundForSize() {
073
074        if (m_tooManyCount != null) {
075            return m_tooManyCount.intValue();
076        } else {
077            return m_workflowResources.size();
078        }
079    }
080
081    /**
082     * Gets the override workflow, or null.<p>
083     *
084     * @return the override workflow, or null
085     */
086    public CmsWorkflow getOverrideWorkflow() {
087
088        return m_overrideWorkflow;
089    }
090
091    /**
092     * Gets the approximate amount of resources if there are too many resources.<p>
093     *
094     * @return the approximate amount of resources if there are too many
095     */
096    public Integer getTooManyCount() {
097
098        return m_tooManyCount;
099    }
100
101    /**
102     * Returns the workflowResources.<p>
103     *
104     * Note that if the isTooMany() method returns true, this method may return an empty list.
105     *
106     * @return the workflowResources
107     */
108    public List<CmsResource> getWorkflowResources() {
109
110        return m_workflowResources;
111    }
112
113    /**
114     * Returns true if there are too many resources.<p>
115     *
116     * @return true if there are too many resources
117     */
118    public boolean isTooMany() {
119
120        return (m_tooManyCount != null)
121            || ((m_workflowResources != null)
122                && (m_workflowResources.size() > OpenCms.getWorkflowManager().getResourceLimit()));
123    }
124
125}