Search in sources :

Example 1 with WfConfigurationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.WfConfigurationType in project midpoint by Evolveum.

the class WfHook method invoke.

@Override
public <O extends ObjectType> HookOperationMode invoke(@NotNull ModelContext<O> context, @NotNull Task taskFromModel, @NotNull OperationResult parentResult) {
    Validate.notNull(context);
    Validate.notNull(taskFromModel);
    Validate.notNull(parentResult);
    // Generally this cannot be minor as we need the "task switched to background" flag.
    // But if the hook does nothing (returns FOREGROUND flag), we mark the result
    // as minor afterwards.
    OperationResult result = parentResult.createSubresult(OPERATION_INVOKE);
    result.addParam("taskFromModel", taskFromModel.toString());
    result.addContext("model state", context.getState());
    try {
        WfConfigurationType wfConfigurationType = baseConfigurationHelper.getWorkflowConfiguration(context, result);
        // TODO consider this if it's secure enough
        if (wfConfigurationType != null && Boolean.FALSE.equals(wfConfigurationType.isModelHookEnabled())) {
            LOGGER.info("Workflow model hook is disabled. Proceeding with operation execution as if everything is approved.");
            result.recordSuccess();
            return HookOperationMode.FOREGROUND;
        }
        if (context.getPartialProcessingOptions().getApprovals() == PartialProcessingTypeType.SKIP) {
            LOGGER.debug("Skipping workflow processing because of the partial processing option set to SKIP");
            result.recordSuccess();
            return HookOperationMode.FOREGROUND;
        }
        // e.g. for tests, initialization is scattered through many places, so that would be too much work.
        if (SchemaConstants.CHANNEL_GUI_INIT_URI.equals(context.getChannel())) {
            LOGGER.debug("Skipping workflow processing because the channel is '" + SchemaConstants.CHANNEL_GUI_INIT_URI + "'.");
            result.recordSuccess();
            return HookOperationMode.FOREGROUND;
        }
        logOperationInformation(context);
        HookOperationMode retval = processModelInvocation(context, wfConfigurationType, taskFromModel, result);
        result.computeStatus();
        if (retval == HookOperationMode.FOREGROUND) {
            result.setMinor(true);
        }
        return retval;
    } catch (RuntimeException e) {
        result.recordFatalError("Couldn't process model invocation in workflow module: " + e.getMessage(), e);
        throw e;
    }
}
Also used : HookOperationMode(com.evolveum.midpoint.model.api.hooks.HookOperationMode) WfConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.WfConfigurationType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Aggregations

HookOperationMode (com.evolveum.midpoint.model.api.hooks.HookOperationMode)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 WfConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.WfConfigurationType)1