@Test public void shouldGetPODIfAlreadyExistsForOrder() throws Exception { Long orderId = 2L; OrderPOD existingPOD = new OrderPOD(); mockStatic(OrderPODDTO.class); Order order = new Order(orderId); OrderPODDTO orderPODDTO = mock(OrderPODDTO.class); when(orderService.getOrder(orderId)).thenReturn(order); when(OrderPODDTO.getOrderDetailsForPOD(order)).thenReturn(orderPODDTO); when(service.getPODByOrderId(2L)).thenReturn(existingPOD); ResponseEntity<OpenLmisResponse> response = controller.createPOD(2L, request); assertThat((OrderPOD) response.getBody().getData().get(PODController.ORDER_POD), is(existingPOD)); assertThat((OrderPODDTO) response.getBody().getData().get(ORDER), is(orderPODDTO)); assertThat(response.getStatusCode(), is(HttpStatus.OK)); }
@RequestMapping(value = "/pods", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'MANAGE_POD')") public ResponseEntity<OpenLmisResponse> createPOD(@RequestParam Long orderId, HttpServletRequest request) throws ParseException { Order order = orderService.getOrder(orderId); OrderPODDTO orderPODDTO = OrderPODDTO.getOrderDetailsForPOD(order); OrderPOD existingPOD = service.getPODByOrderId(orderId); ResponseEntity<OpenLmisResponse> response; if (existingPOD != null) { response = response(ORDER_POD, existingPOD); } else { OrderPOD orderPOD = new OrderPOD(orderId, order.getOrderNumber(), loggedInUserId(request)); OrderPOD createdPOD = service.createPOD(orderPOD); response = response(ORDER_POD, createdPOD, HttpStatus.CREATED); } response.getBody().addData(ORDER, orderPODDTO); return response; }
PODController extends BaseController { @RequestMapping(value = "/pods", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'MANAGE_POD')") public ResponseEntity<OpenLmisResponse> createPOD(@RequestParam Long orderId, HttpServletRequest request) throws ParseException { Order order = orderService.getOrder(orderId); OrderPODDTO orderPODDTO = OrderPODDTO.getOrderDetailsForPOD(order); OrderPOD existingPOD = service.getPODByOrderId(orderId); ResponseEntity<OpenLmisResponse> response; if (existingPOD != null) { response = response(ORDER_POD, existingPOD); } else { OrderPOD orderPOD = new OrderPOD(orderId, order.getOrderNumber(), loggedInUserId(request)); OrderPOD createdPOD = service.createPOD(orderPOD); response = response(ORDER_POD, createdPOD, HttpStatus.CREATED); } response.getBody().addData(ORDER, orderPODDTO); return response; } }
PODController extends BaseController { @RequestMapping(value = "/pods", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'MANAGE_POD')") public ResponseEntity<OpenLmisResponse> createPOD(@RequestParam Long orderId, HttpServletRequest request) throws ParseException { Order order = orderService.getOrder(orderId); OrderPODDTO orderPODDTO = OrderPODDTO.getOrderDetailsForPOD(order); OrderPOD existingPOD = service.getPODByOrderId(orderId); ResponseEntity<OpenLmisResponse> response; if (existingPOD != null) { response = response(ORDER_POD, existingPOD); } else { OrderPOD orderPOD = new OrderPOD(orderId, order.getOrderNumber(), loggedInUserId(request)); OrderPOD createdPOD = service.createPOD(orderPOD); response = response(ORDER_POD, createdPOD, HttpStatus.CREATED); } response.getBody().addData(ORDER, orderPODDTO); return response; }  }
PODController extends BaseController { @RequestMapping(value = "/pods", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'MANAGE_POD')") public ResponseEntity<OpenLmisResponse> createPOD(@RequestParam Long orderId, HttpServletRequest request) throws ParseException { Order order = orderService.getOrder(orderId); OrderPODDTO orderPODDTO = OrderPODDTO.getOrderDetailsForPOD(order); OrderPOD existingPOD = service.getPODByOrderId(orderId); ResponseEntity<OpenLmisResponse> response; if (existingPOD != null) { response = response(ORDER_POD, existingPOD); } else { OrderPOD orderPOD = new OrderPOD(orderId, order.getOrderNumber(), loggedInUserId(request)); OrderPOD createdPOD = service.createPOD(orderPOD); response = response(ORDER_POD, createdPOD, HttpStatus.CREATED); } response.getBody().addData(ORDER, orderPODDTO); return response; }  @RequestMapping(value = "/pods", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'MANAGE_POD')") ResponseEntity<OpenLmisResponse> createPOD(@RequestParam Long orderId,
                                                    HttpServletRequest request); @RequestMapping(value = "/pods/{id}", method = GET, headers = ACCEPT_JSON) @PostAuthorize("@fulfillmentPermissionService.hasPermission(principal, returnObject.body.data.get(\"order\").getId(), 'MANAGE_POD')") ResponseEntity<OpenLmisResponse> getPOD(@PathVariable("id") Long podId); @RequestMapping(value = "/pods/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'MANAGE_POD')") ResponseEntity<OpenLmisResponse> save(@RequestBody OrderPOD orderPOD, @PathVariable Long id, HttpServletRequest request); @RequestMapping(value = "/pods/submit/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'MANAGE_POD')") ResponseEntity<OpenLmisResponse> submit(@PathVariable Long id, HttpServletRequest request); @RequestMapping(value = "/pods/{id}/print", method = GET, headers = ACCEPT_JSON) ModelAndView print(@PathVariable Long id); }
PODController extends BaseController { @RequestMapping(value = "/pods", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'MANAGE_POD')") public ResponseEntity<OpenLmisResponse> createPOD(@RequestParam Long orderId, HttpServletRequest request) throws ParseException { Order order = orderService.getOrder(orderId); OrderPODDTO orderPODDTO = OrderPODDTO.getOrderDetailsForPOD(order); OrderPOD existingPOD = service.getPODByOrderId(orderId); ResponseEntity<OpenLmisResponse> response; if (existingPOD != null) { response = response(ORDER_POD, existingPOD); } else { OrderPOD orderPOD = new OrderPOD(orderId, order.getOrderNumber(), loggedInUserId(request)); OrderPOD createdPOD = service.createPOD(orderPOD); response = response(ORDER_POD, createdPOD, HttpStatus.CREATED); } response.getBody().addData(ORDER, orderPODDTO); return response; }  @RequestMapping(value = "/pods", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'MANAGE_POD')") ResponseEntity<OpenLmisResponse> createPOD(@RequestParam Long orderId,
                                                    HttpServletRequest request); @RequestMapping(value = "/pods/{id}", method = GET, headers = ACCEPT_JSON) @PostAuthorize("@fulfillmentPermissionService.hasPermission(principal, returnObject.body.data.get(\"order\").getId(), 'MANAGE_POD')") ResponseEntity<OpenLmisResponse> getPOD(@PathVariable("id") Long podId); @RequestMapping(value = "/pods/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'MANAGE_POD')") ResponseEntity<OpenLmisResponse> save(@RequestBody OrderPOD orderPOD, @PathVariable Long id, HttpServletRequest request); @RequestMapping(value = "/pods/submit/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'MANAGE_POD')") ResponseEntity<OpenLmisResponse> submit(@PathVariable Long id, HttpServletRequest request); @RequestMapping(value = "/pods/{id}/print", method = GET, headers = ACCEPT_JSON) ModelAndView print(@PathVariable Long id); static final String ORDER_POD; static final String ORDER; static final String RECEIVED_DATE; static final String PRINT_POD; }