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