1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.internal.job

File JobRequestContextInitializer.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

14
16
2
1
98
52
9
0.56
8
2
4.5

Classes

Class Line # Actions
JobRequestContextInitializer 46 16 0% 9 5
0.8437584.4%
 

Contributing tests

This file is covered by 78 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package com.xpn.xwiki.internal.job;
21   
22    import javax.inject.Inject;
23    import javax.inject.Named;
24    import javax.inject.Provider;
25    import javax.inject.Singleton;
26   
27    import org.xwiki.component.annotation.Component;
28    import org.xwiki.job.event.JobStartedEvent;
29    import org.xwiki.observation.AbstractEventListener;
30    import org.xwiki.observation.event.Event;
31   
32    import com.xpn.xwiki.XWikiContext;
33    import com.xpn.xwiki.doc.XWikiDocument;
34    import com.xpn.xwiki.job.JobRequestContext;
35    import com.xpn.xwiki.web.XWikiServletRequestStub;
36   
37    /**
38    * Automatically set various context values before the actual job start.
39    *
40    * @version $Id: 401869b03bdebfcd5ce857bc46a660c22ef580d9 $
41    * @since 8.4RC1
42    */
43    @Component
44    @Named("com.xpn.xwiki.internal.job.JobRequestContextInitializer")
45    @Singleton
 
46    public class JobRequestContextInitializer extends AbstractEventListener
47    {
48    @Inject
49    private Provider<XWikiContext> xcontextProvider;
50   
51    /**
52    * The default constructor.
53    */
 
54  185 toggle public JobRequestContextInitializer()
55    {
56  185 super(JobRequestContextInitializer.class.getName(), new JobStartedEvent());
57    }
58   
 
59  267 toggle @Override
60    public void onEvent(Event event, Object source, Object data)
61    {
62  267 JobStartedEvent jobStartedEvent = (JobStartedEvent) event;
63   
64  267 JobRequestContext jobRequestContext = jobStartedEvent.getRequest().getProperty(JobRequestContext.KEY);
65   
66  267 if (jobRequestContext != null) {
67  33 XWikiContext xcontext = this.xcontextProvider.get();
68   
69  33 if (xcontext != null) {
70    // Wiki id
71  33 if (jobRequestContext.isWikiIdSet()) {
72  33 xcontext.setWikiId(jobRequestContext.getWikiId());
73    }
74   
75    // User
76  33 if (jobRequestContext.isUserReferenceSet()) {
77  33 xcontext.setUserReference(jobRequestContext.getUserReference());
78    }
79   
80    // Document
81  33 if (jobRequestContext.isDocumentSet()) {
82  33 xcontext.setDoc(jobRequestContext.getDocument());
83    }
84   
85    // Secure document
86  33 if (jobRequestContext.isSDocumentSet()) {
87  33 xcontext.put(XWikiDocument.CKEY_SDOC, jobRequestContext.getSDocument());
88    }
89   
90    // Request
91  33 if (jobRequestContext.isRequestSet()) {
92  2 xcontext.setRequest(new XWikiServletRequestStub(jobRequestContext.getRequestURL(),
93    jobRequestContext.getRequestParameters()));
94    }
95    }
96    }
97    }
98    }