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 * Bogdan Stefanescu 018 * Florent Guillaume 019 */ 020package org.nuxeo.ecm.core.model; 021 022import java.io.Serializable; 023import java.util.Collection; 024import java.util.List; 025import java.util.Map; 026 027import org.nuxeo.ecm.core.api.CoreSession; 028import org.nuxeo.ecm.core.api.DocumentNotFoundException; 029import org.nuxeo.ecm.core.api.IterableQueryResult; 030import org.nuxeo.ecm.core.api.PartialList; 031import org.nuxeo.ecm.core.api.ScrollResult; 032import org.nuxeo.ecm.core.api.VersionModel; 033import org.nuxeo.ecm.core.api.lock.LockManager; 034import org.nuxeo.ecm.core.api.security.ACP; 035import org.nuxeo.ecm.core.api.query.QueryFilter; 036 037/** 038 * Internal Session accessing the low-level storage. 039 */ 040public interface Session<T extends QueryFilter> { 041 042 // parameters for the session contexts 043 String USER_NAME = "username"; 044 045 /** 046 * Gets the repository that created this session. 047 * 048 * @return the repository 049 */ 050 String getRepositoryName(); 051 052 /** 053 * Does a query. 054 * 055 * @since 5.9.4 056 */ 057 PartialList<Document> query(String query, String queryType, T queryFilter, long countUpTo); 058 059 /** 060 * Does a query and fetch the individual results as maps. 061 */ 062 IterableQueryResult queryAndFetch(String query, String queryType, T queryFilter, boolean distinctDocuments, 063 Object[] params); 064 065 /** 066 * Does a query and fetch the individual results as maps. 067 * 068 * @since 7.10-HF25, 8.10-HF06, 9.2 069 */ 070 PartialList<Map<String, Serializable>> queryProjection(String query, String queryType, T queryFilter, 071 boolean distinctDocuments, long countUpTo, Object[] params); 072 073 /** 074 * Executes the given query and returns the first batch of results containing id of documents, next batch must be 075 * requested within the keepAliveSeconds delay. 076 * 077 * @since 8.4 078 */ 079 ScrollResult<String> scroll(String query, int batchSize, int keepAliveSeconds); 080 081 /** 082 * Executes the given query and returns the first batch of results containing id of documents, next batch must be 083 * requested within the keepAliveSeconds delay. 084 * 085 * @since 10.3 086 */ 087 ScrollResult<String> scroll(String query, T queryFilter, int batchSize, int keepAliveSeconds); 088 089 /** 090 * Get the next batch of result containing id of documents. 091 * 092 * @since 8.4 093 */ 094 ScrollResult<String> scroll(String scrollId); 095 096 /** 097 * Gets the lock manager for this session. 098 * 099 * @return the lock manager 100 * @since 7.4 101 */ 102 LockManager getLockManager(); 103 104 /** 105 * Saves this session. 106 */ 107 void save(); 108 109 /** 110 * Checks whether the session is alive. 111 * 112 * @return true if the session is closed, false otherwise 113 */ 114 boolean isLive(); 115 116 /** 117 * Closes this session. Does not save. 118 */ 119 void close(); 120 121 /** 122 * Gets the document at the given path, if any. 123 * 124 * @throws DocumentNotFoundException if the document doesn't exist 125 */ 126 Document resolvePath(String path) throws DocumentNotFoundException; 127 128 /** 129 * Gets a document given its ID. 130 * 131 * @param uuid the document id 132 * @return the document 133 * @throws DocumentNotFoundException if the document doesn't exist 134 */ 135 Document getDocumentByUUID(String uuid) throws DocumentNotFoundException; 136 137 /** 138 * Gets the root document in this repository. 139 * 140 * @return the root document 141 */ 142 Document getRootDocument(); 143 144 /** 145 * Gets the null document, to be used as a fake parent to add placeless children. 146 * 147 * @return the null document 148 */ 149 Document getNullDocument(); 150 151 /** 152 * Copies the source document to the given folder. 153 * <p> 154 * If the destination document is not a folder, an exception is thrown. 155 */ 156 Document copy(Document src, Document dst, String name); 157 158 /** 159 * Moves the source document to the given folder. 160 * <p> 161 * If the destination document is not a folder an exception is thrown. 162 * 163 * @param src the source document to move 164 * @param dst the destination folder 165 * @param name the new name of the document or null if the original name should be preserved 166 */ 167 Document move(Document src, Document dst, String name); 168 169 /** 170 * Creates a generic proxy to the given document inside the given folder. 171 * 172 * @param doc the document 173 * @param folder the folder 174 * @return the proxy 175 */ 176 Document createProxy(Document doc, Document folder); 177 178 /** 179 * Finds the proxies for a document. If the folder is not null, the search will be limited to its children. 180 * <p> 181 * If the document is a version, then only proxies to that version will be looked up. 182 * 183 * @param doc the document or version 184 * @param folder the folder, or null 185 * @return the list of proxies if any is found otherwise an empty list 186 * @since 1.4.1 for the case where doc is a proxy 187 */ 188 List<Document> getProxies(Document doc, Document folder); 189 190 /** 191 * Finds the proxies for a document. (The document may be a version or a live document) 192 * 193 * @param doc the document or version 194 * @return the list of proxies if any is found otherwise an empty list 195 * @since 10.2 196 */ 197 List<Document> getProxies(Document doc); 198 199 /** 200 * Sets a proxies' target. 201 * <p> 202 * The target must have the same version series as the proxy. 203 * 204 * @param proxy the proxy 205 * @param target the new target 206 * @since 5.5 207 */ 208 void setProxyTarget(Document proxy, Document target); 209 210 /** 211 * Imports a document with a given id and parent. 212 * <p> 213 * The document can then be filled with the normal imported properties. 214 * 215 * @param uuid the document uuid 216 * @param parent the document parent, or {@code null} for a version 217 * @param name the document name in its parent 218 * @param typeName the document type, or {@code ecm:proxy} for a proxy 219 * @param properties system properties of the document, which will vary depending whether it's a live document, a 220 * version or a proxy (see the various {@code IMPORT_*} constants of {@link CoreSession}) 221 * @return a writable {@link Document}, even for proxies and versions 222 */ 223 Document importDocument(String uuid, Document parent, String name, String typeName, 224 Map<String, Serializable> properties); 225 226 /** 227 * Gets a version of a document, given its versionable id and label. 228 * <p> 229 * The version model contains the label of the version to look for. On return, it is filled with the version's 230 * description and creation date. 231 * 232 * @param versionableId the versionable id 233 * @param versionModel the version model 234 * @return the version, or {@code null} if not found 235 */ 236 Document getVersion(String versionableId, VersionModel versionModel); 237 238 /** 239 * Returns {@code true} if negative ACLs are allowed. 240 * <p> 241 * Negative ACLs are ACLs that include an ACE with a deny (isGranted=false). This does not include the full-blocking 242 * ACE for Everyone/Everything, which is always allowed. 243 * 244 * @return {@code true} if negative ACLs are allowed 245 * @since 6.0 246 */ 247 boolean isNegativeAclAllowed(); 248 249 ACP getMergedACP(Document doc); 250 251 void setACP(Document doc, ACP acp, boolean overwrite); 252 253 /** 254 * Updates the Read ACLs for some documents. 255 * 256 * @param docIds the document ids 257 * @since 9.10 258 */ 259 void updateReadACLs(Collection<String> docIds); 260 261 /** 262 * Gets the fulltext extracted from the binary fields. 263 * 264 * @since 5.9.3 265 */ 266 Map<String, String> getBinaryFulltext(String id); 267 268}