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

Program or script to add a Group for a spcecific Role in multiple products

Program or script to add a Group for a spcecific Role in multiple products

Hi,

I need to grant a Specific Role to a Group of users in 155 Products already existing.

Anyone tried a programmatic way of doing such? or LoadFiles, Script?

Thanks,

Christophe

3 REPLIES 3

Program or script to add a Group for a spcecific Role in multiple products

Hi Christophe, With the following code I am able to add a user to an
existing role of library team. I highlighted the important api. Hope it
helps to write your own utility.

String name="Trash Library";
Class className = wt.inf.library.WTLibrary.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 WTLibrary) {
WTLibrary library = (WTLibrary) obj;
String displayIdentifier = library.getDisplayIdentifier();
System.out.println("Library :"+displayIdentifier);
System.out.println("Container "+ library.getContainerName());

ContainerTeam team =
ContainerTeamHelper.service.getContainerTeam(library);
Enumeration enumeration = team.getRoles().elements();
while (enumeration.hasMoreElements()) {
Object roleobj =enumeration.nextElement();
Role role = (Role) roleobj;
System.out.println(role);
if(role.getDisplay().equalsIgnoreCase("Members")){
WTUser user = (WTUser)SessionHelper.manager.getPrincipal();
ContainerTeamHelper.service.addMember(team,role,user);
System.out.println( "User "+user.getName() +" added to role
"+role.getDisplay()+" in container "+library.getDisplayIdentifier());

}
}
}
}

Regards,
Prathap


RE: Program or script to add a Group for a spcecific Role in multiple products

Hi,

First thanks to Prathap for his help on this.

You will find attached my code sample if it can be of any help.

I am still having problem with the Role wt.project.Role.GUEST which seems to behave differently from the Custom role we have added into our team.

I guest I can manage 288 product updates manually....

Highlighted

RE: Program or script to add a Group for a spcecific Role in multiple products

hi,

I'm trying to add a user to a role using your code and I'm getting this error in MethodServer:

wt.util.WTRuntimeException: ERROR: Can't initialize an ObjectReference to null

Library, role and user exist so I don't know what could be happening.

Some suggestion?

regards,

Felipe

Announcements
LiveWorx Call For Papers Happening Now!