-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSAController.java
More file actions
89 lines (70 loc) · 3.65 KB
/
SAController.java
File metadata and controls
89 lines (70 loc) · 3.65 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package com.ibx.cac2web.sensitiveaccounts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import java.util.List;
@Controller
@RequestMapping(value = "/sensitiveaccounts")
public class SensitiveAccountsController {
@Autowired
private ISensitiveAccountsService sensitiveAccountsService;
private static final String INDEX = "sensitiveaccounts";
private static final String REDIRECTINDEX = "redirect:/sensitiveaccounts";
public SensitiveAccountsController(ISensitiveAccountsService sensitiveAccountsService) {
this.sensitiveAccountsService = sensitiveAccountsService;
}
@RequestMapping("rest/{id}")
@ResponseBody()
public SensitiveAccount getSensitiveAccountsById() {
return null;// SensitiveAccountsDAO.getAccountsByID(id);
}
@GetMapping
public ModelAndView getSensitiveAccounts(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "20") int pageSize,
@RequestParam(value = "searchText", required = false, defaultValue = "") String searchtext) {
ModelAndView modelAndView = new ModelAndView(INDEX);
modelAndView.addObject("searchText", searchtext);
List<SensitiveAccount> sensitiveAccountsList;
boolean allParametersSet = (!searchtext.isEmpty());
if (allParametersSet) {
sensitiveAccountsList = sensitiveAccountsService.getAccountsByMemberId(searchtext);
} else {
sensitiveAccountsList = sensitiveAccountsService.getMemberDataFromMADSensitiveAccount();
}
pagination(sensitiveAccountsList, modelAndView, page, pageSize);
return modelAndView;
}
@PostMapping(value = "/add")
public ModelAndView addSensitiveAccount(@RequestParam String memberId, @RequestParam String firstName, @RequestParam String dateOfBirth, @RequestParam String comments){
ModelAndView modelAndView = new ModelAndView(INDEX);
if (memberId != null && firstName != null && dateOfBirth != null && comments != null) {
sensitiveAccountsService.addSensitiveAccounts(memberId, firstName, dateOfBirth, comments);
modelAndView.addObject("warning", "SensitiveAccountEntity added to the Database");
} else {
modelAndView.addObject("danger", "Something went wrong");
}
return new ModelAndView(REDIRECTINDEX);
}
@PostMapping(value = "/update")
public ModelAndView updateSensitiveAccount(){
return new ModelAndView(REDIRECTINDEX);
}
@RequestMapping(value = "/delete")
public ModelAndView deleteSensitiveAccount(@RequestParam("deleteIDNumber") String id){
String[] idParts = id.split("\\|");
System.out.println(id);
for(String p: idParts) {
System.out.println(p);
}
sensitiveAccountsService.deleteSensitiveAccount(idParts[0], idParts[1], idParts[2]);
return new ModelAndView(REDIRECTINDEX);
}
private void pagination(List<SensitiveAccount> sensitiveAccountsList, ModelAndView modelAndView, int page, int pageSize) {
int numberOfPages = Math.max((sensitiveAccountsList.size() / pageSize), 1);
int startIndex = (numberOfPages >= page) ? (page - 1) * pageSize : 1;
int endIndex = (page == numberOfPages) ? sensitiveAccountsList.size() : startIndex + pageSize;
modelAndView.addObject("numberOfPages", numberOfPages);
modelAndView.addObject("currentPage", page);
modelAndView.addObject("dataList", sensitiveAccountsList.subList(startIndex, endIndex));
}
}//end class