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);
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations