@Test public void shouldReturnAllOrdersForPage() throws Exception { List<Order> orders = new ArrayList<Order>() {{ new Order(); }}; mockStatic(OrderDTO.class); when(orderService.getOrdersForPage(2, USER_ID, RightName.VIEW_ORDER)).thenReturn(orders); List<OrderDTO> orderDTOs = new ArrayList<>(); when(OrderDTO.getOrdersForView(orders)).thenReturn(orderDTOs); ResponseEntity<OpenLmisResponse> fetchedOrders = orderController.getOrdersForPage(2,0L,0L,0L, request); verify(orderService).getOrdersForPage(2, USER_ID, RightName.VIEW_ORDER); assertThat((List<OrderDTO>) fetchedOrders.getBody().getData().get(ORDERS), is(orderDTOs)); }
@RequestMapping(value = "/orders", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'VIEW_ORDER')") public ResponseEntity<OpenLmisResponse> getOrdersForPage(@RequestParam(value = "page", required = true, defaultValue = "1") Integer page, @RequestParam(value="supplyDepot", defaultValue = "0") Long supplyDepot, @RequestParam(value="period", defaultValue = "0") Long period, @RequestParam(value="program", defaultValue = "0") Long program, HttpServletRequest request) { ResponseEntity<OpenLmisResponse> response; if(supplyDepot != 0 || program != 0){ response = response(ORDERS, getOrdersForView(orderService.getOrdersForPage(page, loggedInUserId(request), VIEW_ORDER, supplyDepot, program, period))); response.getBody().addData(PAGE_SIZE, orderService.getPageSize()); response.getBody().addData(NUMBER_OF_PAGES, orderService.getNumberOfPages(supplyDepot, program,period)); }else { response = response(ORDERS, getOrdersForView(orderService.getOrdersForPage(page, loggedInUserId(request), VIEW_ORDER))); response.getBody().addData(PAGE_SIZE, orderService.getPageSize()); response.getBody().addData(NUMBER_OF_PAGES, orderService.getNumberOfPages()); } return response; }
OrderController extends BaseController { @RequestMapping(value = "/orders", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'VIEW_ORDER')") public ResponseEntity<OpenLmisResponse> getOrdersForPage(@RequestParam(value = "page", required = true, defaultValue = "1") Integer page, @RequestParam(value="supplyDepot", defaultValue = "0") Long supplyDepot, @RequestParam(value="period", defaultValue = "0") Long period, @RequestParam(value="program", defaultValue = "0") Long program, HttpServletRequest request) { ResponseEntity<OpenLmisResponse> response; if(supplyDepot != 0 || program != 0){ response = response(ORDERS, getOrdersForView(orderService.getOrdersForPage(page, loggedInUserId(request), VIEW_ORDER, supplyDepot, program, period))); response.getBody().addData(PAGE_SIZE, orderService.getPageSize()); response.getBody().addData(NUMBER_OF_PAGES, orderService.getNumberOfPages(supplyDepot, program,period)); }else { response = response(ORDERS, getOrdersForView(orderService.getOrdersForPage(page, loggedInUserId(request), VIEW_ORDER))); response.getBody().addData(PAGE_SIZE, orderService.getPageSize()); response.getBody().addData(NUMBER_OF_PAGES, orderService.getNumberOfPages()); } return response; } }
OrderController extends BaseController { @RequestMapping(value = "/orders", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'VIEW_ORDER')") public ResponseEntity<OpenLmisResponse> getOrdersForPage(@RequestParam(value = "page", required = true, defaultValue = "1") Integer page, @RequestParam(value="supplyDepot", defaultValue = "0") Long supplyDepot, @RequestParam(value="period", defaultValue = "0") Long period, @RequestParam(value="program", defaultValue = "0") Long program, HttpServletRequest request) { ResponseEntity<OpenLmisResponse> response; if(supplyDepot != 0 || program != 0){ response = response(ORDERS, getOrdersForView(orderService.getOrdersForPage(page, loggedInUserId(request), VIEW_ORDER, supplyDepot, program, period))); response.getBody().addData(PAGE_SIZE, orderService.getPageSize()); response.getBody().addData(NUMBER_OF_PAGES, orderService.getNumberOfPages(supplyDepot, program,period)); }else { response = response(ORDERS, getOrdersForView(orderService.getOrdersForPage(page, loggedInUserId(request), VIEW_ORDER))); response.getBody().addData(PAGE_SIZE, orderService.getPageSize()); response.getBody().addData(NUMBER_OF_PAGES, orderService.getNumberOfPages()); } return response; }  }
OrderController extends BaseController { @RequestMapping(value = "/orders", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'VIEW_ORDER')") public ResponseEntity<OpenLmisResponse> getOrdersForPage(@RequestParam(value = "page", required = true, defaultValue = "1") Integer page, @RequestParam(value="supplyDepot", defaultValue = "0") Long supplyDepot, @RequestParam(value="period", defaultValue = "0") Long period, @RequestParam(value="program", defaultValue = "0") Long program, HttpServletRequest request) { ResponseEntity<OpenLmisResponse> response; if(supplyDepot != 0 || program != 0){ response = response(ORDERS, getOrdersForView(orderService.getOrdersForPage(page, loggedInUserId(request), VIEW_ORDER, supplyDepot, program, period))); response.getBody().addData(PAGE_SIZE, orderService.getPageSize()); response.getBody().addData(NUMBER_OF_PAGES, orderService.getNumberOfPages(supplyDepot, program,period)); }else { response = response(ORDERS, getOrdersForView(orderService.getOrdersForPage(page, loggedInUserId(request), VIEW_ORDER))); response.getBody().addData(PAGE_SIZE, orderService.getPageSize()); response.getBody().addData(NUMBER_OF_PAGES, orderService.getNumberOfPages()); } return response; }  @RequestMapping(value = "/orders", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'CONVERT_TO_ORDER')") ResponseEntity<OpenLmisResponse> convertToOrder(@RequestBody RequisitionList rnrList,
                                                         HttpServletRequest request); @RequestMapping(value = "/orders", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'VIEW_ORDER')") ResponseEntity<OpenLmisResponse> getOrdersForPage(@RequestParam(value = "page",
    required = true,
    defaultValue = "1") Integer page,
     @RequestParam(value="supplyDepot", defaultValue = "0") Long supplyDepot,
     @RequestParam(value="period", defaultValue = "0") Long period,
     @RequestParam(value="program", defaultValue = "0") Long program,
     HttpServletRequest request); @RequestMapping(value = "/orders/{id}/download.csv", method = GET, headers = ACCEPT_CSV) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'VIEW_ORDER')") ModelAndView downloadOrderCsv(@PathVariable Long id); @RequestMapping(value = "/order-file-template", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'SYSTEM_SETTINGS')") ResponseEntity<OpenLmisResponse> getOrderFileTemplateDTO(); @RequestMapping(value = "/order-file-template", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'SYSTEM_SETTINGS')") ResponseEntity<OpenLmisResponse> saveOrderFileTemplateDTO(@RequestBody OrderFileTemplateDTO orderFileTemplateDTO,
                                                                   HttpServletRequest request); @RequestMapping(value = "/order-number-configuration", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'SYSTEM_SETTINGS')") ResponseEntity<OpenLmisResponse> getOrderNumberConfiguration(); @RequestMapping(value = "/order-number-configuration", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'SYSTEM_SETTINGS')") ResponseEntity<OpenLmisResponse> updateOrderNumberConfiguration(@RequestBody OrderNumberConfiguration orderNumberConfiguration); @RequestMapping(value = "/date-formats", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'SYSTEM_SETTINGS')") ResponseEntity<OpenLmisResponse> getAllDateFormats(); @RequestMapping(value = "/manage-pod-orders", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'MANAGE_POD')") ResponseEntity<OpenLmisResponse> getOrdersForPOD(@RequestParam("program") Long program, @RequestParam(value = "facility", defaultValue = "0") Long facility, HttpServletRequest request); }
