001/*
002 * (C) Copyright 2012 Nuxeo SA (http://nuxeo.com/) and contributors.
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.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 *     Antoine Taillefer <ataillefer@nuxeo.com>
016 */
017package org.nuxeo.drive.service;
018
019import java.security.Principal;
020import java.util.List;
021
022import org.nuxeo.drive.adapter.FileItem;
023import org.nuxeo.drive.adapter.FileSystemItem;
024import org.nuxeo.drive.adapter.FolderItem;
025import org.nuxeo.drive.service.impl.FileSystemItemManagerImpl;
026import org.nuxeo.ecm.core.api.Blob;
027import org.nuxeo.ecm.core.api.CoreInstance;
028import org.nuxeo.ecm.core.api.CoreSession;
029
030/**
031 * Provides an API to manage usual file system operations on a {@link FileSystemItem} given its id. Allows the following
032 * actions:
033 * <ul>
034 * <li>Read</li>
035 * <li>Read children</li>
036 * <li>Create</li>
037 * <li>Update</li>
038 * <li>Delete</li>
039 * <li>Rename</li>
040 * <li>Move</li>
041 * </ul>
042 *
043 * @author Antoine Taillefer
044 * @see FileSystemItemManagerImpl
045 */
046public interface FileSystemItemManager {
047
048    /**
049     * Gets a session bound to the given repository for the given principal.
050     *
051     * @deprecated since 7.2, use {@link CoreInstance#openCoreSession(String, Principal)} instead.
052     */
053    @Deprecated
054    CoreSession getSession(String repositoryName, Principal principal);
055
056    /*------------- Read operations ----------------*/
057    /**
058     * Gets the children of the top level {@link FolderItem} for the given principal.
059     *
060     * @deprecated use getTopLevelFolder#getChildren instead
061     */
062    @Deprecated
063    List<FileSystemItem> getTopLevelChildren(Principal principal);
064
065    /**
066     * Gets the top level {@link FolderItem} for the given principal.
067     */
068    FolderItem getTopLevelFolder(Principal principal);
069
070    /**
071     * Returns true if a {@link FileSystemItem} with the given id exists for the given principal.
072     *
073     * @see FileSystemItemFactory#exists(String, Principal)
074     */
075    boolean exists(String id, Principal principal);
076
077    /**
078     * Gets the {@link FileSystemItem} with the given id for the given principal.
079     *
080     * @return the {@link FileSystemItem} or null if none matches the given id
081     * @see FileSystemItemFactory#getFileSystemItemById(String, Principal)
082     */
083    FileSystemItem getFileSystemItemById(String id, Principal principal);
084
085    /**
086     * Gets the {@link FileSystemItem} with the given id and parent id for the given principal.
087     *
088     * @return the {@link FileSystemItem} or null if none matches the given id and parent id
089     * @see #getFileSystemItemById(String, Principal)
090     * @since 6.0
091     */
092    FileSystemItem getFileSystemItemById(String id, String parentId, Principal principal);
093
094    /**
095     * Gets the children of the {@link FileSystemItem} with the given id for the given principal.
096     *
097     * @see FolderItem#getChildren()
098     */
099    List<FileSystemItem> getChildren(String id, Principal principal);
100
101    /**
102     * Return true if the {@link FileSystemItem} with the given source id can be moved to the {@link FileSystemItem}
103     * with the given destination id for the given principal.
104     *
105     * @see FileSystemItem#getCanMove(String)
106     */
107    boolean canMove(String srcId, String destId, Principal principal);
108
109    /*------------- Write operations ----------------*/
110    /**
111     * Creates a folder with the given name in the {@link FileSystemItem} with the given id for the given principal.
112     *
113     * @see FolderItem#createFolder(String)
114     */
115    FolderItem createFolder(String parentId, String name, Principal principal);
116
117    /**
118     * Creates a file with the given blob in the {@link FileSystemItem} with the given id for the given principal.
119     *
120     * @see FolderItem#createFile(Blob)
121     */
122    FileItem createFile(String parentId, Blob blob, Principal principal);
123
124    /**
125     * Updates the {@link FileSystemItem} with the given id with the given blob for the given principal.
126     *
127     * @see FileItem#setBlob(Blob)
128     */
129    FileItem updateFile(String id, Blob blob, Principal principal);
130
131    /**
132     * Updates the {@link FileSystemItem} with the given id and parent id with the given blob for the given principal.
133     *
134     * @see #updateFile(String, Blob, Principal)
135     * @since 6.0
136     */
137    FileItem updateFile(String id, String parentId, Blob blob, Principal principal);
138
139    /**
140     * Deletes the {@link FileSystemItem} with the given id for the given principal.
141     *
142     * @see FileSystemItem#delete()
143     */
144    void delete(String id, Principal principal);
145
146    /**
147     * Deletes the {@link FileSystemItem} with the given id and parent id for the given principal.
148     *
149     * @see #delete(String, Principal)
150     * @since 6.0
151     */
152    void delete(String id, String parentId, Principal principal);
153
154    /**
155     * Renames the {@link FileSystemItem} with the given id with the given name for the given principal.
156     *
157     * @see FileSystemItem#rename(String)
158     */
159    FileSystemItem rename(String id, String name, Principal principal);
160
161    /**
162     * Moves the {@link FileSystemItem} with the given source id to the {@link FileSystemItem} with the given
163     * destination id for the given principal.
164     *
165     * @see FileSystemItem#move(String)
166     */
167    FileSystemItem move(String srcId, String destId, Principal principal);
168
169}