1
2
3
4
5
6
7
8
9
10
11 package psiprobe.controllers.apps;
12
13 import jakarta.inject.Inject;
14 import jakarta.servlet.http.HttpServletRequest;
15 import jakarta.servlet.http.HttpServletResponse;
16
17 import org.apache.catalina.Context;
18 import org.springframework.web.bind.ServletRequestUtils;
19 import org.springframework.web.servlet.ModelAndView;
20
21 import psiprobe.beans.ResourceResolver;
22 import psiprobe.controllers.AbstractContextHandlerController;
23 import psiprobe.model.Application;
24 import psiprobe.model.stats.StatsCollection;
25 import psiprobe.tools.ApplicationUtils;
26 import psiprobe.tools.SecurityUtils;
27
28
29
30
31 public class BaseGetApplicationController extends AbstractContextHandlerController {
32
33
34 private boolean extendedInfo;
35
36
37 @Inject
38 private StatsCollection statsCollection;
39
40
41 private long collectionPeriod;
42
43
44
45
46
47
48 public boolean isExtendedInfo() {
49 return extendedInfo;
50 }
51
52
53
54
55
56
57 public void setExtendedInfo(boolean extendedInfo) {
58 this.extendedInfo = extendedInfo;
59 }
60
61
62
63
64
65
66 public StatsCollection getStatsCollection() {
67 return statsCollection;
68 }
69
70
71
72
73
74
75 public void setStatsCollection(StatsCollection statsCollection) {
76 this.statsCollection = statsCollection;
77 }
78
79
80
81
82
83
84 public long getCollectionPeriod() {
85 return collectionPeriod;
86 }
87
88
89
90
91
92
93 public void setCollectionPeriod(long collectionPeriod) {
94 this.collectionPeriod = collectionPeriod;
95 }
96
97 @Override
98 protected ModelAndView handleContext(String contextName, Context context,
99 HttpServletRequest request, HttpServletResponse response) throws Exception {
100
101 boolean calcSize = ServletRequestUtils.getBooleanParameter(request, "size", false)
102 && SecurityUtils.hasAttributeValueRole(getServletContext());
103
104 ResourceResolver resourceResolver = getContainerWrapper().getResourceResolver();
105 Application app = ApplicationUtils.getApplication(context,
106 isExtendedInfo() ? resourceResolver : null, calcSize, getContainerWrapper());
107
108 if (isExtendedInfo() && getStatsCollection() != null) {
109 String avgStatisticName = "app.avg_proc_time." + app.getName();
110 app.setAvgTime(getStatsCollection().getLastValueForStat(avgStatisticName));
111 }
112
113 return new ModelAndView(getViewName()).addObject("app", app)
114 .addObject("no_resources", !resourceResolver.supportsPrivateResources())
115 .addObject("collectionPeriod", getCollectionPeriod());
116 }
117
118 }