an exception when unassign a licesne i get com.ibm.team.repository.service.compatibility.util.http.CrossServerHttpClient$RestCommunicationException
hello , I am trying to unassign a license and getting this exception:
com.ibm.team.repository.service.compatibility.util.http.CrossServerHttpClient$RestCommunicationException
this is my code:
NullProgressMonitor monitor = new NullProgressMonitor();
LoginHandler login = new LoginHandler("????", "?????");
teamRepository.registerLoginHandler(login);
try {
teamRepository.login(monitor);
} catch (TeamRepositoryException e) {
e.printStackTrace();
System.out.print("this is not good");
}
ILicenseAdminService licenseAdmin = (ILicenseAdminService) ((TeamRepository) teamRepository).getServiceInterface(ILicenseAdminService.class);
System.out.print(licenseAdmin.toString());
//IContributorManager contributorManager = teamRepository.contributorManager();
IContributorHandle aUser;
try {
aUser = teamRepository.contributorManager().fetchContributorByUserId("user_id", null);
licenseAdmin.unassignLicense(aUser, "_0yFhJOGeEeSqbuNMcGcLkA"); // - exception !!
} catch (TeamRepositoryException e1) {
System.out.print(e1.toString());
e1.printStackTrace();
}
many thanks
4 answers
Dependent of this being a client side automation or a server extension the call to get the license manager would be:
Client API:
ILicenseAdminService licAdin = (ILicenseAdminService)teamRepository.getClientLibrary(ILicenseAdminService.class);
licAdin.unassignLicense(contributorHande, licenseId);
Server API (assuming you extend AbstractService):
ILicenseAdminService licAdin = this.getService(ILicenseAdminService.class);
licAdin.unassignLicense(contributorHande, licenseId);
Provided the license ID would be valid, I would assume that this works.
Client API:
ILicenseAdminService licAdin = (ILicenseAdminService)teamRepository.getClientLibrary(ILicenseAdminService.class);
licAdin.unassignLicense(contributorHande, licenseId);
Server API (assuming you extend AbstractService):
ILicenseAdminService licAdin = this.getService(ILicenseAdminService.class);
licAdin.unassignLicense(contributorHande, licenseId);
Provided the license ID would be valid, I would assume that this works.
Fascinating and you are right. The LicenseAdminService does not seem to be a regular client library and getClientLibrary does not work.
This code works for me:
Where the user licenseuser is the ID as string, and licenseID is something like "com.ibm.team.rtc.developer".
I got the licenseID's this way:
This code works for me:
ILicenseAdminService licAdin = (ILicenseAdminService) ((IClientLibraryContext) teamRepository).getServiceInterface(ILicenseAdminService.class); IContributor licenseUser = teamRepository.contributorManager().fetchContributorByUserId(licenseuser, monitor); licAdin.unassignLicense(licenseUser, licenseID);
Where the user licenseuser is the ID as string, and licenseID is something like "com.ibm.team.rtc.developer".
I got the licenseID's this way:
/** * Build the license map only once * * @param licenseService * @param monitor * @return * @throws TeamRepositoryException */ private static HashMapgetLicenseMapper( ILicenseAdminService licenseService, IProgressMonitor monitor) throws TeamRepositoryException { if (fLicenseMapp != null) { return fLicenseMapp; } fLicenseMapp = new HashMap (); IContributorLicenseType[] types = licenseService.getLicenseTypes(); for (IContributorLicenseType iContributorLicenseType : types) { // System.out.println("Lic:"+iContributorLicenseType.getId()+" " + // iContributorLicenseType.getName() + " " + // iContributorLicenseType.getProductName()+ " " + // iContributorLicenseType.getEditionName() +" " + // iContributorLicenseType.getDescription()); fLicenseMapp.put(iContributorLicenseType.getId(), iContributorLicenseType.getProductName() + " " + iContributorLicenseType.getName()); } return fLicenseMapp; }
This is my working code:
I call it with parameters:
"https://clm.example.com:9443/jts" "adminID" "adminPasswd" "userToDeleteLicense" "com.ibm.rtc.developer-iep.floating"
I use ILicenseAdminService as you did above. Note, it apears NOT to be a typical ClientLibrary, so you need to get it with the code you show in your original question.
I call it with parameters:
"https://clm.example.com:9443/jts" "adminID" "adminPasswd" "userToDeleteLicense" "com.ibm.rtc.developer-iep.floating"
I use ILicenseAdminService as you did above. Note, it apears NOT to be a typical ClientLibrary, so you need to get it with the code you show in your original question.
/******************************************************************************* * Licensed Materials - Property of IBM * (c) Copyright IBM Corporation 2008. All Rights Reserved. * * Note to U.S. Government Users Restricted Rights: Use, duplication or * disclosure restricted by GSA ADP Schedule Contract with IBM Corp. *******************************************************************************/ package com.ibm.team.workitem.ide.ui.example; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; 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.client.util.IClientLibraryContext; import com.ibm.team.repository.common.IContributor; import com.ibm.team.repository.common.ILicenseAdminService; import com.ibm.team.repository.common.TeamRepositoryException; /** * Example code, see * https://jazz.net/wiki/bin/view/Main/ProgrammaticWorkItemCreation. */ public class LicenseDelete { 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 != 5) { System.out .println("Usage: LicenseDelete"); System.out.println(" for example 'bob' "); System.out.println(" for example 'com.ibm.team.rtc.developer' "); return false; } IProgressMonitor monitor = new NullProgressMonitor(); String repositoryURI = args[0]; String userId = args[1]; String password = args[2]; String licenseuser = args[3]; String licenseID = args[4]; ITeamRepository teamRepository = TeamPlatform .getTeamRepositoryService().getTeamRepository(repositoryURI); teamRepository.registerLoginHandler(new LoginHandler(userId, password)); teamRepository.login(null); ILicenseAdminService licAdin = (ILicenseAdminService) ((IClientLibraryContext) teamRepository).getServiceInterface(ILicenseAdminService.class); IContributor licenseUser = teamRepository.contributorManager().fetchContributorByUserId(licenseuser, monitor); licAdin.unassignLicense(licenseUser, licenseID); teamRepository.logout(); return true; } }
still no go.
I still get the original error CrossServerHttpClient$RestCommunicationException with a cause reason null.
here is my code :
import java.util.HashMap;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import com.ibm.team.filesystem.client.internal.rest.util.LoginUtil.LoginHandler;
import com.ibm.team.repository.client.IContributorManager;
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.client.internal.TeamRepository;
import com.ibm.team.repository.client.util.IClientLibraryContext;
import com.ibm.team.repository.common.IContributorHandle;
import com.ibm.team.repository.common.IContributorLicenseType;
import com.ibm.team.repository.common.ILicenseAdminService;
import com.ibm.team.repository.common.ILicenseType;
import com.ibm.team.repository.common.TeamRepositoryException;
import com.ibm.team.repository.common.IContributor;
import com.ibm.team.repository.common.TeamRepositoryException;
//import com.ibm.team.rtc.foundation.api.common.progress.IProgressMonitor;
public class first
{
public static ITeamRepository getTeamRepository() {
String repositoryURI = "https://????????????:9443/ccm";
TeamPlatform.startup();
ITeamRepository teamRepository = TeamPlatform.getTeamRepositoryService().getTeamRepository(repositoryURI);
return teamRepository;
}
public static void main (String[] args){
ITeamRepository test = getTeamRepository();
assignClientAccessLicenseToUser(test);
System.out.print(test.toString());
}
public static void assignClientAccessLicenseToUser(ITeamRepository teamRepository)
{
NullProgressMonitor monitor = new NullProgressMonitor();
LoginHandler login = new LoginHandler("?????", "?????");
teamRepository.registerLoginHandler(login);
try {
teamRepository.login(null);
} catch (TeamRepositoryException e) {
e.printStackTrace();
System.out.print("this is not good");
}
ILicenseAdminService licenseAdmin = (ILicenseAdminService) ((IClientLibraryContext) teamRepository).getServiceInterface(ILicenseAdminService.class);
try {
IContributorHandle aUser = teamRepository.contributorManager().fetchContributorByUserId("?????", monitor);
licenseAdmin.unassignLicense(aUser, "com.ibm.team.rtc.?????????????");
} catch (TeamRepositoryException e1) {
System.out.print(e1.toString());
e1.printStackTrace();
}
}
}