use of org.xwiki.job.Job in project xwiki-platform by xwiki.
the class JobScriptService method getJobStatus.
/**
* @param jobId the job id
* @return the status of the specified job, {@code null} if the status cannot be found
*/
public JobStatus getJobStatus(List<String> jobId) {
JobStatus jobStatus;
Job job = this.jobExecutor.getJob(jobId);
if (job == null) {
jobStatus = this.jobStore.getJobStatus(jobId);
} else {
jobStatus = job.getStatus();
}
if (jobStatus != null && !this.authorization.hasAccess(Right.PROGRAM)) {
jobStatus = safe(jobStatus);
}
return jobStatus;
}
use of org.xwiki.job.Job in project xwiki-platform by xwiki.
the class JobScriptService method getCurrentJobStatus.
/**
* Get the status of the currently executing job in the specified group job, if any.
*
* @param path specifies the job group where to look for a running job
* @return status of the currently executing job in the specified group, or {@code null} if no job is being executed
*/
public JobStatus getCurrentJobStatus(Collection<String> path) {
Job job = this.jobExecutor.getCurrentJob(new JobGroupPath(path));
JobStatus jobStatus = null;
if (job != null) {
jobStatus = job.getStatus();
if (!this.authorization.hasAccess(Right.PROGRAM)) {
jobStatus = safe(jobStatus);
}
}
return jobStatus;
}
use of org.xwiki.job.Job in project xwiki-platform by xwiki.
the class RefactoringScriptServiceTest method move.
@Test
public void move() throws Exception {
SpaceReference source = new SpaceReference("Space", new WikiReference("math"));
WikiReference destination = new WikiReference("code");
Job job = mock(Job.class);
ArgumentCaptor<MoveRequest> request = ArgumentCaptor.forClass(MoveRequest.class);
when(this.jobExecutor.execute(eq(RefactoringJobs.MOVE), request.capture())).thenReturn(job);
assertSame(job, getService().move(source, destination));
assertEquals(Arrays.asList(source), request.getValue().getEntityReferences());
assertEquals(destination, request.getValue().getDestination());
assertEquals(Arrays.asList(RefactoringJobs.GROUP, "move"), request.getValue().getId().subList(0, 2));
assertEquals(RefactoringJobs.MOVE, request.getValue().getJobType());
assertEquals(this.userReference, request.getValue().getUserReference());
assertEquals(false, request.getValue().isDeep());
assertEquals(true, request.getValue().isDeleteSource());
assertEquals(true, request.getValue().isUpdateLinks());
assertEquals(true, request.getValue().isAutoRedirect());
assertEquals(false, request.getValue().isInteractive());
assertEquals(true, request.getValue().isCheckRights());
}
use of org.xwiki.job.Job in project xwiki-platform by xwiki.
the class ExtensionHistoryScriptServiceTest method replayWithPR.
@Test
public void replayWithPR() throws Exception {
InstallRequest installRequest = new InstallRequest();
installRequest.addNamespace("wiki:drafts");
installRequest.setProperty("user.reference", new DocumentReference("drafts", "Users", "Alice"));
ExtensionJobHistoryRecord install = new ExtensionJobHistoryRecord("install", installRequest, null, null, null);
List<ExtensionJobHistoryRecord> records = Arrays.asList(install);
when(this.xcontext.getWikiId()).thenReturn("dev");
when(this.xcontext.getAction()).thenReturn("foo");
when(this.documentAccessBridge.getCurrentUserReference()).thenReturn(new DocumentReference("dev", "Users", "Bob"));
when(this.authorization.hasAccess(Right.ADMIN, new WikiReference("dev"))).thenReturn(true);
when(this.authorization.hasAccess(Right.PROGRAM)).thenReturn(true);
Job replayJob = mock(Job.class);
ArgumentCaptor<ReplayRequest> requestCaptor = ArgumentCaptor.forClass(ReplayRequest.class);
when(jobExecutor.execute(eq(ReplayJob.JOB_TYPE), requestCaptor.capture())).thenReturn(replayJob);
assertSame(replayJob, this.mocker.getComponentUnderTest().replay(records));
ReplayRequest request = requestCaptor.getValue();
assertTrue(StringUtils.join(request.getId(), '/').startsWith("extension/history/"));
assertTrue(request.isInteractive());
assertEquals(Arrays.asList(install), request.getRecords());
assertEquals(this.xcontext.getWikiId(), request.getProperty("context.wiki"));
assertEquals(this.xcontext.getAction(), request.getProperty("context.action"));
assertEquals(this.documentAccessBridge.getCurrentUserReference(), request.getProperty("user.reference"));
assertEquals(Arrays.asList("wiki:drafts"), install.getRequest().getNamespaces());
assertEquals(new DocumentReference("drafts", "Users", "Alice"), install.getRequest().getProperty("user.reference"));
}
use of org.xwiki.job.Job in project xwiki-platform by xwiki.
the class XWiki method getCurrentInitializerJobStatus.
/**
* @return the status of the job initializing the instance or the current wiki
* @since 8.4RC1
*/
public JobStatus getCurrentInitializerJobStatus() {
// Get XWiki initializer job
JobStatus jobStatus = getJobStatus();
if (jobStatus == null) {
return null;
}
// The XWiki initialization is not done yet
if (jobStatus.getState() != State.FINISHED) {
return jobStatus;
}
// If XWiki initialization did not failed
if (this.xwiki != null) {
// Get current wiki initializer job
Job wikiJob = this.xwiki.getWikiInitializerJob(this.context.getWikiId());
jobStatus = wikiJob != null ? wikiJob.getStatus() : null;
}
return jobStatus;
}
Aggregations