use of org.xwiki.wiki.provisioning.WikiProvisioningJob 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.WikiProvisioningJob in project xwiki-platform by xwiki.
the class WikiTemplateManagerScriptTest method getWikiProvisioningJobStatus.
@Test
public void getWikiProvisioningJobStatus() throws Exception {
WikiProvisioningJob job = mock(WikiProvisioningJob.class);
when(wikiTemplateManager.getWikiProvisioningJob(anyList())).thenReturn(job);
JobStatus status = mock(JobStatus.class);
when(job.getStatus()).thenReturn(status);
List<String> jobId = new ArrayList<String>();
JobStatus result = mocker.getComponentUnderTest().getWikiProvisioningJobStatus(jobId);
assertEquals(status, result);
}
use of org.xwiki.wiki.provisioning.WikiProvisioningJob in project xwiki-platform by xwiki.
the class DefaultWikiProvisioningJobExecutor method initialize.
@Override
public void initialize() throws InitializationException {
this.jobs = new HashMap<List<String>, WikiProvisioningJob>();
// Setup jobs thread
BasicThreadFactory factory = new BasicThreadFactory.Builder().namingPattern("XWiki provisioning thread").daemon(true).priority(Thread.MIN_PRIORITY).build();
this.jobExecutor = Executors.newCachedThreadPool(factory);
}
use of org.xwiki.wiki.provisioning.WikiProvisioningJob 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);
}
}
use of org.xwiki.wiki.provisioning.WikiProvisioningJob in project xwiki-platform by xwiki.
the class DefaultWikiManagerREST method createWiki.
@Override
@POST
public Response createWiki(@QueryParam("template") String template, Wiki wiki) throws XWikiRestException {
XWikiContext xcontext = getXWikiContext();
WikiDescriptor descriptor = null;
try {
// Create the wiki
descriptor = wikiManager.create(wiki.getId(), wiki.getId(), true);
// Change the descriptor
if (wiki.getOwner() != null) {
descriptor.setOwnerId(wiki.getOwner());
} else {
descriptor.setOwnerId(entityReferenceSerializer.serialize(xcontext.getUserReference()));
}
descriptor.setPrettyName(wiki.getName());
descriptor.setDescription(wiki.getDescription());
// Save the descriptor
wikiDescriptorManager.saveDescriptor(descriptor);
// Apply a template (if needed)
if (template != null) {
WikiProvisioningJob job = wikiTemplateManager.applyTemplate(descriptor.getId(), template);
job.join();
}
// Build the response
Wiki result = createWiki(objectFactory, uriInfo.getBaseUri(), wiki.getId(), wiki.getOwner(), wiki.getDescription());
// Add a link to the WebHome of the newly created wiki.
Link home = objectFactory.createLink();
home.setRel(Relations.HOME);
home.setHref(xcontext.getWiki().getURL(descriptor.getMainPageReference(), "view", xcontext));
result.getLinks().add(home);
// Return the final response
return Response.created(UriBuilder.fromUri(uriInfo.getBaseUri()).path(WikiResource.class).build(wiki.getId())).entity(result).build();
} catch (Exception e) {
throw new XWikiRestException(e);
}
}
Aggregations