Guest User

Untitled

a guest
Dec 15th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. @RequestMapping(value = {"/", "/purchase-history"})
  2. public ModelAndView showHistoryPage(@RequestParam Map<String, String> queryMap,
  3. @ModelAttribute PurchaseHistoryCriteria history,
  4. @RequestParam("pageSize") Optional<Integer> pageSize,
  5. @RequestParam("page") Optional<Integer> page) {
  6. ModelAndView modelAndView = new ModelAndView("purchase-history");
  7. int evalPageSize = pageSize.orElse(INITIAL_PAGE_SIZE);
  8. int evalPage = (page.orElse(0) < 1) ? INITIAL_PAGE : page.get() - 1;
  9.  
  10. Object[] myResult = historyRestController.getAllHistory(history, evalPage);
  11. List<PurchaseHistoryList> listModel = (List<PurchaseHistoryList>)myResult[1];
  12.  
  13. long totalAmount = (long)myResult[2];
  14.  
  15. List<LabInformation> labs = customerRestController.getAllLabs();
  16.  
  17. int totalSize = (int)myResult[0];
  18. Pageable pageable = PageRequest.of(evalPage, evalPageSize);
  19. int start = (int) pageable.getOffset();
  20. int end = (start + pageable.getPageSize()) > totalSize ? totalSize : (start + pageable.getPageSize());
  21. Page<PurchaseHistoryList> result = new PageImpl<PurchaseHistoryList>(listModel, pageable, totalSize);
  22. Pager pager = new Pager(result.getTotalPages(), result.getNumber(), BUTTONS_TO_SHOW);
  23.  
  24. //TODO Need to support Internationalization/Localization later
  25. List<String> genders = new ArrayList<String>();
  26. genders.add("M");
  27. genders.add("F");
  28. modelAndView.addObject("genders", genders);
  29.  
  30. modelAndView.addObject("filteredHistory", history);
  31. modelAndView.addObject("purchaseHistory", result);
  32. modelAndView.addObject("totalAmount", CommonUtil.formatAmountNumber(Long.toString(totalAmount)));
  33. modelAndView.addObject("labs", labs);
  34. modelAndView.addObject("selectedPageSize", evalPageSize);
  35. modelAndView.addObject("pager", pager);
  36.  
  37. //construct GET url
  38. /**
  39. * access from url e.q {url}/purchase-history --> all fields in history will be null
  40. * if clicked search but none of the field entered --> will be blank("") for each field in history object
  41. */
  42. if (history == null || CustomerUtil.checkEmptySearchFields(history))
  43. modelAndView.addObject("url", "/purchase-history"); //important for paging to work
  44. else {
  45. // We need checkedGender from history object because we cannot rely the information from queryMap
  46. String filterHistoryGetUrl = CustomerUtil.createHistoryGetUrl(purchaseHistoryKeys, queryMap, history.getCheckedGenders());
  47. modelAndView.addObject("url", filterHistoryGetUrl);
  48. }
  49.  
  50. return modelAndView;
  51. }
Add Comment
Please, Sign In to add comment