-
Notifications
You must be signed in to change notification settings - Fork 188
/
LensUtil.java
1259 lines (1144 loc) · 58.4 KB
/
LensUtil.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.model.impl.lens;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.function.Supplier;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;
import com.evolveum.midpoint.common.refinery.RefinedResourceSchemaImpl;
import com.evolveum.midpoint.model.api.context.EvaluatedPolicyRule;
import com.evolveum.midpoint.model.api.context.EvaluatedPolicyRuleTrigger;
import com.evolveum.midpoint.model.common.expression.*;
import com.evolveum.midpoint.model.impl.util.Utils;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.polystring.PrismDefaultPolyStringNormalizer;
import com.evolveum.midpoint.schema.SchemaConstantsGenerated;
import com.evolveum.midpoint.schema.util.ObjectResolver;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.exception.*;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.apache.commons.lang.BooleanUtils;
import org.apache.commons.lang.mutable.MutableBoolean;
import com.evolveum.midpoint.common.ActivationComputer;
import com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition;
import com.evolveum.midpoint.common.refinery.RefinedResourceSchema;
import com.evolveum.midpoint.model.common.mapping.Mapping;
import com.evolveum.midpoint.model.common.mapping.PrismValueDeltaSetTripleProducer;
import com.evolveum.midpoint.model.impl.expr.ModelExpressionThreadLocalHolder;
import com.evolveum.midpoint.model.impl.lens.projector.ValueMatcher;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.delta.DeltaSetTriple;
import com.evolveum.midpoint.prism.delta.ItemDelta;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.delta.PrismValueDeltaSetTriple;
import com.evolveum.midpoint.prism.delta.PropertyDelta;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.provisioning.api.ProvisioningService;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.ResourceShadowDiscriminator;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.constants.ExpressionConstants;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.ShadowUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author semancik
*
*/
public class LensUtil {
private static final Trace LOGGER = TraceManager.getTrace(LensUtil.class);
public static <F extends ObjectType> void traceContext(Trace logger, String activity, String phase,
boolean important, LensContext<F> context, boolean showTriples) throws SchemaException {
if (logger.isTraceEnabled()) {
logger.trace("Lens context:\n"+
"---[ {} context {} ]--------------------------------\n"+
"{}\n",
activity, phase, context.dump(showTriples));
}
}
public static <F extends ObjectType> ResourceType getResourceReadOnly(LensContext<F> context,
String resourceOid, ProvisioningService provisioningService, Task task, OperationResult result) throws ObjectNotFoundException,
CommunicationException, SchemaException, ConfigurationException, SecurityViolationException {
ResourceType resourceType = context.getResource(resourceOid);
if (resourceType == null) {
// Fetching from provisioning to take advantage of caching and
// pre-parsed schema
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createReadOnly());
resourceType = provisioningService.getObject(ResourceType.class, resourceOid, options, task, result)
.asObjectable();
context.rememberResource(resourceType);
}
return resourceType;
}
public static <F extends ObjectType> ResourceType getResourceReadOnly(LensContext<F> context, String resourceOid, ObjectResolver objectResolver,
Task task, OperationResult result) throws ObjectNotFoundException,
CommunicationException, SchemaException, ConfigurationException, SecurityViolationException {
ResourceType resourceType = context.getResource(resourceOid);
if (resourceType == null) {
ObjectReferenceType ref = new ObjectReferenceType();
ref.setType(ResourceType.COMPLEX_TYPE);
ref.setOid(resourceOid);
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createReadOnly());
resourceType = objectResolver.resolve(ref, ResourceType.class, options, "resource fetch in lens", task, result);
context.rememberResource(resourceType);
}
return resourceType;
}
public static String refineProjectionIntent(ShadowKindType kind, String intent, ResourceType resource, PrismContext prismContext) throws SchemaException {
RefinedResourceSchema refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource, LayerType.MODEL, prismContext);
RefinedObjectClassDefinition rObjClassDef = refinedSchema.getRefinedDefinition(kind, intent);
if (rObjClassDef == null) {
throw new SchemaException("No projection definition for kind="+kind+" intent="+intent+" in "+resource);
}
return rObjClassDef.getIntent();
}
public static <F extends FocusType> LensProjectionContext getProjectionContext(LensContext<F> context, PrismObject<ShadowType> equivalentAccount,
ProvisioningService provisioningService, PrismContext prismContext,
Task task, OperationResult result) throws ObjectNotFoundException,
CommunicationException, SchemaException, ConfigurationException, SecurityViolationException {
ShadowType equivalentAccountType = equivalentAccount.asObjectable();
ShadowKindType kind = ShadowUtil.getKind(equivalentAccountType);
return getProjectionContext(context, ShadowUtil.getResourceOid(equivalentAccountType),
kind, equivalentAccountType.getIntent(), provisioningService,
prismContext, task, result);
}
public static <F extends FocusType> LensProjectionContext getProjectionContext(LensContext<F> context, String resourceOid,
ShadowKindType kind, String intent,
ProvisioningService provisioningService, PrismContext prismContext,
Task task, OperationResult result) throws ObjectNotFoundException,
CommunicationException, SchemaException, ConfigurationException, SecurityViolationException {
ResourceType resource = getResourceReadOnly(context, resourceOid, provisioningService, task, result);
String refinedIntent = refineProjectionIntent(kind, intent, resource, prismContext);
ResourceShadowDiscriminator rsd = new ResourceShadowDiscriminator(resourceOid, kind, refinedIntent);
return context.findProjectionContext(rsd);
}
public static <F extends ObjectType> LensProjectionContext getOrCreateProjectionContext(LensContext<F> context,
ResourceShadowDiscriminator rsd) {
LensProjectionContext accountSyncContext = context.findProjectionContext(rsd);
if (accountSyncContext == null) {
accountSyncContext = context.createProjectionContext(rsd);
ResourceType resource = context.getResource(rsd.getResourceOid());
accountSyncContext.setResource(resource);
}
accountSyncContext.setDoReconciliation(context.isDoReconciliationForAllProjections());
return accountSyncContext;
}
public static <F extends ObjectType> LensProjectionContext createAccountContext(LensContext<F> context, ResourceShadowDiscriminator rsd){
return new LensProjectionContext(context, rsd);
}
/**
* Consolidate the mappings of a single item to a delta. It takes the convenient structure of ItemValueWithOrigin triple.
* It produces the delta considering the mapping exclusion, authoritativeness and strength.
*
* filterExistingValues: if true, then values that already exist in the item are not added (and those that don't exist are not removed)
*/
@NotNull
public static <V extends PrismValue, D extends ItemDefinition, I extends ItemValueWithOrigin<V,D>>
ItemDelta<V,D> consolidateTripleToDelta(
ItemPath itemPath, DeltaSetTriple<I> triple, D itemDefinition,
ItemDelta<V,D> aprioriItemDelta, PrismContainer<?> itemContainer, ValueMatcher<?> valueMatcher, Comparator<V> comparator,
boolean addUnchangedValues, boolean filterExistingValues, boolean isExclusiveStrong,
String contextDescription, boolean applyWeak) throws ExpressionEvaluationException, PolicyViolationException, SchemaException {
ItemDelta<V,D> itemDelta = itemDefinition.createEmptyDelta(itemPath);
Item<V,D> itemExisting = null;
if (itemContainer != null) {
itemExisting = itemContainer.findItem(itemPath);
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Consolidating {} triple:\n{}\nApriori Delta:\n{}\nExisting item:\n{}",
itemPath, triple.debugDump(1),
DebugUtil.debugDump(aprioriItemDelta, 1),
DebugUtil.debugDump(itemExisting, 1));
}
Collection<V> allValues = collectAllValues(triple, valueMatcher);
final MutableBoolean itemHasStrongMutable = new MutableBoolean(false);
SimpleVisitor<I> visitor = pvwo -> {
if (pvwo.getMapping().getStrength() == MappingStrengthType.STRONG) {
itemHasStrongMutable.setValue(true);
}
};
triple.accept(visitor);
boolean ignoreNormalMappings = itemHasStrongMutable.booleanValue() && isExclusiveStrong;
// We will process each value individually. I really mean each value. This whole method deals with
// a single item (e.g. attribute). But this loop iterates over every potential value of that item.
for (V value : allValues) {
LOGGER.trace(" consolidating value: {}", value);
// Check what to do with the value using the usual "triple routine". It means that if a value is
// in zero set than we need no delta, plus set means add delta and minus set means delete delta.
// The first set that the value is present determines the result.
Collection<ItemValueWithOrigin<V,D>> zeroPvwos =
collectPvwosFromSet(value, triple.getZeroSet(), valueMatcher);
Collection<ItemValueWithOrigin<V,D>> plusPvwos =
collectPvwosFromSet(value, triple.getPlusSet(), valueMatcher);
Collection<ItemValueWithOrigin<V,D>> minusPvwos =
collectPvwosFromSet(value, triple.getMinusSet(), valueMatcher);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("PVWOs for value {}:\nzero = {}\nplus = {}\nminus = {}",
value, zeroPvwos, plusPvwos, minusPvwos);
}
boolean zeroHasStrong = false;
if (!zeroPvwos.isEmpty()) {
for (ItemValueWithOrigin<V,D> pvwo : zeroPvwos) {
PrismValueDeltaSetTripleProducer<V,D> mapping = pvwo.getMapping();
if (mapping.getStrength() == MappingStrengthType.STRONG) {
zeroHasStrong = true;
}
}
}
if (zeroHasStrong && aprioriItemDelta != null && aprioriItemDelta.isValueToDelete(value, true)) {
throw new PolicyViolationException("Attempt to delete value "+value+" from item "+itemPath
+" but that value is mandated by a strong mapping (in "+contextDescription+")");
}
if (!zeroPvwos.isEmpty() && !addUnchangedValues) {
// Value unchanged, nothing to do
LOGGER.trace("Value {} unchanged, doing nothing", value);
continue;
}
PrismValueDeltaSetTripleProducer<V, D> exclusiveMapping = null;
Collection<ItemValueWithOrigin<V,D>> pvwosToAdd = null;
if (addUnchangedValues) {
pvwosToAdd = MiscUtil.union(zeroPvwos, plusPvwos);
} else {
pvwosToAdd = plusPvwos;
}
if (!pvwosToAdd.isEmpty()) {
boolean weakOnly = true;
boolean hasStrong = false;
// There may be several mappings that imply that value. So check them all for
// exclusions and strength
for (ItemValueWithOrigin<V,D> pvwoToAdd : pvwosToAdd) {
PrismValueDeltaSetTripleProducer<V,D> mapping = pvwoToAdd.getMapping();
if (mapping.getStrength() != MappingStrengthType.WEAK) {
weakOnly = false;
}
if (mapping.getStrength() == MappingStrengthType.STRONG) {
hasStrong = true;
}
if (mapping.isExclusive()) {
if (exclusiveMapping == null) {
exclusiveMapping = mapping;
} else {
String message = "Exclusion conflict in " + contextDescription + ", item " + itemPath +
", conflicting constructions: " + exclusiveMapping + " and " + mapping;
LOGGER.error(message);
throw new ExpressionEvaluationException(message);
}
}
}
if (weakOnly) {
// Postpone processing of weak values until we process all other values
LOGGER.trace("Value {} mapping is weak in item {}, postponing processing in {}",
value, itemPath, contextDescription);
continue;
}
if (!hasStrong && ignoreNormalMappings) {
LOGGER.trace("Value {} mapping is normal in item {} and we have exclusiveStrong, skipping processing in {}",
value, itemPath, contextDescription);
continue;
}
if (hasStrong && aprioriItemDelta != null && aprioriItemDelta.isValueToDelete(value, true)) {
throw new PolicyViolationException("Attempt to delete value "+value+" from item "+itemPath
+" but that value is mandated by a strong mapping (in "+contextDescription+")");
}
if (!hasStrong && (aprioriItemDelta != null && !aprioriItemDelta.isEmpty())) {
// There is already a delta, skip this
LOGGER.trace("Value {} mapping is not strong and the item {} already has a delta that is more concrete, " +
"skipping adding in {}", value, itemPath, contextDescription);
continue;
}
if (filterExistingValues && hasValue(itemExisting, value, valueMatcher, comparator)) {
LOGGER.trace("Value {} NOT added to delta for item {} because the item already has that value in {}",
value, itemPath, contextDescription);
continue;
}
LOGGER.trace("Value {} added to delta as ADD for item {} in {}", value, itemPath, contextDescription);
itemDelta.addValueToAdd((V)value.clone());
continue;
}
// We need to check for empty plus set. Values that are both in plus and minus are considered to be added.
// So check for that special case here to avoid removing them.
if (!minusPvwos.isEmpty() && plusPvwos.isEmpty()) {
boolean weakOnly = true;
boolean hasStrong = false;
boolean hasAuthoritative = false;
// There may be several mappings that imply that value. So check them all for
// exclusions and strength
for (ItemValueWithOrigin<V,D> pvwo : minusPvwos) {
PrismValueDeltaSetTripleProducer<V,D> mapping = pvwo.getMapping();
if (mapping.getStrength() != MappingStrengthType.WEAK) {
weakOnly = false;
}
if (mapping.getStrength() == MappingStrengthType.STRONG) {
hasStrong = true;
}
if (mapping.isAuthoritative()) {
hasAuthoritative = true;
}
}
if (!hasAuthoritative) {
LOGGER.trace("Value {} has no authoritative mapping for item {}, skipping deletion in {}",
value, itemPath, contextDescription);
continue;
}
if (!hasStrong && (aprioriItemDelta != null && !aprioriItemDelta.isEmpty())) {
// There is already a delta, skip this
LOGGER.trace("Value {} mapping is not strong and the item {} already has a delta that is more concrete, skipping deletion in {}",
value, itemPath, contextDescription);
continue;
}
if (weakOnly && (itemExisting != null && !itemExisting.isEmpty())) {
// There is already a value, skip this
LOGGER.trace("Value {} mapping is weak and the item {} already has a value, skipping deletion in {}",
value, itemPath, contextDescription);
continue;
}
if (weakOnly && !applyWeak && (itemExisting == null || itemExisting.isEmpty())){
// There is a weak mapping on a property, but we do not have full account available, so skipping deletion of the value is better way
LOGGER.trace("Value {} mapping is weak and the full account could not be fetched, skipping deletion in {}",
value, itemPath, contextDescription);
continue;
}
if (filterExistingValues && !hasValue(itemExisting, value, valueMatcher, comparator)) {
LOGGER.trace("Value {} NOT add to delta as DELETE because item {} the item does not have that value in {} (matcher: {})",
value, itemPath, contextDescription, valueMatcher);
continue;
}
LOGGER.trace("Value {} added to delta as DELETE for item {} in {}",
value, itemPath, contextDescription);
itemDelta.addValueToDelete((V)value.clone());
}
if (!zeroPvwos.isEmpty()) {
boolean weakOnly = true;
boolean hasStrong = false;
boolean hasAuthoritative = false;
// There may be several mappings that imply that value. So check them all for
// exclusions and strength
for (ItemValueWithOrigin<V,D> pvwo : zeroPvwos) {
PrismValueDeltaSetTripleProducer<V,D> mapping = pvwo.getMapping();
if (mapping.getStrength() != MappingStrengthType.WEAK) {
weakOnly = false;
}
if (mapping.getStrength() == MappingStrengthType.STRONG) {
hasStrong = true;
}
if (mapping.isAuthoritative()) {
hasAuthoritative = true;
}
}
if (aprioriItemDelta != null && aprioriItemDelta.isReplace()) {
// Any strong mappings in the zero set needs to be re-applied as otherwise the replace will destroy it
if (hasStrong) {
LOGGER.trace("Value {} added to delta for item {} in {} because there is strong mapping in the zero set",
value, itemPath, contextDescription);
itemDelta.addValueToAdd((V)value.clone());
continue;
}
}
}
}
Item<V,D> itemNew = null;
if (itemContainer != null) {
itemNew = itemContainer.findItem(itemPath);
}
if (!hasValue(itemNew, itemDelta)) {
// The application of computed delta results in no value, apply weak mappings
Collection<? extends ItemValueWithOrigin<V,D>> nonNegativePvwos = triple.getNonNegativeValues();
Collection<V> valuesToAdd = addWeakValues(nonNegativePvwos, OriginType.ASSIGNMENTS, applyWeak);
if (valuesToAdd.isEmpty()) {
valuesToAdd = addWeakValues(nonNegativePvwos, OriginType.OUTBOUND, applyWeak);
}
if (valuesToAdd.isEmpty()) {
valuesToAdd = addWeakValues(nonNegativePvwos, null, applyWeak);
}
LOGGER.trace("No value for item {} in {}, weak mapping processing yielded values: {}",
itemPath, contextDescription, valuesToAdd);
itemDelta.addValuesToAdd(valuesToAdd);
} else {
LOGGER.trace("Existing values for item {} in {}, weak mapping processing skipped",
new Object[]{itemPath, contextDescription});
}
if (itemExisting != null) {
List<V> existingValues = itemExisting.getValues();
if (existingValues != null) {
itemDelta.setEstimatedOldValues(PrismValue.cloneCollection(existingValues));
}
}
return itemDelta;
}
private static <V extends PrismValue, D extends ItemDefinition> boolean hasValue(Item<V,D> item, ItemDelta<V,D> itemDelta) throws SchemaException {
if (item == null || item.isEmpty()) {
if (itemDelta != null && itemDelta.addsAnyValue()) {
return true;
} else {
return false;
}
} else {
if (itemDelta == null || itemDelta.isEmpty()) {
return true;
} else {
Item<V,D> clonedItem = item.clone();
itemDelta.applyToMatchingPath(clonedItem);
return !clonedItem.isEmpty();
}
}
}
private static <V extends PrismValue, D extends ItemDefinition> Collection<V> addWeakValues(Collection<? extends ItemValueWithOrigin<V,D>> pvwos, OriginType origin, boolean applyWeak) {
Collection<V> values = new ArrayList<V>();
for (ItemValueWithOrigin<V,D> pvwo: pvwos) {
if (pvwo.getMapping().getStrength() == MappingStrengthType.WEAK && applyWeak) {
if (origin == null || origin == pvwo.getItemValue().getOriginType()) {
values.add((V)pvwo.getItemValue().clone());
}
}
}
return values;
}
private static <V extends PrismValue, D extends ItemDefinition> boolean hasValue(Item<V,D> existingUserItem, V newValue, ValueMatcher<?> valueMatcher, Comparator<V> comparator) {
if (existingUserItem == null) {
return false;
}
if (valueMatcher != null && newValue instanceof PrismPropertyValue) {
return valueMatcher.hasRealValue((PrismProperty)existingUserItem, (PrismPropertyValue)newValue);
} else {
return existingUserItem.contains(newValue, true, comparator);
}
}
private static <V extends PrismValue, D extends ItemDefinition> Collection<V> collectAllValues
(DeltaSetTriple<? extends ItemValueWithOrigin<V,D>> triple, ValueMatcher<?> valueMatcher) throws SchemaException {
Collection<V> allValues = new HashSet<>();
collectAllValuesFromSet(allValues, triple.getZeroSet(), valueMatcher);
collectAllValuesFromSet(allValues, triple.getPlusSet(), valueMatcher);
collectAllValuesFromSet(allValues, triple.getMinusSet(), valueMatcher);
return allValues;
}
private static <V extends PrismValue, D extends ItemDefinition, T> void collectAllValuesFromSet(Collection<V> allValues,
Collection<? extends ItemValueWithOrigin<V,D>> collection, ValueMatcher<T> valueMatcher) throws SchemaException {
if (collection == null) {
return;
}
for (ItemValueWithOrigin<V,D> pvwo : collection) {
V pval = pvwo.getItemValue();
if (valueMatcher == null) {
if (!PrismValue.containsRealValue(allValues, pval)) {
allValues.add(pval);
}
} else {
boolean found = false;
for (V valueFromAllvalues: allValues) {
if (valueMatcher.match(((PrismPropertyValue<T>)valueFromAllvalues).getValue(),
((PrismPropertyValue<T>)pval).getValue())) {
found = true;
break;
}
}
if (!found) {
allValues.add(pval);
}
}
}
}
private static <V extends PrismValue, D extends ItemDefinition> Collection<ItemValueWithOrigin<V,D>> collectPvwosFromSet(V pvalue,
Collection<? extends ItemValueWithOrigin<V,D>> deltaSet, ValueMatcher<?> valueMatcher) throws SchemaException {
Collection<ItemValueWithOrigin<V,D>> pvwos = new ArrayList<>();
for (ItemValueWithOrigin<V,D> setPvwo : deltaSet) {
if (setPvwo.equalsRealValue(pvalue, valueMatcher)) {
pvwos.add(setPvwo);
}
}
return pvwos;
}
public static PropertyDelta<XMLGregorianCalendar> createActivationTimestampDelta(ActivationStatusType status, XMLGregorianCalendar now,
PrismContainerDefinition<ActivationType> activationDefinition, OriginType origin) {
QName timestampPropertyName;
if (status == null || status == ActivationStatusType.ENABLED) {
timestampPropertyName = ActivationType.F_ENABLE_TIMESTAMP;
} else if (status == ActivationStatusType.DISABLED) {
timestampPropertyName = ActivationType.F_DISABLE_TIMESTAMP;
} else if (status == ActivationStatusType.ARCHIVED) {
timestampPropertyName = ActivationType.F_ARCHIVE_TIMESTAMP;
} else {
throw new IllegalArgumentException("Unknown activation status "+status);
}
PrismPropertyDefinition<XMLGregorianCalendar> timestampDef = activationDefinition.findPropertyDefinition(timestampPropertyName);
PropertyDelta<XMLGregorianCalendar> timestampDelta
= timestampDef.createEmptyDelta(new ItemPath(FocusType.F_ACTIVATION, timestampPropertyName));
timestampDelta.setValueToReplace(new PrismPropertyValue<XMLGregorianCalendar>(now, origin, null));
return timestampDelta;
}
public static <F extends ObjectType> void moveTriggers(LensProjectionContext projCtx, LensFocusContext<F> focusCtx) throws SchemaException {
ObjectDelta<ShadowType> projSecondaryDelta = projCtx.getSecondaryDelta();
if (projSecondaryDelta == null) {
return;
}
Collection<? extends ItemDelta> modifications = projSecondaryDelta.getModifications();
Iterator<? extends ItemDelta> iterator = modifications.iterator();
while (iterator.hasNext()) {
ItemDelta projModification = iterator.next();
LOGGER.trace("MOD: {}\n{}", projModification.getPath(), projModification.debugDump());
if (projModification.getPath().equivalent(SchemaConstants.PATH_TRIGGER)) {
focusCtx.swallowToProjectionWaveSecondaryDelta(projModification);
iterator.remove();
}
}
}
public static Object getIterationVariableValue(LensProjectionContext accCtx) {
Integer iterationOld = null;
PrismObject<ShadowType> shadowCurrent = accCtx.getObjectCurrent();
if (shadowCurrent != null) {
iterationOld = shadowCurrent.asObjectable().getIteration();
}
if (iterationOld == null) {
return accCtx.getIteration();
}
PrismPropertyDefinition<Integer> propDef = new PrismPropertyDefinitionImpl<>(ExpressionConstants.VAR_ITERATION,
DOMUtil.XSD_INT, accCtx.getPrismContext());
PrismProperty<Integer> propOld = propDef.instantiate();
propOld.setRealValue(iterationOld);
PropertyDelta<Integer> propDelta = propDef.createEmptyDelta(new ItemPath(ExpressionConstants.VAR_ITERATION));
propDelta.setValueToReplace(new PrismPropertyValue<Integer>(accCtx.getIteration()));
PrismProperty<Integer> propNew = propDef.instantiate();
propNew.setRealValue(accCtx.getIteration());
ItemDeltaItem<PrismPropertyValue<Integer>,PrismPropertyDefinition<Integer>> idi = new ItemDeltaItem<>(propOld, propDelta, propNew);
return idi;
}
public static Object getIterationTokenVariableValue(LensProjectionContext accCtx) {
String iterationTokenOld = null;
PrismObject<ShadowType> shadowCurrent = accCtx.getObjectCurrent();
if (shadowCurrent != null) {
iterationTokenOld = shadowCurrent.asObjectable().getIterationToken();
}
if (iterationTokenOld == null) {
return accCtx.getIterationToken();
}
PrismPropertyDefinition<String> propDef = new PrismPropertyDefinitionImpl<>(
ExpressionConstants.VAR_ITERATION_TOKEN, DOMUtil.XSD_STRING, accCtx.getPrismContext());
PrismProperty<String> propOld = propDef.instantiate();
propOld.setRealValue(iterationTokenOld);
PropertyDelta<String> propDelta = propDef.createEmptyDelta(new ItemPath(ExpressionConstants.VAR_ITERATION_TOKEN));
propDelta.setValueToReplace(new PrismPropertyValue<String>(accCtx.getIterationToken()));
PrismProperty<String> propNew = propDef.instantiate();
propNew.setRealValue(accCtx.getIterationToken());
ItemDeltaItem<PrismPropertyValue<String>,PrismPropertyDefinition<String>> idi = new ItemDeltaItem<>(propOld, propDelta, propNew);
return idi;
}
/**
* Extracts the delta from this projection context and also from all other projection contexts that have
* equivalent discriminator.
*/
public static <F extends ObjectType, T> PropertyDelta<T> findAPrioriDelta(LensContext<F> context,
LensProjectionContext projCtx, ItemPath projectionPropertyPath) throws SchemaException {
PropertyDelta<T> aPrioriDelta = null;
for (LensProjectionContext aProjCtx: findRelatedContexts(context, projCtx)) {
ObjectDelta<ShadowType> aProjDelta = aProjCtx.getDelta();
if (aProjDelta != null) {
PropertyDelta<T> aPropProjDelta = aProjDelta.findPropertyDelta(projectionPropertyPath);
if (aPropProjDelta != null) {
if (aPrioriDelta == null) {
aPrioriDelta = aPropProjDelta.clone();
} else {
aPrioriDelta.merge(aPropProjDelta);
}
}
}
}
return aPrioriDelta;
}
/**
* Extracts the delta from this projection context and also from all other projection contexts that have
* equivalent discriminator.
*/
public static <F extends ObjectType, T> ObjectDelta<ShadowType> findAPrioriDelta(LensContext<F> context,
LensProjectionContext projCtx) throws SchemaException {
ObjectDelta<ShadowType> aPrioriDelta = null;
for (LensProjectionContext aProjCtx: findRelatedContexts(context, projCtx)) {
ObjectDelta<ShadowType> aProjDelta = aProjCtx.getDelta();
if (aProjDelta != null) {
if (aPrioriDelta == null) {
aPrioriDelta = aProjDelta.clone();
} else {
aPrioriDelta.merge(aProjDelta);
}
}
}
return aPrioriDelta;
}
/**
* Returns a list of context that have equivalent discriminator with the reference context. Ordered by "order" in the
* discriminator.
*/
public static <F extends ObjectType> List<LensProjectionContext> findRelatedContexts(
LensContext<F> context, LensProjectionContext refProjCtx) {
List<LensProjectionContext> projCtxs = new ArrayList<LensProjectionContext>();
ResourceShadowDiscriminator refDiscr = refProjCtx.getResourceShadowDiscriminator();
if (refDiscr == null) {
return projCtxs;
}
for (LensProjectionContext aProjCtx: context.getProjectionContexts()) {
ResourceShadowDiscriminator aDiscr = aProjCtx.getResourceShadowDiscriminator();
if (refDiscr.equivalent(aDiscr)) {
projCtxs.add(aProjCtx);
}
}
Comparator<? super LensProjectionContext> orderComparator = new Comparator<LensProjectionContext>() {
@Override
public int compare(LensProjectionContext ctx1, LensProjectionContext ctx2) {
int order1 = ctx1.getResourceShadowDiscriminator().getOrder();
int order2 = ctx2.getResourceShadowDiscriminator().getOrder();
return Integer.compare(order1, order2);
}
};
Collections.sort(projCtxs, orderComparator);
return projCtxs;
}
public static <F extends ObjectType> boolean hasLowerOrderContext(LensContext<F> context,
LensProjectionContext refProjCtx) {
ResourceShadowDiscriminator refDiscr = refProjCtx.getResourceShadowDiscriminator();
for (LensProjectionContext aProjCtx: context.getProjectionContexts()) {
ResourceShadowDiscriminator aDiscr = aProjCtx.getResourceShadowDiscriminator();
if (refDiscr.equivalent(aDiscr) && (refDiscr.getOrder() > aDiscr.getOrder())) {
return true;
}
}
return false;
}
public static <F extends ObjectType> boolean hasDependentContext(LensContext<F> context,
LensProjectionContext targetProjectionContext) {
for (LensProjectionContext projectionContext: context.getProjectionContexts()) {
for (ResourceObjectTypeDependencyType dependency: projectionContext.getDependencies()) {
if (isDependencyTargetContext(projectionContext, targetProjectionContext, dependency)) {
return true;
}
}
}
return false;
}
public static <F extends ObjectType> boolean isDependencyTargetContext(LensProjectionContext sourceProjContext, LensProjectionContext targetProjectionContext, ResourceObjectTypeDependencyType dependency) {
ResourceShadowDiscriminator refDiscr = new ResourceShadowDiscriminator(dependency,
sourceProjContext.getResource().getOid(), sourceProjContext.getKind());
return targetProjectionContext.compareResourceShadowDiscriminator(refDiscr, false);
}
public static <F extends ObjectType> LensProjectionContext findLowerOrderContext(LensContext<F> context,
LensProjectionContext refProjCtx) {
int minOrder = -1;
LensProjectionContext foundCtx = null;
ResourceShadowDiscriminator refDiscr = refProjCtx.getResourceShadowDiscriminator();
for (LensProjectionContext aProjCtx: context.getProjectionContexts()) {
ResourceShadowDiscriminator aDiscr = aProjCtx.getResourceShadowDiscriminator();
if (refDiscr.equivalent(aDiscr) && (refDiscr.getOrder() > aDiscr.getOrder())) {
if (minOrder < 0 || (aDiscr.getOrder() < minOrder)) {
minOrder = aDiscr.getOrder();
foundCtx = aProjCtx;
}
}
}
return foundCtx;
}
public static <T extends ObjectType, F extends ObjectType> void setContextOid(LensContext<F> context,
LensElementContext<T> objectContext, String oid) {
objectContext.setOid(oid);
// Check if we need to propagate this oid also to higher-order contexts
if (!(objectContext instanceof LensProjectionContext)) {
return;
}
LensProjectionContext refProjCtx = (LensProjectionContext)objectContext;
ResourceShadowDiscriminator refDiscr = refProjCtx.getResourceShadowDiscriminator();
if (refDiscr == null) {
return;
}
for (LensProjectionContext aProjCtx: context.getProjectionContexts()) {
ResourceShadowDiscriminator aDiscr = aProjCtx.getResourceShadowDiscriminator();
if (aDiscr != null && refDiscr.equivalent(aDiscr) && (refDiscr.getOrder() < aDiscr.getOrder())) {
aProjCtx.setOid(oid);
}
}
}
public static <F extends FocusType> PrismObjectDefinition<F> getFocusDefinition(LensContext<F> context) {
LensFocusContext<F> focusContext = context.getFocusContext();
if (focusContext == null) {
return null;
}
Class<F> typeClass = focusContext.getObjectTypeClass();
return context.getPrismContext().getSchemaRegistry().findObjectDefinitionByCompileTimeClass(typeClass);
}
public static int determineMaxIterations(IterationSpecificationType iterationSpecType) {
if (iterationSpecType != null) {
return iterationSpecType.getMaxIterations();
} else {
return 0;
}
}
public static <F extends ObjectType> String formatIterationToken(LensContext<F> context,
LensElementContext<?> accountContext, IterationSpecificationType iterationType,
int iteration, ExpressionFactory expressionFactory, ExpressionVariables variables,
Task task, OperationResult result)
throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
if (iterationType == null) {
return formatIterationTokenDefault(iteration);
}
ExpressionType tokenExpressionType = iterationType.getTokenExpression();
if (tokenExpressionType == null) {
return formatIterationTokenDefault(iteration);
}
PrismPropertyDefinition<String> outputDefinition = new PrismPropertyDefinitionImpl<>(ExpressionConstants.VAR_ITERATION_TOKEN,
DOMUtil.XSD_STRING, context.getPrismContext());
Expression<PrismPropertyValue<String>,PrismPropertyDefinition<String>> expression = expressionFactory.makeExpression(tokenExpressionType, outputDefinition , "iteration token expression in "+accountContext.getHumanReadableName(), task, result);
Collection<Source<?,?>> sources = new ArrayList<>();
PrismPropertyDefinitionImpl<Integer> inputDefinition = new PrismPropertyDefinitionImpl<>(ExpressionConstants.VAR_ITERATION,
DOMUtil.XSD_INT, context.getPrismContext());
inputDefinition.setMaxOccurs(1);
PrismProperty<Integer> input = inputDefinition.instantiate();
input.add(new PrismPropertyValue<Integer>(iteration));
ItemDeltaItem<PrismPropertyValue<Integer>,PrismPropertyDefinition<Integer>> idi = new ItemDeltaItem<>(input);
Source<PrismPropertyValue<Integer>,PrismPropertyDefinition<Integer>> iterationSource = new Source<>(idi, ExpressionConstants.VAR_ITERATION);
sources.add(iterationSource);
ExpressionEvaluationContext expressionContext = new ExpressionEvaluationContext(sources , variables,
"iteration token expression in "+accountContext.getHumanReadableName(), task, result);
PrismValueDeltaSetTriple<PrismPropertyValue<String>> outputTriple = ModelExpressionThreadLocalHolder.evaluateExpressionInContext(expression, expressionContext, task, result);
Collection<PrismPropertyValue<String>> outputValues = outputTriple.getNonNegativeValues();
if (outputValues.isEmpty()) {
return "";
}
if (outputValues.size() > 1) {
throw new ExpressionEvaluationException("Iteration token expression in "+accountContext.getHumanReadableName()+" returned more than one value ("+outputValues.size()+" values)");
}
String realValue = outputValues.iterator().next().getValue();
if (realValue == null) {
return "";
}
return realValue;
}
public static String formatIterationTokenDefault(int iteration) {
if (iteration == 0) {
return "";
}
return Integer.toString(iteration);
}
public static <F extends ObjectType> boolean evaluateIterationCondition(LensContext<F> context,
LensElementContext<?> accountContext, IterationSpecificationType iterationType,
int iteration, String iterationToken, boolean beforeIteration,
ExpressionFactory expressionFactory, ExpressionVariables variables, Task task, OperationResult result)
throws ExpressionEvaluationException, SchemaException, ObjectNotFoundException {
if (iterationType == null) {
return true;
}
ExpressionType expressionType;
String desc;
if (beforeIteration) {
expressionType = iterationType.getPreIterationCondition();
desc = "pre-iteration expression in "+accountContext.getHumanReadableName();
} else {
expressionType = iterationType.getPostIterationCondition();
desc = "post-iteration expression in "+accountContext.getHumanReadableName();
}
if (expressionType == null) {
return true;
}
PrismPropertyDefinition<Boolean> outputDefinition = new PrismPropertyDefinitionImpl<>(
ExpressionConstants.OUTPUT_ELEMENT_NAME,
DOMUtil.XSD_BOOLEAN, context.getPrismContext());
Expression<PrismPropertyValue<Boolean>,PrismPropertyDefinition<Boolean>> expression = expressionFactory.makeExpression(expressionType, outputDefinition , desc, task, result);
variables.addVariableDefinition(ExpressionConstants.VAR_ITERATION, iteration);
variables.addVariableDefinition(ExpressionConstants.VAR_ITERATION_TOKEN, iterationToken);
ExpressionEvaluationContext expressionContext = new ExpressionEvaluationContext(null , variables, desc, task, result);
PrismValueDeltaSetTriple<PrismPropertyValue<Boolean>> outputTriple = ModelExpressionThreadLocalHolder.evaluateExpressionInContext(expression, expressionContext, task, result);
Collection<PrismPropertyValue<Boolean>> outputValues = outputTriple.getNonNegativeValues();
if (outputValues.isEmpty()) {
return false;
}
if (outputValues.size() > 1) {
throw new ExpressionEvaluationException(desc+" returned more than one value ("+outputValues.size()+" values)");
}
Boolean realValue = outputValues.iterator().next().getValue();
if (realValue == null) {
return false;
}
return realValue;
}
/**
* Used for assignments and similar objects that do not have separate lifecycle.
*/
public static boolean isAssignmentValid(FocusType focus, AssignmentType assignmentType, XMLGregorianCalendar now, ActivationComputer activationComputer) {
String focusLifecycleState = focus.getLifecycleState();
if (!activationComputer.lifecycleHasActiveAssignments(focusLifecycleState)) {
return false;
}
return isValid(assignmentType.getLifecycleState(), assignmentType.getActivation(), now, activationComputer);
}
public static boolean isFocusValid(FocusType focus, XMLGregorianCalendar now, ActivationComputer activationComputer) {
return isValid(focus.getLifecycleState(), focus.getActivation(), now, activationComputer);
}
private static boolean isValid(String lifecycleState, ActivationType activationType, XMLGregorianCalendar now, ActivationComputer activationComputer) {
TimeIntervalStatusType validityStatus = activationComputer.getValidityStatus(activationType, now);
ActivationStatusType effectiveStatus = activationComputer.getEffectiveStatus(lifecycleState, activationType, validityStatus);
return effectiveStatus == ActivationStatusType.ENABLED;
}
public static AssignmentPathVariables computeAssignmentPathVariables(AssignmentPathImpl assignmentPath) throws SchemaException {
if (assignmentPath == null || assignmentPath.isEmpty()) {
return null;
}
AssignmentPathVariables vars = new AssignmentPathVariables();
vars.setAssignmentPath(assignmentPath.clone());
Iterator<AssignmentPathSegmentImpl> iterator = assignmentPath.getSegments().iterator();
while (iterator.hasNext()) {
AssignmentPathSegmentImpl segment = iterator.next();
ItemDeltaItem<PrismContainerValue<AssignmentType>,PrismContainerDefinition<AssignmentType>> segmentAssignmentIdi = segment.getAssignmentIdi();
ItemDeltaItem<PrismContainerValue<AssignmentType>,PrismContainerDefinition<AssignmentType>> magicAssignmentIdi;
// Magic assignment
if (vars.getMagicAssignment() == null) {
magicAssignmentIdi = segmentAssignmentIdi.clone();
vars.setMagicAssignment(magicAssignmentIdi);
} else {
// Collect extension values from the assignment extension
magicAssignmentIdi = vars.getMagicAssignment();
mergeExtension(magicAssignmentIdi, segmentAssignmentIdi);
}
// Collect extension values from the source object extension
ObjectType segmentSource = segment.getSource();
if (segmentSource != null) {
mergeExtension(magicAssignmentIdi, segmentSource.asPrismObject());
}
// immediate assignment (use assignment from previous iteration)
vars.setImmediateAssignment(vars.getThisAssignment());
// this assignment
ItemDeltaItem<PrismContainerValue<AssignmentType>,PrismContainerDefinition<AssignmentType>> thisAssignment = segmentAssignmentIdi.clone();
vars.setThisAssignment(thisAssignment);
if (iterator.hasNext() && segmentSource instanceof AbstractRoleType) {
vars.setImmediateRole((PrismObject<? extends AbstractRoleType>) segmentSource.asPrismObject());
}
}
AssignmentPathSegmentImpl focusAssignmentSegment = assignmentPath.first();
ItemDeltaItem<PrismContainerValue<AssignmentType>,PrismContainerDefinition<AssignmentType>> focusAssignment = focusAssignmentSegment.getAssignmentIdi().clone();
vars.setFocusAssignment(focusAssignment);
return vars;
}
private static void mergeExtension(ItemDeltaItem<PrismContainerValue<AssignmentType>,PrismContainerDefinition<AssignmentType>> destIdi, ItemDeltaItem<PrismContainerValue<AssignmentType>,PrismContainerDefinition<AssignmentType>> srcIdi) throws SchemaException {
mergeExtension(destIdi.getItemOld(), srcIdi.getItemOld());
mergeExtension(destIdi.getItemNew(), srcIdi.getItemNew());
if (srcIdi.getDelta() != null || srcIdi.getSubItemDeltas() != null) {
throw new UnsupportedOperationException("Merge of IDI with deltas not supported");
}
}
private static void mergeExtension(Item<PrismContainerValue<AssignmentType>,PrismContainerDefinition<AssignmentType>> dstItem,
Item<PrismContainerValue<AssignmentType>,PrismContainerDefinition<AssignmentType>> srcItem) throws SchemaException {
if (srcItem == null || dstItem == null) {
return;
}
PrismContainer<Containerable> srcExtension = ((PrismContainer<AssignmentType>)srcItem).findContainer(AssignmentType.F_EXTENSION);
mergeExtensionContainers(dstItem, srcExtension);
}
private static <O extends ObjectType> void mergeExtension(ItemDeltaItem<PrismContainerValue<AssignmentType>,PrismContainerDefinition<AssignmentType>> destIdi,
PrismObject<O> srcObject) throws SchemaException {
if (srcObject == null) {
return;
}
PrismContainer<Containerable> srcExtension = srcObject.findContainer(ObjectType.F_EXTENSION);
mergeExtensionContainers(destIdi.getItemNew(), srcExtension);
mergeExtensionContainers(destIdi.getItemOld(), srcExtension);
}
private static void mergeExtensionContainers(Item<PrismContainerValue<AssignmentType>,PrismContainerDefinition<AssignmentType>> dstItem, PrismContainer<Containerable> srcExtension) throws SchemaException {
if (dstItem == null) {
return;
}
PrismContainer<AssignmentType> dstContainer = (PrismContainer<AssignmentType>) dstItem;
if (srcExtension != null && !srcExtension.getValue().isEmpty()) {
PrismContainer<Containerable> dstExtension = dstContainer.findOrCreateContainer(AssignmentType.F_EXTENSION);
for (Item<?,?> srcExtensionItem: srcExtension.getValue().getItems()) {
Item<?,?> magicItem = dstExtension.findItem(srcExtensionItem.getElementName());
if (magicItem == null) {
dstExtension.add(srcExtensionItem.clone());
}
}
}
}
private static void mergeExtension(PrismContainer<Containerable> magicExtension, PrismContainer<Containerable> segmentExtension) throws SchemaException {
if (segmentExtension != null && !segmentExtension.getValue().isEmpty()) {
for (Item<?,?> segmentItem: segmentExtension.getValue().getItems()) {
Item<?,?> magicItem = magicExtension.findItem(segmentItem.getElementName());
if (magicItem == null) {
magicExtension.add(segmentItem.clone());
}
}
}
}
public static <V extends PrismValue,D extends ItemDefinition> Mapping.Builder<V,D> addAssignmentPathVariables(Mapping.Builder<V,D> builder, AssignmentPathVariables assignmentPathVariables) {
ExpressionVariables expressionVariables = new ExpressionVariables();
Utils.addAssignmentPathVariables(assignmentPathVariables, expressionVariables);
return builder.addVariableDefinitions(expressionVariables.getMap());
}
public static <F extends ObjectType> void checkContextSanity(LensContext<F> context, String activityDescription,
OperationResult result) throws SchemaException, PolicyViolationException {
LensFocusContext<F> focusContext = context.getFocusContext();
if (focusContext != null) {
PrismObject<F> focusObjectNew = focusContext.getObjectNew();
if (focusObjectNew != null) {
PolyStringType namePolyType = focusObjectNew.asObjectable().getName();
if (namePolyType == null) {
throw new SchemaException("Focus "+focusObjectNew+" does not have a name after "+activityDescription);
}
ObjectPolicyConfigurationType objectPolicyConfigurationType = focusContext.getObjectPolicyConfigurationType();
checkObjectPolicy(focusContext, objectPolicyConfigurationType);
}
}
}
private static <F extends ObjectType> void checkObjectPolicy(LensFocusContext<F> focusContext, ObjectPolicyConfigurationType objectPolicyConfigurationType) throws SchemaException, PolicyViolationException {