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