001/*
002 * Copyright (c) 2006-2014 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 *
009 * Contributors:
010 *     Bogdan Stefanescu
011 *     Florent Guillaume
012 */
013package org.nuxeo.ecm.core.model;
014
015import java.io.Serializable;
016import java.util.List;
017import java.util.Map;
018
019import org.nuxeo.ecm.core.api.CoreSession;
020import org.nuxeo.ecm.core.api.DocumentNotFoundException;
021import org.nuxeo.ecm.core.api.IterableQueryResult;
022import org.nuxeo.ecm.core.api.PartialList;
023import org.nuxeo.ecm.core.api.VersionModel;
024import org.nuxeo.ecm.core.api.security.ACP;
025import org.nuxeo.ecm.core.query.QueryFilter;
026
027/**
028 * Internal Session accessing the low-level storage.
029 */
030public interface Session {
031
032    // parameters for the session contexts
033    String USER_NAME = "username";
034
035    /**
036     * Gets the repository that created this session.
037     *
038     * @return the repository
039     */
040    String getRepositoryName();
041
042    /**
043     * Does a query.
044     *
045     * @since 5.9.4
046     */
047    PartialList<Document> query(String query, String queryType, QueryFilter queryFilter, long countUpTo);
048
049    /**
050     * Does a query and fetch the individual results as maps.
051     */
052    IterableQueryResult queryAndFetch(String query, String queryType, QueryFilter queryFilter, Object[] params);
053
054    /**
055     * Gets the lock manager for this session.
056     *
057     * @return the lock manager
058     * @since 7.4
059     */
060    LockManager getLockManager();
061
062    /**
063     * Saves this session.
064     */
065    void save();
066
067    /**
068     * Checks whether the session is alive.
069     *
070     * @return true if the session is closed, false otherwise
071     */
072    boolean isLive();
073
074    /**
075     * Returns {@code true} if all sessions in the current thread share the same state.
076     */
077    boolean isStateSharedByAllThreadSessions();
078
079    /**
080     * Closes this session. Does not save.
081     */
082    void close();
083
084    /**
085     * Gets the document at the given path, if any.
086     *
087     * @param path
088     * @return
089     * @throws DocumentNotFoundException if the document doesn't exist
090     */
091    Document resolvePath(String path) throws DocumentNotFoundException;
092
093    /**
094     * Gets a document given its ID.
095     *
096     * @param uuid the document id
097     * @return the document
098     * @throws DocumentNotFoundException if the document doesn't exist
099     */
100    Document getDocumentByUUID(String uuid) throws DocumentNotFoundException;
101
102    /**
103     * Gets the root document in this repository.
104     *
105     * @return the root document
106     */
107    Document getRootDocument();
108
109    /**
110     * Gets the null document, to be used as a fake parent to add placeless children.
111     *
112     * @return the null document
113     */
114    Document getNullDocument();
115
116    /**
117     * Copies the source document to the given folder.
118     * <p>
119     * If the destination document is not a folder, an exception is thrown.
120     *
121     * @param src
122     * @param dst
123     * @param name
124     */
125    Document copy(Document src, Document dst, String name);
126
127    /**
128     * Moves the source document to the given folder.
129     * <p>
130     * If the destination document is not a folder an exception is thrown.
131     *
132     * @param src the source document to move
133     * @param dst the destination folder
134     * @param name the new name of the document or null if the original name should be preserved
135     */
136    Document move(Document src, Document dst, String name);
137
138    /**
139     * Creates a generic proxy to the given document inside the given folder.
140     *
141     * @param doc the document
142     * @param folder the folder
143     * @return the proxy
144     */
145    Document createProxy(Document doc, Document folder);
146
147    /**
148     * Finds the proxies for a document. If the folder is not null, the search will be limited to its children.
149     * <p>
150     * If the document is a version, then only proxies to that version will be looked up.
151     *
152     * @param doc the document or version
153     * @param folder the folder, or null
154     * @return the list of proxies if any is found otherwise an empty list
155     * @since 1.4.1 for the case where doc is a proxy
156     */
157    List<Document> getProxies(Document doc, Document folder);
158
159    /**
160     * Sets a proxies' target.
161     * <p>
162     * The target must have the same version series as the proxy.
163     *
164     * @param proxy the proxy
165     * @param target the new target
166     * @since 5.5
167     */
168    void setProxyTarget(Document proxy, Document target);
169
170    /**
171     * Imports a document with a given id and parent.
172     * <p>
173     * The document can then be filled with the normal imported properties.
174     *
175     * @param uuid the document uuid
176     * @param parent the document parent, or {@code null} for a version
177     * @param name the document name in its parent
178     * @param typeName the document type, or {@code ecm:proxy} for a proxy
179     * @param properties system properties of the document, which will vary depending whether it's a live document, a
180     *            version or a proxy (see the various {@code IMPORT_*} constants of {@link CoreSession})
181     * @return a writable {@link Document}, even for proxies and versions
182     */
183    Document importDocument(String uuid, Document parent, String name, String typeName,
184            Map<String, Serializable> properties);
185
186    /**
187     * Gets a version of a document, given its versionable id and label.
188     * <p>
189     * The version model contains the label of the version to look for. On return, it is filled with the version's
190     * description and creation date.
191     *
192     * @param versionableId the versionable id
193     * @param versionModel the version model
194     * @return the version, or {@code null} if not found
195     */
196    Document getVersion(String versionableId, VersionModel versionModel);
197
198    /**
199     * Returns {@code true} if negative ACLs are allowed.
200     * <p>
201     * Negative ACLs are ACLs that include an ACE with a deny (isGranted=false). This does not include the full-blocking
202     * ACE for Everyone/Everything, which is always allowed.
203     *
204     * @return {@code true} if negative ACLs are allowed
205     * @since 6.0
206     */
207    boolean isNegativeAclAllowed();
208
209    ACP getMergedACP(Document doc);
210
211    void setACP(Document doc, ACP acp, boolean overwrite);
212
213    /**
214     * Gets the fulltext extracted from the binary fields.
215     *
216     * @since 5.9.3
217     */
218    Map<String, String> getBinaryFulltext(String id);
219
220}