@Test public void shouldUpdate() { String productName = "Primary Name for facility approved product"; Product product = new Product(); product.setPrimaryName(productName); ProgramProduct programProduct = new ProgramProduct(); programProduct.setProduct(product); FacilityTypeApprovedProduct facilityTypeApprovedProduct = new FacilityTypeApprovedProduct(); facilityTypeApprovedProduct.setProgramProduct(programProduct); doNothing().when(service).save(facilityTypeApprovedProduct); when(messageService.message("message.facility.approved.product.updated.success", productName)).thenReturn(productName + " updated successfully"); ResponseEntity<OpenLmisResponse> response = controller.update(2L, facilityTypeApprovedProduct, request); assertThat(facilityTypeApprovedProduct.getId(), is(2L)); assertThat(facilityTypeApprovedProduct.getModifiedBy(), is(userId)); assertThat((FacilityTypeApprovedProduct) response.getBody().getData().get(FACILITY_TYPE_APPROVED_PRODUCT), is(facilityTypeApprovedProduct)); assertThat(response.getBody().getSuccessMsg(), is("Primary Name for facility approved product updated successfully")); }
@RequestMapping(value = "/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY_APPROVED_PRODUCT')") public ResponseEntity<OpenLmisResponse> update(@PathVariable("id") Long id, @RequestBody FacilityTypeApprovedProduct facilityTypeApprovedProduct, HttpServletRequest request) { facilityTypeApprovedProduct.setId(id); facilityTypeApprovedProduct.setModifiedBy(loggedInUserId(request)); try { service.save(facilityTypeApprovedProduct); } catch (DataException e) { return OpenLmisResponse.error(e, BAD_REQUEST); } OpenLmisResponse openLmisResponse = new OpenLmisResponse(FACILITY_TYPE_APPROVED_PRODUCT, facilityTypeApprovedProduct); String successMessage = messageService.message("message.facility.approved.product.updated.success", facilityTypeApprovedProduct.getProgramProduct().getProduct().getPrimaryName()); return openLmisResponse.successEntity(successMessage); }
FacilityApprovedProductController extends BaseController { @RequestMapping(value = "/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY_APPROVED_PRODUCT')") public ResponseEntity<OpenLmisResponse> update(@PathVariable("id") Long id, @RequestBody FacilityTypeApprovedProduct facilityTypeApprovedProduct, HttpServletRequest request) { facilityTypeApprovedProduct.setId(id); facilityTypeApprovedProduct.setModifiedBy(loggedInUserId(request)); try { service.save(facilityTypeApprovedProduct); } catch (DataException e) { return OpenLmisResponse.error(e, BAD_REQUEST); } OpenLmisResponse openLmisResponse = new OpenLmisResponse(FACILITY_TYPE_APPROVED_PRODUCT, facilityTypeApprovedProduct); String successMessage = messageService.message("message.facility.approved.product.updated.success", facilityTypeApprovedProduct.getProgramProduct().getProduct().getPrimaryName()); return openLmisResponse.successEntity(successMessage); } }
FacilityApprovedProductController extends BaseController { @RequestMapping(value = "/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY_APPROVED_PRODUCT')") public ResponseEntity<OpenLmisResponse> update(@PathVariable("id") Long id, @RequestBody FacilityTypeApprovedProduct facilityTypeApprovedProduct, HttpServletRequest request) { facilityTypeApprovedProduct.setId(id); facilityTypeApprovedProduct.setModifiedBy(loggedInUserId(request)); try { service.save(facilityTypeApprovedProduct); } catch (DataException e) { return OpenLmisResponse.error(e, BAD_REQUEST); } OpenLmisResponse openLmisResponse = new OpenLmisResponse(FACILITY_TYPE_APPROVED_PRODUCT, facilityTypeApprovedProduct); String successMessage = messageService.message("message.facility.approved.product.updated.success", facilityTypeApprovedProduct.getProgramProduct().getProduct().getPrimaryName()); return openLmisResponse.successEntity(successMessage); }  }
FacilityApprovedProductController extends BaseController { @RequestMapping(value = "/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY_APPROVED_PRODUCT')") public ResponseEntity<OpenLmisResponse> update(@PathVariable("id") Long id, @RequestBody FacilityTypeApprovedProduct facilityTypeApprovedProduct, HttpServletRequest request) { facilityTypeApprovedProduct.setId(id); facilityTypeApprovedProduct.setModifiedBy(loggedInUserId(request)); try { service.save(facilityTypeApprovedProduct); } catch (DataException e) { return OpenLmisResponse.error(e, BAD_REQUEST); } OpenLmisResponse openLmisResponse = new OpenLmisResponse(FACILITY_TYPE_APPROVED_PRODUCT, facilityTypeApprovedProduct); String successMessage = messageService.message("message.facility.approved.product.updated.success", facilityTypeApprovedProduct.getProgramProduct().getProduct().getPrimaryName()); return openLmisResponse.successEntity(successMessage); }  @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(value = "/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY_APPROVED_PRODUCT')") public ResponseEntity<OpenLmisResponse> update(@PathVariable("id") Long id, @RequestBody FacilityTypeApprovedProduct facilityTypeApprovedProduct, HttpServletRequest request) { facilityTypeApprovedProduct.setId(id); facilityTypeApprovedProduct.setModifiedBy(loggedInUserId(request)); try { service.save(facilityTypeApprovedProduct); } catch (DataException e) { return OpenLmisResponse.error(e, BAD_REQUEST); } OpenLmisResponse openLmisResponse = new OpenLmisResponse(FACILITY_TYPE_APPROVED_PRODUCT, facilityTypeApprovedProduct); String successMessage = messageService.message("message.facility.approved.product.updated.success", facilityTypeApprovedProduct.getProgramProduct().getProduct().getPrimaryName()); return openLmisResponse.successEntity(successMessage); }  @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; }