use of com.epam.ta.reportportal.entity.jasper.ReportFormat in project service-api by reportportal.
the class AbstractJasperReportHandler method getReportFormat.
@Override
public ReportFormat getReportFormat(String view) {
ReportFormat reportFormat = ReportFormat.findByName(view).orElseThrow(() -> new ReportPortalException(BAD_REQUEST_ERROR, Suppliers.formattedSupplier("Unexpected report format: {}", view)));
BusinessRule.expect(reportFormat, getAvailableReportFormats()::contains).verify(ErrorType.BAD_REQUEST_ERROR, Suppliers.formattedSupplier(unsupportedReportFormatExceptionMessage, reportFormat.name()));
return reportFormat;
}
use of com.epam.ta.reportportal.entity.jasper.ReportFormat in project service-api by reportportal.
the class UserController method export.
@Transactional(readOnly = true)
@GetMapping(value = "/export")
@PreAuthorize(ADMIN_ONLY)
@ApiOperation(value = "Exports information about all users", notes = "Allowable only for users with administrator role")
public void export(@ApiParam(allowableValues = "csv") @RequestParam(value = "view", required = false, defaultValue = "csv") String view, @FilterFor(User.class) Filter filter, @FilterFor(User.class) Queryable queryable, @AuthenticationPrincipal ReportPortalUser currentUser, HttpServletResponse response) {
ReportFormat format = jasperReportHandler.getReportFormat(view);
response.setContentType(format.getContentType());
response.setHeader(com.google.common.net.HttpHeaders.CONTENT_DISPOSITION, String.format("attachment; filename=RP_USERS_%s_Report.%s", format.name(), format.getValue()));
try (OutputStream outputStream = response.getOutputStream()) {
getUserHandler.exportUsers(format, outputStream, new CompositeFilter(Operator.AND, filter, queryable));
} catch (IOException e) {
throw new ReportPortalException(ErrorType.BAD_REQUEST_ERROR, "Unable to write data to the response.");
}
}
use of com.epam.ta.reportportal.entity.jasper.ReportFormat in project service-api by reportportal.
the class LaunchController method getLaunchReport.
@Transactional(readOnly = true)
@GetMapping(value = "/{launchId}/report")
@ResponseStatus(OK)
@ApiOperation(value = "Export specified launch", notes = "Only following formats are supported: pdf (by default), xls, html.")
public void getLaunchReport(@PathVariable String projectName, @PathVariable Long launchId, @ApiParam(allowableValues = "pdf, xls, html") @RequestParam(value = "view", required = false, defaultValue = "pdf") String view, @AuthenticationPrincipal ReportPortalUser user, HttpServletResponse response) {
ReportFormat format = getJasperHandler.getReportFormat(view);
response.setContentType(format.getContentType());
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, String.format("attachment; filename=RP_LAUNCH_%s_Report.%s", format.name(), format.getValue()));
try (OutputStream outputStream = response.getOutputStream()) {
getLaunchMessageHandler.exportLaunch(launchId, format, outputStream, user);
} catch (IOException e) {
throw new ReportPortalException(ErrorType.BAD_REQUEST_ERROR, "Unable to write data to the response.");
}
}
use of com.epam.ta.reportportal.entity.jasper.ReportFormat in project service-api by reportportal.
the class ProjectController method exportProjects.
@Transactional(readOnly = true)
@PreAuthorize(ADMIN_ONLY)
@GetMapping(value = "/export")
@ResponseStatus(HttpStatus.OK)
@ApiOperation(value = "Exports information about all projects", notes = "Allowable only for users with administrator role")
public void exportProjects(@ApiParam(allowableValues = "csv") @RequestParam(value = "view", required = false, defaultValue = "csv") String view, @FilterFor(ProjectInfo.class) Filter filter, @FilterFor(ProjectInfo.class) Queryable predefinedFilter, @AuthenticationPrincipal ReportPortalUser user, HttpServletResponse response) {
ReportFormat format = jasperReportHandler.getReportFormat(view);
response.setContentType(format.getContentType());
response.setHeader(CONTENT_DISPOSITION, String.format("attachment; filename=RP_PROJECTS_%s_Report.%s", format.name(), format.getValue()));
try (OutputStream outputStream = response.getOutputStream()) {
getProjectHandler.exportProjects(format, new CompositeFilter(Operator.AND, filter, predefinedFilter), outputStream);
} catch (IOException e) {
throw new ReportPortalException(ErrorType.BAD_REQUEST_ERROR, "Unable to write data to the response.");
}
}
Aggregations