/
RefinedObjectClassDefinitionImpl.java
1294 lines (1130 loc) · 46 KB
/
RefinedObjectClassDefinitionImpl.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.common.refinery;
import com.evolveum.midpoint.common.ResourceObjectPattern;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.marshaller.QueryConvertor;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.query.ObjectFilter;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.prism.util.ItemPathUtil;
import com.evolveum.midpoint.schema.ResourceShadowDiscriminator;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.processor.*;
import com.evolveum.midpoint.schema.util.ObjectQueryUtil;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.schema.util.ResourceTypeUtil;
import com.evolveum.midpoint.schema.util.SchemaDebugUtil;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.util.PrettyPrinter;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SystemException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.CapabilityType;
import com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.CountObjectsCapabilityType;
import com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.PagedSearchCapabilityType;
import com.evolveum.prism.xml.ns._public.query_3.SearchFilterType;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.Validate;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.xml.namespace.QName;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.stream.Collectors;
/**
* @author semancik
*/
public class RefinedObjectClassDefinitionImpl implements RefinedObjectClassDefinition {
private static final Trace LOGGER = TraceManager.getTrace(RefinedObjectClassDefinition.class);
@NotNull private final List<RefinedAttributeDefinition<?>> attributeDefinitions = new ArrayList<>();
@NotNull private final List<RefinedAssociationDefinition> associationDefinitions = new ArrayList<>();
@NotNull private final ObjectClassComplexTypeDefinition originalObjectClassDefinition;
@NotNull private final List<RefinedObjectClassDefinition> auxiliaryObjectClassDefinitions = new ArrayList<>();
private final String resourceOid;
private ResourceObjectTypeDefinitionType schemaHandlingObjectTypeDefinitionType;
private String intent;
private ShadowKindType kind;
private String displayName;
private String description;
private boolean isDefault;
private boolean shared = true; // experimental
@NotNull private final List<RefinedAttributeDefinition<?>> identifiers = new ArrayList<>();
@NotNull private final List<RefinedAttributeDefinition<?>> secondaryIdentifiers = new ArrayList<>();
@NotNull private final List<ResourceObjectPattern> protectedObjectPatterns = new ArrayList<>();
private ResourceObjectReferenceType baseContext;
private RefinedAttributeDefinition<?> displayNameAttributeDefinition;
private RefinedAttributeDefinition<?> namingAttributeDefinition;
private RefinedAttributeDefinition<?> descriptionAttributeDefinition;
/**
* Refined object definition. The "any" parts are replaced with appropriate schema (e.g. resource schema)
*/
private PrismObjectDefinition<ShadowType> objectDefinition = null;
private RefinedObjectClassDefinitionImpl(String resourceOid, @NotNull ObjectClassComplexTypeDefinition objectClassDefinition) {
this.resourceOid = resourceOid;
this.originalObjectClassDefinition = objectClassDefinition;
}
//region General attribute definitions ========================================================
@NotNull
@Override
public Collection<? extends RefinedAttributeDefinition<?>> getAttributeDefinitions() {
return Collections.unmodifiableList(attributeDefinitions);
}
@NotNull
@Override
public List<? extends ItemDefinition> getDefinitions() {
return (List<? extends ItemDefinition>) getAttributeDefinitions();
}
@Override
public Collection<? extends QName> getNamesOfAttributesWithOutboundExpressions() {
return getAttributeDefinitions().stream()
.filter(attrDef -> attrDef.getOutboundMappingType() != null)
.map(attrDef -> attrDef.getName())
.collect(Collectors.toCollection(HashSet::new));
}
@Override
public Collection<? extends QName> getNamesOfAttributesWithInboundExpressions() {
return getAttributeDefinitions().stream()
.filter(attrDef -> CollectionUtils.isNotEmpty(attrDef.getInboundMappingTypes()))
.map(attrDef -> attrDef.getName())
.collect(Collectors.toCollection(HashSet::new));
}
@Override
public <ID extends ItemDefinition> ID findItemDefinition(@NotNull QName name, @NotNull Class<ID> clazz,
boolean caseInsensitive) {
for (ItemDefinition def : getDefinitions()) {
if (def.isValidFor(name, clazz, caseInsensitive)) {
return (ID) def;
}
}
return null;
}
//endregion
//region Special attribute definitions ========================================================
@NotNull
@Override
public Collection<RefinedAttributeDefinition<?>> getPrimaryIdentifiers() {
return identifiers;
}
@NotNull
@Override
public Collection<RefinedAttributeDefinition<?>> getSecondaryIdentifiers() {
return secondaryIdentifiers;
}
@Override
public <X> RefinedAttributeDefinition<X> getDescriptionAttribute() {
return substituteRefinedAttributeDefinition(
() -> (RefinedAttributeDefinition<X>) descriptionAttributeDefinition,
rad -> descriptionAttributeDefinition = rad,
originalObjectClassDefinition::getDescriptionAttribute
);
}
@Override
public <X> RefinedAttributeDefinition<X> getNamingAttribute() {
return substituteRefinedAttributeDefinition(
() -> (RefinedAttributeDefinition<X>) namingAttributeDefinition,
rad -> namingAttributeDefinition = rad,
originalObjectClassDefinition::getNamingAttribute
);
}
@Override
public <X> RefinedAttributeDefinition<X> getDisplayNameAttribute() {
return substituteRefinedAttributeDefinition(
() -> (RefinedAttributeDefinition<X>) displayNameAttributeDefinition,
rad -> displayNameAttributeDefinition = rad,
originalObjectClassDefinition::getDisplayNameAttribute
);
}
private <X> RefinedAttributeDefinition<X> substituteRefinedAttributeDefinition(
Supplier<RefinedAttributeDefinition<X>> getter, Consumer<RefinedAttributeDefinition<X>> setter,
Supplier<ResourceAttributeDefinition<X>> getterOfOriginal) {
RefinedAttributeDefinition<X> value = getter.get();
if (value == null) {
ResourceAttributeDefinition original = getterOfOriginal.get();
if (original == null) {
return null;
}
value = findAttributeDefinition(original.getName());
setter.accept(value);
}
return value;
}
//endregion
//region General association definitions ========================================================
@NotNull
@Override
public Collection<RefinedAssociationDefinition> getAssociationDefinitions() {
return Collections.unmodifiableList(associationDefinitions);
}
@Override
public Collection<RefinedAssociationDefinition> getAssociationDefinitions(ShadowKindType kind) {
return Collections.unmodifiableList(
associationDefinitions.stream()
.filter(association -> kind == association.getKind())
.collect(Collectors.toList()));
}
@Override
public RefinedAssociationDefinition findAssociationDefinition(QName name) {
return associationDefinitions.stream()
.filter(a -> QNameUtil.match(a.getName(), name))
.findFirst().orElse(null);
}
@Override
public Collection<QName> getNamesOfAssociations() {
return getAssociationDefinitions().stream()
.map(a -> a.getName())
.collect(Collectors.toCollection(HashSet::new));
}
@Override
public Collection<? extends QName> getNamesOfAssociationsWithOutboundExpressions() {
return getAssociationDefinitions().stream()
.filter(assocDef -> assocDef.getOutboundMappingType() != null)
.map(a -> a.getName())
.collect(Collectors.toCollection(HashSet::new));
}
//endregion
//region General information ========================================================
@Override
public String getDisplayName() {
return displayName;
}
private void setDisplayName(String displayName) {
this.displayName = displayName;
}
@Override
public String getDescription() {
return description;
}
private void setDescription(String description) {
this.description = description;
}
@Override
public ObjectClassComplexTypeDefinition getObjectClassDefinition() {
return originalObjectClassDefinition;
}
@Override
public String getResourceOid() {
return resourceOid;
}
@Override
public boolean isDefault() {
return isDefault;
}
private void setDefault(boolean isDefault) {
this.isDefault = isDefault;
}
@Override
public boolean isDefaultInAKind() {
return isDefault;
}
@Override
public ResourceObjectReferenceType getBaseContext() {
return baseContext;
}
private void setBaseContext(ResourceObjectReferenceType baseContext) {
this.baseContext = baseContext;
}
@Override
public String getIntent() {
return intent;
}
public void setIntent(String intent) {
this.intent = intent;
}
@Override
public ShadowKindType getKind() {
if (kind != null) {
return kind;
}
return getObjectClassDefinition().getKind();
}
public void setKind(ShadowKindType kind) {
this.kind = kind;
}
@Override
public ResourceObjectVolatilityType getVolatility() {
if (schemaHandlingObjectTypeDefinitionType == null) {
return null;
}
return schemaHandlingObjectTypeDefinitionType.getVolatility();
}
//endregion
//region Generating and matching artifacts ========================================================
@Override
public PrismObjectDefinition<ShadowType> getObjectDefinition() {
if (objectDefinition == null) {
objectDefinition = constructObjectDefinition(this);
}
return objectDefinition;
}
static PrismObjectDefinition<ShadowType> constructObjectDefinition(RefinedObjectClassDefinition refinedObjectClassDefinition) {
// Almost-shallow clone of object definition and complex type
PrismObjectDefinition<ShadowType> originalObjectDefinition =
refinedObjectClassDefinition.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(ShadowType.class);
return originalObjectDefinition.cloneWithReplacedDefinition(ShadowType.F_ATTRIBUTES,
refinedObjectClassDefinition.toResourceAttributeContainerDefinition());
}
@Override
public PrismObject<ShadowType> createBlankShadow(RefinedObjectClassDefinition definition) {
PrismObject<ShadowType> accountShadow;
try {
accountShadow = getPrismContext().createObject(ShadowType.class);
} catch (SchemaException e) {
// This should not happen
throw new SystemException("Internal error instantiating account shadow: "+e.getMessage(), e);
}
ShadowType accountShadowType = accountShadow.asObjectable();
accountShadowType
.intent(getIntent())
.kind(getKind())
.objectClass(getObjectClassDefinition().getTypeName())
.resourceRef(getResourceOid(), ResourceType.COMPLEX_TYPE);
// Setup definition
PrismObjectDefinition<ShadowType> newDefinition = accountShadow.getDefinition().cloneWithReplacedDefinition(
ShadowType.F_ATTRIBUTES, definition.toResourceAttributeContainerDefinition());
accountShadow.setDefinition(newDefinition);
return accountShadow;
}
@Override
public ResourceShadowDiscriminator getShadowDiscriminator() {
return new ResourceShadowDiscriminator(getResourceOid(), getKind(), getIntent());
}
@Override
public boolean matches(ShadowType shadowType) {
if (shadowType == null) {
return false;
}
if (!QNameUtil.match(getObjectClassDefinition().getTypeName(), shadowType.getObjectClass())) {
return false;
}
if (shadowType.getKind() == null) {
if (kind != ShadowKindType.ACCOUNT) {
return false;
}
} else {
if (!MiscUtil.equals(kind, shadowType.getKind())) {
return false;
}
}
if (shadowType.getIntent() != null) {
// if (isDefault) {
// return true;
// } else {
// return false;
// }
// } else {
return MiscUtil.equals(intent, shadowType.getIntent());
}
return true;
}
@Override
public ObjectQuery createShadowSearchQuery(String resourceOid) throws SchemaException {
if (getKind() == null) {
return ObjectQueryUtil.createResourceAndObjectClassQuery(resourceOid, getTypeName(), getPrismContext());
} else {
return ObjectQueryUtil.createResourceAndKindIntent(resourceOid, getKind(), getIntent(), getPrismContext());
}
}
//endregion
//region Accessing parts of schema handling ========================================================
@NotNull
@Override
public Collection<RefinedObjectClassDefinition> getAuxiliaryObjectClassDefinitions() {
return auxiliaryObjectClassDefinitions;
}
@Override
public boolean hasAuxiliaryObjectClass(QName expectedObjectClassName) {
return auxiliaryObjectClassDefinitions.stream()
.anyMatch(def -> QNameUtil.match(def.getTypeName(), expectedObjectClassName));
}
@Override
public boolean isTolerantAuxiliaryObjectClasses() {
if (schemaHandlingObjectTypeDefinitionType == null) {
return false;
}
Boolean tolerantAuxiliaryObjectClasses = schemaHandlingObjectTypeDefinitionType.isTolerantAuxiliaryObjectClasses();
if (tolerantAuxiliaryObjectClasses == null) {
return false;
} else {
return tolerantAuxiliaryObjectClasses;
}
}
@Override
public Collection<ResourceObjectPattern> getProtectedObjectPatterns() {
return protectedObjectPatterns;
}
@Override
public ResourcePasswordDefinitionType getPasswordDefinition() {
if (schemaHandlingObjectTypeDefinitionType == null) {
return null;
}
ResourceCredentialsDefinitionType credentials = schemaHandlingObjectTypeDefinitionType.getCredentials();
if (credentials == null) {
return null;
}
return credentials.getPassword();
}
@Override
public List<MappingType> getPasswordInbound() {
ResourcePasswordDefinitionType password = getPasswordDefinition();
if (password == null || password.getInbound() == null) {
return null;
}
return password.getInbound();
}
@Override
public List<MappingType> getPasswordOutbound() {
ResourcePasswordDefinitionType password = getPasswordDefinition();
if (password == null || password.getOutbound() == null) {
return null;
}
return password.getOutbound();
}
@Override
public AttributeFetchStrategyType getPasswordFetchStrategy() {
ResourcePasswordDefinitionType password = getPasswordDefinition();
if (password == null) {
return AttributeFetchStrategyType.IMPLICIT;
}
if (password.getFetchStrategy() == null) {
return AttributeFetchStrategyType.IMPLICIT;
}
return password.getFetchStrategy();
}
@Override
public ObjectReferenceType getPasswordPolicy() {
ResourcePasswordDefinitionType password = getPasswordDefinition();
if (password == null || password.getPasswordPolicyRef() == null){
return null;
}
return password.getPasswordPolicyRef();
}
@Override
public ResourceActivationDefinitionType getActivationSchemaHandling(){
if (schemaHandlingObjectTypeDefinitionType == null) {
return null;
}
return schemaHandlingObjectTypeDefinitionType.getActivation();
}
@Override
public ResourceBidirectionalMappingType getActivationBidirectionalMappingType(QName propertyName) {
ResourceActivationDefinitionType activationSchemaHandling = getActivationSchemaHandling();
if (activationSchemaHandling == null) {
return null;
}
if (QNameUtil.match(ActivationType.F_ADMINISTRATIVE_STATUS, propertyName)) {
return activationSchemaHandling.getAdministrativeStatus();
} else if (QNameUtil.match(ActivationType.F_VALID_FROM, propertyName)) {
return activationSchemaHandling.getValidFrom();
} else if (QNameUtil.match(ActivationType.F_VALID_TO, propertyName)) {
return activationSchemaHandling.getValidTo();
} else if (QNameUtil.match(ActivationType.F_LOCKOUT_STATUS, propertyName)) {
return activationSchemaHandling.getLockoutStatus();
} else if (QNameUtil.match(ActivationType.F_LOCKOUT_EXPIRATION_TIMESTAMP, propertyName)) {
return null; // todo implement this
} else {
throw new IllegalArgumentException("Unknown activation property "+propertyName);
}
}
@Override
public AttributeFetchStrategyType getActivationFetchStrategy(QName propertyName) {
ResourceBidirectionalMappingType biType = getActivationBidirectionalMappingType(propertyName);
if (biType == null) {
return AttributeFetchStrategyType.IMPLICIT;
}
if (biType.getFetchStrategy() == null) {
return AttributeFetchStrategyType.IMPLICIT;
}
return biType.getFetchStrategy();
}
//endregion
//region Capabilities ========================================================
@Override
public <T extends CapabilityType> T getEffectiveCapability(Class<T> capabilityClass, ResourceType resourceType) {
return ResourceTypeUtil.getEffectiveCapability(resourceType, schemaHandlingObjectTypeDefinitionType, capabilityClass);
}
@Override
public PagedSearchCapabilityType getPagedSearches(ResourceType resourceType) {
return getEffectiveCapability(PagedSearchCapabilityType.class, resourceType);
}
@Override
public boolean isPagedSearchEnabled(ResourceType resourceType) {
return getPagedSearches(resourceType) != null; // null means nothing or disabled
}
@Override
public boolean isObjectCountingEnabled(ResourceType resourceType) {
return getEffectiveCapability(CountObjectsCapabilityType.class, resourceType) != null;
}
//endregion
//region Cloning ========================================================
@NotNull
@Override
public RefinedObjectClassDefinitionImpl clone() {
RefinedObjectClassDefinitionImpl clone = new RefinedObjectClassDefinitionImpl(resourceOid, originalObjectClassDefinition);
copyDefinitionData(clone);
shared = false;
return clone;
}
// assuming we are called on empty object
private void copyDefinitionData(RefinedObjectClassDefinitionImpl clone) {
clone.attributeDefinitions.addAll(cloneDefinitions(this.attributeDefinitions));
clone.associationDefinitions.addAll(cloneAssociations(this.associationDefinitions));
clone.auxiliaryObjectClassDefinitions.addAll(auxiliaryObjectClassDefinitions);
clone.schemaHandlingObjectTypeDefinitionType = this.schemaHandlingObjectTypeDefinitionType;
clone.intent = this.intent;
clone.kind = this.kind;
clone.displayName = this.displayName;
clone.description = this.description;
clone.isDefault = this.isDefault;
clone.identifiers.addAll(cloneDefinitions(this.identifiers));
clone.secondaryIdentifiers.addAll(cloneDefinitions(this.secondaryIdentifiers));
clone.protectedObjectPatterns.addAll(this.protectedObjectPatterns);
clone.baseContext = this.baseContext;
}
@NotNull
@Override
public RefinedObjectClassDefinition deepClone(Map<QName, ComplexTypeDefinition> ctdMap) {
// TODO TODO TODO (note that in original implementation this was also missing...)
RefinedObjectClassDefinitionImpl clone = new RefinedObjectClassDefinitionImpl(resourceOid, originalObjectClassDefinition.deepClone(ctdMap));
copyDefinitionData(clone);
shared = false;
return clone;
}
private Collection<RefinedAssociationDefinition> cloneAssociations(Collection<RefinedAssociationDefinition> origAsoc) {
return origAsoc.stream()
.map(RefinedAssociationDefinition::clone)
.collect(Collectors.toList());
}
private List<? extends RefinedAttributeDefinition<?>> cloneDefinitions(Collection<? extends RefinedAttributeDefinition<?>> origDefs) {
return origDefs.stream()
.map(RefinedAttributeDefinition::clone)
.collect(Collectors.toList());
}
//endregion
/**
* Creates a derived version of this ROCD for a given layer.
* TODO clone if necessary/if specified (currently there is no cloning)
*
* @param layerType
* @return
*/
@Override
public LayerRefinedObjectClassDefinition forLayer(@NotNull LayerType layerType) {
Validate.notNull(layerType);
return LayerRefinedObjectClassDefinitionImpl.wrap(this, layerType);
}
//region Delegations ========================================================
@NotNull
@Override
public QName getTypeName() {
return getObjectClassDefinition().getTypeName();
}
@Override
public String getNativeObjectClass() {
return getObjectClassDefinition().getNativeObjectClass();
}
public boolean isAuxiliary() {
return getObjectClassDefinition().isAuxiliary();
}
@Override
public PrismContext getPrismContext() {
return originalObjectClassDefinition.getPrismContext();
}
@Nullable
@Override
public Class<?> getCompileTimeClass() {
return originalObjectClassDefinition.getCompileTimeClass(); // most probably null
}
@Nullable
@Override
public QName getExtensionForType() {
return originalObjectClassDefinition.getExtensionForType(); // most probably null
}
@Override
public boolean isContainerMarker() {
return originalObjectClassDefinition.isContainerMarker(); // most probably false
}
@Override
public boolean isObjectMarker() {
return originalObjectClassDefinition.isObjectMarker(); // most probably false
}
@Override
public boolean isXsdAnyMarker() {
return originalObjectClassDefinition.isXsdAnyMarker();
}
// TODO
@Override
public <ID extends ItemDefinition> ID findItemDefinition(@NotNull ItemPath path, @NotNull Class<ID> clazz) {
if (path.size() != 1) {
return null;
}
QName first = ItemPath.getFirstName(path);
if (first == null) {
return null;
}
return findItemDefinition(first, clazz);
}
// TODO
@Override
public <ID extends ItemDefinition> ID findNamedItemDefinition(@NotNull QName firstName, @NotNull ItemPath rest,
@NotNull Class<ID> clazz) {
return findItemDefinition(firstName);
}
@Nullable
@Override
public String getDefaultNamespace() {
return originalObjectClassDefinition.getDefaultNamespace();
}
@Override
public boolean isRuntimeSchema() {
return originalObjectClassDefinition.isRuntimeSchema();
}
@NotNull
@Override
public List<String> getIgnoredNamespaces() {
return originalObjectClassDefinition.getIgnoredNamespaces();
}
@Nullable
@Override
public QName getSuperType() {
return originalObjectClassDefinition.getSuperType();
}
@Override
public void merge(ComplexTypeDefinition otherComplexTypeDef) {
throw new UnsupportedOperationException("TODO implement this");
}
@Override
public void revive(PrismContext prismContext) {
originalObjectClassDefinition.revive(prismContext);
// TODO revive attributes
}
@Override
public boolean isIgnored() {
return originalObjectClassDefinition.isIgnored();
}
@Override
public boolean isAbstract() {
return originalObjectClassDefinition.isAbstract();
}
@Override
public boolean isEmpty() {
return attributeDefinitions.isEmpty() && associationDefinitions.isEmpty();
}
@Override
public boolean isDeprecated() {
return originalObjectClassDefinition.isDeprecated();
}
@Override
public boolean isEmphasized() {
return originalObjectClassDefinition.isEmphasized();
}
@Override
public Integer getDisplayOrder() {
return originalObjectClassDefinition.getDisplayOrder();
}
@Override
public String getHelp() {
return originalObjectClassDefinition.getHelp();
}
@Override
public String getDocumentation() {
return originalObjectClassDefinition.getDocumentation();
}
@Override
public String getDocumentationPreview() {
return originalObjectClassDefinition.getDocumentationPreview();
}
@Override
public Class getTypeClassIfKnown() {
return originalObjectClassDefinition.getTypeClassIfKnown();
}
@Override
public Class getTypeClass() {
return originalObjectClassDefinition.getTypeClass();
}
@Override
public ResourceAttributeContainer instantiate(QName elementName) {
return ObjectClassComplexTypeDefinitionImpl.instantiate(elementName, this);
}
@Override
public boolean isListMarker() {
return originalObjectClassDefinition.isListMarker();
}
//endregion
//region ==== Parsing =================================================================================
static RefinedObjectClassDefinition parse(ResourceObjectTypeDefinitionType entTypeDefType,
ResourceType resourceType, RefinedResourceSchema rSchema, ShadowKindType impliedKind, PrismContext prismContext,
String contextDescription) throws SchemaException {
ShadowKindType kind = entTypeDefType.getKind();
if (kind == null) {
kind = impliedKind;
}
if (kind == null) {
kind = ShadowKindType.ACCOUNT;
}
String intent = entTypeDefType.getIntent();
if (intent == null) {
intent = SchemaConstants.INTENT_DEFAULT;
}
RefinedObjectClassDefinition rObjectClassDef = parseRefinedObjectClass(entTypeDefType,
resourceType, rSchema, prismContext, kind, intent, kind.value(), kind.value() + " type definition '"+intent+"' in " + contextDescription);
if (entTypeDefType.getPagedSearches() != null) {
LOGGER.warn("PagedSearches element is no more supported and is ignored. Use PagedSearchCapabilityType instead. In {}", resourceType);
}
return rObjectClassDef;
}
private static void parseProtected(RefinedObjectClassDefinition rAccountDef, ResourceObjectTypeDefinitionType accountTypeDefType) throws SchemaException {
for (ResourceObjectPatternType protectedType: accountTypeDefType.getProtected()) {
ResourceObjectPattern protectedPattern = convertToPattern(protectedType, rAccountDef);
rAccountDef.getProtectedObjectPatterns().add(protectedPattern);
}
}
private static ResourceObjectPattern convertToPattern(ResourceObjectPatternType patternType, RefinedObjectClassDefinition rAccountDef) throws SchemaException {
ResourceObjectPattern resourceObjectPattern = new ResourceObjectPattern(rAccountDef);
SearchFilterType filterType = patternType.getFilter();
if (filterType != null) {
ObjectFilter filter = QueryConvertor.parseFilter(filterType, rAccountDef.getObjectDefinition());
resourceObjectPattern.addFilter(filter);
return resourceObjectPattern;
}
// Deprecated
if (patternType.getName() != null) {
RefinedAttributeDefinition attributeDefinition = rAccountDef.findAttributeDefinition(new QName(SchemaConstants.NS_ICF_SCHEMA,"name"));
if (attributeDefinition == null) {
throw new SchemaException("No ICF NAME attribute in schema as specified in the definition of protected objects (this is deprecated syntax anyway, convert it to filter)");
}
ResourceAttribute<String> attr = attributeDefinition.instantiate();
attr.setRealValue(patternType.getName());
resourceObjectPattern.addIdentifier(attr);
} else if (patternType.getUid() != null) {
RefinedAttributeDefinition attributeDefinition = rAccountDef.findAttributeDefinition(new QName(SchemaConstants.NS_ICF_SCHEMA,"uid"));
if (attributeDefinition == null) {
throw new SchemaException("No ICF UID attribute in schema as specified in the definition of protected objects (this is deprecated syntax anyway, convert it to filter)");
}
ResourceAttribute<String> attr = attributeDefinition.instantiate();
attr.setRealValue(patternType.getUid());
resourceObjectPattern.addIdentifier(attr);
} else {
throw new SchemaException("No filter and no deprecated name/uid in resource object pattern");
}
return resourceObjectPattern;
}
public static RefinedObjectClassDefinition parseFromSchema(ObjectClassComplexTypeDefinition objectClassDef, ResourceType resourceType,
RefinedResourceSchema rSchema,
PrismContext prismContext, String contextDescription) throws SchemaException {
RefinedObjectClassDefinitionImpl rOcDef = new RefinedObjectClassDefinitionImpl(resourceType.getOid(), objectClassDef);
String intent = objectClassDef.getIntent();
if (intent == null && objectClassDef.isDefaultInAKind()) {
intent = SchemaConstants.INTENT_DEFAULT;
}
rOcDef.setIntent(intent);
if (objectClassDef.getDisplayName() != null) {
rOcDef.setDisplayName(objectClassDef.getDisplayName());
}
rOcDef.setDefault(objectClassDef.isDefaultInAKind());
for (ResourceAttributeDefinition attrDef : objectClassDef.getAttributeDefinitions()) {
String attrContextDescription = intent + ", in " + contextDescription;
RefinedAttributeDefinition rAttrDef = RefinedAttributeDefinitionImpl.parse(attrDef, null, objectClassDef, prismContext,
attrContextDescription);
rOcDef.processIdentifiers(rAttrDef, objectClassDef);
if (rOcDef.containsAttributeDefinition(rAttrDef.getName())) {
throw new SchemaException("Duplicate definition of attribute " + rAttrDef.getName() + " in " + attrContextDescription);
}
rOcDef.add(rAttrDef);
}
return rOcDef;
}
private static RefinedObjectClassDefinition parseRefinedObjectClass(ResourceObjectTypeDefinitionType schemaHandlingObjDefType,
ResourceType resourceType, RefinedResourceSchema rSchema, PrismContext prismContext,
@NotNull ShadowKindType kind, @NotNull String intent, String typeDesc, String contextDescription) throws SchemaException {
ObjectClassComplexTypeDefinition objectClassDef;
if (schemaHandlingObjDefType.getObjectClass() != null) {
QName objectClass = schemaHandlingObjDefType.getObjectClass();
objectClassDef = rSchema.getOriginalResourceSchema().findObjectClassDefinition(objectClass);
if (objectClassDef == null) {
throw new SchemaException("Object class " + objectClass + " as specified in "+typeDesc+" type " + schemaHandlingObjDefType.getIntent() + " was not found in the resource schema of " + contextDescription);
}
} else {
throw new SchemaException("Definition of "+typeDesc+" type " + schemaHandlingObjDefType.getIntent() + " does not have objectclass, in " + contextDescription);
}
RefinedObjectClassDefinitionImpl rOcDef = new RefinedObjectClassDefinitionImpl(resourceType.getOid(), objectClassDef);
rOcDef.setKind(kind);
rOcDef.setIntent(intent);
// clone here to disassociate this definition from the resource. So this definition can be serialized without the need to serialize
// entire resource. If we do not clone then the resource will be present here through parent in the schemaHandlingObjDefType
rOcDef.schemaHandlingObjectTypeDefinitionType = schemaHandlingObjDefType.clone();
if (rOcDef.schemaHandlingObjectTypeDefinitionType.getDisplayName() != null) {
rOcDef.setDisplayName(rOcDef.schemaHandlingObjectTypeDefinitionType.getDisplayName());
} else {
if (objectClassDef.getDisplayName() != null) {
rOcDef.setDisplayName(objectClassDef.getDisplayName());
}
}
if (rOcDef.schemaHandlingObjectTypeDefinitionType.getDescription() != null) {
rOcDef.setDescription(rOcDef.schemaHandlingObjectTypeDefinitionType.getDescription());
}
if (rOcDef.schemaHandlingObjectTypeDefinitionType.isDefault() != null) {
rOcDef.setDefault(rOcDef.schemaHandlingObjectTypeDefinitionType.isDefault());
} else {
rOcDef.setDefault(objectClassDef.isDefaultInAKind());
}
if (rOcDef.schemaHandlingObjectTypeDefinitionType.getBaseContext() != null) {
rOcDef.setBaseContext(rOcDef.schemaHandlingObjectTypeDefinitionType.getBaseContext());
}
return rOcDef;
}
void parseAssociations(RefinedResourceSchema rSchema) throws SchemaException {
if (schemaHandlingObjectTypeDefinitionType == null) {
return;
}
for (ResourceObjectAssociationType resourceObjectAssociationType: schemaHandlingObjectTypeDefinitionType.getAssociation()) {
RefinedAssociationDefinition rAssocDef = new RefinedAssociationDefinition(resourceObjectAssociationType);
ShadowKindType assocKind = rAssocDef.getKind();
RefinedObjectClassDefinition assocTarget = rSchema.getRefinedDefinition(assocKind, rAssocDef.getIntents());
rAssocDef.setAssociationTarget(assocTarget);
associationDefinitions.add(rAssocDef);
}
}
void parseAuxiliaryObjectClasses(RefinedResourceSchema rSchema) throws SchemaException {
if (schemaHandlingObjectTypeDefinitionType == null) {
return;
}
List<QName> auxiliaryObjectClassQNames = schemaHandlingObjectTypeDefinitionType.getAuxiliaryObjectClass();
for (QName auxiliaryObjectClassQName: auxiliaryObjectClassQNames) {
RefinedObjectClassDefinition auxiliaryObjectClassDef = rSchema.getRefinedDefinition(auxiliaryObjectClassQName);
if (auxiliaryObjectClassDef == null) {
throw new SchemaException("Auxiliary object class "+auxiliaryObjectClassQName+" specified in "+this+" does not exist");
}
auxiliaryObjectClassDefinitions.add(auxiliaryObjectClassDef);
}
}
void parseAttributes(RefinedResourceSchema rSchema, String contextDescription) throws SchemaException {
if (schemaHandlingObjectTypeDefinitionType == null) {
// this is definition from schema. We already have all we need.
return;
}
parseAttributesFrom(rSchema, getObjectClassDefinition(), false, contextDescription);
for (RefinedObjectClassDefinition auxiliaryObjectClassDefinition: auxiliaryObjectClassDefinitions) {
parseAttributesFrom(rSchema, auxiliaryObjectClassDefinition, true, contextDescription);
}
// Check for extra attribute definitions in the account type
for (ResourceAttributeDefinitionType attrDefType : schemaHandlingObjectTypeDefinitionType.getAttribute()) {
if (!containsAttributeDefinition(attrDefType.getRef()) && !RefinedAttributeDefinitionImpl.isIgnored(attrDefType)) {
throw new SchemaException("Definition of attribute " + attrDefType.getRef() + " not found in object class " + originalObjectClassDefinition
.getTypeName() + " as defined in " + contextDescription);
}
}
parseProtected(this, schemaHandlingObjectTypeDefinitionType);
}
private void parseAttributesFrom(RefinedResourceSchema rSchema, ObjectClassComplexTypeDefinition ocDef, boolean auxiliary,
String contextDescription) throws SchemaException {
if (schemaHandlingObjectTypeDefinitionType == null) {
// this is definition from schema. We already have all we need.
return;
}
for (ResourceAttributeDefinition road : ocDef.getAttributeDefinitions()) {
String attrContextDescription = road.getName() + ", in " + contextDescription;
ResourceAttributeDefinitionType attrDefType = findAttributeDefinitionType(road.getName(), schemaHandlingObjectTypeDefinitionType,
attrContextDescription);
// We MUST NOT skip ignored attribute definitions here. We must include them in the schema as
// the shadows will still have that attributes and we will need their type definition to work
// well with them. They may also be mandatory. We cannot pretend that they do not exist.
// TODO !!!! fix the cast
RefinedAttributeDefinition<?> rAttrDef = (RefinedAttributeDefinition<?>) RefinedAttributeDefinitionImpl.parse(road, attrDefType, ocDef,
rSchema.getPrismContext(), "in "+kind+" type " + intent + ", in " + contextDescription);
if (!auxiliary) {
processIdentifiers(rAttrDef, ocDef);
}
if (containsAttributeDefinition(rAttrDef.getName())) {
if (auxiliary) {