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