001/*
002 * (C) Copyright 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 *     Antoine Taillefer <ataillefer@nuxeo.com>
018 */
019package org.nuxeo.drive.service;
020
021import java.io.Serializable;
022import java.util.List;
023import java.util.Map;
024import java.util.Set;
025
026import org.nuxeo.ecm.core.api.CoreSession;
027import org.nuxeo.ecm.core.api.IdRef;
028
029/**
030 * Allows to find document changes.
031 *
032 * @author Antoine Taillefer
033 */
034public interface FileSystemChangeFinder extends Serializable {
035
036    /**
037     * Handles the parameters contributed through the {@code changeFinder} contribution.
038     */
039    void handleParameters(Map<String, String> parameters);
040
041    /**
042     * Gets the changes in the repository against which the given session is bound for the given synchronization root
043     * paths, since the given last successful synchronization date and without exceeding the given limit. The change
044     * summaries are mapped back to the file system view: the file system items might not always have the same tree
045     * layout as the backing documents in the repositories but this is a back-end detail that the client does not have
046     * to deal with.
047     *
048     * @param session the session bound to a specific repository
049     * @param lastActiveRootRefs docrefs of the roots as reported by the last successful synchronization (can be empty
050     *            or null)
051     * @param activeRoots the currently active synchronization roots
052     * @param lastSuccessfulSyncDate the last successful synchronization date as measured on the server for this user
053     *            device.
054     * @param syncDate the current synchronization date (upper bound on the date of the changes to return). This date is
055     *            typically obtained by calling {@link #getCurrentDate()}
056     * @param limit the maximum number of changes to fetch
057     * @return the list of document changes
058     * @throws TooManyChangesException if the number of changes found has exceeded the limit
059     */
060    List<FileSystemItemChange> getFileSystemChanges(CoreSession session, Set<IdRef> lastActiveRootRefs,
061            SynchronizationRoots activeRoots, long lastSuccessfulSyncDate, long syncDate, int limit)
062            throws TooManyChangesException;
063
064    /**
065     * Gets the changes in the repository against which the given session is bound for the given synchronization root
066     * paths, between the given lower and upper integer bounds and without exceeding the given limit. The change
067     * summaries are mapped back to the file system view: the file system items might not always have the same tree
068     * layout as the backing documents in the repositories but this is a back-end detail that the client does not have
069     * to deal with.
070     *
071     * @param session the session bound to a specific repository
072     * @param lastActiveRootRefs docrefs of the roots as reported by the last successful synchronization (can be empty
073     *            or null)
074     * @param activeRoots the currently active synchronization roots
075     * @param collectionSyncRootMemberIds the collection sync root member ids
076     * @param lowerBound the lower integer bound of the range clause in the change query
077     * @param upperBound the upper integer bound of the range clause in the change query. This id is typically obtained
078     *            by calling {@link #getUpperBound())}
079     * @param limit the maximum number of changes to fetch
080     * @return the list of document changes
081     * @throws TooManyChangesException if the number of changes found has exceeded the limit
082     */
083    List<FileSystemItemChange> getFileSystemChangesIntegerBounds(CoreSession session, Set<IdRef> lastActiveRootRefs,
084            SynchronizationRoots activeRoots, Set<String> collectionSyncRootMemberIds, long lowerBound,
085            long upperBound, int limit) throws TooManyChangesException;
086
087    /**
088     * Read the current time code to query for changes. The time is truncated to 0 milliseconds to have a consistent
089     * behavior across databases. Call to this method should be monotonic (or very nearly monotonic).
090     */
091    long getCurrentDate();
092
093    /**
094     * Return the upper bound of the range clause in the change query.
095     */
096    long getUpperBound();
097
098    /**
099     * Returns the upper bound of the range clause in the change query taking into account the clustering delay if
100     * clustering is enabled for at least one of the given repositories.
101     *
102     * @since 8.2
103     */
104    long getUpperBound(Set<String> repositoryNames);
105
106}