Search in sources :

Example 1 with WikiProvisioningFailedEvent

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);
    }
}
Also used : WikiProvisioningFailedEvent(org.xwiki.bridge.event.WikiProvisioningFailedEvent) WikiProvisionedEvent(org.xwiki.bridge.event.WikiProvisionedEvent) WikiCopiedEvent(org.xwiki.bridge.event.WikiCopiedEvent) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiProvisioningEvent(org.xwiki.bridge.event.WikiProvisioningEvent) WikiProvisioningJobRequest(org.xwiki.wiki.provisioning.WikiProvisioningJobRequest) XWikiContext(com.xpn.xwiki.XWikiContext) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException)

Example 2 with WikiProvisioningFailedEvent

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);
    }
}
Also used : WikiProvisioningFailedEvent(org.xwiki.bridge.event.WikiProvisioningFailedEvent) WikiCopiedEvent(org.xwiki.bridge.event.WikiCopiedEvent) WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException)

Example 3 with WikiProvisioningFailedEvent

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));
}
Also used : WikiProvisioningFailedEvent(org.xwiki.bridge.event.WikiProvisioningFailedEvent) WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) WikiProvisioningEvent(org.xwiki.bridge.event.WikiProvisioningEvent) WikiCreationRequest(org.xwiki.platform.wiki.creationjob.WikiCreationRequest) ExtensionId(org.xwiki.extension.ExtensionId) Test(org.junit.Test)

Aggregations

WikiProvisioningFailedEvent (org.xwiki.bridge.event.WikiProvisioningFailedEvent)3 WikiCopiedEvent (org.xwiki.bridge.event.WikiCopiedEvent)2 WikiProvisioningEvent (org.xwiki.bridge.event.WikiProvisioningEvent)2 WikiCreationException (org.xwiki.platform.wiki.creationjob.WikiCreationException)2 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 Test (org.junit.Test)1 WikiProvisionedEvent (org.xwiki.bridge.event.WikiProvisionedEvent)1 ExtensionId (org.xwiki.extension.ExtensionId)1 WikiCreationRequest (org.xwiki.platform.wiki.creationjob.WikiCreationRequest)1 WikiProvisioningJobRequest (org.xwiki.wiki.provisioning.WikiProvisioningJobRequest)1