OrderController extends BaseController { @RequestMapping(value = "/orders", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'VIEW_ORDER')") public ResponseEntity<OpenLmisResponse> getOrdersForPage(@RequestParam(value = "page", required = true, defaultValue = "1") Integer page, @RequestParam(value="supplyDepot", defaultValue = "0") Long supplyDepot, @RequestParam(value="period", defaultValue = "0") Long period, @RequestParam(value="program", defaultValue = "0") Long program, HttpServletRequest request) { ResponseEntity<OpenLmisResponse> response; if(supplyDepot != 0 || program != 0){ response = response(ORDERS, getOrdersForView(orderService.getOrdersForPage(page, loggedInUserId(request), VIEW_ORDER, supplyDepot, program, period))); response.getBody().addData(PAGE_SIZE, orderService.getPageSize()); response.getBody().addData(NUMBER_OF_PAGES, orderService.getNumberOfPages(supplyDepot, program,period)); }else { response = response(ORDERS, getOrdersForView(orderService.getOrdersForPage(page, loggedInUserId(request), VIEW_ORDER))); response.getBody().addData(PAGE_SIZE, orderService.getPageSize()); response.getBody().addData(NUMBER_OF_PAGES, orderService.getNumberOfPages()); } return response; }  @RequestMapping(value = "/orders", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'CONVERT_TO_ORDER')") ResponseEntity<OpenLmisResponse> convertToOrder(@RequestBody RequisitionList rnrList,
                                                         HttpServletRequest request); @RequestMapping(value = "/orders", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'VIEW_ORDER')") ResponseEntity<OpenLmisResponse> getOrdersForPage(@RequestParam(value = "page",
    required = true,
    defaultValue = "1") Integer page,
     @RequestParam(value="supplyDepot", defaultValue = "0") Long supplyDepot,
     @RequestParam(value="period", defaultValue = "0") Long period,
     @RequestParam(value="program", defaultValue = "0") Long program,
     HttpServletRequest request); @RequestMapping(value = "/orders/{id}/download.csv", method = GET, headers = ACCEPT_CSV) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'VIEW_ORDER')") ModelAndView downloadOrderCsv(@PathVariable Long id); @RequestMapping(value = "/order-file-template", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'SYSTEM_SETTINGS')") ResponseEntity<OpenLmisResponse> getOrderFileTemplateDTO(); @RequestMapping(value = "/order-file-template", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'SYSTEM_SETTINGS')") ResponseEntity<OpenLmisResponse> saveOrderFileTemplateDTO(@RequestBody OrderFileTemplateDTO orderFileTemplateDTO,
                                                                   HttpServletRequest request); @RequestMapping(value = "/order-number-configuration", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'SYSTEM_SETTINGS')") ResponseEntity<OpenLmisResponse> getOrderNumberConfiguration(); @RequestMapping(value = "/order-number-configuration", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'SYSTEM_SETTINGS')") ResponseEntity<OpenLmisResponse> updateOrderNumberConfiguration(@RequestBody OrderNumberConfiguration orderNumberConfiguration); @RequestMapping(value = "/date-formats", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'SYSTEM_SETTINGS')") ResponseEntity<OpenLmisResponse> getAllDateFormats(); @RequestMapping(value = "/manage-pod-orders", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'MANAGE_POD')") ResponseEntity<OpenLmisResponse> getOrdersForPOD(@RequestParam("program") Long program, @RequestParam(value = "facility", defaultValue = "0") Long facility, HttpServletRequest request); static final String ORDERS; static final String ORDER; static final String ORDER_FILE_TEMPLATE; static final String ORDER_NUMBER_CONFIGURATION; static final String DATE_FORMATS; static final String PAGE_SIZE; static final String NUMBER_OF_PAGES; static final String ORDERS_FOR_POD; }