Search in sources :

Example 51 with XWikiException

use of com.xpn.xwiki.XWikiException in project xwiki-platform by xwiki.

the class FilesystemAttachmentStore method loadAttachmentContent.

@Override
public void loadAttachmentContent(final XWikiAttachment attachment, final XWikiContext context, final boolean bTransaction) throws XWikiException {
    final File attachFile = this.fileTools.getAttachmentFileProvider(attachment.getReference()).getAttachmentContentFile();
    if (!attachFile.exists()) {
        throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_FILENOTFOUND, "The attachment could not be found in the filesystem attachment store (" + attachFile + ").\n");
    }
    FilesystemAttachmentContent content = new FilesystemAttachmentContent(attachFile);
    content.setContentDirty(false);
    attachment.setAttachment_content(content);
    attachment.setContentStore(FileSystemStoreUtils.HINT);
}
Also used : FilesystemAttachmentContent(org.xwiki.store.legacy.doc.internal.FilesystemAttachmentContent) File(java.io.File) XWikiException(com.xpn.xwiki.XWikiException)

Example 52 with XWikiException

use of com.xpn.xwiki.XWikiException in project xwiki-platform by xwiki.

the class FilesystemAttachmentStore method deleteXWikiAttachment.

@Override
public void deleteXWikiAttachment(final XWikiAttachment attachment, final boolean parentUpdate, final XWikiContext context, final boolean bTransaction) throws XWikiException {
    final XWikiHibernateTransaction transaction = new XWikiHibernateTransaction(context);
    this.getAttachmentDeleteRunnable(attachment, parentUpdate, context).runIn(transaction);
    try {
        transaction.start();
    } catch (Exception e) {
        throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_UNKNOWN, "Exception while deleting attachment.", e);
    }
}
Also used : XWikiException(com.xpn.xwiki.XWikiException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) XWikiException(com.xpn.xwiki.XWikiException)

Example 53 with XWikiException

use of com.xpn.xwiki.XWikiException in project xwiki-platform by xwiki.

the class FilesystemAttachmentStore method saveAttachmentsContent.

/**
 * {@inheritDoc}
 * <p>
 * This implementation cannot operate in a larger transaction so it starts a new transaction no matter whether
 * bTransaction is true or false.
 * </p>
 *
 * @see com.xpn.xwiki.store.XWikiAttachmentStoreInterface#saveAttachmentsContent( List, XWikiDocument, boolean,
 *      XWikiContext, boolean)
 */
@Override
public void saveAttachmentsContent(final List<XWikiAttachment> attachments, final XWikiDocument doc, final boolean updateDocument, final XWikiContext context, final boolean bTransaction) throws XWikiException {
    if (attachments == null || attachments.isEmpty()) {
        return;
    }
    try {
        final XWikiHibernateTransaction transaction = new XWikiHibernateTransaction(context);
        for (XWikiAttachment attach : attachments) {
            this.getAttachmentContentSaveRunnable(attach, false, context).runIn(transaction);
        }
        // Save the parent document only once.
        if (updateDocument) {
            new TransactionRunnable<XWikiHibernateTransaction>() {

                @Override
                protected void onRun() throws Exception {
                    context.getWiki().getStore().saveXWikiDoc(doc, context, false);
                }
            }.runIn(transaction);
        }
        transaction.start();
    } catch (XWikiException e) {
        throw e;
    } catch (Exception e) {
        throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_SAVING_ATTACHMENT, "Exception while saving attachments", e);
    }
}
Also used : XWikiAttachment(com.xpn.xwiki.doc.XWikiAttachment) XWikiException(com.xpn.xwiki.XWikiException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) XWikiException(com.xpn.xwiki.XWikiException)

Example 54 with XWikiException

use of com.xpn.xwiki.XWikiException in project xwiki-platform by xwiki.

the class FilesystemRecycleBinContentStore method save.

@Override
public void save(XWikiDocument document, long index, boolean bTransaction) throws XWikiException {
    final XWikiContext xcontext = this.xcontextProvider.get();
    final XWikiHibernateTransaction transaction = new XWikiHibernateTransaction(xcontext);
    final File contentFile = this.fileTools.getDeletedDocumentFileProvider(document.getDocumentReferenceWithLocale(), index).getDeletedDocumentContentFile();
    FileSerializer serializer = new DeletedDocumentContentFileSerializer(document, StandardCharsets.UTF_8.name());
    new FileSaveTransactionRunnable(contentFile, fileTools.getTempFile(contentFile), fileTools.getBackupFile(contentFile), fileTools.getLockForFile(contentFile), serializer).runIn(transaction);
    try {
        transaction.start();
    } catch (Exception e) {
        throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_SAVING_ATTACHMENT, "Exception while saving deleted document content.", e);
    }
}
Also used : FileSerializer(org.xwiki.store.FileSerializer) XWikiContext(com.xpn.xwiki.XWikiContext) FileSaveTransactionRunnable(org.xwiki.store.FileSaveTransactionRunnable) File(java.io.File) XWikiException(com.xpn.xwiki.XWikiException) XWikiException(com.xpn.xwiki.XWikiException)

Example 55 with XWikiException

use of com.xpn.xwiki.XWikiException in project xwiki-platform by xwiki.

the class DefaultWikiUserManager method getMembersGroupDocument.

private XWikiDocument getMembersGroupDocument(String wikiId) throws WikiUserManagerException {
    // Reference to the document
    DocumentReference memberGroupReference = new DocumentReference(wikiId, XWiki.SYSTEM_SPACE, "XWikiAllGroup");
    // Get the document
    try {
        XWikiContext xcontext = xcontextProvider.get();
        XWiki xwiki = xcontext.getWiki();
        return xwiki.getDocument(memberGroupReference, xcontext);
    } catch (XWikiException e) {
        throw new WikiUserManagerException(String.format("Fail to load the member group document [%s].", memberGroupReference.toString()), e);
    }
}
Also used : WikiUserManagerException(org.xwiki.wiki.user.WikiUserManagerException) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) DocumentReference(org.xwiki.model.reference.DocumentReference) XWikiException(com.xpn.xwiki.XWikiException)

Aggregations

XWikiException (com.xpn.xwiki.XWikiException)442 XWikiContext (com.xpn.xwiki.XWikiContext)156 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)147 DocumentReference (org.xwiki.model.reference.DocumentReference)98 BaseObject (com.xpn.xwiki.objects.BaseObject)88 IOException (java.io.IOException)57 QueryException (org.xwiki.query.QueryException)57 ArrayList (java.util.ArrayList)56 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)51 XWiki (com.xpn.xwiki.XWiki)48 XWikiRestException (org.xwiki.rest.XWikiRestException)44 Session (org.hibernate.Session)42 Document (com.xpn.xwiki.api.Document)38 InitializationException (org.xwiki.component.phase.InitializationException)36 WebApplicationException (javax.ws.rs.WebApplicationException)32 SQLException (java.sql.SQLException)31 ObjectNotFoundException (org.hibernate.ObjectNotFoundException)30 MigrationRequiredException (com.xpn.xwiki.store.migration.MigrationRequiredException)29 UnexpectedException (org.xwiki.store.UnexpectedException)29 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)25