/
SchemaHandlingStep.java
1245 lines (1054 loc) · 51.6 KB
/
SchemaHandlingStep.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
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* 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.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.prism.util.ItemPathTypeUtil;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
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.QNameUtil;
import com.evolveum.midpoint.util.exception.CommonException;
import com.evolveum.midpoint.util.exception.SchemaException;
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.MultiValueTextEditPanel;
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.WizardUtil;
import com.evolveum.midpoint.web.component.wizard.resource.component.schemahandling.*;
import com.evolveum.midpoint.web.component.wizard.resource.dto.ResourceObjectTypeDefinitionTypeDto;
import com.evolveum.midpoint.web.component.wizard.resource.dto.SchemaHandlingDto;
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 com.evolveum.prism.xml.ns._public.types_3.ItemPathType;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.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.extensions.ajax.markup.html.autocomplete.AutoCompleteSettings;
import org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField;
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.util.string.Strings;
import org.jetbrains.annotations.NotNull;
import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import static com.evolveum.midpoint.schema.util.ResourceTypeUtil.fillDefault;
/**
* @author lazyman
* @author shood
*/
public class SchemaHandlingStep extends WizardStep {
private static final long serialVersionUID = 1L;
private static final Trace LOGGER = TraceManager.getTrace(SchemaHandlingStep.class);
private static final String DOT_CLASS = SchemaHandlingStep.class.getName() + ".";
private static final String OPERATION_SAVE_SCHEMA_HANDLING = DOT_CLASS + "saveSchemaHandling";
private static final String ID_ROWS = "tableRows";
private static final String ID_ROW_OBJECT_TYPE = "objectTypeRow";
private static final String ID_LINK_OBJECT_TYPE = "objectTypeLink";
private static final String ID_NAME_OBJECT_TYPE = "objectTypeName";
private static final String ID_BUTTON_DELETE_OBJECT_TYPE = "objectTypeDelete";
private static final String ID_PAGING_OBJECT_TYPE = "objectTypePaging";
private static final String ID_BUTTON_ADD_OBJECT_TYPE = "objectTypeAddButton";
private static final String ID_OBJECT_TYPE_EDITOR = "objectTypeConfig";
private static final String ID_THIRD_ROW_CONTAINER = "thirdRowContainer";
private static final String ID_EDITOR_NAME = "editorName";
private static final String ID_EDITOR_KIND = "editorKind";
private static final String ID_EDITOR_INTENT = "editorIntent";
private static final String ID_EDITOR_DISPLAY_NAME = "editorDisplayName";
private static final String ID_EDITOR_DESCRIPTION = "editorDescription";
private static final String ID_EDITOR_DEFAULT = "editorDefault";
private static final String ID_EDITOR_BUTTON_DEPENDENCY = "editorDependencyButton";
private static final String ID_EDITOR_OBJECT_CLASS = "editorObjectClass";
private static final String ID_EDITOR_ASSIGNMENT_POLICY = "editorAssignmentPolicyRef";
private static final String ID_EDITOR_BUTTON_ITERATION = "editorIterationButton";
private static final String ID_EDITOR_BUTTON_PROTECTED = "editorProtectedButton";
private static final String ID_EDITOR_BUTTON_ACTIVATION = "editorActivationButton";
private static final String ID_EDITOR_BUTTON_CREDENTIALS = "editorCredentialsButton";
private static final String ID_EDITOR_ATTRIBUTES = "editorAttributes";
private static final String ID_EDITOR_ASSOCIATIONS = "editorAssociations";
private static final String ID_T_KIND = "kindTooltip";
private static final String ID_T_INTENT = "intentTooltip";
private static final String ID_T_DEFAULT = "defaultTooltip";
private static final String ID_T_DEPENDENCY = "dependencyTooltip";
private static final String ID_T_OBJECT_CLASS = "objectClassTooltip";
private static final String ID_T_ATTRIBUTES = "attributesTooltip";
private static final String ID_T_ASSOCIATIONS = "associationsTooltip";
private static final String ID_T_ASSIGNMENT_POLICY_REF = "assignmentPolicyRefTooltip";
private static final String ID_T_ITERATION = "iterationTooltip";
private static final String ID_T_PROTECTED = "protectedTooltip";
private static final String ID_T_ACTIVATION = "activationTooltip";
private static final String ID_T_CREDENTIALS = "credentialsTooltip";
private static final Integer AUTO_COMPLETE_LIST_SIZE = 10;
@NotNull final private PageResourceWizard parentPage;
@NotNull final private NonEmptyLoadableModel<PrismObject<ResourceType>> resourceModel;
@NotNull final private NonEmptyLoadableModel<SchemaHandlingDto> schemaHandlingDtoModel;
public SchemaHandlingStep(@NotNull final NonEmptyLoadableModel<PrismObject<ResourceType>> resourceModel, @NotNull PageResourceWizard parentPage) {
super(parentPage);
this.parentPage = parentPage;
this.resourceModel = resourceModel;
schemaHandlingDtoModel = new NonEmptyLoadableModel<SchemaHandlingDto>(false) {
@Override
@NotNull
protected SchemaHandlingDto load() {
return loadSchemaHandlingDto();
}
@Override
public void reset() {
LOGGER.trace("Resetting schemaHandlingDtoModel {}", schemaHandlingDtoModel);
super.reset();
}
};
parentPage.registerDependentModel(schemaHandlingDtoModel);
initLayout();
setOutputMarkupId(true);
}
private SchemaHandlingDto loadSchemaHandlingDto() {
List<ResourceObjectTypeDefinitionTypeDto> objectTypeDefs = new ArrayList<>();
SchemaHandlingType schemaHandling = getOrCreateSchemaHandling();
for (ResourceObjectTypeDefinitionType objectType: schemaHandling.getObjectType()) {
objectTypeDefs.add(new ResourceObjectTypeDefinitionTypeDto(objectType));
}
List<QName> objectClasses = loadResourceObjectClassList(resourceModel, LOGGER,
getString("SchemaHandlingStep.message.errorLoadingObjectTypeList"));
return new SchemaHandlingDto(objectTypeDefs, objectClasses);
}
private boolean isAnySelected() {
return schemaHandlingDtoModel.getObject().getSelectedObjectTypeDto() != null;
}
private void initLayout() {
final ListDataProvider<ResourceObjectTypeDefinitionTypeDto> objectTypeProvider = new ListDataProvider<>(this,
new PropertyModel<List<ResourceObjectTypeDefinitionTypeDto>>(schemaHandlingDtoModel, SchemaHandlingDto.F_OBJECT_TYPE_DTO_LIST));
// first row - object types table
WebMarkupContainer objectTypesTable = new WebMarkupContainer(ID_ROWS);
objectTypesTable.setOutputMarkupId(true);
add(objectTypesTable);
// second row - object type editor
WebMarkupContainer objectTypeEditor = new WebMarkupContainer(ID_OBJECT_TYPE_EDITOR);
objectTypeEditor.setOutputMarkupId(true);
objectTypeEditor.add(new VisibleEnableBehaviour(){
@Override
public boolean isVisible() {
return isAnySelected();
}
});
add(objectTypeEditor);
// third row container
WebMarkupContainer thirdRowContainer = new WebMarkupContainer(ID_THIRD_ROW_CONTAINER);
thirdRowContainer.setOutputMarkupId(true);
add(thirdRowContainer);
// ---------------------- details -----------------------
// Object type table (list)
DataView<ResourceObjectTypeDefinitionTypeDto> objectTypeDataView = new DataView<ResourceObjectTypeDefinitionTypeDto>(ID_ROW_OBJECT_TYPE,
objectTypeProvider, UserProfileStorage.DEFAULT_PAGING_SIZE) {
@Override
protected void populateItem(final Item<ResourceObjectTypeDefinitionTypeDto> item) {
final ResourceObjectTypeDefinitionTypeDto objectType = item.getModelObject();
AjaxSubmitLink link = new AjaxSubmitLink(ID_LINK_OBJECT_TYPE) {
@Override
protected void onSubmit(AjaxRequestTarget target) {
editObjectTypePerformed(target, objectType);
}
@Override
protected void onError(AjaxRequestTarget target) {
target.add(parentPage.getFeedbackPanel());
}
};
item.add(link);
Label label = new Label(ID_NAME_OBJECT_TYPE, createObjectTypeDisplayModel(objectType));
label.setOutputMarkupId(true);
link.add(label);
AjaxLink<Void> delete = new AjaxLink<Void>(ID_BUTTON_DELETE_OBJECT_TYPE) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
deleteObjectTypePerformed(target, objectType);
}
};
parentPage.addEditingVisibleBehavior(delete);
link.add(delete);
item.add(AttributeModifier.replace("class", new IModel<String>() {
@Override
public String getObject() {
return isSelected(item.getModelObject()) ? "success" : null;
}
}));
}
};
objectTypesTable.add(objectTypeDataView);
NavigatorPanel navigator = new NavigatorPanel(ID_PAGING_OBJECT_TYPE, objectTypeDataView, true);
navigator.setOutputMarkupPlaceholderTag(true);
navigator.setOutputMarkupId(true);
add(navigator);
AjaxSubmitLink add = new AjaxSubmitLink(ID_BUTTON_ADD_OBJECT_TYPE) {
@Override
protected void onSubmit(AjaxRequestTarget target) {
addObjectTypePerformed(target);
}
@Override
protected void onError(AjaxRequestTarget target) {
target.add(parentPage.getFeedbackPanel());
}
};
parentPage.addEditingVisibleBehavior(add);
add(add);
initObjectTypeEditor(objectTypeEditor);
}
@Override
protected void onConfigure() {
super.onConfigure();
if (!isAnySelected()) {
insertEmptyThirdRow();
}
}
private IModel<String> createObjectTypeDisplayModel(final ResourceObjectTypeDefinitionTypeDto objectType){
return new IModel<String>() {
@Override
public String getObject() {
StringBuilder sb = new StringBuilder();
if (objectType != null) {
ResourceObjectTypeDefinitionType object = objectType.getObjectType();
sb.append(object.getDisplayName() != null ? object.getDisplayName() + " " : "");
addKindAndIntent(sb, object.getKind(), object.getIntent());
sb.append(" -> ");
sb.append(object.getObjectClass() != null ? object.getObjectClass().getLocalPart() : "");
}
return sb.toString();
}
};
}
static void addKindAndIntent(StringBuilder sb, ShadowKindType kind, String intent) {
sb.append("(");
sb.append(ResourceTypeUtil.fillDefault(kind));
sb.append(", ");
sb.append(ResourceTypeUtil.fillDefault(intent));
sb.append(")");
}
private void initObjectTypeEditor(WebMarkupContainer editor){
Label editorLabel = new Label(ID_EDITOR_NAME, new IModel<Object>() {
@Override
public String getObject() {
ResourceObjectTypeDefinitionTypeDto selected = schemaHandlingDtoModel.getObject().getSelectedObjectTypeDto();
return selected != null ? selected.getObjectType().getDisplayName() : "";
}
});
editorLabel.setOutputMarkupId(true);
editor.add(editorLabel);
DropDownChoice editorKind = new DropDownChoice<>(ID_EDITOR_KIND,
new PropertyModel<>(schemaHandlingDtoModel, getExpression(ResourceObjectTypeDefinitionType.F_KIND)),
WebComponentUtil.createReadonlyModelFromEnum(ShadowKindType.class),
new EnumChoiceRenderer<>(this));
editorKind.add(new UpdateNamesBehaviour());
parentPage.addEditingEnabledBehavior(editorKind);
editor.add(editorKind);
TextField editorIntent = new TextField<>(ID_EDITOR_INTENT, new PropertyModel<String>(schemaHandlingDtoModel,
getExpression(ResourceObjectTypeDefinitionType.F_INTENT)));
editorIntent.add(new UpdateNamesBehaviour());
parentPage.addEditingEnabledBehavior(editorIntent);
editor.add(editorIntent);
TextField editorDisplayName = new TextField<>(ID_EDITOR_DISPLAY_NAME, new PropertyModel<String>(schemaHandlingDtoModel,
getExpression(ResourceObjectTypeDefinitionType.F_DISPLAY_NAME)));
editorDisplayName.add(new UpdateNamesBehaviour());
parentPage.addEditingEnabledBehavior(editorDisplayName);
editor.add(editorDisplayName);
TextArea editorDescription = new TextArea<>(ID_EDITOR_DESCRIPTION, new PropertyModel<String>(schemaHandlingDtoModel,
getExpression(ResourceObjectTypeDefinitionType.F_DESCRIPTION)));
parentPage.addEditingEnabledBehavior(editorDescription);
editor.add(editorDescription);
final CheckBox editorDefault = new CheckBox(ID_EDITOR_DEFAULT, new PropertyModel<>(schemaHandlingDtoModel,
getExpression(ResourceObjectTypeDefinitionType.F_DEFAULT)));
editorDefault.add(new EmptyOnChangeAjaxFormUpdatingBehavior() {
@Override
protected void onUpdate(AjaxRequestTarget target) {
Boolean newValue = editorDefault.getModelObject();
if (Boolean.TRUE.equals(newValue)) {
SchemaHandlingDto dto = schemaHandlingDtoModel.getObject();
ResourceObjectTypeDefinitionTypeDto selected = dto.getSelectedObjectTypeDto();
ShadowKindType selectedKind = fillDefault(selected.getObjectType().getKind());
for (ResourceObjectTypeDefinitionTypeDto currentObjectTypeDto : dto.getObjectTypeDtoList()) {
ShadowKindType currentKind = fillDefault(currentObjectTypeDto.getObjectType().getKind());
if (currentObjectTypeDto != selected && currentKind == selectedKind
&& Boolean.TRUE.equals(currentObjectTypeDto.getObjectType().isDefault())) {
currentObjectTypeDto.getObjectType().setDefault(false);
}
}
}
parentPage.refreshIssues(target);
}
});
parentPage.addEditingEnabledBehavior(editorDefault);
editor.add(editorDefault);
AjaxSubmitLink editorDependency = new AjaxSubmitLink(ID_EDITOR_BUTTON_DEPENDENCY) {
@Override
protected void onSubmit(AjaxRequestTarget target) {
dependencyEditPerformed(target);
}
};
addDisabledClassModifier(editorDependency);
editor.add(editorDependency);
AutoCompleteSettings autoCompleteSettings = new AutoCompleteSettings();
autoCompleteSettings.setShowListOnEmptyInput(true);
autoCompleteSettings.setMaxHeightInPx(200);
AutoCompleteTextField<String> editorObjectClass = new AutoCompleteTextField<String>(ID_EDITOR_OBJECT_CLASS,
new PropertyModel<>(schemaHandlingDtoModel, SchemaHandlingDto.F_OBJECT_CLASS_NAME), autoCompleteSettings) {
@Override
protected Iterator<String> getChoices(String input) {
return getObjectClassChoices(input);
}
};
editorObjectClass.add(new UpdateNamesBehaviour());
editorObjectClass.add(createObjectClassValidator(new IModel<List<QName>>() {
@Override
public List<QName> getObject() {
return schemaHandlingDtoModel.getObject().getObjectClassList();
}
}));
parentPage.addEditingEnabledBehavior(editorObjectClass);
editorObjectClass.setConvertEmptyInputStringToNull(true);
editor.add(editorObjectClass);
MultiValueTextEditPanel editorAttributes = new MultiValueTextEditPanel<ResourceAttributeDefinitionType>(ID_EDITOR_ATTRIBUTES,
new PropertyModel<>(schemaHandlingDtoModel,
getExpression(ResourceObjectTypeDefinitionType.F_ATTRIBUTE)),
new PropertyModel<>(schemaHandlingDtoModel, SchemaHandlingDto.F_SELECTED_ATTRIBUTE), false, true,
parentPage.getReadOnlyModel()) {
@Override
protected IModel<String> createTextModel(final IModel<ResourceAttributeDefinitionType> model) {
return new Model<String>() {
@Override
public String getObject() {
if (model == null || model.getObject() == null) {
return null;
}
ResourceAttributeDefinitionType attribute = model.getObject();
return formatItemInfo(attribute, attribute.getRef(), attribute.getDisplayName(), attribute.getInbound(), attribute.getOutbound());
}
};
}
@Override
protected ResourceAttributeDefinitionType createNewEmptyItem(){
return createEmptyAttributeObject();
}
@Override
protected void performAddValueHook(AjaxRequestTarget target, ResourceAttributeDefinitionType added) {
parentPage.refreshIssues(target);
}
@Override
protected void editPerformed(AjaxRequestTarget target, ResourceAttributeDefinitionType object){
editAttributePerformed(target, object);
}
@Override
protected boolean buttonsDisabled(){
return !isAnySelected();
}
@Override
protected void performRemoveValueHook(AjaxRequestTarget target, ListItem<ResourceAttributeDefinitionType> item) {
resetThirdRowContainer(target);
parentPage.refreshIssues(target);
}
};
editorAttributes.setOutputMarkupId(true);
editor.add(editorAttributes);
MultiValueTextEditPanel editorAssociations = new MultiValueTextEditPanel<ResourceObjectAssociationType>(ID_EDITOR_ASSOCIATIONS,
new PropertyModel<>(schemaHandlingDtoModel,
getExpression(ResourceObjectTypeDefinitionType.F_ASSOCIATION)),
new PropertyModel<>(schemaHandlingDtoModel, SchemaHandlingDto.F_SELECTED_ASSOCIATION),
false, true, parentPage.getReadOnlyModel()) {
@Override
protected IModel<String> createTextModel(final IModel<ResourceObjectAssociationType> model) {
return new Model<String>() {
@Override
public String getObject() {
ResourceObjectAssociationType association = model.getObject();
if (association == null) {
return null;
}
return formatItemInfo(association, association.getRef(), association.getDisplayName(), association.getInbound(), association.getOutbound());
}
};
}
@Override
protected ResourceObjectAssociationType createNewEmptyItem() {
return createEmptyAssociationObject();
}
@Override
protected void performAddValueHook(AjaxRequestTarget target, ResourceObjectAssociationType added) {
parentPage.refreshIssues(target);
}
@Override
protected void editPerformed(AjaxRequestTarget target, ResourceObjectAssociationType object){
editAssociationPerformed(target, object);
}
@Override
protected boolean buttonsDisabled(){
return !isAnySelected();
}
@Override
protected void performRemoveValueHook(AjaxRequestTarget target, ListItem<ResourceObjectAssociationType> item) {
resetThirdRowContainer(target);
parentPage.refreshIssues(target);
}
};
editorAssociations.setOutputMarkupId(true);
editor.add(editorAssociations);
// DropDownChoice editorAssignmentPolicyRef = new DropDownChoice<>(ID_EDITOR_ASSIGNMENT_POLICY,
// new PropertyModel<AssignmentPolicyEnforcementType>(schemaHandlingDtoModel,
// getExpression(ResourceObjectTypeDefinitionType.F_ASSIGNMENT_POLICY_ENFORCEMENT)),
// WebComponentUtil.createReadonlyModelFromEnum(AssignmentPolicyEnforcementType.class),
// new EnumChoiceRenderer<AssignmentPolicyEnforcementType>(this));
// parentPage.addEditingEnabledBehavior(editorAssignmentPolicyRef);
// editor.add(editorAssignmentPolicyRef);
AjaxSubmitLink editorIteration = new AjaxSubmitLink(ID_EDITOR_BUTTON_ITERATION) {
@Override
protected void onSubmit(AjaxRequestTarget target) {
iterationEditPerformed(target);
}
};
addDisabledClassModifier(editorIteration);
editor.add(editorIteration);
AjaxSubmitLink editorProtected = new AjaxSubmitLink(ID_EDITOR_BUTTON_PROTECTED) {
@Override
protected void onSubmit(AjaxRequestTarget target) {
protectedEditPerformed(target);
}
};
addDisabledClassModifier(editorProtected);
editor.add(editorProtected);
AjaxSubmitLink editorActivation = new AjaxSubmitLink(ID_EDITOR_BUTTON_ACTIVATION) {
@Override
protected void onSubmit(AjaxRequestTarget target) {
activationEditPerformed(target);
}
};
addDisabledClassModifier(editorActivation);
editor.add(editorActivation);
AjaxSubmitLink editorCredentials = new AjaxSubmitLink(ID_EDITOR_BUTTON_CREDENTIALS) {
@Override
protected void onSubmit(AjaxRequestTarget target) {
credentialsEditPerformed(target);
}
};
addDisabledClassModifier(editorCredentials);
editor.add(editorCredentials);
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 defaultTooltip = new Label(ID_T_DEFAULT);
defaultTooltip.add(new InfoTooltipBehavior());
editor.add(defaultTooltip);
Label dependencyTooltip = new Label(ID_T_DEPENDENCY);
dependencyTooltip.add(new InfoTooltipBehavior());
editor.add(dependencyTooltip);
Label objectClassTooltip = new Label(ID_T_OBJECT_CLASS);
objectClassTooltip.add(new InfoTooltipBehavior());
editor.add(objectClassTooltip);
Label attributesTooltip = new Label(ID_T_ATTRIBUTES);
attributesTooltip.add(new InfoTooltipBehavior());
editor.add(attributesTooltip);
Label associationsTooltip = new Label(ID_T_ASSOCIATIONS);
associationsTooltip.add(new InfoTooltipBehavior());
editor.add(associationsTooltip);
Label assignmentPolicyRefTooltip = new Label(ID_T_ASSIGNMENT_POLICY_REF);
assignmentPolicyRefTooltip.add(new InfoTooltipBehavior());
editor.add(assignmentPolicyRefTooltip);
Label iterationTooltip = new Label(ID_T_ITERATION);
iterationTooltip.add(AttributeAppender.append("title", createStringResource("SchemaHandlingStep.tooltip.iteration",
WebComponentUtil.getMidpointCustomSystemName(getPageBase(), "midpoint.default.system.name"))));
iterationTooltip.add(new InfoTooltipBehavior());
editor.add(iterationTooltip);
Label protectedTooltip = new Label(ID_T_PROTECTED);
protectedTooltip.add(new InfoTooltipBehavior());
editor.add(protectedTooltip);
Label activationTooltip = new Label(ID_T_ACTIVATION);
activationTooltip.add(new InfoTooltipBehavior());
editor.add(activationTooltip);
Label credentialsTooltip = new Label(ID_T_CREDENTIALS);
credentialsTooltip.add(new InfoTooltipBehavior());
editor.add(credentialsTooltip);
}
private String formatItemInfo(ResourceItemDefinitionType item, ItemPathType ref, String displayName, List<MappingType> inbounds,
MappingType outbound) {
StringBuilder sb = new StringBuilder();
if (ref != null && !ref.getItemPath().isEmpty()) {
QName name = ref.getItemPath().asSingleName();
if (name != null) {
String prefix = SchemaConstants.NS_ICF_SCHEMA.equals(name.getNamespaceURI()) ? "icfs" : "ri";
sb.append(prefix);
sb.append(": ");
sb.append(name.getLocalPart());
}
} else {
sb.append("-");
}
String duplicateInfo = getDuplicateInfo(item);
if (duplicateInfo != null) {
sb.append(" (").append(duplicateInfo).append(")");
}
if (displayName != null) {
sb.append(" (").append(displayName).append(")");
}
if (!inbounds.isEmpty()) {
sb.append(" | ");
sb.append(getString("SchemaHandlingStep.in", ""));
boolean first = true;
for (MappingType inbound : inbounds) {
if (inbound != null && inbound.getTarget() != null) {
if (first) first = false; else sb.append(", ");
sb.append(formatPath(inbound.getTarget().getPath()));
}
}
}
if (outbound != null) {
sb.append(" | ").append(getString("SchemaHandlingStep.out")).append(": ");
boolean first = true;
for (VariableBindingDefinitionType source : outbound.getSource()) {
if (source != null) {
if (first) first = false; else sb.append(", ");
sb.append(formatPath(source.getPath()));
}
}
}
return sb.toString();
}
// FIXME brutally hacked for now
private String formatPath(ItemPathType path) {
String rv = String.valueOf(path);
rv = StringUtils.removeStart(rv, "$user/");
rv = StringUtils.removeStart(rv, "$c:user/");
rv = StringUtils.removeStart(rv, "$focus/");
rv = StringUtils.removeStart(rv, "$c:focus/");
rv = StringUtils.removeStart(rv, "extension/");
rv = StringUtils.removeStart(rv, "c:extension/");
return rv;
}
private String getDuplicateInfo(ResourceItemDefinitionType item) {
ResourceObjectTypeDefinitionTypeDto selectedObjectTypeDto = schemaHandlingDtoModel.getObject().getSelectedObjectTypeDto();
if (selectedObjectTypeDto == null) {
return null; // shouldn't occur
}
ResourceObjectTypeDefinitionType selectedObjectType = selectedObjectTypeDto.getObjectType();
List<ItemRefinedDefinitionType> existingItems = new ArrayList<>();
existingItems.addAll(selectedObjectType.getAttribute());
existingItems.addAll(selectedObjectType.getAssociation());
QName name = ItemPathTypeUtil.asSingleName(item.getRef());
int count = 0, position = 0;
for (ItemRefinedDefinitionType existingItem : existingItems) {
QName existingName = ItemPathTypeUtil.asSingleName(existingItem.getRef());
if (QNameUtil.match(name, existingName)) {
count++;
}
if (item == existingItem) {
position = count;
}
}
if (count == 1) {
return null;
}
return getString("SchemaHandlingStep.dup", position);
}
@NotNull
private String getExpression(QName property) {
return SchemaHandlingDto.F_SELECTED_OBJECT_TYPE_DTO + ".objectType." + property.getLocalPart();
}
private Iterator<String> getObjectClassChoices(String input) {
List<QName> resourceObjectClassList = schemaHandlingDtoModel.getObject().getObjectClassList();
List<String> choices = new ArrayList<>(AUTO_COMPLETE_LIST_SIZE);
if(Strings.isEmpty(input)){
for(QName q: resourceObjectClassList){
choices.add(q.getLocalPart());
if(choices.size() == AUTO_COMPLETE_LIST_SIZE){
break;
}
}
return choices.iterator();
}
for(QName q: resourceObjectClassList){
if(q.getLocalPart().toLowerCase().startsWith(input.toLowerCase())){
choices.add(q.getLocalPart());
if(choices.size() == AUTO_COMPLETE_LIST_SIZE){
break;
}
}
}
return choices.iterator();
}
private void addDisabledClassModifier(Component component){
component.add(new AttributeAppender("class", new IModel<String>() {
@Override
public String getObject() {
if(!isAnySelected()){
return " disabled";
}
return null;
}
}));
}
private Component getObjectListTable(){
return get(ID_ROWS);
}
private Component getObjectTypeEditor(){
return get(ID_OBJECT_TYPE_EDITOR);
}
public Component getAttributeList() {
return get(createComponentPath(ID_OBJECT_TYPE_EDITOR, ID_EDITOR_ATTRIBUTES));
}
public Component getAssociationList() {
return get(createComponentPath(ID_OBJECT_TYPE_EDITOR, ID_EDITOR_ASSOCIATIONS));
}
private Component getThirdRowContainer(){
return get(ID_THIRD_ROW_CONTAINER);
}
private Component getNavigator(){
return get(ID_PAGING_OBJECT_TYPE);
}
private void resetSelected(){
schemaHandlingDtoModel.getObject().setSelectedObjectTypeDto(null);
}
private void insertEmptyThirdRow(){
getThirdRowContainer().replaceWith(new WebMarkupContainer(ID_THIRD_ROW_CONTAINER));
}
private void dependencyEditPerformed(AjaxRequestTarget target){
WebMarkupContainer newContainer = new ResourceDependencyEditor(ID_THIRD_ROW_CONTAINER,
new PropertyModel<>(schemaHandlingDtoModel,
getExpression(ResourceObjectTypeDefinitionType.F_DEPENDENCY)), parentPage);
getThirdRowContainer().replaceWith(newContainer);
target.add(getThirdRowContainer(), get(ID_OBJECT_TYPE_EDITOR), parentPage.getFeedbackPanel());
resetSelections(target);
}
private void resetThirdRowContainer(AjaxRequestTarget target) {
insertEmptyThirdRow();
target.add(getThirdRowContainer());
resetSelections(target);
}
private void resetSelections(AjaxRequestTarget target) {
SchemaHandlingDto dto = schemaHandlingDtoModel.getObject();
if (dto.getSelectedAssociation() != null) {
dto.setSelectedAssociation(null);
target.add(getAssociationList());
}
if (dto.getSelectedAttribute() != null) {
dto.setSelectedAttribute(null);
target.add(getAttributeList());
}
}
private void iterationEditPerformed(AjaxRequestTarget target){
WebMarkupContainer newContainer = new ResourceIterationEditor(ID_THIRD_ROW_CONTAINER,
new PropertyModel<>(schemaHandlingDtoModel,
getExpression(ResourceObjectTypeDefinitionType.F_ITERATION)), parentPage);
getThirdRowContainer().replaceWith(newContainer);
resetSelections(target);
target.add(getThirdRowContainer(), get(ID_OBJECT_TYPE_EDITOR), parentPage.getFeedbackPanel());
}
private void protectedEditPerformed(AjaxRequestTarget target) {
WebMarkupContainer newContainer = new ResourceProtectedEditor(ID_THIRD_ROW_CONTAINER,
new PropertyModel<>(schemaHandlingDtoModel,
getExpression(ResourceObjectTypeDefinitionType.F_PROTECTED)), parentPage);
getThirdRowContainer().replaceWith(newContainer);
resetSelections(target);
target.add(getThirdRowContainer(), get(ID_OBJECT_TYPE_EDITOR), parentPage.getFeedbackPanel());
}
private void activationEditPerformed(AjaxRequestTarget target){
WebMarkupContainer newContainer = new ResourceActivationEditor(ID_THIRD_ROW_CONTAINER,
new PropertyModel<>(schemaHandlingDtoModel,
getExpression(ResourceObjectTypeDefinitionType.F_ACTIVATION)), parentPage.getReadOnlyModel());
getThirdRowContainer().replaceWith(newContainer);
resetSelections(target);
target.add(getThirdRowContainer(), get(ID_OBJECT_TYPE_EDITOR), parentPage.getFeedbackPanel());
}
private void credentialsEditPerformed(AjaxRequestTarget target){
WebMarkupContainer newContainer = new ResourceCredentialsEditor(ID_THIRD_ROW_CONTAINER,
new PropertyModel<>(schemaHandlingDtoModel,
getExpression(ResourceObjectTypeDefinitionType.F_CREDENTIALS)), parentPage);
getThirdRowContainer().replaceWith(newContainer);
resetSelections(target);
target.add(getThirdRowContainer(), get(ID_OBJECT_TYPE_EDITOR), parentPage.getFeedbackPanel());
}
private void editAttributePerformed(AjaxRequestTarget target, final ResourceAttributeDefinitionType object) {
resetSelections(target);
if (schemaHandlingDtoModel.getObject().getSelectedObjectTypeDto() != null && schemaHandlingDtoModel.getObject().getSelectedObjectTypeDto().getObjectType().getObjectClass() != null) {
schemaHandlingDtoModel.getObject().setSelectedAttribute(object);
WebMarkupContainer newContainer = new ResourceAttributeEditor(ID_THIRD_ROW_CONTAINER, new Model<>(object),
schemaHandlingDtoModel.getObject().getSelectedObjectTypeDto().getObjectType(), resourceModel.getObject(), this, parentPage.getReadOnlyModel());
getThirdRowContainer().replaceWith(newContainer);
target.add(getThirdRowContainer(), get(ID_OBJECT_TYPE_EDITOR));
} else {
warn(getString("SchemaHandlingStep.message.selectObjectClassAttr"));
getThirdRowContainer().replaceWith(new WebMarkupContainer(ID_THIRD_ROW_CONTAINER));
target.add(parentPage.getFeedbackPanel(), get(ID_OBJECT_TYPE_EDITOR), getThirdRowContainer());
}
}
private void editAssociationPerformed(AjaxRequestTarget target, ResourceObjectAssociationType object) {
resetSelections(target);
if (schemaHandlingDtoModel.getObject().getSelectedObjectTypeDto() != null && schemaHandlingDtoModel.getObject().getSelectedObjectTypeDto().getObjectType().getObjectClass() != null) {
schemaHandlingDtoModel.getObject().setSelectedAssociation(object);
WebMarkupContainer newContainer = new ResourceAssociationEditor(ID_THIRD_ROW_CONTAINER, new Model<>(object),
schemaHandlingDtoModel.getObject().getSelectedObjectTypeDto().getObjectType(), resourceModel.getObject(), this, parentPage.getReadOnlyModel());
getThirdRowContainer().replaceWith(newContainer);
target.add(getThirdRowContainer(), get(ID_OBJECT_TYPE_EDITOR), parentPage.getFeedbackPanel());
} else {
warn(getString("SchemaHandlingStep.message.selectObjectClassAss"));
getThirdRowContainer().replaceWith(new WebMarkupContainer(ID_THIRD_ROW_CONTAINER));
target.add(parentPage.getFeedbackPanel(), get(ID_OBJECT_TYPE_EDITOR), getThirdRowContainer());
}
}
@Override
public void applyState() {
parentPage.refreshIssues(null);
if (parentPage.isReadOnly() || !isComplete()) {
return;
}
savePerformed();
insertEmptyThirdRow(); // otherwise the original 3rd column would be displayed after returning to the page
// (but without 2nd column)
}
private void savePerformed() {
PrismObject<ResourceType> oldResource;
@NotNull PrismObject<ResourceType> newResource = resourceModel.getObject();
Task task = parentPage.createSimpleTask(OPERATION_SAVE_SCHEMA_HANDLING);
OperationResult result = task.getResult();
ModelService modelService = parentPage.getModelService();
ObjectDelta delta;
boolean saved = false;
removeEmptyContainers(newResource);
try {
oldResource = WebModelServiceUtils.loadObject(ResourceType.class, newResource.getOid(), parentPage, task, result);
if (oldResource == null) {
throw new IllegalStateException("No resource to apply schema handling to");
}
delta = parentPage.computeDiff(oldResource, newResource);
if (!delta.isEmpty()) {
parentPage.logDelta(delta);
@SuppressWarnings("unchecked")
Collection<ObjectDelta<? extends ObjectType>> deltas = WebComponentUtil.createDeltaCollection(delta);
modelService.executeChanges(deltas, null, parentPage.createSimpleTask(OPERATION_SAVE_SCHEMA_HANDLING), result);
parentPage.resetModels();
saved = true;
}
} catch (RuntimeException|CommonException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't save schema handling", e);
result.recordFatalError(getString("SchemaHandlingStep.message.saveError", e));
} finally {
result.computeStatusIfUnknown();
}
setResult(result);
if (parentPage.showSaveResultInPage(saved, result)) {
parentPage.showResult(result);
}
}
private void editObjectTypePerformed(AjaxRequestTarget target, ResourceObjectTypeDefinitionTypeDto objectType){
boolean wasAnySelected = isAnySelected();
schemaHandlingDtoModel.getObject().setSelectedObjectTypeDto(objectType);
resetSelections(target);
insertEmptyThirdRow();
if (wasAnySelected) {
target.add(getObjectListTable(), getNavigator(), getObjectTypeEditor(), getThirdRowContainer());
} else {
target.add(this);
}
}
private void deleteObjectTypePerformed(AjaxRequestTarget target, ResourceObjectTypeDefinitionTypeDto objectType) {
ResourceObjectTypeDefinitionType realObjectType = objectType.getObjectType();
resourceModel.getObject().asObjectable().getSchemaHandling().getObjectType().remove(realObjectType);
if (isSelected(objectType)) {
resetSelected();
resetThirdRowContainer(target);
}
ArrayList<ResourceObjectTypeDefinitionTypeDto> list = (ArrayList<ResourceObjectTypeDefinitionTypeDto>) schemaHandlingDtoModel.getObject().getObjectTypeDtoList();
list.remove(objectType);
if (list.isEmpty()) {
resetThirdRowContainer(target);
}
target.add(getObjectTypeEditor(), getObjectListTable(), getNavigator());
parentPage.refreshIssues(target);
}
private boolean isSelected(@NotNull ResourceObjectTypeDefinitionTypeDto objectType) {
return schemaHandlingDtoModel.getObject().getSelectedObjectTypeDto() == objectType;
}
private void addObjectTypePerformed(AjaxRequestTarget target) {
ResourceObjectTypeDefinitionType objectType = new ResourceObjectTypeDefinitionType();
//objectType.setDisplayName(generateName(getString("SchemaHandlingStep.label.newObjectType")));
ResourceObjectTypeDefinitionTypeDto dto = new ResourceObjectTypeDefinitionTypeDto(objectType);
if (schemaHandlingDtoModel.getObject().getObjectTypeDtoList().isEmpty()) {
objectType.setDefault(true);
}
resetSelected();
schemaHandlingDtoModel.getObject().setSelectedObjectTypeDto(dto);
schemaHandlingDtoModel.getObject().getObjectTypeDtoList().add(dto);
getOrCreateSchemaHandling().getObjectType().add(objectType);
insertEmptyThirdRow();
resetSelections(target);
target.add(this);
parentPage.refreshIssues(target);
}
private String generateName(String prefix) {
List<String> existing = new ArrayList<>();
for (ResourceObjectTypeDefinitionTypeDto objectTypeDto : schemaHandlingDtoModel.getObject().getObjectTypeDtoList()) {
CollectionUtils.addIgnoreNull(existing, objectTypeDto.getObjectType().getDisplayName());
}
return generateName(existing, prefix);
}
static String generateName(List<String> existing, String prefix) {
for (int i = 1;; i++) {
String candidate = prefix + (i > 1 ? " "+i : "");
if (!existing.contains(candidate)) {
return candidate;
}
}
}
@NotNull
private SchemaHandlingType getOrCreateSchemaHandling() {
PrismObject<ResourceType> resource = resourceModel.getObject();
try {
resource.findOrCreateContainer(ResourceType.F_SCHEMA_HANDLING);
} catch (SchemaException e) {
throw new IllegalStateException("Couldn't find/create schemaHandling container: " + e.getMessage(), e);
}
return resource.asObjectable().getSchemaHandling();
}
private void removeEmptyContainers(@NotNull PrismObject<ResourceType> resourcePrism) {
ResourceType resource = resourcePrism.asObjectable();
if (resource.getSchemaHandling() != null) {
SchemaHandlingType schemaHandling = resource.getSchemaHandling();
for (ResourceObjectTypeDefinitionType objectType: schemaHandling.getObjectType()) {
//Clear empty/invalid containers from attributes
List<ResourceAttributeDefinitionType> newAttributeList = new ArrayList<>();
newAttributeList.addAll(objectType.getAttribute());