Search in sources :

Example 1 with WikiProvisioningEvent

use of org.xwiki.bridge.event.WikiProvisioningEvent 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 WikiProvisioningEvent

use of org.xwiki.bridge.event.WikiProvisioningEvent in project xwiki-platform by xwiki.

the class ProvisionWikiStepTest method executeWhenSourceIsExtension.

@Test
public void executeWhenSourceIsExtension() throws Exception {
    WikiCreationRequest request = new WikiCreationRequest();
    request.setWikiId("wikiId");
    request.setWikiSource(WikiSource.EXTENSION);
    ExtensionId extensionId = new ExtensionId("id", "version");
    request.setExtensionId(extensionId);
    // Test
    mocker.getComponentUnderTest().execute(request);
    // Verify
    verify(extensionInstaller).installExtension(eq("wikiId"), eq(extensionId));
    verify(observationManager).notify(eq(new WikiProvisioningEvent("wikiId")), eq("wikiId"), eq(xcontext));
    verify(observationManager).notify(eq(new WikiProvisionedEvent("wikiId")), eq("wikiId"), eq(xcontext));
    verifyZeroInteractions(wikiCopier);
}
Also used : WikiProvisionedEvent(org.xwiki.bridge.event.WikiProvisionedEvent) WikiProvisioningEvent(org.xwiki.bridge.event.WikiProvisioningEvent) WikiCreationRequest(org.xwiki.platform.wiki.creationjob.WikiCreationRequest) ExtensionId(org.xwiki.extension.ExtensionId) Test(org.junit.Test)

Example 3 with WikiProvisioningEvent

use of org.xwiki.bridge.event.WikiProvisioningEvent in project xwiki-platform by xwiki.

the class ProvisionWikiStepTest method executeWhenSourceIsTemplate.

@Test
public void executeWhenSourceIsTemplate() throws Exception {
    WikiCreationRequest request = new WikiCreationRequest();
    request.setWikiId("wikiId");
    request.setWikiSource(WikiSource.TEMPLATE);
    request.setTemplateId("template");
    // Test
    mocker.getComponentUnderTest().execute(request);
    // Verify
    verify(wikiCopier).copyDocuments(eq("template"), eq("wikiId"), eq(false));
    verify(observationManager).notify(eq(new WikiProvisioningEvent("wikiId")), eq("wikiId"), eq(xcontext));
    verify(observationManager).notify(eq(new WikiCopiedEvent("template", "wikiId")), eq("template"), eq(xcontext));
    verify(observationManager).notify(eq(new WikiProvisionedEvent("wikiId")), eq("wikiId"), eq(xcontext));
    verifyZeroInteractions(extensionInstaller);
}
Also used : WikiCopiedEvent(org.xwiki.bridge.event.WikiCopiedEvent) WikiProvisionedEvent(org.xwiki.bridge.event.WikiProvisionedEvent) WikiProvisioningEvent(org.xwiki.bridge.event.WikiProvisioningEvent) WikiCreationRequest(org.xwiki.platform.wiki.creationjob.WikiCreationRequest) Test(org.junit.Test)

Example 4 with WikiProvisioningEvent

use of org.xwiki.bridge.event.WikiProvisioningEvent 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

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