Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

RAM API to find roles and usergroups

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 );
}
}
}

}

}

0 votes


Be the first one to answer this question!

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details

Question asked: Jul 10 '10, 4:02 a.m.

Question was seen: 4,891 times

Last updated: Jul 10 '10, 4:02 a.m.

Confirmation Cancel Confirm