-
Notifications
You must be signed in to change notification settings - Fork 188
/
SchemaHandlingStep.java
685 lines (553 loc) · 28.7 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
/*
* 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.component.wizard.resource;
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.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.LoadableModel;
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.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.session.UserProfileStorage;
import com.evolveum.midpoint.web.util.WebMiscUtil;
import com.evolveum.midpoint.web.util.WebModelUtils;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
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.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.repeater.Item;
import org.apache.wicket.markup.repeater.data.DataView;
import org.apache.wicket.model.AbstractReadOnlyModel;
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 javax.xml.namespace.QName;
import java.util.*;
/**
* @author lazyman
* @author shood
*/
public class SchemaHandlingStep extends WizardStep {
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 Integer AUTO_COMPLETE_LIST_SIZE = 10;
private IModel<PrismObject<ResourceType>> resourceModel;
private IModel<SchemaHandlingDto> model;
public SchemaHandlingStep(final IModel<PrismObject<ResourceType>> resourceModel) {
this.resourceModel = resourceModel;
model = new LoadableModel<SchemaHandlingDto>(false) {
@Override
protected SchemaHandlingDto load() {
return lodObjectTypes();
}
};
initLayout();
}
private SchemaHandlingDto lodObjectTypes(){
SchemaHandlingDto dto = new SchemaHandlingDto();
List<ResourceObjectTypeDefinitionTypeDto> list = new ArrayList<>();
if(resourceModel != null && resourceModel.getObject() != null
&& resourceModel.getObject().asObjectable() != null){
SchemaHandlingType schemaHandling = resourceModel.getObject().asObjectable().getSchemaHandling();
ResourceObjectTypeDefinitionTypeDto obj;
if(schemaHandling != null && schemaHandling.getObjectType() != null){
for(ResourceObjectTypeDefinitionType objectType: schemaHandling.getObjectType()){
// temporary fix - think about better solution
if(objectType.getAttribute().isEmpty()){
objectType.getAttribute().add(new ResourceAttributeDefinitionType());
}
if(objectType.getAssociation().isEmpty()){
objectType.getAssociation().add(new ResourceObjectAssociationType());
}
obj = new ResourceObjectTypeDefinitionTypeDto(objectType);
list.add(obj);
}
}
}
dto.setSelected(createPlaceholderObjectType());
dto.setObjectClassList(loadResourceObjectClassList(resourceModel, LOGGER, getString("SchemaHandlingStep.message.errorLoadingObjectTypeList")));
dto.setObjectTypeList(list);
return dto;
}
private ResourceObjectTypeDefinitionType createPlaceholderObjectType(){
// temporary fix - think about better solution
ResourceObjectTypeDefinitionType placeholder = new ResourceObjectTypeDefinitionType();
placeholder.getAttribute().add(new ResourceAttributeDefinitionType());
placeholder.getAssociation().add(new ResourceObjectAssociationType());
return placeholder;
}
private boolean isAnySelected(){
for(ResourceObjectTypeDefinitionTypeDto dto: model.getObject().getObjectTypeList()){
if(dto.isSelected()){
return true;
}
}
return false;
}
private void initLayout(){
final ListDataProvider<ResourceObjectTypeDefinitionTypeDto> objectTypeProvider = new ListDataProvider<>(this,
new PropertyModel<List<ResourceObjectTypeDefinitionTypeDto>>(model, SchemaHandlingDto.F_OBJECT_TYPES));
// first row - object types list
WebMarkupContainer tableBody = new WebMarkupContainer(ID_ROWS);
tableBody.setOutputMarkupId(true);
add(tableBody);
// second row - object type editor
WebMarkupContainer objectTypeEditor = new WebMarkupContainer(ID_OBJECT_TYPE_EDITOR);
objectTypeEditor.setOutputMarkupId(true);
objectTypeEditor.add(new VisibleEnableBehaviour(){
@Override
public boolean isEnabled() {
return isAnySelected();
}
});
add(objectTypeEditor);
// third row container
WebMarkupContainer thirdRowContainer = new WebMarkupContainer(ID_THIRD_ROW_CONTAINER);
thirdRowContainer.setOutputMarkupId(true);
add(thirdRowContainer);
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, Form<?> form) {
editObjectTypePerformed(target, objectType);
}
};
item.add(link);
Label label = new Label(ID_NAME_OBJECT_TYPE, createObjectTypeDisplayModel(objectType));
label.setOutputMarkupId(true);
link.add(label);
AjaxLink delete = new AjaxLink(ID_BUTTON_DELETE_OBJECT_TYPE) {
@Override
public void onClick(AjaxRequestTarget target) {
deleteObjectTypePerformed(target, objectType);
}
};
item.add(delete);
item.add(AttributeModifier.replace("class", new AbstractReadOnlyModel<String>() {
@Override
public String getObject() {
if(item.getModelObject().isSelected()){
return "success";
}
return null;
}
}));
}
};
tableBody.add(objectTypeDataView);
NavigatorPanel navigator = new NavigatorPanel(ID_PAGING_OBJECT_TYPE, objectTypeDataView, true);
navigator.setOutputMarkupPlaceholderTag(true);
navigator.setOutputMarkupId(true);
add(navigator);
AjaxLink add = new AjaxLink(ID_BUTTON_ADD_OBJECT_TYPE) {
@Override
public void onClick(AjaxRequestTarget target) {
addObjectTypePerformed(target);
}
};
add(add);
initObjectTypeEditor(objectTypeEditor);
}
private IModel<String> createObjectTypeDisplayModel(final ResourceObjectTypeDefinitionTypeDto objectType){
return new AbstractReadOnlyModel<String>() {
@Override
public String getObject() {
StringBuilder sb = new StringBuilder();
if(objectType != null && objectType.getObjectType() != null){
ResourceObjectTypeDefinitionType object = objectType.getObjectType();
sb.append(object.getDisplayName() != null ? object.getDisplayName() : "- ");
if(object.getKind() != null || object.getIntent() != null){
sb.append(" (");
sb.append(object.getKind() != null ? object.getKind() : " - ");
sb.append(", ");
sb.append(object.getIntent() != null ? object.getIntent() : "- ");
sb.append(")");
}
}
return sb.toString();
}
};
}
private void initObjectTypeEditor(WebMarkupContainer editor){
Label editorLabel = new Label(ID_EDITOR_NAME, new LoadableModel<String>() {
@Override
protected String load() {
if(!isAnySelected()){
return getString("SchemaHandlingStep.label.emptyDisplayName");
} else {
return model.getObject().getSelected().getDisplayName();
}
}
});
editor.add(editorLabel);
DropDownChoice editorKind = new DropDownChoice<>(ID_EDITOR_KIND,
new PropertyModel<ShadowKindType>(model, SchemaHandlingDto.F_SELECTED + ".kind"),
WebMiscUtil.createReadonlyModelFromEnum(ShadowKindType.class),
new EnumChoiceRenderer<ShadowKindType>(this));
editor.add(editorKind);
TextField editorIntent = new TextField<>(ID_EDITOR_INTENT, new PropertyModel<String>(model,
SchemaHandlingDto.F_SELECTED + ".intent"));
editor.add(editorIntent);
TextField editorDisplayName = new TextField<>(ID_EDITOR_DISPLAY_NAME, new PropertyModel<String>(model,
SchemaHandlingDto.F_SELECTED + ".displayName"));
editor.add(editorDisplayName);
TextArea editorDescription = new TextArea<>(ID_EDITOR_DESCRIPTION, new PropertyModel<String>(model,
SchemaHandlingDto.F_SELECTED + ".description"));
editor.add(editorDescription);
CheckBox editorDefault = new CheckBox(ID_EDITOR_DEFAULT, new PropertyModel<Boolean>(model,
SchemaHandlingDto.F_SELECTED + "._default"));
editor.add(editorDefault);
AjaxSubmitLink editorDependency = new AjaxSubmitLink(ID_EDITOR_BUTTON_DEPENDENCY) {
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
dependencyEditPerformed(target);
}
};
addDisabledClassModifier(editorDependency);
editor.add(editorDependency);
AutoCompleteTextField<String> editorObjectClass = new AutoCompleteTextField<String>(ID_EDITOR_OBJECT_CLASS,
new PropertyModel<String>(model, SchemaHandlingDto.F_SELECTED_OBJECT_CLASS)) {
@Override
protected Iterator<String> getChoices(String input) {
if(Strings.isEmpty(input)){
List<String> emptyList = Collections.emptyList();
return emptyList.iterator();
}
List<QName> resourceObjectClassList = model.getObject().getObjectClassList();
List<String> choices = new ArrayList<>(AUTO_COMPLETE_LIST_SIZE);
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();
}
};
editorObjectClass.add(createObjectClassValidator(new LoadableModel<List<QName>>(false) {
@Override
protected List<QName> load() {
return model.getObject().getObjectClassList();
}
}));
editor.add(editorObjectClass);
MultiValueTextEditPanel editorAttributes = new MultiValueTextEditPanel<ResourceAttributeDefinitionType>(ID_EDITOR_ATTRIBUTES,
new PropertyModel<List<ResourceAttributeDefinitionType>>(model, SchemaHandlingDto.F_SELECTED + ".attribute"), false, false){
@Override
protected IModel<String> createTextModel(final IModel<ResourceAttributeDefinitionType> model) {
return new Model<String>() {
@Override
public String getObject() {
StringBuilder sb = new StringBuilder();
if(model.getObject().getRef() != null){
sb.append(model.getObject().getRef().getLocalPart());
} else {
return null;
}
if(model.getObject().getDisplayName() != null){
sb.append(" (").append(model.getObject().getDisplayName()).append(")");
}
return sb.toString();
}
};
}
@Override
protected ResourceAttributeDefinitionType createNewEmptyItem(){
return new ResourceAttributeDefinitionType();
}
@Override
protected void editPerformed(AjaxRequestTarget target, ResourceAttributeDefinitionType object){
editAttributePerformed(target, object);
}
@Override
protected boolean buttonsDisabled(){
return !isAnySelected();
}
};
editor.add(editorAttributes);
MultiValueTextEditPanel editorAssociations = new MultiValueTextEditPanel<ResourceObjectAssociationType>(ID_EDITOR_ASSOCIATIONS,
new PropertyModel<List<ResourceObjectAssociationType>>(model, SchemaHandlingDto.F_SELECTED + ".association"), false, false){
@Override
protected IModel<String> createTextModel(final IModel<ResourceObjectAssociationType> model) {
return new Model<String>() {
@Override
public String getObject() {
StringBuilder sb = new StringBuilder();
if(model.getObject().getRef() != null){
sb.append(model.getObject().getRef().getLocalPart());
} else {
return null;
}
if(model.getObject().getDisplayName() != null){
sb.append(" (").append(model.getObject().getDisplayName()).append(")");
}
return sb.toString();
}
};
}
@Override
protected ResourceObjectAssociationType createNewEmptyItem(){
return new ResourceObjectAssociationType();
}
@Override
protected void editPerformed(AjaxRequestTarget target, ResourceObjectAssociationType object){
editAssociationPerformed(target, object);
}
@Override
protected boolean buttonsDisabled(){
return !isAnySelected();
}
};
editor.add(editorAssociations);
DropDownChoice editorAssignmentPolicyRef = new DropDownChoice<>(ID_EDITOR_ASSIGNMENT_POLICY,
new PropertyModel<AssignmentPolicyEnforcementType>(model, SchemaHandlingDto.F_SELECTED + ".assignmentPolicyEnforcement"),
WebMiscUtil.createReadonlyModelFromEnum(AssignmentPolicyEnforcementType.class),
new EnumChoiceRenderer<AssignmentPolicyEnforcementType>(this));
editor.add(editorAssignmentPolicyRef);
AjaxSubmitLink editorIteration = new AjaxSubmitLink(ID_EDITOR_BUTTON_ITERATION) {
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
iterationEditPerformed(target);
}
};
addDisabledClassModifier(editorIteration);
editor.add(editorIteration);
AjaxSubmitLink editorProtected = new AjaxSubmitLink(ID_EDITOR_BUTTON_PROTECTED) {
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
protectedEditPerformed(target);
}
};
addDisabledClassModifier(editorProtected);
editor.add(editorProtected);
AjaxSubmitLink editorActivation = new AjaxSubmitLink(ID_EDITOR_BUTTON_ACTIVATION) {
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
activationEditPerformed(target);
}
};
addDisabledClassModifier(editorActivation);
editor.add(editorActivation);
AjaxSubmitLink editorCredentials = new AjaxSubmitLink(ID_EDITOR_BUTTON_CREDENTIALS) {
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
credentialsEditPerformed(target);
}
};
addDisabledClassModifier(editorCredentials);
editor.add(editorCredentials);
}
private void addDisabledClassModifier(Component component){
component.add(new AttributeAppender("class", new AbstractReadOnlyModel<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);
}
private Component getThirdRowContainer(){
return get(ID_THIRD_ROW_CONTAINER);
}
private Component getNavigator(){
return get(ID_PAGING_OBJECT_TYPE);
}
private void resetSelected(){
for(ResourceObjectTypeDefinitionTypeDto dto: model.getObject().getObjectTypeList()){
dto.setSelected(false);
}
}
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<List<ResourceObjectTypeDependencyType>>(model, SchemaHandlingDto.F_SELECTED + ".dependency"));
getThirdRowContainer().replaceWith(newContainer);
target.add(getThirdRowContainer(), getPageBase().getFeedbackPanel());
}
private void iterationEditPerformed(AjaxRequestTarget target){
WebMarkupContainer newContainer = new ResourceIterationEditor(ID_THIRD_ROW_CONTAINER,
new PropertyModel<IterationSpecificationType>(model, SchemaHandlingDto.F_SELECTED + ".iteration"));
getThirdRowContainer().replaceWith(newContainer);
target.add(getThirdRowContainer(), getPageBase().getFeedbackPanel());
}
private void protectedEditPerformed(AjaxRequestTarget target){
WebMarkupContainer newContainer = new ResourceProtectedEditor(ID_THIRD_ROW_CONTAINER,
new PropertyModel<List<ResourceObjectPatternType>>(model, SchemaHandlingDto.F_SELECTED + "._protected"));
getThirdRowContainer().replaceWith(newContainer);
target.add(getThirdRowContainer(), getPageBase().getFeedbackPanel());
}
private void activationEditPerformed(AjaxRequestTarget target){
WebMarkupContainer newContainer = new ResourceActivationEditor(ID_THIRD_ROW_CONTAINER,
new PropertyModel<ResourceActivationDefinitionType>(model, SchemaHandlingDto.F_SELECTED + ".activation"));
getThirdRowContainer().replaceWith(newContainer);
target.add(getThirdRowContainer(), getPageBase().getFeedbackPanel());
}
private void credentialsEditPerformed(AjaxRequestTarget target){
WebMarkupContainer newContainer = new ResourceCredentialsEditor(ID_THIRD_ROW_CONTAINER,
new PropertyModel<ResourceCredentialsDefinitionType>(model, SchemaHandlingDto.F_SELECTED + ".credentials"));
getThirdRowContainer().replaceWith(newContainer);
target.add(getThirdRowContainer(), getPageBase().getFeedbackPanel());
}
private void editAttributePerformed(AjaxRequestTarget target, ResourceAttributeDefinitionType object){
if(model.getObject().getSelected() != null && model.getObject().getSelected().getObjectClass() != null){
WebMarkupContainer newContainer = new ResourceAttributeEditor(ID_THIRD_ROW_CONTAINER, new Model<>(object),
model.getObject().getSelected(), resourceModel.getObject());
getThirdRowContainer().replaceWith(newContainer);
target.add(getThirdRowContainer());
} else {
warn(getString("SchemaHandlingStep.message.selectObjectClassAttr"));
getThirdRowContainer().replaceWith(new WebMarkupContainer(ID_THIRD_ROW_CONTAINER));
target.add(getPageBase().getFeedbackPanel(), getThirdRowContainer());
}
}
private void editAssociationPerformed(AjaxRequestTarget target, ResourceObjectAssociationType object){
if(model.getObject().getSelected() != null && model.getObject().getSelected().getObjectClass() != null){
WebMarkupContainer newContainer = new ResourceAssociationEditor(ID_THIRD_ROW_CONTAINER, new Model<>(object),
model.getObject().getSelected(), resourceModel.getObject());
getThirdRowContainer().replaceWith(newContainer);
target.add(getThirdRowContainer(), getPageBase().getFeedbackPanel());
} else {
warn(getString("SchemaHandlingStep.message.selectObjectClassAss"));
getThirdRowContainer().replaceWith(new WebMarkupContainer(ID_THIRD_ROW_CONTAINER));
target.add(getPageBase().getFeedbackPanel(), getThirdRowContainer());
}
}
@Override
public void applyState() {
savePerformed();
}
private void savePerformed(){
PrismObject<ResourceType> oldResource;
PrismObject<ResourceType> newResource = resourceModel.getObject();
OperationResult result = new OperationResult(OPERATION_SAVE_SCHEMA_HANDLING);
ModelService modelService = getPageBase().getModelService();
ObjectDelta delta;
try{
oldResource = WebModelUtils.loadObject(ResourceType.class, newResource.getOid(), result, getPageBase());
if(oldResource != null){
delta = oldResource.diff(newResource);
if(LOGGER.isTraceEnabled()){
LOGGER.trace(delta.debugDump());
}
Collection<ObjectDelta<? extends ObjectType>> deltas = WebMiscUtil.createDeltaCollection(delta);
modelService.executeChanges(deltas, null, getPageBase().createSimpleTask(OPERATION_SAVE_SCHEMA_HANDLING), result);
}
} catch (Exception e){
LoggingUtils.logException(LOGGER, "Couldn't save schema handling", e);
result.recordFatalError(getString("SchemaHandlingStep.message.saveError", e));
} finally {
result.computeStatusIfUnknown();
}
if(WebMiscUtil.showResultInPage(result)){
getPageBase().showResult(result);
}
}
private void editObjectTypePerformed(AjaxRequestTarget target, ResourceObjectTypeDefinitionTypeDto objectType){
resetSelected();
objectType.setSelected(true);
model.getObject().setSelected(objectType.getObjectType());
insertEmptyThirdRow();
target.add(getObjectListTable(), getNavigator(), getObjectTypeEditor(), getThirdRowContainer());
}
private void deleteObjectTypePerformed(AjaxRequestTarget target, ResourceObjectTypeDefinitionTypeDto objectType){
ArrayList<ResourceObjectTypeDefinitionTypeDto> list = (ArrayList<ResourceObjectTypeDefinitionTypeDto>) model.getObject().getObjectTypeList();
list.remove(objectType);
if(objectType.isSelected()){
model.getObject().setSelected(createPlaceholderObjectType());
insertEmptyThirdRow();
target.add(getThirdRowContainer());
}
if(list.isEmpty()){
ResourceObjectTypeDefinitionType newObj = new ResourceObjectTypeDefinitionType();
newObj.setDisplayName(getString("SchemaHandlingStep.label.newObjectType"));
ResourceObjectTypeDefinitionTypeDto dto = new ResourceObjectTypeDefinitionTypeDto(newObj);
dto.setSelected(true);
list.add(dto);
}
target.add(getObjectTypeEditor(), getObjectListTable(), getNavigator());
}
private void addObjectTypePerformed(AjaxRequestTarget target){
ResourceObjectTypeDefinitionType objectType = new ResourceObjectTypeDefinitionType();
objectType.getAttribute().add(new ResourceAttributeDefinitionType());
objectType.getAssociation().add(new ResourceObjectAssociationType());
objectType.setDisplayName(getString("SchemaHandlingStep.label.newObjectType"));
ResourceObjectTypeDefinitionTypeDto dto = new ResourceObjectTypeDefinitionTypeDto(objectType);
resetSelected();
dto.setSelected(true);
model.getObject().setSelected(dto.getObjectType());
model.getObject().getObjectTypeList().add(dto);
insertEmptyThirdRow();
target.add(getObjectListTable(), getNavigator(), getObjectTypeEditor(), getThirdRowContainer());
}
}