/
SynchronizationStep.java
841 lines (709 loc) · 34.2 KB
/
SynchronizationStep.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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
/*
* Copyright (c) 2010-2019 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;
import com.evolveum.midpoint.gui.api.model.NonEmptyLoadableModel;
import com.evolveum.midpoint.gui.api.model.NonEmptyWrapperModel;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils;
import com.evolveum.midpoint.model.api.ModelService;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.ResourceTypeUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.exception.CommonException;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.data.paging.NavigatorPanel;
import com.evolveum.midpoint.web.component.form.multivalue.MultiValueAutoCompleteTextPanel;
import com.evolveum.midpoint.web.component.form.multivalue.MultiValueTextEditPanel;
import com.evolveum.midpoint.web.component.input.ObjectReferenceChoiceRenderer;
import com.evolveum.midpoint.web.component.input.QNameChoiceRenderer;
import com.evolveum.midpoint.web.component.input.TriStateComboPanel;
import com.evolveum.midpoint.web.component.util.ListDataProvider;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.web.component.wizard.WizardStep;
import com.evolveum.midpoint.web.component.wizard.resource.component.synchronization.ConditionalSearchFilterEditor;
import com.evolveum.midpoint.web.component.wizard.resource.component.synchronization.SynchronizationExpressionEditor;
import com.evolveum.midpoint.web.component.wizard.resource.component.synchronization.SynchronizationReactionEditor;
import com.evolveum.midpoint.web.component.wizard.resource.dto.ResourceSynchronizationDto;
import com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnChangeAjaxFormUpdatingBehavior;
import com.evolveum.midpoint.web.page.admin.resources.PageResourceWizard;
import com.evolveum.midpoint.web.session.UserProfileStorage;
import com.evolveum.midpoint.web.util.ExpressionUtil;
import com.evolveum.midpoint.web.util.InfoTooltipBehavior;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
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.markup.html.list.ListItem;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.DataView;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.validation.IValidator;
import org.jetbrains.annotations.NotNull;
import javax.xml.namespace.QName;
import java.util.*;
/**
* @author lazyman
* @author shood
*/
public class SynchronizationStep extends WizardStep {
private static final Trace LOGGER = TraceManager.getTrace(SynchronizationStep.class);
private static final String DOT_CLASS = SynchronizationStep.class.getName() + ".";
private static final String OPERATION_SAVE_SYNC = DOT_CLASS + "saveResourceSynchronization";
private static final String ID_TABLE_ROWS = "tableRows";
private static final String ID_OBJECT_SYNC_ROW = "objectSyncRow";
private static final String ID_OBJECT_SYNC_LINK = "objectSyncLink";
private static final String ID_OBJECT_SYNC_LABEL = "objectSyncName";
private static final String ID_OBJECT_SYNC_DELETE = "objectSyncDelete";
private static final String ID_PAGING = "objectSyncPaging";
private static final String ID_OBJECT_SYNC_ADD = "objectSyncAddButton";
private static final String ID_OBJECT_SYNC_EDITOR = "objectSyncConfig";
private static final String ID_THIRD_ROW_CONTAINER = "thirdRowContainer";
private static final String ID_EDITOR_LABEL = "editorLabel";
private static final String ID_EDITOR_NAME = "editorName";
private static final String ID_EDITOR_DESCRIPTION = "editorDescription";
private static final String ID_EDITOR_KIND = "editorKind";
private static final String ID_EDITOR_INTENT = "editorIntent";
private static final String ID_EDITOR_FOCUS = "editorFocus";
private static final String ID_EDITOR_ENABLED = "editorEnabled";
private static final String ID_EDITOR_BUTTON_CONDITION = "editorConditionButton";
private static final String ID_EDITOR_BUTTON_CONFIRMATION = "editorConfirmationButton";
private static final String ID_EDITOR_OBJECT_TEMPLATE = "editorObjectTemplate";
private static final String ID_EDITOR_RECONCILE = "editorReconcile";
private static final String ID_EDITOR_OPPORTUNISTIC = "editorOpportunistic";
private static final String ID_EDITOR_OBJECT_CLASS = "editorObjectClass";
private static final String ID_EDITOR_EDITOR_CORRELATION = "editorCorrelation";
private static final String ID_EDITOR_REACTION = "editorReaction";
private static final String ID_T_KIND = "kindTooltip";
private static final String ID_T_INTENT = "intentTooltip";
private static final String ID_T_OBJ_CLASS = "objectClassTooltip";
private static final String ID_T_FOCUS = "focusTooltip";
private static final String ID_T_ENABLED = "enabledTooltip";
private static final String ID_T_CONDITION = "conditionTooltip";
private static final String ID_T_CONFIRMATION = "confirmationTooltip";
private static final String ID_T_OBJ_TEMPLATE = "objectTemplateTooltip";
private static final String ID_T_RECONCILE = "reconcileTooltip";
private static final String ID_T_OPPORTUNISTIC = "opportunisticTooltip";
private static final String ID_T_CORRELATION = "correlationTooltip";
private static final String ID_T_REACTION = "reactionTooltip";
@NotNull private final PageResourceWizard parentPage;
@NotNull private final NonEmptyLoadableModel<PrismObject<ResourceType>> resourceModel;
@NotNull private final NonEmptyLoadableModel<ResourceSynchronizationDto> syncDtoModel;
public SynchronizationStep(@NotNull NonEmptyLoadableModel<PrismObject<ResourceType>> resourceModel, @NotNull PageResourceWizard parentPage) {
super(parentPage);
this.parentPage = parentPage;
this.resourceModel = resourceModel;
syncDtoModel = new NonEmptyLoadableModel<ResourceSynchronizationDto>(false) {
@Override
@NotNull
protected ResourceSynchronizationDto load() {
return loadResourceSynchronization();
}
};
parentPage.registerDependentModel(syncDtoModel);
initLayout();
setOutputMarkupId(true);
}
@NotNull
private ResourceSynchronizationDto loadResourceSynchronization() {
if (resourceModel.getObject().asObjectable().getSynchronization() == null) {
resourceModel.getObject().asObjectable().setSynchronization(new SynchronizationType());
}
ResourceSynchronizationDto dto = new ResourceSynchronizationDto(resourceModel.getObject().asObjectable().getSynchronization().getObjectSynchronization());
dto.setObjectClassList(loadResourceObjectClassList(resourceModel, LOGGER, parentPage.getString("SynchronizationStep.message.errorLoadingObjectSyncList")));
return dto;
}
private boolean isAnySelected() {
return syncDtoModel.getObject().getSelected() != null;
}
private void initLayout() {
final ListDataProvider<ObjectSynchronizationType> syncProvider = new ListDataProvider<>(this,
new PropertyModel<List<ObjectSynchronizationType>>(syncDtoModel, ResourceSynchronizationDto.F_OBJECT_SYNCRONIZATION_LIST));
//first row - object sync list
WebMarkupContainer tableBody = new WebMarkupContainer(ID_TABLE_ROWS);
tableBody.setOutputMarkupId(true);
add(tableBody);
//second row - ObjectSynchronizationType editor
WebMarkupContainer objectSyncEditor = new WebMarkupContainer(ID_OBJECT_SYNC_EDITOR);
objectSyncEditor.setOutputMarkupId(true);
objectSyncEditor.add(new VisibleEnableBehaviour(){
@Override
public boolean isVisible(){
return isAnySelected();
}
});
add(objectSyncEditor);
//third row - container for more specific editors
WebMarkupContainer thirdRowContainer = new WebMarkupContainer(ID_THIRD_ROW_CONTAINER);
thirdRowContainer.setOutputMarkupId(true);
add(thirdRowContainer);
DataView<ObjectSynchronizationType> syncDataView = new DataView<ObjectSynchronizationType>(ID_OBJECT_SYNC_ROW,
syncProvider, UserProfileStorage.DEFAULT_PAGING_SIZE) {
@Override
protected void populateItem(Item<ObjectSynchronizationType> item) {
final ObjectSynchronizationType syncObject = item.getModelObject();
AjaxSubmitLink link = new AjaxSubmitLink(ID_OBJECT_SYNC_LINK) {
@Override
protected void onSubmit(AjaxRequestTarget target) {
editSyncObjectPerformed(target, syncObject);
}
};
item.add(link);
Label label = new Label(ID_OBJECT_SYNC_LABEL, createObjectSyncTypeDisplayModel(syncObject));
label.setOutputMarkupId(true);
link.add(label);
AjaxLink<Void> delete = new AjaxLink<Void>(ID_OBJECT_SYNC_DELETE) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target){
deleteSyncObjectPerformed(target, syncObject);
}
};
parentPage.addEditingVisibleBehavior(delete);
link.add(delete);
item.add(AttributeModifier.replace("class", new IModel<String>() {
@Override
public String getObject() {
if (isSelected(syncObject)) {
return "success";
}
return null;
}
}));
}
};
tableBody.add(syncDataView);
NavigatorPanel navigator = new NavigatorPanel(ID_PAGING, syncDataView, true);
navigator.setOutputMarkupId(true);
navigator.setOutputMarkupPlaceholderTag(true);
add(navigator);
AjaxLink<Void> add = new AjaxLink<Void>(ID_OBJECT_SYNC_ADD) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
addSyncObjectPerformed(target);
}
};
parentPage.addEditingVisibleBehavior(add);
add(add);
initObjectSyncEditor(objectSyncEditor);
}
@Override
protected void onConfigure() {
super.onConfigure();
if (!isAnySelected()) {
insertEmptyThirdRow();
}
}
private void initObjectSyncEditor(WebMarkupContainer editor){
Label editorLabel = new Label(ID_EDITOR_LABEL, new IModel<String>() {
@Override
public String getObject() {
if (!isAnySelected()) {
return null; // shouldn't occur
}
String name = syncDtoModel.getObject().getSelected().getName() != null ? syncDtoModel.getObject().getSelected().getName() : "";
return getString("SynchronizationStep.label.editSyncObject", name);
}
});
editorLabel.setOutputMarkupId(true);
editor.add(editorLabel);
TextField editorName = new TextField<>(ID_EDITOR_NAME, new PropertyModel<String>(syncDtoModel,
ResourceSynchronizationDto.F_SELECTED + ".name"));
editorName.add(new UpdateNamesBehaviour());
parentPage.addEditingEnabledBehavior(editorName);
editor.add(editorName);
TextArea editorDescription = new TextArea<>(ID_EDITOR_DESCRIPTION, new PropertyModel<String>(syncDtoModel,
ResourceSynchronizationDto.F_SELECTED + ".description"));
parentPage.addEditingEnabledBehavior(editorDescription);
editor.add(editorDescription);
DropDownChoice editorKind = new DropDownChoice<>(ID_EDITOR_KIND,
new PropertyModel<>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED + ".kind"),
WebComponentUtil.createReadonlyModelFromEnum(ShadowKindType.class),
new EnumChoiceRenderer<>());
editorKind.setNullValid(true);
editorKind.add(new UpdateNamesBehaviour());
parentPage.addEditingEnabledBehavior(editorKind);
editor.add(editorKind);
TextField editorIntent = new TextField<>(ID_EDITOR_INTENT, new PropertyModel<String>(syncDtoModel,
ResourceSynchronizationDto.F_SELECTED + ".intent"));
editorIntent.add(new UpdateNamesBehaviour());
parentPage.addEditingEnabledBehavior(editorIntent);
editor.add(editorIntent);
MultiValueAutoCompleteTextPanel<QName> editorObjectClass = new MultiValueAutoCompleteTextPanel<QName>(ID_EDITOR_OBJECT_CLASS,
new PropertyModel<>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED + ".objectClass"), true, parentPage.getReadOnlyModel()) {
@Override
protected IModel<String> createTextModel(final IModel<QName> model) {
return new PropertyModel<>(model, "localPart");
}
@Override
protected QName createNewEmptyItem() {
return new QName("");
}
@Override
protected boolean buttonsDisabled() {
return !isAnySelected();
}
@Override
protected List<QName> createObjectList() {
return syncDtoModel.getObject().getObjectClassList();
}
@Override
protected String createAutoCompleteObjectLabel(QName object) {
return object.getLocalPart();
}
@Override
protected IValidator<String> createAutoCompleteValidator(){
return createObjectClassValidator(new IModel<List<QName>>() {
@Override
public List<QName> getObject() {
return syncDtoModel.getObject().getObjectClassList();
}
});
}
};
parentPage.addEditingEnabledBehavior(editorObjectClass);
editor.add(editorObjectClass);
// TODO: switch to ObjectTypeSelectPanel
DropDownChoice editorFocus = new DropDownChoice<>(ID_EDITOR_FOCUS, new PropertyModel<>(syncDtoModel,
ResourceSynchronizationDto.F_SELECTED + ".focusType"),
new IModel<List<QName>>() {
@Override
public List<QName> getObject() {
return WebComponentUtil.createFocusTypeList();
}
}, new QNameChoiceRenderer());
editorFocus.setNullValid(true);
editorFocus.add(new UpdateNamesBehaviour());
parentPage.addEditingEnabledBehavior(editorFocus);
editor.add(editorFocus);
CheckBox editorEnabled = new CheckBox(ID_EDITOR_ENABLED, new PropertyModel<>(syncDtoModel,
ResourceSynchronizationDto.F_SELECTED + ".enabled"));
parentPage.addEditingEnabledBehavior(editorEnabled);
editor.add(editorEnabled);
AjaxSubmitLink editorCondition = new AjaxSubmitLink(ID_EDITOR_BUTTON_CONDITION){
@Override
protected void onSubmit(AjaxRequestTarget target) {
conditionEditPerformed(target);
}
};
addDisableClassModifier(editorCondition);
editor.add(editorCondition);
AjaxSubmitLink editorConfirmation = new AjaxSubmitLink(ID_EDITOR_BUTTON_CONFIRMATION){
@Override
protected void onSubmit(AjaxRequestTarget target) {
confirmationEditPerformed(target);
}
};
addDisableClassModifier(editorConfirmation);
editor.add(editorConfirmation);
DropDownChoice editorObjectTemplate = new DropDownChoice<>(ID_EDITOR_OBJECT_TEMPLATE,
new PropertyModel<>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED + ".objectTemplateRef"),
new IModel<List<ObjectReferenceType>>() {
@Override
public List<ObjectReferenceType> getObject() {
return WebModelServiceUtils.createObjectReferenceList(ObjectTemplateType.class, getPageBase(), syncDtoModel.getObject().getObjectTemplateMap());
}
}, new ObjectReferenceChoiceRenderer(syncDtoModel.getObject().getObjectTemplateMap()));
editorObjectTemplate.setNullValid(true);
parentPage.addEditingEnabledBehavior(editorObjectTemplate);
editor.add(editorObjectTemplate);
CheckBox editorReconcile = new CheckBox(ID_EDITOR_RECONCILE, new PropertyModel<>(syncDtoModel,
ResourceSynchronizationDto.F_SELECTED + ".reconcile"));
parentPage.addEditingEnabledBehavior(editorReconcile);
editor.add(editorReconcile);
TriStateComboPanel opportunistic = new TriStateComboPanel(ID_EDITOR_OPPORTUNISTIC, new PropertyModel<>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED + ".opportunistic"));
parentPage.addEditingEnabledBehavior(opportunistic);
editor.add(opportunistic);
MultiValueTextEditPanel editorCorrelation = new MultiValueTextEditPanel<ConditionalSearchFilterType>(ID_EDITOR_EDITOR_CORRELATION,
new PropertyModel<>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED + ".correlation"),
new PropertyModel<>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED_CORRELATION),
false, true, parentPage.getReadOnlyModel()) {
@Override
protected IModel<String> createTextModel(final IModel<ConditionalSearchFilterType> model) {
return new Model<String>() {
@Override
public String getObject() {
StringBuilder sb = new StringBuilder();
ConditionalSearchFilterType searchFilter = model.getObject();
if(searchFilter != null && searchFilter.getDescription() != null){
sb.append(searchFilter.getDescription());
}
if(sb.toString().isEmpty()){
sb.append(getString("SynchronizationStep.label.notSpecified"));
}
return sb.toString();
}
};
}
@Override
protected ConditionalSearchFilterType createNewEmptyItem(){
return new ConditionalSearchFilterType();
}
@Override
protected void editPerformed(AjaxRequestTarget target, ConditionalSearchFilterType object) {
correlationEditPerformed(target, object);
}
@Override
protected void performAddValueHook(AjaxRequestTarget target, ConditionalSearchFilterType added) {
parentPage.refreshIssues(target);
}
@Override
protected void performRemoveValueHook(AjaxRequestTarget target, ListItem<ConditionalSearchFilterType> item) {
parentPage.refreshIssues(target);
}
@Override
protected boolean buttonsDisabled(){
return !isAnySelected();
}
};
editor.add(editorCorrelation);
MultiValueTextEditPanel editorReaction = new MultiValueTextEditPanel<SynchronizationReactionType>(ID_EDITOR_REACTION,
new PropertyModel<>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED + ".reaction"),
new PropertyModel<>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED_REACTION),
false, true, parentPage.getReadOnlyModel()) {
@Override
protected IModel<String> createTextModel(final IModel<SynchronizationReactionType> model) {
return new Model<String>() {
@Override
public String getObject() {
SynchronizationReactionType reaction = model.getObject();
if (reaction == null) {
return "";
}
StringBuilder sb = new StringBuilder();
sb.append(reaction.getName() != null ? reaction.getName() + " " : "");
sb.append("(");
if (reaction.getSituation() != null) {
sb.append(reaction.getSituation());
}
if (Boolean.TRUE.equals(reaction.isSynchronize()) || !reaction.getAction().isEmpty()) {
sb.append(" -> ");
if (!reaction.getAction().isEmpty()) {
boolean first = true;
for (SynchronizationActionType action : reaction.getAction()) {
if (first) {
first = false;
} else {
sb.append(", ");
}
sb.append(StringUtils.substringAfter(action.getHandlerUri(), "#"));
}
} else {
sb.append(getString("SynchronizationStep.label.editorReaction"));
}
}
sb.append(")");
return sb.toString();
}
};
}
@Override
protected SynchronizationReactionType createNewEmptyItem(){
return new SynchronizationReactionType();
}
@Override
protected void editPerformed(AjaxRequestTarget target, SynchronizationReactionType object){
reactionEditPerformed(target, object);
}
@Override
protected void performAddValueHook(AjaxRequestTarget target, SynchronizationReactionType added) {
parentPage.refreshIssues(target);
}
@Override
protected void performRemoveValueHook(AjaxRequestTarget target, ListItem<SynchronizationReactionType> item) {
parentPage.refreshIssues(target);
}
@Override
protected boolean buttonsDisabled(){
return !isAnySelected();
}
};
editorReaction.setOutputMarkupId(true);
editor.add(editorReaction);
Label kindTooltip = new Label(ID_T_KIND);
kindTooltip.add(new InfoTooltipBehavior());
editor.add(kindTooltip);
Label intentTooltip = new Label(ID_T_INTENT);
intentTooltip.add(new InfoTooltipBehavior());
editor.add(intentTooltip);
Label objClassTooltip = new Label(ID_T_OBJ_CLASS);
objClassTooltip.add(new InfoTooltipBehavior());
editor.add(objClassTooltip);
Label focusTooltip = new Label(ID_T_FOCUS);
focusTooltip.add(new InfoTooltipBehavior());
editor.add(focusTooltip);
Label enabledTooltip = new Label(ID_T_ENABLED);
enabledTooltip.add(new InfoTooltipBehavior());
editor.add(enabledTooltip);
Label conditionTooltip = new Label(ID_T_CONDITION);
conditionTooltip.add(new InfoTooltipBehavior());
editor.add(conditionTooltip);
Label confirmationTooltip = new Label(ID_T_CONFIRMATION);
confirmationTooltip.add(new InfoTooltipBehavior());
editor.add(confirmationTooltip);
Label objTemplateTooltip = new Label(ID_T_OBJ_TEMPLATE);
objTemplateTooltip.add(new InfoTooltipBehavior());
editor.add(objTemplateTooltip);
Label reconcileTooltip = new Label(ID_T_RECONCILE);
reconcileTooltip.add(new InfoTooltipBehavior());
editor.add(reconcileTooltip);
Label opportunisticTooltip = new Label(ID_T_OPPORTUNISTIC);
opportunisticTooltip.add(new InfoTooltipBehavior());
editor.add(opportunisticTooltip);
Label correlationTooltip = new Label(ID_T_CORRELATION);
correlationTooltip.add(new InfoTooltipBehavior());
editor.add(correlationTooltip);
Label reactionTooltip = new Label(ID_T_REACTION);
reactionTooltip.add(new InfoTooltipBehavior());
editor.add(reactionTooltip);
}
private IModel<String> createObjectSyncTypeDisplayModel(final ObjectSynchronizationType syncObject){
return new IModel<String>() {
@Override
public String getObject() {
StringBuilder sb = new StringBuilder();
if (syncObject != null) {
sb.append(syncObject.getName() != null ? syncObject.getName() + " " : "");
SchemaHandlingStep.addKindAndIntent(sb, syncObject.getKind(), syncObject.getIntent());
sb.append(" => ");
sb.append(getTypeDisplayName(ResourceTypeUtil.fillDefaultFocusType(syncObject.getFocusType())));
}
return sb.toString();
}
};
}
// TODO move to some utils
private static String getTypeDisplayName(@NotNull QName name) {
return StringUtils.removeEnd(name.getLocalPart(), "Type");
}
private void addDisableClassModifier(Component component){
component.add(new AttributeAppender("class", new IModel<String>() {
@Override
public String getObject() {
if(!isAnySelected()){
return " disabled";
}
return null;
}
}));
}
private Component getSyncObjectTable(){
return get(ID_TABLE_ROWS);
}
private Component getNavigator(){
return get(ID_PAGING);
}
private Component getSyncObjectEditor(){
return get(ID_OBJECT_SYNC_EDITOR);
}
public Component getReactionList() {
return get(createComponentPath(ID_OBJECT_SYNC_EDITOR, ID_EDITOR_REACTION));
}
public Component getCorrelationList() {
return get(createComponentPath(ID_OBJECT_SYNC_EDITOR, ID_EDITOR_EDITOR_CORRELATION));
}
private Component getThirdRowContainer(){
return get(ID_THIRD_ROW_CONTAINER);
}
private void insertEmptyThirdRow(){
getThirdRowContainer().replaceWith(new WebMarkupContainer(ID_THIRD_ROW_CONTAINER));
}
private void conditionEditPerformed(AjaxRequestTarget target){
WebMarkupContainer newContainer = new SynchronizationExpressionEditor(ID_THIRD_ROW_CONTAINER,
new PropertyModel<>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED + ".condition"), parentPage) {
@Override
public String getLabel(){
return "SynchronizationExpressionEditor.label.condition";
}
};
getThirdRowContainer().replaceWith(newContainer);
resetSelections(target);
target.add(getThirdRowContainer(), get(ID_OBJECT_SYNC_EDITOR), getPageBase().getFeedbackPanel());
}
private void confirmationEditPerformed(AjaxRequestTarget target){
WebMarkupContainer newContainer = new SynchronizationExpressionEditor(ID_THIRD_ROW_CONTAINER,
new PropertyModel<>(syncDtoModel, ResourceSynchronizationDto.F_SELECTED + ".confirmation"), parentPage){
@Override
public String getLabel(){
return "SynchronizationExpressionEditor.label.confirmation";
}
};
getThirdRowContainer().replaceWith(newContainer);
resetSelections(target);
target.add(getThirdRowContainer(), get(ID_OBJECT_SYNC_EDITOR), getPageBase().getFeedbackPanel());
}
private void correlationEditPerformed(AjaxRequestTarget target, @NotNull ConditionalSearchFilterType condition) {
if (condition.getCondition() == null) {
condition.setCondition(new ExpressionType()); // removed at save
}
resetSelections(target);
syncDtoModel.getObject().setSelectedCorrelation(condition);
WebMarkupContainer newContainer = new ConditionalSearchFilterEditor(ID_THIRD_ROW_CONTAINER,
new NonEmptyWrapperModel<>(new Model<>(condition)), parentPage);
getThirdRowContainer().replaceWith(newContainer);
target.add(getThirdRowContainer(), get(ID_OBJECT_SYNC_EDITOR), getPageBase().getFeedbackPanel());
}
private void reactionEditPerformed(AjaxRequestTarget target, SynchronizationReactionType reaction){
WebMarkupContainer newContainer = new SynchronizationReactionEditor(ID_THIRD_ROW_CONTAINER, new Model<>(reaction), this, parentPage);
getThirdRowContainer().replaceWith(newContainer);
resetSelections(target);
syncDtoModel.getObject().setSelectedReaction(reaction);
target.add(getThirdRowContainer(), get(ID_OBJECT_SYNC_EDITOR), getPageBase().getFeedbackPanel());
}
@Override
public void applyState() {
parentPage.refreshIssues(null);
if (parentPage.isReadOnly() || !isComplete()) {
return;
}
savePerformed();
insertEmptyThirdRow();
resetSelections(null);
}
private void savePerformed() {
PrismObject<ResourceType> oldResource;
PrismObject<ResourceType> newResource = resourceModel.getObject();
Task task = getPageBase().createSimpleTask(OPERATION_SAVE_SYNC);
OperationResult result = task.getResult();
ModelService modelService = getPageBase().getModelService();
boolean saved = false;
removeEmptyContainers(newResource.asObjectable());
try {
oldResource = WebModelServiceUtils.loadObject(ResourceType.class, newResource.getOid(), getPageBase(), task, result);
if (oldResource != null) {
ObjectDelta<ResourceType> delta = parentPage.computeDiff(oldResource, newResource);
if (!delta.isEmpty()) {
parentPage.logDelta(delta);
Collection<ObjectDelta<? extends ObjectType>> deltas = WebComponentUtil.createDeltaCollection(delta);
modelService.executeChanges(deltas, null, getPageBase().createSimpleTask(OPERATION_SAVE_SYNC), result);
parentPage.resetModels();
syncDtoModel.reset();
saved = true;
}
}
} catch (CommonException|RuntimeException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't save resource synchronization.", e);
result.recordFatalError(getString("SynchronizationStep.message.cantSave", e));
} finally {
result.computeStatusIfUnknown();
setResult(result);
}
if (parentPage.showSaveResultInPage(saved, result)) {
getPageBase().showResult(result);
}
}
private void removeEmptyContainers(ResourceType resourceType) {
if (resourceType.getSynchronization() == null) {
return;
}
for (ObjectSynchronizationType objectSync : resourceType.getSynchronization().getObjectSynchronization()) {
objectSync.getObjectClass().removeIf(name -> name == null || StringUtils.isBlank(name.getLocalPart()));
if (objectSync.getCondition() != null && ExpressionUtil.isEmpty(objectSync.getCondition())) {
objectSync.setCondition(null);
}
if (objectSync.getConfirmation() != null && ExpressionUtil.isEmpty(objectSync.getConfirmation())) {
objectSync.setConfirmation(null);
}
for (ConditionalSearchFilterType correlationFilter : objectSync.getCorrelation()) {
if (correlationFilter.getCondition() != null && ExpressionUtil.isEmpty(correlationFilter.getCondition())) {
correlationFilter.setCondition(null);
}
}
}
}
private void editSyncObjectPerformed(AjaxRequestTarget target, ObjectSynchronizationType syncObject) {
boolean wasAnySelected = isAnySelected();
syncDtoModel.getObject().setSelected(syncObject);
insertEmptyThirdRow();
resetSelections(target);
if (wasAnySelected) {
target.add(getSyncObjectTable(), getNavigator(), getSyncObjectEditor(), getThirdRowContainer());
} else {
target.add(this);
}
}
private void deleteSyncObjectPerformed(AjaxRequestTarget target, ObjectSynchronizationType syncObject) {
if (isSelected(syncObject)) {
syncDtoModel.getObject().setSelected(null);
insertEmptyThirdRow();
resetSelections(target);
target.add(getThirdRowContainer());
}
ArrayList<ObjectSynchronizationType> list = (ArrayList<ObjectSynchronizationType>) syncDtoModel.getObject().getObjectSynchronizationList();
list.remove(syncObject);
if (list.isEmpty()) {
insertEmptyThirdRow();
resetSelections(target);
target.add(getThirdRowContainer());
}
target.add(getSyncObjectEditor(), getSyncObjectTable(), getNavigator());
parentPage.refreshIssues(target);
}
private boolean isSelected(ObjectSynchronizationType syncObject) {
return syncDtoModel.getObject().getSelected() == syncObject;
}
private void addSyncObjectPerformed(AjaxRequestTarget target){
ObjectSynchronizationType syncObject = new ObjectSynchronizationType();
syncObject.setEnabled(true);
//syncObject.setName(generateName(getString("SynchronizationStep.label.newObjectType")));
resourceModel.getObject().asObjectable().getSynchronization().getObjectSynchronization().add(syncObject);
editSyncObjectPerformed(target, syncObject);
parentPage.refreshIssues(target);
}
private class UpdateNamesBehaviour extends EmptyOnChangeAjaxFormUpdatingBehavior {
@Override
protected void onUpdate(AjaxRequestTarget target) {
target.add(getSyncObjectTable(), getSyncObjectEditor().get(ID_EDITOR_LABEL));
parentPage.refreshIssues(target);
}
}
private void resetSelections(AjaxRequestTarget target) {
ResourceSynchronizationDto dto = syncDtoModel.getObject();
if (dto.getSelectedCorrelation() != null) {
dto.setSelectedCorrelation(null);
if (target != null) {
target.add(getCorrelationList());
}
}
if (dto.getSelectedReaction() != null) {
dto.setSelectedReaction(null);
if (target != null) {
target.add(getReactionList());
}
}
}
private String generateName(String prefix) {
List<String> existing = new ArrayList<>();
for (ObjectSynchronizationType sync : syncDtoModel.getObject().getObjectSynchronizationList()) {
CollectionUtils.addIgnoreNull(existing, sync.getName());
}
return SchemaHandlingStep.generateName(existing, prefix);
}
}