-
Notifications
You must be signed in to change notification settings - Fork 188
/
ModelExecuteOptions.java
560 lines (464 loc) · 19.6 KB
/
ModelExecuteOptions.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
/*
* Copyright (c) 2010-2017 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.model.api;
import static org.apache.commons.lang3.BooleanUtils.isTrue;
import static com.evolveum.midpoint.xml.ns._public.common.common_3.ModelExecuteOptionsType.*;
import java.io.Serializable;
import java.util.List;
import org.jetbrains.annotations.NotNull;
import com.evolveum.midpoint.prism.Item;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.path.ItemName;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.schema.AbstractOptions;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
/**
* Options for execution of Model operations. These options influence the way how the operations are executed.
* The options are not mandatory. All options have reasonable default values. They may not be specified at all.
*
* @author semancik
*/
@SuppressWarnings("UnusedReturnValue")
public class ModelExecuteOptions extends AbstractOptions implements Serializable, Cloneable {
/**
* Majority of the content is present also in ModelExecuteOptionsType.
* So let's reuse the schema instead of duplicating it.
*/
@NotNull private final ModelExecuteOptionsType content;
/**
* Is this operation already authorized, i.e. should it be executed without any further authorization checks?
* EXPERIMENTAL. Currently supported only for raw executions.
*/
private Boolean preAuthorized;
/**
* Processes all assignment relations on recompute. Used for computing all assignments.
* TEMPORARY. EXPERIMENTAL. Should be replaced by something more generic (e.g. setting optimization level).
* Therefore we do not currently put this to XML version of the options.
*/
private Boolean evaluateAllAssignmentRelationsOnRecompute;
/**
* Traces the model operation execution.
* EXPERIMENTAL. (So not put into XML version of the options yet.)
*/
private TracingProfileType tracingProfile;
public ModelExecuteOptions(PrismContext prismContext) {
content = new ModelExecuteOptionsType(prismContext);
}
private ModelExecuteOptions(@NotNull ModelExecuteOptionsType content) {
this.content = content;
}
private ModelExecuteOptions() {
this((PrismContext) null);
}
public static ModelExecuteOptions create(PrismContext prismContext) {
return new ModelExecuteOptions(prismContext);
}
public static ModelExecuteOptions create(ModelExecuteOptions original, PrismContext prismContext) {
return original != null ? original.clone() : new ModelExecuteOptions(prismContext);
}
public static boolean is(ModelExecuteOptions options, ItemName itemName) {
return is(options, itemName, false);
}
public static boolean is(ModelExecuteOptions options, ItemName itemName, boolean defaultValue) {
if (options == null) {
return defaultValue;
}
Boolean value = (Boolean) options.content.asPrismContainerValue().getPropertyRealValue(itemName, Boolean.class);
return value != null ? value : defaultValue;
}
//region Extension processing
@SuppressWarnings("WeakerAccess")
public <T> T getExtensionItemRealValue(ItemName name, Class<T> clazz) {
Item<?, ?> item = content.asPrismContainerValue().findItem(ItemPath.create(F_EXTENSION, name));
return item != null ? item.getRealValue(clazz) : null;
}
public static <T> T getExtensionItemRealValue(ModelExecuteOptions options, ItemName name, Class<T> clazz) {
return options != null ? options.getExtensionItemRealValue(name, clazz) : null;
}
public ModelExecuteOptions setExtensionPropertyRealValues(PrismContext prismContext, ItemName propertyName, Object... values)
throws SchemaException {
ObjectTypeUtil.setExtensionPropertyRealValues(prismContext, content.asPrismContainerValue(), propertyName, values);
return this;
}
//endregion
//region Specific methods
public Boolean getForce() {
return content.isForce();
}
public ModelExecuteOptions force(Boolean force) {
content.setForce(force);
return this;
}
public ModelExecuteOptions force() {
return force(true);
}
public static boolean isForce(ModelExecuteOptions options) {
return is(options, ModelExecuteOptionsType.F_FORCE);
}
public Boolean getPushChanges() {
return content.isPushChanges();
}
public static boolean isPushChanges(ModelExecuteOptions options) {
return is(options, F_PUSH_CHANGES);
}
public ModelExecuteOptions pushChanges(Boolean value) {
content.setPushChanges(value);
return this;
}
public ModelExecuteOptions pushChanges() {
return pushChanges(true);
}
public Boolean getRaw() {
return content.isRaw();
}
public ModelExecuteOptions raw(Boolean raw) {
content.setRaw(raw);
return this;
}
public ModelExecuteOptions raw() {
return raw(true);
}
public static boolean isRaw(ModelExecuteOptions options) {
return is(options, ModelExecuteOptionsType.F_RAW);
}
@Deprecated // kept because of (expected) external uses; use create(prismContext).raw() instead
public static ModelExecuteOptions createRaw() {
ModelExecuteOptions opts = new ModelExecuteOptions();
opts.raw(true);
return opts;
}
public Boolean getNoCrypt() {
return content.isNoCrypt();
}
public ModelExecuteOptions noCrypt(Boolean noCrypt) {
content.setNoCrypt(noCrypt);
return this;
}
public static boolean isNoCrypt(ModelExecuteOptions options) {
return is(options, F_NO_CRYPT);
}
public Boolean getReconcile() {
return content.isReconcile();
}
public ModelExecuteOptions reconcile(Boolean reconcile) {
content.setReconcile(reconcile);
return this;
}
public ModelExecuteOptions reconcile() {
return reconcile(true);
}
public static boolean isReconcile(ModelExecuteOptions options) {
return is(options, ModelExecuteOptionsType.F_RECONCILE);
}
@Deprecated // kept because of (expected) external uses; use create(prismContext).reconcile() instead
public static ModelExecuteOptions createReconcile() {
ModelExecuteOptions opts = new ModelExecuteOptions();
opts.reconcile(true);
return opts;
}
public ModelExecuteOptions reconcileFocus(Boolean reconcileFocus) {
content.setReconcileFocus(reconcileFocus);
return this;
}
public ModelExecuteOptions reconcileFocus() {
return reconcileFocus(true);
}
public static boolean isReconcileFocus(ModelExecuteOptions options) {
return is(options, ModelExecuteOptionsType.F_RECONCILE_FOCUS);
}
public Boolean getOverwrite() {
return content.isOverwrite();
}
public ModelExecuteOptions overwrite(Boolean overwrite) {
content.setOverwrite(overwrite);
return this;
}
public ModelExecuteOptions overwrite() {
return overwrite(true);
}
public static boolean isOverwrite(ModelExecuteOptions options) {
return is(options, F_OVERWRITE);
}
// Intentionally using "set" to avoid confusion with asking on "isImport"
@SuppressWarnings("WeakerAccess")
public ModelExecuteOptions setIsImport(Boolean isImport) {
content.setIsImport(isImport);
return this;
}
// Intentionally using "set" to avoid confusion with asking on "isImport"
public ModelExecuteOptions setIsImport() {
setIsImport(true);
return this;
}
public static boolean isIsImport(ModelExecuteOptions options) {
return is(options, F_IS_IMPORT);
}
public ModelExecuteOptions executeImmediatelyAfterApproval(Boolean executeImmediatelyAfterApproval) {
content.setExecuteImmediatelyAfterApproval(executeImmediatelyAfterApproval);
return this;
}
public ModelExecuteOptions executeImmediatelyAfterApproval() {
return executeImmediatelyAfterApproval(true);
}
public static boolean isExecuteImmediatelyAfterApproval(ModelExecuteOptions options) {
return is(options, F_EXECUTE_IMMEDIATELY_AFTER_APPROVAL);
}
public Boolean getLimitPropagation() {
return content.isLimitPropagation();
}
public ModelExecuteOptions limitPropagation(Boolean limitPropagation) {
content.setLimitPropagation(limitPropagation);
return this;
}
public static boolean isLimitPropagation(ModelExecuteOptions options) {
return is(options, F_LIMIT_PROPAGATION);
}
public ModelExecuteOptions reevaluateSearchFilters(Boolean reevaluateSearchFilters) {
content.setReevaluateSearchFilters(reevaluateSearchFilters);
return this;
}
public static boolean isReevaluateSearchFilters(ModelExecuteOptions options) {
return is(options, F_REEVALUATE_SEARCH_FILTERS);
}
@SuppressWarnings("WeakerAccess")
public void preAuthorized(Boolean value) {
this.preAuthorized = value;
}
public ModelExecuteOptions preAuthorized() {
preAuthorized(true);
return this;
}
public static boolean isPreAuthorized(ModelExecuteOptions options) {
return options != null && options.preAuthorized != null && options.preAuthorized;
}
@SuppressWarnings("WeakerAccess")
public OperationBusinessContextType getRequestBusinessContext() {
return content.getRequestBusinessContext();
}
public ModelExecuteOptions requestBusinessContext(OperationBusinessContextType requestBusinessContext) {
content.setRequestBusinessContext(requestBusinessContext);
return this;
}
public static OperationBusinessContextType getRequestBusinessContext(ModelExecuteOptions options) {
if (options == null) {
return null;
}
return options.getRequestBusinessContext();
}
public PartialProcessingOptionsType getPartialProcessing() {
return content.getPartialProcessing();
}
public ModelExecuteOptions partialProcessing(PartialProcessingOptionsType partialProcessing) {
content.setPartialProcessing(partialProcessing);
return this;
}
public static PartialProcessingOptionsType getPartialProcessing(ModelExecuteOptions options) {
if (options == null) {
return null;
}
return options.getPartialProcessing();
}
public PartialProcessingOptionsType getInitialPartialProcessing() {
return content.getInitialPartialProcessing();
}
public ModelExecuteOptions initialPartialProcessing(PartialProcessingOptionsType initialPartialProcessing) {
content.setInitialPartialProcessing(initialPartialProcessing);
return this;
}
public static PartialProcessingOptionsType getInitialPartialProcessing(ModelExecuteOptions options) {
if (options == null) {
return null;
}
return options.getInitialPartialProcessing();
}
@SuppressWarnings("WeakerAccess")
public ConflictResolutionType getFocusConflictResolution() {
return content.getFocusConflictResolution();
}
public ModelExecuteOptions focusConflictResolution(ConflictResolutionType focusConflictResolution) {
content.setFocusConflictResolution(focusConflictResolution);
return this;
}
public static ConflictResolutionType getFocusConflictResolution(ModelExecuteOptions options) {
if (options == null) {
return null;
}
return options.getFocusConflictResolution();
}
@SuppressWarnings("WeakerAccess")
public ModelExecuteOptions evaluateAllAssignmentRelationsOnRecompute(Boolean evaluateAllAssignmentRelationsOnRecompute) {
this.evaluateAllAssignmentRelationsOnRecompute = evaluateAllAssignmentRelationsOnRecompute;
return this;
}
public ModelExecuteOptions evaluateAllAssignmentRelationsOnRecompute() {
return evaluateAllAssignmentRelationsOnRecompute(true);
}
public static boolean isEvaluateAllAssignmentRelationsOnRecompute(ModelExecuteOptions options) {
return options != null && isTrue(options.evaluateAllAssignmentRelationsOnRecompute);
}
public TracingProfileType getTracingProfile() {
return tracingProfile;
}
public ModelExecuteOptions tracingProfile(TracingProfileType tracingProfile) {
this.tracingProfile = tracingProfile;
return this;
}
public static TracingProfileType getTracingProfile(ModelExecuteOptions options) {
return options != null ? options.tracingProfile : null;
}
// TEMPORARY
public ModelExecuteOptions reconcileAffected(Boolean value) {
content.setReconcileAffected(value);
return this;
}
public static boolean isReconcileAffected(ModelExecuteOptions options) {
return is(options, F_RECONCILE_AFFECTED);
}
//endregion
public ModelExecuteOptionsType toModelExecutionOptionsType() {
return clone().content; // cloning for safety reasons
}
public static ModelExecuteOptions fromModelExecutionOptionsType(ModelExecuteOptionsType bean) {
return bean != null ? new ModelExecuteOptions(bean.clone()) : null;
}
public static ModelExecuteOptions fromRestOptions(List<String> options, PrismContext prismContext) {
if (options == null || options.isEmpty()) {
return null;
}
ModelExecuteOptions retVal = new ModelExecuteOptions(prismContext);
for (String option : options){
if (ModelExecuteOptionsType.F_RAW.getLocalPart().equals(option)) {
retVal.raw(true);
}
if (ModelExecuteOptionsType.F_EXECUTE_IMMEDIATELY_AFTER_APPROVAL.getLocalPart().equals(option)) {
retVal.executeImmediatelyAfterApproval(true);
}
if (ModelExecuteOptionsType.F_FORCE.getLocalPart().equals(option)) {
retVal.force(true);
}
if (F_PUSH_CHANGES.getLocalPart().equals(option)) {
retVal.pushChanges(true);
}
if (F_NO_CRYPT.getLocalPart().equals(option)) {
retVal.noCrypt(true);
}
if (F_OVERWRITE.getLocalPart().equals(option)) {
retVal.overwrite(true);
}
if (ModelExecuteOptionsType.F_RECONCILE.getLocalPart().equals(option)) {
retVal.reconcile(true);
}
if (ModelExecuteOptionsType.F_IS_IMPORT.getLocalPart().equals(option)) {
retVal.setIsImport(true);
}
if (ModelExecuteOptionsType.F_LIMIT_PROPAGATION.getLocalPart().equals(option)) {
retVal.limitPropagation(true);
}
if (ModelExecuteOptionsType.F_REEVALUATE_SEARCH_FILTERS.getLocalPart().equals(option)) {
retVal.reevaluateSearchFilters(true);
}
// preAuthorized is purposefully omitted (security reasons)
}
return retVal;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder("ModelExecuteOptions(");
appendFlag(sb, "executeImmediatelyAfterApproval", content.isExecuteImmediatelyAfterApproval());
appendFlag(sb, "force", content.isForce());
appendFlag(sb, "isImport", content.isIsImport());
appendFlag(sb, "limitPropagation", content.isLimitPropagation());
appendFlag(sb, "noCrypt", content.isNoCrypt());
appendFlag(sb, "overwrite", content.isOverwrite());
appendFlag(sb, "preAuthorized", preAuthorized);
appendFlag(sb, "raw", content.isRaw());
appendFlag(sb, "reconcile", content.isReconcile());
appendFlag(sb, "reconcileFocus", content.isReconcileFocus());
appendFlag(sb, "reevaluateSearchFilters", content.isReevaluateSearchFilters());
appendFlag(sb, "requestBusinessContext", content.getRequestBusinessContext() == null ? null : true);
appendVal(sb, "partialProcessing", format(content.getPartialProcessing()));
appendVal(sb, "initialPartialProcessing", format(content.getInitialPartialProcessing()));
appendVal(sb, "focusConflictResolution", content.getFocusConflictResolution());
appendVal(sb, "tracingProfile", tracingProfile);
removeLastComma(sb);
sb.append(")");
return sb.toString();
}
private Object format(PartialProcessingOptionsType pp) {
if (pp == null) {
return null;
}
StringBuilder sb = new StringBuilder();
sb.append("(");
appendPpFlag(sb, pp.getLoad(), "L");
appendPpFlag(sb, pp.getFocus(), "F");
appendPpFlag(sb, pp.getInbound(), "I");
appendPpFlag(sb, pp.getFocusActivation(), "FA");
appendPpFlag(sb, pp.getObjectTemplateBeforeAssignments(), "OTBA");
appendPpFlag(sb, pp.getAssignments(), "A");
appendPpFlag(sb, pp.getAssignmentsOrg(), "AORG");
appendPpFlag(sb, pp.getAssignmentsMembershipAndDelegate(), "AM&D");
appendPpFlag(sb, pp.getAssignmentsConflicts(), "AC");
appendPpFlag(sb, pp.getObjectTemplateAfterAssignments(), "OTAA");
appendPpFlag(sb, pp.getFocusCredentials(), "FC");
appendPpFlag(sb, pp.getFocusPolicyRules(), "FPR");
appendPpFlag(sb, pp.getProjection(), "P");
appendPpFlag(sb, pp.getOutbound(), "O");
appendPpFlag(sb, pp.getProjectionValues(), "PV");
appendPpFlag(sb, pp.getProjectionCredentials(), "PC");
appendPpFlag(sb, pp.getProjectionReconciliation(), "PR");
appendPpFlag(sb, pp.getProjectionLifecycle(), "PL");
appendPpFlag(sb, pp.getApprovals(), "APP");
appendPpFlag(sb, pp.getExecution(), "E");
appendPpFlag(sb, pp.getNotification(), "N");
removeLastComma(sb);
sb.append(")");
return sb.toString();
}
private void appendPpFlag(StringBuilder sb, PartialProcessingTypeType option, String label) {
if (option == null) {
return;
}
String value;
switch (option) {
case AUTOMATIC: return;
case PROCESS: value = "+"; break;
case SKIP: value = "-"; break;
default: throw new AssertionError();
}
sb.append(label).append(value).append(",");
}
@SuppressWarnings("MethodDoesntCallSuperMethod")
public ModelExecuteOptions clone() {
ModelExecuteOptions clone = new ModelExecuteOptions(content.clone());
clone.preAuthorized = this.preAuthorized;
clone.evaluateAllAssignmentRelationsOnRecompute = this.evaluateAllAssignmentRelationsOnRecompute;
clone.tracingProfile = this.tracingProfile;
return clone;
}
public boolean notEmpty() {
// hack but quite effective
return !toString().equals(new ModelExecuteOptions().toString());
}
public PartialProcessingOptionsType getOrCreatePartialProcessing() {
if (content.getPartialProcessing() == null) {
content.setPartialProcessing(new PartialProcessingOptionsType());
}
return content.getPartialProcessing();
}
public static GetOperationOptions toGetOperationOptions(ModelExecuteOptions modelOptions) {
if (modelOptions == null) {
return null;
}
GetOperationOptions getOptions = new GetOperationOptions();
getOptions.setRaw(modelOptions.getRaw());
return getOptions;
}
}