@Override public boolean isTrashed() { if (hasSession()) { isTrashed = getSession().isTrashed(ref); } return isTrashed; }
/** * @param document the document to edit. * @param blobXPath XPath to the blob property * @return true if the document is immutable and the blob's mime type is supported, false otherwise. * @since 5.4 */ public boolean isLiveEditable(DocumentModel document, Blob blob) { // NXP-24034: testing new trash state needs to have an existing document in DB // NXP-14476: Testing trashed state is part of the "mutable_document" filter DocumentRef docRef = document.getRef(); if (!documentManager.exists(docRef) || documentManager.isTrashed(docRef)) { return false; } if (document.isImmutable()) { return false; } if (blob == null) { return false; } String mimetype = blob.getMimeType(); return isMimeTypeLiveEditable(mimetype); }
protected Set<DocumentRef> doUntrashDocument(DocumentModel doc, boolean processChildren) { CoreSession session = doc.getCoreSession(); DocumentRef docRef = doc.getRef(); DocumentModel docForEvent = doc; // move only non placeless document // currently we don't trash placeless document DocumentRef parentRef = doc.getParentRef(); if (!Boolean.TRUE.equals(doc.getContextData(DISABLE_TRASH_RENAMING)) && parentRef != null) { String newName = unmangleName(doc); if (!newName.equals(doc.getName())) { session.move(docRef, parentRef, newName); docForEvent = session.getDocument(docRef); docForEvent.copyContextData(doc); } } session.setDocumentSystemProp(docRef, SYSPROP_IS_TRASHED, Boolean.FALSE); notifyEvent(session, DOCUMENT_UNTRASHED, docForEvent); if (processChildren && session.hasChildren(doc.getRef())) { trashDescendants(doc, Boolean.FALSE); } Set<DocumentRef> docRefs = new HashSet<>(); docRefs.add(docRef); // now untrash the parent if needed if (parentRef != null && session.isTrashed(parentRef)) { DocumentModel parent = session.getDocument(parentRef); Set<DocumentRef> ancestorDocRefs = doUntrashDocument(parent, false); docRefs.addAll(ancestorDocRefs); } return docRefs; }
if (!documentManager.exists(docRef) || documentManager.isTrashed(docRef)) { return false;
@Override public void trashDocuments(List<DocumentModel> docs) { if (docs.isEmpty()) { return; } CoreSession session = docs.get(0).getCoreSession(); for (DocumentModel doc : docs) { DocumentRef docRef = doc.getRef(); if (session.getAllowedStateTransitions(docRef).contains(LifeCycleConstants.DELETE_TRANSITION) && !doc.isProxy()) { if (!session.canRemoveDocument(docRef)) { throw new DocumentSecurityException("User " + session.getPrincipal().getName() + " does not have the permission to remove the document " + doc.getId() + " (" + doc.getPath() + ")"); } trashDocument(session, doc); } else if (session.isTrashed(docRef)) { log.warn("Document " + doc.getId() + " of type " + doc.getType() + " is already in the trash, nothing to do"); return; } else { log.warn("Document " + doc.getId() + " of type " + doc.getType() + " in state " + doc.getCurrentLifeCycleState() + " does not support transition " + LifeCycleConstants.DELETE_TRANSITION + ", it will be deleted immediately"); session.removeDocument(docRef); } } session.save(); }
"User " + session.getPrincipal().getName() + " does not have the permission to remove the document " + doc.getId() + " (" + doc.getPath() + ")"); } else if (session.isTrashed(docRef)) { log.warn("Document " + doc.getId() + " of type " + doc.getType() + " is already in the trash, nothing to do");