@Test public void shouldSaveProgramProduct() { ProductDTO productDTO = new ProductDTO(); Product product = new Product(); productDTO.setProduct(product); List<ProgramProduct> programProducts = asList(new ProgramProduct()); productDTO.setProgramProducts(programProducts); doNothing().when(service).save(product); doNothing().when(programProductService).saveAll(programProducts, product); when(messageService.message("message.product.created.success", productDTO.getProduct().getName())).thenReturn("save success"); ResponseEntity<OpenLmisResponse> response = controller.save(productDTO, request); assertThat(product.getCreatedBy(), is(11L)); assertThat(product.getModifiedBy(), is(11L)); assertThat(response.getBody().getSuccessMsg(), is("save success")); assertThat((Long) response.getBody().getData().get("productId"), is(product.getId())); verify(service).save(product); }
@RequestMapping(method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") public ResponseEntity<OpenLmisResponse> save(@RequestBody ProductDTO productDTO, HttpServletRequest request) { ResponseEntity<OpenLmisResponse> response; Product product = productDTO.getProduct(); List<ProgramProduct> programProducts = productDTO.getProgramProducts(); try { Long userId = loggedInUserId(request); product.setCreatedBy(userId); product.setModifiedBy(userId); service.save(product); programProductService.saveAll(programProducts, product); } catch (DataException e) { response = OpenLmisResponse.error(e, BAD_REQUEST); return response; } response = OpenLmisResponse.success(messageService.message("message.product.created.success", product.getName())); response.getBody().addData("productId", product.getId()); return response; }
ProductController extends BaseController { @RequestMapping(method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") public ResponseEntity<OpenLmisResponse> save(@RequestBody ProductDTO productDTO, HttpServletRequest request) { ResponseEntity<OpenLmisResponse> response; Product product = productDTO.getProduct(); List<ProgramProduct> programProducts = productDTO.getProgramProducts(); try { Long userId = loggedInUserId(request); product.setCreatedBy(userId); product.setModifiedBy(userId); service.save(product); programProductService.saveAll(programProducts, product); } catch (DataException e) { response = OpenLmisResponse.error(e, BAD_REQUEST); return response; } response = OpenLmisResponse.success(messageService.message("message.product.created.success", product.getName())); response.getBody().addData("productId", product.getId()); return response; } }
ProductController extends BaseController { @RequestMapping(method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") public ResponseEntity<OpenLmisResponse> save(@RequestBody ProductDTO productDTO, HttpServletRequest request) { ResponseEntity<OpenLmisResponse> response; Product product = productDTO.getProduct(); List<ProgramProduct> programProducts = productDTO.getProgramProducts(); try { Long userId = loggedInUserId(request); product.setCreatedBy(userId); product.setModifiedBy(userId); service.save(product); programProductService.saveAll(programProducts, product); } catch (DataException e) { response = OpenLmisResponse.error(e, BAD_REQUEST); return response; } response = OpenLmisResponse.success(messageService.message("message.product.created.success", product.getName())); response.getBody().addData("productId", product.getId()); return response; }  }
ProductController extends BaseController { @RequestMapping(method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") public ResponseEntity<OpenLmisResponse> save(@RequestBody ProductDTO productDTO, HttpServletRequest request) { ResponseEntity<OpenLmisResponse> response; Product product = productDTO.getProduct(); List<ProgramProduct> programProducts = productDTO.getProgramProducts(); try { Long userId = loggedInUserId(request); product.setCreatedBy(userId); product.setModifiedBy(userId); service.save(product); programProductService.saveAll(programProducts, product); } catch (DataException e) { response = OpenLmisResponse.error(e, BAD_REQUEST); return response; } response = OpenLmisResponse.success(messageService.message("message.product.created.success", product.getName())); response.getBody().addData("productId", product.getId()); return response; }  @RequestMapping(value = "/groups", method = RequestMethod.GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") List<ProductGroup> getAllGroups(); @RequestMapping(value = "/forms", method = RequestMethod.GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") List<ProductForm> getAllForms(); @RequestMapping(value = "/dosageUnits", method = RequestMethod.GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") List<DosageUnit> getAllDosageUnits(); @RequestMapping(value = "/{id}", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") ProductDTO getById(@PathVariable(value = "id") Long id); @RequestMapping(method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") ResponseEntity<OpenLmisResponse> save(@RequestBody ProductDTO productDTO, HttpServletRequest request); @RequestMapping(value = "/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") ResponseEntity<OpenLmisResponse> update(@RequestBody ProductDTO productDTO, @PathVariable(value = "id") Long id,
                                                 HttpServletRequest request); @RequestMapping(value = "/categories", method = RequestMethod.GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") List<ProductCategory> getAllCategories(); }
ProductController extends BaseController { @RequestMapping(method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") public ResponseEntity<OpenLmisResponse> save(@RequestBody ProductDTO productDTO, HttpServletRequest request) { ResponseEntity<OpenLmisResponse> response; Product product = productDTO.getProduct(); List<ProgramProduct> programProducts = productDTO.getProgramProducts(); try { Long userId = loggedInUserId(request); product.setCreatedBy(userId); product.setModifiedBy(userId); service.save(product); programProductService.saveAll(programProducts, product); } catch (DataException e) { response = OpenLmisResponse.error(e, BAD_REQUEST); return response; } response = OpenLmisResponse.success(messageService.message("message.product.created.success", product.getName())); response.getBody().addData("productId", product.getId()); return response; }  @RequestMapping(value = "/groups", method = RequestMethod.GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") List<ProductGroup> getAllGroups(); @RequestMapping(value = "/forms", method = RequestMethod.GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") List<ProductForm> getAllForms(); @RequestMapping(value = "/dosageUnits", method = RequestMethod.GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") List<DosageUnit> getAllDosageUnits(); @RequestMapping(value = "/{id}", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") ProductDTO getById(@PathVariable(value = "id") Long id); @RequestMapping(method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") ResponseEntity<OpenLmisResponse> save(@RequestBody ProductDTO productDTO, HttpServletRequest request); @RequestMapping(value = "/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") ResponseEntity<OpenLmisResponse> update(@RequestBody ProductDTO productDTO, @PathVariable(value = "id") Long id,
                                                 HttpServletRequest request); @RequestMapping(value = "/categories", method = RequestMethod.GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") List<ProductCategory> getAllCategories();  }