You are viewing the documentation for Blueriq 15. Documentation for other versions is available in our documentation directory.

The Blueriq as a Service SOAP and REST endpoints use an abstraction to start flows, the com.aquima.web.aaas.BaasFlowStarter interface.

The responsibilities of the BaaS Flow Starter are:

  • to create a session in which the flow will execute
  • to start the actual flow



The default BaaS Flow Starter is com.aquima.web.aaas.DefaultBaasFlowStarter. This implementation creates a session for the current user and starts the flow, if any exists:


package com.aquima.web.aaas;

import com.aquima.interactions.portal.IApplication;
import com.aquima.interactions.portal.IPortalSession;
import com.aquima.interactions.portal.IWebServiceOperationDefinition;
import com.aquima.interactions.portal.model.session.PortalEventBus;
import com.aquima.interactions.portal.model.session.PortalMessageBus;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Serializable;
import java.util.Map;

/**
 * Default {@link BaasFlowStarter} implementation. This class can be used as a starting point for custom flow starters,
 * either via extension or via delegation.
 * 
 * @since 11.4
 */
public class DefaultBaasFlowStarter implements BaasFlowStarter {

  private static final Logger LOG = LoggerFactory.getLogger(DefaultBaasFlowStarter.class);

  private final IAuthorisationManager authManager;


  public DefaultBaasFlowStarter(IAuthorisationManager authManager) {
    this.authManager = authManager;
  }

  @Override
  public IPortalSession createSession(IApplication application) {
    IUserData userData = authManager.getUserData();
    return application.createSession(null, userData);
  }

  @Override
  public void startFlow(IApplication application, IWebServiceOperationDefinition operation, IPortalSession session) {
    String flowName = operation.getFlowName();
    if (flowName != null) {
      if (LOG.isInfoEnabled()) {
        LOG.info("Starting flow: " + flowName);
      }
      session.startFlow(flowName, getFlowParameters(), true);
    }
  }

  /**
   * Returns the flow parameters, which will be added to the request scope. May return null if there are no parameters.
   * This class always returns null from this method. Subclasses may override this method to add flow parameters.
   * 
   * @return the flow parameters or null
   */
  protected Map<String, Serializable> getFlowParameters() {
    return null;
  }

}



Custom BaaS flow starters can be provided by either implementing the BaasFlowStarter interface or by extending the DefaultBaasFlowStarter class and exposing this implementation as a Spring managed bean, for example:


package com.example;

import com.aquima.interactions.portal.IApplication;
import com.aquima.interactions.portal.IPortalSession;
import com.aquima.interactions.portal.IWebServiceOperationDefinition;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

@Component
public class CustomBaasFlowStarter extends DefaultBaasFlowStarter {


  private final HttpServletRequest httpRequest;
  public CustomBaasFlowStarter (IAuthorisationManager authManager, HttpServletRequest httpRequest) {
    // wrap the auth manager in a custom implementation that is also aware of the current HTTP request
    super(new CustomAuthorisationManager(authManager, httpRequest);


    this.httpRequest = httpRequest;
  }
  
  @Override
  public IPortalSession createSession(IApplication application) {
    IPortalSession result = super.createSession(application);
    // custom logic, for example execute an action handler to modify the profile before the request is mapped
    return result;
  }
  
  @Override
  public void startFlow(IApplication application, IWebServiceOperationDefinition operation, IPortalSession session) {
    // custom logic before the flow is started, for example:
    // - setting session scoped attributes
    // - modify the profile after the request is mapped
    super.startFlow(application, operation, session);
  }
  
  @Override
  protected Map<String, Serializable> getFlowParameters() {
    Map<String, Serializable> parameters = new HashMap<>();
    parameters.put("example.custom_parameter", httpRequest.getHeader("X-Custom-Header"));
    
    return parameters;
  }
}


A single BaasFlowStarter implementation may be present in the Spring Application Context. The default implementation is present only if no other implementation is available.

The Blueriq SOAP and REST endpoints use the BaaS Flow starter in the following way:

  • the createSession(IApplication) method is called
    • custom flow starters may create a session using the provided IApplication parameter, optionally providing a user and/or channel as well
    • the profile or session scope may be modified by executing action handlers
  • the request is mapped based on the request domain/xsd schema and the web service definition into the profile of the created session
  • the startFlow(IApplication, IWebServiceOperationDefinition, IPortalSession) method is called
    • custom flow starters should start the flow given by IWebServiceOperationDefinition.getFlowName() in the session provided as parameter
    • not all web services have a flow, the flow name may be null; in this case, no flow should be started
    • flow parameters may be provided (these are internally added to the request scope); the default implementation provides the getFlowParameters() method that sub-classes can override to provide custom parameters