001/* 002 * (C) Copyright 2006-2011 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 * Florent Guillaume 018 */ 019package org.nuxeo.ecm.core.trash; 020 021import java.security.Principal; 022import java.util.List; 023import java.util.Set; 024 025import org.nuxeo.common.utils.Path; 026import org.nuxeo.ecm.core.api.CoreSession; 027import org.nuxeo.ecm.core.api.DocumentModel; 028import org.nuxeo.ecm.core.api.DocumentModelList; 029import org.nuxeo.ecm.core.api.DocumentRef; 030 031/** 032 * Service containing the logic about deleting/purging/undeleting a document. 033 */ 034public interface TrashService { 035 036 /** 037 * Can a child of the folder be deleted? 038 * 039 * @param folder the folder 040 * @return {@code true} if the folder allows its children to be deleted 041 */ 042 boolean folderAllowsDelete(DocumentModel folder); 043 044 /** 045 * Is at least one doc deletable according to its container? 046 * 047 * @param docs the documents 048 * @return {@code true} if one doc is in a folder that allows its children to be deleted 049 */ 050 boolean checkDeletePermOnParents(List<DocumentModel> docs); 051 052 /** 053 * Is at least one doc deletable? 054 * 055 * @param docs the documents 056 * @param principal the current user (to check locks) 057 * @param checkProxies {@code true} to count proxies as non-deletable 058 * @return {@code true} if at least one doc is deletable 059 */ 060 boolean canDelete(List<DocumentModel> docs, Principal principal, boolean checkProxies); 061 062 /** 063 * Are all documents purgeable/undeletable? 064 * <p> 065 * Documents need to be in the deleted lifecycle state for this to be true, in addition to the standard permission 066 * checks. 067 * 068 * @param docs the documents 069 * @param principal the current user (to check locks) 070 * @return {@code true} if the documents are purgeable/undeletable 071 */ 072 boolean canPurgeOrUndelete(List<DocumentModel> docs, Principal principal); 073 074 /** 075 * Gets the trash info for a list of documents. 076 * 077 * @param docs the documents 078 * @param principal the current user (to check locks) 079 * @param checkProxies {@code true} to count proxies as non-deletable 080 * @param checkDeleted {@code true} if documents have to be in the deleted state to be considered (otherwise 081 * forbidden) 082 * @return the trash info 083 */ 084 TrashInfo getTrashInfo(List<DocumentModel> docs, Principal principal, boolean checkProxies, boolean checkDeleted); 085 086 /** 087 * Gets the closest document's ancestor above all the paths. 088 * <p> 089 * This is used to find what safe document to redirect to when deleting some. 090 * 091 * @param doc the document 092 * @param paths the paths 093 * @return the closer document above doc and above all the paths 094 */ 095 DocumentModel getAboveDocument(DocumentModel doc, Set<Path> paths); 096 097 /** 098 * Moves documents to the trash, or directly deletes them if their lifecycle does not allow trash use. 099 * <p> 100 * Do nothing if the document current state is deleted. 101 * <p> 102 * Placeless documents are deleted immediately. 103 * 104 * @param docs the documents to trash 105 */ 106 void trashDocuments(List<DocumentModel> docs); 107 108 /** 109 * Purges (completely deletes) documents . 110 * 111 * @param session the session 112 * @param docRefs the documents to purge 113 */ 114 void purgeDocuments(CoreSession session, List<DocumentRef> docRefs); 115 116 /** 117 * Undeletes documents (and ancestors if needed to make them visible). 118 * <p> 119 * Also fires async events to undelete the children. 120 * 121 * @param docs the documents to undelete 122 * @return the set of ancestors whose children have been undeleted (for UI notification) 123 */ 124 Set<DocumentRef> undeleteDocuments(List<DocumentModel> docs); 125 126 /** 127 * Get all documents from the trash of the current document. 128 * 129 * @since 7.1 130 * @param currentDoc The current/parent document of trash document. 131 * @return All documents in the trash of the current document. 132 */ 133 DocumentModelList getDocuments(DocumentModel currentDoc); 134 135 /** 136 * Mangles the name of a document to avoid collisions with non-trashed documents when it's in the trash. 137 * 138 * @param doc the document 139 * @return 140 * @since 7.3 141 */ 142 String mangleName(DocumentModel doc); 143 144 /** 145 * Unmangles the name of a document in the trash to find its un-trashed name. 146 * 147 * @param doc the trashed document 148 * @return the unmangled name 149 * @since 7.3 150 */ 151 String unmangleName(DocumentModel doc); 152 153}