How to archive a user with REST api
Accepted answer
New users are imported automatically from LDAP, but deleting users is manual process.
Is the any way I can archive a user and thus release his license with the REST api?
Hi Anders,
I searched the SDK and here is the code that should work also with the Plain Java Client Library.
/**
* Example code, see
* https://jazz.net/wiki/bin/view/Main/ProgrammaticWorkItemCreation.
*/
public class ArchiveUser {
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;
}
}
public static void main(String[] args) {
boolean result;
TeamPlatform.startup();
try {
result = run(args);
} catch (TeamRepositoryException x) {
x.printStackTrace();
result = false;
} finally {
TeamPlatform.shutdown();
}
if (!result)
System.exit(1);
}
private static boolean run(String[] args) throws TeamRepositoryException {
if (args.length != 4) {
System.out
.println("Usage: ArchiveUser <repositoryURI> <userId> <password> <userToArchive>");
return false;
}
String repositoryURI = args[0];
String userId = args[1];
String password = args[2];
String archiveID = args[3];
ITeamRepository teamRepository = TeamPlatform
.getTeamRepositoryService().getTeamRepository(repositoryURI);
teamRepository.registerLoginHandler(new LoginHandler(userId, password));
teamRepository.login(null);
IContributor user = teamRepository.contributorManager().fetchContributorByUserId(
archiveID, null);
IContributor archiveIDWorkingCopy = (IContributor) user.getWorkingCopy();
archiveIDWorkingCopy.setArchived(true);
teamRepository.contributorManager().saveContributor(archiveIDWorkingCopy, null);
System.out.println("Archived user: " + archiveID + ".");
teamRepository.logout();
}
}
8 other answers
You can use the plain java client libraries to run a query and iterate the result.
this code should delete an IWorkitem.
I did not try this code myself.
this code should delete an IWorkitem.
IWorkItemClient workItemClient = (IWorkItemClient) ((ITeamRepository) workItem
.getOrigin()).getClientLibrary(IWorkItemClient.class);
IWorkItemWorkingCopyManager wcm = workItemClient.getWorkItemWorkingCopyManager();
wcm.connect(workItem, IWorkItem.FULL_PROFILE, null);
try {
WorkItemWorkingCopy workItemWorkingCopy = wcm.getWorkingCopy(workItem);
workItemWorkingCopy.delete(monitor);
IDetailedStatus s = destWorkingCopy.save(null);
if (!s.isOK()) {
throw new TeamRepositoryException("Error saving work item",
s.getException());
}
} finally {
wcm.disconnect(dest);
}
I did not try this code myself.
Hi Ralph Schoon,
check my code below.
i am having error in the following places
1. workItem.getOrigin()
2. monitor
3. destWorkingCopy
4. dest
import com.ibm.team.repository.client.ITeamRepository;
import com.ibm.team.repository.client.TeamPlatform;
import com.ibm.team.repository.common.TeamRepositoryException;
import com.ibm.team.workitem.client.IDetailedStatus;
import com.ibm.team.workitem.client.IWorkItemClient;
import com.ibm.team.workitem.client.IWorkItemWorkingCopyManager;
import com.ibm.team.workitem.client.WorkItemWorkingCopy;
import com.ibm.team.workitem.common.model.IWorkItem;
public class QueryDeletion {
public static void main(String args[]) throws TeamRepositoryException
{
boolean result;
TeamPlatform.startup();
try {
result = run(args);
} finally {
TeamPlatform.shutdown();
}
if (!result)
System.exit(1);
}
private static boolean run(String[] args) {
// TODO Auto-generated method stub
IWorkItemClient workItemClient = (IWorkItemClient) ((ITeamRepository) workItem.getOrigin()).getClientLibrary(IWorkItemClient.class);
IWorkItemWorkingCopyManager wcm = workItemClient.getWorkItemWorkingCopyManager();
wcm.connect(workItem, IWorkItem.FULL_PROFILE, null);
try {
WorkItemWorkingCopy workItemWorkingCopy = wcm.getWorkingCopy(workItem);
workItemWorkingCopy.delete(monitor);
IDetailedStatus s = destWorkingCopy.save(null);
if (!s.isOK()) {
throw new TeamRepositoryException("Error saving work item",
s.getException());
}
} finally {
wcm.disconnect(dest);
}
return false;
}
}
Thanks ,
Pugazh s
check my code below.
i am having error in the following places
1. workItem.getOrigin()
2. monitor
3. destWorkingCopy
4. dest
import com.ibm.team.repository.client.ITeamRepository;
import com.ibm.team.repository.client.TeamPlatform;
import com.ibm.team.repository.common.TeamRepositoryException;
import com.ibm.team.workitem.client.IDetailedStatus;
import com.ibm.team.workitem.client.IWorkItemClient;
import com.ibm.team.workitem.client.IWorkItemWorkingCopyManager;
import com.ibm.team.workitem.client.WorkItemWorkingCopy;
import com.ibm.team.workitem.common.model.IWorkItem;
public class QueryDeletion {
public static void main(String args[]) throws TeamRepositoryException
{
boolean result;
TeamPlatform.startup();
try {
result = run(args);
} finally {
TeamPlatform.shutdown();
}
if (!result)
System.exit(1);
}
private static boolean run(String[] args) {
// TODO Auto-generated method stub
IWorkItemClient workItemClient = (IWorkItemClient) ((ITeamRepository) workItem.getOrigin()).getClientLibrary(IWorkItemClient.class);
IWorkItemWorkingCopyManager wcm = workItemClient.getWorkItemWorkingCopyManager();
wcm.connect(workItem, IWorkItem.FULL_PROFILE, null);
try {
WorkItemWorkingCopy workItemWorkingCopy = wcm.getWorkingCopy(workItem);
workItemWorkingCopy.delete(monitor);
IDetailedStatus s = destWorkingCopy.save(null);
if (!s.isOK()) {
throw new TeamRepositoryException("Error saving work item",
s.getException());
}
} finally {
wcm.disconnect(dest);
}
return false;
}
}
Thanks ,
Pugazh s
Can some tell me how to import User from LDAP to RTC server programmetically. I looked into call mechanism at RTC WebClient .It uses AdminRestService and IExternalUserRegistryRestService both of which have discouraged access over plugins\com.ibm.team.repository.service_1.1.1.v20110524_1821\repository_service.jar.
Can someone tell me an alternative way to import LDAP User to RTC server ?
Can someone tell me an alternative way to import LDAP User to RTC server ?
Can some tell me how to import User from LDAP to RTC server programmetically. I looked into call mechanism at RTC WebClient .It uses AdminRestService and IExternalUserRegistryRestService both of which have discouraged access over plugins\com.ibm.team.repository.service_1.1.1.v20110524_1821\repository_service.jar.
Can someone tell me an alternative way to import LDAP User to RTC server ?
Can someone tell me an alternative way to import LDAP User to RTC server ?