Search in sources :

Example 91 with ExecutionContext

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());
}
Also used : ExecutionContext(org.xwiki.context.ExecutionContext) Execution(org.xwiki.context.Execution) Before(org.junit.Before)

Example 92 with ExecutionContext

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);
}
Also used : WatchListConfiguration(org.xwiki.watchlist.WatchListConfiguration) Execution(org.xwiki.context.Execution) DefaultExecution(org.xwiki.context.internal.DefaultExecution) ExecutionContext(org.xwiki.context.ExecutionContext) WatchListStore(org.xwiki.watchlist.internal.api.WatchListStore) EventListener(org.xwiki.observation.EventListener) Before(org.junit.Before)

Example 93 with ExecutionContext

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);
    }
}
Also used : ServletRequest(org.xwiki.container.servlet.ServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletContainerException(org.xwiki.container.servlet.ServletContainerException) ExecutionContext(org.xwiki.context.ExecutionContext) ExecutionContextManager(org.xwiki.context.ExecutionContextManager) RequestInitializerManager(org.xwiki.container.RequestInitializerManager) ServletContainerException(org.xwiki.container.servlet.ServletContainerException)

Example 94 with ExecutionContext

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);
    }
}
Also used : PortletRequest(org.xwiki.container.portlet.PortletRequest) ExecutionContext(org.xwiki.context.ExecutionContext) RequestInitializerException(org.xwiki.container.RequestInitializerException) PortletContainerException(org.xwiki.container.portlet.PortletContainerException) ExecutionContextException(org.xwiki.context.ExecutionContextException)

Example 95 with ExecutionContext

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;
}
Also used : ExecutionContext(org.xwiki.context.ExecutionContext) Set(java.util.Set) NotificationFilterPreference(org.xwiki.notifications.filters.NotificationFilterPreference)

Aggregations

ExecutionContext (org.xwiki.context.ExecutionContext)114 Execution (org.xwiki.context.Execution)62 XWikiContext (com.xpn.xwiki.XWikiContext)47 Before (org.junit.Before)31 Test (org.junit.Test)25 XWiki (com.xpn.xwiki.XWiki)19 DocumentReference (org.xwiki.model.reference.DocumentReference)19 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)15 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)14 ComponentManager (org.xwiki.component.manager.ComponentManager)9 ExecutionContextException (org.xwiki.context.ExecutionContextException)9 WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)9 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)8 ExecutionContextManager (org.xwiki.context.ExecutionContextManager)8 List (java.util.List)6 Map (java.util.Map)6 Properties (java.util.Properties)6 Session (javax.mail.Session)6 MimeMessage (javax.mail.internet.MimeMessage)6 XWikiException (com.xpn.xwiki.XWikiException)5