001/*
002 * (C) Copyright 2006-2016 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 */
020
021package org.nuxeo.ecm.core.api;
022
023import java.io.Serializable;
024import java.security.Principal;
025import java.util.Arrays;
026import java.util.Collection;
027import java.util.List;
028import java.util.Map;
029
030import org.nuxeo.ecm.core.api.DocumentModel.DocumentModelRefresh;
031import org.nuxeo.ecm.core.api.event.DocumentEventTypes;
032import org.nuxeo.ecm.core.api.security.ACE;
033import org.nuxeo.ecm.core.api.security.ACP;
034import org.nuxeo.ecm.core.schema.DocumentType;
035import org.nuxeo.ecm.core.schema.types.Schema;
036
037/**
038 * A session to the Nuxeo Core.
039 *
040 * @see DocumentModel
041 * @see DocumentRef
042 * @author Bogdan Stefanescu
043 * @author Florent Guillaume
044 */
045public interface CoreSession extends AutoCloseable {
046
047    // used to pass properties to importDocument
048    String IMPORT_VERSION_VERSIONABLE_ID = "ecm:versionableId";
049
050    String IMPORT_VERSION_CREATED = "ecm:versionCreated";
051
052    String IMPORT_VERSION_LABEL = "ecm:versionLabel";
053
054    String IMPORT_VERSION_DESCRIPTION = "ecm:versionDescription";
055
056    String IMPORT_VERSION_IS_LATEST = "ecm:isLatestVersion";
057
058    String IMPORT_VERSION_IS_LATEST_MAJOR = "ecm:isLatestMajorVersion";
059
060    String IMPORT_IS_VERSION = "ecm:isVersion";
061
062    String IMPORT_VERSION_MAJOR = "ecm:majorVersion";
063
064    String IMPORT_VERSION_MINOR = "ecm:minorVersion";
065
066    String IMPORT_PROXY_TARGET_ID = "ecm:proxyTargetId";
067
068    String IMPORT_PROXY_VERSIONABLE_ID = "ecm:proxyVersionableId";
069
070    String IMPORT_LIFECYCLE_POLICY = "ecm:lifeCyclePolicy";
071
072    String IMPORT_LIFECYCLE_STATE = "ecm:lifeCycleState";
073
074    /**
075     * @deprecated since 5.4.2, use {@link #IMPORT_LOCK_OWNER} and {@link #IMPORT_LOCK_CREATED} instead
076     */
077    @Deprecated
078    String IMPORT_LOCK = "ecm:lock";
079
080    /** @since 5.4.2 */
081    String IMPORT_LOCK_OWNER = "ecm:lockOwner";
082
083    /**
084     * Lock creation time as a Calendar object.
085     *
086     * @since 5.4.2
087     */
088    String IMPORT_LOCK_CREATED = "ecm:lockCreated";
089
090    String IMPORT_CHECKED_IN = "ecm:isCheckedIn";
091
092    String IMPORT_BASE_VERSION_ID = "ecm:baseVersionId";
093
094    /** The document type to use to create a proxy by import. */
095    String IMPORT_PROXY_TYPE = "ecm:proxy";
096
097    /**
098     * Allow version write, Boolean parameter passed in context data at saveDocument time.
099     *
100     * @since 5.9.2
101     */
102    String ALLOW_VERSION_WRITE = "allowVersionWrite";
103
104    /**
105     * Closes this session.
106     *
107     * @since 5.9.3
108     */
109    @Override
110    void close();
111
112    /**
113     * Destroys any system resources held by this instance.
114     * <p>
115     * Called when the instance is no more needed.
116     */
117    void destroy();
118
119    /**
120     * Gets the document type object given its type name.
121     *
122     * @param type the document type name
123     * @return the type the doc type object
124     */
125    DocumentType getDocumentType(String type);
126
127    /**
128     * NOT PUBLIC, DO NOT CALL.
129     * <p>
130     * Connects the CoreSession to a low-level Session.
131     *
132     * @param repositoryName the repository name
133     * @param principal the principal
134     */
135    void connect(String repositoryName, NuxeoPrincipal principal);
136
137    /**
138     * Returns true if the session is currently connected to the repository.
139     */
140    boolean isLive(boolean onThread);
141
142    /**
143     * Cancels any pending change made through this session.
144     */
145    void cancel();
146
147    /**
148     * Saves any pending changes done until now through this session.
149     */
150    void save();
151
152    /**
153     * Gets the current session id.
154     * <p>
155     * If the client is not connected returns null.
156     *
157     * @return the session id or null if not connected
158     */
159    String getSessionId();
160
161    /**
162     * Returns {@code true} if all sessions in the current thread share the same state.
163     */
164    boolean isStateSharedByAllThreadSessions();
165
166    /**
167     * Gets the principal that created the client session.
168     *
169     * @return the principal
170     */
171    Principal getPrincipal();
172
173    /**
174     * Checks if the principal that created the client session has the given privilege on the referred document.
175     */
176    boolean hasPermission(DocumentRef docRef, String permission);
177
178    /**
179     * Checks if a given principal has the given privilege on the referred document.
180     */
181    boolean hasPermission(Principal principal, DocumentRef docRef, String permission);
182
183    /**
184     * Gets the root document of this repository.
185     *
186     * @return the root document. cannot be null
187     */
188    DocumentModel getRootDocument();
189
190    /**
191     * Gets a document model given its reference.
192     * <p>
193     * The default schemas are used to populate the returned document model. Default schemas are configured via the
194     * document type manager.
195     * <p>
196     * Any other data model not part of the default schemas will be lazily loaded as needed.
197     *
198     * @param docRef the document reference
199     * @return the document
200     * @throws DocumentNotFoundException if the document cannot be found
201     */
202    DocumentModel getDocument(DocumentRef docRef) throws DocumentNotFoundException;
203
204    /**
205     * Gets a list of documents given their references.
206     * <p>
207     * Documents that are not accessible are skipped.
208     *
209     * @throws DocumentNotFoundException if a document cannot be found
210     */
211    DocumentModelList getDocuments(DocumentRef[] docRefs) throws DocumentNotFoundException;
212
213    /**
214     * Gets a child document given its name and the parent reference.
215     * <p>
216     * Throws an exception if the document could not be found.
217     * <p>
218     * If the supplied id is null, returns the default child of the document if any, otherwise raises an exception.
219     * <p>
220     * If the parent is null or its path is null, then root is considered.
221     *
222     * @param parent the reference to the parent document
223     * @param name the name of the child document to retrieve
224     * @return the named child if exists
225     * @throws DocumentNotFoundException if there is no child with the given name
226     */
227    DocumentModel getChild(DocumentRef parent, String name);
228
229    /**
230     * Tests if the document has a child with the given name.
231     * <p>
232     * This operation silently ignores non-folder documents: If the document is not a folder then returns false.
233     *
234     * @param parent the document
235     * @param name the child name
236     * @return {@code true} if the document has a child with the given name
237     * @since 7.3
238     */
239    boolean hasChild(DocumentRef parent, String name);
240
241    /**
242     * Gets the children of the given parent.
243     *
244     * @param parent the parent reference
245     * @return the children if any, an empty list if no children or null if the specified parent document is not a
246     *         folder
247     */
248    DocumentModelList getChildren(DocumentRef parent);
249
250    /**
251     * Gets an iterator to the children of the given parent.
252     *
253     * @param parent the parent reference
254     * @return iterator over the children collection or null if the specified parent document is not a folder
255     */
256    DocumentModelIterator getChildrenIterator(DocumentRef parent);
257
258    /**
259     * Gets the children of the given parent filtered according to the given document type.
260     *
261     * @param parent the parent reference
262     * @param type the wanted document type
263     * @return the documents if any, an empty list if none were found or null if the parent document is not a folder
264     */
265    DocumentModelList getChildren(DocumentRef parent, String type);
266
267    /**
268     * Gets an iterator to the children of the given parent filtered according to the given document type.
269     */
270    DocumentModelIterator getChildrenIterator(DocumentRef parent, String type);
271
272    /**
273     * Gets the children of the given parent filtered according to the given document type and permission.
274     *
275     * @param parent the parent reference
276     * @param type the wanted document type
277     * @param perm the permission the user must have
278     * @return the documents if any, an empty list if none were found or null if the parent document is not a folder
279     */
280    DocumentModelList getChildren(DocumentRef parent, String type, String perm);
281
282    /**
283     * Same as {@link #getChildren(DocumentRef, String, String)} but the result is filtered and then sorted using the
284     * specified filter and sorter.
285     *
286     * @param parent the parent reference
287     * @param type the wanted type
288     * @param perm permission to check for. If null, defaults to READ
289     * @param filter the filter to use if any, null otherwise
290     * @param sorter the sorter to use if any, null otherwise
291     * @return the list of the children or an empty list if no children were found or null if the given parent is not a
292     *         folder
293     */
294    DocumentModelList getChildren(DocumentRef parent, String type, String perm, Filter filter, Sorter sorter);
295
296    /**
297     * Gets the references of the children. No permission is checked if perm is null.
298     *
299     * @param parentRef the parent reference
300     * @param perm the permission to check on the children (usually READ); if null, <b>no permission is checked</b>
301     * @return a list of children references
302     * @since 1.4.1
303     */
304    List<DocumentRef> getChildrenRefs(DocumentRef parentRef, String perm);
305
306    /**
307     * Gets the children of the given parent filtered according to the given document type and permission. Long result
308     * sets are loaded frame by frame transparently by the DocumentModelIterator.
309     */
310    DocumentModelIterator getChildrenIterator(DocumentRef parent, String type, String perm, Filter filter);
311
312    /**
313     * Same as {@link #getChildren(DocumentRef, String, String, Filter, Sorter)} without specific permission filtering.
314     *
315     * @param parent the parent reference
316     * @param type the wanted type
317     * @param filter the filter to use if any, null otherwise
318     * @param sorter the sorter to use if any, null otherwise
319     * @return the list of the children or an empty list if no children were found or null if the given parent is not a
320     *         folder
321     */
322    DocumentModelList getChildren(DocumentRef parent, String type, Filter filter, Sorter sorter);
323
324    /**
325     * Same as {@link CoreSession#getChildren(DocumentRef)} but returns only folder documents.
326     *
327     * @param parent the parent ref
328     * @return a list of children if any, an empty one if none or null if the given parent is not a folder
329     */
330    DocumentModelList getFolders(DocumentRef parent);
331
332    /**
333     * Same as {@link CoreSession#getFolders(DocumentRef)} but uses an optional filter and sorter on the result.
334     *
335     * @param parent the parent reference
336     * @param filter the filter to use or null if none
337     * @param sorter the sorter to use or null if none
338     * @return a list of children if any, an empty one if none or null if the given parent is not a folder
339     */
340    DocumentModelList getFolders(DocumentRef parent, Filter filter, Sorter sorter);
341
342    /**
343     * Same as {@link CoreSession#getChildren(DocumentRef)} but returns only non-folder documents.
344     *
345     * @param parent the parent reference
346     * @return a list of children if any, an empty one if none or null if the given parent is not a folder
347     */
348    DocumentModelList getFiles(DocumentRef parent);
349
350    /**
351     * Same as {@link #getFiles} but uses an optional filter and sorter on the result.
352     *
353     * @param parent the parent reference
354     * @param filter the filter to use or null if none
355     * @param sorter the sorter to use or null if none
356     * @return a list of children if any, an empty one if none or null if the given parent is not a folder
357     */
358    DocumentModelList getFiles(DocumentRef parent, Filter filter, Sorter sorter);
359
360    /**
361     * Returns the parent ref of the document referenced by {@code docRef} or {@code null} if this is the root document.
362     * <p>
363     * This method does not check the permissions on the parent document of this {@code CoreSession}'s {@code Principal}.
364     *
365     * @since 5.4.2
366     */
367    DocumentRef getParentDocumentRef(DocumentRef docRef);
368
369    /**
370     * Gets the parent document or null if this is the root document.
371     *
372     * @return the parent document or null if this is the root document
373     */
374    DocumentModel getParentDocument(DocumentRef docRef);
375
376    /**
377     * Gets the parent documents in path from the root to the given document or empty list if this is the root document.
378     * <p>
379     * Documents the principal is is not allowed to browse are filtered out the parents list.
380     *
381     * @return the list with parent documents or empty list if this is the root document
382     */
383    List<DocumentModel> getParentDocuments(DocumentRef docRef);
384
385    /**
386     * Tests if the document pointed by the given reference exists and is accessible.
387     * <p>
388     * This operation makes no difference between non-existence and permission problems.
389     * <p>
390     * If the parent is null or its path is null, then root is considered.
391     *
392     * @param docRef the reference to the document to test for existence
393     * @return true if the referenced document exists, false otherwise
394     */
395    boolean exists(DocumentRef docRef);
396
397    /**
398     * Tests if the document has any children.
399     * <p>
400     * This operation silently ignores non-folder documents: If the document is not a folder then returns false.
401     * <p>
402     * If the parent is null or its path is null, then root is considered.
403     *
404     * @param docRef the reference to the document to test
405     * @return true if document has children, false otherwise
406     */
407    boolean hasChildren(DocumentRef docRef);
408
409    /**
410     * Creates a document model using type name.
411     * <p>
412     * Used to fetch initial datamodels from the type definition.
413     * <p>
414     * DocumentModel creation notifies a {@link DocumentEventTypes#EMPTY_DOCUMENTMODEL_CREATED} so that core event
415     * listener can initialize its content with computed properties.
416     *
417     * @return the initial document model
418     */
419    DocumentModel createDocumentModel(String typeName);
420
421    /**
422     * Creates a document model using required information.
423     * <p>
424     * Used to fetch initial datamodels from the type definition.
425     * <p>
426     * DocumentModel creation notifies a {@link DocumentEventTypes#EMPTY_DOCUMENTMODEL_CREATED} so that core event
427     * listener can initialize its content with computed properties.
428     *
429     * @param parentPath the parent path
430     * @param name The destination name
431     * @param typeName the type name
432     * @return the initial document model
433     */
434    DocumentModel createDocumentModel(String parentPath, String name, String typeName);
435
436    /**
437     * Creates a document model using required information.
438     * <p>
439     * Used to fetch initial datamodels from the type definition.
440     * <p>
441     * DocumentModel creation notifies a {@link DocumentEventTypes#EMPTY_DOCUMENTMODEL_CREATED} so that core event
442     * listener can initialize its content with computed properties.
443     *
444     * @param typeName the type name
445     * @param options additional contextual data provided to core event listeners
446     * @return the initial document model
447     */
448    DocumentModel createDocumentModel(String typeName, Map<String, Object> options);
449
450    /**
451     * Creates a document using given document model for initialization.
452     * <p>
453     * The model contains path of the new document, its type and optionally the initial data models of the document.
454     * <p>
455     *
456     * @param model the document model to use for initialization
457     * @return the created document
458     */
459    DocumentModel createDocument(DocumentModel model);
460
461    /**
462     * Bulk creation of documents.
463     *
464     * @param docModels the document models to use for intialization
465     * @return the created documents
466     */
467    DocumentModel[] createDocument(DocumentModel[] docModels);
468
469    /**
470     * Low-level import of documents, reserved for the administrator.
471     * <p>
472     * This method is used to import documents with given ids, or directly import versions and proxies.
473     * <p>
474     * The id, parent, name and typeName must be present in each docModel.
475     * <p>
476     * The context data needs to be filled with values depending on the type of the document:
477     * <p>
478     * For a proxy (type = {@code "ecm:proxyType"}): {@link #IMPORT_PROXY_TARGET_ID} and
479     * {@link #IMPORT_PROXY_VERSIONABLE_ID}.
480     * <p>
481     * For a version (no parent): {@link #IMPORT_VERSION_VERSIONABLE_ID}, {@link #IMPORT_VERSION_CREATED},
482     * {@link #IMPORT_VERSION_LABEL} and {@link #IMPORT_VERSION_DESCRIPTION}.
483     * <p>
484     * For a live document: {@link #IMPORT_BASE_VERSION_ID} and {@link #IMPORT_CHECKED_IN} (Boolean).
485     * <p>
486     * For a live document or a version: {@link #IMPORT_LIFECYCLE_POLICY} , {@link #IMPORT_LIFECYCLE_STATE},
487     * {@link #IMPORT_VERSION_MAJOR} (Long) and {@link #IMPORT_VERSION_MINOR} (Long).
488     *
489     * @param docModels the documents to create
490     */
491    void importDocuments(List<DocumentModel> docModels);
492
493    /**
494     * Saves changes done on the given document model.
495     *
496     * @param docModel the document model that needs modified
497     */
498    DocumentModel saveDocument(DocumentModel docModel);
499
500    /**
501     * Bulk document saving.
502     *
503     * @param docModels the document models that needs to be saved
504     */
505    void saveDocuments(DocumentModel[] docModels);
506
507    /**
508     * Check if a document can be removed. This needs the REMOVE permission on the document and the REMOVE_CHILDREN
509     * permission on the parent.
510     * <p>
511     * For an archived version to be removeable, it must not be referenced from any proxy or be the base of a working
512     * document, and the REMOVE permission must be available on the working document (or the user must be an
513     * administrator if no working document exists).
514     *
515     * @param docRef the document
516     * @return true if the document can be removed
517     */
518    boolean canRemoveDocument(DocumentRef docRef);
519
520    /**
521     * Removes this document and all its children, if any.
522     *
523     * @param docRef the reference to the document to remove
524     */
525    void removeDocument(DocumentRef docRef);
526
527    /**
528     * Bulk method to remove documents.
529     * <p>
530     * This method is safe with respect to orderings: it doesn't fail if an ancestor of a document occurs before the
531     * document.
532     * </p>
533     *
534     * @param docRefs the refs to the document to remove
535     */
536    void removeDocuments(DocumentRef[] docRefs);
537
538    /**
539     * Removes all children from the given document.
540     *
541     * @param docRef the reference to the document to remove
542     */
543    void removeChildren(DocumentRef docRef);
544
545    /**
546     * Copies the source document to the destination folder under the given name. If the name is null the original name
547     * is preserved.
548     * <p>
549     * If the destination document is not a folder or it doesn't exists then throws an exception.
550     * <p>
551     * If the source is a proxy the destination will be a copy of the proxy.
552     *
553     * @param src the source document reference
554     * @param dst the destination folder reference
555     * @param name the new name of the file or null if the original name must be preserved
556     * @param copyOptions the options for copy
557     */
558    DocumentModel copy(DocumentRef src, DocumentRef dst, String name, CopyOption... copyOptions);
559
560    /**
561     * Copies the source document to the destination folder under the given name. If the name is null the original name
562     * is preserved.
563     * <p>
564     * If the destination document is not a folder or it doesn't exists then throws an exception.
565     * <p>
566     * If the source is a proxy the destination will be a copy of the proxy.
567     *
568     * @param src the source document reference
569     * @param dst the destination folder reference
570     * @param name the new name of the file or null if the original name must be preserved
571     * @param resetLifeCycle the property that flagged whether reset destination document lifecycle or not
572     * @since 5.7
573     * @deprecated Since 8.2. Use {@link #copy(DocumentRef, DocumentRef, String, CopyOption...)} instead
574     */
575    @Deprecated
576    DocumentModel copy(DocumentRef src, DocumentRef dst, String name, boolean resetLifeCycle);
577
578    /**
579     * Bulk copy. Destination must be a folder document.
580     *
581     * @param src the documents to copy
582     * @param dst the destination folder
583     * @param copyOptions the options for copy
584     * @since 8.2
585     */
586    List<DocumentModel> copy(List<DocumentRef> src, DocumentRef dst, CopyOption... copyOptions);
587
588    /**
589     * Bulk copy. Destination must be a folder document.
590     *
591     * @param src the documents to copy
592     * @param dst the destination folder
593     * @param resetLifeCycle the property that flagged whether reset destination document lifecycle or not
594     * @since 5.7
595     * @deprecated Since 8.2. Use {@link #copy(List, DocumentRef, CopyOption...)} instead
596     */
597    @Deprecated
598    List<DocumentModel> copy(List<DocumentRef> src, DocumentRef dst, boolean resetLifeCycle);
599
600    /**
601     * Work like copy but in the case of a source proxy the destination will be a new document instead of a proxy.
602     *
603     * @see CoreSession#copy(DocumentRef, DocumentRef, String, CopyOption...)
604     * @param src the source document reference
605     * @param dst the destination folder reference
606     * @param name the new name of the file or null if the original name must be preserved
607     * @param copyOptions the options for copy
608     * @since 8.2
609     */
610    DocumentModel copyProxyAsDocument(DocumentRef src, DocumentRef dst, String name, CopyOption... copyOptions);
611
612    /**
613     * Work like copy but in the case of a source proxy the destination will be a new document instead of a proxy.
614     *
615     * @param src the source document reference
616     * @param dst the destination folder reference
617     * @param name the new name of the file or null if the original name must be preserved
618     * @param resetLifeCycle the property that flagged whether reset destination document lifecycle or not
619     * @since 5.7
620     * @deprecated Since 8.2. Use {@link #copyProxyAsDocument(DocumentRef, DocumentRef, String, CopyOption...)} instead
621     */
622    @Deprecated
623    DocumentModel copyProxyAsDocument(DocumentRef src, DocumentRef dst, String name, boolean resetLifeCycle);
624
625    /**
626     * Bulk copyProxyAsDocument. Destination must be a folder document.
627     *
628     * @param src the documents to copy
629     * @param dst the destination folder
630     * @param copyOptions the options of copy
631     * @since 8.2
632     */
633    List<DocumentModel> copyProxyAsDocument(List<DocumentRef> src, DocumentRef dst, CopyOption... copyOptions);
634
635    /**
636     * Bulk copyProxyAsDocument. Destination must be a folder document.
637     *
638     * @param src the documents to copy
639     * @param dst the destination folder
640     * @param resetLifeCycle the property that flagged whether reset destination document lifecycle or not
641     * @since 5.7
642     * @deprecated Since 8.2. Use {@link #copyProxyAsDocument(List, DocumentRef, CopyOption...)} instead
643     */
644    @Deprecated
645    List<DocumentModel> copyProxyAsDocument(List<DocumentRef> src, DocumentRef dst, boolean resetLifeCycle);
646
647    /**
648     * Moves the source document to the destination folder under the given name. If the name is {@code null} or if there
649     * is a collision, a suitable new name is found.
650     * <p>
651     * If the destination document is not a folder or it doesn't exists then throws an exception.
652     *
653     * @param src the source document reference
654     * @param dst the destination folder reference
655     * @param name the new name of the file, or {@code null}
656     */
657    DocumentModel move(DocumentRef src, DocumentRef dst, String name);
658
659    /**
660     * Bulk move. Destination must be a folder document.
661     *
662     * @param src the documents to move
663     * @param dst the destination folder
664     */
665    void move(List<DocumentRef> src, DocumentRef dst);
666
667    /**
668     * Gets the document access control policy.
669     * <p>
670     * The returned ACP is the ACP defined on that document if any + the inherited ACL if any. If neither a local ACP
671     * nor inherited ACL exists null is returned.
672     * <p>
673     * Note that modifying the returned ACP will not affect in any way the stored document ACP. To modify the ACP you
674     * must explicitely set it by calling {@link CoreSession#setACP(DocumentRef, ACP, boolean)}
675     * <p>
676     * This method will always fetch a fresh ACP from the storage. The recommended way to get the ACP is to use
677     * {@link DocumentModel#getACP()} this way the ACP will be cached at the document model level and so you can use it
678     * for multiple permission checks without fetching it each time.
679     *
680     * @param docRef the doc ref to retrieve ACP or null if none
681     * @return the ACP
682     */
683    ACP getACP(DocumentRef docRef);
684
685    /**
686     * Sets the ACP for this document.
687     * <p>
688     * If the ACP contains an <code>INHERITED</code> ACL it will be discarded. Only ACLs relative to the current
689     * document may be changed.
690     * <p>
691     * If the <code>overwrite</code> argument is false, the ACP is merged with the existing one if any. The merge is
692     * done as follow:
693     * <ul>
694     * <li>If any ACL is that already exists on the document ACp is redefined by the new ACO then it will be replaced by
695     * the new one. So if you want to remove an ACl in this mode you need to specify an empty ACL.
696     * <li>If the new ACP contains an ACl that is not defined by the old one the it will be added to the merged ACP.
697     * <li>If the <code>owners</code> are specified then they will replace the existing ones if any. Otherwise the old
698     * owners are preserved if any. As for the ACL if you want to remove existing owners you need to specify an empty
699     * owner array (and not a null one)
700     * </ul>
701     * If the <code>overwrite</code> argument is true, the old ACP will be replaced by the new one.
702     * <p>
703     * This way if you can remove the existing ACP by specifying a null ACP and <code>overwrite</code> argument set to
704     * true.
705     * <p>
706     * Setting a null ACP when <code>overwrite</code> is false will do nothing.
707     */
708    void setACP(DocumentRef docRef, ACP acp, boolean overwrite);
709
710    /**
711     * Replace the {@code oldACE} with the {@code newACE} on the given {@code aclName}.
712     * <p>
713     *
714     * @since 7.4
715     */
716    void replaceACE(DocumentRef docRef, String aclName, ACE oldACE, ACE newACE);
717
718    /**
719     * Returns {@code true} if negative ACLs are allowed.
720     * <p>
721     * Negative ACLs are ACLs that include an ACE with a deny (isGranted=false). This does not include the full-blocking
722     * ACE for Everyone/Everything, which is always allowed.
723     *
724     * @return {@code true} if negative ACLs are allowed
725     * @since 6.0
726     */
727    boolean isNegativeAclAllowed();
728
729    /*
730     * Support for lazy loading
731     */
732
733    /**
734     * Retrieves a data model given a document reference and a schema.
735     * <p>
736     * For INTERNAL use by the core.
737     *
738     * @since 5.4.2
739     */
740    DataModel getDataModel(DocumentRef docRef, Schema schema);
741
742    // -------- Versioning API ---------------
743
744    /**
745     * Gets the last version of a document.
746     *
747     * @param docRef the reference to the document
748     * @return the version
749     * @deprecated use {@link #getLastDocumentVersion} instead
750     */
751    @Deprecated
752    VersionModel getLastVersion(DocumentRef docRef);
753
754    /**
755     * Gets the document corresponding to the last version for the given document.
756     *
757     * @param docRef the reference to the document
758     * @return the document model corresponding to the version
759     */
760    DocumentModel getLastDocumentVersion(DocumentRef docRef);
761
762    /**
763     * Gets the document reference corresponding to the last version for the given document.
764     *
765     * @param docRef the reference to the document
766     * @return the document reference corresponding to the last version
767     */
768    DocumentRef getLastDocumentVersionRef(DocumentRef docRef);
769
770    /**
771     * Gets the head (live) document for this document.
772     *
773     * @param docRef the reference to the document
774     * @return the version
775     */
776    DocumentModel getSourceDocument(DocumentRef docRef);
777
778    /**
779     * Gets the references of the versions of the document.
780     *
781     * @param docRef the reference to the document
782     * @return a list of version references
783     * @since 1.4.1
784     */
785    List<DocumentRef> getVersionsRefs(DocumentRef docRef);
786
787    /**
788     * Retrieves all the versions for a specified document.
789     *
790     * @param docRef the reference to the document
791     * @return the list of {@link DocumentModel} representing versions, empty list if none is found.
792     */
793    List<DocumentModel> getVersions(DocumentRef docRef);
794
795    /**
796     * Retrieves all the versions for a specified document.
797     *
798     * @param docRef the reference to the document
799     * @return the list of {@link VersionModel} representing versions, empty list if none is found.
800     */
801    List<VersionModel> getVersionsForDocument(DocumentRef docRef);
802
803    /**
804     * Gets a document version, given the versionable id and label.
805     * <p>
806     * The version model contains the label of the version to look for. On return, it is filled with the version's
807     * description and creation date.
808     *
809     * @param versionableId the versionable id
810     * @param versionModel the version model holding the label
811     * @return the version, or {@code null} if not found
812     */
813    DocumentModel getVersion(String versionableId, VersionModel versionModel);
814
815    /**
816     * Gets the version label for a document, according to the versioning service.
817     *
818     * @param docModel the document
819     * @return the version label
820     */
821    String getVersionLabel(DocumentModel docModel);
822
823    /**
824     * Returns a document that represents the specified version of the document.
825     *
826     * @param docRef the reference to the document
827     * @param version the version for which we want the corresponding document
828     */
829    DocumentModel getDocumentWithVersion(DocumentRef docRef, VersionModel version);
830
831    /**
832     * Restores the given document to the specified version.
833     *
834     * @param docRef the reference to the document
835     * @param versionRef the reference to the version
836     * @param skipSnapshotCreation {@code true} if the document should not be snapshotted before being restored
837     * @param skipCheckout {@code true} if the restored document should be kept in a checked-in state
838     * @since 5.4
839     */
840    DocumentModel restoreToVersion(DocumentRef docRef, DocumentRef versionRef, boolean skipSnapshotCreation,
841            boolean skipCheckout);
842
843    /**
844     * Restores the given document to the specified version permitting to skip the creation of the snapshot for current
845     * document.
846     *
847     * @param docRef the reference to the document
848     * @param version the version to which the document should be restored to - only the label is used for the moment
849     * @param skipSnapshotCreation indicates if skipping snapshot creation
850     * @deprecated use {@link #restoreToVersion(DocumentRef, DocumentRef, boolean, boolean)} instead
851     */
852    @Deprecated
853    DocumentModel restoreToVersion(DocumentRef docRef, VersionModel version, boolean skipSnapshotCreation);
854
855    /**
856     * Restores the given document to the specified version.
857     *
858     * @param docRef the reference to the document
859     * @param versionRef the reference to the version
860     * @since 5.4
861     */
862    DocumentModel restoreToVersion(DocumentRef docRef, DocumentRef versionRef);
863
864    /**
865     * Restores the given document to the specified version.
866     *
867     * @param docRef the reference to the document
868     * @param version the version to which the document should be restored to - only the label is used for the moment
869     * @deprecated use {@link #restoreToVersion(DocumentRef, DocumentRef)} instead
870     */
871    @Deprecated
872    DocumentModel restoreToVersion(DocumentRef docRef, VersionModel version);
873
874    /**
875     * Gets the version to which a checked in document is linked.
876     * <p>
877     * Returns {@code null} for a checked out document or a version or a proxy.
878     *
879     * @return the version, or {@code null}
880     */
881    DocumentRef getBaseVersion(DocumentRef docRef);
882
883    /**
884     * Checks out a versioned document.
885     *
886     * @param docRef the reference to the document
887     */
888    void checkOut(DocumentRef docRef);
889
890    /**
891     * Checks in a modified document, creating a new version.
892     *
893     * @param docRef the reference to the document
894     * @param version the version descriptor
895     * @return the version document just created
896     * @deprecated use {@link #checkIn(DocumentRef, VersioningOption, String)} instead
897     */
898    @Deprecated
899    DocumentModel checkIn(DocumentRef docRef, VersionModel version);
900
901    /**
902     * Checks in a modified document, creating a new version.
903     *
904     * @param docRef the reference to the document
905     * @param option whether to do create a new {@link VersioningOption#MINOR} or {@link VersioningOption#MAJOR} version
906     *            during check in
907     * @param checkinComment the checkin comment
908     * @return the version just created
909     * @since 5.4
910     */
911    DocumentRef checkIn(DocumentRef docRef, VersioningOption option, String checkinComment);
912
913    /**
914     * Returns whether the current document is checked-out or not.
915     *
916     * @param docRef the reference to the document
917     */
918    boolean isCheckedOut(DocumentRef docRef);
919
920    /**
921     * Gets the version series id for a document.
922     * <p>
923     * All documents and versions derived by a check in or checkout from the same original document share the same
924     * version series id.
925     *
926     * @param docRef the document reference
927     * @return the version series id
928     * @since 5.4
929     */
930    String getVersionSeriesId(DocumentRef docRef);
931
932    /**
933     * Gets the working copy (live document) for a proxy or a version.
934     *
935     * @param docRef the document reference
936     * @return the working copy, or {@code null} if not found
937     * @since 5.4
938     */
939    DocumentModel getWorkingCopy(DocumentRef docRef);
940
941    /**
942     * Creates a generic proxy to the given document inside the given folder.
943     * <p>
944     * The document may be a version, or a working copy (live document) in which case the proxy will be a "shortcut".
945     *
946     * @since 1.6.1 (5.3.1)
947     */
948    DocumentModel createProxy(DocumentRef docRef, DocumentRef folderRef);
949
950    /** -------------------------- Query API --------------------------- * */
951
952    /**
953     * Executes the given NXQL query an returns the result.
954     *
955     * @param query the query to execute
956     * @return the query result
957     */
958    DocumentModelList query(String query);
959
960    /**
961     * Executes the given NXQL query an returns the result.
962     *
963     * @param query the query to execute
964     * @param max number of document to retrieve
965     * @return the query result
966     */
967    DocumentModelList query(String query, int max);
968
969    /**
970     * Executes the given NXQL query and returns the result that matches the filter.
971     *
972     * @param query the query to execute
973     * @param filter the filter to apply to result
974     * @return the query result
975     */
976    DocumentModelList query(String query, Filter filter);
977
978    /**
979     * Executes the given NXQL query and returns the result that matches the filter.
980     *
981     * @param query the query to execute
982     * @param filter the filter to apply to result
983     * @param max number of document to retrieve
984     * @return the query result
985     */
986    DocumentModelList query(String query, Filter filter, int max);
987
988    /**
989     * Executes the given NXQL query and returns the result that matches the filter.
990     *
991     * @param query the query to execute
992     * @param filter the filter to apply to result
993     * @param limit the maximum number of documents to retrieve, or 0 for all of them
994     * @param offset the offset (starting at 0) into the list of documents
995     * @param countTotal if {@code true}, return a {@link DocumentModelList} that includes a total size of the
996     *            underlying list (size if there was no limit or offset)
997     * @return the query result
998     */
999    DocumentModelList query(String query, Filter filter, long limit, long offset, boolean countTotal);
1000
1001    /**
1002     * Executes the given NXQL query and returns the result that matches the filter.
1003     *
1004     * @param query the query to execute
1005     * @param filter the filter to apply to result
1006     * @param limit the maximum number of documents to retrieve, or 0 for all of them
1007     * @param offset the offset (starting at 0) into the list of documents
1008     * @param countUpTo if {@code -1}, count the total size without offset/limit.<br>
1009     *            If {@code 0}, don't count the total size.<br>
1010     *            If {@code n}, count the total number if there are less than n documents otherwise set the size to
1011     *            {@code -1}.
1012     * @return the query result
1013     * @since 5.6
1014     */
1015    DocumentModelList query(String query, Filter filter, long limit, long offset, long countUpTo);
1016
1017    /**
1018     * Executes the given query and returns the result that matches the filter.
1019     *
1020     * @param query the query to execute
1021     * @param queryType the query type, like "NXQL"
1022     * @param filter the filter to apply to result
1023     * @param limit the maximum number of documents to retrieve, or 0 for all of them
1024     * @param offset the offset (starting at 0) into the list of documents
1025     * @param countTotal if {@code true}, return a {@link DocumentModelList} that includes a total size of the
1026     *            underlying list (size if there was no limit or offset)
1027     * @return the query result
1028     * @since 5.5
1029     */
1030    DocumentModelList query(String query, String queryType, Filter filter, long limit, long offset, boolean countTotal);
1031
1032    /**
1033     * Executes the given query and returns the result that matches the filter.
1034     *
1035     * @param query the query to execute
1036     * @param queryType the query type, like "NXQL"
1037     * @param filter the filter to apply to result
1038     * @param limit the maximum number of documents to retrieve, or 0 for all of them
1039     * @param offset the offset (starting at 0) into the list of documents
1040     * @param countUpTo if {@code -1}, return a {@link DocumentModelList} that includes a total size of the underlying
1041     *            list (size if there was no limit or offset). <br>
1042     *            If {@code 0}, don't return the total size of the underlying list. <br>
1043     *            If {@code n}, return the total size of the underlying list when the size is smaller than {@code n}
1044     *            else return a total size of {@code -1}.
1045     * @return the query result
1046     * @since 5.6
1047     */
1048    DocumentModelList query(String query, String queryType, Filter filter, long limit, long offset, long countUpTo);
1049
1050    /**
1051     * Executes the given query and returns an iterable of maps containing the requested properties (which must be
1052     * closed when done).
1053     *
1054     * @param query the query to execute
1055     * @param queryType the query type, usually "NXQL"
1056     * @param params optional query-type-dependent parameters
1057     * @return an {@link IterableQueryResult}, which <b>must</b> be closed after use
1058     */
1059    IterableQueryResult queryAndFetch(String query, String queryType, Object... params);
1060
1061    /**
1062     * Executes the given query and returns an iterable of maps containing the requested properties (which must be
1063     * closed when done).
1064     * <p>
1065     * It's possible to specify {@code distinctDocuments = true} to get a maximum of one row of results per document,
1066     * this will behave differently only when the {@code WHERE} clause contains wildcards.
1067     *
1068     * @param query the query to execute
1069     * @param queryType the query type, usually "NXQL"
1070     * @param distinctDocuments if {@code true} then a maximum of one row per document will be returned
1071     * @param params optional query-type-dependent parameters
1072     * @return an {@link IterableQueryResult}, which <b>must</b> be closed after use
1073     * @since 7.10-HF04, 8.2
1074     */
1075    IterableQueryResult queryAndFetch(String query, String queryType, boolean distinctDocuments, Object... params);
1076
1077    /** -------------------------- Security API --------------------------- * */
1078
1079    /**
1080     * Retrieves the available security permissions existing in the system.
1081     * <p>
1082     *
1083     * @return a raw list of permission names, either basic or group names
1084     */
1085    // TODO: (Hardcoded at the moment. In the future wil get data from
1086    // LDAP/database.)
1087    List<String> getAvailableSecurityPermissions();
1088
1089    /**
1090     * Returns the life cycle of the document.
1091     *
1092     * @see org.nuxeo.ecm.core.lifecycle
1093     * @param docRef the document reference
1094     * @return the life cycle as a string
1095     */
1096    String getCurrentLifeCycleState(DocumentRef docRef);
1097
1098    /**
1099     * Returns the life cycle policy of the document.
1100     *
1101     * @see org.nuxeo.ecm.core.lifecycle
1102     * @param docRef the document reference
1103     * @return the life cycle policy
1104     */
1105    String getLifeCyclePolicy(DocumentRef docRef);
1106
1107    /**
1108     * Follows a given life cycle transition.
1109     * <p>
1110     * This will update the current life cycle of the document.
1111     *
1112     * @param docRef the document reference
1113     * @param transition the name of the transition to follow
1114     * @return a boolean representing the status if the operation
1115     * @throws LifeCycleException if the transition cannot be followed
1116     */
1117    boolean followTransition(DocumentRef docRef, String transition) throws LifeCycleException;
1118
1119    /**
1120     * Follows a given life cycle transition.
1121     * <p>
1122     * This will update the current life cycle of the document.
1123     *
1124     * @param doc the document model
1125     * @param transition the name of the transition to follow
1126     * @return a boolean representing the status if the operation
1127     * @throws LifeCycleException if the transition cannot be followed
1128     */
1129    boolean followTransition(DocumentModel doc, String transition) throws LifeCycleException;
1130
1131    /**
1132     * Gets the allowed state transitions for this document.
1133     *
1134     * @param docRef the document reference
1135     * @return a collection of state transitions as string
1136     */
1137    Collection<String> getAllowedStateTransitions(DocumentRef docRef);
1138
1139    /**
1140     * Reinitializes the life cycle state of the document to its default state.
1141     *
1142     * @param docRef the document
1143     * @since 5.4.2
1144     */
1145    void reinitLifeCycleState(DocumentRef docRef);
1146
1147    /**
1148     * Retrieves the given field value from the given schema for all the given documents.
1149     *
1150     * @param docRefs the document references
1151     * @param schema the schema
1152     * @param field the field name
1153     * @return the field values in the same order as the given docRefs
1154     */
1155    Object[] getDataModelsField(DocumentRef[] docRefs, String schema, String field);
1156
1157    /**
1158     * Creates an array with all parent refs starting from the given document up to the root. So the return value will
1159     * have [0] = parent ref; [1] = parent parent ref... etc.
1160     *
1161     * @return an array with ancestor documents ref
1162     */
1163    DocumentRef[] getParentDocumentRefs(DocumentRef docRef);
1164
1165    /**
1166     * Retrieves the given field value from the given schema for the given document along with all its parent documents.
1167     *
1168     * @param docRef the document reference
1169     * @param schema the schema
1170     * @param field the field name
1171     * @return an array with field values of all documents on the path from the given document to the root
1172     */
1173    Object[] getDataModelsFieldUp(DocumentRef docRef, String schema, String field);
1174
1175    /**
1176     * Gets the lock key on the given document if a lock exists or null otherwise.
1177     * <p>
1178     * A lock key has the form {@code someuser:Nov 29, 2010}.
1179     *
1180     * @param doc the document reference
1181     * @return the lock key if the document is locked, null otherwise
1182     * @deprecated since 5.4.2, use {@link #getLockInfo} instead
1183     */
1184    @Deprecated
1185    String getLock(DocumentRef doc);
1186
1187    /**
1188     * Sets a lock on the given document using the given key.
1189     * <p>
1190     * A lock key must have the form {@code someuser:Nov 29, 2010}.
1191     *
1192     * @param doc the document reference
1193     * @param key the lock key
1194     * @throws LockException if the document is already locked
1195     * @deprecated since 5.4.2, use {@link #setLock(DocumentRef)} instead
1196     */
1197    @Deprecated
1198    void setLock(DocumentRef doc, String key) throws LockException;
1199
1200    /**
1201     * Removes the lock if one exists.
1202     * <p>
1203     * The caller principal should be the same as the one who set the lock or to belongs to the administrator group,
1204     * otherwise an exception will be throw.
1205     * <p>
1206     * If the document was not locked, does nothing.
1207     *
1208     * @param docRef the document to unlock
1209     * @return the lock key that was removed
1210     * @deprecated since 5.4.2, use {@link #removeLock} instead
1211     */
1212    @Deprecated
1213    String unlock(DocumentRef docRef);
1214
1215    /**
1216     * Sets a lock on the given document.
1217     *
1218     * @param docRef the document reference
1219     * @return the lock info that was set
1220     * @throws LockException if the document is already locked
1221     * @since 5.4.2
1222     */
1223    Lock setLock(DocumentRef docRef) throws LockException;
1224
1225    /**
1226     * Gets the lock info on the given document.
1227     * <p>
1228     * Lock info is never cached, and needs to use a separate transaction in a separate thread, so care should be taken
1229     * to not call this method needlessly.
1230     *
1231     * @param docRef the document reference
1232     * @return the lock info if the document is locked, or {@code null} otherwise
1233     * @since 5.4.2
1234     */
1235    Lock getLockInfo(DocumentRef docRef);
1236
1237    /**
1238     * Removes the lock on the given document.
1239     * <p>
1240     * The caller principal should be the same as the one who set the lock or to belongs to the administrator group,
1241     * otherwise an exception will be throw.
1242     * <p>
1243     * If the document was not locked, does nothing.
1244     * <p>
1245     * Returns the previous lock info.
1246     *
1247     * @param docRef the document to unlock
1248     * @return the removed lock info, or {@code null} if there was no lock
1249     * @since 5.4.2
1250     * @throws LockException if the document is locked by someone else
1251     */
1252    Lock removeLock(DocumentRef docRef) throws LockException;
1253
1254    /**
1255     * Applies default Read permissions on root JCR Document for the given user or group name. It can only be called by
1256     * Administrators.
1257     * <p>
1258     * Usage: As an administrator, you may want to add new users or groups. This method needs to be called to grand
1259     * default reading permissions on the root document of the repository for the newly created users/groups.
1260     */
1261    void applyDefaultPermissions(String userOrGroupName);
1262
1263    /**
1264     * Checks if the given document is dirty.
1265     *
1266     * @param doc the doc reference
1267     * @return true if dirty false otherwise
1268     * @deprecated since 5.4, use {@link #isCheckedOut} instead
1269     */
1270    @Deprecated
1271    boolean isDirty(DocumentRef doc);
1272
1273    /**
1274     * Publishes the document in a section overwriting any existing proxy to the same document. This is simmilar to
1275     * publishDocument(docToPublish, section, true);
1276     *
1277     * @return The proxy document that was created
1278     * @since 1.4.1 for the case where docToPublish is a proxy
1279     */
1280    DocumentModel publishDocument(DocumentModel docToPublish, DocumentModel section);
1281
1282    /**
1283     * Publishes the document in a section.
1284     *
1285     * @return The proxy document that was created
1286     */
1287    DocumentModel publishDocument(DocumentModel docToPublish, DocumentModel section, boolean overwriteExistingProxy);
1288
1289    /**
1290     * Finds the proxies for a document. If the parent is not null, the search will be limited to its direct children.
1291     * <p>
1292     * If the document is a version, then only proxies to that version will be looked up.
1293     * <p>
1294     * If the document is a proxy, then all similar proxies (pointing to any version of the same versionable) are
1295     * retrieved.
1296     *
1297     * @param docRef the target document for the proxies
1298     * @param folderRef the folder where proxies are located or {@code null}
1299     * @return the list of the proxies. An empty list is returned if no proxy are found
1300     * @since 1.4.1 for the case where docRef is a proxy
1301     */
1302    DocumentModelList getProxies(DocumentRef docRef, DocumentRef folderRef);
1303
1304    /**
1305     * Gets all proxy versions to document docRef inside folder folderRef.
1306     * <p>
1307     * Intended to be used by UI clients to display information about proxies in sections.
1308     *
1309     * @param docRef the target document for the proxies
1310     * @param folderRef the folder where proxies are located
1311     * @return an array of the proxy versions, with an empty string being used for a live proxy. {@code null} is
1312     *         returned if no proxies are found the specified folder
1313     * @deprecated since 5.4, use {@link #getProxies} instead
1314     */
1315    @Deprecated
1316    String[] getProxyVersions(DocumentRef docRef, DocumentRef folderRef);
1317
1318    /**
1319     * Returns the type of his parent SuperSpace (workspace, section, etc.). SuperSpace is qualified by the SuperSpace
1320     * facet.
1321     */
1322    String getSuperParentType(DocumentModel doc);
1323
1324    /**
1325     * Returns the parent SuperSpace (workspace, section, etc.). SuperSpace is qualified by the SuperSpace facet.
1326     *
1327     * @return DocumentModel of SuperSpace
1328     */
1329    DocumentModel getSuperSpace(DocumentModel doc);
1330
1331    /**
1332     * Returns the repository name against which this core session is bound.
1333     *
1334     * @return the repository name used currently used as an identifier
1335     */
1336    String getRepositoryName();
1337
1338    /**
1339     * Gets system property of the specified type for the document ref.
1340     */
1341    <T extends Serializable> T getDocumentSystemProp(DocumentRef ref, String systemProperty, Class<T> type);
1342
1343    /**
1344     * Sets given value as a system property.
1345     */
1346    <T extends Serializable> void setDocumentSystemProp(DocumentRef ref, String systemProperty, T value);
1347
1348    /**
1349     * Given a parent document, order the source child before the destination child. The source and destination must be
1350     * name of child documents of the given parent document. (a document name can be retrieved using
1351     * <code>docModel.getName()</code>) To place the source document at the end of the children list use a null
1352     * destination node.
1353     *
1354     * @param parent the parent document
1355     * @param src the document to be moved (ordered)
1356     * @param dest the document before which the reordered document will be placed If null the source document will be
1357     *            placed at the end of the children list
1358     */
1359    void orderBefore(DocumentRef parent, String src, String dest);
1360
1361    /**
1362     * Internal method - it is used internally by {@link DocumentModel#refresh()}
1363     * <p>
1364     * Get fresh data from a document given a description of what kind of data should be refetched.
1365     * <p>
1366     * The refresh information is specified using a bit mask. See {@link DocumentModel} for all accepted flags.
1367     * <p>
1368     * When the flag {@link DocumentModel#REFRESH_CONTENT_IF_LOADED} is specified a third argument must be passed
1369     * representing the schema names for document parts to refresh. This argument is ignored if the flag is not
1370     * specified or no schema names are provided
1371     *
1372     * @param ref the document reference
1373     * @param refreshFlags refresh flags as defined in {@link DocumentModel}
1374     * @param schemas the schema names if a partial content refresh is required
1375     * @return a DocumentModelRefresh object
1376     */
1377    DocumentModelRefresh refreshDocument(DocumentRef ref, int refreshFlags, String[] schemas);
1378
1379    /**
1380     * Provides the full list of all permissions or groups of permissions that contain the given one (inclusive). It
1381     * makes the method {@link org.nuxeo.ecm.core.security.SecurityService#getPermissionsToCheck} available remote.
1382     *
1383     * @return the list, as an array of strings.
1384     */
1385    String[] getPermissionsToCheck(String permission);
1386
1387    /**
1388     * Find the first parent with the given {@code facet} and adapt it on the {@code adapterClass}.
1389     * <p>
1390     * This method does not check the permissions on the document to be adapted of this {@code CoreSession}'s
1391     * {@code Principal}, and so the adapter must not need other schemas from the {@code DocumentModel} except the
1392     * schemas related to the given facet.
1393     *
1394     * @return the first parent with the given {@code facet} adapted, or {@code null} if no parent found or the document
1395     *         does not support the given {@code adapterClass}.
1396     * @since 5.4.2
1397     */
1398    <T extends DetachedAdapter> T adaptFirstMatchingDocumentWithFacet(DocumentRef docRef, String facet,
1399            Class<T> adapterClass);
1400
1401    /**
1402     * Gets the fulltext extracted from the binary fields.
1403     *
1404     * @param ref the document reference
1405     * @return the fulltext map or {@code null} if not supported.
1406     * @since 5.9.3
1407     */
1408    Map<String, String> getBinaryFulltext(DocumentRef ref);
1409
1410    /** @since 8.2 */
1411    enum CopyOption {
1412
1413        RESET_LIFE_CYCLE,
1414
1415        RESET_CREATOR;
1416
1417        public static boolean isResetLifeCycle(CopyOption... options) {
1418            return Arrays.asList(options).contains(RESET_LIFE_CYCLE);
1419        }
1420
1421        public static boolean isResetCreator(CopyOption... options) {
1422            return Arrays.asList(options).contains(RESET_CREATOR);
1423        }
1424
1425    }
1426
1427}