Search in sources :

Example 1 with JobStartedEvent

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()));
            }
        }
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiServletRequestStub(com.xpn.xwiki.web.XWikiServletRequestStub) XWikiContext(com.xpn.xwiki.XWikiContext) JobStartedEvent(org.xwiki.job.event.JobStartedEvent) JobRequestContext(com.xpn.xwiki.job.JobRequestContext)

Example 2 with JobStartedEvent

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;
}
Also used : DefaultRequest(org.xwiki.job.DefaultRequest) AbstractRequest(org.xwiki.job.AbstractRequest) Request(org.xwiki.job.Request) AbstractRequest(org.xwiki.job.AbstractRequest) DefaultRequest(org.xwiki.job.DefaultRequest) JobStartedEvent(org.xwiki.job.event.JobStartedEvent)

Aggregations

JobStartedEvent (org.xwiki.job.event.JobStartedEvent)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 JobRequestContext (com.xpn.xwiki.job.JobRequestContext)1 XWikiServletRequestStub (com.xpn.xwiki.web.XWikiServletRequestStub)1 AbstractRequest (org.xwiki.job.AbstractRequest)1 DefaultRequest (org.xwiki.job.DefaultRequest)1 Request (org.xwiki.job.Request)1