Search in sources :

Example 1 with DeletedAttachmentContent

use of com.xpn.xwiki.doc.DeletedAttachmentContent in project xwiki-platform by xwiki.

the class HibernateAttachmentRecycleBinStore method createDeletedAttachment.

private DeletedAttachment createDeletedAttachment(XWikiAttachment attachment, String deleter, Date date, AttachmentRecycleBinContentStore contentStore) throws XWikiException {
    DeletedAttachment trashdoc;
    String storeType = null;
    DeletedAttachmentContent deletedDocumentContent = null;
    if (contentStore != null) {
        storeType = contentStore.getHint();
    } else {
        deletedDocumentContent = new HibernateDeletedAttachmentContent(attachment);
    }
    trashdoc = new DeletedAttachment(attachment.getDocId(), attachment.getDoc().getFullName(), attachment.getFilename(), storeType, deleter, date, deletedDocumentContent);
    return trashdoc;
}
Also used : DeletedAttachmentContent(com.xpn.xwiki.doc.DeletedAttachmentContent) HibernateDeletedAttachmentContent(com.xpn.xwiki.internal.store.hibernate.HibernateDeletedAttachmentContent) DeletedAttachment(com.xpn.xwiki.doc.DeletedAttachment) HibernateDeletedAttachmentContent(com.xpn.xwiki.internal.store.hibernate.HibernateDeletedAttachmentContent)

Example 2 with DeletedAttachmentContent

use of com.xpn.xwiki.doc.DeletedAttachmentContent 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

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