Search in sources :

Example 36 with Job

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;
}
Also used : JobStatus(org.xwiki.job.event.status.JobStatus) Job(org.xwiki.job.Job)

Example 37 with Job

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;
}
Also used : JobStatus(org.xwiki.job.event.status.JobStatus) JobGroupPath(org.xwiki.job.JobGroupPath) Job(org.xwiki.job.Job)

Example 38 with Job

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());
}
Also used : MoveRequest(org.xwiki.refactoring.job.MoveRequest) SpaceReference(org.xwiki.model.reference.SpaceReference) WikiReference(org.xwiki.model.reference.WikiReference) Job(org.xwiki.job.Job) Test(org.junit.Test)

Example 39 with Job

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"));
}
Also used : ExtensionJobHistoryRecord(org.xwiki.extension.job.history.ExtensionJobHistoryRecord) ReplayRequest(org.xwiki.extension.job.history.ReplayRequest) InstallRequest(org.xwiki.extension.job.InstallRequest) WikiReference(org.xwiki.model.reference.WikiReference) ReplayJob(org.xwiki.extension.job.history.internal.ReplayJob) Job(org.xwiki.job.Job) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 40 with Job

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;
}
Also used : JobStatus(org.xwiki.job.event.status.JobStatus) XWikiInitializerJobStatus(com.xpn.xwiki.internal.XWikiInitializerJobStatus) XWikiInitializerJob(com.xpn.xwiki.internal.XWikiInitializerJob) Job(org.xwiki.job.Job)

Aggregations

Job (org.xwiki.job.Job)41 Test (org.junit.Test)11 JobStatus (org.xwiki.job.event.status.JobStatus)10 AbstractExtensionJob (org.xwiki.extension.job.internal.AbstractExtensionJob)8 InstallJob (org.xwiki.extension.job.internal.InstallJob)8 UninstallJob (org.xwiki.extension.job.internal.UninstallJob)8 JobException (org.xwiki.job.JobException)8 DocumentReference (org.xwiki.model.reference.DocumentReference)8 InstallRequest (org.xwiki.extension.job.InstallRequest)7 UpgradePlanJob (org.xwiki.extension.job.internal.UpgradePlanJob)7 InstallPlanJob (org.xwiki.extension.job.internal.InstallPlanJob)6 UninstallPlanJob (org.xwiki.extension.job.internal.UninstallPlanJob)6 XWikiException (com.xpn.xwiki.XWikiException)5 LogEvent (org.xwiki.logging.event.LogEvent)5 InstallException (org.xwiki.extension.InstallException)4 UninstallException (org.xwiki.extension.UninstallException)4 XarInstalledExtension (org.xwiki.extension.xar.internal.repository.XarInstalledExtension)4 EntityReference (org.xwiki.model.reference.EntityReference)4 WikiReference (org.xwiki.model.reference.WikiReference)4 IOException (java.io.IOException)3