@Test public void shouldUploadJasperTemplateFileIfValid() throws Exception { MockMultipartFile reportTemplateFile = new MockMultipartFile("template.jrxml", "template.jrxml", "", new byte[1]); Template template = new Template(); whenNew(Template.class).withArguments("name", null, null, CONSISTENCY_REPORT, "desc").thenReturn(template); when(messageService.message(JASPER_CREATE_REPORT_SUCCESS)).thenReturn("Report created successfully"); ResponseEntity<OpenLmisResponse> response = controller.createJasperReportTemplate(request, reportTemplateFile, "name", "desc"); assertThat(response.getBody().getSuccessMsg(), is("Report created successfully")); assertThat(template.getCreatedBy(), is(1L)); verify(templateService).validateFileAndInsertTemplate(template, reportTemplateFile); }
@RequestMapping(value = "/report-templates", method = POST) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_REPORT')") public ResponseEntity<OpenLmisResponse> createJasperReportTemplate(HttpServletRequest request, MultipartFile file, String name, String description) { try { Template template = new Template(name, null, null, CONSISTENCY_REPORT, description); template.setCreatedBy(loggedInUserId(request)); templateService.validateFileAndInsertTemplate(template, file); return success(messageService.message(JASPER_CREATE_REPORT_SUCCESS), MediaType.TEXT_HTML_VALUE); } catch (IOException e) { return error(messageService.message(JASPER_CREATE_REPORT_ERROR), OK, MediaType.TEXT_HTML_VALUE); } catch (DataException e) { return OpenLmisResponse.error(e, OK, MediaType.TEXT_HTML_VALUE); } }
TemplateController extends BaseController { @RequestMapping(value = "/report-templates", method = POST) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_REPORT')") public ResponseEntity<OpenLmisResponse> createJasperReportTemplate(HttpServletRequest request, MultipartFile file, String name, String description) { try { Template template = new Template(name, null, null, CONSISTENCY_REPORT, description); template.setCreatedBy(loggedInUserId(request)); templateService.validateFileAndInsertTemplate(template, file); return success(messageService.message(JASPER_CREATE_REPORT_SUCCESS), MediaType.TEXT_HTML_VALUE); } catch (IOException e) { return error(messageService.message(JASPER_CREATE_REPORT_ERROR), OK, MediaType.TEXT_HTML_VALUE); } catch (DataException e) { return OpenLmisResponse.error(e, OK, MediaType.TEXT_HTML_VALUE); } } }
TemplateController extends BaseController { @RequestMapping(value = "/report-templates", method = POST) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_REPORT')") public ResponseEntity<OpenLmisResponse> createJasperReportTemplate(HttpServletRequest request, MultipartFile file, String name, String description) { try { Template template = new Template(name, null, null, CONSISTENCY_REPORT, description); template.setCreatedBy(loggedInUserId(request)); templateService.validateFileAndInsertTemplate(template, file); return success(messageService.message(JASPER_CREATE_REPORT_SUCCESS), MediaType.TEXT_HTML_VALUE); } catch (IOException e) { return error(messageService.message(JASPER_CREATE_REPORT_ERROR), OK, MediaType.TEXT_HTML_VALUE); } catch (DataException e) { return OpenLmisResponse.error(e, OK, MediaType.TEXT_HTML_VALUE); } }  }
TemplateController extends BaseController { @RequestMapping(value = "/report-templates", method = POST) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_REPORT')") public ResponseEntity<OpenLmisResponse> createJasperReportTemplate(HttpServletRequest request, MultipartFile file, String name, String description) { try { Template template = new Template(name, null, null, CONSISTENCY_REPORT, description); template.setCreatedBy(loggedInUserId(request)); templateService.validateFileAndInsertTemplate(template, file); return success(messageService.message(JASPER_CREATE_REPORT_SUCCESS), MediaType.TEXT_HTML_VALUE); } catch (IOException e) { return error(messageService.message(JASPER_CREATE_REPORT_ERROR), OK, MediaType.TEXT_HTML_VALUE); } catch (DataException e) { return OpenLmisResponse.error(e, OK, MediaType.TEXT_HTML_VALUE); } }  @RequestMapping(value = "/report-templates", method = POST) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_REPORT')") ResponseEntity<OpenLmisResponse> createJasperReportTemplate(HttpServletRequest request, MultipartFile file, String name, String description); @RequestMapping(value = "/report-templates", method = GET) @PreAuthorize("@permissionEvaluator.hasReportingPermission(principal)") List<Template> getAllTemplatesForUser(HttpServletRequest request); }
TemplateController extends BaseController { @RequestMapping(value = "/report-templates", method = POST) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_REPORT')") public ResponseEntity<OpenLmisResponse> createJasperReportTemplate(HttpServletRequest request, MultipartFile file, String name, String description) { try { Template template = new Template(name, null, null, CONSISTENCY_REPORT, description); template.setCreatedBy(loggedInUserId(request)); templateService.validateFileAndInsertTemplate(template, file); return success(messageService.message(JASPER_CREATE_REPORT_SUCCESS), MediaType.TEXT_HTML_VALUE); } catch (IOException e) { return error(messageService.message(JASPER_CREATE_REPORT_ERROR), OK, MediaType.TEXT_HTML_VALUE); } catch (DataException e) { return OpenLmisResponse.error(e, OK, MediaType.TEXT_HTML_VALUE); } }  @RequestMapping(value = "/report-templates", method = POST) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_REPORT')") ResponseEntity<OpenLmisResponse> createJasperReportTemplate(HttpServletRequest request, MultipartFile file, String name, String description); @RequestMapping(value = "/report-templates", method = GET) @PreAuthorize("@permissionEvaluator.hasReportingPermission(principal)") List<Template> getAllTemplatesForUser(HttpServletRequest request); static final String JASPER_CREATE_REPORT_SUCCESS; static final String JASPER_CREATE_REPORT_ERROR; static final String CONSISTENCY_REPORT; }