use of org.xwiki.job.DefaultRequest in project xwiki-platform by xwiki.
the class ModelFactory method toJobRequest.
public DefaultRequest toJobRequest(JobRequest restJobRequest) {
DefaultRequest request = new DefaultRequest();
if (restJobRequest.getId() != null) {
request.setId(restJobRequest.getId().getElements());
}
request.setInteractive(restJobRequest.isInteractive());
request.setVerbose(restJobRequest.isVerbose());
request.setStatusSerialized(restJobRequest.isStatusSerialized());
request.setStatusLogIsolated(restJobRequest.isStatusLogIsolated());
for (MapEntry restEntry : restJobRequest.getProperties()) {
request.setProperty(restEntry.getKey(), this.jaxbConverter.unserializeAny(restEntry.getValue()));
}
return request;
}
use of org.xwiki.job.DefaultRequest 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.DefaultRequest in project xwiki-platform by xwiki.
the class ExtensionJobEventConverter method fromRemote.
@Override
public boolean fromRemote(RemoteEventData remoteEvent, LocalEventData localEvent) {
if (remoteEvent.getEvent() instanceof JobStartedEvent) {
JobStartedEvent jobEvent = (JobStartedEvent) remoteEvent.getEvent();
if (JOBS.contains(jobEvent.getJobType())) {
Request request = jobEvent.getRequest();
// Indicate the job has been triggered by a remote event
if (!(request instanceof AbstractRequest)) {
request = new DefaultRequest(request);
}
((AbstractRequest) request).setRemote(true);
// We don't want to directly simulate a new JobStartedEvent event but we want to start a new job
// which will generate a new JobStartedEvent
localEvent.setEvent(new RemoteExtensionJobStartedEvent(jobEvent.getJobType(), request));
return true;
}
}
return false;
}
Aggregations