001/*
002 * (C) Copyright 2006-2012 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl-2.1.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Thomas Roger <troger@nuxeo.com>
016 */
017
018package org.nuxeo.ecm.quota;
019
020import java.util.List;
021
022import org.nuxeo.ecm.core.api.CoreSession;
023import org.nuxeo.ecm.core.api.DocumentModel;
024import org.nuxeo.ecm.core.event.Event;
025import org.nuxeo.ecm.core.event.impl.DocumentEventContext;
026
027/**
028 * Service used to compute quota and statistics on documents.
029 *
030 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a>
031 * @since 5.5
032 */
033public interface QuotaStatsService {
034
035    List<QuotaStatsUpdater> getQuotaStatsUpdaters();
036
037    /**
038     * Update the statistics for the given {@code docCtx} and {@code event}.
039     * <p>
040     * Call all the registered {@link org.nuxeo.ecm.quota.QuotaStatsUpdater}s.
041     */
042    void updateStatistics(DocumentEventContext docCtx, Event event);
043
044    /**
045     * Compute the initial statistics for the given @{code updaterName}.
046     */
047    void computeInitialStatistics(String updaterName, CoreSession session, QuotaStatsInitialWork currentWorker);
048
049    /**
050     * Launch an asynchronously initial computation for the given {@code updaterName} on {@code repositoryName}.
051     */
052    void launchInitialStatisticsComputation(String updaterName, String repositoryName);
053
054    /**
055     * Returns the progress status of {@code updaterName}.
056     */
057    String getProgressStatus(String updaterName, String repositoryName);
058
059    /**
060     * Gets the quota from the first parent where quota has been set. Returns -1 if no quota has been set. For user
061     * workspaces, only the first parent is investigated
062     *
063     * @since 5.7
064     */
065    public long getQuotaFromParent(DocumentModel doc, CoreSession session);
066
067    /**
068     * Test to see if quota allowed. Skip user worskpaces, where validation rules don't apply.
069     *
070     * @since 5.7
071     */
072    public boolean canSetMaxQuota(long maxQuota, DocumentModel doc, CoreSession session);
073
074    /**
075     * Sets this maxQuota on all user workspaces
076     *
077     * @since 5.7
078     */
079    public void launchSetMaxQuotaOnUserWorkspaces(long maxQuota, DocumentModel context, CoreSession session);
080
081    /**
082     * Activates the quota on user personal workspaces
083     *
084     * @since 5.7
085     */
086    public void activateQuotaOnUserWorkspaces(long maxQuota, CoreSession session);
087
088    /**
089     * @since 5.7
090     */
091    public long getQuotaSetOnUserWorkspaces(CoreSession session);
092
093}