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 *     <a href="mailto:tdelprat@nuxeo.com">Tiry</a>
018 */
019
020package org.nuxeo.ecm.quota.size;
021
022import java.io.IOException;
023import org.nuxeo.ecm.core.api.DocumentModel;
024
025/**
026 * Interface to manage DocumentModel that supports Quotas
027 *
028 * @author <a href="mailto:tdelprat@nuxeo.com">Tiry</a>
029 * @since 5.6
030 */
031public interface QuotaAware {
032
033    public static final String QUOTA_TOTALSIZE_CACHE_NAME = "quota-totalsize-cache";
034
035    long getInnerSize();
036
037    long getTotalSize();
038
039    long getTrashSize();
040
041    long getVersionsSize();
042
043    long getMaxQuota();
044
045    void setInnerSize(long size, boolean save);
046
047    void addInnerSize(long additionalSize, boolean save);
048
049    void addTotalSize(long additionalSize, boolean save);
050
051    void addTrashSize(long additionalSize, boolean save);
052
053    void addVersionsSize(long additionalSize, boolean save);
054
055    void save();
056
057    /**
058     * @since 5.7 allows to save the document without notifying DublincoreListener and the notification service
059     */
060    void save(boolean disableNotifications);
061
062    DocumentModel getDoc();
063
064    void setMaxQuota(long maxSize, boolean save);
065
066    void setMaxQuota(long maxSize, boolean save, boolean skipValidation);
067
068    QuotaInfo getQuotaInfo();
069
070    void resetInfos(boolean save);
071
072    /**
073     * Invalidates "total size" key-value in cache if exists.
074     * 
075     * @throws IOException when unable to invalidate key-value
076     * @since 6.0-HF16, 7.4
077     */
078    void invalidateTotalSizeCache() throws IOException;
079    
080    /**
081     * Returns value of "total size" cache of document OR <code>null</code> if cache does not exist or key does not exist in cache.
082     * 
083     * @return <code>Long</code> object or <code>null</code>
084     * @since 6.0-HF16, 7.4
085     */
086    Long getTotalSizeCache() throws IOException;
087    
088    /**
089     * Stores "total size" value in cache if it exists.
090     * 
091     * @param size
092     * @throws IOException if unable to store value
093     * @since 6.0-HF16, 7.4
094     */
095    void putTotalSizeCache(long size) throws IOException;
096    
097    /**
098     * @return <code>true</code> if "total size" cache exists otherwise <code>false</code>.
099     * 
100     * @since 6.0-HF16, 7.4
101     */
102    boolean totalSizeCacheExists();
103}