RequestMapping method RequestMethod GET public String listPayments Req

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
@RequestMapping(method = RequestMethod.GET)
public String listPayments(@RequestParam(value = "customer", required = false) String customerId,
@RequestParam(value = "biller", required = false) String billerId,
@ModelAttribute("model") ModelMap model) {
List<Payment> result = new ArrayList<>();
Set<Payment> customerPayments = null;
Set<Payment> billerPayments = null;
if (customerId != null) {
long id = Long.parseLong(customerId);
customerPayments = customerService.getById(id).getPayments();
}
if (billerId != null) {
long id = Long.parseLong(billerId);
billerPayments = billerService.getById(id).getPayments();
}
if (customerPayments != null && billerPayments != null) {
customerPayments.retainAll(billerPayments);
result.addAll(customerPayments);
}
if (customerPayments != null) {
result.addAll(customerPayments);
}
if (billerPayments != null) {
result.addAll(billerPayments);
}
model.addAttribute("payments", result);
return "payments";
}