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);
}
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);
}
}
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);
}
}
Aggregations