Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Mar 7, 2023
2 parents 455a510 + 61d0aa0 commit efc0a20
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public boolean isFullyPersistent() {
return persistenceMode == FULL;
}

public boolean isShadowLevelPersistent() {
public boolean isPersistentAtShadowLevelButNotFully() {
return persistenceMode == SHADOWS;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1094,4 +1094,10 @@ public static boolean isNonAttributeResourceModification(QName firstPathName) {
|| QNameUtil.match(firstPathName, ShadowType.F_ASSOCIATION)
|| QNameUtil.match(firstPathName, ShadowType.F_AUXILIARY_OBJECT_CLASS);
}

public static @Nullable SynchronizationSituationDescriptionType getLastSyncSituationDescription(@NotNull ShadowType shadow) {
return shadow.getSynchronizationSituationDescription().stream()
.max(Comparator.comparing(desc -> XmlTypeConverter.toMillis(desc.getTimestamp())))
.orElse(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ public static int getObjectsDeleted(@NotNull SimulationResultType simulationResu
.intValue();
}

public static int getObjectsUnchanged(@NotNull SimulationResultType simulationResult) {
return getObjectsProcessed(simulationResult)
- getObjectsAdded(simulationResult)
- getObjectsModified(simulationResult)
- getObjectsDeleted(simulationResult);
}

public static int getObjectsProcessed(@NotNull SimulationResultType simulationResult) {
// Any of the built-in would be OK.
SimulationMetricValuesType mv = getMetricValuesBean(simulationResult, SimulationMetricReference.BuiltIn.ADDED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private <AH extends AssignmentHolderType> LocalizableMessage createShortMessage(
QName relation = ctx.evaluatedAssignment.getNormalizedRelation();
LocalizableMessage builtInMessage;

if (relation == null || relation == prismContext.getDefaultRelation()) {
if (prismContext.isDefaultRelation(relation)) {
builtInMessage = new LocalizableMessageBuilder()
.key(SchemaConstants.DEFAULT_POLICY_CONSTRAINT_SHORT_MESSAGE_KEY_PREFIX + CONSTRAINT_KEY_PREFIX + keyPostfix)
.arg(ObjectTypeUtil.createDisplayInformation(ctx.evaluatedAssignment.getTarget(), false))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ ShadowUpdater updateAllSyncMetadataRespectingMode() throws SchemaException {

XMLGregorianCalendar now = beans.clock.currentTimeXMLGregorianCalendar();

if (syncCtx.isExecutionFullyPersistent()) {
if (syncCtx.areShadowChangesPersistent()) {
updateSyncSituation();
updateSyncSituationDescription(now);
updateBasicSyncTimestamp(now); // this is questionable, but the same behavior is in LinkUpdater class
Expand Down Expand Up @@ -153,24 +153,18 @@ private ShadowUpdater updateCoordinates(boolean overwriteUnknownValues) throws S
if (updateType) {
// Before 4.6, the kind was updated unconditionally, only intent was driven by "force intent change" flag.
// This is now changed to treat kind+intent as a single data item.
if (ctxKind != shadowKind) {
deltas.add(
PrismContext.get().deltaFor(ShadowType.class)
.item(ShadowType.F_KIND).replace(ctxKind)
.asItemDelta());
}
if (!ctxIntent.equals(shadowIntent)) {
deltas.add(
PrismContext.get().deltaFor(ShadowType.class)
.item(ShadowType.F_INTENT).replace(ctxIntent)
.asItemDelta());
}
deltas.addAll(
PrismContext.get().deltaFor(ShadowType.class)
.optimizing()
.item(ShadowType.F_KIND).old(shadowKind).replace(ctxKind)
.item(ShadowType.F_INTENT).old(shadowIntent).replace(ctxIntent)
.asItemDeltas());
}

if (StringUtils.isNotBlank(ctxTag) && !ctxTag.equals(shadowTag)) {
deltas.add(
PrismContext.get().deltaFor(ShadowType.class)
.item(ShadowType.F_TAG).replace(ctxTag)
.item(ShadowType.F_TAG).old(shadowTag).replace(ctxTag)
.asItemDelta());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -481,13 +481,13 @@ public boolean isDryRun() {
return executionMode == ExecutionModeType.DRY_RUN;
}

// TEMPORARY
boolean shouldExecuteSynchronizationActions() {
boolean isNotDryRunLikeMode() {
return !isDryRun() && !task.areShadowChangesSimulated();
}

boolean isFullMode() {
return executionMode == ExecutionModeType.FULL;
return executionMode == ExecutionModeType.FULL
&& task.isExecutionFullyPersistent();
}

public @NotNull ResourceObjectShadowChangeDescription getChange() {
Expand All @@ -512,6 +512,11 @@ boolean isExecutionFullyPersistent() {
return task.isExecutionFullyPersistent();
}

/** I.e. we are either in full persistence or at least in shadow persistence mode. */
boolean areShadowChangesPersistent() {
return !task.areShadowChangesSimulated();
}

public boolean isVisible() {
return SimulationUtil.isVisible(resource, resourceObjectDefinition, task.getExecutionMode());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ public void notifyChange(
}
// FIXME: Somewhere here we should validate preFocus



SynchronizationContext.Complete<?> completeCtx = (SynchronizationContext.Complete<?>) syncCtx;
setupLinkedOwnerAndSituation(completeCtx, change, result);

Expand All @@ -107,11 +105,12 @@ public void notifyChange(
.commit(result);

boolean synchronizationFailure;
if (completeCtx.shouldExecuteSynchronizationActions()) {
if (completeCtx.isNotDryRunLikeMode()) {
synchronizationFailure =
new SynchronizationActionExecutor<>(completeCtx)
.react(result);
// Note that exceptions from action execution are not propagated here.
// Note that standard exceptions from action execution are not re-thrown to here; in such cases,
// the processing continues normally here, with synchronizationFailure set to true.
} else {
synchronizationFailure = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public void test100CreateUser() throws Exception {
.assertObjectsAdded(1)
.assertObjectsModified(0)
.assertObjectsDeleted(0)
.assertObjectsUnchanged(0)
.assertObjectsProcessed(1)
.getObjectable();

Expand Down Expand Up @@ -755,7 +756,8 @@ private void assertTest20xShadow(String name, Task task, OperationResult result)
.assertKind(ShadowKindType.ACCOUNT)
.assertIntent("default")
.assertIsExists()
.assertSynchronizationSituation(null);
.assertSynchronizationSituation(SynchronizationSituationType.UNMATCHED)
.assertSynchronizationSituationDescriptionUpdatedButNotFull();
}

@SuppressWarnings("SameParameterValue")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ public SimulationResultAsserter<RA> assertObjectsDeleted(int expected) {
return this;
}

public SimulationResultAsserter<RA> assertObjectsUnchanged(int expected) {
assertThat(SimulationResultTypeUtil.getObjectsUnchanged(simulationResult))
.as("objects unchanged")
.isEqualTo(expected);
return this;
}

public SimulationResultAsserter<RA> assertObjectsProcessed(int expected) {
assertThat(SimulationResultTypeUtil.getObjectsProcessed(simulationResult))
.as("objects deleted")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ public String execute(OperationResult result) throws CommonException, IOExceptio
private @NotNull ExecutionModeType getBackgroundTaskExecutionMode() {
if (taskExecutionMode.isFullyPersistent()) {
return ExecutionModeType.FULL;
} else if (taskExecutionMode.isShadowLevelPersistent()) {
} else if (taskExecutionMode.isPersistentAtShadowLevelButNotFully()) {
return ExecutionModeType.PREVIEW;
} else if (taskExecutionMode.areShadowChangesSimulated()) {
} else if (taskExecutionMode.isNothingPersistent()) {
return ExecutionModeType.SHADOW_MANAGEMENT_PREVIEW;
} else {
throw new AssertionError(taskExecutionMode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ private LocalizableMessage createDefaultProcessName(ModelInvocationContext<?> ct

QName relation = assignment.getNormalizedRelation();

if (relation == null) {
if (prismContext.isDefaultRelation(relation)) {
return new LocalizableMessageBuilder()
.key(SchemaConstants.DEFAULT_POLICY_CONSTRAINT_SHORT_MESSAGE_KEY_PREFIX + "assignmentModification.toBe" + operationKey)
.arg(ObjectTypeUtil.createDisplayInformation(target, false))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,26 @@ public ShadowAsserter<RA> assertSynchronizationSituation(SynchronizationSituatio
return this;
}

public ShadowAsserter<RA> assertSynchronizationSituationDescriptionUpdatedButNotFull() {
return assertSynchronizationSituationDescriptionUpdated(false);
}

private ShadowAsserter<RA> assertSynchronizationSituationDescriptionUpdated(boolean full) {
ShadowType shadow = getObjectable();
SynchronizationSituationDescriptionType desc = ShadowUtil.getLastSyncSituationDescription(shadow);
assertThat(desc).as("synchronization situation description").isNotNull();
assertThat(desc.getSituation())
.withFailMessage("situation in description differs from the one in shadow")
.isEqualTo(shadow.getSynchronizationSituation());
assertThat(desc.getTimestamp())
.withFailMessage("timestamp in description differs from the one in shadow")
.isEqualTo(full ? shadow.getFullSynchronizationTimestamp() : shadow.getSynchronizationTimestamp());
assertThat(desc.isFull())
.as("'full' flag in situation description")
.isEqualTo(full);
return this;
}

public ShadowAsserter<RA> assertAdministrativeStatus(ActivationStatusType expected) {
ActivationType activation = getActivation();
if (activation == null) {
Expand Down

0 comments on commit efc0a20

Please sign in to comment.