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 * Destroys this session. 111 */ 112 void destroy(); 113 114 /** 115 * Gets the document at the given path, if any. 116 * 117 * @throws DocumentNotFoundException if the document doesn't exist 118 */ 119 Document resolvePath(String path) throws DocumentNotFoundException; 120 121 /** 122 * Gets a document given its ID. 123 * 124 * @param uuid the document id 125 * @return the document 126 * @throws DocumentNotFoundException if the document doesn't exist 127 */ 128 Document getDocumentByUUID(String uuid) throws DocumentNotFoundException; 129 130 /** 131 * Gets the root document in this repository. 132 * 133 * @return the root document 134 */ 135 Document getRootDocument(); 136 137 /** 138 * Gets the null document, to be used as a fake parent to add placeless children. 139 * 140 * @return the null document 141 */ 142 Document getNullDocument(); 143 144 /** 145 * Copies the source document to the given folder. 146 * <p> 147 * If the destination document is not a folder, an exception is thrown. 148 */ 149 Document copy(Document src, Document dst, String name); 150 151 /** 152 * Moves the source document to the given folder. 153 * <p> 154 * If the destination document is not a folder an exception is thrown. 155 * 156 * @param src the source document to move 157 * @param dst the destination folder 158 * @param name the new name of the document or null if the original name should be preserved 159 */ 160 Document move(Document src, Document dst, String name); 161 162 /** 163 * Creates a generic proxy to the given document inside the given folder. 164 * 165 * @param doc the document 166 * @param folder the folder 167 * @return the proxy 168 */ 169 Document createProxy(Document doc, Document folder); 170 171 /** 172 * Finds the proxies for a document. If the folder is not null, the search will be limited to its children. 173 * <p> 174 * If the document is a version, then only proxies to that version will be looked up. 175 * 176 * @param doc the document or version 177 * @param folder the folder, or null 178 * @return the list of proxies if any is found otherwise an empty list 179 * @since 1.4.1 for the case where doc is a proxy 180 */ 181 List<Document> getProxies(Document doc, Document folder); 182 183 /** 184 * Finds the proxies for a document. (The document may be a version or a live document) 185 * 186 * @param doc the document or version 187 * @return the list of proxies if any is found otherwise an empty list 188 * @since 10.2 189 */ 190 List<Document> getProxies(Document doc); 191 192 /** 193 * Sets a proxies' target. 194 * <p> 195 * The target must have the same version series as the proxy. 196 * 197 * @param proxy the proxy 198 * @param target the new target 199 * @since 5.5 200 */ 201 void setProxyTarget(Document proxy, Document target); 202 203 /** 204 * Imports a document with a given id and parent. 205 * <p> 206 * The document can then be filled with the normal imported properties. 207 * 208 * @param uuid the document uuid 209 * @param parent the document parent, or {@code null} for a version 210 * @param name the document name in its parent 211 * @param typeName the document type, or {@code ecm:proxy} for a proxy 212 * @param properties system properties of the document, which will vary depending whether it's a live document, a 213 * version or a proxy (see the various {@code IMPORT_*} constants of {@link CoreSession}) 214 * @return a writable {@link Document}, even for proxies and versions 215 */ 216 Document importDocument(String uuid, Document parent, String name, String typeName, 217 Map<String, Serializable> properties); 218 219 /** 220 * Gets a version of a document, given its versionable id and label. 221 * <p> 222 * The version model contains the label of the version to look for. On return, it is filled with the version's 223 * description and creation date. 224 * 225 * @param versionableId the versionable id 226 * @param versionModel the version model 227 * @return the version, or {@code null} if not found 228 */ 229 Document getVersion(String versionableId, VersionModel versionModel); 230 231 /** 232 * Returns {@code true} if negative ACLs are allowed. 233 * <p> 234 * Negative ACLs are ACLs that include an ACE with a deny (isGranted=false). This does not include the full-blocking 235 * ACE for Everyone/Everything, which is always allowed. 236 * 237 * @return {@code true} if negative ACLs are allowed 238 * @since 6.0 239 */ 240 boolean isNegativeAclAllowed(); 241 242 ACP getMergedACP(Document doc); 243 244 void setACP(Document doc, ACP acp, boolean overwrite); 245 246 /** 247 * Updates the Read ACLs for some documents. 248 * 249 * @param docIds the document ids 250 * @since 9.10 251 */ 252 void updateReadACLs(Collection<String> docIds); 253 254 /** 255 * Checks if fulltext extracted from the binary fields is internally stored as a blob. 256 * 257 * @return {@code true} if fulltext from binaries is store as a blob 258 * @since 11.1 259 */ 260 boolean isFulltextStoredInBlob(); 261 262 /** 263 * Gets the fulltext extracted from the binary fields. 264 * 265 * @since 5.9.3 266 */ 267 Map<String, String> getBinaryFulltext(String id); 268 269 /** 270 * Removes a document. In DBS, this removal is done without checking if proxies are targeting the document, or if it 271 * has any children. 272 * 273 * @param id the document id 274 * @since 11.1 275 */ 276 void removeDocument(String id); 277 278 /** 279 * INTERNAL framework property allowing deletion of undeletable documents. Should only be used in tests. 280 * <p> 281 * Note that even when this is set, a low-level blob provider may still disallow blob removal. 282 * 283 * @since 11.1 284 */ 285 String PROP_ALLOW_DELETE_UNDELETABLE_DOCUMENTS = "org.nuxeo.core.allowDeleteUndeletableDocuments"; 286 287 /* 288 * ----- Transaction management ----- 289 */ 290 291 /** 292 * Start the transaction. 293 * 294 * @since 11.1 295 */ 296 void start(); 297 298 /** 299 * Called just before the transaction is committed or rolled back. 300 * 301 * @since 11.1 302 */ 303 void end(); 304 305 /** 306 * Commit the transaction. 307 * 308 * @since 11.1 309 */ 310 void commit(); 311 312 /** 313 * Rollback the transaction. 314 * 315 * @since 11.1 316 */ 317 void rollback(); 318 319}