Need assistance with RTC Query Java Code
![]()
Hopefully Ralph Schoon will see this. I used the code he provided from his blog work items for automation, but receive a few compilation errors and I was wondering if I could get help resolving those.
public class QueryRTCRunSave { public static void main(String args[]) { //creates a progress monitor IProgressMonitor monitor = new NullProgressMonitor(); //stores login credentials in strings String repositoryURI = "https://rtc.domain.com/jazz"; String userId = "myid"; String password = "****"; //client initializes itself TeamPlatform.startup(); try { ITeamRepository repo = logIntoTeamRepository(repositoryURI, userId, password, monitor); repo.logout(); } catch (TeamRepositoryException e) { //this will handle any repository exceptions such as login problems e.printStackTrace(); //this shuts down the platform } finally { TeamPlatform.shutdown(); } } private static ITeamRepository logIntoTeamRepository(String repositoryURI, String userId, String password, IProgressMonitor monitor) throws TeamRepositoryException { System.out.println("Trying to log into repository: " + repositoryURI); TeamPlatform.startup(); ITeamRepository teamRepository = TeamPlatform .getTeamRepositoryService().getTeamRepository(repositoryURI); teamRepository.registerLoginHandler(new LoginHandler(userId, password)); teamRepository.login(monitor); System.out.println("Login succeeded."); return teamRepository; } 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; } } /* Do all of my work with RTC servers here. */ //calls the method findpersonalquery IQueryDescriptor query = findPersonalQuery(projectArea, "All Work Items", monitor);<-- projectArea cannot be resolved to a variable //method that Finds personal queries stored in repository by project area,name public static IQueryDescriptor findPersonalQuery(IProjectArea projectArea, String queryName, IProgressMonitor monitor) throws TeamRepositoryException { // Get the required client libraries ITeamRepository teamRepository = (ITeamRepository)projectArea.getOrigin(); IWorkItemClient workItemClient = (IWorkItemClient) teamRepository.getClientLibrary( IWorkItemClient.class); IQueryClient queryClient = workItemClient.getQueryClient(); // Get the current user. IContributor loggedIn = teamRepository.loggedInContributor(); IQueryDescriptor queryToRun = null; // Get all queries of the user in this project area. List queries = queryClient.findPersonalQueries( projectArea.getProjectArea(), loggedIn, QueryTypes.WORK_ITEM_QUERY, IQueryDescriptor.FULL_PROFILE, monitor); // Find a query with a matching name for (Iterator iterator = queries.iterator(); iterator.hasNext();) { IQueryDescriptor iQueryDescriptor = (IQueryDescriptor) iterator.next(); if (iQueryDescriptor.getName().equals(queryName)) { queryToRun = iQueryDescriptor; break; } } return queryToRun; } //to get unresolved query results stored, you pass query as a parameter IQueryResult unresolvedResults = queryClient.getQueryResults(queryToRun);<-- queryClient cannot be resolved, queryToRun cannot be resolved to a variable //calls the method processUnresolvedResults processUnresolvedResults(projectArea, unresolvedResults, loadProfile, monitor);<-- return type for this method is missing //method that processes the unresolvedResults and stores in file public static void processUnresolvedResults(IProjectArea projectArea , IQueryResult results, ItemProfile profile, IProgressMonitor monitor) throws TeamRepositoryException { // Get the required client libraries ITeamRepository teamRepository = (ITeamRepository)projectArea.getOrigin(); IWorkItemClient workItemClient = (IWorkItemClient)teamRepository.getClientLibrary(IWorkItemClient.class); IAuditableCommon auditableCommon = (IAuditableCommon)teamRepository.getClientLibrary(IAuditableCommon.class); long processed = 0; while (results.hasNext(monitor)) {<--has next method in IQueryResult is not applicable for arguments IProgressMonitor IResult result = (IResult) results.next(monitor);<--next(IProgressMonitor)is undefined for type IQueryResult IWorkItem workItem = auditableCommon.resolveAuditable( (IAuditableHandle) result.getItem(), profile, monitor); // Do something with the work item here(save to csv or xml) processed++; } System.out.println("Processed results: " + processed); } } |
3 answers
![]()
and another answer built from Ralph's example
a full workitem example here https://jazz.net/forum/questions/94776/assertionfailedexception-problem-with-getting-the-values-of-attributes second post. watch out for the forum adding extra double quotes down near the bottom and lowercasing the datatype names. this will print out all the attributes of all the workitems returned in the query. takes 5 parms repo, userid, password, projectname, queryname |
![]()
You must initialize projectArea
I've attached similar method which find shared query
IProjectArea projectArea = null; |
![]()
Ralph Schoon (62.3k●3●36●43)
| answered Mar 28 '14, 9:48 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Hi Brandy,
if you have missing code pieces, try searching the blog e.g. for projectArea. A lot of the code uses the same infrastructure. Links to this are also provided: e.g. the wiki entry on Programmatic Work Item Creation or https://jazz.net/wiki/bin/view/Main/QueryDevGuide in https://rsjazz.wordpress.com/2012/10/29/using-work-item-queris-for-automation/ Unfortunately I can not package all the code and sometimes the blog software also interferes with the code. Comments Thank you Ralph, I will do the blog search I totally understand about not being able to package it all. |