/
CoverageAccessPage.java
158 lines (134 loc) · 6.36 KB
/
CoverageAccessPage.java
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/* (c) 2014 - 2016 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
*/
package org.geoserver.web.admin;
import java.util.Arrays;
import java.util.List;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.FormComponent;
import org.apache.wicket.markup.html.form.ChoiceRenderer;
import org.apache.wicket.markup.html.form.NumberTextField;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.form.validation.AbstractFormValidator;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.StringResourceModel;
import org.apache.wicket.validation.validator.RangeValidator;
import org.geoserver.config.CoverageAccessInfo;
import org.geoserver.config.CoverageAccessInfo.QueueType;
import org.geoserver.config.GeoServer;
import org.geoserver.config.GeoServerInfo;
import org.geoserver.web.wicket.ParamResourceModel;
/**
* Edits the Coverage configuration parameters
*/
public class CoverageAccessPage extends ServerAdminPage {
private static final long serialVersionUID = -5028265196560034398L;
class PoolSizeValidator extends AbstractFormValidator {
private static final long serialVersionUID = -3435198454570572665L;
public FormComponent<?>[] getDependentFormComponents() {
return null;
}
public void validate(Form<?> form) {
// only validate on final submit
if (form.findSubmittingButton() != form.get("submit")) {
return;
}
// Getting pool components
final TextField<?> maxPoolField = (TextField<?>) form.get("maxPoolSize");
final TextField<?> corePoolField = (TextField<?>) form.get("corePoolSize");
int maxPool;
int corePool;
// checking limits are properly set
if (maxPoolField != null && corePoolField != null) {
final String mp = maxPoolField.getValue();
final String cp = corePoolField.getValue();
if (!(mp == null || cp == null || mp.trim().isEmpty() || cp.trim()
.isEmpty())) {
try {
maxPool = Integer.valueOf(mp);
} catch (NumberFormatException nfe) {
// The MinimumValidator(1) should already deal with that
return;
}
try {
corePool = Integer.valueOf(cp);
} catch (NumberFormatException nfe) {
// The MinimumValidator(1) should already deal with that
return;
}
if (maxPool >= 1 && corePool >= 1 && maxPool < corePool) {
form.error(new ParamResourceModel("poolSizeCheck", getPage()).getString());
}
}
}
}
}
public CoverageAccessPage(){
final IModel<?> geoServerModel = getGeoServerModel();
// this invocation will trigger a clone of the CoverageAccessInfo,
// which will allow the modification proxy seeing changes on the
// CoverageAccess page with respect to the original CoverageAccessInfo object
final IModel<CoverageAccessInfo> coverageModel = getCoverageAccessModel();
// form and submit
Form<CoverageAccessInfo> form = new Form<CoverageAccessInfo>("form", new CompoundPropertyModel<CoverageAccessInfo>(coverageModel));
add( form );
form.add(new PoolSizeValidator());
// All the fields
NumberTextField<Integer> corePoolSize = new NumberTextField<Integer>("corePoolSize",Integer.class);
corePoolSize.setMinimum(1);
form.add(corePoolSize);
TextField<String> maxPoolSize = new TextField<String>("maxPoolSize");
maxPoolSize.add(RangeValidator.minimum(1));
form.add(maxPoolSize);
TextField<String> keepAliveTime = new TextField<String>("keepAliveTime");
keepAliveTime.add(RangeValidator.minimum(1));
form.add(keepAliveTime);
final DropDownChoice<QueueType> queueType = new DropDownChoice<QueueType>("queueType", Arrays.asList(CoverageAccessInfo.QueueType.values()), new QueueTypeRenderer());
form.add(queueType);
TextField<String> imageIOCacheThreshold = new TextField<String>("imageIOCacheThreshold");
imageIOCacheThreshold.add(RangeValidator.minimum(0l));
form.add(imageIOCacheThreshold);
Button submit = new Button("submit", new StringResourceModel("submit", this, null)) {
private static final long serialVersionUID = 4149741045073254811L;
@Override
public void onSubmit() {
GeoServer gs = (GeoServer) geoServerModel.getObject();
GeoServerInfo global = gs.getGlobal();
global.setCoverageAccess( (CoverageAccessInfo)coverageModel.getObject() );
gs.save(global);
doReturn();
}
};
form.add(submit);
Button cancel = new Button("cancel") {
private static final long serialVersionUID = -57093747603810865L;
@Override
public void onSubmit() {
doReturn();
}
};
form.add(cancel);
}
/**
* Display and ID mapping adapter for QueueType.
*/
// TODO: consider use of EnumChoiceRenderer<QueueType>
private class QueueTypeRenderer extends ChoiceRenderer<QueueType> {
private static final long serialVersionUID = -702911785346928083L;
public String getDisplayValue(QueueType type) {
return new StringResourceModel(type.name(), CoverageAccessPage.this, null).getString();
}
public String getIdValue(QueueType type, int index) {
return type.name();
}
@Override
public QueueType getObject(String id, IModel<? extends List<? extends QueueType>> choices) {
return QueueType.valueOf(id);
}
}
}