Is it possible to retrieve license information using the plain java API?
Using the plain java API I'd like to get information about what licenses a particular IContributor has assigned to them. Looking at the javadocs, the ILicenseAdminService interface provides the methods I'm after, however as far as I can tell this is only available to server side participants because calling ITeamRepository#getClientLibrary(ILicenseAdminService.class) returns null.
Is there any way of getting a handle to an ILicenseAdminService instance using the client-side java API, or are there any alternative APIs that would allow me to achieve the same result?
Thanks
Accepted answer
Here is some code I am using on the client to allocate a license
public boolean allocateLicense(Contributor contributor, String license) throws Exception
{
ITeamRepository teamRepository = getTeamRepository(); // However you are getting access to this...
ILicenseAdminService licAdminService =
(ILicenseAdminService) ((TeamRepository) teamRepository).getServiceInterface(ILicenseAdminService.class);
if (contributor == null)
{
throw new Exception("Contributor is null");
}
if (license == null)
{
System.err.println("Invalid license");
throw new Exception("Invalid license");
}
licAdminService.assignLicense(contributor, license);
return true;
}
3 other answers
This does not work with the RTC Plain Java API.
There's something like
There's something like
repository.getClientLibrary(ILicenseClient.class).. however, it does not seem to be too useful.
Comments
it works for me. I wrote getTeamRepository() method, but the rest is Plain Java lib calls.
Found out - the trick is that you have to do a cast to internal API:
Your instance of
com.ibm.team.repository.client.ITeamRepository
must be cast to
com.ibm.team.repository.client.internal.TeamRepositoryas this implements com.ibm.team.repository.client.util.IClientLibraryContext.
Then the necessary method getServiceInterface(Class) will be available and works as described above.
This took me some time to figure out and is not nice, as it depends on internal non-public API.
Here a working example with downloadable code: https://rsjazz.wordpress.com/2017/03/29/managing-contributor-licenses-using-the-plain-java-client-libraries/