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

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

How To Determine Users In a Product Context Role

vimalkumar.ajit
1-Visitor

How To Determine Users In a Product Context Role

Hope this helps...


wt.inf.team.ContainerTeam containerteam =
wt.inf.team.ContainerTeamHelper.service.getContainerTeam((wt.inf.team.ContainerTeamManaged)((wt.inf.container.WTContained)wtobject).getContainerReference().getObject());
WTGroup wtgroup =
wt.inf.team.ContainerTeamHelper.service.findContainerTeamGroup(containerteam,"roleGroups",grpname);
if(wtgroup!=null)
{
//WTGroup wtgroup =
wt.inf.team.ContainerTeamHelper.service.findContainerTeamGroup((wt.inf.team.ContainerTeamManaged)((wt.inf.container.WTContained)wtobject).getContainerReference().getObject(),"roles",s2);
Enumeration enumeration =
OrganizationServicesHelper.manager.members(wtgroup);
while(enumeration.hasMoreElements())
{
wtprincipal1 = (WTPrincipal)enumeration.nextElement();
if(wtprincipal1 instanceof WTUser)
{
wtuser = (WTUser)wtprincipal1;

}
}
}


Regards,
Vimal


On Fri, May 28, 2010 at 10:19 PM, Jim VanDragt <
-> wrote:

> Good Day All,
>
> How do I determine which users are contained within a Role for a given
> product context. The code below works to determine all of the roles for the
> product context "ABC", but now I'm stuck on how to find out which users are
> contained in the roles.
>
> String name="ABC";
> Class className = wt.pdmlink.PDMLinkProduct.*class*;
> *int*[] index = *new* *int*[1];
> index[0] = 0;
> QuerySpec queryspec = *new* QuerySpec(className);
> queryspec.appendWhere(*new* SearchCondition(className,
> "containerInfo.name", "=", name), index);
> QueryResult queryresult = PersistenceHelper.manager.find(queryspec);
> System.out.println("Result size :"+ queryresult.size());
>
> *while* (queryresult.hasMoreElements()) {
> Object obj = queryresult.nextElement();
> *if* (obj *instanceof* PDMLinkProduct) {
> PDMLinkProduct product = (PDMLinkProduct) obj;
> String displayIdentifier =
> product.getDisplayIdentifier().toString();
> System.out.println("Product :"+displayIdentifier);
> System.out.println("Container "+ product.getContainerName());
>
> ContainerTeam team =
> ContainerTeamHelper.service.getContainerTeam(product);
>
> Enumeration enumeration = team.getRoles().elements();
> *while* (enumeration.hasMoreElements()) {
> Object roleobj =enumeration.nextElement();
> Role role = (Role) roleobj;
> System.out.println(role);
>
> }
> }
> }
>
> Thanks,
>
> Jim
>
> Jim Van Dragt
> Information Technology
> Herman Miller Inc.
> 616.654.5285 - Office
> 616.836.8394 - Cell
>
>
4 REPLIES 4

seen this code &/or request for containerteam, role, users or grups & its users, when I had a similar task.

So I generated some code to generate output to show tree (somewhat) of the above.

the zip with codce/class/readme/sample output is in zip on my site:

http://www.datajett.com/windchill/wc_dev/TeamRoleParticipants.zip

readme is:

http://www.datajett.com/windchill/wc_dev/TeamRoleParticipants/TeamRoleParticipants_readme.txt

Sample output is:

http://www.datajett.com/windchill/wc_dev/TeamRoleParticipants/TeamRoleParticipants_090510_232140.txt

class/java are in zip or same folder.

I will throw java at end of message, so future searches will find its methods/etc.

command line is: java ext.TeamRoleParticipants & this will throw output to screen.

it will take one arg if you want to create time stamped file in a chosen directory (dir path is arg):

java ext.TeamRoleParticipants c:\temp

/**/ can be replaced with tabs for java creation, but the /**/ is used for formatting & makes for better viewing.

Let me know if you see errors &/or need adds. The user fullname, phone, email, etc was left off, but could be easily added.

Larry Jett
cadjett@aolo.com;datajett@aol.com

code:===============================

package ext;

import java.io.*;
import java.util.*;
import java.text.*;

import wt.query.*;
import wt.fc.*;

import wt.team.Team;
import wt.project.Role;
import wt.inf.team.ContainerTeam;
import wt.project.Role;

import wt.org.*;
import wt.org.WTUser;
import wt.org.WTOrganization;
import wt.org.WTGroup;
import wt.org.WTPrincipal;
import wt.org.WTPrincipalReference;

import wt.inf.team.*;
import wt.inf.container.*;
import wt.inf.container.WTContainer;

import wt.projmgmt.admin.*;

import wt.method.RemoteMethodServer;
import wt.httpgw.GatewayAuthenticator;

