/
AssignmentEditorPanel.java
1180 lines (991 loc) · 40.1 KB
/
AssignmentEditorPanel.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-2017 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.midpoint.web.component.assignment;
import com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition;
import com.evolveum.midpoint.common.refinery.RefinedResourceSchema;
import com.evolveum.midpoint.common.refinery.RefinedResourceSchemaImpl;
import com.evolveum.midpoint.gui.api.GuiStyleConstants;
import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.gui.api.component.objecttypeselect.ObjectTypeSelectPanel;
import com.evolveum.midpoint.gui.api.component.togglebutton.ToggleIconButton;
import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.gui.api.page.PageBase;
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.*;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.prism.query.builder.QueryBuilder;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.security.api.ItemSecurityDecisions;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.exception.CommunicationException;
import com.evolveum.midpoint.util.exception.ConfigurationException;
import com.evolveum.midpoint.util.exception.ExpressionEvaluationException;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SecurityViolationException;
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.DateInput;
import com.evolveum.midpoint.web.component.input.DropDownChoicePanel;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.web.page.admin.PageAdminFocus;
import com.evolveum.midpoint.web.page.admin.configuration.component.ChooseTypePanel;
import com.evolveum.midpoint.web.page.admin.dto.ObjectViewDto;
import com.evolveum.midpoint.web.page.admin.users.component.AssignmentsPreviewDto;
import com.evolveum.midpoint.web.page.admin.users.dto.UserDtoStatus;
import com.evolveum.midpoint.web.page.self.PageAssignmentDetails;
import com.evolveum.midpoint.web.page.self.PageAssignmentsList;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.types_3.ItemPathType;
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.AjaxCheckBox;
import org.apache.wicket.markup.head.CssHeaderItem;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.TextArea;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
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.request.resource.PackageResourceReference;
import javax.xml.namespace.QName;
import java.util.*;
/**
* @author lazyman
*/
public class AssignmentEditorPanel extends BasePanel<AssignmentEditorDto> {
private static final long serialVersionUID = 1L;
private static final Trace LOGGER = TraceManager.getTrace(AssignmentEditorPanel.class);
private static final String DOT_CLASS = AssignmentEditorPanel.class.getName() + ".";
private static final String OPERATION_LOAD_OBJECT = DOT_CLASS + "loadObject";
private static final String OPERATION_LOAD_RESOURCE = DOT_CLASS + "loadResource";
private static final String OPERATION_LOAD_ATTRIBUTES = DOT_CLASS + "loadAttributes";
private static final String OPERATION_LOAD_TARGET_OBJECT = DOT_CLASS + "loadItemSecurityDecisions";
private static final String ID_HEADER_ROW = "headerRow";
private static final String ID_SELECTED = "selected";
private static final String ID_TYPE_IMAGE = "typeImage";
private static final String ID_NAME_LABEL = "nameLabel";
private static final String ID_NAME = "name";
private static final String ID_ACTIVATION = "activation";
private static final String ID_ACTIVATION_BLOCK = "activationBlock";
private static final String ID_EXPAND = "expand";
protected static final String ID_BODY = "body";
private static final String ID_DESCRIPTION = "description";
private static final String ID_RELATION_CONTAINER = "relationContainer";
private static final String ID_FOCUS_TYPE = "focusType";
private static final String ID_FOCUS_TYPE_CONTAINER = "focusTypeContainer";
protected static final String ID_RELATION = "relation";
private static final String ID_RELATION_LABEL = "relationLabel";
private static final String ID_ADMINISTRATIVE_STATUS = "administrativeStatus";
private static final String ID_VALID_FROM = "validFrom";
private static final String ID_VALID_TO = "validTo";
private static final String ID_SHOW_EMPTY = "showEmpty";
private static final String ID_SHOW_EMPTY_LABEL = "showEmptyLabel";
private static final String ID_ATTRIBUTES = "attributes";
private static final String ID_ATTRIBUTE = "attribute";
private static final String ID_AC_ATTRIBUTE = "acAttribute";
private static final String ID_TARGET = "target";
private static final String ID_TARGET_CONTAINER = "targetContainer";
private static final String ID_CONSTRUCTION_CONTAINER = "constructionContainer";
private static final String ID_CONTAINER_TENANT_REF = "tenantRefContainer";
private static final String ID_TENANT_CHOOSER = "tenantRefChooser";
private static final String ID_CONTAINER_ORG_REF = "orgRefContainer";
private static final String ID_ORG_CHOOSER = "orgRefChooser";
private static final String ID_BUTTON_SHOW_MORE = "errorLink";
private static final String ID_ERROR_ICON = "errorIcon";
private static final String ID_METADATA_CONTAINER = "metadataContainer";
private static final String ID_PROPERTY_CONTAINER = "propertyContainer";
private static final String ID_DESCRIPTION_CONTAINER = "descriptionContainer";
private static final String ID_ADMIN_STATUS_CONTAINER = "administrativeStatusContainer";
private static final String ID_VALID_FROM_CONTAINER = "validFromContainer";
private static final String ID_VALID_TO_CONTAINER = "validToContainer";
private IModel<List<ACAttributeDto>> attributesModel;
protected WebMarkupContainer headerRow;
protected PageBase pageBase;
protected IModel<List<AssignmentsPreviewDto>> privilegesListModel;
protected boolean delegatedToMe;
private LoadableModel<ItemSecurityDecisions> decisionsModel;
public AssignmentEditorPanel(String id, IModel<AssignmentEditorDto> model, boolean delegatedToMe,
LoadableModel<List<AssignmentsPreviewDto>> privilegesListModel, PageBase pageBase) {
super(id, model);
this.pageBase = pageBase;
this.privilegesListModel = privilegesListModel;
this.delegatedToMe = delegatedToMe;
initDecisionsModel();
initLayout();
}
public AssignmentEditorPanel(String id, IModel<AssignmentEditorDto> model) {
this(id, model, null);
}
public AssignmentEditorPanel(String id, IModel<AssignmentEditorDto> model, PageBase pageBase) {
super(id, model);
this.pageBase = pageBase;
attributesModel = new LoadableModel<List<ACAttributeDto>>(false) {
@Override
protected List<ACAttributeDto> load() {
return loadAttributes();
}
};
initDecisionsModel();
initLayout();
}
@Override
public void renderHead(IHeaderResponse response) {
super.renderHead(response);
response.render(CssHeaderItem.forReference(
new PackageResourceReference(AssignmentEditorPanel.class, "AssignmentEditorPanel.css")));
}
protected void initLayout() {
setOutputMarkupId(true);
headerRow = new WebMarkupContainer(ID_HEADER_ROW);
headerRow.add(AttributeModifier.append("class", createHeaderClassModel(getModel())));
headerRow.setOutputMarkupId(true);
add(headerRow);
initHeaderRow();
WebMarkupContainer body = new WebMarkupContainer(ID_BODY);
body.setOutputMarkupId(true);
body.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
AssignmentEditorDto editorDto = AssignmentEditorPanel.this.getModel().getObject();
return !editorDto.isMinimized();
}
});
add(body);
initBodyLayout(body);
}
protected void initHeaderRow(){
AjaxCheckBox selected = new AjaxCheckBox(ID_SELECTED,
new PropertyModel<>(getModel(), AssignmentEditorDto.F_SELECTED)) {
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
// do we want to update something?
}
};
selected.add(new VisibleEnableBehaviour(){
@Override
public boolean isVisible(){
return !getModel().getObject().isSimpleView();
}
});
headerRow.add(selected);
WebMarkupContainer typeImage = new WebMarkupContainer(ID_TYPE_IMAGE);
typeImage.add(AttributeModifier.append("class", createImageTypeModel(getModel())));
headerRow.add(typeImage);
Label errorIcon = new Label(ID_ERROR_ICON);
errorIcon.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
@Override
public boolean isVisible() {
return !isTargetValid();
}
});
headerRow.add(errorIcon);
AjaxLink name = new AjaxLink(ID_NAME) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
nameClickPerformed(target);
}
};
headerRow.add(name);
AjaxLink errorLink = new AjaxLink(ID_BUTTON_SHOW_MORE) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
showErrorPerformed(target);
}
};
errorLink.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
@Override
public boolean isVisible() {
return !isTargetValid();
}
});
headerRow.add(errorLink);
Label nameLabel = new Label(ID_NAME_LABEL, createAssignmentNameLabelModel(false));
nameLabel.setOutputMarkupId(true);
name.add(nameLabel);
Label activation = new Label(ID_ACTIVATION, AssignmentsUtil.createActivationTitleModel(getModel().getObject().getActivation(), "-", AssignmentEditorPanel.this));
headerRow.add(activation);
ToggleIconButton expandButton = new ToggleIconButton(ID_EXPAND, GuiStyleConstants.CLASS_ICON_EXPAND,
GuiStyleConstants.CLASS_ICON_COLLAPSE) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
nameClickPerformed(target);
}
@Override
public boolean isOn() {
return !AssignmentEditorPanel.this.getModelObject().isMinimized();
}
};
expandButton.add(new VisibleEnableBehaviour(){
@Override
public boolean isVisible(){
return !getModel().getObject().isSimpleView();
}
});
headerRow.add(expandButton);
}
protected IModel<String> createAssignmentNameLabelModel(final boolean isManager) {
return new AbstractReadOnlyModel<String>() {
@Override
public String getObject() {
if (getModel() != null && getModel().getObject() != null) {
AssignmentEditorDto dto = getModelObject();
if (dto.getName() != null) {
StringBuilder name = new StringBuilder(dto.getName());
if (isManager) {
name.append(" - Manager");
}
return name.toString();
}
if (dto.getAltName() != null) {
return getString("AssignmentEditorPanel.name.focus");
}
}
return getString("AssignmentEditorPanel.name.noTarget");
}
};
}
private boolean isTargetValid() {
if (getModel() != null && getModel().getObject() != null) {
AssignmentEditorDto dto = getModelObject();
if (dto.getName() == null && dto.getAltName() == null) {
return false;
}
}
return true;
}
protected IModel<String> createHeaderClassModel(final IModel<AssignmentEditorDto> model) {
return AssignmentsUtil.createAssignmentStatusClassModel(model.getObject().getStatus());
}
protected void initBodyLayout(WebMarkupContainer body) {
WebMarkupContainer propertyContainer = new WebMarkupContainer(ID_PROPERTY_CONTAINER);
propertyContainer.setOutputMarkupId(true);
body.add(propertyContainer);
WebMarkupContainer descriptionContainer = new WebMarkupContainer(ID_DESCRIPTION_CONTAINER);
descriptionContainer.setOutputMarkupId(true);
descriptionContainer.add(new VisibleEnableBehaviour(){
private static final long serialVersionUID = 1L;
@Override
public boolean isVisible(){
return isItemAllowed(new ItemPath(FocusType.F_ASSIGNMENT, AssignmentType.F_DESCRIPTION));
}
});
body.add(descriptionContainer);
TextArea<String> description = new TextArea<>(ID_DESCRIPTION,
new PropertyModel<String>(getModel(), AssignmentEditorDto.F_DESCRIPTION));
description.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
@Override
public boolean isEnabled() {
return getModel().getObject().isEditable();
}
});
descriptionContainer.add(description);
WebMarkupContainer relationContainer = new WebMarkupContainer(ID_RELATION_CONTAINER);
relationContainer.setOutputMarkupId(true);
relationContainer.setOutputMarkupPlaceholderTag(true);
relationContainer.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
if (!isItemAllowed(new ItemPath(FocusType.F_ASSIGNMENT, AssignmentType.F_TARGET_REF,
ObjectReferenceType.F_RELATION))){
return false;
}
AssignmentEditorDto dto = getModel().getObject();
if (dto != null) {
if (AssignmentEditorDtoType.ORG_UNIT.equals(dto.getType()) ||
AssignmentEditorDtoType.SERVICE.equals(dto.getType()) ||
AssignmentEditorDtoType.ROLE.equals(dto.getType())) {
return true;
}
}
return false;
}
});
body.add(relationContainer);
addRelationDropDown(relationContainer);
WebMarkupContainer focusTypeContainer = new WebMarkupContainer(ID_FOCUS_TYPE_CONTAINER);
focusTypeContainer.setOutputMarkupId(true);
focusTypeContainer.add(new VisibleEnableBehaviour(){
private static final long serialVersionUID = 1L;
@Override
public boolean isVisible(){
return isItemAllowed(new ItemPath(FocusType.F_ASSIGNMENT, AssignmentType.F_FOCUS_TYPE));
}
});
body.add(focusTypeContainer);
ObjectTypeSelectPanel<FocusType> focusType = new ObjectTypeSelectPanel<>(ID_FOCUS_TYPE,
new PropertyModel<>(getModel(), AssignmentEditorDto.F_FOCUS_TYPE), FocusType.class);
focusTypeContainer.add(focusType);
Label relationLabel = new Label(ID_RELATION_LABEL, new AbstractReadOnlyModel<String>() {
@Override
public String getObject() {
if (getModel() == null || getModel().getObject() == null) {
return getString("AssignmentEditorPanel.relation.notSpecified");
}
AssignmentEditorDto object = getModel().getObject();
String propertyKey = RelationTypes.class.getSimpleName() + "." +
(object.getTargetRef() == null || object.getTargetRef().getRelation() == null ?
RelationTypes.MEMBER : RelationTypes.getRelationType(object.getTargetRef().getRelation()));
return createStringResource(propertyKey).getString();
}
});
relationLabel.setOutputMarkupId(true);
relationLabel.setOutputMarkupPlaceholderTag(true);
relationLabel.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return !isCreatingNewAssignment();
}
});
relationContainer.add(relationLabel);
WebMarkupContainer tenantRefContainer = createTenantContainer();
tenantRefContainer.add(new VisibleEnableBehaviour(){
private static final long serialVersionUID = 1L;
@Override
public boolean isVisible(){
return isItemAllowed(new ItemPath(FocusType.F_ASSIGNMENT, AssignmentType.F_TENANT_REF));
}
});
body.add(tenantRefContainer);
WebMarkupContainer orgRefContainer = createOrgContainer();
orgRefContainer.add(new VisibleEnableBehaviour(){
private static final long serialVersionUID = 1L;
@Override
public boolean isVisible(){
return isItemAllowed(new ItemPath(FocusType.F_ASSIGNMENT, AssignmentType.F_ORG_REF));
}
});
body.add(orgRefContainer);
propertyContainer.add(new VisibleEnableBehaviour(){
private static final long serialVersionUID = 1L;
@Override
public boolean isVisible(){
return isItemAllowed(new ItemPath(FocusType.F_ASSIGNMENT, AssignmentType.F_DESCRIPTION))
|| isItemAllowed(new ItemPath(FocusType.F_ASSIGNMENT, AssignmentType.F_TARGET_REF,
ObjectReferenceType.F_RELATION))
|| isItemAllowed(new ItemPath(FocusType.F_ASSIGNMENT, AssignmentType.F_FOCUS_TYPE))
|| isItemAllowed(new ItemPath(FocusType.F_ASSIGNMENT, AssignmentType.F_TENANT_REF))
|| isItemAllowed(new ItemPath(FocusType.F_ASSIGNMENT, AssignmentType.F_ORG_REF));
}
});
WebMarkupContainer activationBlock = new WebMarkupContainer(ID_ACTIVATION_BLOCK);
body.add(activationBlock);
WebMarkupContainer adminStatusContainer = new WebMarkupContainer(ID_ADMIN_STATUS_CONTAINER);
adminStatusContainer.setOutputMarkupId(true);
adminStatusContainer.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
@Override
public boolean isVisible() {
return isItemAllowed(new ItemPath(FocusType.F_ASSIGNMENT, AssignmentType.F_ACTIVATION,
ActivationType.F_ADMINISTRATIVE_STATUS));
}
});
activationBlock.add(adminStatusContainer);
DropDownChoicePanel administrativeStatus = WebComponentUtil.createEnumPanel(
ActivationStatusType.class, ID_ADMINISTRATIVE_STATUS,
new PropertyModel<ActivationStatusType>(getModel(), AssignmentEditorDto.F_ACTIVATION + "."
+ ActivationType.F_ADMINISTRATIVE_STATUS.getLocalPart()),
this);
administrativeStatus.add(new VisibleEnableBehaviour(){
private static final long serialVersionUID = 1L;
@Override
public boolean isEnabled(){
return getModel().getObject().isEditable();
}
});
adminStatusContainer.add(administrativeStatus);
WebMarkupContainer validFromContainer = new WebMarkupContainer(ID_VALID_FROM_CONTAINER);
validFromContainer.setOutputMarkupId(true);
validFromContainer.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
@Override
public boolean isVisible() {
return isItemAllowed(new ItemPath(FocusType.F_ASSIGNMENT, AssignmentType.F_ACTIVATION,
ActivationType.F_VALID_FROM));
}
});
activationBlock.add(validFromContainer);
DateInput validFrom = new DateInput(ID_VALID_FROM,
AssignmentsUtil.createDateModel(new PropertyModel<>(getModel(),
AssignmentEditorDto.F_ACTIVATION + ".validFrom")));
validFrom.add(new VisibleEnableBehaviour(){
private static final long serialVersionUID = 1L;
@Override
public boolean isEnabled(){
return getModel().getObject().isEditable();
}
});
validFromContainer.add(validFrom);
WebMarkupContainer validToContainer = new WebMarkupContainer(ID_VALID_TO_CONTAINER);
validToContainer.setOutputMarkupId(true);
validToContainer.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
@Override
public boolean isVisible() {
return isItemAllowed(new ItemPath(FocusType.F_ASSIGNMENT, AssignmentType.F_ACTIVATION,
ActivationType.F_VALID_TO));
}
});
activationBlock.add(validToContainer);
DateInput validTo = new DateInput(ID_VALID_TO,
AssignmentsUtil.createDateModel(new PropertyModel<>(getModel(),
AssignmentEditorDto.F_ACTIVATION + ".validTo")));
validTo.add(new VisibleEnableBehaviour(){
private static final long serialVersionUID = 1L;
@Override
public boolean isEnabled(){
return getModel().getObject().isEditable();
}
});
validToContainer.add(validTo);
activationBlock.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
// enabled activation in assignments for now.
return true;
}
});
WebMarkupContainer targetContainer = new WebMarkupContainer(ID_TARGET_CONTAINER);
targetContainer.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
if (!isItemAllowed(new ItemPath(FocusType.F_ASSIGNMENT, AssignmentType.F_TARGET))){
return false;
}
AssignmentEditorDto dto = getModel().getObject();
return !AssignmentEditorDtoType.CONSTRUCTION.equals(dto.getType());
}
});
body.add(targetContainer);
Label target = new Label(ID_TARGET, createTargetModel());
targetContainer.add(target);
WebMarkupContainer constructionContainer = new WebMarkupContainer(ID_CONSTRUCTION_CONTAINER);
constructionContainer.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
AssignmentEditorDto dto = getModel().getObject();
return AssignmentEditorDtoType.CONSTRUCTION.equals(dto.getType());
}
});
body.add(constructionContainer);
AjaxLink showEmpty = new AjaxLink(ID_SHOW_EMPTY) {
@Override
public void onClick(AjaxRequestTarget target) {
showEmptyPerformed(target);
}
};
constructionContainer.add(showEmpty);
Label showEmptyLabel = new Label(ID_SHOW_EMPTY_LABEL, createShowEmptyLabel());
showEmptyLabel.setOutputMarkupId(true);
showEmpty.add(showEmptyLabel);
initAttributesLayout(constructionContainer);
Component metadataPanel;
if (UserDtoStatus.ADD.equals(getModel().getObject().getStatus()) ||
getModelObject().getOldValue().asContainerable() == null){
metadataPanel = new WebMarkupContainer(ID_METADATA_CONTAINER);
} else {
metadataPanel = new MetadataPanel(ID_METADATA_CONTAINER, new AbstractReadOnlyModel<MetadataType>() {
@Override
public MetadataType getObject() {
return getModelObject().getOldValue().getValue().getMetadata();
}
}, "", "row");
}
metadataPanel.setOutputMarkupId(true);
metadataPanel.add(new VisibleEnableBehaviour(){
@Override
public boolean isVisible(){
return !UserDtoStatus.ADD.equals(getModel().getObject().getStatus());
}
});
body.add(metadataPanel);
WebComponentUtil.addAjaxOnUpdateBehavior(body);
}
private void updateAssignmentName(AjaxRequestTarget target, Boolean isManager){
Label nameLabel = new Label(ID_NAME_LABEL, createAssignmentNameLabelModel(isManager));
nameLabel.setOutputMarkupId(true);
AjaxLink name = (AjaxLink) get(createComponentPath(ID_HEADER_ROW, ID_NAME));
name.addOrReplace(nameLabel);
target.add(name);
}
private WebMarkupContainer createTenantContainer() {
WebMarkupContainer tenantRefContainer = new WebMarkupContainer(ID_CONTAINER_TENANT_REF);
ChooseTypePanel tenantRef = new ChooseTypePanel(ID_TENANT_CHOOSER,
new PropertyModel<ObjectViewDto>(getModel(), AssignmentEditorDto.F_TENANT_REF)) {
@Override
protected ObjectQuery getChooseQuery() {
return QueryBuilder.queryFor(OrgType.class, getPageBase().getPrismContext())
.item(OrgType.F_TENANT).eq(true)
.build();
}
@Override
protected boolean isSearchEnabled() {
return true;
}
@Override
protected QName getSearchProperty() {
return OrgType.F_NAME;
}
};
tenantRef.setPanelEnabled(getModel().getObject().isEditable());
tenantRefContainer.add(tenantRef);
tenantRefContainer.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
AssignmentEditorDto dto = getModel().getObject();
if (dto != null) {
if (AssignmentEditorDtoType.ROLE.equals(dto.getType())) {
return true;
}
}
return false;
}
});
return tenantRefContainer;
}
private WebMarkupContainer createOrgContainer() {
WebMarkupContainer tenantRefContainer = new WebMarkupContainer(ID_CONTAINER_ORG_REF);
ChooseTypePanel tenantRef = new ChooseTypePanel(ID_ORG_CHOOSER,
new PropertyModel<ObjectViewDto>(getModel(), AssignmentEditorDto.F_ORG_REF)) {
@Override
protected ObjectQuery getChooseQuery() {
return QueryBuilder.queryFor(OrgType.class, getPageBase().getPrismContext())
.item(OrgType.F_TENANT).eq(false)
.or().item(OrgType.F_TENANT).isNull()
.build();
}
@Override
protected boolean isSearchEnabled() {
return true;
}
@Override
protected QName getSearchProperty() {
return OrgType.F_NAME;
}
};
tenantRefContainer.add(tenantRef);
tenantRef.setEnabled(getModel().getObject().isEditable());
tenantRefContainer.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
AssignmentEditorDto dto = getModel().getObject();
if (dto != null) {
if (AssignmentEditorDtoType.ROLE.equals(dto.getType())) {
return true;
}
}
return false;
}
});
return tenantRefContainer;
}
private void initAttributesLayout(WebMarkupContainer constructionContainer) {
WebMarkupContainer attributes = new WebMarkupContainer(ID_ATTRIBUTES);
attributes.setOutputMarkupId(true);
attributes.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
AssignmentEditorDto dto = getModel().getObject();
return AssignmentEditorDtoType.CONSTRUCTION.equals(dto.getType());
}
});
attributes.setEnabled(getModel().getObject().isEditable());
constructionContainer.add(attributes);
ListView<ACAttributeDto> attribute = new ListView<ACAttributeDto>(ID_ATTRIBUTE, attributesModel) {
@Override
protected void populateItem(ListItem<ACAttributeDto> listItem) {
final IModel<ACAttributeDto> attrModel = listItem.getModel();
ACAttributePanel acAttribute = new ACAttributePanel(ID_AC_ATTRIBUTE, attrModel, ignoreMandatoryAttributes());
acAttribute.setRenderBodyOnly(true);
listItem.add(acAttribute);
listItem.setOutputMarkupId(true);
listItem.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
AssignmentEditorDto editorDto = AssignmentEditorPanel.this.getModel().getObject();
if (editorDto.isShowEmpty()) {
return true;
}
ACAttributeDto dto = attrModel.getObject();
return !dto.isEmpty();
}
});
}
};
attributes.add(attribute);
// todo extension
}
private IModel<String> createShowEmptyLabel() {
return new AbstractReadOnlyModel<String>() {
@Override
public String getObject() {
AssignmentEditorDto dto = AssignmentEditorPanel.this.getModel().getObject();
if (dto.isShowEmpty()) {
return getString("AssignmentEditorPanel.hideEmpty");
} else {
return getString("AssignmentEditorPanel.showEmpty");
}
}
};
}
private void showEmptyPerformed(AjaxRequestTarget target) {
AssignmentEditorDto dto = AssignmentEditorPanel.this.getModel().getObject();
dto.setShowEmpty(!dto.isShowEmpty());
WebMarkupContainer parent = (WebMarkupContainer) get(
createComponentPath(ID_BODY, ID_CONSTRUCTION_CONTAINER));
target.add(parent.get(ID_ATTRIBUTES),
parent.get(createComponentPath(ID_SHOW_EMPTY, ID_SHOW_EMPTY_LABEL)),
getPageBase().getFeedbackPanel());
}
private List<ACAttributeDto> loadAttributes() {
AssignmentEditorDto dto = getModel().getObject();
OperationResult result = new OperationResult(OPERATION_LOAD_ATTRIBUTES);
List<ACAttributeDto> attributes = new ArrayList<>();
try {
ConstructionType construction = WebComponentUtil.getContainerValue(dto.getOldValue(),
AssignmentType.F_CONSTRUCTION, ConstructionType.class);
if (construction == null) {
return attributes;
}
PrismObject<ResourceType> resource = construction.getResource() != null
? construction.getResource().asPrismObject() : null;
if (resource == null) {
resource = getReference(construction.getResourceRef(), result);
}
PrismContext prismContext = getPageBase().getPrismContext();
RefinedResourceSchema refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource,
LayerType.PRESENTATION, prismContext);
RefinedObjectClassDefinition objectClassDefinition = refinedSchema
.getRefinedDefinition(ShadowKindType.ACCOUNT, construction.getIntent());
if (objectClassDefinition == null) {
return attributes;
}
PrismContainerDefinition definition = objectClassDefinition
.toResourceAttributeContainerDefinition();
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Refined definition for {}\n{}", construction, definition.debugDump());
}
List<ResourceAttributeDefinitionType> attrConstructions = construction.getAttribute();
Collection<ItemDefinition> definitions = definition.getDefinitions();
for (ItemDefinition attrDef : definitions) {
if (!(attrDef instanceof PrismPropertyDefinition)) {
// log skipping or something...
continue;
}
PrismPropertyDefinition propertyDef = (PrismPropertyDefinition) attrDef;
if (propertyDef.isOperational() || propertyDef.isIgnored()) {
continue;
}
attributes.add(ACAttributeDto.createACAttributeDto(propertyDef,
findOrCreateValueConstruction(propertyDef, attrConstructions), prismContext));
}
result.recordSuccess();
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Exception occurred during assignment attribute loading", ex);
result.recordFatalError("Exception occurred during assignment attribute loading.", ex);
} finally {
result.recomputeStatus();
}
Collections.sort(attributes, new Comparator<ACAttributeDto>() {
@Override
public int compare(ACAttributeDto a1, ACAttributeDto a2) {
return String.CASE_INSENSITIVE_ORDER.compare(a1.getName(), a2.getName());
}
});
if (dto.getAttributes() != null && !dto.getAttributes().isEmpty()) {
for (ACAttributeDto assignmentAttribute : dto.getAttributes()) {
for (ACAttributeDto attributeDto : attributes){
if (attributeDto.getName().equals(assignmentAttribute.getName())){
attributes.set(attributes.indexOf(attributeDto), assignmentAttribute);
continue;
}
}
}
}
dto.setAttributes(attributes);
getPageBase().showResult(result, false);
return dto.getAttributes();
}
private PrismObject getReference(ObjectReferenceType ref, OperationResult result) {
OperationResult subResult = result.createSubresult(OPERATION_LOAD_RESOURCE);
subResult.addParam("targetRef", ref.getOid());
PrismObject target = null;
try {
Task task = getPageBase().createSimpleTask(OPERATION_LOAD_RESOURCE);
Class type = ObjectType.class;
if (ref.getType() != null) {
type = getPageBase().getPrismContext().getSchemaRegistry()
.determineCompileTimeClass(ref.getType());
}
target = getPageBase().getModelService().getObject(type, ref.getOid(), null, task, subResult);
subResult.recordSuccess();
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't get account construction resource ref", ex);
subResult.recordFatalError("Couldn't get account construction resource ref.", ex);
}
return target;
}
private ResourceAttributeDefinitionType findOrCreateValueConstruction(PrismPropertyDefinition attrDef,
List<ResourceAttributeDefinitionType> attrConstructions) {
for (ResourceAttributeDefinitionType construction : attrConstructions) {
if (attrDef.getName().equals(construction.getRef())) {
return construction;
}
}
ResourceAttributeDefinitionType construction = new ResourceAttributeDefinitionType();
construction.setRef(new ItemPathType(new ItemPath(attrDef.getName())));
return construction;
}
protected IModel<String> createImageTypeModel(final IModel<AssignmentEditorDto> model) {
return new AbstractReadOnlyModel<String>() {
private static final long serialVersionUID = 1L;
@Override
public String getObject() {
AssignmentEditorDto assignmentEditorDto = model.getObject();
PrismObject targetObject = null;
try {
targetObject = getTargetObject(assignmentEditorDto);
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load object", ex);
// Otherwise ignore, will be pocessed by the fallback code
// below
}
if (targetObject == null) {
AssignmentEditorDtoType type = assignmentEditorDto.getType();
return type.getIconCssClass();
} else {
return WebComponentUtil.createDefaultIcon(targetObject);
}
}
};
}
protected void nameClickPerformed(AjaxRequestTarget target) {
AssignmentEditorDto dto = getModel().getObject();
boolean minimized = dto.isMinimized();
dto.setMinimized(!minimized);
target.add(this);
}
protected IModel<String> createTargetModel() {
return new LoadableModel<String>(false) {
private static final long serialVersionUID = 1L;
@Override
protected String load() {
AssignmentEditorDto dto = getModel().getObject();
PrismObject targetObject;
try {
targetObject = getTargetObject(dto);
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load object", ex);
return getString("AssignmentEditorPanel.loadError");
}
if (targetObject == null) {
return getString("AssignmentEditorPanel.undefined");
}
return WebComponentUtil.getName(targetObject);
}
};
}
private void addRelationDropDown(WebMarkupContainer relationContainer){
List<RelationTypes> availableRelations = getModelObject().getNotAssignedRelationsList();
DropDownChoicePanel relation = WebComponentUtil.createEnumPanel(RelationTypes.class, ID_RELATION,
getModelObject().isMultyAssignable() ?
WebComponentUtil.createReadonlyModelFromEnum(RelationTypes.class) : Model.ofList(availableRelations),
getRelationModel(availableRelations), this, false);
relation.setEnabled(getModel().getObject().isEditable());
relation.setOutputMarkupId(true);
relation.setOutputMarkupPlaceholderTag(true);
relation.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return isCreatingNewAssignment();
}
});
relationContainer.add(relation);
}
private IModel<RelationTypes> getRelationModel(List<RelationTypes> availableRelations){
return new IModel<RelationTypes>() {