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