cancel
Showing results for 
Search instead for 
Did you mean: 

Getting Roles from Portal

Former Member
0 Kudos

Hi Experts,

I need my portal roles are displyed in a dropdown.

Once I click on any of the role it need to display the Users, in assigned to that role. How to do that? give your suggestions?

Regards,

P.Manivannan.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

See what i undestand is u need to fetch portal roles and then

display them in a drop down and on selection of any role u

need to fetch users assigned to that roles.

In order to that create a value node say ctx_portal(1..n

cardinality) and create two attributes say portal_role and portal

id in it.This will hold the roles and unique ID to that role

fetched from the portal.

use the below code to fetch the portal roles,ids and saving it

into ctx_portal node.


IRoleFactory rolef=UMFactory.getRoleFactory();
IRoleSearchFilter searchfilterrole= rolef.getRoleSearchFilter();
ISearchResult searchResult = rolef.searchRoles(searchfilterrole);
wdContext.nodeCtx_portal().invalidate();
while(searchResult.hasNext())
{

IPrivateMyappView.ICtx_portalElement myelement =wdContext.nodeCtx_portal().createCtx_portalElement();
String unq=(String) searchResult.next();
IRole role1=rolef.getRole(unq);
myelement.setPortal_role(role1.getDisplayName());
myelement.setPortal_id(role1.getUniqueID());
wdContext.nodeCtx_portal().addElement(myelement);
}			


Now u have Roles fetched from portal and just need to display

it into a dropdown.

Use DropdownByIndex and bind it to portal_role.

On Action of this Element write the below code.



try {
        IRoleFactory rolef=UMFactory.getRoleFactory();
        IUserFactory userf=UMFactory.getUserFactory();
       IRole role2=rolef.getRole(wdContext.currentCtx_portalElement().getPortal_id());
     Iterator itr = role2.getUserMembers(true);
      if(itr.hasNext())
       {
          while(itr.hasNext())
          {
	String user1=(String)itr.next();
	IUser user=userf.getUser(user1);
	wdComponentAPI.getMessageManager().reportSuccess("User to above role "+user.getDisplayName());
         }			
         }
else
{
wdComponentAPI.getMessageManager().reportSuccess("No user to above role");
}
					
} 
catch (UMException e) {
		// TODO Auto-generated catch block
wdComponentAPI.getMessageManager().reportSuccess(e.getLocalizedMessage());
}

Rewards point if helpful.

Regards

Surender Dahiya

Former Member
0 Kudos

Hi Surender,

Thanks for your valuable reply. I got solution. I also thank to ayyaparaj and vijai.

Regards,

P.Manivannan.

Answers (2)

Answers (2)

Former Member
0 Kudos

Hello Palanisamy,

Please go thru this code , to get roles for user

The following function will check if a user belongs to a specific role:

public boolean userHasRole(String userId, String roleName) {

boolean result = false; IWDMessageManager manager = wdComponentAPI.getMessageManager();

try {

// get webdynpro user

IWDClientUser wdcu = WDClientUser.getCurrentUser();

// get sap WAS user for WD user

IUser sapUser = wdcu.getSAPUser();

// get role for name

IRole sapRole = UMFactory.getRoleFactory().getRole(roleName);

// check if user is member of role,

// the "true" attribute means, that role assignment might be

// indirect (ie. for a group in which user is a member

result = sapRole.isUserMember(sapUser.getUniqueID(), true);

// return a message in case of exception

}

catch (WDUMException e1) {

wdComponentAPI.getMessageManager().reportWarning("Error when obtaining user information : " + e1.getMessage());

}

catch (UMException e2) {

wdComponentAPI.getMessageManager().reportWarning("Error when obtaining user information : " + e2.getMessage());

}

// the result is true, if current user has the named role return result;

}

let me know if problem still exits ,

Please Awards points if helpful

Please close the thread if "problem solved"

Thanks

Regards

Vijay

Former Member
0 Kudos

Hi,

Once I click on any of the role it need to display the Users, in assigned to that role. How to do that?

UMFactory.getRoleFactory().getUsersOfRole(String arg0, boolean arg1);

Pl refer the API for the details of params

Regards

Ayyapparaj