Accessing Custom Fields set in RTC for a Project using Rest Services/API
I would like to retrieve the custom fields set for a Project in RTC(version 3.0.1.3) and I am currently trying to use API to do this :
public void getCustomAttributes() {
IProgressMonitor myProgressMonitor = new CustomProgressMonitor(); // Create a progress monitor
final String userId = "";
final String password = "";
String repoUri = "";
TeamPlatform.startup();
ITeamRepository repo = TeamPlatform.getTeamRepositoryService().getTeamRepository(repoUri);
repo.registerLoginHandler(new ILoginHandler2() {
@Override
public ILoginInfo2 challenge(ITeamRepository repo) {
return new UsernameAndPasswordLoginInfo(userId, password);
}
});
try {
repo.login(myProgressMonitor);
} catch (TeamRepositoryException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
TeamPlatform.shutdown();
}
IWorkItemClient workItemClient = (IWorkItemClient) repo.getClientLibrary(IWorkItemClient.class);
try {
IWorkItem workItem = workItemClient.findWorkItemById(18588, IWorkItem.FULL_PROFILE, myProgressMonitor);
List custAttributeHandles = workItem.getCustomAttributes();
for (Iterator iterator = custAttributeHandles.iterator(); iterator.hasNext();) {
IAttributeHandle iAttributeHandle = (IAttributeHandle) iterator.next();
IAttribute iAttribute = (IAttribute) repo
.itemManager().fetchCompleteItem(
iAttributeHandle, IItemManager.DEFAULT ,myProgressMonitor);
LOGGER.info(iAttribute.getDisplayName());
}
} catch (TeamRepositoryException e) {
e.printStackTrace();
}
repo.logout();
}
The work item with ID 18588(it has been hard-coded int he above snippet) has a value set for a custom field(say, 'Re-open count' ). I have set the correct userId, password and repoUrl for access.
Issue :
The code won't run because there is a NoSuchMethod exception thrown for a class(org/eclipse/core/internal/registry/ExtensionRegistry) whose containing jar is in my Project's build path. I don't see any issue there but I keep getting this exception. Also, hitting the Simple query URL for the Project, exposed by OSLC, retrieves ONLY the built-in fields for the work items such as 'foundIn','description','title',...
Question :
Is the above code snippet the right way to retrieve custom fields? Or is it possible to do the same using rest services.
Any guidance would be of great help. Thanks in advance.
Comments
sam detweiler
Mar 24 '14, 9:02 a.m.my sample code here, post 3.