public class TeamRoleParticipants{

/**/static File outPath;
/**/static PrintWriter printwriter;

/**/public static void main(String[] args) throws Exception{

/**//**/RemoteMethodServer rms = RemoteMethodServer.getDefault();
/**//**/GatewayAuthenticator auth = new GatewayAuthenticator();
/**//**/auth.setRemoteUser("wcadmin");
/**//**/rms.setAuthenticator(auth);

/**//**/boolean writeFlag = false;

/**//**/if(args.length == 1)
/**//**/{
/**//**//**/writeFlag = true;
/**//**//**/SimpleDateFormat df = new SimpleDateFormat ("MMddyy_HHmmss", Locale.getDefault());
/**//**//**/java.util.Date tm = new java.util.Date();
/**//**//**/String dtStg = df.format(tm);

/**//**//**/outPath = new File(args[0]+"\\TeamRoleParticipants_"+dtStg+".txt");
/**//**//**/System.out.println( "\nWriting Ouput to File: "+args[0]+"\\TeamRoleParticipants_"+dtStg+".txt\n" );
/**//**/}

/**//**/if(writeFlag)
/**//**//**/printwriter = new PrintWriter(new FileWriter(outPath));

/**//**/QueryResult resCTT=PersistenceHelper.manager.find(new QuerySpec(ContainerTeam.class));
/**//**/while(resCTT.hasMoreElements()) {
/**//**//**/ContainerTeam contTeam = (ContainerTeam)resCTT.nextElement();
/**//**//**/System.out.println( "\nContainerTeam: " + contTeam.getName()+"\n" );
/**//**//**/if(writeFlag)
/**//**//**//**/printwriter.println((new StringBuilder()).append("\nContainerTeam: " + contTeam.getName()+"\n").toString());

/**//**//**/Vector vector = contTeam.getRoles();
/**//**//**/int i = vector.size();
/**//**/label0:
/**//**//**/for(int j = 0; j < i; j++)
/**//**//**/{
/**//**//**//**/Role role = (Role)vector.get(j);
/**//**//**//**/System.out.println("\tRole: "+role.getDisplay());
/**//**//**//**/if(writeFlag)
/**//**//**//**//**/printwriter.println((new StringBuilder()).append("\tRole: "+role.getDisplay()).toString());

/**//**//**//**/ArrayList arraylist = contTeam.getAllPrincipalsForTarget(role);

/**//**//**//**/int k = 0;
/**//**//**//**/do
/**//**//**//**/{
/**//**//**//**//**/if(k >= arraylist.size()) {
/**//**//**//**//**//**/continue label0;
/**//**//**//**//**/}
/**//**//**//**//**/WTPrincipalReference wtprincipalreference1 = (WTPrincipalReference)(WTPrincipalReference)arraylist.get(k);
/**//**//**//**//**/WTPrincipal wtprincipal = (WTPrincipal)wtprincipalreference1.getObject();
/**//**//**//**//**/if(wtprincipal instanceof WTUser) {
/**//**//**//**//**//**/WTUser wtuser = (WTUser)wtprincipal;
/**//**//**//**//**//**/System.out.println( "\t\tUser: "+wtuser.getName());
/**//**//**//**//**//**/if(writeFlag)
/**//**//**//**//**//**//**/printwriter.println((new StringBuilder()).append("\t\tUser: "+wtuser.getName()).toString());
/**//**//**//**//**/}
/**//**//**//**//**/else if(wtprincipal instanceof WTGroup)
/**//**//**//**//**/{
/**//**//**//**//**//**/WTGroup wtgroup = (WTGroup)wtprincipal;
/**//**//**//**//**//**/System.out.println( "\t\tGroup: "+wtgroup.getName());
/**//**//**//**//**//**/if(writeFlag)
/**//**//**//**//**//**//**/printwriter.println((new StringBuilder()).append("\t\tGroup: "+wtgroup.getName()).toString());

/**//**//**//**//**//**//**/for(Enumeration enumeration = wtgroup.members(); enumeration.hasMoreElements();)
/**//**//**//**//**//**//**/{
/**//**//**//**//**//**//**//**/WTUser wtuser = (WTUser)enumeration.nextElement();
/**//**//**//**//**//**//**//**/System.out.println( "\t\t\tUser: "+wtuser.getName());
/**//**//**//**//**//**//**//**/if(writeFlag)
/**//**//**//**//**//**//**//**//**/printwriter.println((new StringBuilder()).append("\t\t\tUser: "+wtuser.getName()).toString());
/**//**//**//**//**//**//**/}
/**//**//**//**//**/}
/**//**//**//**//**/else if(wtprincipal instanceof WTOrganization)
/**//**//**//**//**/{
/**//**//**//**//**//**/WTOrganization wtorg = (WTOrganization)wtprincipal;
/**//**//**//**//**//**/System.out.println( "\t\tOrg: "+wtorg.getName());
/**//**//**//**//**//**/if(writeFlag)
/**//**//**//**//**//**//**/printwriter.println((new StringBuilder()).append("\t\tOrg: "+wtorg.getName()).toString());;
/**//**//**//**//**/}
/**//**//**//**//**/k++;
/**//**//**//**/} while(true);
/**//**//**/}
/**//**/}

/**//**/System.out.println("\nNumber of ContainerTeams: "+resCTT.size() + "\n");
/**//**/if(writeFlag) {
/**//**//**/printwriter.println((new StringBuilder()).append("\nNumber of ContainerTeams: "+resCTT.size() + "\n").toString());
/**//**//**/printwriter.flush();
/**//**//**/printwriter.close();
/**//**/}
/**/}
}

This is awesome Thanks Man it really helps alot 

KU_9877195_0-1683575973376.png

Can do same with a query builder report - and the output has hyperlinks to all.

This is awesome Thanks Man it really helps alot 🙂

Announcements


Top Tags