Search in sources :

Example 1 with AttachmentRecycleBinContentStore

use of com.xpn.xwiki.store.AttachmentRecycleBinContentStore in project xwiki-platform by xwiki.

the class HibernateAttachmentRecycleBinStore method resolveDeletedAttachmentContent.

private DeletedAttachment resolveDeletedAttachmentContent(DeletedAttachment deletedAttachment, boolean bTransaction, boolean failIfNoContent) throws XWikiException {
    AttachmentRecycleBinContentStore contentStore = getAttachmentRecycleBinContentStore(deletedAttachment.getContentStore());
    if (contentStore != null) {
        AttachmentReference reference = deletedAttachment.getAttachmentReference();
        DeletedAttachmentContent content = contentStore.get(reference, deletedAttachment.getDate(), deletedAttachment.getId(), bTransaction);
        if (content == null) {
            if (failIfNoContent) {
                throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_UNKNOWN, "Can't find any content for deleted attachment [" + reference + "] with id [" + deletedAttachment.getId() + "]");
            } else {
                this.logger.warn("Can't find any content for deleted attachment [{}] with id [{}]", reference, deletedAttachment.getId());
            }
        }
        try {
            FieldUtils.writeDeclaredField(deletedAttachment, "content", content, true);
        } catch (IllegalAccessException e) {
            throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_UNKNOWN, "Failed to set deleted document content", e);
        }
    }
    return deletedAttachment;
}
Also used : AttachmentReference(org.xwiki.model.reference.AttachmentReference) DeletedAttachmentContent(com.xpn.xwiki.doc.DeletedAttachmentContent) HibernateDeletedAttachmentContent(com.xpn.xwiki.internal.store.hibernate.HibernateDeletedAttachmentContent) AttachmentRecycleBinContentStore(com.xpn.xwiki.store.AttachmentRecycleBinContentStore) XWikiException(com.xpn.xwiki.XWikiException)

Aggregations

XWikiException (com.xpn.xwiki.XWikiException)1 DeletedAttachmentContent (com.xpn.xwiki.doc.DeletedAttachmentContent)1 HibernateDeletedAttachmentContent (com.xpn.xwiki.internal.store.hibernate.HibernateDeletedAttachmentContent)1 AttachmentRecycleBinContentStore (com.xpn.xwiki.store.AttachmentRecycleBinContentStore)1 AttachmentReference (org.xwiki.model.reference.AttachmentReference)1