Search in sources :

Example 1 with WikiProvisioningJobRequest

use of org.xwiki.wiki.provisioning.WikiProvisioningJobRequest in project xwiki-platform by xwiki.

the class DefaultWikiProvisioningJobExecutorTest method createAndExecuteJob.

@Test
public void createAndExecuteJob() throws Exception {
    // Mocks
    WikiProvisioningJob provisioningJob = mock(WikiProvisioningJob.class);
    mocker.registerComponent(Job.class, "wikiprovisioning.test", provisioningJob);
    ExecutionContextManager executionContextManager = mock(ExecutionContextManager.class);
    mocker.registerComponent(ExecutionContextManager.class, executionContextManager);
    Execution execution = mock(Execution.class);
    mocker.registerComponent(Execution.class, execution);
    DocumentReference user = new DocumentReference("xwiki", "XWiki", "User");
    when(xcontext.getUserReference()).thenReturn(user);
    // Execute
    WikiProvisioningJob job = mocker.getComponentUnderTest().createAndExecuteJob("wikiid", "wikiprovisioning.test", "templateid");
    // Verify
    // Id of the job.
    List<String> jobId = new ArrayList<String>();
    jobId.add("wiki");
    jobId.add("provisioning");
    jobId.add("wikiprovisioning.test");
    jobId.add("wikiid");
    verify(provisioningJob).initialize(eq(new WikiProvisioningJobRequest(jobId, "wikiid", "templateid", user)));
    Thread.sleep(100);
    verify(provisioningJob).run();
    // getJobs also works
    assertEquals(mocker.getComponentUnderTest().getJob(jobId), job);
}
Also used : Execution(org.xwiki.context.Execution) ExecutionContextManager(org.xwiki.context.ExecutionContextManager) ArrayList(java.util.ArrayList) WikiProvisioningJobRequest(org.xwiki.wiki.provisioning.WikiProvisioningJobRequest) DocumentReference(org.xwiki.model.reference.DocumentReference) WikiProvisioningJob(org.xwiki.wiki.provisioning.WikiProvisioningJob) Test(org.junit.Test)

Example 2 with WikiProvisioningJobRequest

use of org.xwiki.wiki.provisioning.WikiProvisioningJobRequest 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 3 with WikiProvisioningJobRequest

use of org.xwiki.wiki.provisioning.WikiProvisioningJobRequest in project xwiki-platform by xwiki.

the class DefaultWikiProvisioningJobExecutor method createAndExecuteJob.

@Override
public WikiProvisioningJob createAndExecuteJob(String wikiId, String provisioningJobName, Object parameter) throws WikiProvisioningJobException {
    try {
        // Get the context
        XWikiContext xcontext = xcontextProvider.get();
        // Create the job
        WikiProvisioningJob job = componentManager.getInstance(Job.class, provisioningJobName);
        // Id of the new job
        List<String> jobId = new ArrayList<String>();
        jobId.add("wiki");
        jobId.add("provisioning");
        jobId.add(provisioningJobName);
        jobId.add(wikiId);
        // Initialize it
        job.initialize(new WikiProvisioningJobRequest(jobId, wikiId, parameter, xcontext.getUserReference()));
        // Add it to the list of jobs
        jobs.put(jobId, job);
        // Pass it to the executor
        jobExecutor.execute(job);
        // Return the job
        return job;
    } catch (ComponentLookupException e) {
        throw new WikiProvisioningJobException(String.format("Failed to lookup provisioning job component for role [%s]", provisioningJobName), e);
    }
}
Also used : WikiProvisioningJobException(org.xwiki.wiki.provisioning.WikiProvisioningJobException) ArrayList(java.util.ArrayList) XWikiContext(com.xpn.xwiki.XWikiContext) WikiProvisioningJobRequest(org.xwiki.wiki.provisioning.WikiProvisioningJobRequest) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) WikiProvisioningJob(org.xwiki.wiki.provisioning.WikiProvisioningJob)

Aggregations

WikiProvisioningJobRequest (org.xwiki.wiki.provisioning.WikiProvisioningJobRequest)3 XWikiContext (com.xpn.xwiki.XWikiContext)2 ArrayList (java.util.ArrayList)2 WikiProvisioningJob (org.xwiki.wiki.provisioning.WikiProvisioningJob)2 Test (org.junit.Test)1 WikiCopiedEvent (org.xwiki.bridge.event.WikiCopiedEvent)1 WikiProvisionedEvent (org.xwiki.bridge.event.WikiProvisionedEvent)1 WikiProvisioningEvent (org.xwiki.bridge.event.WikiProvisioningEvent)1 WikiProvisioningFailedEvent (org.xwiki.bridge.event.WikiProvisioningFailedEvent)1 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1 Execution (org.xwiki.context.Execution)1 ExecutionContextManager (org.xwiki.context.ExecutionContextManager)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)1 WikiProvisioningJobException (org.xwiki.wiki.provisioning.WikiProvisioningJobException)1