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

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

Team: Display the roles of a user

HenriMarchal
7-Bedrock

Team: Display the roles of a user

Hello,

I have to implement a way of displaying the roles that a user owns.

With WCAdmin, it is possible. You browse to Principal Administrator, you find a user and when you hit the info button, this information is displayed.

But when you are a basic user, if you hit the info button of another user (for example in the team tab of a product), you've got another jsp (netmarkets/jsp/user/view.jsp) with less information.

I'ld like the basic user to be redirected on the same kind of jsp than the wcadmin in the Principal Administrator. Do you think it is possible. How to procede ? And is not there a special access right for the full display of the user data shown in the Principal Administrator ?

Thank you for your help.

HM

ACCEPTED SOLUTION

Accepted Solutions

Customize netmarkets/jsp/user/profile.jsp to display what you want.

Here's how to find all of a user's roles.... It should be enough to get you going, anyways.

public class MyRoles {
public static void main(String[] args) {
try {
//get your user....
WTPrincipal user = SessionHelper.manager.getPrincipal();
Set<Role> teamRoles = teamRoles(user);
Set<Role> containerTeamRoles = containerTeamRoles(user);
System.out.println("teamRoles.size(): " + teamRoles.size());
System.out.println("containerTeamRoles.size(): " + containerTeamRoles.size());
} catch (Exception e) {
e.printStackTrace();
}
}
public static Set<Role> teamRoles(WTPrincipal principal) throws WTException, WTPropertyVetoException {
Set<Role> roles = new HashSet<Role>();
QuerySpec qs = new QuerySpec();
qs.setDistinct(true);
int rpmIndex = qs.appendClassList(RolePrincipalMap.class, false);
qs.appendSelectAttribute(RolePrincipalMap.ROLE, rpmIndex, false);
qs.appendWhere(new SearchCondition(RolePrincipalMap.class,RolePrincipalMap.PRINCIPAL_PARTICIPANT + ".key",SearchCondition.EQUAL,PersistenceHelper.getObjectIdentifier(principal)),new int[rpmIndex]);
QueryResult qr = PersistenceHelper.manager.find((StatementSpec)qs);
while(qr.hasMoreElements()) {
Object nextArray[] = (Object[])qr.nextElement();
if(nextArray != null && nextArray.length == 1) {
roles.add((Role)nextArray[0]);
}
}
return roles;
}
public static Set<Role> containerTeamRoles(WTPrincipal principal) throws WTException {
Set<Role> set = new HashSet<Role>();
QueryResult containerTeams = findContainerTeams();
while(containerTeams.hasMoreElements()) {
ContainerTeam team = (ContainerTeam)containerTeams.nextElement();
Iterator<Role> roles = team.getRoles().iterator();
while(roles.hasNext()) {
Role role = roles.next();
WTGroup group = ContainerTeamHelper.service.findContainerTeamGroup(team, ContainerTeamHelper.ROLE_GROUPS, role.toString());
if(group != null) {
if(group.isMember(principal)) {
set.add(role);
}
}
}
}
return set;
}
private static QueryResult findContainerTeams() throws WTException {
QuerySpec qs = new QuerySpec(ContainerTeam.class);
return PersistenceHelper.manager.find((StatementSpec)qs);
}
}

View solution in original post

2 REPLIES 2

See attached reports

Customize netmarkets/jsp/user/profile.jsp to display what you want.

Here's how to find all of a user's roles.... It should be enough to get you going, anyways.

public class MyRoles {
public static void main(String[] args) {
try {
//get your user....
WTPrincipal user = SessionHelper.manager.getPrincipal();
Set<Role> teamRoles = teamRoles(user);
Set<Role> containerTeamRoles = containerTeamRoles(user);
System.out.println("teamRoles.size(): " + teamRoles.size());
System.out.println("containerTeamRoles.size(): " + containerTeamRoles.size());
} catch (Exception e) {
e.printStackTrace();
}
}
public static Set<Role> teamRoles(WTPrincipal principal) throws WTException, WTPropertyVetoException {
Set<Role> roles = new HashSet<Role>();
QuerySpec qs = new QuerySpec();
qs.setDistinct(true);
int rpmIndex = qs.appendClassList(RolePrincipalMap.class, false);
qs.appendSelectAttribute(RolePrincipalMap.ROLE, rpmIndex, false);
qs.appendWhere(new SearchCondition(RolePrincipalMap.class,RolePrincipalMap.PRINCIPAL_PARTICIPANT + ".key",SearchCondition.EQUAL,PersistenceHelper.getObjectIdentifier(principal)),new int[rpmIndex]);
QueryResult qr = PersistenceHelper.manager.find((StatementSpec)qs);
while(qr.hasMoreElements()) {
Object nextArray[] = (Object[])qr.nextElement();
if(nextArray != null && nextArray.length == 1) {
roles.add((Role)nextArray[0]);
}
}
return roles;
}
public static Set<Role> containerTeamRoles(WTPrincipal principal) throws WTException {
Set<Role> set = new HashSet<Role>();
QueryResult containerTeams = findContainerTeams();
while(containerTeams.hasMoreElements()) {
ContainerTeam team = (ContainerTeam)containerTeams.nextElement();
Iterator<Role> roles = team.getRoles().iterator();
while(roles.hasNext()) {
Role role = roles.next();
WTGroup group = ContainerTeamHelper.service.findContainerTeamGroup(team, ContainerTeamHelper.ROLE_GROUPS, role.toString());
if(group != null) {
if(group.isMember(principal)) {
set.add(role);
}
}
}
}
return set;
}
private static QueryResult findContainerTeams() throws WTException {
QuerySpec qs = new QuerySpec(ContainerTeam.class);
return PersistenceHelper.manager.find((StatementSpec)qs);
}
}
Announcements


Top Tags