How to connect to RTC Rest API from external web application ?
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
One answer
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);
}