SAP BusinessObjects – BI Platform – Java SDK – List of Users who are in more than one group

If you are SAP BusinessObjects BI Platform Administrator and looking to find Users who are part of multiple groups, this blog is for your reference.

Query to get the groups a user is belonging to:

SELECT SI_ID, SI_NAME, SI_USERGROUPS FROM CI_SYSTEMOBJECTS WHERE SI_KIND='User' AND SI_ID = <id>

Here is the JAVA SDK sample to print the list of groups, each User is belonging to:

package com.sap.businessobjects.bi.samples; import java.util.Iterator;
import java.util.Set; import com.businessobjects.bcm.BCM;
import com.crystaldecisions.sdk.exception.SDKException;
import com.crystaldecisions.sdk.framework.CrystalEnterprise;
import com.crystaldecisions.sdk.framework.IEnterpriseSession;
import com.crystaldecisions.sdk.framework.ISessionMgr;
import com.crystaldecisions.sdk.occa.infostore.IInfoObject;
import com.crystaldecisions.sdk.occa.infostore.IInfoObjects;
import com.crystaldecisions.sdk.occa.infostore.IInfoStore;
import com.crystaldecisions.sdk.plugin.desktop.user.IUser; public class listOfUsersInMoreThanOneGroup { public static void main (String[] agrs) { Set<Integer> setUserGroups; String cmsname = null; String username = null; String password = null; int x = 0; int y = 1; Object groupID = null; cmsname = "localhost:6400"; username = "administrator"; password = "Password1"; IEnterpriseSession boSession = null; ISessionMgr lSessionMgr = null; IInfoStore infoStore = null; IInfoObjects users = null; IInfoObjects boUserGroups = null; IInfoObject boUserGroup = null; IUser user = null; try { BCM.initializeSAPJCE(); lSessionMgr = CrystalEnterprise.getSessionMgr(); System.out.println("LIST OF USERS IN MORE THAN ONE GROUP: "); System.out.println(); boSession = lSessionMgr.logon(username, password, cmsname, "secEnterprise"); infoStore = (IInfoStore)boSession.getService("", "InfoStore"); for(int i=0;i<1;i++) { users = infoStore.query("SELECT si_id, SI_USERGROUPS FROM CI_SYSTEMOBJECTS WHERE SI_KIND='User'"); if(users.size() == 0) { break; } for(Iterator<?> iuser = users.iterator() ; iuser.hasNext() ; ) { user = (IUser) iuser.next(); setUserGroups = user.getGroups(); if (setUserGroups.size() > 1) { x=1; System.out.println(" "+y+" - User '" + user.getTitle() + "' is part of " + setUserGroups.size() + " groups, and they are: "); for(Iterator<?> iGroup = setUserGroups.iterator() ; iGroup.hasNext() ; ) { groupID = iGroup.next(); boUserGroups = infoStore.query("SELECT SI_NAME FROM CI_SYSTEMOBJECTS WHERE SI_KIND = 'UserGroup' AND SI_ID = '" + groupID + "'"); boUserGroup = (IInfoObject) boUserGroups.get(0); System.out.println(" "+ x + " - " + boUserGroup.getTitle()); x++; } System.out.println(); y++; } } } } catch (SDKException e) { e.printStackTrace(); } finally { if (boSession!= null) { boSession.logoff(); } } }
}

Regards, Venkat.