/
SystemConfigPanel.java
275 lines (225 loc) · 13.6 KB
/
SystemConfigPanel.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/*
* Copyright (c) 2010-2013 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.midpoint.web.page.admin.configuration.component;
import com.evolveum.midpoint.web.component.ObjectPolicyConfigurationEditor;
import com.evolveum.midpoint.web.component.form.DropDownFormGroup;
import com.evolveum.midpoint.web.component.util.SimplePanel;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.web.page.admin.configuration.dto.*;
import com.evolveum.midpoint.web.page.admin.dto.ObjectViewDto;
import com.evolveum.midpoint.web.util.InfoTooltipBehavior;
import com.evolveum.midpoint.web.util.WebMiscUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.MailTransportSecurityType;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;
import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.*;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;
import com.evolveum.midpoint.web.component.form.Form;
import java.util.List;
/**
* @author lazyman
*/
public class SystemConfigPanel extends SimplePanel<SystemConfigurationDto> {
private static final String ID_GLOBAL_PASSWORD_POLICY_CHOOSER = "passwordPolicyChooser";
private static final String ID_GLOBAL_USER_TEMPLATE_CHOOSER = "userTemplateChooser";
private static final String ID_OBJECT_POLICY_EDITOR = "objectPolicyEditor";
private static final String ID_GLOBAL_AEP = "aepChooser";
private static final String ID_CLEANUP_AUDIT_RECORDS = "auditRecordsCleanup";
private static final String ID_CLEANUP_CLOSED_TASKS = "closedTasksCleanup";
private static final String ID_CLEANUP_AUDIT_RECORDS_TOOLTIP = "auditRecordsCleanupTooltip";
private static final String ID_CLEANUP_CLOSED_TASKS_TOOLTIP = "closedTasksCleanupTooltip";
private static final String ID_DEFAULT_FROM = "defaultFrom";
private static final String ID_DEBUG = "debugCheckbox";
private static final String ID_MAIL_SERVER = "mailServer";
private static final String ID_MAIL_SERVER_CONFIG_CONTAINER = "mailServerConfigContainer";
private static final String ID_BUTTON_ADD_NEW_MAIL_SERVER_CONFIG = "addNewConfigButton";
private static final String ID_BUTTON_REMOVE_MAIL_SERVER_CONFIG = "removeConfigButton";
private static final String ID_MAIL_SERVER_TOOLTIP = "serverConfigTooltip";
private static final String ID_HOST = "host";
private static final String ID_PORT = "port";
private static final String ID_USERNAME = "username";
private static final String ID_PASSWORD = "password";
private static final String ID_TRANSPORT_SECURITY = "transportSecurity";
private static final String ID_REDIRECT_TO_FILE = "redirectToFile";
private static final String ID_MAIN_FORM = "mainForm";
private static final String ID_LABEL_SIZE = "col-lg-4";
private static final String ID_INPUT_SIZE = "col-lg-4";
public SystemConfigPanel(String id, IModel<SystemConfigurationDto> model) {
super(id, model);
setOutputMarkupId(true);
}
@Override
protected void initLayout(){
Form form = new Form(ID_MAIN_FORM, true);
form.setOutputMarkupId(true);
add(form);
ChooseTypePanel passPolicyChoosePanel = new ChooseTypePanel(ID_GLOBAL_PASSWORD_POLICY_CHOOSER,
new PropertyModel<ObjectViewDto>(getModel(), SystemConfigurationDto.F_PASSWORD_POLICY));
ChooseTypePanel userTemplateChoosePanel = new ChooseTypePanel(ID_GLOBAL_USER_TEMPLATE_CHOOSER,
new PropertyModel<ObjectViewDto>(getModel(), SystemConfigurationDto.F_OBJECT_TEMPLATE));
form.add(passPolicyChoosePanel);
form.add(userTemplateChoosePanel);
ObjectPolicyConfigurationEditor objectPolicyEditor = new ObjectPolicyConfigurationEditor(ID_OBJECT_POLICY_EDITOR,
new PropertyModel<List<ObjectPolicyConfigurationTypeDto>>(getModel(), SystemConfigurationDto.F_OBJECT_POLICY_LIST));
form.add(objectPolicyEditor);
DropDownChoice<AEPlevel> aepLevel = new DropDownChoice<>(ID_GLOBAL_AEP,
new PropertyModel<AEPlevel>(getModel(), SystemConfigurationDto.F_AEP_LEVEL),
WebMiscUtil.createReadonlyModelFromEnum(AEPlevel.class),
new EnumChoiceRenderer<AEPlevel>(SystemConfigPanel.this));
aepLevel.setOutputMarkupId(true);
if(aepLevel.getModel().getObject() == null){
aepLevel.getModel().setObject(null);
}
form.add(aepLevel);
TextField<String> auditRecordsField = new TextField<>(ID_CLEANUP_AUDIT_RECORDS, new PropertyModel<String>(getModel(), SystemConfigurationDto.F_AUDIT_CLEANUP));
TextField<String> closedTasksField = new TextField<>(ID_CLEANUP_CLOSED_TASKS, new PropertyModel<String>(getModel(), SystemConfigurationDto.F_TASK_CLEANUP));
form.add(auditRecordsField);
form.add(closedTasksField);
createTooltip(ID_CLEANUP_AUDIT_RECORDS_TOOLTIP, form);
createTooltip(ID_CLEANUP_CLOSED_TASKS_TOOLTIP, form);
TextField<String> defaultFromField = new TextField<>(ID_DEFAULT_FROM, new PropertyModel<String>(getModel(), "notificationConfig.defaultFrom"));
CheckBox debugCheck = new CheckBox(ID_DEBUG, new PropertyModel<Boolean>(getModel(), "notificationConfig.debug"));
DropDownChoice mailServerConfigChooser = new DropDownChoice<>(ID_MAIL_SERVER,
new PropertyModel<MailServerConfigurationTypeDto>(getModel(), "notificationConfig." + NotificationConfigurationDto.F_SELECTED_SERVER),
new AbstractReadOnlyModel<List<MailServerConfigurationTypeDto>>() {
@Override
public List<MailServerConfigurationTypeDto> getObject() {
return getModel().getObject().getNotificationConfig().getServers();
}
}, new IChoiceRenderer<MailServerConfigurationTypeDto>() {
@Override
public String getDisplayValue(MailServerConfigurationTypeDto object) {
return object.getHost();
}
@Override
public String getIdValue(MailServerConfigurationTypeDto object, int index) {
return Integer.toString(index);
}
});
mailServerConfigChooser.setNullValid(true);
mailServerConfigChooser.add(new OnChangeAjaxBehavior() {
@Override
protected void onUpdate(AjaxRequestTarget target) {
PasswordTextField passwordField = (PasswordTextField)get(ID_MAIN_FORM + ":" + ID_MAIL_SERVER_CONFIG_CONTAINER + ":" + ID_PASSWORD);
if(getModelObject() != null){
if(getModelObject().getNotificationConfig().getSelectedServer() != null &&
getModelObject().getNotificationConfig().getSelectedServer().getPassword() != null){
passwordField.add(new AttributeModifier("placeholder", createStringResource("SystemConfigPanel.mail.password.placeholder.set")));
} else {
passwordField.add(new AttributeModifier("placeholder", createStringResource("SystemConfigPanel.mail.password.placeholder.empty")));
}
}
target.add(SystemConfigPanel.this);
}
});
form.add(mailServerConfigChooser);
Label serverConfigTooltip = new Label(ID_MAIL_SERVER_TOOLTIP);
serverConfigTooltip.add(new InfoTooltipBehavior());
form.add(serverConfigTooltip);
WebMarkupContainer serverConfigContainer = new WebMarkupContainer(ID_MAIL_SERVER_CONFIG_CONTAINER);
serverConfigContainer.setOutputMarkupId(true);
serverConfigContainer.setOutputMarkupPlaceholderTag(true);
serverConfigContainer.add(new VisibleEnableBehaviour(){
@Override
public boolean isVisible() {
if(getModelObject() != null && getModelObject().getNotificationConfig() != null){
return getModelObject().getNotificationConfig().getSelectedServer() != null;
}
return false;
}
});
form.add(serverConfigContainer);
TextField<String> hostField = new TextField<>(ID_HOST, new PropertyModel<String>(getModel(), "notificationConfig.selectedServer.host"));
TextField<Integer> portField = new TextField<>(ID_PORT, new PropertyModel<Integer>(getModel(), "notificationConfig.selectedServer.port"));
TextField<String> userNameField = new TextField<>(ID_USERNAME, new PropertyModel<String>(getModel(), "notificationConfig.selectedServer.username"));
PasswordTextField passwordField = new PasswordTextField(ID_PASSWORD, new PropertyModel<String>(getModel(), "notificationConfig.selectedServer.password"));
passwordField.setRequired(false);
TextField<String> redirectToFileField = new TextField<>(ID_REDIRECT_TO_FILE, new PropertyModel<String>(getModel(), "notificationConfig.redirectToFile"));
DropDownFormGroup transportSecurity = new DropDownFormGroup<>(ID_TRANSPORT_SECURITY, new PropertyModel<MailTransportSecurityType>(getModel(),
"notificationConfig.selectedServer.mailTransportSecurityType"), WebMiscUtil.createReadonlyModelFromEnum(MailTransportSecurityType.class),
new EnumChoiceRenderer<MailTransportSecurityType>(this), createStringResource("SystemConfigPanel.mail.transportSecurity"),
ID_LABEL_SIZE, ID_INPUT_SIZE, false);
serverConfigContainer.add(hostField);
serverConfigContainer.add(portField);
serverConfigContainer.add(userNameField);
serverConfigContainer.add(passwordField);
serverConfigContainer.add(transportSecurity);
form.add(defaultFromField);
form.add(debugCheck);
form.add(redirectToFileField);
AjaxSubmitLink buttonAddNewMailServerConfig = new AjaxSubmitLink(ID_BUTTON_ADD_NEW_MAIL_SERVER_CONFIG) {
@Override
protected void onSubmit(AjaxRequestTarget target, org.apache.wicket.markup.html.form.Form<?> form) {
MailServerConfigurationTypeDto newConfig = new MailServerConfigurationTypeDto();
newConfig.setHost(getString("SystemConfigPanel.mail.config.placeholder"));
if(getModelObject() != null && getModelObject().getNotificationConfig() != null){
getModelObject().getNotificationConfig().getServers().add(newConfig);
getModelObject().getNotificationConfig().setSelectedServer(newConfig);
}
target.add(SystemConfigPanel.this, getPageBase().getFeedbackPanel());
}
@Override
protected void onError(AjaxRequestTarget target, org.apache.wicket.markup.html.form.Form<?> form) {
target.add(getPageBase().getFeedbackPanel());
}
};
form.add(buttonAddNewMailServerConfig);
AjaxSubmitLink removeMailServerConfig = new AjaxSubmitLink(ID_BUTTON_REMOVE_MAIL_SERVER_CONFIG) {
@Override
protected void onSubmit(AjaxRequestTarget target, org.apache.wicket.markup.html.form.Form<?> form) {
if(getModelObject() != null && getModelObject().getNotificationConfig() != null){
NotificationConfigurationDto notificationConfig = getModelObject().getNotificationConfig();
MailServerConfigurationTypeDto selected = notificationConfig.getSelectedServer();
if(notificationConfig.getServers().contains(selected)){
notificationConfig.getServers().remove(selected);
notificationConfig.setSelectedServer(null);
} else {
warn(getString("SystemConfigPanel.mail.server.remove.warn"));
}
target.add(SystemConfigPanel.this, getPageBase().getFeedbackPanel());
}
}
@Override
protected void onError(AjaxRequestTarget target, org.apache.wicket.markup.html.form.Form<?> form) {
target.add(getPageBase().getFeedbackPanel());
}
};
removeMailServerConfig.add(new AttributeAppender("class", new AbstractReadOnlyModel<String>() {
@Override
public String getObject() {
if(getModelObject() != null && getModelObject().getNotificationConfig() != null &&
getModelObject().getNotificationConfig().getSelectedServer() != null){
return null;
} else {
return " disabled";
}
}
}));
form.add(removeMailServerConfig);
}
private void createTooltip(String id, WebMarkupContainer parent) {
Label tooltip = new Label(id);
tooltip.add(new InfoTooltipBehavior());
parent.add(tooltip);
}
}