Search in sources :

Example 1 with WikiProvisionedEvent

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

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

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

Aggregations

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