Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

How to archive a user with REST api

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?

0 votes


Accepted answer

Permanent link
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

1 vote

Comments

Just what the doctor ordered :-)


8 other answers

Permanent link
Hi ,

i want delete workitems based on query result.

Kindly help on this.

Thanks

Pugazh

0 votes


Permanent link
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.

0 votes


Permanent link
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

0 votes


Permanent link
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

0 votes


Permanent link
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.

0 votes


Permanent link
Hi Ralph ,

Thank you very.

I have installed the plain java library

Now its working fine.

Thanks,

Pugazh

0 votes


Permanent link
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 ?

0 votes


Permanent link
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 ?

0 votes

Your answer

Register or log in to post 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,938

Question asked: Nov 18 '11, 6:51 a.m.

Question was seen: 8,972 times

Last updated: Sep 20 '12, 8:37 a.m.

Confirmation Cancel Confirm