It's all about the answers!

Ask a question

RAM API to find roles and usergroups


Yuan Yuan (111) | asked Jul 10 '10, 4:02 a.m.
I have requirements to get roles and usgroups based on the input community name and user id.

Please see the following codes.
I am not sure whether the api I called is correct or there are some more efficient api can implement my requirements.


import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import com.ibm.ram.client.RAMCommunity;
import com.ibm.ram.client.RAMSession;
import com.ibm.ram.common.data.UserInformation;
import com.ibm.ram.internal.access.ws.RAM1;
import com.ibm.ram.internal.client.RAMClient;
import com.ibm.ram.internal.common.data.CommunitySO;
import com.ibm.ram.internal.common.data.RoleSO;
import com.ibm.ram.internal.common.data.UserGroupSO;

public class Test {

public void test( String communityName, String userId ) throws Exception {

List<RoleSO> roles = new ArrayList<RoleSO>();
List<UserGroupSO> groups = new ArrayList<UserGroupSO>();

// Get community based on the community name
RAMSession session = new RAMSession( "RAMURL", "ADMIN", "PASSWORD" );
RAMCommunity community = session.getCommunity( communityName );

// Connect ram server
RAM1 ram1 = new RAMClient(new URL( "RAMURL" ), "ADMIN", "PASSWORD", null).getRAM1Webservice();
int[] communityIdArray = { community.getId() };
CommunitySO[] communitySO = ram1.getCommunities( communityIdArray, true, true );
CommunitySO so = communitySO;

RoleSO[] rolesArray = so.getRoles();
UserGroupSO[] groupsArray = so.getUserGroups();

// Get roles and put into role list
for( RoleSO role : rolesArray ) {
String[] userIdArray = role.getUserIDs();
for( String id : userIdArray ) {
if( userId.equals( id ) ) {
roles.add( role );
}
}
}

// Get user groups and put into group list
for( UserGroupSO group : groupsArray ) {
UserInformation[] userArray = group.getUsers();
for( UserInformation user : userArray ) {
if( userId.equals( user.getUid() ) ) {
groups.add( group );
}
}
}

}

}

Be the first one to answer this question!


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.