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

How to connect to RTC Rest API from external web application ?

Hello,

         I'm developing a web application using Spring MVC and Hibernate. I want to access the RTC workitems and perform a search operation which can display the result on the web page. For this I m planning to use the Java API. So, how can I authenticate and get access to the RTC and search the WorkItems. Are there any examples which can help me out to do so. I m an entry level developer, so this question might be nooby.

Thanks
Sujith

0 votes



One answer

Permanent link
 Hi Sujith,

for logging into RTC take a look at Snippet 1 that comes along the plain-java-api.

For the query part here is the code I used to find a query, execute it and retrieve the results as a csv file:

  

private IQueryDescriptor findQuery(final String queryName) throws Exception {

IWorkItemClient workItemClient = (IWorkItemClient) teamRepository.getClientLibrary(IWorkItemClient.class);

IQueryClient queryClient = workItemClient.getQueryClient();


List<IProjectAreaHandle> sharingTargets = new ArrayList<IProjectAreaHandle>();

sharingTargets.add(projectArea);


List<IQueryDescriptor> personalQueries = queryClient.findPersonalQueries(projectArea,

(IContributorHandle) teamRepository.loggedInContributor().getItemHandle(), QueryTypes.WORK_ITEM_QUERY,

QueryDescriptor.FULL_PROFILE, monitor);


for (IQueryDescriptor query : personalQueries) {

if (queryName.equalsIgnoreCase(query.getName())) {

logger.info("Query '" + queryName + "' has been found: " + query);

return query;

}

}


return null;

}


private Map<String, List<String>> createParameters(final IQueryDescriptor query) throws TeamRepositoryException {

ArrayList<String> columns = new ArrayList<String>();

Statement statement = (Statement) query.getExpression();

for (String column : statement.getSelectClause().getColumnIdentifiers()) {

columns.add(column);

}


HashMap<String, List<String>> parameters = new HashMap<String, List<String>>();

parameters.put(ExportLocations.URL_PARAM_COLUMNS, columns);

parameters.put(ExportLocations.URL_PARAM_LINK_STYLE,

Collections.singletonList(ExportLocations.URL_PARAM_LINK_STYLE_ABSOLUTE));

parameters.put(ExportLocations.URL_PARAM_FIELD_DELIMITER, Collections.singletonList("\t"));

parameters.put(ExportLocations.URL_PARAM_ENCODING, Collections.singletonList("UTF-16LE"));

parameters.put(ExportLocations.URL_PARAM_QUOTE_STRINGS, Collections.singletonList(Boolean.toString(true)));

parameters.put(ExportLocations.URL_PARAM_HEADERS_INCLUDED, Collections.singletonList(Boolean.toString(true)));


return parameters;

}


private void fetchContents(final Location location, final String exportFileName) throws Exception {

File file = new File(exportFileName);

logger.debug("Work Items are exported to: " + file.getAbsolutePath());


OutputStream outputStream = new FileOutputStream(file);

ITeamRestServiceClient restClient = ((TeamRepository) teamRepository).getItemRestService();

IRestClientConnection connection = restClient.getConnection(location);

Response response = connection.doGet();

InputStream inputStream = response.getResponseStream();

ClientUtils.copyStream(inputStream, outputStream, monitor);

}

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,939

Question asked: Aug 20 '14, 2:04 p.m.

Question was seen: 3,980 times

Last updated: Oct 01 '14, 11:43 a.m.

Confirmation Cancel Confirm