001/*
002 * (C) Copyright 2006-2012 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Thomas Roger <troger@nuxeo.com>
018 */
019
020package org.nuxeo.ecm.quota;
021
022import java.util.List;
023
024import org.nuxeo.ecm.core.api.CoreSession;
025import org.nuxeo.ecm.core.api.DocumentModel;
026import org.nuxeo.ecm.core.event.Event;
027import org.nuxeo.ecm.core.event.impl.DocumentEventContext;
028
029/**
030 * Service used to compute quota and statistics on documents.
031 *
032 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a>
033 * @since 5.5
034 */
035public interface QuotaStatsService {
036
037    List<QuotaStatsUpdater> getQuotaStatsUpdaters();
038
039    /**
040     * Update the statistics for the given {@code docCtx} and {@code event}.
041     * <p>
042     * Call all the registered {@link org.nuxeo.ecm.quota.QuotaStatsUpdater}s.
043     */
044    void updateStatistics(DocumentEventContext docCtx, Event event);
045
046    /**
047     * Compute the initial statistics for the given @{code updaterName}.
048     *
049     * @deprecated since 10.1, use other signature
050     */
051    @Deprecated
052    default void computeInitialStatistics(String updaterName, CoreSession session, QuotaStatsInitialWork currentWorker) {
053        computeInitialStatistics(updaterName, session, currentWorker, null);
054    }
055
056    /**
057     * Compute the initial statistics for the given @{code updaterName} for {@code docPath}.
058     *
059     * @since 10.1
060     */
061    void computeInitialStatistics(String updaterName, CoreSession session, QuotaStatsInitialWork currentWorker, String path);
062
063    /**
064     * Launch an asynchronously initial computation for the given {@code updaterName} on {@code repositoryName}.
065     *
066     * @deprecated since 10.1, use other signature
067     */
068    @Deprecated
069    default void launchInitialStatisticsComputation(String updaterName, String repositoryName) {
070        launchInitialStatisticsComputation(updaterName, repositoryName, null);
071    }
072
073    /**
074     * Launch an asynchronously initial computation for the given {@code updaterName} on {@code repositoryName}
075     * for {@code docPath}.
076     *
077     * @since 10.1
078     */
079    void launchInitialStatisticsComputation(String updaterName, String repositoryName, String path);
080
081    /**
082     * Returns the progress status of {@code updaterName}.
083     */
084    String getProgressStatus(String updaterName, String repositoryName);
085
086    /**
087     * Gets the quota from the first parent where quota has been set. Returns -1 if no quota has been set. For user
088     * workspaces, only the first parent is investigated
089     *
090     * @since 5.7
091     */
092    long getQuotaFromParent(DocumentModel doc, CoreSession session);
093
094    /**
095     * Test to see if quota allowed. Skip user worskpaces, where validation rules don't apply.
096     *
097     * @since 5.7
098     */
099    boolean canSetMaxQuota(long maxQuota, DocumentModel doc, CoreSession session);
100
101    /**
102     * Sets this maxQuota on all user workspaces
103     *
104     * @since 5.7
105     */
106    void launchSetMaxQuotaOnUserWorkspaces(long maxQuota, DocumentModel context, CoreSession session);
107
108    /**
109     * Activates the quota on user personal workspaces
110     *
111     * @since 5.7
112     */
113    void activateQuotaOnUserWorkspaces(long maxQuota, CoreSession session);
114
115    /**
116     * @since 5.7
117     */
118    long getQuotaSetOnUserWorkspaces(CoreSession session);
119
120}