HowTo: Multiple Repositories Scenario in an SD application

Official Content

This is the scenario where a smart device application connects to a different GAM Repository depending on the company of the user (multitenant scenario).

In this case, connection.gam - a server file containing all the GAM Repository Connections - will have one GAM connection to each Repository where the application is going to connect.

In general, applications of this kind have one Repository for each company, each with its own Repository Namespace. In order to allow users to connect to one Repository, the GAM Repository connection needs to be defined in the connection.gam file.

More information about the corresponding configuration issues is provided in Multiple Repositories Scenario: The same application installation is shared by many companies

As for the program, the GAM connection has to be set programmatically before login pointing to the Repository that belongs to the user's company.

The connection can be set in two ways. One, is to use a procedure that executes a SetConnection using the corresponding GAM Connection name. Another, is to use the Repository property of the LoginExternalAdditionalParameters data type. The LoginExternalAdditionalParameters data type is used in the GAM Login Method to set some parameters. In particular, you can set the Repository you have to connect to.

Example

Using the Setconnection method

The following is a sample Login event of the SD panel GAMSDlogin, which calls a proc called "setconnectionproc" invoked before the Login.

Event 'GXLogin'
    Composite
        GeneXus.Common.UI.Progress.ShowWithTitle("Connecting...")
        setconnectionProc(&companyname,&Messages)
        GeneXus.SD.Actions.Login(&User, &Password)
        GeneXus.Common.UI.Progress.Hide()
        Return
    EndComposite
EndEvent

 Note that the "setconnectionproc" procedure should have Integrated Security Level property = None.

The code of the "setconnectionproc" is as follows:

parm(in:&CompanyName);

//Code that decides which connection is going to be used.
//This is a user procedure which, given the "Company" information, decides which GAM connection corresponds to this company.
&connectionName = GetConnectionName(&Company)

//Set the connection to GAM
&isOK = GAM.SetConnection(&connectionName, &GAMErrors) 
If not &isOK
    GAMConvertErrorsToMessages(&GAMErrors, &Messages) //&Messages is Messages, GeneXus.Common
Endif

The SetConnection is a method of the GAM External Object (that is part of the GAM API).

It receives the GAM Repository Connection name as a parameter. The GAM Repository Connection name is the value of the Name element in the connection.gam file, as shown below:

<ConnectionCollection>
<Connection xmlns="">
        <Name>test</Name>
        <Repository>df4e34b8-3d1d-4752-a62b-c81ba4aa383b</Repository>
        <UserName>9+XkRvi7qSkGzRQQvqPqE0Lh3bVY5y8ToqcckMK3Lpw=</UserName>
        <UserPassword>Ff9+cMARHXh5FdjQ1fd/tA==</UserPassword>
        <Type>LAN</Type>
        <Language />
    </Connection>
</ConnectionCollection>

Notes:

1. In Smart Devices, if the connection.gam has more than one entry, and a setconnection is not performed, the following error is thrown:

The connection to GAM is not specified. Please contact the application administrator.

image_2017127141244_1_png

2. More information on how to use the SetConnection method can be found on HowTo: Get and Set GAM Repository Connections.

For a demo, see this video.

Using the Repository property of LoginExternalAdditionalParameters data type

The LoginExternalAdditionalParameters object allows to set the Repository GUID where the connection is going to be set.
It's the same as executing a procedure where the SetConnection is executed - but using Setconnection method, the connection name is used. In this case - using the Repository property of LoginExternalAdditionalParameters data type - the Repository GUID is used. So, in the connection.gam, there must be one connection at least, for this Repository.

Event 'GXLogin'
    Composite
        GeneXus.Common.UI.Progress.ShowWithTitle("Connecting...")
        &LoginExternalAdditionalParameters.Repository = !"1e89a9ca-bc52-482b-a344-c4cda4a9cc8f"
        GeneXus.SD.Actions.Login(&User, &Password,&LoginExternalAdditionalParameters)
        GeneXus.Common.UI.Progress.Hide()
        Return
    EndComposite
EndEvent

If the connection.gam has only one entry, the Repository parameter is ignored.