Skip to content

Commit

Permalink
Link related "processed objects" in simulations
Browse files Browse the repository at this point in the history
Added "identifier", [is] "focus", "focusRecordId", and
"projections" [count] to SimulationResultProcessedObjectType.

No repo support yet. To be discussed.
  • Loading branch information
mederly committed Jan 27, 2023
1 parent 882996c commit 9311c65
Show file tree
Hide file tree
Showing 21 changed files with 379 additions and 202 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,17 @@
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="identifier" type="xsd:string" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Identifier of this "processed object" record.

EXPERIMENTAL
TODO Should it be generated by the repository? Probably so.
TODO Should it be named "identifier" or "recordId" or ... ?
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="transactionId" type="xsd:string" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Expand Down Expand Up @@ -968,6 +979,27 @@
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="focus" type="xsd:boolean" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Is this the focus?
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="focusRecordId" type="xsd:string" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
For projection-related records, this field denotes the focus record ID to which this projection belongs.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="projectionRecords" type="xsd:int" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
How many owned projection records are there? Set only for focus records.
</xsd:documentation>
</xsd:annotation>
</xsd:element>

<!-- Extra stored state; may be reduced -->
<xsd:element name="before" type="tns:ObjectType">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

import org.jetbrains.annotations.NotNull;

import com.evolveum.midpoint.task.api.SimulationProcessedObjectListener;
import com.evolveum.midpoint.task.api.SimulationDataConsumer;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SimulationResultType;

public interface SimulationResultContext {

@NotNull SimulationProcessedObjectListener getSimulationProcessedObjectListener(@NotNull String transactionId);
@NotNull SimulationDataConsumer getSimulationDataConsumer(@NotNull String transactionId);

/** OID of the {@link SimulationResultType} object. */
@NotNull String getResultOid();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import java.util.Set;
import java.util.stream.Collectors;

import com.evolveum.midpoint.model.impl.simulation.SimulationDataImpl;

import com.google.common.collect.Sets;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -168,7 +170,7 @@ <F extends ObjectType> HookOperationMode runWithConflictDetection(LensContext<F>
}
} finally {
operationExecutionRecorder.recordOperationExecutions(context, task, result);
beans.clockworkAuditHelper.submitSimulationDeltas(context, task, result);
task.acceptSimulationData(SimulationDataImpl.with(context), result);
clockworkConflictResolver.unregisterConflictWatcher(context);
exitCaches();
context.reportProgress(new ProgressInformation(CLOCKWORK, EXITING));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.evolveum.midpoint.audit.api.AuditEventStage;
import com.evolveum.midpoint.audit.api.AuditEventType;
import com.evolveum.midpoint.model.common.util.AuditHelper;
import com.evolveum.midpoint.model.impl.simulation.ProcessedObjectImpl;
import com.evolveum.midpoint.model.impl.util.ModelImplUtils;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismObject;
Expand All @@ -35,7 +34,6 @@
import com.evolveum.midpoint.schema.constants.ExpressionConstants;
import com.evolveum.midpoint.schema.expression.VariablesMap;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.SimulationProcessedObject;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.exception.*;
import com.evolveum.midpoint.util.logging.LoggingUtils;
Expand Down Expand Up @@ -359,51 +357,4 @@ private void addRecordMessage(AuditEventRecord auditRecord, String message) {
}
auditRecord.setMessage(sb.toString());
}

/**
* Passes the simulation deltas to the appropriate listener.
*
* The code is here because of the similarity with auditing.
*
* Temporary code.
*/
<F extends ObjectType> void submitSimulationDeltas(LensContext<F> context, Task task, OperationResult result) {
if (task.isPersistentExecution()) {
return;
}

LensFocusContext<F> focusContext = context.getFocusContext();
if (focusContext != null) {
submitElementSimulationDelta(focusContext, task, result);
}
// We ignore duplicates stemming from higher-order contexts for now
for (LensProjectionContext projectionContext : context.getProjectionContexts()) {
submitElementSimulationDelta(projectionContext, task, result);
}
}

/**
* Submits the information about the (summary) change computed.
*
* Limitations:
*
* - We ignore the fact that sometimes we don't have full shadow loaded. The deltas applied to "shadow-only" state
* may be misleading.
*/
private <E extends ObjectType> void submitElementSimulationDelta(
LensElementContext<E> elementContext, Task task, OperationResult result) {
if (task.hasSimulationProcessedObjectListener()) {
try {
SimulationProcessedObject processedObject = ProcessedObjectImpl.create(elementContext, task, result);
if (processedObject != null) {
task.onObjectProcessedBySimulation(processedObject, task, result);
}
} catch (CommonException e) {
// TODO do we need more precise error reporting here?
// Or should we conceal some of these exceptions? (Probably not.)
throw new SystemException(
"Couldn't process or store the simulation object processing record: " + e.getMessage(), e);
}
}
}
}

0 comments on commit 9311c65

Please sign in to comment.