@Test public void shouldThrowExceptionOnInsert() { FacilityTypeApprovedProductList facilityTypeApprovedProducts = new FacilityTypeApprovedProductList(); doThrow(new DataException("error")).when(service).saveAll(facilityTypeApprovedProducts, 1l); ResponseEntity<OpenLmisResponse> errorResponse = controller.insert(facilityTypeApprovedProducts, request); assertThat(errorResponse.getBody().getErrorMsg(), is("error")); assertThat(errorResponse.getStatusCode(), is(BAD_REQUEST)); }
@RequestMapping(method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY_APPROVED_PRODUCT')") public ResponseEntity<OpenLmisResponse> insert(@RequestBody FacilityTypeApprovedProductList facilityTypeApprovedProducts, HttpServletRequest request) { try { service.saveAll(facilityTypeApprovedProducts, loggedInUserId(request)); } catch (DataException e) { return OpenLmisResponse.error(e, BAD_REQUEST); } return OpenLmisResponse.success(messageService.message("message.facility.type.approved.products.added.successfully", facilityTypeApprovedProducts.size())); }
FacilityApprovedProductController extends BaseController { @RequestMapping(method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY_APPROVED_PRODUCT')") public ResponseEntity<OpenLmisResponse> insert(@RequestBody FacilityTypeApprovedProductList facilityTypeApprovedProducts, HttpServletRequest request) { try { service.saveAll(facilityTypeApprovedProducts, loggedInUserId(request)); } catch (DataException e) { return OpenLmisResponse.error(e, BAD_REQUEST); } return OpenLmisResponse.success(messageService.message("message.facility.type.approved.products.added.successfully", facilityTypeApprovedProducts.size())); } }
FacilityApprovedProductController extends BaseController { @RequestMapping(method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY_APPROVED_PRODUCT')") public ResponseEntity<OpenLmisResponse> insert(@RequestBody FacilityTypeApprovedProductList facilityTypeApprovedProducts, HttpServletRequest request) { try { service.saveAll(facilityTypeApprovedProducts, loggedInUserId(request)); } catch (DataException e) { return OpenLmisResponse.error(e, BAD_REQUEST); } return OpenLmisResponse.success(messageService.message("message.facility.type.approved.products.added.successfully", facilityTypeApprovedProducts.size())); }  }
FacilityApprovedProductController extends BaseController { @RequestMapping(method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY_APPROVED_PRODUCT')") public ResponseEntity<OpenLmisResponse> insert(@RequestBody FacilityTypeApprovedProductList facilityTypeApprovedProducts, HttpServletRequest request) { try { service.saveAll(facilityTypeApprovedProducts, loggedInUserId(request)); } catch (DataException e) { return OpenLmisResponse.error(e, BAD_REQUEST); } return OpenLmisResponse.success(messageService.message("message.facility.type.approved.products.added.successfully", facilityTypeApprovedProducts.size())); }  @RequestMapping(value = "/facility/{facilityId}/program/{programId}/nonFullSupply", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'CREATE_REQUISITION, AUTHORIZE_REQUISITION')") ResponseEntity<OpenLmisResponse> getAllNonFullSupplyProductsByFacilityAndProgram(@PathVariable("facilityId") Long facilityId,
                                                                                          @PathVariable("programId") Long programId); @RequestMapping(method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY_APPROVED_PRODUCT')") ResponseEntity<OpenLmisResponse> getAllBy(@RequestParam("facilityTypeId") Long facilityTypeId,
                                                   @RequestParam("programId") Long programId,
                                                   @RequestParam(value = "searchParam", defaultValue = "", required = false) String searchParam,
                                                   @RequestParam(value = "page", defaultValue = "1") Integer page,
                                                   @Value("${search.page.size}") String limit); @RequestMapping(method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY_APPROVED_PRODUCT')") ResponseEntity<OpenLmisResponse> insert(@RequestBody FacilityTypeApprovedProductList facilityTypeApprovedProducts,
                                                 HttpServletRequest request); @RequestMapping(value = "/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY_APPROVED_PRODUCT')") ResponseEntity<OpenLmisResponse> update(@PathVariable("id") Long id,
                                                 @RequestBody FacilityTypeApprovedProduct facilityTypeApprovedProduct,
                                                 HttpServletRequest request); @RequestMapping(value = "/{id}", method = DELETE, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY_APPROVED_PRODUCT')") ResponseEntity<OpenLmisResponse> delete(@PathVariable("id") Long id); }
FacilityApprovedProductController extends BaseController { @RequestMapping(method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY_APPROVED_PRODUCT')") public ResponseEntity<OpenLmisResponse> insert(@RequestBody FacilityTypeApprovedProductList facilityTypeApprovedProducts, HttpServletRequest request) { try { service.saveAll(facilityTypeApprovedProducts, loggedInUserId(request)); } catch (DataException e) { return OpenLmisResponse.error(e, BAD_REQUEST); } return OpenLmisResponse.success(messageService.message("message.facility.type.approved.products.added.successfully", facilityTypeApprovedProducts.size())); }  @RequestMapping(value = "/facility/{facilityId}/program/{programId}/nonFullSupply", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'CREATE_REQUISITION, AUTHORIZE_REQUISITION')") ResponseEntity<OpenLmisResponse> getAllNonFullSupplyProductsByFacilityAndProgram(@PathVariable("facilityId") Long facilityId,
                                                                                          @PathVariable("programId") Long programId); @RequestMapping(method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY_APPROVED_PRODUCT')") ResponseEntity<OpenLmisResponse> getAllBy(@RequestParam("facilityTypeId") Long facilityTypeId,
                                                   @RequestParam("programId") Long programId,
                                                   @RequestParam(value = "searchParam", defaultValue = "", required = false) String searchParam,
                                                   @RequestParam(value = "page", defaultValue = "1") Integer page,
                                                   @Value("${search.page.size}") String limit); @RequestMapping(method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY_APPROVED_PRODUCT')") ResponseEntity<OpenLmisResponse> insert(@RequestBody FacilityTypeApprovedProductList facilityTypeApprovedProducts,
                                                 HttpServletRequest request); @RequestMapping(value = "/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY_APPROVED_PRODUCT')") ResponseEntity<OpenLmisResponse> update(@PathVariable("id") Long id,
                                                 @RequestBody FacilityTypeApprovedProduct facilityTypeApprovedProduct,
                                                 HttpServletRequest request); @RequestMapping(value = "/{id}", method = DELETE, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY_APPROVED_PRODUCT')") ResponseEntity<OpenLmisResponse> delete(@PathVariable("id") Long id); static final String NON_FULL_SUPPLY_PRODUCTS; static final String FACILITY_APPROVED_PRODUCTS; static final String PAGINATION; static final String FACILITY_TYPE_APPROVED_PRODUCT; }