/
LayerRefinedObjectClassDefinitionImpl.java
630 lines (522 loc) · 18.8 KB
/
LayerRefinedObjectClassDefinitionImpl.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
/*
* 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 java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.xml.namespace.QName;
import com.evolveum.midpoint.common.ResourceObjectPattern;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.schema.ResourceShadowDiscriminator;
import com.evolveum.midpoint.schema.processor.*;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
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.PagedSearchCapabilityType;
import com.evolveum.prism.xml.ns._public.types_3.ItemPathType;
import org.jetbrains.annotations.NotNull;
/**
* @author semancik
* @author mederly
*
* Work in-progress.
*
*/
public class LayerRefinedObjectClassDefinitionImpl implements LayerRefinedObjectClassDefinition {
private static final long serialVersionUID = 1L;
private RefinedObjectClassDefinition refinedObjectClassDefinition;
private LayerType layer;
/**
* Keeps layer-specific information on resource object attributes.
* This list is lazily evaluated.
*/
private List<LayerRefinedAttributeDefinition<?>> layerRefinedAttributeDefinitions;
private LayerRefinedObjectClassDefinitionImpl(RefinedObjectClassDefinition refinedAccountDefinition, LayerType layer) {
this.refinedObjectClassDefinition = refinedAccountDefinition;
this.layer = layer;
}
static LayerRefinedObjectClassDefinition wrap(RefinedObjectClassDefinition rOCD, LayerType layer) {
if (rOCD == null) {
return null;
}
return new LayerRefinedObjectClassDefinitionImpl(rOCD, layer);
}
static List<? extends LayerRefinedObjectClassDefinition> wrapCollection(Collection<? extends RefinedObjectClassDefinition> rOCDs, LayerType layer) {
return(rOCDs.stream()
.map(rAccountDef -> wrap(rAccountDef, layer))
.collect(Collectors.toCollection(() -> new ArrayList<>(rOCDs.size()))));
}
@Override
public LayerType getLayer() {
return layer;
}
@NotNull
@Override
public QName getTypeName() {
return refinedObjectClassDefinition.getTypeName();
}
@Override
public boolean isIgnored() {
return refinedObjectClassDefinition.isIgnored();
}
public boolean isEmphasized() {
return refinedObjectClassDefinition.isEmphasized();
}
@Override
public <X> LayerRefinedAttributeDefinition<X> getDescriptionAttribute() {
// TODO optimize
return substituteLayerRefinedAttributeDefinition(refinedObjectClassDefinition.getDescriptionAttribute());
}
@Override
@NotNull
public List<String> getIgnoredNamespaces() {
return refinedObjectClassDefinition.getIgnoredNamespaces();
}
private <X> LayerRefinedAttributeDefinition<X> substituteLayerRefinedAttributeDefinition(ResourceAttributeDefinition<?> attributeDef) {
return findAttributeDefinition(attributeDef.getName());
}
private Collection<LayerRefinedAttributeDefinition<?>> substituteLayerRefinedAttributeDefinitionCollection(Collection<? extends RefinedAttributeDefinition<?>> attributes) {
return attributes.stream()
.map(this::substituteLayerRefinedAttributeDefinition)
.collect(Collectors.toList());
}
@Override
public <X> LayerRefinedAttributeDefinition<X> getNamingAttribute() {
return substituteLayerRefinedAttributeDefinition(refinedObjectClassDefinition.getNamingAttribute());
}
@Override
public String getNativeObjectClass() {
return refinedObjectClassDefinition.getNativeObjectClass();
}
@Override
public boolean isAuxiliary() {
return refinedObjectClassDefinition.isAuxiliary();
}
@Override
public Integer getDisplayOrder() {
return refinedObjectClassDefinition.getDisplayOrder();
}
// TODO - doesn't return layered definition (should it?)
@Override
public <ID extends ItemDefinition> ID findItemDefinition(@NotNull ItemPath path,
@NotNull Class<ID> clazz) {
return refinedObjectClassDefinition.findItemDefinition(path, clazz);
}
// TODO - doesn't return layered definition (should it?)
@Override
public <ID extends ItemDefinition> ID findNamedItemDefinition(@NotNull QName firstName, @NotNull ItemPath rest,
@NotNull Class<ID> clazz) {
return refinedObjectClassDefinition.findNamedItemDefinition(firstName, rest, clazz);
}
@Override
public boolean isDefaultInAKind() {
return refinedObjectClassDefinition.isDefaultInAKind();
}
@Override
public ShadowKindType getKind() {
return refinedObjectClassDefinition.getKind();
}
@Override
public AttributeFetchStrategyType getPasswordFetchStrategy() {
return refinedObjectClassDefinition.getPasswordFetchStrategy();
}
@Override
public String getIntent() {
return refinedObjectClassDefinition.getIntent();
}
@Override
public LayerRefinedObjectClassDefinition forLayer(@NotNull LayerType layerType) {
return refinedObjectClassDefinition.forLayer(layerType);
}
@Override
public <X> LayerRefinedAttributeDefinition<X> getDisplayNameAttribute() {
return substituteLayerRefinedAttributeDefinition(refinedObjectClassDefinition.getDisplayNameAttribute());
}
@Override
public String getHelp() {
return refinedObjectClassDefinition.getHelp();
}
@NotNull
@Override
public Collection<? extends LayerRefinedAttributeDefinition<?>> getPrimaryIdentifiers() {
return substituteLayerRefinedAttributeDefinitionCollection(refinedObjectClassDefinition.getPrimaryIdentifiers());
}
@Override
public Collection<? extends LayerRefinedAttributeDefinition<?>> getAllIdentifiers() {
return substituteLayerRefinedAttributeDefinitionCollection(refinedObjectClassDefinition.getAllIdentifiers());
}
@NotNull
@Override
public Collection<? extends LayerRefinedAttributeDefinition<?>> getSecondaryIdentifiers() {
return LayerRefinedAttributeDefinitionImpl.wrapCollection(refinedObjectClassDefinition.getSecondaryIdentifiers(), layer);
}
@Override
public Class getTypeClass() {
return refinedObjectClassDefinition.getTypeClass();
}
@Override
public Collection<ResourceObjectPattern> getProtectedObjectPatterns() {
return refinedObjectClassDefinition.getProtectedObjectPatterns();
}
@Override
public void merge(ComplexTypeDefinition otherComplexTypeDef) {
refinedObjectClassDefinition.merge(otherComplexTypeDef);
}
@Override
public PrismContext getPrismContext() {
return refinedObjectClassDefinition.getPrismContext();
}
@Override
public ResourceAttributeContainer instantiate(QName name) {
return ObjectClassComplexTypeDefinitionImpl.instantiate(name, this);
}
// @Override
// public <T> PrismPropertyDefinition<T> findPropertyDefinition(@NotNull QName name) {
// LayerRefinedAttributeDefinition<T> def = findAttributeDefinition(name);
// if (def != null) {
// return def;
// } else {
// return LayerRefinedAttributeDefinitionImpl.wrap((RefinedAttributeDefinition<T>) refinedObjectClassDefinition.findPropertyDefinition(name), layer);
// }
// }
@Override
public <X> LayerRefinedAttributeDefinition<X> findAttributeDefinition(@NotNull QName elementQName) {
for (LayerRefinedAttributeDefinition definition : getAttributeDefinitions()) {
if (QNameUtil.match(definition.getName(), elementQName)) {
return definition;
}
}
return null;
}
@Override
public LayerRefinedAttributeDefinition<?> findAttributeDefinition(String elementLocalname) {
return LayerRefinedAttributeDefinitionImpl.wrap(refinedObjectClassDefinition.findAttributeDefinition(elementLocalname), layer);
}
@Override
public String getDisplayName() {
return refinedObjectClassDefinition.getDisplayName();
}
@NotNull
@Override
public List<? extends ItemDefinition> getDefinitions() {
return getAttributeDefinitions();
}
@Override
public String getDescription() {
return refinedObjectClassDefinition.getDescription();
}
@Override
public boolean isDefault() {
return refinedObjectClassDefinition.isDefault();
}
@Override
public ObjectClassComplexTypeDefinition getObjectClassDefinition() {
return refinedObjectClassDefinition.getObjectClassDefinition();
}
@NotNull
@Override
public List<? extends LayerRefinedAttributeDefinition<?>> getAttributeDefinitions() {
if (layerRefinedAttributeDefinitions == null) {
layerRefinedAttributeDefinitions = LayerRefinedAttributeDefinitionImpl.wrapCollection(refinedObjectClassDefinition.getAttributeDefinitions(), layer);
}
return layerRefinedAttributeDefinitions;
}
@Override
public boolean containsAttributeDefinition(ItemPathType pathType) {
return refinedObjectClassDefinition.containsAttributeDefinition(pathType);
}
@Override
public String getResourceOid() {
return refinedObjectClassDefinition.getResourceOid();
}
@Override
public PrismObjectDefinition<ShadowType> getObjectDefinition() {
return refinedObjectClassDefinition.getObjectDefinition();
}
@Override
public boolean containsAttributeDefinition(QName attributeName) {
return refinedObjectClassDefinition.containsAttributeDefinition(attributeName);
}
@Override
public boolean isEmpty() {
return refinedObjectClassDefinition.isEmpty();
}
@Override
public PrismObject<ShadowType> createBlankShadow(RefinedObjectClassDefinition definition) {
return refinedObjectClassDefinition.createBlankShadow(definition);
}
@Override
public ResourceShadowDiscriminator getShadowDiscriminator() {
return refinedObjectClassDefinition.getShadowDiscriminator();
}
@Override
public Collection<? extends QName> getNamesOfAttributesWithOutboundExpressions() {
return refinedObjectClassDefinition.getNamesOfAttributesWithOutboundExpressions();
}
@Override
public Collection<? extends QName> getNamesOfAttributesWithInboundExpressions() {
return refinedObjectClassDefinition.getNamesOfAttributesWithInboundExpressions();
}
@Override
public List<MappingType> getPasswordInbound() {
return refinedObjectClassDefinition.getPasswordInbound();
}
@Override
public List<MappingType> getPasswordOutbound() {
return refinedObjectClassDefinition.getPasswordOutbound();
}
@Override
public ObjectReferenceType getPasswordPolicy() {
return refinedObjectClassDefinition.getPasswordPolicy();
}
@Override
public ResourcePasswordDefinitionType getPasswordDefinition() {
return refinedObjectClassDefinition.getPasswordDefinition();
}
@Override
public Class<?> getCompileTimeClass() {
return refinedObjectClassDefinition.getCompileTimeClass();
}
@Override
public QName getExtensionForType() {
return refinedObjectClassDefinition.getExtensionForType();
}
@Override
public boolean isContainerMarker() {
return refinedObjectClassDefinition.isContainerMarker();
}
@Override
public boolean isPrimaryIdentifier(QName attrName) {
return refinedObjectClassDefinition.isPrimaryIdentifier(attrName);
}
@Override
public boolean isObjectMarker() {
return refinedObjectClassDefinition.isObjectMarker();
}
@Override
public boolean isXsdAnyMarker() {
return refinedObjectClassDefinition.isXsdAnyMarker();
}
@Override
public boolean isListMarker() {
return refinedObjectClassDefinition.isListMarker();
}
@Override
public QName getSuperType() {
return refinedObjectClassDefinition.getSuperType();
}
@Override
public boolean isSecondaryIdentifier(QName attrName) {
return refinedObjectClassDefinition.isSecondaryIdentifier(attrName);
}
@Override
public boolean isRuntimeSchema() {
return refinedObjectClassDefinition.isRuntimeSchema();
}
@NotNull
@Override
public Collection<RefinedAssociationDefinition> getAssociationDefinitions() {
return refinedObjectClassDefinition.getAssociationDefinitions();
}
@Override
public Collection<RefinedAssociationDefinition> getAssociationDefinitions(ShadowKindType kind) {
return refinedObjectClassDefinition.getAssociationDefinitions(kind);
}
@Override
public Collection<QName> getNamesOfAssociations() {
return refinedObjectClassDefinition.getNamesOfAssociations();
}
@Override
public ResourceActivationDefinitionType getActivationSchemaHandling() {
return refinedObjectClassDefinition.getActivationSchemaHandling();
}
@Override
public ResourceBidirectionalMappingType getActivationBidirectionalMappingType(QName propertyName) {
return refinedObjectClassDefinition.getActivationBidirectionalMappingType(propertyName);
}
@Override
public AttributeFetchStrategyType getActivationFetchStrategy(QName propertyName) {
return refinedObjectClassDefinition.getActivationFetchStrategy(propertyName);
}
@Override
public <T extends CapabilityType> T getEffectiveCapability(Class<T> capabilityClass, ResourceType resourceType) {
return (T) refinedObjectClassDefinition.getEffectiveCapability(capabilityClass, resourceType);
}
@Override
public PagedSearchCapabilityType getPagedSearches(ResourceType resourceType) {
return refinedObjectClassDefinition.getPagedSearches(resourceType);
}
@Override
public boolean isPagedSearchEnabled(ResourceType resourceType) {
return refinedObjectClassDefinition.isPagedSearchEnabled(resourceType);
}
@Override
public boolean isObjectCountingEnabled(ResourceType resourceType) {
return refinedObjectClassDefinition.isObjectCountingEnabled(resourceType);
}
@Override
public boolean isAbstract() {
return refinedObjectClassDefinition.isAbstract();
}
@Override
public boolean isDeprecated() {
return refinedObjectClassDefinition.isDeprecated();
}
@Override
public String getDocumentation() {
return refinedObjectClassDefinition.getDocumentation();
}
@Override
public String getDocumentationPreview() {
return refinedObjectClassDefinition.getDocumentationPreview();
}
@Override
public RefinedAssociationDefinition findAssociationDefinition(QName name) {
return refinedObjectClassDefinition.findAssociationDefinition(name);
}
@Override
public <ID extends ItemDefinition> ID findItemDefinition(@NotNull QName name, @NotNull Class<ID> clazz,
boolean caseInsensitive) {
ID def = refinedObjectClassDefinition.findItemDefinition(name, clazz, caseInsensitive);
return (ID) LayerRefinedAttributeDefinitionImpl.wrap((RefinedAttributeDefinition) def, layer);
}
@Override
public Collection<? extends QName> getNamesOfAssociationsWithOutboundExpressions() {
return refinedObjectClassDefinition.getNamesOfAssociationsWithOutboundExpressions();
}
@Override
public boolean matches(ShadowType shadowType) {
return refinedObjectClassDefinition.matches(shadowType);
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((layer == null) ? 0 : layer.hashCode());
result = prime * result + ((refinedObjectClassDefinition == null) ? 0 : refinedObjectClassDefinition.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
// if (!super.equals(obj))
// return false;
if (getClass() != obj.getClass())
return false;
LayerRefinedObjectClassDefinitionImpl other = (LayerRefinedObjectClassDefinitionImpl) obj;
if (layer != other.layer)
return false;
if (refinedObjectClassDefinition == null) {
if (other.refinedObjectClassDefinition != null)
return false;
} else if (!refinedObjectClassDefinition.equals(other.refinedObjectClassDefinition))
return false;
return true;
}
@Override
public String debugDump() {
return debugDump(0);
}
@Override
public String getDefaultNamespace() {
return refinedObjectClassDefinition.getDefaultNamespace();
}
@Override
public String debugDump(int indent) {
return RefinedObjectClassDefinitionImpl.debugDump(indent, layer, this);
}
// Do NOT override&delegate debugDump(int indent, LayerType layer) here.
// We want to use code in the context of this class so things like
// getDebugDumpClassName() will be correct.
/**
* Return a human readable name of this class suitable for logs.
*/
public String getDebugDumpClassName() {
return "LRObjectClassDef";
}
@Override
public String getHumanReadableName() {
return refinedObjectClassDefinition.getHumanReadableName();
}
@NotNull
@Override
public LayerRefinedObjectClassDefinition clone() {
return wrap(refinedObjectClassDefinition.clone(), this.layer);
}
@NotNull
@Override
public RefinedObjectClassDefinition deepClone(Map<QName, ComplexTypeDefinition> ctdMap) {
return new LayerRefinedObjectClassDefinitionImpl(refinedObjectClassDefinition.deepClone(ctdMap), layer);
}
@Override
public ResourceObjectReferenceType getBaseContext() {
return refinedObjectClassDefinition.getBaseContext();
}
@Override
public ResourceObjectVolatilityType getVolatility() {
return refinedObjectClassDefinition.getVolatility();
}
@Override
public Class getTypeClassIfKnown() {
return refinedObjectClassDefinition.getTypeClassIfKnown();
}
@NotNull
@Override
public Collection<RefinedObjectClassDefinition> getAuxiliaryObjectClassDefinitions() {
return refinedObjectClassDefinition.getAuxiliaryObjectClassDefinitions();
}
@Override
public boolean hasAuxiliaryObjectClass(QName expectedObjectClassName) {
return refinedObjectClassDefinition.hasAuxiliaryObjectClass(expectedObjectClassName);
}
@Override
public boolean isTolerantAuxiliaryObjectClasses() {
return refinedObjectClassDefinition.isTolerantAuxiliaryObjectClasses();
}
@Override
public ObjectQuery createShadowSearchQuery(String resourceOid) throws SchemaException {
return refinedObjectClassDefinition.createShadowSearchQuery(resourceOid);
}
@Override
public void revive(PrismContext prismContext) {
refinedObjectClassDefinition.revive(prismContext);
}
@Override
public String toString() {
return "LROCDef("+layer+": "
+ refinedObjectClassDefinition + ")";
}
@Override
public void trimTo(@NotNull Collection<ItemPath> paths) {
if (refinedObjectClassDefinition != null) {
refinedObjectClassDefinition.trimTo(paths);
}
}
@Override
public boolean isShared() {
if (refinedObjectClassDefinition != null) {
return refinedObjectClassDefinition.isShared();
} else {
return true; // ok?
}
}
}