001/*
002 * (C) Copyright 2006-2017 Nuxeo (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 *     Nuxeo - initial API and implementation
018 *
019 * $Id: JOOoConvertPluginImpl.java 18651 2007-05-13 20:28:53Z sfermigier $
020 */
021
022package org.nuxeo.ecm.platform.filemanager.api;
023
024import java.io.IOException;
025import java.security.Principal;
026import java.util.List;
027
028import org.nuxeo.ecm.core.api.Blob;
029import org.nuxeo.ecm.core.api.CoreSession;
030import org.nuxeo.ecm.core.api.DocumentLocation;
031import org.nuxeo.ecm.core.api.DocumentModel;
032import org.nuxeo.ecm.core.api.DocumentModelList;
033import org.nuxeo.ecm.core.api.VersioningOption;
034
035/**
036 * File Manager.
037 * <p>
038 * File Manager to handle file
039 *
040 * @author Andreas Kalogeropoulos
041 */
042public interface FileManager {
043
044    /**
045     * Returns an initialized doc based on a given blob.
046     *
047     * @param input the blob containing the content and the mime type
048     * @param path the path were to create the document
049     * @param overwrite whether to overwrite an existing file with the same title or not
050     * @param fullName the fullname that contains the filename
051     * @return the created Document
052     */
053    DocumentModel createDocumentFromBlob(CoreSession documentManager, Blob input, String path, boolean overwrite,
054            String fullName) throws IOException;
055
056    /**
057     * Returns an initialized doc based on a given blob.
058     *
059     * @param input the blob containing the content and the mime type
060     * @param path the path were to create the document
061     * @param overwrite whether to overwrite an existing file with the same title or not
062     * @param fullName the fullname that contains the filename
063     * @param noMimeTypeCheck true if the blob's mime-type doesn't have to be checked against fullName
064     * @return the created Document
065     * @since 8.10
066     */
067    DocumentModel createDocumentFromBlob(CoreSession documentManager, Blob input, String path, boolean overwrite,
068            String fullName, boolean noMimeTypeCheck) throws IOException;
069
070    /**
071     * Just applies the same actions as creation but does not changes the doc type.
072     *
073     * @param input the blob containing the content and the mime type
074     * @param path the path to the file to update
075     * @param fullName the full name that contains the filename
076     * @return the updated Document
077     */
078    DocumentModel updateDocumentFromBlob(CoreSession documentManager, Blob input, String path, String fullName);
079
080    /**
081     * Creates a Folder.
082     *
083     * @param fullname the full name of the folder
084     * @param path the path were to create the folder
085     * @return the Folder Created
086     * @deprecated since 9.1, use {@link #createFolder(CoreSession, String, String, boolean)} instead
087     */
088    @Deprecated
089    default DocumentModel createFolder(CoreSession documentManager, String fullname, String path) throws IOException {
090        return createFolder(documentManager, fullname, path, true);
091    }
092
093    /**
094     * Creates a Folder.
095     *
096     * @param fullname the full name of the folder
097     * @param path the path were to create the folder
098     * @param overwrite whether to overwrite an existing folder with the same title or not
099     * @return the Folder Created
100     * @since 9.1
101     */
102    DocumentModel createFolder(CoreSession documentManager, String fullname, String path, boolean overwrite)
103            throws IOException;
104
105    /**
106     * Returns the list of document that are to be suggested to principalName as a candidate container for a new
107     * document of type docType on all registered repositories.
108     *
109     * @return the list of candidate containers
110     */
111    DocumentModelList getCreationContainers(Principal principal, String docType);
112
113    /**
114     * Returns the list of document that are to be suggested to the principal of documentManager as a candidate
115     * container for a new document of type docType.
116     *
117     * @return the list of candidate containers
118     */
119    DocumentModelList getCreationContainers(CoreSession documentManager, String docType);
120
121    List<DocumentLocation> findExistingDocumentWithFile(CoreSession documentManager, String path, String digest,
122            Principal principal);
123
124    boolean isUnicityEnabled();
125
126    List<String> getFields();
127
128    String getDigestAlgorithm();
129
130    boolean isDigestComputingEnabled();
131
132    /**
133     * Gets the versioning applied on an overwritten document before it is overwritten.
134     *
135     * @since 5.7
136     * @deprecated since 9.1 automatic versioning is now handled at versioning service level, remove versioning
137     * behaviors from importers
138     */
139    @Deprecated
140    VersioningOption getVersioningOption();
141
142    /**
143     * Checks whether versioning should also be applied after a document is added.
144     *
145     * @since 5.7
146     * @deprecated since 9.1 automatic versioning is now handled at versioning service level, remove versioning
147     * behaviors from importers
148     */
149    @Deprecated
150    boolean doVersioningAfterAdd();
151
152}