- 1. Summary
- 2. Result
- 3. Step by Step Guide
- 3.1 Step 1 - Define the context structure
- 3.2 Step 2 - Inject the new context dataset into the application
- 3.3 Step 3 - Configure a dedicated service to easily access the context from within the PASOE
- 3.4 Step 4 - Register the new services into the PASOE
- 3.5 Step 5 - Access the context from your client/business logic
1. Summary
When implementing your own application, you might come across the requirement to maintain certain information in the current user session. This guide will help you set up a custom user session to store any number of properties.
2. Result
At the end of this guide, we will have a custom session set up with 2 property ‘Property1’ and ‘Property2’.
3. Step by Step Guide
3.1 Step 1 - Define the context structure
We will define the context with a dataset containing the standard B1 context tables and a custom context one:
&SCOPED-DEFINE ACCESS {&ACCESS}
{ Consultingwerk/OERA/Context/eContextProperties.i &NO-BEFORE=YES }
{ Consultingwerk/OERA/Context/eSessionContext.i &NO-BEFORE=YES }
{ Akioma/Swat/OERA/Context/eSwatSessionContext.i &NO-BEFORE=YES }
DEFINE {&ACCESS} TEMP-TABLE eMyAppSessionContext NO-UNDO
FIELD Property1 AS CHARACTER
FIELD Property2 AS CHARACTER
.
DEFINE DATASET dsMyAppContext FOR eContextProperties, eSessionContext, eSwatSessionContext, eMyAppSessionContext.
3.2 Step 2 - Inject the new context dataset into the application
Now that we have defined the model of our context, we will need to inject it into the application, using a dedicated factory service:
BLOCK-LEVEL ON ERROR UNDO, THROW.
CLASS MyApp.Session.MyAppContextDatasetFactory
INHERITS Akioma.Swat.OERA.Context.BaseContextDatasetFactory:
{ MyApp/Session/dsMyAppContext.i }
CONSTRUCTOR MyAppContextDatasetFactory():
SUPER(DATASET dsMyAppContext:HANDLE).
END CONSTRUCTOR.
END CLASS.
3.3 Step 3 - Configure a dedicated service to easily access the context from within the PASOE
To be able to easily access the new context from within the OpenEdge business logic, a dedicated context wrapper service needs to be set up:
BLOCK-LEVEL ON ERROR UNDO, THROW.
CLASS MyApp.Session.MyAppContextWrapper
INHERITS Akioma.Swat.OERA.Context.BaseContextWrapper:
{ Akioma/Swat/OERA/Context/Helper/define-context-wrapper-property.i &NAME="Property1" }
{ Akioma/Swat/OERA/Context/Helper/define-context-wrapper-property.i &NAME="Property2" }
CONSTRUCTOR MyAppContextWrapper():
SUPER("eMyAppSessionContext").
END CONSTRUCTOR.
METHOD OVERRIDE VOID InitializeSessionFromUser(pcUser AS CHARACTER, pcDomain AS CHARACTER):
// initialize session properties
END METHOD.
END CLASS.
The InitializeSessionFromUser properties allows the assignment of the properties on session initialization.
3.4 Step 4 - Register the new services into the PASOE
The application needs to be configured to use the new services for the context. This is done by adding the following entries to the custom services configuration:
<?xml version="1.0"?>
<ttServiceLoader xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ttServiceLoaderRow>
<Order>1</Order>
<ServiceTypeName>MyApp.Session.MyAppContextWrapper</ServiceTypeName>
<ServiceClassName>MyApp.Session.MyAppContextWrapper</ServiceClassName>
</ttServiceLoaderRow>
<ttServiceLoaderRow>
<Order>5</Order>
<ServiceTypeName>Consultingwerk.OERA.Context.IContextDatasetFactory</ServiceTypeName>
<ServiceClassName>MyApp.Session.MyAppContextDatasetFactory</ServiceClassName>
</ttServiceLoaderRow>
</ttServiceLoader>
3.5 Step 5 - Access the context from your client/business logic
Once everything has been set up, the PASOE will need to be trimmed to register the changed.
All existing user session will still have the old context model active, so another authentication will be required to force a new user session to be created.
Now, the new session context model should be active!
It should be accessible from the webui client logic using the following code:
akioma.swat.SessionManager.get('Property1', 'eMyAppSessionContext');
From our PASOE business logic, it will be accessible with the following code:
DEFINE VARIABLE oMyAppContextWrapper AS MyApp.Session.MyAppContextWrapper NO-UNDO.
oMyAppContextWrapper = {Consultingwerk/get-mandatory-service.i MyApp.Session.MyAppContextWrapper}.
MESSAGE "MyApp Context Property1" QUOTER(oMyAppContextWrapper:Property1).
Back to Use Cases
Back to Build.One Help-Center Home