use of org.eclipse.sw360.exporter.ReleaseExporter in project sw360portal by sw360.
the class ProjectPortlet method exportReleasesSpreadsheet.
private void exportReleasesSpreadsheet(ResourceRequest request, ResourceResponse response) {
final User user = UserCacheHolder.getUserFromRequest(request);
try {
String id = request.getParameter(PROJECT_ID);
ProjectService.Iface client = thriftClients.makeProjectClient();
Project project = null;
if (!isNullOrEmpty(id)) {
project = client.getProjectById(id, user);
}
if (project != null) {
List<ReleaseClearingStatusData> releaseStringMap = client.getReleaseClearingStatuses(id, user);
List<Release> releases = releaseStringMap.stream().map(ReleaseClearingStatusData::getRelease).sorted(Comparator.comparing(SW360Utils::printFullname)).collect(Collectors.toList());
ReleaseExporter exporter = new ReleaseExporter(thriftClients.makeComponentClient(), releases, user, releaseStringMap);
PortletResponseUtil.sendFile(request, response, String.format("releases-%s-%s-%s.xlsx", project.getName(), project.getVersion(), SW360Utils.getCreatedOn()), exporter.makeExcelExport(releases), CONTENT_TYPE_OPENXML_SPREADSHEET);
}
} catch (IOException | TException e) {
log.error("An error occurred while generating the Excel export", e);
response.setProperty(ResourceResponse.HTTP_STATUS_CODE, Integer.toString(HttpServletResponse.SC_INTERNAL_SERVER_ERROR));
}
}
Aggregations