Search in sources :

Example 1 with JobException

use of org.xwiki.job.JobException in project xwiki-platform by xwiki.

the class DeleteAction method startDeleteJob.

private Job startDeleteJob(EntityReference entityReference, XWikiContext context) throws XWikiException {
    RefactoringScriptService refactoring = (RefactoringScriptService) Utils.getComponent(ScriptService.class, "refactoring");
    EntityRequest deleteRequest = refactoring.createDeleteRequest(Arrays.asList(entityReference));
    deleteRequest.setInteractive(isAsync(context.getRequest()));
    try {
        JobExecutor jobExecutor = Utils.getComponent(JobExecutor.class);
        return jobExecutor.execute(RefactoringJobs.DELETE, deleteRequest);
    } catch (JobException e) {
        throw new XWikiException(String.format("Failed to schedule the delete job for [%s]", entityReference), e);
    }
}
Also used : RefactoringScriptService(org.xwiki.refactoring.script.RefactoringScriptService) ScriptService(org.xwiki.script.service.ScriptService) JobException(org.xwiki.job.JobException) EntityRequest(org.xwiki.refactoring.job.EntityRequest) JobExecutor(org.xwiki.job.JobExecutor) RefactoringScriptService(org.xwiki.refactoring.script.RefactoringScriptService) XWikiException(com.xpn.xwiki.XWikiException)

Example 2 with JobException

use of org.xwiki.job.JobException in project xwiki-platform by xwiki.

the class RefactoringScriptServiceTest method moveWithException.

@Test
public void moveWithException() throws Exception {
    MoveRequest request = new MoveRequest();
    JobException exception = new JobException("Some error message");
    when(this.jobExecutor.execute(RefactoringJobs.MOVE, request)).thenThrow(exception);
    assertNull(getService().move(request));
    assertSame(exception, getService().getLastError());
}
Also used : JobException(org.xwiki.job.JobException) MoveRequest(org.xwiki.refactoring.job.MoveRequest) Test(org.junit.Test)

Example 3 with JobException

use of org.xwiki.job.JobException in project xwiki-platform by xwiki.

the class JobsResourceImpl method executeJob.

@Override
public JobStatus executeJob(String jobType, boolean async, JobRequest restJobRequest) throws XWikiRestException {
    // TODO: provide extension point to decide of the access depending on the job
    if (!this.authorization.hasAccess(Right.PROGRAM, null)) {
        throw new WebApplicationException(Status.UNAUTHORIZED);
    }
    // Parse JobRequest
    DefaultRequest request = this.factory.toJobRequest(restJobRequest);
    if (request == null) {
        request = new DefaultRequest();
    }
    // Start job
    Job job;
    try {
        // Give a few context related values to the job
        if (request.getProperty(JobRequestContext.KEY) == null) {
            JobRequestContext.set(request, this.xcontextProvider.get());
        }
        job = this.jobExecutor.execute(jobType, request);
    } catch (JobException e) {
        throw new XWikiRestException("Failed to start job", e);
    }
    // Wait for the job end if asked
    if (!async) {
        try {
            job.join();
        } catch (InterruptedException e) {
            throw new XWikiRestException("The job as been interrupted", e);
        }
        // Fail the HTTP request if the job failed
        if (job.getStatus().getError() != null) {
            throw new XWikiRestException("The job failed (" + ExceptionUtils.getRootCauseMessage(job.getStatus().getError()) + ")", job.getStatus().getError());
        }
    }
    // Get job status
    org.xwiki.job.event.status.JobStatus status = job.getStatus();
    // Convert Job status
    return this.factory.toRestJobStatus(status, null, true, false, false, null);
}
Also used : JobException(org.xwiki.job.JobException) WebApplicationException(javax.ws.rs.WebApplicationException) DefaultRequest(org.xwiki.job.DefaultRequest) XWikiRestException(org.xwiki.rest.XWikiRestException) Job(org.xwiki.job.Job)

Example 4 with JobException

use of org.xwiki.job.JobException in project xwiki-platform by xwiki.

the class FlavorManagerScriptService method searchValidFlavors.

