use of org.xwiki.bridge.event.WikiProvisioningFailedEvent 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.bridge.event.WikiProvisioningFailedEvent in project xwiki-platform by xwiki.
the class ProvisionWikiStep method execute.
@Override
public void execute(WikiCreationRequest request) throws WikiCreationException {
try {
if (request.getWikiSource() == null) {
// No source is defined, we let the wiki empty and DW will do the rest
return;
}
switch(request.getWikiSource()) {
case EXTENSION:
sendWikiProvisioningEvent(request);
extensionInstaller.installExtension(request.getWikiId(), request.getExtensionId());
sendWikiProvisionedEvent(request);
break;
case TEMPLATE:
sendWikiProvisioningEvent(request);
wikiCopier.copyDocuments(request.getTemplateId(), request.getWikiId(), false);
observationManager.notify(new WikiCopiedEvent(request.getTemplateId(), request.getWikiId()), request.getTemplateId(), xcontextProvider.get());
sendWikiProvisionedEvent(request);
break;
default:
// No source is defined, we let the wiki empty and DW will do the rest
break;
}
} catch (WikiManagerException | WikiCreationException e) {
observationManager.notify(new WikiProvisioningFailedEvent(request.getWikiId()), request.getWikiId(), xcontextProvider.get());
throw new WikiCreationException(String.format("Failed to provision the wiki [%s].", request.getWikiId()), e);
}
}
use of org.xwiki.bridge.event.WikiProvisioningFailedEvent in project xwiki-platform by xwiki.
the class ProvisionWikiStepTest method executeWhenException.
@Test
public void executeWhenException() throws Exception {
WikiCreationRequest request = new WikiCreationRequest();
request.setWikiId("wikiId");
request.setWikiSource(WikiSource.EXTENSION);
ExtensionId extensionId = new ExtensionId("id", "version");
request.setExtensionId(extensionId);
// Mocks
WikiCreationException exception = new WikiCreationException("Exception in ExtensionInstaller");
doThrow(exception).when(extensionInstaller).installExtension("wikiId", extensionId);
// Test
WikiCreationException caughtException = null;
try {
mocker.getComponentUnderTest().execute(request);
} catch (WikiCreationException e) {
caughtException = e;
}
// Verify
assertNotNull(caughtException);
assertEquals("Failed to provision the wiki [wikiId].", caughtException.getMessage());
assertEquals(exception, caughtException.getCause());
verify(observationManager).notify(eq(new WikiProvisioningEvent("wikiId")), eq("wikiId"), eq(xcontext));
verify(observationManager).notify(eq(new WikiProvisioningFailedEvent("wikiId")), eq("wikiId"), eq(xcontext));
}
Aggregations