Skip to content

Commit be9c2c8

Browse files
committed
Return deltas computed by inbound processing
**What** Instead of applying the computed delta to the target object directly in the `AbstractInboundsProcessing` class, move this responsibility to the caller of inbound processing implementations. **Why** Main reason is, that I want to use inbound processing implementation in the mappings simulation activity. But in there, I need the deltas, not the target object with them already applied, because I need to write those deltas to the simulation result. Other option would be to diff the object with applied deltas with the original object. But that is a waste of resources. There is also other reason. The `executeToDeltas` method, originally computed the deltas, but it also applied them to the target object. But that is quite counter-intuitive. Considering the method name, I would expect it will just compute and return the deltas. By moving the application of the deltas outside, we also gain more flexibility, because the way how deltas are applied does not need to be defined by the implementations. That means, the deltas produced by one implementation, can be used in different ways, depending on the requirements of the caller. **Task**: 10992
1 parent b207d1d commit be9c2c8

File tree

4 files changed

+13
-23
lines changed

4 files changed

+13
-23
lines changed

model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/lens/projector/focus/InboundProcessor.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
package com.evolveum.midpoint.model.impl.lens.projector.focus;
88

9+
import java.util.Collection;
910
import javax.xml.datatype.XMLGregorianCalendar;
1011

1112
import org.springframework.beans.factory.annotation.Autowired;
@@ -19,6 +20,7 @@
1920
import com.evolveum.midpoint.model.impl.lens.projector.loader.ContextLoader;
2021
import com.evolveum.midpoint.model.impl.lens.projector.util.ProcessorExecution;
2122
import com.evolveum.midpoint.model.impl.lens.projector.util.ProcessorMethod;
23+
import com.evolveum.midpoint.prism.delta.ItemDelta;
2224
import com.evolveum.midpoint.prism.delta.ObjectDelta;
2325
import com.evolveum.midpoint.schema.result.OperationResult;
2426
import com.evolveum.midpoint.task.api.Task;
@@ -51,8 +53,8 @@ <F extends FocusType> void processInbounds(
5153

5254
var env = new MappingEvaluationEnvironment(activityDescription, now, task);
5355

54-
new FullInboundsProcessing<>(context, env)
55-
.executeToDeltas(result);
56+
final Collection<ItemDelta<?, ?>> deltas = new FullInboundsProcessing<>(context, env).executeToDeltas(result);
57+
context.getFocusContextRequired().swallowToSecondaryDelta(deltas);
5658

5759
context.checkConsistenceIfNeeded();
5860
medic.traceContext(LOGGER, activityDescription, "inbound", false, context, false);

model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/lens/projector/focus/inbounds/AbstractInboundsProcessing.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ abstract class AbstractInboundsProcessing<T extends Containerable> {
8181
this.env = env;
8282
}
8383

84-
/** Full processing, resulting in deltas being applied (to focus context or target object). */
85-
public void executeToDeltas(OperationResult result)
84+
/** Full processing, resulting in deltas being computed. */
85+
public Collection<ItemDelta<?, ?>> executeToDeltas(OperationResult result)
8686
throws SchemaException, ObjectNotFoundException, SecurityViolationException,
8787
CommunicationException, ConfigurationException, ExpressionEvaluationException {
8888
executeToTriples(result);
89-
consolidateTriples(result);
89+
return consolidateTriples(result);
9090
}
9191

9292
/** Partial processing that stops after triples are computed, i.e. just prepares and evaluates the mappings. */
@@ -180,7 +180,7 @@ private <V extends PrismValue, D extends ItemDefinition<?>> void mergeMappingOut
180180
}
181181
}
182182

183-
private void consolidateTriples(OperationResult result)
183+
private Collection<ItemDelta<?, ?>> consolidateTriples(OperationResult result)
184184
throws CommunicationException, ObjectNotFoundException, ConfigurationException, SchemaException,
185185
SecurityViolationException, ExpressionEvaluationException {
186186

@@ -203,7 +203,7 @@ private void consolidateTriples(OperationResult result)
203203
result);
204204
consolidation.computeItemDeltas();
205205

206-
applyComputedDeltas(consolidation.getItemDeltas());
206+
return consolidation.getItemDeltas();
207207
}
208208

209209
@NotNull private ItemDefinition<?> getItemDefinition(@NotNull ItemPath itemPath) {
@@ -229,8 +229,6 @@ private boolean rangeIsCompletelyDefined(ItemPath itemPath) {
229229

230230
abstract @Nullable LensContext<?> getLensContextIfPresent();
231231

232-
abstract void applyComputedDeltas(Collection<? extends ItemDelta<?,?>> itemDeltas) throws SchemaException;
233-
234232
public @NotNull DeltaSetTripleIvwoMap getOutputTripleMap() {
235233
return outputTripleMap;
236234
}

model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/lens/projector/focus/inbounds/FullInboundsProcessing.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,6 @@ Function<ItemPath, Boolean> getFocusPrimaryItemDeltaExistsProvider() {
217217
}
218218
}
219219

220-
@Override
221-
void applyComputedDeltas(Collection<? extends ItemDelta<?, ?>> itemDeltas) throws SchemaException {
222-
lensContext.getFocusContextRequired().swallowToSecondaryDelta(itemDeltas);
223-
}
224-
225220
@Override
226221
@Nullable LensContext<?> getLensContextIfPresent() {
227222
return lensContext;

model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/lens/projector/focus/inbounds/SingleShadowInboundsProcessing.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class SingleShadowInboundsProcessing<T extends Containerable> extends Abs
5555

5656
@NotNull private final SingleShadowInboundsProcessingContext<T> ctx;
5757

58-
private SingleShadowInboundsProcessing(
58+
public SingleShadowInboundsProcessing(
5959
@NotNull SingleShadowInboundsProcessingContext<T> ctx,
6060
@NotNull MappingEvaluationEnvironment env) {
6161
super(env);
@@ -70,8 +70,10 @@ public static <C extends Containerable> C evaluate(SingleShadowInboundsProcessin
7070
.build();
7171
try {
7272

73-
new SingleShadowInboundsProcessing<>(ctx, createEnv(ctx))
73+
final Collection<ItemDelta<?, ?>> deltas = new SingleShadowInboundsProcessing<>(ctx, createEnv(ctx))
7474
.executeToDeltas(result);
75+
LOGGER.trace("Applying deltas to the pre-focus:\n{}", DebugUtil.debugDumpLazily(deltas, 1));
76+
ItemDeltaCollectionsUtil.applyTo(deltas, ctx.getPreFocusAsPcv());
7577

7678
var focus = ctx.getPreFocus();
7779
LOGGER.debug("Focus:\n{}", focus.debugDumpLazily(1));
@@ -189,13 +191,6 @@ private ObjectTemplateType getObjectTemplate(OperationResult result)
189191
}
190192
}
191193

192-
@Override
193-
void applyComputedDeltas(Collection<? extends ItemDelta<?, ?>> itemDeltas) throws SchemaException {
194-
LOGGER.trace("Applying deltas to the pre-focus:\n{}", DebugUtil.debugDumpLazily(itemDeltas, 1));
195-
ItemDeltaCollectionsUtil.applyTo(
196-
itemDeltas, ctx.getPreFocusAsPcv());
197-
}
198-
199194
@Override
200195
@NotNull
201196
Function<ItemPath, Boolean> getFocusPrimaryItemDeltaExistsProvider() {

0 commit comments

Comments
 (0)