Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @RequestMapping(value = {"/", "/purchase-history"})
- public ModelAndView showHistoryPage(@RequestParam Map<String, String> queryMap,
- @ModelAttribute PurchaseHistoryCriteria history,
- @RequestParam("pageSize") Optional<Integer> pageSize,
- @RequestParam("page") Optional<Integer> page) {
- ModelAndView modelAndView = new ModelAndView("purchase-history");
- int evalPageSize = pageSize.orElse(INITIAL_PAGE_SIZE);
- int evalPage = (page.orElse(0) < 1) ? INITIAL_PAGE : page.get() - 1;
- Object[] myResult = historyRestController.getAllHistory(history, evalPage);
- List<PurchaseHistoryList> listModel = (List<PurchaseHistoryList>)myResult[1];
- long totalAmount = (long)myResult[2];
- List<LabInformation> labs = customerRestController.getAllLabs();
- int totalSize = (int)myResult[0];
- Pageable pageable = PageRequest.of(evalPage, evalPageSize);
- int start = (int) pageable.getOffset();
- int end = (start + pageable.getPageSize()) > totalSize ? totalSize : (start + pageable.getPageSize());
- Page<PurchaseHistoryList> result = new PageImpl<PurchaseHistoryList>(listModel, pageable, totalSize);
- Pager pager = new Pager(result.getTotalPages(), result.getNumber(), BUTTONS_TO_SHOW);
- //TODO Need to support Internationalization/Localization later
- List<String> genders = new ArrayList<String>();
- genders.add("M");
- genders.add("F");
- modelAndView.addObject("genders", genders);
- modelAndView.addObject("filteredHistory", history);
- modelAndView.addObject("purchaseHistory", result);
- modelAndView.addObject("totalAmount", CommonUtil.formatAmountNumber(Long.toString(totalAmount)));
- modelAndView.addObject("labs", labs);
- modelAndView.addObject("selectedPageSize", evalPageSize);
- modelAndView.addObject("pager", pager);
- //construct GET url
- /**
- * access from url e.q {url}/purchase-history --> all fields in history will be null
- * if clicked search but none of the field entered --> will be blank("") for each field in history object
- */
- if (history == null || CustomerUtil.checkEmptySearchFields(history))
- modelAndView.addObject("url", "/purchase-history"); //important for paging to work
- else {
- // We need checkedGender from history object because we cannot rely the information from queryMap
- String filterHistoryGetUrl = CustomerUtil.createHistoryGetUrl(purchaseHistoryKeys, queryMap, history.getCheckedGenders());
- modelAndView.addObject("url", filterHistoryGetUrl);
- }
- return modelAndView;
- }
Add Comment
Please, Sign In to add comment