How to add members to Project Area in Rational Design Manager programmatically
2 answers
For RTC, QM, RDNG it is possibl eto use the RTC Plain Java Client libraries and the code would be the same like below. I have no example for OSLC. Most likely there is no OSLC spec. There might be REST services you could use.
/**
* Adds users and roles to a project area.
*
* @param teamRepository
* @param area
* @param monitor
* @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);
//area.addAdministrator(user);
area.addMember(user);
IRole role = getRole(area, roleID, monitor);
area.addRoleAssignments(user, new IRole[] { role });
@SuppressWarnings("unused")
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.
*
* @param area
* @param roleID
* @param monitor
* @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");
}
/**
* Adds users and roles to a project area.
*
* @param teamRepository
* @param area
* @param monitor
* @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);
//area.addAdministrator(user);
area.addMember(user);
IRole role = getRole(area, roleID, monitor);
area.addRoleAssignments(user, new IRole[] { role });
@SuppressWarnings("unused")
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.
*
* @param area
* @param roleID
* @param monitor
* @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");
}
Comments
PS: the code above would work for team areas or, if you use IProcessArea for both.
Thanks Ralph for the answer.
But what about RDM ? Can i use the same RTC API's for RDM as well ?
I haven't tested RDM because I have not installed it. My assumption would be it uses the same Jazz core API, but I leave it to the reader to test that.
This is the response from IBM David Hirsch
RDM SDK currently doesn't support creating project areas or adding members to it.
The creation of project areas is provided by jfs.
RTC SDK (to my best knowledge) is using the jfs client libraries to provide the service of manipulating projectareas.
Currently dm sdk is not build on top of the jfs clients. As a result we cannot provide this service out of the box.
RDM SDK currently doesn't support creating project areas or adding members to it.
The creation of project areas is provided by jfs.
RTC SDK (to my best knowledge) is using the jfs client libraries to provide the service of manipulating projectareas.
Currently dm sdk is not build on top of the jfs clients. As a result we cannot provide this service out of the box.
OSLC is a linking protocol, it doesn't play a role when creating project areas.