-
Notifications
You must be signed in to change notification settings - Fork 188
/
ResourceActivationEditor.java
359 lines (302 loc) · 17.6 KB
/
ResourceActivationEditor.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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
/*
* Copyright (c) 2010-2017 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.component.wizard.resource.component.schemahandling;
import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.gui.api.model.NonEmptyModel;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.schema.constants.ExpressionConstants;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.form.multivalue.MultiValueTextEditPanel;
import com.evolveum.midpoint.web.component.wizard.WizardUtil;
import com.evolveum.midpoint.web.component.wizard.resource.component.schemahandling.modal.MappingEditorDialog;
import com.evolveum.midpoint.web.component.wizard.resource.dto.MappingTypeDto;
import com.evolveum.midpoint.web.util.InfoTooltipBehavior;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.types_3.ItemPathType;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.EnumChoiceRenderer;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
import java.util.List;
/**
* @author shood
* */
public class ResourceActivationEditor extends BasePanel<ResourceActivationDefinitionType> {
private static final Trace LOGGER = TraceManager.getTrace(ResourceActivationEditor.class);
private static final String ID_EXISTENCE_FS = "existenceFetchStrategy";
private static final String ID_EXISTENCE_OUT = "existenceOutbound";
private static final String ID_EXISTENCE_IN = "existenceInbound";
private static final String ID_ADM_STATUS_FS = "admStatusFetchStrategy";
private static final String ID_ADM_STATUS_OUT = "admStatusOutbound";
private static final String ID_ADM_STATUS_IN = "admStatusInbound";
private static final String ID_VALID_FROM_FS = "validFromFetchStrategy";
private static final String ID_VALID_FROM_OUT = "validFromOutbound";
private static final String ID_VALID_FROM_IN = "validFromInbound";
private static final String ID_VALID_TO_FS = "validToFetchStrategy";
private static final String ID_VALID_TO_OUT = "validToOutbound";
private static final String ID_VALID_TO_IN = "validToInbound";
private static final String ID_MODAL_MAPPING = "mappingEditor";
private static final String ID_T_EX_FETCH = "existenceFetchStrategyTooltip";
private static final String ID_T_EX_OUT = "existenceOutboundTooltip";
private static final String ID_T_EX_IN = "existenceInboundTooltip";
private static final String ID_T_ADM_FETCH = "admStatusFetchStrategyTooltip";
private static final String ID_T_ADM_OUT = "admStatusOutboundTooltip";
private static final String ID_T_ADM_IN = "admStatusInboundTooltip";
private static final String ID_T_VALID_F_FETCH = "validFromFetchStrategyTooltip";
private static final String ID_T_VALID_F_OUT = "validFromOutboundTooltip";
private static final String ID_T_VALID_F_IN = "validFromInboundTooltip";
private static final String ID_T_VALID_T_FETCH = "validToFetchStrategyTooltip";
private static final String ID_T_VALID_T_OUT = "validToOutboundTooltip";
private static final String ID_T_VALID_T_IN = "validToInboundTooltip";
//Default mapping inbound/outbound sources/targets
public static final String EXISTENCE_DEFAULT_SOURCE = "&" + ExpressionConstants.VAR_LEGAL;
public static final String ADM_STATUS_OUT_SOURCE_DEFAULT = "&" + ExpressionConstants.VAR_FOCUS + "/activation/administrativeStatus";
public static final String ADM_STATUS_OUT_TARGET_DEFAULT = "&" + ExpressionConstants.VAR_PROJECTION + "/activation/administrativeStatus";
public static final String ADM_STATUS_IN_SOURCE_DEFAULT = "&" + ExpressionConstants.VAR_PROJECTION + "/activation/administrativeStatus";
public static final String ADM_STATUS_IN_TARGET_DEFAULT = "&" + ExpressionConstants.VAR_FOCUS + "/activation/administrativeStatus";
public static final String VALID_TO_OUT_SOURCE_DEFAULT = "&" + ExpressionConstants.VAR_FOCUS + "/activation/validTo";
public static final String VALID_TO_OUT_TARGET_DEFAULT = "&" + ExpressionConstants.VAR_PROJECTION + "/activation/validTo";
public static final String VALID_TO_IN_SOURCE_DEFAULT = "&" + ExpressionConstants.VAR_PROJECTION + "/activation/validTo";
public static final String VALID_TO_IN_TARGET_DEFAULT = "&" + ExpressionConstants.VAR_FOCUS + "/activation/validTo";
public static final String VALID_FROM_OUT_SOURCE_DEFAULT = "&" + ExpressionConstants.VAR_FOCUS + "/activation/validFrom";
public static final String VALID_FROM_OUT_TARGET_DEFAULT = "&" + ExpressionConstants.VAR_PROJECTION + "/activation/validFrom";
public static final String VALID_FROM_IN_SOURCE_DEFAULT = "&" + ExpressionConstants.VAR_PROJECTION + "/activation/validFrom";
public static final String VALID_FROM_IN_TARGET_DEFAULT = "&" + ExpressionConstants.VAR_FOCUS + "/activation/validFrom";
private boolean isInitialized = false;
public ResourceActivationEditor(String id, IModel<ResourceActivationDefinitionType> model, NonEmptyModel<Boolean> readOnlyModel) {
super(id, model);
initLayout(readOnlyModel);
}
@Override
public IModel<ResourceActivationDefinitionType> getModel() {
IModel<ResourceActivationDefinitionType> activationModel = super.getModel();
if(activationModel.getObject() == null){
activationModel.setObject(new ResourceActivationDefinitionType());
}
if(!isInitialized){
prepareActivationObject(activationModel.getObject());
isInitialized = true;
}
return activationModel;
}
private void prepareActivationObject(ResourceActivationDefinitionType activation){
if(activation.getExistence() == null){
activation.setExistence(new ResourceBidirectionalMappingType());
} else {
for(MappingType mapping: activation.getExistence().getInbound()) {
if(mapping.equals(new MappingType())){
VariableBindingDefinitionType source = new VariableBindingDefinitionType();
source.setPath(getPrismContext().itemPathParser().asItemPathType(EXISTENCE_DEFAULT_SOURCE));
mapping.getSource().add(source);
}
}
}
if(activation.getAdministrativeStatus() == null){
activation.setAdministrativeStatus(new ResourceBidirectionalMappingType());
} else {
for(MappingType outbound: activation.getAdministrativeStatus().getOutbound()){
if(outbound.equals(new MappingType())){
VariableBindingDefinitionType source = new VariableBindingDefinitionType();
source.setPath(getPrismContext().itemPathParser().asItemPathType(ADM_STATUS_OUT_SOURCE_DEFAULT));
outbound.getSource().add(source);
VariableBindingDefinitionType target = new VariableBindingDefinitionType();
target.setPath(getPrismContext().itemPathParser().asItemPathType(ADM_STATUS_OUT_TARGET_DEFAULT));
outbound.setTarget(target);
}
}
for(MappingType inbound: activation.getAdministrativeStatus().getInbound()){
if(inbound.equals(new MappingType())){
VariableBindingDefinitionType source = new VariableBindingDefinitionType();
source.setPath(getPrismContext().itemPathParser().asItemPathType(ADM_STATUS_IN_SOURCE_DEFAULT));
inbound.getSource().add(source);
VariableBindingDefinitionType target = new VariableBindingDefinitionType();
target.setPath(getPrismContext().itemPathParser().asItemPathType(ADM_STATUS_IN_TARGET_DEFAULT));
inbound.setTarget(target);
}
}
}
if(activation.getValidFrom() == null){
activation.setValidFrom(new ResourceBidirectionalMappingType());
} else {
for(MappingType outbound: activation.getValidFrom().getOutbound()){
if(outbound.equals(new MappingType())){
VariableBindingDefinitionType source = new VariableBindingDefinitionType();
source.setPath(getPrismContext().itemPathParser().asItemPathType(VALID_FROM_OUT_SOURCE_DEFAULT));
outbound.getSource().add(source);
VariableBindingDefinitionType target = new VariableBindingDefinitionType();
target.setPath(getPrismContext().itemPathParser().asItemPathType(VALID_FROM_OUT_TARGET_DEFAULT));
outbound.setTarget(target);
}
}
for(MappingType inbound: activation.getValidFrom().getInbound()){
if(inbound.equals(new MappingType())){
VariableBindingDefinitionType source = new VariableBindingDefinitionType();
source.setPath(getPrismContext().itemPathParser().asItemPathType(VALID_FROM_IN_SOURCE_DEFAULT));
inbound.getSource().add(source);
VariableBindingDefinitionType target = new VariableBindingDefinitionType();
target.setPath(getPrismContext().itemPathParser().asItemPathType(VALID_FROM_IN_TARGET_DEFAULT));
inbound.setTarget(target);
}
}
}
if(activation.getValidTo() == null){
activation.setValidTo(new ResourceBidirectionalMappingType());
} else {
for(MappingType outbound: activation.getValidTo().getOutbound()){
if(outbound.equals(new MappingType())){
VariableBindingDefinitionType source = new VariableBindingDefinitionType();
source.setPath(getPrismContext().itemPathParser().asItemPathType(VALID_TO_OUT_SOURCE_DEFAULT));
outbound.getSource().add(source);
VariableBindingDefinitionType target = new VariableBindingDefinitionType();
target.setPath(getPrismContext().itemPathParser().asItemPathType(VALID_TO_OUT_TARGET_DEFAULT));
outbound.setTarget(target);
}
}
for(MappingType inbound: activation.getValidTo().getInbound()){
if(inbound.equals(new MappingType())){
VariableBindingDefinitionType source = new VariableBindingDefinitionType();
source.setPath(getPrismContext().itemPathParser().asItemPathType(VALID_TO_IN_SOURCE_DEFAULT));
inbound.getSource().add(source);
VariableBindingDefinitionType target = new VariableBindingDefinitionType();
target.setPath(getPrismContext().itemPathParser().asItemPathType(VALID_TO_IN_TARGET_DEFAULT));
inbound.setTarget(target);
}
}
}
}
protected void initLayout(NonEmptyModel<Boolean> readOnlyModel) {
prepareActivationPanelBody(ResourceActivationDefinitionType.F_EXISTENCE.getLocalPart(), ID_EXISTENCE_FS,
ID_EXISTENCE_OUT, ID_EXISTENCE_IN, readOnlyModel);
prepareActivationPanelBody(ResourceActivationDefinitionType.F_ADMINISTRATIVE_STATUS.getLocalPart(), ID_ADM_STATUS_FS,
ID_ADM_STATUS_OUT, ID_ADM_STATUS_IN, readOnlyModel);
prepareActivationPanelBody(ResourceActivationDefinitionType.F_VALID_FROM.getLocalPart(), ID_VALID_FROM_FS,
ID_VALID_FROM_OUT, ID_VALID_FROM_IN, readOnlyModel);
prepareActivationPanelBody(ResourceActivationDefinitionType.F_VALID_TO.getLocalPart(), ID_VALID_TO_FS,
ID_VALID_TO_OUT, ID_VALID_TO_IN, readOnlyModel);
Label exFetchTooltip = new Label(ID_T_EX_FETCH);
exFetchTooltip.add(new InfoTooltipBehavior());
add(exFetchTooltip);
Label exOutTooltip = new Label(ID_T_EX_OUT);
exOutTooltip.add(new InfoTooltipBehavior());
add(exOutTooltip);
Label exInTooltip = new Label(ID_T_EX_IN);
exInTooltip.add(new InfoTooltipBehavior());
add(exInTooltip);
Label admFetchTooltip = new Label(ID_T_ADM_FETCH);
admFetchTooltip.add(new InfoTooltipBehavior());
add(admFetchTooltip);
Label admOutTooltip = new Label(ID_T_ADM_OUT);
admOutTooltip.add(new InfoTooltipBehavior());
add(admOutTooltip);
Label admInTooltip = new Label(ID_T_ADM_IN);
admInTooltip.add(new InfoTooltipBehavior());
add(admInTooltip);
Label validFromFetchTooltip = new Label(ID_T_VALID_F_FETCH);
validFromFetchTooltip.add(new InfoTooltipBehavior());
add(validFromFetchTooltip);
Label validFromOutTooltip = new Label(ID_T_VALID_F_OUT);
validFromOutTooltip.add(new InfoTooltipBehavior());
add(validFromOutTooltip);
Label validFromInTooltip = new Label(ID_T_VALID_F_IN);
validFromInTooltip.add(new InfoTooltipBehavior());
add(validFromInTooltip);
Label validToFetchTooltip = new Label(ID_T_VALID_T_FETCH);
validToFetchTooltip.add(new InfoTooltipBehavior());
add(validToFetchTooltip);
Label validToOutTooltip = new Label(ID_T_VALID_T_OUT);
validToOutTooltip.add(new InfoTooltipBehavior());
add(validToOutTooltip);
Label validToInTooltip = new Label(ID_T_VALID_T_IN);
validToInTooltip.add(new InfoTooltipBehavior());
add(validToInTooltip);
initModals(readOnlyModel);
}
private void prepareActivationPanelBody(String containerValue, String fetchStrategyId, String outboundId, String inboundId,
NonEmptyModel<Boolean> readOnlyModel){
DropDownChoice fetchStrategy = new DropDownChoice<>(fetchStrategyId,
new PropertyModel<>(getModel(), containerValue + ".fetchStrategy"),
WebComponentUtil.createReadonlyModelFromEnum(AttributeFetchStrategyType.class),
new EnumChoiceRenderer<>(this));
fetchStrategy.setNullValid(true);
fetchStrategy.add(WebComponentUtil.enabledIfFalse(readOnlyModel));
add(fetchStrategy);
MultiValueTextEditPanel outbound = new MultiValueTextEditPanel<MappingType>(outboundId,
new PropertyModel<>(getModel(), containerValue + ".outbound"), null, false, true,
readOnlyModel) {
@Override
protected IModel<String> createTextModel(final IModel<MappingType> model) {
return new Model<String>() {
@Override
public String getObject() {
return MappingTypeDto.createMappingLabel(model.getObject(), LOGGER, getPageBase().getPrismContext(),
getString("MappingType.label.placeholder"), getString("MultiValueField.nameNotSpecified"));
}
};
}
@Override
protected MappingType createNewEmptyItem(){
return WizardUtil.createEmptyMapping();
}
@Override
protected void editPerformed(AjaxRequestTarget target, MappingType object){
mappingEditPerformed(target, object, false);
}
};
add(outbound);
MultiValueTextEditPanel inbound = new MultiValueTextEditPanel<MappingType>(inboundId,
new PropertyModel<>(getModel(), containerValue + ".inbound"), null, false, true, readOnlyModel) {
@Override
protected IModel<String> createTextModel(final IModel<MappingType> model) {
return new Model<String>() {
@Override
public String getObject() {
return MappingTypeDto.createMappingLabel(model.getObject(), LOGGER, getPageBase().getPrismContext(),
getString("MappingType.label.placeholder"), getString("MultiValueField.nameNotSpecified"));
}
};
}
@Override
protected MappingType createNewEmptyItem(){
return WizardUtil.createEmptyMapping();
}
@Override
protected void editPerformed(AjaxRequestTarget target, MappingType object){
mappingEditPerformed(target, object, true);
}
};
inbound.setOutputMarkupId(true);
add(inbound);
}
private void initModals(NonEmptyModel<Boolean> readOnlyModel) {
ModalWindow mappingEditor = new MappingEditorDialog(ID_MODAL_MAPPING, null, readOnlyModel) {
@Override
public void updateComponents(AjaxRequestTarget target){
target.add(ResourceActivationEditor.this);
}
};
add(mappingEditor);
}
private void mappingEditPerformed(AjaxRequestTarget target, MappingType mapping, boolean isInbound){
MappingEditorDialog window = (MappingEditorDialog) get(ID_MODAL_MAPPING);
window.updateModel(target, mapping, isInbound);
window.show(target);
}
}