use of org.xwiki.job.event.JobStartedEvent in project xwiki-platform by xwiki.
the class JobRequestContextInitializer method onEvent.
@Override
public void onEvent(Event event, Object source, Object data) {
JobStartedEvent jobStartedEvent = (JobStartedEvent) event;
JobRequestContext jobRequestContext = jobStartedEvent.getRequest().getProperty(JobRequestContext.KEY);
if (jobRequestContext != null) {
XWikiContext xcontext = this.xcontextProvider.get();
if (xcontext != null) {
// Wiki id
if (jobRequestContext.isWikiIdSet()) {
xcontext.setWikiId(jobRequestContext.getWikiId());
}
// User
if (jobRequestContext.isUserReferenceSet()) {
xcontext.setUserReference(jobRequestContext.getUserReference());
}
// Document
if (jobRequestContext.isDocumentSet()) {
XWikiDocument document = getDocument(jobRequestContext, xcontext);
xcontext.setDoc(document);
}
// Secure document
if (jobRequestContext.isSDocumentSet()) {
XWikiDocument sdocument = getSDocument(jobRequestContext, xcontext);
xcontext.put(XWikiDocument.CKEY_SDOC, sdocument);
}
// Request
if (jobRequestContext.isRequestSet()) {
xcontext.setRequest(new XWikiServletRequestStub(jobRequestContext.getRequestURL(), jobRequestContext.getRequestParameters()));
}
}
}
}
use of org.xwiki.job.event.JobStartedEvent 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