use of org.xwiki.context.ExecutionContext in project xwiki-platform by xwiki.
the class AbstractWikiTestCase method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
this.executionContext = new ExecutionContext();
Execution execution = getComponentManager().getInstance(Execution.class);
execution.setContext(this.executionContext);
Utils.setComponentManager(getComponentManager());
}
use of org.xwiki.context.ExecutionContext in project xwiki-platform by xwiki.
the class AutomaticWatchModeListenerTest method setUp.
@Before
public void setUp() throws Exception {
this.mockStore = mocker.getInstance(WatchListStore.class);
// Make sure we have an Execution Context since the observationContextListener will store current events in it
Execution execution = mocker.getInstance(Execution.class);
execution.setContext(new ExecutionContext());
this.observationContextListener = mocker.getInstance(EventListener.class, "ObservationContextListener");
this.configuration = mocker.getInstance(WatchListConfiguration.class);
when(this.configuration.isEnabled()).thenReturn(true);
}
use of org.xwiki.context.ExecutionContext in project xwiki-platform by xwiki.
the class DefaultServletContainerInitializer method initializeRequest.
@Override
public void initializeRequest(HttpServletRequest httpServletRequest, Object xwikiContext) throws ServletContainerException {
// 1) Create an empty request. From this point forward request initializers can use the
// Container object to get any data they want from the Request.
this.container.setRequest(new ServletRequest(httpServletRequest));
// 2) Create an empty Execution context so that the Container initializers can put things in the
// execution context when they execute.
this.execution.setContext(new ExecutionContext());
// XWikiContext object whereas new code uses the Container component.
if (xwikiContext != null) {
ExecutionContext ec = this.execution.getContext();
String key = "xwikicontext";
if (ec.hasProperty(key)) {
ec.setProperty(key, xwikiContext);
} else {
ec.newProperty(key).inherited().initial(xwikiContext).declare();
}
}
// 4) Call the request initializers to populate the Request further.
try {
RequestInitializerManager manager = this.componentManager.getInstance(RequestInitializerManager.class);
manager.initializeRequest(this.container.getRequest());
} catch (Exception e) {
throw new ServletContainerException("Failed to initialize request", e);
}
// 5) Call Execution Context initializers to perform further Execution Context initializations
try {
ExecutionContextManager manager = this.componentManager.getInstance(ExecutionContextManager.class);
manager.initialize(this.execution.getContext());
} catch (Exception e) {
throw new ServletContainerException("Failed to initialize Execution Context", e);
}
}
use of org.xwiki.context.ExecutionContext in project xwiki-platform by xwiki.
the class DefaultPortletContainerInitializer method initializeRequest.
@Override
public void initializeRequest(javax.portlet.PortletRequest portletRequest, Object xwikiContext) throws PortletContainerException {
// 1) Create an empty request. From this point forward request initializers can use the
// Container object to get any data they want from the Request.
this.container.setRequest(new PortletRequest(portletRequest));
// 2) Create en empty Execution context so that the Container initializers can put things in the
// execution context when they execute.
this.execution.setContext(new ExecutionContext());
// XWikiContext object whereas new code uses the ExecutionContext found in the Execution component.
if (xwikiContext != null) {
ExecutionContext ec = this.execution.getContext();
String key = "xwikicontext";
if (ec.hasProperty(key)) {
ec.setProperty(key, xwikiContext);
} else {
ec.newProperty(key).inherited().initial(xwikiContext).declare();
}
}
// initializers.
try {
this.requestInitializerManager.initializeRequest(this.container.getRequest());
} catch (RequestInitializerException e) {
throw new PortletContainerException("Failed to initialize request", e);
}
// 5) Call Execution Context initializers to perform further Execution Context initializations
try {
this.executionContextManager.initialize(this.execution.getContext());
} catch (ExecutionContextException e) {
throw new PortletContainerException("Failed to initialize Execution Context", e);
}
}
use of org.xwiki.context.ExecutionContext in project xwiki-platform by xwiki.
the class CachedModelBridge method getFilterPreferences.
@Override
public Set<NotificationFilterPreference> getFilterPreferences(DocumentReference user) throws NotificationException {
// We need to store the user reference in the cache's key, otherwise all users of the same context will share
// the same cache, which can happen when a notification email is triggered.
final String contextEntry = String.format(CONTEXT_KEY_FORMAT, USER_FILTER_PREFERENCES, serializer.serialize(user));
ExecutionContext context = execution.getContext();
Object cachedPreferences = context.getProperty(contextEntry);
if (cachedPreferences != null && cachedPreferences instanceof Set) {
return (Set<NotificationFilterPreference>) cachedPreferences;
}
Set<NotificationFilterPreference> preferences = modelBridge.getFilterPreferences(user);
context.setProperty(contextEntry, preferences);
return preferences;
}
Aggregations