use of com.evolveum.midpoint.schema.ObjectTreeDeltas in project midpoint by Evolveum.
the class WfPrepareRootOperationTaskHandler method run.
//endregion
//region run method
@Override
public TaskRunResult run(Task task) {
TaskRunResultStatus status = TaskRunResultStatus.FINISHED;
try {
OperationResult result = task.getResult();
WfTask rootWfTask = wfTaskController.recreateRootWfTask(task);
List<WfTask> children = rootWfTask.listChildren(result);
LensContext rootContext = (LensContext) rootWfTask.retrieveModelContext(result);
boolean changed = false;
for (WfTask child : children) {
if (child.getTaskExecutionStatus() != TaskExecutionStatus.CLOSED) {
throw new IllegalStateException("Child task " + child + " is not in CLOSED state; its state is " + child.getTaskExecutionStatus());
}
if (child.hasModelContext()) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Child job {} has model context present - skipping fetching deltas from it.", child);
}
} else {
ObjectTreeDeltas deltas = child.retrieveResultingDeltas();
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Child job {} returned {} deltas", child, deltas != null ? deltas.getDeltaList().size() : 0);
}
if (deltas != null) {
LensFocusContext focusContext = rootContext.getFocusContext();
ObjectDelta focusDelta = deltas.getFocusChange();
if (focusDelta != null) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Adding delta from job {} to root model context; delta = {}", child, focusDelta.debugDump(0));
}
if (focusContext.getPrimaryDelta() != null && !focusContext.getPrimaryDelta().isEmpty()) {
focusContext.addPrimaryDelta(focusDelta);
} else {
focusContext.setPrimaryDelta(focusDelta);
}
changed = true;
}
Set<Map.Entry<ResourceShadowDiscriminator, ObjectDelta<ShadowType>>> entries = deltas.getProjectionChangeMapEntries();
for (Map.Entry<ResourceShadowDiscriminator, ObjectDelta<ShadowType>> entry : entries) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Adding projection delta from job {} to root model context; rsd = {}, delta = {}", child, entry.getKey(), entry.getValue().debugDump());
}
ModelProjectionContext projectionContext = rootContext.findProjectionContext(entry.getKey());
if (projectionContext == null) {
// TODO more liberal treatment?
throw new IllegalStateException("No projection context for " + entry.getKey());
}
if (projectionContext.getPrimaryDelta() != null && !projectionContext.getPrimaryDelta().isEmpty()) {
projectionContext.addPrimaryDelta(entry.getValue());
} else {
projectionContext.setPrimaryDelta(entry.getValue());
}
changed = true;
}
}
}
}
if (!rootContext.hasAnyPrimaryChange()) {
// deletes the model context
rootContext = null;
// regardless of whether rootContext was changed or not
changed = true;
}
if (changed) {
rootWfTask.storeModelContext(rootContext);
rootWfTask.commitChanges(result);
}
} catch (SchemaException | ObjectNotFoundException | ObjectAlreadyExistsException | ConfigurationException | ExpressionEvaluationException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't aggregate resulting deltas from child workflow-monitoring tasks due to schema exception", e);
status = TaskRunResultStatus.PERMANENT_ERROR;
} catch (CommunicationException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't aggregate resulting deltas from child workflow-monitoring tasks", e);
status = TaskRunResultStatus.TEMPORARY_ERROR;
}
TaskRunResult runResult = new TaskRunResult();
runResult.setRunResultStatus(status);
return runResult;
}
use of com.evolveum.midpoint.schema.ObjectTreeDeltas in project midpoint by Evolveum.
the class PrimaryChangeProcessor method processModelInvocation.
//endregion
//region Processing model invocation
// =================================================================================== Processing model invocation
@Override
public HookOperationMode processModelInvocation(@NotNull ModelContext<?> context, WfConfigurationType wfConfigurationType, @NotNull Task taskFromModel, @NotNull OperationResult result) throws SchemaException, ObjectNotFoundException {
if (context.getState() != PRIMARY || context.getFocusContext() == null) {
return null;
}
PrimaryChangeProcessorConfigurationType processorConfigurationType = wfConfigurationType != null ? wfConfigurationType.getPrimaryChangeProcessor() : null;
if (processorConfigurationType != null && Boolean.FALSE.equals(processorConfigurationType.isEnabled())) {
LOGGER.debug("Primary change processor is disabled.");
return null;
}
ObjectTreeDeltas objectTreeDeltas = baseModelInvocationProcessingHelper.extractTreeDeltasFromModelContext(context);
if (objectTreeDeltas.isEmpty()) {
return null;
}
// examine the request using process aspects
ObjectTreeDeltas changesBeingDecomposed = objectTreeDeltas.clone();
ModelInvocationContext ctx = new ModelInvocationContext(getPrismContext(), context, wfConfigurationType, taskFromModel);
List<PcpChildWfTaskCreationInstruction> childTaskInstructions = gatherStartInstructions(changesBeingDecomposed, ctx, result);
if (childTaskInstructions.isEmpty()) {
LOGGER.trace("There are no workflow processes to be started, exiting.");
return null;
}
return submitTasks(childTaskInstructions, context, changesBeingDecomposed, taskFromModel, wfConfigurationType, result);
}
use of com.evolveum.midpoint.schema.ObjectTreeDeltas in project midpoint by Evolveum.
the class WfPrepareChildOperationTaskHandler method run.
//endregion
//region Body
@SuppressWarnings("unchecked")
@Override
public TaskRunResult run(Task task) {
TaskRunResult.TaskRunResultStatus status = TaskRunResult.TaskRunResultStatus.FINISHED;
LOGGER.trace("WfPrepareChildOperationTaskHandler starting... task = {}", task);
try {
WfTask wfTask = wfTaskController.recreateWfTask(task);
OperationResult result = task.getResult();
ModelContext<?> modelContext = wfTask.retrieveModelContext(result);
if (modelContext == null) {
throw new IllegalStateException("There's no model context in child task; task = " + task);
}
// prepare deltaOut to be used
ObjectTreeDeltas deltasOut = wfTask.retrieveResultingDeltas();
if (LOGGER.isTraceEnabled()) {
dumpDeltaOut(deltasOut);
}
if (deltasOut == null || deltasOut.isEmpty()) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("There's no primary delta in focus context; we'll delete model operation context. Task = {}, model context:\n{}", task, modelContext.debugDump());
}
wfTask.deleteModelOperationContext();
} else {
// place deltaOut into model context
modelContext.getFocusContext().setPrimaryDelta(deltasOut.getFocusChange());
Set<Map.Entry<ResourceShadowDiscriminator, ObjectDelta<ShadowType>>> entries = deltasOut.getProjectionChangeMapEntries();
for (Map.Entry<ResourceShadowDiscriminator, ObjectDelta<ShadowType>> entry : entries) {
// TODO what if projection context does not exist?
modelContext.findProjectionContext(entry.getKey()).setPrimaryDelta(entry.getValue());
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Resulting model context to be stored into task {}:\n{}", task, modelContext.debugDump(0));
}
wfTask.storeModelContext(modelContext);
}
task.savePendingModifications(result);
} catch (SchemaException | ObjectNotFoundException | ObjectAlreadyExistsException | ConfigurationException | ExpressionEvaluationException | RuntimeException | Error e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't prepare child model context", e);
status = TaskRunResult.TaskRunResultStatus.PERMANENT_ERROR;
} catch (CommunicationException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't prepare child model context", e);
status = TaskRunResult.TaskRunResultStatus.TEMPORARY_ERROR;
}
TaskRunResult runResult = new TaskRunResult();
runResult.setRunResultStatus(status);
return runResult;
}
use of com.evolveum.midpoint.schema.ObjectTreeDeltas in project midpoint by Evolveum.
the class AddAssociationAspect method prepareJobCreateInstructions.
private List<PcpChildWfTaskCreationInstruction> prepareJobCreateInstructions(ModelContext<?> modelContext, Task taskFromModel, OperationResult result, List<ApprovalRequest<AssociationAdditionType>> approvalRequestList) throws SchemaException, ObjectNotFoundException {
List<PcpChildWfTaskCreationInstruction> instructions = new ArrayList<>();
String assigneeName = MiscDataUtil.getFocusObjectName(modelContext);
String assigneeOid = MiscDataUtil.getFocusObjectOid(modelContext);
PrismObject<UserType> requester = baseModelInvocationProcessingHelper.getRequester(taskFromModel, result);
for (ApprovalRequest<AssociationAdditionType> approvalRequest : approvalRequestList) {
LOGGER.trace("Approval request = {}", approvalRequest);
AssociationAdditionType associationAddition = approvalRequest.getItemToApprove();
ShadowAssociationType association = associationAddition.getAssociation();
ShadowType target = getAssociationApprovalTarget(association, result);
Validate.notNull(target, "No target in association to be approved");
String targetName = target.getName() != null ? target.getName().getOrig() : "(unnamed)";
String approvalTaskName = "Approve adding " + targetName + " to " + assigneeName;
// create a JobCreateInstruction for a given change processor (primaryChangeProcessor in this case)
PcpChildWfTaskCreationInstruction instruction = PcpChildWfTaskCreationInstruction.createItemApprovalInstruction(getChangeProcessor(), approvalTaskName, approvalRequest.getApprovalSchemaType(), null);
// set some common task/process attributes
instruction.prepareCommonAttributes(this, modelContext, requester);
// prepare and set the delta that has to be approved
ObjectTreeDeltas objectTreeDeltas = associationAdditionToDelta(modelContext, associationAddition, assigneeOid);
instruction.setDeltasToProcesses(objectTreeDeltas);
// TODO - or should we take shadow as an object?
instruction.setObjectRef(modelContext, result);
instruction.setTargetRef(ObjectTypeUtil.createObjectRef(target), result);
// set the names of midPoint task and activiti process instance
String andExecuting = instruction.isExecuteApprovedChangeImmediately() ? "and execution " : "";
instruction.setTaskName("Approval " + andExecuting + "of adding " + targetName + " to " + assigneeName);
instruction.setProcessInstanceName("Adding " + targetName + " to " + assigneeName);
// setup general item approval process
itemApprovalProcessInterface.prepareStartInstruction(instruction);
instructions.add(instruction);
}
return instructions;
}
use of com.evolveum.midpoint.schema.ObjectTreeDeltas in project midpoint by Evolveum.
the class WorkItemDto method prepareDeltaVisualization.
public void prepareDeltaVisualization(String sceneNameKey, PrismContext prismContext, ModelInteractionService modelInteractionService, Task opTask, OperationResult result) throws SchemaException, ExpressionEvaluationException {
TaskType task = getTaskType();
if (task == null || task.getWorkflowContext() == null) {
return;
}
if (!(task.getWorkflowContext().getProcessorSpecificState() instanceof WfPrimaryChangeProcessorStateType)) {
return;
}
WfPrimaryChangeProcessorStateType state = (WfPrimaryChangeProcessorStateType) task.getWorkflowContext().getProcessorSpecificState();
Scene deltasScene = SceneUtil.visualizeObjectTreeDeltas(state.getDeltasToProcess(), sceneNameKey, prismContext, modelInteractionService, opTask, result);
deltas = new SceneDto(deltasScene);
ObjectTreeDeltas deltas = ObjectTreeDeltas.fromObjectTreeDeltasType(state.getDeltasToProcess(), prismContext);
changes = TaskDto.createChangesToBeApproved(deltas, modelInteractionService, prismContext, opTask, result);
}
Aggregations