Thursday, 17 May 2012

Business Context In WCS

Business Context Service can be used instead of Http session or Cookies. Business Context Service option is available for maintaining the information throughout the user activity and invalidating it when the user logs out or the browser is closed.

It uses a couple of tables CTXDATA and CTXMGMT, to manage the context. Essentially each time a user comes to the site, a new activity is created in CTXMGMT table and it associates the calling user (Users_id as CALLER_ID) with an ACTIVITY_ID . The ACTIVITY_ID remains the same in the course of the session and it also keeps all the contexts associated with the activity in CTXDATA table.

When the same user logs in from a different device or a separate browser, essentially the previous context in CTXMGMT is marked as T (Terminated). It creates a new activity with a state A (Active).

CTXMGMT -This table contains the management information of each context service activity.
CTXDATA -This table contains the data that associates with a particular activity.

WebSphere Commerce configuration file (wc-server.xml) business context files are defined as follows.

BusinessContextConfigFile="config/businessContext.xml,config/,config/,config/" display="false">
<ExpiryManagement ExpiryMgmtChannelId="-2,-4"
InactivityTimeout="30" Threshold="30" enable="true"/>

Business Context configuration file

Business contexts are defined in the xml/config/businessContext.xml file.

In the configuration file, there are two major sections.

1)BusinessContexts - This section defines the different business contexts that are available to the site

<BusinessContext ctxId="BaseContext"
factoryClassname="" >
<parameter name="spiClassname" value="" />

2)InitialBusinessContextSets- This section defines the business context set which is a logical grouping of business contexts for a particular type of request.
If no business context set is defined for the request, the default business context set is used.

<InitialBusinessContextSets activeCtxSetId="Default" >

< !-- default configuration -->
<InitialBusinessContextSet ctxSetId="Default" >
<InitialBusinessContext ctxId="BaseContext" createOrder="0" />
<InitialBusinessContext ctxId="EntitlementContext" createOrder="1" />
<InitialBusinessContext ctxId="GlobalizationContext" createOrder="1" />
<InitialBusinessContext ctxId="AuditContext" createOrder="1" />

A required attribute that identifies the business context within the configuration file.This identifier is necessary when defining contexts within a business context set.

For ctxId ,the following attributes can be specified:

This context contains the basic attributes that an activity needs, such as store ID, caller ID, and the run-as ID.

<BusinessContext ctxId="BaseContext"
factoryClassname="" >
<parameter name="spiClassname" value="" />

Other than base contexts WebSphere Commerce predefines the following contexts

This context holds information about entitlement criteria, such as reduced prices for gold club membership.

This context helps components determine locale-specific information such as what language a message should be rendered in,or what currency should be used in the calculation of a price.

If Workspaces are enabled, this context determines the content or business objects that can be displayed or edited based on versioning information.

If Workspaces are enabled, this context determines which task an administrator is currently performing.

AuditContext is usually provided by third party components. This context enables you to connect to a different vendor's implementation of the service in the future without the need to rewrite your component.

PreviewContext is the attempt by allowing multi-users to validate independent content without influencing other users and ensuring the content does not required additional changes after validation.

ExperimentContext is used to store the result of all active experiments for individual users and the result is a system-generated number which determines the control or test element to be selected in the experiment. This information is persisted throughout the user session, so the same result will be used in the same session without re-generation of the number.

CatalogContext contains information related to the catalog in the current session, such as the catalog ID, the catalog owner, and whether this is a master catalog or not.

GiftRegistryContext contains gift registry information for a user in the current session, such as a list of gift registries that the user has accessed, the relationship the user has to specific gift registries (gift giver, registrant or coregistrant), and the external ID of the gift registry the user is currently managing.

Defining business context sets for a Web application

Steps to be followed

Step 1) Open the WebSphere Commerce configuration file in an editor.
Set the contextSetName attribute within the Module element. For example, to enable the CommerceAccelerator webapp to use the Authoring business context:

urlMappingPath="/servlet" webAlias="/wcs">
<InitParameters adapters="BrowserAdapter" contextSetName="Authoring"/>

The predefined business context sets defined in the business context configuration files are:

Defines the minimum set of business contexts. Use Default when the context set does not belong to a Web application for example, MQ requests, or Sales Center requests. This is the default context set as specified by the activeCtxSetId attribute in the BusinessContext.xml file
Defines the business context set for requests that come through the Store webapp. For example, catalog browsing, and order processing through the storefront.
Defines the business context set for requests that come through the Accelerator webapp. This context set supports content management and preview capabilities.
Defines the business context set for requests that come through the Administration webapps (Orgadminconsole and Adminconsole). This context set supports administering the site.

Step 2) Save and close the file. Restart WebSphere Commerce.

How to create a Custom Business Context Service /Business context Service Customizations

Please follow the below steps for Business Context Service customization

1.First create a new Interface for the custom context by extending the interface.
2.Create a context implementation class that implements the custom interface created by extending the
3. Registering new Business Context by making an entry in businessContext.xml or Create a new businessContext.xml (Recommended  Approach).
4. Register this new businessContext.xml in the wc-server.xml under the BusinessContextService element.
5.Based on the customer requirement put the the values from the controller command or View into the context and then use the values across the application.

1 comment:

  1. I tried creating new businessContext but my flow is BOD, I am able to fetch the new businessContext in bOD command but not able to get in Handler . Its coming as null for my businesscontext as well as existing context like GlobalisationContext and BaseContext. I found Handler itself has businessContext , but does not incluse my businessContext attributes. Please suggest how to keep some any session attribute in BOD flows available in whole flow.