Page tree
Skip to end of metadata
Go to start of metadata

As of release SWAT 19.15.1, we have added official support for custom session properties.

The current session is stored in a session dataset, where the SmartComponent Library and SWAT session property tables are stored.
To hold additional properties, the dataset will need to be extended. To this extent, SmartComponent Library provides the Consultingwerk.OERA.Context.IContextDatasetFactory service, which is responsible for the provision of the dataset.
A custom class will need to be implemented to provide the extended dataset.

Sample: TestContextDatasetFactory
USING Progress.Lang.*.
USING Consultingwerk.OERA.Context.IContextDatasetFactory FROM PROPATH.

BLOCK-LEVEL ON ERROR UNDO, THROW.

CLASS Test.TestContextDatasetFactory
    IMPLEMENTS IContextDatasetFactory: 

    { Test/dsTestContext.i }

    /*------------------------------------------------------------------------------
        Purpose: Factory method for the context dataset                                                                       
        Notes:   Returns the handle for the Context Dataset
                 Initializes the Client Progress Version Number
        @return The handle of the context dataset instance                                                                      
    ------------------------------------------------------------------------------*/
    METHOD PUBLIC HANDLE CreateContextDataset ():
        
        IF NOT SESSION:REMOTE THEN DO:
            CREATE eSessionContext . 
            ASSIGN eSessionContext.ClientProVersion = PROVERSION 
                   eSessionContext.ClientType       = SESSION:CLIENT-TYPE . 
            CREATE eSwatSessionContext .
            CREATE eTestSessionContext .
        END.
        
        RETURN DATASET dsTestContext:HANDLE .

    END METHOD.
END CLASS.
Sample: dsTestContext
&SCOPED-DEFINE ACCESS {&ACCESS}
&SCOPED-DEFINE REFERENCE-ONLY {&REFERENCE-ONLY}
&SCOPED-DEFINE SUFFIX {&SUFFIX}

&GLOBAL-DEFINE DATASET-NAME dsTestContext

{ 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 }
{ Test/eTestSessionContext.i &NO-BEFORE=YES }


DEFINE {&ACCESS} DATASET dsTestContext{&SUFFIX} {&REFERENCE-ONLY} FOR eContextProperties{&SUFFIX}, eSessionContext{&SUFFIX}, eSwatSessionContext{&SUFFIX}, eTestSessionContext{&SUFFIX} 

    . 
Sample: eTestSessionContext
DEFINE {&ACCESS} TEMP-TABLE eTestSessionContext{&SUFFIX} NO-UNDO {&REFERENCE-ONLY} &IF DEFINED (NO-BEFORE) EQ 0 &THEN BEFORE-TABLE eTestSessionContextBefore{&SUFFIX} &ENDIF
    
    FIELD TestProperty1 AS CHARACTER
    FIELD TestProperty2 AS CHARACTER
    .


Next, a context wrapper class needs to be defined to provide access to the eTestSessionContext table fields.
For the SmartComponent Library session, the properties are available by accessing Consultingwerk.OERA.ContextWrapper.
For the SWAT session, the properties are available by accessing Akioma.Swat.OERA.Context.SwatContextWrapper.
A similar class should be implemented to provide strong-typed access to the custom session properties.
Both the SmartComponent Library and the SWAT context wrappers are separated into 2 different classes, the wrapper and the wrapper implementation (ex. Consultingwerk.OERA.ContextWrapper and Consultingwerk.OERA.ContextWrapperImpl), but this is not a requirement.
To simplify the implementation, we provide a base class for the implementation class: Akioma.Swat.OERA.Context.BaseContextWrapperImpl.

Sample: ITestContextWrapper
INTERFACE Test.ITestContextWrapper: 
    
    DEFINE PUBLIC PROPERTY TestProperty1 AS CHARACTER NO-UNDO
    	GET. SET.  
??
	DEFINE PUBLIC PROPERTY TestProperty2 AS CHARACTER NO-UNDO
    	GET. SET.  
  
END INTERFACE.
Sample: TestContextWrapper
USING Progress.Lang.*.
USING Test.TestContextWrapper FROM PROPATH.

BLOCK-LEVEL ON ERROR UNDO, THROW.

