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.util.Set;
022import java.util.concurrent.Semaphore;
023
024import org.nuxeo.drive.adapter.FileSystemItem;
025import org.nuxeo.drive.adapter.FolderItem;
026import org.nuxeo.drive.service.impl.FileSystemItemAdapterServiceImpl;
027import org.nuxeo.ecm.core.api.DocumentModel;
028import org.nuxeo.ecm.core.api.Lock;
029
030/**
031 * Service for creating the right {@link FileSystemItem} adapter depending on the {@link DocumentModel} type or facet.
032 * <p>
033 * Factories can be contributed to implement a specific behavior for the {@link FileSystemItem} adapter creation.
034 *
035 * @author Antoine Taillefer
036 * @see FileSystemItemAdapterServiceImpl
037 */
038public interface FileSystemItemAdapterService {
039
040    /**
041     * Gets the {@link FileSystemItem} for the given {@link DocumentModel}. If the document is in the trash it is not
042     * considered as adaptable as a {@link FileSystemItem}, thus the method returns null.
043     *
044     * @return the {@link FileSystemItem} or null if the {@link DocumentModel} is not adaptable as a
045     *         {@link FileSystemItem}
046     * @see FileSystemItemFactory#getFileSystemItem(DocumentModel)
047     */
048    FileSystemItem getFileSystemItem(DocumentModel doc);
049
050    /**
051     * Gets the {@link FileSystemItem} for the given {@link DocumentModel}. If {@code includeDeleted} is true no filter
052     * is applied on the "trashed" state, else if the document is in the trash it is not considered as adaptable as a
053     * {@link FileSystemItem}, thus the method returns null.
054     *
055     * @return the {@link FileSystemItem} or null if the {@link DocumentModel} is not adaptable as a
056     *         {@link FileSystemItem}
057     * @see FileSystemItemFactory#getFileSystemItem(DocumentModel, boolean)
058     */
059    FileSystemItem getFileSystemItem(DocumentModel doc, boolean includeDeleted);
060
061    /**
062     * Gets the {@link FileSystemItem} for the given {@link DocumentModel}.
063     * <p>
064     * If {@code includeDeleted} is true no filter is applied on the "trashed" state, else if the document is in the
065     * trash it is not considered as adaptable as a {@link FileSystemItem}, thus the method returns null.
066     * <p>
067     * If {@code relaxSyncRootConstraint} is true no filter is applied on the synchronization root aspect for the
068     * current user.
069     *
070     * @return the {@link FileSystemItem} or null if the {@link DocumentModel} is not adaptable as a
071     *         {@link FileSystemItem}
072     * @see FileSystemItemFactory#getFileSystemItem(DocumentModel, boolean, boolean)
073     */
074    FileSystemItem getFileSystemItem(DocumentModel doc, boolean includeDeleted, boolean relaxSyncRootConstraint);
075
076    /**
077     * Gets the {@link FileSystemItem} for the given {@link DocumentModel}.
078     * <p>
079     * If {@code includeDeleted} is true no filter is applied on the "trashed" state, else if the document is in the
080     * trash it is not considered as adaptable as a {@link FileSystemItem}, thus the method returns null.
081     * <p>
082     * If {@code relaxSyncRootConstraint} is true no filter is applied on the synchronization root aspect for the
083     * current user.
084     * <p>
085     * If {@code getLockInfo} is true the {@link Lock} is fetched from the {@link DocumentModel} and set on the returned
086     * {@link FileSystemItem}.
087     *
088     * @since 8.3
089     * @return the {@link FileSystemItem} or null if the {@link DocumentModel} is not adaptable as a
090     *         {@link FileSystemItem}
091     * @see FileSystemItemFactory#getFileSystemItem(DocumentModel, boolean, boolean, boolean)
092     */
093    FileSystemItem getFileSystemItem(DocumentModel doc, boolean includeDeleted, boolean relaxSyncRootConstraint,
094            boolean getLockInfo);
095
096    /**
097     * Gets the {@link FileSystemItem} for the given {@link DocumentModel} forcing its parent with the given
098     * {@code parentItem}. If the document is in the trash it is not considered as adaptable as a
099     * {@link FileSystemItem}, thus the method returns null.
100     *
101     * @return the {@link FileSystemItem} or null if the {@link DocumentModel} is not adaptable as a
102     *         {@link FileSystemItem}
103     * @see FileSystemItemFactory#getFileSystemItem(DocumentModel, FolderItem)
104     */
105    FileSystemItem getFileSystemItem(DocumentModel doc, FolderItem parentItem);
106
107    /**
108     * Gets the {@link FileSystemItem} for the given {@link DocumentModel} forcing its parent with the given
109     * {@code parentItem}. If {@code includeDeleted} is true no filter is applied on the "trashed" state, else if the
110     * document is in the trash it is not considered as adaptable as a {@link FileSystemItem}, thus the method returns
111     * null.
112     *
113     * @return the {@link FileSystemItem} or null if the {@link DocumentModel} is not adaptable as a
114     *         {@link FileSystemItem}
115     * @see FileSystemItemFactory#getFileSystemItem(DocumentModel, FolderItem, boolean)
116     */
117    FileSystemItem getFileSystemItem(DocumentModel doc, FolderItem parentItem, boolean includeDeleted);
118
119    /**
120     * Gets the {@link FileSystemItem} for the given {@link DocumentModel} forcing its parent with the given
121     * {@code parentItem}.
122     * <p>
123     * If {@code includeDeleted} is true no filter is applied on the "trashed" state, else if the document is in the
124     * trash it is not considered as adaptable as a {@link FileSystemItem}, thus the method returns null.
125     * <p>
126     * If {@code relaxSyncRootConstraint} is true no filter is applied on the synchronization root aspect for the
127     * current user.
128     *
129     * @return the {@link FileSystemItem} or null if the {@link DocumentModel} is not adaptable as a
130     *         {@link FileSystemItem}
131     * @see FileSystemItemFactory#getFileSystemItem(DocumentModel, FolderItem, boolean, boolean)
132     */
133    FileSystemItem getFileSystemItem(DocumentModel doc, FolderItem parentItem, boolean includeDeleted,
134            boolean relaxSyncRootConstraint);
135
136    /**
137     * Gets the {@link FileSystemItem} for the given {@link DocumentModel} forcing its parent with the given
138     * {@code parentItem}.
139     * <p>
140     * If {@code includeDeleted} is true no filter is applied on the "trashed" state, else if the document is in the
141     * trash it is not considered as adaptable as a {@link FileSystemItem}, thus the method returns null.
142     * <p>
143     * If {@code relaxSyncRootConstraint} is true no filter is applied on the synchronization root aspect for the
144     * current user.
145     * <p>
146     * If {@code getLockInfo} is true the {@link Lock} is fetched from the {@link DocumentModel} and set on the returned
147     * {@link FileSystemItem}.
148     *
149     * @since 8.3
150     * @return the {@link FileSystemItem} or null if the {@link DocumentModel} is not adaptable as a
151     *         {@link FileSystemItem}
152     * @see FileSystemItemFactory#getFileSystemItem(DocumentModel, FolderItem, boolean, boolean, boolean)
153     */
154    FileSystemItem getFileSystemItem(DocumentModel doc, FolderItem parentItem, boolean includeDeleted,
155            boolean relaxSyncRootConstraint, boolean getLockInfo);
156
157    /**
158     * Gets the {@link FileSystemItemFactory} that can handle the the given {@link FileSystemItem} id.
159     *
160     * @see FileSystemItemFactory#canHandleFileSystemItemId(String)
161     */
162    FileSystemItemFactory getFileSystemItemFactoryForId(String id);
163
164    /**
165     * Gets the {@link TopLevelFolderItemFactory}.
166     */
167    TopLevelFolderItemFactory getTopLevelFolderItemFactory();
168
169    /**
170     * Gets the {@link VirtualFolderItemFactory} for the given factory name.
171     */
172    VirtualFolderItemFactory getVirtualFolderItemFactory(String factoryName);
173
174    /**
175     * Gets the active {@link FileSystemItem} factory names.
176     */
177    Set<String> getActiveFileSystemItemFactories();
178
179    /**
180     * Allows to limit the number of concurrent scrolls run by {@link FolderItem#scrollDescendants(String, int, long)}.
181     *
182     * @since 8.3
183     */
184    Semaphore getScrollBatchSemaphore();
185
186}