cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

Get programmatically list ProductContext that have specific role for specific user

AB_9905442
4-Participant

Get programmatically list ProductContext that have specific role for specific user

Hello ,
My user have role " role001" in 3 differents ProductContext .
How can i get programmatically this 3 productContext when i login with my user .
Thank You 

 

ACCEPTED SOLUTION

Accepted Solutions

Hello @AB_9905442 

You can use following code to get the contexts. 

 

example contains user as a null but you need to find the WTUser. 

 

WTUser user = null; // you need to search for the user WTPrincipal = WTUser 
String contextRoleName = "PRODUCT MANAGER"; //internal context role name

Enumeration parentGroups = user.parentGroups();
while (parentGroups.hasMoreElements())
{
	WTPrincipalReference wtref = (WTPrincipalReference) parentGroups.nextElement();
	WTPrincipal principal = (WTPrincipal) wtref.getObject();
	if (principal.getName().equalsIgnoreCase(contextRoleName))
	{
		if (principal instanceof WTGroup)
		{
			WTContainer container = ((WTGroup) principal).getContainer();
			System.out.println(container.getName()); //this is the context
		}
	}
}

 

PetrH

View solution in original post

1 REPLY 1

Hello @AB_9905442 

You can use following code to get the contexts. 

 

example contains user as a null but you need to find the WTUser. 

 

WTUser user = null; // you need to search for the user WTPrincipal = WTUser 
String contextRoleName = "PRODUCT MANAGER"; //internal context role name

Enumeration parentGroups = user.parentGroups();
while (parentGroups.hasMoreElements())
{
	WTPrincipalReference wtref = (WTPrincipalReference) parentGroups.nextElement();
	WTPrincipal principal = (WTPrincipal) wtref.getObject();
	if (principal.getName().equalsIgnoreCase(contextRoleName))
	{
		if (principal instanceof WTGroup)
		{
			WTContainer container = ((WTGroup) principal).getContainer();
			System.out.println(container.getName()); //this is the context
		}
	}
}

 

PetrH

Announcements

Top Tags