1
2
3
4
5
6
7
8
9
10
11 package psiprobe.controllers.datasources;
12
13 import jakarta.servlet.http.HttpServletRequest;
14 import jakarta.servlet.http.HttpServletResponse;
15
16 import java.util.ArrayList;
17 import java.util.Collection;
18 import java.util.Collections;
19 import java.util.List;
20
21 import org.springframework.beans.factory.annotation.Value;
22 import org.springframework.stereotype.Controller;
23 import org.springframework.web.bind.annotation.RequestMapping;
24 import org.springframework.web.servlet.ModelAndView;
25
26 import psiprobe.controllers.AbstractTomcatContainerController;
27 import psiprobe.model.ApplicationResource;
28 import psiprobe.model.DataSourceInfo;
29 import psiprobe.model.DataSourceInfoGroup;
30
31
32
33
34 @Controller
35 public class ListAllJdbcResourceGroupsController extends AbstractTomcatContainerController {
36
37 @RequestMapping(path = "/datasourcegroups.htm")
38 @Override
39 public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
40 throws Exception {
41 return super.handleRequest(request, response);
42 }
43
44 @Override
45 protected ModelAndView handleRequestInternal(HttpServletRequest request,
46 HttpServletResponse response) throws Exception {
47
48 List<DataSourceInfoGroup> dataSourceGroups = new ArrayList<>();
49 List<DataSourceInfo> dataSources = new ArrayList<>();
50
51 List<ApplicationResource> privateResources = getContainerWrapper().getPrivateDataSources();
52 List<ApplicationResource> globalResources = getContainerWrapper().getGlobalDataSources();
53
54
55
56
57 filterValidDataSources(privateResources, dataSources);
58 filterValidDataSources(globalResources, dataSources);
59
60
61 Collections.sort(dataSources, (ds1, ds2) -> {
62 String jdbcUrl1 = ds1.getJdbcUrl();
63 String jdbcUrl2 = ds2.getJdbcUrl();
64
65
66
67 return jdbcUrl1.compareToIgnoreCase(jdbcUrl2);
68 });
69
70
71 DataSourceInfoGroup dsGroup = null;
72 for (DataSourceInfo ds : dataSources) {
73 if (dsGroup == null || !dsGroup.getJdbcUrl().equalsIgnoreCase(ds.getJdbcUrl())) {
74 dsGroup = new DataSourceInfoGroup().builder(ds);
75 dataSourceGroups.add(dsGroup);
76 } else {
77 dsGroup.addDataSourceInfo(ds);
78 }
79 }
80
81 return new ModelAndView(getViewName(), "dataSourceGroups", dataSourceGroups);
82 }
83
84
85
86
87
88
89
90 protected void filterValidDataSources(Collection<ApplicationResource> resources,
91 Collection<DataSourceInfo> dataSources) {
92
93 for (ApplicationResource res : resources) {
94 if (res.isLookedUp() && res.getDataSourceInfo() != null
95 && res.getDataSourceInfo().getJdbcUrl() != null) {
96 dataSources.add(res.getDataSourceInfo());
97 }
98 }
99 }
100
101 @Value("datasourcegroup")
102 @Override
103 public void setViewName(String viewName) {
104 super.setViewName(viewName);
105 }
106
107 }