CLASS Test.TestContextWrapper: 
??
	DEFINE PUBLIC STATIC PROPERTY TestProperty1 AS CHARACTER NO-UNDO
    GET:
        RETURN TestContextWrapper:GetContextWrapperImpl ():TestProperty1 .
    END GET .
    SET (arg AS CHARACTER):
        TestContextWrapper:GetContextWrapperImpl ():TestProperty1 = arg .
    END .

	DEFINE PUBLIC STATIC PROPERTY TestProperty2 AS CHARACTER NO-UNDO
    GET:
        RETURN TestContextWrapper:GetContextWrapperImpl ():TestProperty2 .
    END GET .
    SET (arg AS CHARACTER):
        TestContextWrapper:GetContextWrapperImpl ():TestProperty2 = arg .
    END .
    
    DEFINE PROTECTED STATIC VARIABLE oContextWrapperInstance AS Test.ITestContextWrapper NO-UNDO.
    
    METHOD PROTECTED STATIC Test.ITestContextWrapper GetContextWrapperImpl ():
        IF VALID-OBJECT (oContextWrapperInstance) THEN
            RETURN oContextWrapperInstance.
        oContextWrapperInstance = {Consultingwerk/get-service.i Test.ITestContextWrapper
                                                                "NEW Test.TestContextWrapperImpl ()" } .
        RETURN oContextWrapperInstance .
    END METHOD.

END CLASS.
Sample: TestContextWrapperImpl
USING Progress.Lang.*.
USING Test.ITestContextWrapper FROM PROPATH.
USING Akioma.Swat.OERA.Context.BaseContextWrapperImpl FROM PROPATH.
USING Akioma.Swat.SessionManager FROM PROPATH.

BLOCK-LEVEL ON ERROR UNDO, THROW.

CLASS Test.TestContextWrapperImpl
    INHERITS BaseContextWrapperImpl
    IMPLEMENTS ITestContextWrapper : 
    
	DEFINE PUBLIC PROPERTY TestProperty1 AS CHARACTER NO-UNDO
    GET ():
        IF NOT IsValidateSessionContext ("Get":U) THEN
            RETURN ?.
        RETURN GetSessionContextField ("TestProperty1"):BUFFER-VALUE .
    END GET .
    SET (arg AS CHARACTER):
        IsValidateSessionContext ("Set":U).
        GetSessionContextField ("TestProperty1"):BUFFER-VALUE = arg .
    END SET.
??
	DEFINE PUBLIC PROPERTY TestProperty2 AS CHARACTER NO-UNDO
    GET ():
        IF NOT IsValidateSessionContext ("Get":U) THEN
            RETURN ?.
        RETURN GetSessionContextField ("TestProperty2"):BUFFER-VALUE .
    END GET .
    SET (arg AS CHARACTER):
        IsValidateSessionContext ("Set":U).
        GetSessionContextField ("TestProperty2"):BUFFER-VALUE = arg .
    END SET.
    
    CONSTRUCTOR TestContextWrapperImpl():
        SUPER().
        THIS-OBJECT:ContextTableName = "eTestSessionContext".
    END CONSTRUCTOR.

END CLASS.


Once all the classes are available the services file needs to be updated to use them:

Sample: Service file entries
	<ttServiceLoaderRow>
		<Order>210</Order>
		<ServiceTypeName>Consultingwerk.Framework.Server.IContextDatasetStore</ServiceTypeName>
		<ServiceClassName>Akioma.Swat.OERA.Context.SwatContextDatasetStore</ServiceClassName>
	</ttServiceLoaderRow>
	<ttServiceLoaderRow>
		<Order>211</Order>
		<ServiceTypeName>Consultingwerk.OERA.Context.IContextDatasetFactory</ServiceTypeName>
		<ServiceClassName>Test.TestContextDatasetFactory</ServiceClassName>
	</ttServiceLoaderRow>


Additionally, we provide a new web handler which returns the session, which requires the 'ContextName' path portion.
The ContextName will need to be one of the tables from the session dataset: eSessionContext (SmartComponentLibrary), eSwatSessionContext (SWAT), eTestSessionContext (Sample)

Sample: PASOE web handler setting
handler15=Akioma.Swat.OERA.WebHandler.SwatSessionContextWebHandler: /SessionContext/{ContextName}


See how to work with session properties from the front-end here.

 

  • No labels