How to bulk add one user to 400 project areas?
Jorge Alarcon (41●11●22)
| asked Apr 27 '16, 8:03 p.m.
edited May 04 '16, 5:13 a.m. by Krzysztof Kaźmierczyk (7.5k●4●80●103)
Do you know if there is a way to automate importing and assigning licenses to users into JTS?
Regards |
3 answers
Ralph Schoon (63.5k●3●36●46)
| answered May 04 '16, 7:53 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Too big for a comment. The code would look like:
/*******************************************************************************
* Licensed Materials - Property of IBM
* (c) Copyright IBM Corporation 2013. All Rights Reserved.
*
* ServerSetup
*
* Note to U.S. Government Users Restricted Rights: Use, duplication or
* disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
*******************************************************************************/
package com.ibm.js.team.admin.automation;
import java.net.URI;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import com.ibm.team.process.client.IClientProcess;
import com.ibm.team.process.client.IProcessItemService;
import com.ibm.team.process.common.IProcessArea;
import com.ibm.team.process.common.IProcessItem;
import com.ibm.team.process.common.IProjectArea;
import com.ibm.team.process.common.IRole;
import com.ibm.team.repository.client.ITeamRepository;
import com.ibm.team.repository.client.ITeamRepository.ILoginHandler;
import com.ibm.team.repository.client.ITeamRepository.ILoginHandler.ILoginInfo;
import com.ibm.team.repository.client.TeamPlatform;
import com.ibm.team.repository.common.IContributor;
import com.ibm.team.repository.common.TeamRepositoryException;
/**
* Automates setting up the RTC Extension workshop. Class to set up a project,
* users and the SCM component for a project Extracts given files into the SCM
* system.
*
*/
public class AddUserToProjectArea {
/**
* Basic constructor.
*
*/
public AddUserToProjectArea() {
super();
}
/**
* Main Entry Point run the whole server setup
*
* @throws Exception
*/
public static void main(String[] args) throws Exception {
boolean result;
System.out.println("Starting Team Platform");
if (!TeamPlatform.isStarted())
TeamPlatform.startup();
try {
System.out.println("Team Platform started");
AddUserToProjectArea setupParea = new AddUserToProjectArea();
result = setupParea.run(args);
} catch (TeamRepositoryException x) {
x.printStackTrace();
result = false;
} finally {
TeamPlatform.shutdown();
}
if (!result)
System.exit(1);
}
/**
* This actually does the work
*
* @return
* @throws Exception
*/
private boolean run(String[] args) throws Exception {
if (args.length != 5) {
System.out
.println("Usage: CreateProjectArea [repositoryURI] [adminUserId] [adminPassword] [projectAreaName] [addUserID] [addRoleID]");
return false;
}
// Get the parameters
String repositoryURI = args[0];
String adminUserId = args[1];
String adminPassword = args[2];
String projectAreaName = args[3];
String addUserID = args[4];
String addRoleID = args[5];
IProgressMonitor monitor = new NullProgressMonitor();
ITeamRepository teamRepository = logIntoTeamRepository(repositoryURI,
adminUserId, adminPassword, monitor);
IProcessItemService service = (IProcessItemService) teamRepository
.getClientLibrary(IProcessItemService.class);
URI uri = URI.create(projectAreaName.replaceAll(" ", "%20"));
IProjectArea area = (IProjectArea) service.findProcessArea(uri,
IProcessItemService.ALL_PROPERTIES, monitor);
if (area == null) {
System.out.println("Project Area not found: " + projectAreaName);
return false;
}
addUsersAndRoles(teamRepository, area, addUserID, addRoleID, monitor);
System.out.println("Success");
return true;
}
/**
* Adds users and roles to a project area.
*
* @return
* @throws TeamRepositoryException
*/
private IProjectArea addUsersAndRoles(ITeamRepository teamRepository,
IProjectArea area, String userID, String roleID, IProgressMonitor monitor)
throws TeamRepositoryException {
IProcessItemService service = (IProcessItemService) teamRepository
.getClientLibrary(IProcessItemService.class);
area = (IProjectArea) service.getMutableCopy(area);
System.out.println("Trying to add member with roles: "
+ roleID + " to Project Area" + area.getName());
IContributor user = teamRepository.contributorManager().fetchContributorByUserId(userID, monitor);
IRole role = getRole(area, roleID, monitor);
area.addAdministrator(user);
area.addMember(user);
area.addRoleAssignments(user, new IRole[] { role });
IProcessItem[] items = service.save(new IProcessItem[] { area },
monitor);
System.out.println("Users with Roles added to " + area.getName());
return area;
}
/**
* Gets a role by its ID.
*
* @return
* @throws TeamRepositoryException
*/
private IRole getRole(IProcessArea area, String roleID,
IProgressMonitor monitor) throws TeamRepositoryException {
ITeamRepository repo = (ITeamRepository) area.getOrigin();
IProcessItemService service = (IProcessItemService) repo
.getClientLibrary(IProcessItemService.class);
IClientProcess clientProcess = service.getClientProcess(area, monitor);
IRole[] availableRoles = clientProcess.getRoles(area, monitor);
for (int i = 0; i < availableRoles.length; i++) {
IRole role = availableRoles[i];
// IRole2 role2 = (IRole2)role;
// role2.getRoleName();
if (role.getId().equalsIgnoreCase(roleID))
return role;
}
throw new IllegalArgumentException("Couldn't find roles");
}
/**
* Manages the login process.
*
* @return
* @throws TeamRepositoryException
*/
private ITeamRepository logIntoTeamRepository(String repositoryURI,
String userId, String password, IProgressMonitor monitor)
throws TeamRepositoryException {
System.out.println("Trying to log into repository: " + repositoryURI);
ITeamRepository teamRepository = TeamPlatform
.getTeamRepositoryService().getTeamRepository(repositoryURI);
teamRepository.registerLoginHandler(new LoginHandler(userId, password));
teamRepository.login(monitor);
System.out.println("Login succeeded.");
return teamRepository;
}
/**
* Login Handler implementation
*
*/
private static class LoginHandler implements ILoginHandler, ILoginInfo {
private String fUserId;
private String fPassword;
private LoginHandler(String userId, String password) {
fUserId = userId;
fPassword = password;
}
public String getUserId() {
return fUserId;
}
public String getPassword() {
return fPassword;
}
public ILoginInfo challenge(ITeamRepository repository) {
return this;
}
}
}
Comments
Jorge Alarcon
commented May 04 '16, 12:41 p.m.
hi Ralph
|
Ralph Schoon (63.5k●3●36●46)
| answered May 04 '16, 7:05 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
You have to do the import from LDAP first. Once the user is member of the project area, you could use the Plain Java Client Libraries to add the user to all project areas.
I don't have code for everything, but most parts.
Setup API work: https://rsjazz.wordpress.com/2015/09/30/learning-to-fly-getting-started-with-the-rtc-java-apis/
Iterate all project areas: https://rsjazz.wordpress.com/2012/12/09/analyzing-a-aroject-areas-members-and-roles-using-the-plain-java-client-libraries/
Adding users to project areas: https://rsjazz.wordpress.com/2013/09/18/deploying-templates-and-creating-projects-using-the-plain-java-clients-library/
Also see snippet 3 shipped with the plain java client libraries.
|
Hi Jorge,
There is a repotools -importUsers command which allows you to set user roles and licenses. You can find more in the documentation: https://jazz.net/help-dev/clm/index.jsp?re=1&topic=/com.ibm.jazz.install.doc/topics/r_repotools_importusers.html&scope=null Let us know if this is what you were looking for Comments Hi
Krzysztof Kaźmierczyk
commented May 04 '16, 5:59 a.m.
Hi Jorge,
Jorge Alarcon
commented May 04 '16, 12:40 p.m.
Hi
|
Your answer
Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.