/**
 * Start searching for valid flavors.
 *
 * @param namespace the namespace where to validate the flavors
 * @return the {@link Job} searching the flavors
 * @since 8.0RC1
 */
public Job searchValidFlavors(String namespace) {
    setError(null);
    Job job = null;
    try {
        FlavorSearchRequest flavorRequest = new FlavorSearchRequest();
        flavorRequest.setId(getSearchJobId(namespace));
        flavorRequest.addNamespace(namespace);
        setRightsProperties(flavorRequest);
        job = this.jobExecutor.execute(FlavorSearchJob.JOBTYPE, flavorRequest);
    } catch (JobException e) {
        setError(e);
    }
    return job;
}
Also used : JobException(org.xwiki.job.JobException) FlavorSearchRequest(org.xwiki.platform.flavor.job.FlavorSearchRequest) Job(org.xwiki.job.Job) FlavorSearchJob(org.xwiki.platform.flavor.internal.job.FlavorSearchJob)

Example 5 with JobException

use of org.xwiki.job.JobException in project xwiki-platform by xwiki.

the class UndeleteAction method startRestoreJob.

private Job startRestoreJob(XWikiDeletedDocument deletedDocument, XWikiContext context) throws XWikiException {
    XWikiRequest request = context.getRequest();
    RefactoringScriptService refactoring = (RefactoringScriptService) Utils.getComponent(ScriptService.class, "refactoring");
    RestoreRequest restoreRequest = null;
    if (TRUE.equals(request.getParameter(INCLUDE_BATCH_PARAMETER))) {
        // Restore the entire batch, including the current document.
        String batchId = deletedDocument.getBatchId();
        restoreRequest = refactoring.createRestoreRequest(batchId);
    } else {
        // Restore just the current document.
        restoreRequest = refactoring.createRestoreRequest(Arrays.asList(deletedDocument.getId()));
    }
    restoreRequest.setInteractive(isAsync(request));
    try {
        JobExecutor jobExecutor = Utils.getComponent(JobExecutor.class);
        return jobExecutor.execute(RefactoringJobs.RESTORE, restoreRequest);
    } catch (JobException e) {
        throw new XWikiException(String.format("Failed to schedule the restore job for deleted document [%s], id [%s] of batch [%s]", deletedDocument.getFullName(), deletedDocument.getId(), deletedDocument.getBatchId()), e);
    }
}
Also used : RefactoringScriptService(org.xwiki.refactoring.script.RefactoringScriptService) ScriptService(org.xwiki.script.service.ScriptService) JobException(org.xwiki.job.JobException) JobExecutor(org.xwiki.job.JobExecutor) RefactoringScriptService(org.xwiki.refactoring.script.RefactoringScriptService) RestoreRequest(org.xwiki.refactoring.job.RestoreRequest) XWikiException(com.xpn.xwiki.XWikiException)

Aggregations

JobException (org.xwiki.job.JobException)13 Job (org.xwiki.job.Job)8 AbstractExtensionJob (org.xwiki.extension.job.internal.AbstractExtensionJob)5 InstallJob (org.xwiki.extension.job.internal.InstallJob)5 InstallPlanJob (org.xwiki.extension.job.internal.InstallPlanJob)5 UninstallJob (org.xwiki.extension.job.internal.UninstallJob)5 UninstallPlanJob (org.xwiki.extension.job.internal.UninstallPlanJob)5 UpgradePlanJob (org.xwiki.extension.job.internal.UpgradePlanJob)5 XWikiException (com.xpn.xwiki.XWikiException)2 Test (org.junit.Test)2 JobExecutor (org.xwiki.job.JobExecutor)2 DocumentReference (org.xwiki.model.reference.DocumentReference)2 RefactoringScriptService (org.xwiki.refactoring.script.RefactoringScriptService)2 ScriptService (org.xwiki.script.service.ScriptService)2 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 IOException (java.io.IOException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 ExtensionId (org.xwiki.extension.ExtensionId)1 InstallRequest (org.xwiki.extension.job.InstallRequest)1 ReplayRequest (org.xwiki.extension.job.history.ReplayRequest)1