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

We are happy to announce the new Windchill Customization board! Learn more.

Extract all Groups, user and its profile related information by java code

vuchekar
9-Granite

Extract all Groups, user and its profile related information by java code

Hi All,

i need to extarct all Groups, Group Member and user related information in tabular manner by using java code.

Please any one give me some idea how i can achive this requirement.

Thanks,

Vivek

17 REPLIES 17
MikeLockwood
22-Sapphire I
(To:vuchekar)

Every Windchill system admin needs this. This exact question has been posted to the world at least 1,000,000,000 times that I'm aware of. It's pretty incredible that at release 10.x PTC has not provided any way to extract this info. We paid a consultant to create a report. Others export from Windchill DS and parse in innovative ways in Excel.

The needed info is at Org, Groups (or possibly Site, Util, Participant admin). There is just no way to output the results currently.

Vivek, if you are familiar with customization, you can use the Windchill APIs (refer to Windchill javadoc) to write a java class that extracts this information in a required format. You can look for helper and service apis related to WTUser, WTPrincipal, WTGroup classes along with the QuerySpec.

Another option is to create a custom report using Query Build (Report Manager), but that is way too complex. You might want to consider it only as last resort.

Query Builder can't reach into LDAP.

True, Mike. But every LDAP user who once logs into Windchill would have an entry in the windchill database table, from where you can query the record, using either query builder or java code.

Agree on the wtuser and wtgroup tables - but the key thing is not being able to get group membership from the database via query builder.

Right. Thats where using the query builder becomes complicated!

Using java code - We can query all the groups using QuerySpec apis, and then for each group, we can use the WTGroup.members() method to get an enumeration of all the group members.

I'm very interested in getting a report still that lists users and what groups they are in. The report we paid for gets confused when groups are nested and we highly nest them. Do have this available and can you share to mike.lockwood@alcon.com?

I'll happily supply anything we have that you are interested in.

thanks

Unfortunately, I dont have this available, but here is what you can do:

1. Query all the groups from the database using QuerySpec apis (you can search for QuerySpec in Windchill javadocs).

2. For each group, get all the members using WTGroup's members() method.

3. What you would get in the enumeration would be a WTPrincipal reference, and a WTPrincipal could either be a WTUser or WTGroup. If the it is WTUser, you have got a user and if its WTGroup, you have got a nest group and can get the members for this group too.

WTGroup.GIF

members.GIF

WTUser.GIF

Mike I will send you Report..

cd suthar,

can you please post your report here in the community?

Thanks

Marco

Hi Suthar,

Could you please share the report with me as well on wasim.b.ahmed@accenture.com?

thanks,

Wasim

satre-2
1-Newbie
(To:wahmed)

Wasim,


Below code will extranksct/Print  the Organization > Group tables.

Hope it helps !!!

Thanks

Shreyas

package ext.sra;

import java.lang.reflect.InvocationTargetException;

import java.rmi.RemoteException;

import java.util.Enumeration;

import wt.fc.PersistenceHelper;

import wt.fc.QueryResult;

import wt.org.OrganizationServicesHelper;

import wt.org.WTGroup;

import wt.org.WTPrincipal;

import wt.query.QuerySpec;

import wt.query.SearchCondition;

import wt.util.WTException;

public class groupMembers {

  public static void main(String args[]) throws WTException, RemoteException,

  InvocationTargetException {

  QuerySpec qs = null;

  try {

  qs = new QuerySpec(WTGroup.class);

  SearchCondition sc1 = new SearchCondition(WTGroup.class,

  WTGroup.INTERNAL, SearchCondition.IS_FALSE);

  qs.appendWhere(sc1);

  QueryResult qr = PersistenceHelper.manager.find(qs);

  while (qr.hasMoreElements()) {

  WTGroup group = (WTGroup) qr.nextElement();

  if (group.getName().equals("ORG ADMIN")){

  continue;

  }

  if (!group.isDisabled()) {

  System.out

  .println("\n\n ===========================\nGroup Members pf Group  -->   "

  + group.getName());

  groupMembers.test(group.getDn());

  System.out.println("\n\n ===========================\n");

  }

  }

  } catch (WTException ex) {

  ex.printStackTrace();

  }

  }

  @SuppressWarnings("deprecation")

  public static void test(String name) throws WTException {

  WTPrincipal principal = OrganizationServicesHelper.manager

  .getPrincipalByDN(name);

  if (principal == null) {

  System.out.println("Principle not found###" + name);

  return;

  }

  Enumeration parents = OrganizationServicesHelper.manager.members(

  (WTGroup) principal, false);

  while (parents.hasMoreElements()) {

  WTGroup gr = null;

  WTPrincipal parent = (WTPrincipal) (parents.nextElement());

  if (parent.getClass().isAssignableFrom(WTGroup.class)) {

  System.out.println("--------" + parent.getName());

  if (parent.getName().equals("ORG ADMIN")){

  continue;

  }

  test(parent.getName().toString());

  // System.out.println("-->" +

  // test(parent.getName().toString()));

  } else {

  System.out.println("--------" + parent.getName());

  }

  }

  }

}

wahmed
3-Visitor
(To:satre-2)

Thanks a lot Shreyas. I'll give a try and let you know the results.

Shreyas,

Thank you so much, this really helps. But one question i'm able to fetch details of only 50 groups using the code whereas my Windchill instance has around 145 Unique groups in it.

I ran a DB query of "Select DISTINCT NAME from WTGROUP;" which gives me 145 groups, but when i run this code the code fetches details of 50 Groups only. Any pointers?

Is it grabbing only the Site or Org groups?

This is because WTGroup stores internal group table information as well, which are not LDAP group byt context roles

While running this code I get the following error. please help.

 

D:\ptc\Windchill>windchill sh.GroupMembers2 "AAV SU ARES Guests"
(wt.fc.fcResource/0) wt.util.WTException: The operation:   "find" failed.
Nested exception is: wt.util.WTRemoteException: Unable to invoke remote method;
nested exception is:
        wt.method.AuthenticationException
        at wt.method.RemoteMethodServer.invoke(RemoteMethodServer.java:810)
        at wt.services.ServiceFactory$ClientInvocationHandler.invoke(ServiceFactory.java:349)
        at com.sun.proxy.$Proxy1.find(Unknown Source)
        at sh.GroupMembers2.main(GroupMembers2.java:28)

Top Tags