It's all about the answers!

Ask a question

How to archive a user with REST api


Anders Truelsen (1622020) | asked Nov 18 '11, 6:51 a.m.
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?

Accepted answer


permanent link
Ralph Schoon (61.8k33643) | answered Nov 21 '11, 8:49 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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();
}
}
Anders Truelsen selected this answer as the correct answer

Comments
Anders Truelsen commented Sep 20 '12, 8:37 a.m.

Just what the doctor ordered :-)

8 other answers



permanent link
pugazhenthi samidurai (26423742) | answered Mar 09 '12, 6:58 a.m.
Hi ,

i want delete workitems based on query result.

Kindly help on this.

Thanks

Pugazh

permanent link
Ralph Schoon (61.8k33643) | answered Mar 09 '12, 7:23 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
You can use the plain java client libraries to run a query and iterate the result.

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.

permanent link
pugazhenthi samidurai (26423742) | answered Mar 12 '12, 1:23 a.m.
Hi,

i am new to RTC. so i am unable to execute this code.

could you able to given me full java file and the instruction for executing this file.



Thanks ,

Pugazh

permanent link
pugazhenthi samidurai (26423742) | answered Mar 12 '12, 3:23 a.m.
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

permanent link
Ralph Schoon (61.8k33643) | answered Mar 13 '12, 8:09 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Please follow https://jazz.net/library/article/784 and https://jazz.net/wiki/bin/view/Main/RTCSDK20_DevelopmentEnvironmentSetup to setup your project for development.

I can't debug your code. Sorry.

permanent link
pugazhenthi samidurai (26423742) | answered Mar 17 '12, 6:42 a.m.
Hi Ralph ,

Thank you very.

I have installed the plain java library

Now its working fine.

Thanks,

Pugazh

permanent link
khayati ohri (1644) | answered Mar 29 '12, 11:23 a.m.
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 ?

permanent link
khayati ohri (1644) | answered Mar 29 '12, 11:28 a.m.
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 ?

Your answer


Register or to post your answer.