Search in sources :

Example 1 with JobRequestContext

use of com.xpn.xwiki.job.JobRequestContext 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)

Aggregations

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 JobStartedEvent (org.xwiki.job.event.JobStartedEvent)1