-
Notifications
You must be signed in to change notification settings - Fork 188
/
WebComponentUtil.java
4689 lines (4081 loc) · 213 KB
/
WebComponentUtil.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-2020 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.gui.api.util;
import static com.evolveum.midpoint.gui.api.page.PageBase.createStringResourceStatic;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.net.URI;
import java.text.Collator;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;
import com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.*;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.commons.lang3.time.DurationFormatUtils;
import org.apache.commons.validator.routines.checkdigit.VerhoeffCheckDigit;
import org.apache.wicket.*;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
import org.apache.wicket.authroles.authentication.AuthenticatedWebApplication;
import org.apache.wicket.authroles.authorization.strategies.role.Roles;
import org.apache.wicket.behavior.Behavior;
import org.apache.wicket.core.request.handler.RenderPageRequestHandler;
import org.apache.wicket.datetime.PatternDateConverter;
import org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable;
import org.apache.wicket.extensions.markup.html.repeater.util.SortParam;
import org.apache.wicket.extensions.markup.html.tabs.ITab;
import org.apache.wicket.feedback.IFeedback;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.FormComponent;
import org.apache.wicket.markup.html.form.IChoiceRenderer;
import org.apache.wicket.markup.repeater.data.IDataProvider;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.StringResourceModel;
import org.apache.wicket.request.IRequestHandler;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.util.string.StringValue;
import org.apache.wicket.util.visit.IVisit;
import org.apache.wicket.util.visit.IVisitor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.joda.time.format.DateTimeFormat;
import com.evolveum.midpoint.common.LocalizationService;
import com.evolveum.midpoint.common.refinery.*;
import com.evolveum.midpoint.gui.api.GuiStyleConstants;
import com.evolveum.midpoint.gui.api.SubscriptionType;
import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.gui.api.component.MainObjectListPanel;
import com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext;
import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.gui.api.model.NonEmptyModel;
import com.evolveum.midpoint.gui.api.model.ReadOnlyValueModel;
import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper;
import com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerValueWrapper;
import com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerWrapper;
import com.evolveum.midpoint.gui.api.prism.wrapper.PrismPropertyWrapper;
import com.evolveum.midpoint.gui.impl.GuiChannel;
import com.evolveum.midpoint.gui.impl.component.icon.CompositedIcon;
import com.evolveum.midpoint.gui.impl.component.icon.CompositedIconBuilder;
import com.evolveum.midpoint.gui.impl.component.icon.IconCssStyle;
import com.evolveum.midpoint.gui.impl.component.icon.LayeredIconCssStyle;
import com.evolveum.midpoint.gui.impl.prism.wrapper.PrismPropertyValueWrapper;
import com.evolveum.midpoint.model.api.*;
import com.evolveum.midpoint.model.api.authentication.CompiledGuiProfile;
import com.evolveum.midpoint.model.api.authentication.CompiledObjectCollectionView;
import com.evolveum.midpoint.model.api.util.ResourceUtils;
import com.evolveum.midpoint.model.api.visualizer.Scene;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.crypto.EncryptionException;
import com.evolveum.midpoint.prism.crypto.Protector;
import com.evolveum.midpoint.prism.delta.ChangeType;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.delta.PropertyDelta;
import com.evolveum.midpoint.prism.path.ItemName;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.path.ItemPathCollectionsUtil;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.query.*;
import com.evolveum.midpoint.prism.query.builder.S_FilterEntryOrEmpty;
import com.evolveum.midpoint.prism.util.PolyStringUtils;
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
import com.evolveum.midpoint.repo.common.expression.ExpressionUtil;
import com.evolveum.midpoint.repo.common.expression.ExpressionVariables;
import com.evolveum.midpoint.schema.*;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.schema.constants.RelationTypes;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.processor.ResourceSchema;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.result.OperationResultStatus;
import com.evolveum.midpoint.schema.util.*;
import com.evolveum.midpoint.security.api.AuthorizationConstants;
import com.evolveum.midpoint.security.api.MidPointPrincipal;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.task.api.TaskCategory;
import com.evolveum.midpoint.util.*;
import com.evolveum.midpoint.util.exception.*;
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.application.AuthorizationAction;
import com.evolveum.midpoint.web.application.PageDescriptor;
import com.evolveum.midpoint.web.component.DateLabelComponent;
import com.evolveum.midpoint.web.component.TabbedPanel;
import com.evolveum.midpoint.web.component.assignment.AssignmentsUtil;
import com.evolveum.midpoint.web.component.breadcrumbs.Breadcrumb;
import com.evolveum.midpoint.web.component.breadcrumbs.BreadcrumbPageClass;
import com.evolveum.midpoint.web.component.breadcrumbs.BreadcrumbPageInstance;
import com.evolveum.midpoint.web.component.data.BaseSortableDataProvider;
import com.evolveum.midpoint.web.component.data.SelectableBeanObjectDataProvider;
import com.evolveum.midpoint.web.component.data.Table;
import com.evolveum.midpoint.web.component.data.column.ColumnMenuAction;
import com.evolveum.midpoint.web.component.data.column.ColumnUtils;
import com.evolveum.midpoint.web.component.input.DisplayableValueChoiceRenderer;
import com.evolveum.midpoint.web.component.input.DropDownChoicePanel;
import com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem;
import com.evolveum.midpoint.web.component.menu.cog.InlineMenuItemAction;
import com.evolveum.midpoint.web.component.prism.DynamicFormPanel;
import com.evolveum.midpoint.web.component.prism.InputPanel;
import com.evolveum.midpoint.web.component.prism.ItemVisibility;
import com.evolveum.midpoint.web.component.prism.ValueStatus;
import com.evolveum.midpoint.web.component.prism.show.SceneDto;
import com.evolveum.midpoint.web.component.prism.show.SceneUtil;
import com.evolveum.midpoint.web.component.util.Selectable;
import com.evolveum.midpoint.web.component.util.SelectableBeanImpl;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.web.page.admin.archetype.PageArchetype;
import com.evolveum.midpoint.web.page.admin.cases.PageCase;
import com.evolveum.midpoint.web.page.admin.objectCollection.PageObjectCollection;
import com.evolveum.midpoint.web.page.admin.reports.PageReport;
import com.evolveum.midpoint.web.page.admin.resources.PageResource;
import com.evolveum.midpoint.web.page.admin.resources.PageResourceWizard;
import com.evolveum.midpoint.web.page.admin.resources.PageResources;
import com.evolveum.midpoint.web.page.admin.resources.content.PageAccount;
import com.evolveum.midpoint.web.page.admin.roles.PageRole;
import com.evolveum.midpoint.web.page.admin.roles.PageRoles;
import com.evolveum.midpoint.web.page.admin.server.PageTask;
import com.evolveum.midpoint.web.page.admin.server.PageTasks;
import com.evolveum.midpoint.web.page.admin.server.dto.OperationResultStatusPresentationProperties;
import com.evolveum.midpoint.web.page.admin.services.PageService;
import com.evolveum.midpoint.web.page.admin.services.PageServices;
import com.evolveum.midpoint.web.page.admin.users.PageOrgUnit;
import com.evolveum.midpoint.web.page.admin.users.PageUser;
import com.evolveum.midpoint.web.page.admin.users.PageUsers;
import com.evolveum.midpoint.web.page.admin.valuePolicy.PageValuePolicy;
import com.evolveum.midpoint.web.page.admin.workflow.dto.EvaluatedTriggerGroupDto;
import com.evolveum.midpoint.web.page.self.PageOrgSelfProfile;
import com.evolveum.midpoint.web.page.self.PageRoleSelfProfile;
import com.evolveum.midpoint.web.page.self.PageServiceSelfProfile;
import com.evolveum.midpoint.web.page.self.PageUserSelfProfile;
import com.evolveum.midpoint.web.security.MidPointApplication;
import com.evolveum.midpoint.web.security.util.SecurityUtils;
import com.evolveum.midpoint.web.session.SessionStorage;
import com.evolveum.midpoint.web.session.UserProfileStorage.TableId;
import com.evolveum.midpoint.web.util.DateValidator;
import com.evolveum.midpoint.web.util.InfoTooltipBehavior;
import com.evolveum.midpoint.web.util.ObjectTypeGuiDescriptor;
import com.evolveum.midpoint.web.util.OnePageParameterEncoder;
import com.evolveum.midpoint.wf.util.ApprovalUtils;
import com.evolveum.midpoint.wf.util.ChangesByState;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.midpoint.xml.ns._public.model.scripting_3.ExecuteScriptType;
import com.evolveum.prism.xml.ns._public.query_3.QueryType;
import com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;
import com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType;
/**
* Utility class containing miscellaneous methods used mostly in Wicket
* components.
*
* @author lazyman
*/
public final class WebComponentUtil {
private static final Trace LOGGER = TraceManager.getTrace(WebComponentUtil.class);
private static final String KEY_BOOLEAN_NULL = "Boolean.NULL";
private static final String KEY_BOOLEAN_TRUE = "Boolean.TRUE";
private static final String KEY_BOOLEAN_FALSE = "Boolean.FALSE";
/**
* To be used only for tests when there's no MidpointApplication.
* (Quite a hack. Replace eventually by a more serious solution.)
*/
private static RelationRegistry staticallyProvidedRelationRegistry;
private static final Map<Class<?>, Class<? extends PageBase>> OBJECT_DETAILS_PAGE_MAP;
private static final Map<Class<?>, Class<? extends PageBase>> CREATE_NEW_OBJECT_PAGE_MAP;
static {
OBJECT_DETAILS_PAGE_MAP = new HashMap<>();
OBJECT_DETAILS_PAGE_MAP.put(UserType.class, PageUser.class);
OBJECT_DETAILS_PAGE_MAP.put(OrgType.class, PageOrgUnit.class);
OBJECT_DETAILS_PAGE_MAP.put(RoleType.class, PageRole.class);
OBJECT_DETAILS_PAGE_MAP.put(ServiceType.class, PageService.class);
OBJECT_DETAILS_PAGE_MAP.put(ResourceType.class, PageResource.class);
OBJECT_DETAILS_PAGE_MAP.put(TaskType.class, PageTask.class);
OBJECT_DETAILS_PAGE_MAP.put(ReportType.class, PageReport.class);
OBJECT_DETAILS_PAGE_MAP.put(ValuePolicyType.class, PageValuePolicy.class);
OBJECT_DETAILS_PAGE_MAP.put(CaseType.class, PageCase.class);
OBJECT_DETAILS_PAGE_MAP.put(ArchetypeType.class, PageArchetype.class);
OBJECT_DETAILS_PAGE_MAP.put(ShadowType.class, PageAccount.class);
OBJECT_DETAILS_PAGE_MAP.put(ObjectCollectionType.class, PageObjectCollection.class);
}
static {
CREATE_NEW_OBJECT_PAGE_MAP = new HashMap<>();
CREATE_NEW_OBJECT_PAGE_MAP.put(ResourceType.class, PageResourceWizard.class);
}
// only pages that support 'advanced search' are currently listed here (TODO: generalize)
private static final Map<Class<?>, Class<? extends PageBase>> OBJECT_LIST_PAGE_MAP;
static {
OBJECT_LIST_PAGE_MAP = new HashMap<>();
OBJECT_LIST_PAGE_MAP.put(UserType.class, PageUsers.class);
OBJECT_LIST_PAGE_MAP.put(RoleType.class, PageRoles.class);
OBJECT_LIST_PAGE_MAP.put(ServiceType.class, PageServices.class);
OBJECT_LIST_PAGE_MAP.put(ResourceType.class, PageResources.class);
OBJECT_LIST_PAGE_MAP.put(TaskType.class, PageTasks.class);
}
private static final Map<TableId, String> STORAGE_TABLE_ID_MAP;
static {
STORAGE_TABLE_ID_MAP = new HashMap<>();
STORAGE_TABLE_ID_MAP.put(TableId.PAGE_RESOURCE_ACCOUNTS_PANEL_REPOSITORY_MODE, SessionStorage.KEY_RESOURCE_ACCOUNT_CONTENT + SessionStorage.KEY_RESOURCE_PAGE_REPOSITORY_CONTENT);
STORAGE_TABLE_ID_MAP.put(TableId.PAGE_RESOURCE_ACCOUNTS_PANEL_RESOURCE_MODE, SessionStorage.KEY_RESOURCE_ACCOUNT_CONTENT + SessionStorage.KEY_RESOURCE_PAGE_RESOURCE_CONTENT);
STORAGE_TABLE_ID_MAP.put(TableId.PAGE_RESOURCE_ENTITLEMENT_PANEL_REPOSITORY_MODE, SessionStorage.KEY_RESOURCE_ENTITLEMENT_CONTENT + SessionStorage.KEY_RESOURCE_PAGE_REPOSITORY_CONTENT);
STORAGE_TABLE_ID_MAP.put(TableId.PAGE_RESOURCE_ENTITLEMENT_PANEL_RESOURCE_MODE, SessionStorage.KEY_RESOURCE_ENTITLEMENT_CONTENT + SessionStorage.KEY_RESOURCE_PAGE_RESOURCE_CONTENT);
STORAGE_TABLE_ID_MAP.put(TableId.PAGE_RESOURCE_GENERIC_PANEL_REPOSITORY_MODE, SessionStorage.KEY_RESOURCE_GENERIC_CONTENT + SessionStorage.KEY_RESOURCE_PAGE_REPOSITORY_CONTENT);
STORAGE_TABLE_ID_MAP.put(TableId.PAGE_RESOURCE_GENERIC_PANEL_RESOURCE_MODE, SessionStorage.KEY_RESOURCE_GENERIC_CONTENT + SessionStorage.KEY_RESOURCE_PAGE_RESOURCE_CONTENT);
STORAGE_TABLE_ID_MAP.put(TableId.PAGE_RESOURCE_OBJECT_CLASS_PANEL, SessionStorage.KEY_RESOURCE_OBJECT_CLASS_CONTENT);
STORAGE_TABLE_ID_MAP.put(TableId.ROLE_MEMBER_PANEL, SessionStorage.KEY_ROLE_MEMBER_PANEL);
STORAGE_TABLE_ID_MAP.put(TableId.ORG_MEMBER_PANEL, SessionStorage.KEY_ORG_MEMBER_PANEL);
STORAGE_TABLE_ID_MAP.put(TableId.SERVICE_MEMBER_PANEL, SessionStorage.KEY_SERVICE_MEMBER_PANEL);
}
private static final Map<String, LoggingComponentType> COMPONENT_MAP = new HashMap<>();
static {
COMPONENT_MAP.put("com.evolveum.midpoint", LoggingComponentType.ALL);
COMPONENT_MAP.put("com.evolveum.midpoint.model", LoggingComponentType.MODEL);
COMPONENT_MAP.put("com.evolveum.midpoint.provisioning", LoggingComponentType.PROVISIONING);
COMPONENT_MAP.put("com.evolveum.midpoint.repo", LoggingComponentType.REPOSITORY);
COMPONENT_MAP.put("com.evolveum.midpoint.web", LoggingComponentType.WEB);
COMPONENT_MAP.put("com.evolveum.midpoint.gui", LoggingComponentType.GUI);
COMPONENT_MAP.put("com.evolveum.midpoint.task", LoggingComponentType.TASKMANAGER);
COMPONENT_MAP.put("com.evolveum.midpoint.model.sync",
LoggingComponentType.RESOURCEOBJECTCHANGELISTENER);
COMPONENT_MAP.put("com.evolveum.midpoint.wf", LoggingComponentType.WORKFLOWS);
COMPONENT_MAP.put("com.evolveum.midpoint.notifications", LoggingComponentType.NOTIFICATIONS);
COMPONENT_MAP.put("com.evolveum.midpoint.certification", LoggingComponentType.ACCESS_CERTIFICATION);
COMPONENT_MAP.put("com.evolveum.midpoint.security", LoggingComponentType.SECURITY);
}
public enum AssignmentOrder {
ASSIGNMENT(0),
INDUCEMENT(1);
private final int order;
AssignmentOrder(int order) {
this.order = order;
}
public int getOrder() {
return order;
}
}
public static String nl2br(String text) {
if (text == null) {
return null;
}
return StringEscapeUtils.escapeHtml4(text).replace("\n", "<br/>");
}
public static String getTypeLocalized(ObjectReferenceType ref) {
ObjectTypes type = ref != null ? ObjectTypes.getObjectTypeFromTypeQName(ref.getType()) : null;
ObjectTypeGuiDescriptor descriptor = ObjectTypeGuiDescriptor.getDescriptor(type);
if (descriptor == null) {
return null;
}
return createStringResourceStatic(null, descriptor.getLocalizationKey()).getString();
}
public static String getReferencedObjectNames(List<ObjectReferenceType> refs, boolean showTypes) {
return getReferencedObjectNames(refs, showTypes, true);
}
public static String getReferencedObjectNames(List<ObjectReferenceType> refs, boolean showTypes, boolean translate) {
return refs.stream()
.map(ref -> emptyIfNull(getName(ref, translate)) + (showTypes ? (" (" + emptyIfNull(getTypeLocalized(ref)) + ")") : ""))
.collect(Collectors.joining(", "));
}
private static String emptyIfNull(String s) {
return s != null ? s : "";
}
public static String getReferencedObjectDisplayNamesAndNames(List<ObjectReferenceType> refs, boolean showTypes) {
return refs.stream()
.map(ref -> emptyIfNull(getDisplayNameAndName(ref)) + (showTypes ? (" (" + emptyIfNull(getTypeLocalized(ref)) + ")") : ""))
.collect(Collectors.joining(", "));
}
public static String getReferencedObjectDisplayNamesAndNames(Referencable ref, boolean showTypes) {
return getReferencedObjectDisplayNamesAndNames(ref, showTypes, true);
}
public static String getReferencedObjectDisplayNamesAndNames(Referencable ref, boolean showTypes, boolean translate) {
if (ref == null) {
return "";
}
String name = ref.getTargetName() == null ? "" :
(translate ? ref.getTargetName().getOrig() : "");
StringBuilder sb = new StringBuilder(name);
if (showTypes) {
sb.append(" (");
ObjectTypes type = ObjectTypes.getObjectTypeFromTypeQName(ref.getType());
ObjectTypeGuiDescriptor descriptor = ObjectTypeGuiDescriptor.getDescriptor(type);
if (descriptor == null) {
return null;
}
sb.append(emptyIfNull(createStringResourceStatic(null, descriptor.getLocalizationKey()).getString())).append(")");
}
return sb.toString();
}
public static <O extends ObjectType> List<O> loadReferencedObjectList(List<ObjectReferenceType> refList, String operation, PageBase pageBase) {
List<O> loadedObjectsList = new ArrayList<>();
if (refList == null) {
return loadedObjectsList;
}
refList.forEach(objectRef -> {
OperationResult result = new OperationResult(operation);
PrismObject<O> loadedObject = WebModelServiceUtils.resolveReferenceNoFetch(objectRef, pageBase, pageBase.createSimpleTask(operation), result);
if (loadedObject != null) {
loadedObjectsList.add(loadedObject.asObjectable());
}
});
return loadedObjectsList;
}
public static List<UserType> loadTargetUsersListForShoppingCart(String operation, PageBase pageBase) {
List<String> usersOidsList = pageBase.getSessionStorage().getRoleCatalog().getTargetUserOidsList();
if (CollectionUtils.isEmpty(usersOidsList)) {
return new ArrayList<>();
}
List<ObjectReferenceType> usersReferenceList = new ArrayList<>();
usersOidsList.forEach(userOid -> {
usersReferenceList.add(ObjectTypeUtil.createObjectRef(userOid, ObjectTypes.USER));
});
return WebComponentUtil.loadReferencedObjectList(usersReferenceList, operation, pageBase);
}
public static ObjectFilter getShadowTypeFilterForAssociation(ConstructionType construction, String operation, PageBase pageBase) {
PrismContext prismContext = pageBase.getPrismContext();
if (construction == null) {
return null;
}
PrismObject<ResourceType> resource = WebComponentUtil.getConstructionResource(construction, operation, pageBase);
if (resource == null) {
return null;
}
ObjectQuery query = prismContext.queryFactory().createQuery();
try {
RefinedResourceSchema refinedResourceSchema = RefinedResourceSchema.getRefinedSchema(resource);
RefinedObjectClassDefinition oc = refinedResourceSchema.getRefinedDefinition(construction.getKind(), construction.getIntent());
if (oc == null) {
return null;
}
Collection<RefinedAssociationDefinition> refinedAssociationDefinitions = oc.getAssociationDefinitions();
for (RefinedAssociationDefinition refinedAssociationDefinition : refinedAssociationDefinitions) {
S_FilterEntryOrEmpty atomicFilter = prismContext.queryFor(ShadowType.class);
List<ObjectFilter> orFilterClauses = new ArrayList<>();
refinedAssociationDefinition.getIntents()
.forEach(intent -> orFilterClauses.add(atomicFilter.item(ShadowType.F_INTENT).eq(intent).buildFilter()));
OrFilter intentFilter = prismContext.queryFactory().createOr(orFilterClauses);
AndFilter filter = (AndFilter) atomicFilter.item(ShadowType.F_KIND).eq(refinedAssociationDefinition.getKind()).and()
.item(ShadowType.F_RESOURCE_REF).ref(resource.getOid(), ResourceType.COMPLEX_TYPE).buildFilter();
filter.addCondition(intentFilter);
query.setFilter(filter); // TODO this overwrites existing filter (created in previous cycle iteration)... is it OK? [med]
}
} catch (SchemaException ex) {
LOGGER.error("Couldn't create query filter for ShadowType for association: {}", ex.getErrorTypeMessage());
}
return query.getFilter();
}
public static void addAjaxOnUpdateBehavior(WebMarkupContainer container) {
container.visitChildren(new IVisitor<Component, Object>() {
@Override
public void component(Component component, IVisit<Object> objectIVisit) {
if (component instanceof InputPanel) {
addAjaxOnBlurUpdateBehaviorToComponent(((InputPanel) component).getBaseFormComponent());
} else if (component instanceof FormComponent) {
addAjaxOnBlurUpdateBehaviorToComponent(component);
}
}
});
}
private static void addAjaxOnBlurUpdateBehaviorToComponent(final Component component) {
component.setOutputMarkupId(true);
component.add(new AjaxFormComponentUpdatingBehavior("blur") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
}
});
}
public static String resolveLocalizableMessage(LocalizableMessageType localizableMessage, Component component) {
if (localizableMessage == null) {
return null;
}
return resolveLocalizableMessage(LocalizationUtil.toLocalizableMessage(localizableMessage), component);
}
public static String resolveLocalizableMessage(LocalizableMessage localizableMessage, Component component) {
if (localizableMessage == null) {
return null;
} else if (localizableMessage instanceof SingleLocalizableMessage) {
return resolveLocalizableMessage((SingleLocalizableMessage) localizableMessage, component);
} else if (localizableMessage instanceof LocalizableMessageList) {
return resolveLocalizableMessage((LocalizableMessageList) localizableMessage, component);
} else {
throw new AssertionError("Unsupported localizable message type: " + localizableMessage);
}
}
private static String resolveLocalizableMessage(SingleLocalizableMessage localizableMessage, Component component) {
if (localizableMessage == null) {
return null;
}
while (localizableMessage.getFallbackLocalizableMessage() != null) {
if (localizableMessage.getKey() != null) {
Localizer localizer = Application.get().getResourceSettings().getLocalizer();
if (localizer.getStringIgnoreSettings(localizableMessage.getKey(), component, null, null) != null) {
break; // the key exists => we can use the current localizableMessage
}
}
if (localizableMessage.getFallbackLocalizableMessage() instanceof SingleLocalizableMessage) {
localizableMessage = (SingleLocalizableMessage) localizableMessage.getFallbackLocalizableMessage();
} else {
return resolveLocalizableMessage(localizableMessage.getFallbackLocalizableMessage(), component);
}
}
String key = localizableMessage.getKey() != null ? localizableMessage.getKey() : localizableMessage.getFallbackMessage();
StringResourceModel stringResourceModel = new StringResourceModel(key, component)
.setModel(new Model<String>())
.setDefaultValue(localizableMessage.getFallbackMessage())
.setParameters(resolveArguments(localizableMessage.getArgs(), component));
String rv = stringResourceModel.getString();
//System.out.println("GUI: Resolving [" + key + "]: to [" + rv + "]");
return rv;
}
// todo deduplicate with similar method in LocalizationServiceImpl
private static String resolveLocalizableMessage(LocalizableMessageList msgList, Component component) {
String separator = resolveIfPresent(msgList.getSeparator(), component);
String prefix = resolveIfPresent(msgList.getPrefix(), component);
String suffix = resolveIfPresent(msgList.getPostfix(), component);
return msgList.getMessages().stream()
.map(m -> resolveLocalizableMessage(m, component))
.collect(Collectors.joining(separator, prefix, suffix));
}
private static String resolveIfPresent(LocalizableMessage msg, Component component) {
return msg != null ? resolveLocalizableMessage(msg, component) : "";
}
private static Object[] resolveArguments(Object[] args, Component component) {
if (args == null) {
return null;
}
Object[] rv = new Object[args.length];
for (int i = 0; i < args.length; i++) {
if (args[i] instanceof LocalizableMessage) {
rv[i] = resolveLocalizableMessage(((LocalizableMessage) args[i]), component);
} else {
rv[i] = args[i];
}
}
return rv;
}
// TODO add other classes; probably move to some enum
@Nullable
public static String getAuthorizationActionForTargetClass(Class targetClass) {
if (UserType.class.equals(targetClass)) {
return AuthorizationConstants.AUTZ_UI_USER_URL;
} else if (OrgType.class.equals(targetClass)) {
return AuthorizationConstants.AUTZ_UI_ORG_UNIT_URL;
} else if (RoleType.class.equals(targetClass)) {
return AuthorizationConstants.AUTZ_UI_ROLE_URL;
} else if (ServiceType.class.equals(targetClass)) {
return AuthorizationConstants.AUTZ_UI_SERVICE_URL;
} else if (ResourceType.class.equals(targetClass)) {
return AuthorizationConstants.AUTZ_UI_RESOURCE_URL;
} else {
return null;
}
}
public static void safeResultCleanup(OperationResult result, Trace logger) {
try {
result.cleanupResultDeeply();
} catch (Throwable t) {
LoggingUtils.logUnexpectedException(logger, "Couldn't clean up the operation result", t);
}
}
/**
* Default list view setting should never be needed. Always check setting for specific
* object type (and archetype).
*/
@Deprecated
public static CompiledObjectCollectionView getDefaultGuiObjectListType(PageBase pageBase) {
return pageBase.getCompiledGuiProfile().getDefaultObjectCollectionView();
}
// public enum Channel {
// // TODO: move this to schema component
// LIVE_SYNC(SchemaConstants.CHANGE_CHANNEL_LIVE_SYNC_URI),
// RECONCILIATION(SchemaConstants.CHANGE_CHANNEL_RECON_URI),
// RECOMPUTATION(SchemaConstants.CHANGE_CHANNEL_RECOMPUTE_URI),
// DISCOVERY(SchemaConstants.CHANGE_CHANNEL_DISCOVERY_URI),
// WEB_SERVICE(SchemaConstants.CHANNEL_WEB_SERVICE_URI),
// IMPORT(SchemaConstants.CHANNEL_OBJECT_IMPORT_URI),
// REST(SchemaConstants.CHANNEL_REST_URI),
// INIT(SchemaConstants.CHANNEL_GUI_INIT_URI),
// USER(SchemaConstants.CHANNEL_USER_URI),
// SELF_REGISTRATION(SchemaConstants.CHANNEL_GUI_SELF_REGISTRATION_URI),
// RESET_PASSWORD(SchemaConstants.CHANNEL_GUI_RESET_PASSWORD_URI);
//
// private String channel;
//
// Channel(String channel) {
// this.channel = channel;
// }
//
// public String getChannel() {
// return channel;
// }
// }
public static DateValidator getRangeValidator(Form<?> form, ItemPath path) {
DateValidator validator = null;
List<DateValidator> validators = form.getBehaviors(DateValidator.class);
if (validators != null) {
for (DateValidator val : validators) {
if (path.equivalent(val.getIdentifier())) {
validator = val;
break;
}
}
}
if (validator == null) {
validator = new DateValidator();
validator.setIdentifier(path);
form.add(validator);
}
return validator;
}
public static boolean isItemVisible(List<ItemPath> visibleItems, ItemPath itemToBeFound) {
return ItemPathCollectionsUtil.containsSubpathOrEquivalent(visibleItems, itemToBeFound);
}
public static Class<?> qnameToClass(PrismContext prismContext, QName type) {
return prismContext.getSchemaRegistry().determineCompileTimeClass(type);
}
public static <T extends ObjectType> Class<T> qnameToClass(PrismContext prismContext, QName type, Class<T> returnType) {
return prismContext.getSchemaRegistry().determineCompileTimeClass(type);
}
public static <T extends ObjectType> QName classToQName(PrismContext prismContext, Class<T> clazz) {
return prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(clazz).getTypeName();
}
public static TaskType createSingleRecurrenceTask(String taskName, QName applicableType, ObjectQuery query,
ObjectDelta delta, ModelExecuteOptions options, String category, PageBase pageBase) throws SchemaException {
TaskType task = new TaskType(pageBase.getPrismContext());
MidPointPrincipal owner = SecurityUtils.getPrincipalUser();
ObjectReferenceType ownerRef = new ObjectReferenceType();
ownerRef.setOid(owner.getOid());
ownerRef.setType(UserType.COMPLEX_TYPE);
task.setOwnerRef(ownerRef);
task.setBinding(TaskBindingType.LOOSE);
task.setCategory(category);
task.setExecutionStatus(TaskExecutionStatusType.RUNNABLE);
task.setRecurrence(TaskRecurrenceType.SINGLE);
task.setThreadStopAction(ThreadStopActionType.RESTART);
task.setHandlerUri(pageBase.getTaskService().getHandlerUriForCategory(category));
ScheduleType schedule = new ScheduleType();
schedule.setMisfireAction(MisfireActionType.EXECUTE_IMMEDIATELY);
task.setSchedule(schedule);
task.setName(WebComponentUtil.createPolyFromOrigString(taskName));
PrismObject<TaskType> prismTask = task.asPrismObject();
QueryType queryType = pageBase.getQueryConverter().createQueryType(query);
prismTask.findOrCreateProperty(SchemaConstants.PATH_MODEL_EXTENSION_OBJECT_QUERY).addRealValue(queryType);
if (applicableType != null) {
prismTask.findOrCreateProperty(SchemaConstants.PATH_MODEL_EXTENSION_OBJECT_TYPE).setRealValue(applicableType);
}
if (delta != null) {
ObjectDeltaType deltaBean = DeltaConvertor.toObjectDeltaType(delta);
prismTask.findOrCreateProperty(SchemaConstants.PATH_MODEL_EXTENSION_OBJECT_DELTA).setRealValue(deltaBean);
}
if (options != null) {
prismTask.findOrCreateContainer(SchemaConstants.PATH_MODEL_EXTENSION_EXECUTE_OPTIONS)
.setRealValue(options.toModelExecutionOptionsType());
}
return task;
}
public static boolean canSuspendTask(TaskType task, PageBase pageBase) {
return pageBase.isAuthorized(ModelAuthorizationAction.SUSPEND_TASK, task.asPrismObject())
&& (isRunnableTask(task) || isRunningTask(task) || isWaitingTask(task))
&& !isWorkflowTask(task);
}
public static boolean canResumeTask(TaskType task, PageBase pageBase) {
return pageBase.isAuthorized(ModelAuthorizationAction.RESUME_TASK, task.asPrismObject())
&& (isSuspendedTask(task) || (isClosedTask(task) && isRecurringTask(task)))
&& !isWorkflowTask(task);
}
public static boolean canRunNowTask(TaskType task, PageBase pageBase) {
return pageBase.isAuthorized(ModelAuthorizationAction.RUN_TASK_IMMEDIATELY, task.asPrismObject())
&& !isRunningTask(task) && (isRunnableTask(task) || (isClosedTask(task) && !isRecurringTask(task)))
&& !isWorkflowTask(task);
}
public static boolean isRunnableTask(TaskType task) {
return task != null && TaskExecutionStatusType.RUNNABLE == task.getExecutionStatus();
}
public static boolean isRunningTask(TaskType task) {
return task != null && task.getNodeAsObserved() != null;
}
public static boolean isWaitingTask(TaskType task) {
return task != null && TaskExecutionStatusType.WAITING == task.getExecutionStatus();
}
public static boolean isSuspendedTask(TaskType task) {
return task != null && TaskExecutionStatusType.SUSPENDED == task.getExecutionStatus();
}
public static boolean isClosedTask(TaskType task) {
return task != null && TaskExecutionStatusType.CLOSED == task.getExecutionStatus();
}
public static boolean isRecurringTask(TaskType task) {
return task != null && TaskRecurrenceType.RECURRING == task.getRecurrence();
}
public static boolean isWorkflowTask(TaskType task) {
return task != null && TaskCategory.WORKFLOW.equals(task.getCategory());
}
public static boolean isReconciliation(TaskType task) {
return isArchetypedTask(task, SystemObjectsType.ARCHETYPE_RECONCILIATION_TASK);
}
public static boolean isRecomputation(TaskType task) {
return isArchetypedTask(task, SystemObjectsType.ARCHETYPE_RECOMPUTATION_TASK);
}
public static boolean isReport(TaskType task) {
return isArchetypedTask(task, SystemObjectsType.ARCHETYPE_REPORT_TASK);
}
public static boolean isImport(TaskType task) {
return isArchetypedTask(task, SystemObjectsType.ARCHETYPE_IMPORT_TASK);
}
public static boolean isLiveSync(TaskType task) {
return isArchetypedTask(task, SystemObjectsType.ARCHETYPE_LIVE_SYNC_TASK);
}
private static boolean isArchetypedTask(TaskType taskType, SystemObjectsType archetype) {
ObjectReferenceType archetypeRef = getArchetypeReference(taskType);
if (archetypeRef == null) {
return false;
}
return archetype.value().equals(archetypeRef.getOid());
}
private static ObjectReferenceType getArchetypeReference(TaskType task) {
ObjectReferenceType archetypeRef = null;
if (task.getAssignment() == null || task.getAssignment().size() == 0) {
return archetypeRef;
}
for (AssignmentType assignment : task.getAssignment()) {
if (StringUtils.isNotEmpty(assignment.getTargetRef().getOid())
&& assignment.getTargetRef() != null && QNameUtil.match(assignment.getTargetRef().getType(), ArchetypeType.COMPLEX_TYPE)) {
archetypeRef = assignment.getTargetRef();
}
}
return archetypeRef;
}
public static void iterativeExecuteBulkAction(PageBase pageBase, ExecuteScriptType script, Task task, OperationResult result)
throws SchemaException, SecurityViolationException, ObjectNotFoundException, ExpressionEvaluationException,
CommunicationException, ConfigurationException {
pageBase.getScriptingService().evaluateIterativeExpressionInBackground(script, task, result);
}
public static boolean isAuthorized(String... action) {
if (action == null || action.length == 0) {
return true;
}
List<String> actions = Arrays.asList(action);
return isAuthorized(actions);
}
public static boolean isAuthorized(Collection<String> actions) {
if (actions == null || actions.isEmpty()) {
return true;
}
Roles roles = new Roles(AuthorizationConstants.AUTZ_ALL_URL);
roles.add(AuthorizationConstants.AUTZ_GUI_ALL_URL);
roles.add(AuthorizationConstants.AUTZ_GUI_ALL_DEPRECATED_URL);
roles.addAll(actions);
return ((AuthenticatedWebApplication) AuthenticatedWebApplication.get()).hasAnyRole(roles);
}
public static boolean isAuthorized(Class<? extends ObjectType> clazz) {
Class<? extends PageBase> detailsPage = WebComponentUtil.getObjectDetailsPage(clazz);
if (detailsPage == null) {
return false;
}
PageDescriptor descriptor = detailsPage.getAnnotation(PageDescriptor.class);
AuthorizationAction[] actions = descriptor.action();
List<String> actionUris = new ArrayList<>();
for (AuthorizationAction action : actions) {
actionUris.add(action.actionUri());
}
return isAuthorized(actionUris);
}
// TODO: move to util component
public static Integer safeLongToInteger(Long l) {
if (l == null) {
return null;
}
if (l > Integer.MAX_VALUE || l < Integer.MIN_VALUE) {
throw new IllegalArgumentException(
"Couldn't transform long '" + l + "' to int, too big or too small.");
}
return (int) l.longValue();
}
// TODO: move to schema component
public static List<QName> createObjectTypeList() {
return createObjectTypesList().stream().map(type -> type.getTypeQName()).collect(Collectors.toList());
}
public static List<ObjectTypes> createObjectTypesList() {
List<ObjectTypes> types = Arrays.asList(ObjectTypes.values());
return types.stream().sorted((type1, type2) -> {
Validate.notNull(type1);
Validate.notNull(type2);
ObjectTypeGuiDescriptor decs1 = ObjectTypeGuiDescriptor.getDescriptor(type1);
ObjectTypeGuiDescriptor desc2 = ObjectTypeGuiDescriptor.getDescriptor(type2);
String localizedType1 = translate(decs1);
if (localizedType1 == null) {
localizedType1 = decs1.getLocalizationKey();
}
String localizedType2 = translate(desc2);
if (localizedType2 == null) {
localizedType2 = desc2.getLocalizationKey();
}
Collator collator = Collator.getInstance(getCurrentLocale());
collator.setStrength(Collator.PRIMARY);
return collator.compare(localizedType1, localizedType2);
}).collect(Collectors.toList());
}
private static String translate(ObjectTypeGuiDescriptor descriptor) {
MidPointApplication app = MidPointApplication.get();
String translatedValue = app.getLocalizationService().translate(descriptor.getLocalizationKey(), null, getCurrentLocale());
return translatedValue != null ? translatedValue : descriptor.getLocalizationKey();
}
public static List<QName> createContainerableTypesQnameList() {
List<ObjectTypes> types = Arrays.asList(ObjectTypes.values());
List<QName> qnameList = types.stream().map(type -> type.getTypeQName()).collect(Collectors.toList());
//todo create enum for containerable types?
qnameList.add(AuditEventRecordType.COMPLEX_TYPE);
return qnameList.stream().sorted((type1, type2) -> {
Validate.notNull(type1);
Validate.notNull(type2);
String key1 = "ObjectType." + type1.getLocalPart();
String localizedType1 = createStringResourceStatic(null, key1).getString();
if (StringUtils.isEmpty(localizedType1) || localizedType1.equals(key1)) {
localizedType1 = type1.getLocalPart();
}
String key2 = "ObjectType." + type2.getLocalPart();
String localizedType2 = createStringResourceStatic(null, key2).getString();
if (StringUtils.isEmpty(localizedType2) || localizedType1.equals(key2)) {
localizedType2 = type2.getLocalPart();
}
Collator collator = Collator.getInstance(getCurrentLocale());
collator.setStrength(Collator.PRIMARY);
return collator.compare(localizedType1, localizedType2);
}).collect(Collectors.toList());
}
public static List<QName> createAssignmentHolderTypeQnamesList() {
List<ObjectTypes> objectTypes = createAssignmentHolderTypesList();
return objectTypes.stream().map(type -> type.getTypeQName()).collect(Collectors.toList());
}
public static List<ObjectTypes> createAssignmentHolderTypesList() {
return createObjectTypesList().stream().filter(type -> AssignmentHolderType.class.isAssignableFrom(type.getClassDefinition())).collect(Collectors.toList());
}
// TODO: move to schema component
public static List<QName> createFocusTypeList() {
return createFocusTypeList(false);
}
public static List<QName> createFocusTypeList(boolean includeAbstractType) {
List<QName> focusTypeList = new ArrayList<>();
focusTypeList.add(UserType.COMPLEX_TYPE);
focusTypeList.add(OrgType.COMPLEX_TYPE);
focusTypeList.add(RoleType.COMPLEX_TYPE);
focusTypeList.add(ServiceType.COMPLEX_TYPE);
if (includeAbstractType) {
focusTypeList.add(FocusType.COMPLEX_TYPE);
}
return focusTypeList;
}
// TODO: move to schema component
public static List<QName> createAbstractRoleTypeList() {
List<QName> focusTypeList = new ArrayList<>();
focusTypeList.add(AbstractRoleType.COMPLEX_TYPE);
focusTypeList.add(OrgType.COMPLEX_TYPE);
focusTypeList.add(RoleType.COMPLEX_TYPE);
focusTypeList.add(ServiceType.COMPLEX_TYPE);
return focusTypeList;
}
public static List<ObjectTypes> createAssignableTypesList() {
List<ObjectTypes> focusTypeList = new ArrayList<>();
focusTypeList.add(ObjectTypes.RESOURCE);
focusTypeList.add(ObjectTypes.ORG);
focusTypeList.add(ObjectTypes.ROLE);
focusTypeList.add(ObjectTypes.SERVICE);
return focusTypeList;
}
public static List<QName> createSupportedTargetTypeList(QName targetTypeFromDef) {
if (targetTypeFromDef == null || ObjectType.COMPLEX_TYPE.equals(targetTypeFromDef)) {
return createObjectTypeList();
}
if (AbstractRoleType.COMPLEX_TYPE.equals(targetTypeFromDef)) {
return createAbstractRoleTypeList();
}
if (FocusType.COMPLEX_TYPE.equals(targetTypeFromDef)) {
return createFocusTypeList();
}
if (AssignmentHolderType.COMPLEX_TYPE.equals(targetTypeFromDef)) {
return createAssignmentHolderTypeQnamesList();
}
return Collections.singletonList(targetTypeFromDef);
}
/**
* Takes a collection of object types (classes) that may contain abstract types. Returns a collection
* that only contain concrete types.
*
* @param <O> common supertype for all the types in the collections
* <p>
* TODO: move to schema component
*/
public static <O extends ObjectType> List<QName> resolveObjectTypesToQNames(Collection<Class<? extends O>> types, PrismContext prismContext) {
if (types == null) {
return null;
}
List<QName> concreteTypes = new ArrayList<>(types.size());
for (Class<? extends O> type : types) {
if (type == null || type.equals(ObjectType.class)) {
MiscUtil.addAllIfNotPresent(concreteTypes, createObjectTypeList());
} else if (type.equals(FocusType.class)) {
MiscUtil.addAllIfNotPresent(concreteTypes, createFocusTypeList());
} else if (type.equals(AbstractRoleType.class)) {
MiscUtil.addAllIfNotPresent(concreteTypes, createAbstractRoleTypeList());
} else {
MiscUtil.addIfNotPresent(concreteTypes, classToQName(prismContext, type));
}
}
return concreteTypes;
}
public static <T extends Enum> IModel<String> createLocalizedModelForEnum(T value, Component comp) {
String key = value != null ? value.getClass().getSimpleName() + "." + value.name() : "";
return new StringResourceModel(key, comp, null);
}
public static <T extends Enum> IModel<List<T>> createReadonlyModelFromEnum(final Class<T> type) {
return (IModel<List<T>>) () -> {
List<T> list = new ArrayList<>();
Collections.addAll(list, type.getEnumConstants());
return list;
};
}
// use for small enums only
@NotNull
public static <T extends Enum> IModel<List<T>> createReadonlyValueModelFromEnum(@NotNull Class<T> type, @NotNull Predicate<T> filter) {
return new ReadOnlyValueModel<>(
Arrays.stream(type.getEnumConstants())
.filter(filter)
.collect(Collectors.toList()));
}
public static IModel<String> createCategoryNameModel(final Component component,
final IModel<String> categorySymbolModel) {
return (IModel<String>) () -> createStringResourceStatic(component,
"pageTasks.category." + categorySymbolModel.getObject()).getString();
}