eVBI

How to Sync Groups between Clarity and Jaspersoft Solution Hint

Discussion created by eVBI on Jul 20, 2016
Latest reply on Jul 20, 2016 by Chris_Hackett


Hi,

 

I created a solution to sync user groups in Clarity with the roles in Jaspersoft.

To do so you can use the REST calls to Jaspersoft.

You can create a view to define which groups to sync, and with the REST calls you can adjust the users.

Requirement is that the role exists.

The way I build it does the following functional steps:

1. read config file with server details/ users/(encyrpted) password required for access.

2. connect to Clarity database retrieves the groups and the jaspersoft synced users

3. do REST call per user to assign the groups

 

The following stripped code is made in c# and you can use it, maybe with some tweaks to do the REST calls.

{

    class Program

    {

        static int Main(string[] args)

        {

           // sync the roles

           RunAsync(theData, findUser).Wait();

           }

        static async Task RunAsync(DataTable data, string user)

        {

}

            //Created by E. van Bommel - Elwin@evbi.nl

      

            var credentials = new NetworkCredential(superuser, password));

            var handler = new HttpClientHandler { Credentials = credentials };

      

            using (var client = new HttpClient(handler))

            {

                client.BaseAddress = new Uri("http://server/reportservice/rest_v2/users");

                client.DefaultRequestHeaders.Accept.Clear();

                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            

               //Get the user in json format

                HttpResponseMessage response = await client.GetAsync(username);

                if (response.IsSuccessStatusCode)

                {

                    string role = await response.Content.ReadAsStringAsync();

                 }

                              // HTTP POST

                                         //Example:

string jsonContent = ("{ \"roles\": [{\"name\":\"ROLE_USER\"} ]}");

                HttpResponseMessage request = await client.PutAsync(user, Content);

               // HttpResponseMessage request = await client.DeleteAsync(user); //this works :-)

           if (request.IsSuccessStatusCode)

                {

                    // Get the URI of the created resource.

                    Logging.WriteLogEntry("User send via REST " + user);

                }             

            }

}

Outcomes