Search in sources :

Example 1 with ReportFormat

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;
}
Also used : ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) ReportFormat(com.epam.ta.reportportal.entity.jasper.ReportFormat)

Example 2 with 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.");
    }
}
Also used : CompositeFilter(com.epam.ta.reportportal.commons.querygen.CompositeFilter) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) ReportFormat(com.epam.ta.reportportal.entity.jasper.ReportFormat) OutputStream(java.io.OutputStream) IOException(java.io.IOException) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with ReportFormat

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.");
    }
}
Also used : ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) ReportFormat(com.epam.ta.reportportal.entity.jasper.ReportFormat) OutputStream(java.io.OutputStream) IOException(java.io.IOException) ApiOperation(io.swagger.annotations.ApiOperation) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with ReportFormat

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.");
    }
}
Also used : CompositeFilter(com.epam.ta.reportportal.commons.querygen.CompositeFilter) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) ReportFormat(com.epam.ta.reportportal.entity.jasper.ReportFormat) OutputStream(java.io.OutputStream) IOException(java.io.IOException) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ReportFormat (com.epam.ta.reportportal.entity.jasper.ReportFormat)4 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)4 ApiOperation (io.swagger.annotations.ApiOperation)3 IOException (java.io.IOException)3 OutputStream (java.io.OutputStream)3 Transactional (org.springframework.transaction.annotation.Transactional)3 CompositeFilter (com.epam.ta.reportportal.commons.querygen.CompositeFilter)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2