use of org.xwiki.wiki.manager.WikiManagerException in project xwiki-platform by xwiki.
the class DefaultWikiTemplateManager method createWikiFromTemplate.
@Override
public WikiProvisioningJob createWikiFromTemplate(String newWikiId, String newWikiAlias, String templateId, String ownerId, boolean failOnExist) throws WikiTemplateManagerException {
try {
// First, create the new wiki
WikiDescriptor descriptor = wikiManager.create(newWikiId, newWikiAlias, failOnExist);
// Set the owner
descriptor.setOwnerId(ownerId);
wikiDescriptorManager.saveDescriptor(descriptor);
// finally, we apply the template to the new wiki
return applyTemplate(newWikiId, templateId);
} catch (WikiManagerException e) {
throw new WikiTemplateManagerException(e.getMessage(), e);
}
}
use of org.xwiki.wiki.manager.WikiManagerException in project xwiki-platform by xwiki.
the class TemplateWikiProvisioningJob method runInternal.
@Override
protected void runInternal() throws Exception {
WikiProvisioningJobRequest request = getRequest();
if (!(request.getProvisioningJobParameter() instanceof String)) {
throw new Exception("The provisioning parameter is not a valid String.");
}
XWikiContext xcontext = xcontextProvider.get();
String wikiId = request.getWikiId();
String templateId = (String) request.getProvisioningJobParameter();
// Set the user actually doing the action in the context
xcontext.setUserReference(request.getProvisioningUser());
try {
observationManager.notify(new WikiProvisioningEvent(wikiId), wikiId, xcontext);
wikiCopier.copyDocuments(templateId, wikiId, false);
observationManager.notify(new WikiProvisionedEvent(wikiId), wikiId, xcontext);
observationManager.notify(new WikiCopiedEvent(templateId, wikiId), templateId, xcontext);
} catch (WikiManagerException e) {
logger.error("Failed to provision wiki [{}] from template [{}].", wikiId, templateId, e);
observationManager.notify(new WikiProvisioningFailedEvent(wikiId), wikiId, xcontext);
}
}
use of org.xwiki.wiki.manager.WikiManagerException in project xwiki-platform by xwiki.
the class WikiTemplatePropertyGroupProvider method save.
@Override
public void save(WikiPropertyGroup group, String wikiId) throws WikiPropertyGroupException {
XWikiContext context = xcontextProvider.get();
XWiki xwiki = context.getWiki();
WikiTemplatePropertyGroup templateGroup = (WikiTemplatePropertyGroup) group;
try {
XWikiDocument descriptorDocument = wikiDescriptorDocumentHelper.getDocumentFromWikiId(wikiId);
BaseObject object = descriptorDocument.getXObject(WikiTemplateClassDocumentInitializer.SERVER_CLASS, true, context);
object.setIntValue(WikiTemplateClassDocumentInitializer.FIELD_ISWIKITEMPLATE, templateGroup.isTemplate() ? 1 : 0);
// The document must have a creator
if (descriptorDocument.getCreatorReference() == null) {
descriptorDocument.setCreatorReference(context.getUserReference());
}
// The document must have an author
if (descriptorDocument.getAuthorReference() == null) {
descriptorDocument.setAuthorReference(context.getUserReference());
}
xwiki.saveDocument(descriptorDocument, String.format("Changed property group [%s].", GROUP_NAME), context);
} catch (WikiManagerException e) {
throw new WikiPropertyGroupException(String.format(ERROR_MESSAGE_NO_DESCRIPTOR_DOCUMENT, wikiId), e);
} catch (XWikiException e) {
throw new WikiPropertyGroupException("Unable to save descriptor document.", e);
}
}
use of org.xwiki.wiki.manager.WikiManagerException in project xwiki-platform by xwiki.
the class WikiTemplateManagerScriptTest method setTemplateErrorWithDescriptorManager.
@Test
public void setTemplateErrorWithDescriptorManager() throws Exception {
Exception exception = new WikiManagerException("error in getById");
when(wikiDescriptorManager.getById("wikiId")).thenThrow(exception);
boolean result = mocker.getComponentUnderTest().setTemplate("wikiId", true);
assertFalse(result);
assertEquals(exception, mocker.getComponentUnderTest().getLastError());
verify(mocker.getMockedLogger()).error("Failed to get the descriptor of the wiki [wikiId].", exception);
}
use of org.xwiki.wiki.manager.WikiManagerException in project xwiki-platform by xwiki.
the class DefaultWikiDeleter method delete.
@Override
public void delete(String wikiId) throws WikiManagerException {
XWikiContext context = xcontextProvider.get();
XWiki xwiki = context.getWiki();
// Check if we try to delete the main wiki
if (wikiId.equals(wikiDescriptorManager.getMainWikiId())) {
throw new WikiManagerException("It's not allowed to delete the main wiki!");
}
// Delete the database
try {
xwiki.getStore().deleteWiki(wikiId, context);
} catch (XWikiException e) {
throw new WikiManagerException(String.format("Error deleting the database [%s]", wikiId), e);
}
// Delete the descriptor document
try {
XWikiDocument descriptorDocument = descriptorDocumentHelper.getDocumentFromWikiId(wikiId);
xwiki.deleteDocument(descriptorDocument, context);
} catch (XWikiException e) {
throw new WikiManagerException(String.format("Error deleting the Wiki Descriptor Document for database [%s]", wikiId), e);
}
}
Aggregations