Search in sources :

Example 6 with DefaultWorkItemManager

use of io.automatiko.engine.workflow.base.instance.impl.workitem.DefaultWorkItemManager in project automatiko-engine by automatiko-io.

the class DynamicUtils method executeWorkItem.

private static void executeWorkItem(InternalProcessRuntime runtime, WorkItemImpl workItem, WorkItemNodeInstance workItemNodeInstance) {
    ProcessEventSupport eventSupport = runtime.getProcessEventSupport();
    eventSupport.fireBeforeNodeTriggered(workItemNodeInstance, runtime);
    ((DefaultWorkItemManager) runtime.getWorkItemManager()).internalExecuteWorkItem(workItem);
    workItemNodeInstance.internalSetWorkItemId(workItem.getId());
    eventSupport.fireAfterNodeTriggered(workItemNodeInstance, runtime);
}
Also used : ProcessEventSupport(io.automatiko.engine.workflow.base.core.event.ProcessEventSupport) DefaultWorkItemManager(io.automatiko.engine.workflow.base.instance.impl.workitem.DefaultWorkItemManager)

Example 7 with DefaultWorkItemManager

use of io.automatiko.engine.workflow.base.instance.impl.workitem.DefaultWorkItemManager in project automatiko-engine by automatiko-io.

the class HandleMessageAction method execute.

public void execute(ProcessContext context) throws Exception {
    Object variable = VariableUtil.resolveVariable(variableName, context.getNodeInstance());
    if (transformation != null) {
        variable = new EventTransformerImpl(transformation).transformEvent(variable);
    }
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setName("Send Task");
    workItem.setNodeInstanceId(context.getNodeInstance().getId());
    workItem.setProcessInstanceId(context.getProcessInstance().getId());
    workItem.setProcessInstanceId(context.getProcessInstance().getParentProcessInstanceId());
    workItem.setNodeId(context.getNodeInstance().getNodeId());
    workItem.setParameter("MessageType", messageType);
    if (variable != null) {
        workItem.setParameter("Message", variable);
    }
    ((DefaultWorkItemManager) context.getProcessRuntime().getWorkItemManager()).internalExecuteWorkItem(workItem);
}
Also used : DefaultWorkItemManager(io.automatiko.engine.workflow.base.instance.impl.workitem.DefaultWorkItemManager) WorkItemImpl(io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemImpl) EventTransformerImpl(io.automatiko.engine.workflow.base.core.event.EventTransformerImpl)

Example 8 with DefaultWorkItemManager

use of io.automatiko.engine.workflow.base.instance.impl.workitem.DefaultWorkItemManager in project automatiko-engine by automatiko-io.

the class SignalProcessInstanceAction method execute.

public void execute(ProcessContext context) throws Exception {
    String variableName = VariableUtil.resolveVariable(this.variableName, context.getNodeInstance());
    Object variable = variableName == null ? eventDataSupplier.apply(context) : context.getVariable(variableName);
    if (transformation != null) {
        variable = new io.automatiko.engine.workflow.base.core.event.EventTransformerImpl(transformation).transformEvent(context.getProcessInstance().getVariables());
    }
    if (DEFAULT_SCOPE.equals(scope)) {
        context.getProcessRuntime().signalEvent(VariableUtil.resolveVariable(signalName, context.getNodeInstance()), variable);
    } else if (PROCESS_INSTANCE_SCOPE.equals(scope)) {
        context.getProcessInstance().signalEvent(VariableUtil.resolveVariable(signalName, context.getNodeInstance()), variable);
    } else if (EXTERNAL_SCOPE.equals(scope)) {
        WorkItemImpl workItem = new WorkItemImpl();
        workItem.setName("External Send Task");
        workItem.setNodeInstanceId(context.getNodeInstance().getId());
        workItem.setProcessInstanceId(context.getProcessInstance().getId());
        workItem.setProcessInstanceId(context.getProcessInstance().getParentProcessInstanceId());
        workItem.setNodeId(context.getNodeInstance().getNodeId());
        workItem.setParameter("Signal", VariableUtil.resolveVariable(signalName, context.getNodeInstance()));
        workItem.setParameter("SignalProcessInstanceId", context.getVariable("SignalProcessInstanceId"));
        workItem.setParameter("SignalWorkItemId", context.getVariable("SignalWorkItemId"));
        workItem.setParameter("SignalDeploymentId", context.getVariable("SignalDeploymentId"));
        if (variable == null) {
            workItem.setParameter("Data", variable);
        }
        ((DefaultWorkItemManager) context.getProcessRuntime().getWorkItemManager()).internalExecuteWorkItem(workItem);
    }
}
Also used : DefaultWorkItemManager(io.automatiko.engine.workflow.base.instance.impl.workitem.DefaultWorkItemManager) WorkItemImpl(io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemImpl)

Example 9 with DefaultWorkItemManager

use of io.automatiko.engine.workflow.base.instance.impl.workitem.DefaultWorkItemManager in project automatiko-engine by automatiko-io.

the class PredictionAwareHumanTaskLifeCycle method transitionTo.

@Override
public Map<String, Object> transitionTo(WorkItem workItem, WorkItemManager manager, Transition<Map<String, Object>> transition) {
    LifeCyclePhase targetPhase = phaseById(transition.phase());
    if (targetPhase == null) {
        logger.debug("Target life cycle phase '{}' does not exist in {}", transition.phase(), this.getClass().getSimpleName());
        throw new InvalidLifeCyclePhaseException(transition.phase());
    }
    HumanTaskWorkItemImpl humanTaskWorkItem = (HumanTaskWorkItemImpl) workItem;
    if (targetPhase.id().equals(Active.ID)) {
        PredictionOutcome outcome = predictionService.predict(workItem, workItem.getParameters());
        logger.debug("Prediction service returned confidence level {} for work item {}", outcome.getConfidenceLevel(), humanTaskWorkItem.getId());
        if (outcome.isCertain()) {
            humanTaskWorkItem.getResults().putAll(outcome.getData());
            logger.debug("Prediction service is certain (confidence level {}) on the outputs, completing work item {}", outcome.getConfidenceLevel(), humanTaskWorkItem.getId());
            ((DefaultWorkItemManager) manager).internalCompleteWorkItem(humanTaskWorkItem);
            return outcome.getData();
        } else if (outcome.isPresent()) {
            logger.debug("Prediction service is NOT certain (confidence level {}) on the outputs, setting recommended outputs on work item {}", outcome.getConfidenceLevel(), humanTaskWorkItem.getId());
            humanTaskWorkItem.getResults().putAll(outcome.getData());
        }
    }
    // prediction service does work only on activating tasks
    Map<String, Object> data = super.transitionTo(workItem, manager, transition);
    if (targetPhase.id().equals(Complete.ID)) {
        // upon actual transition train the data if it's completion phase
        predictionService.train(humanTaskWorkItem, workItem.getParameters(), data);
    }
    return data;
}
Also used : DefaultWorkItemManager(io.automatiko.engine.workflow.base.instance.impl.workitem.DefaultWorkItemManager) InvalidLifeCyclePhaseException(io.automatiko.engine.api.workflow.workitem.InvalidLifeCyclePhaseException) HumanTaskWorkItemImpl(io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskWorkItemImpl) LifeCyclePhase(io.automatiko.engine.api.workflow.workitem.LifeCyclePhase)

Aggregations

DefaultWorkItemManager (io.automatiko.engine.workflow.base.instance.impl.workitem.DefaultWorkItemManager)9 WorkItemImpl (io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemImpl)3 WorkItem (io.automatiko.engine.api.runtime.process.WorkItem)2 InvalidLifeCyclePhaseException (io.automatiko.engine.api.workflow.workitem.InvalidLifeCyclePhaseException)2 LifeCyclePhase (io.automatiko.engine.api.workflow.workitem.LifeCyclePhase)2 WorkItemHandlerNotFoundException (io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemHandlerNotFoundException)2 WorkflowProcessInstance (io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance)2 WorkflowRuntimeException (io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException)2 HumanTaskWorkItem (io.automatiko.engine.api.runtime.process.HumanTaskWorkItem)1 ProcessWorkItemHandlerException (io.automatiko.engine.api.runtime.process.ProcessWorkItemHandlerException)1 InvalidTransitionException (io.automatiko.engine.api.workflow.workitem.InvalidTransitionException)1 NotAuthorizedException (io.automatiko.engine.api.workflow.workitem.NotAuthorizedException)1 Policy (io.automatiko.engine.api.workflow.workitem.Policy)1 WorkItemExecutionError (io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError)1 EventTransformerImpl (io.automatiko.engine.workflow.base.core.event.EventTransformerImpl)1 ProcessEventSupport (io.automatiko.engine.workflow.base.core.event.ProcessEventSupport)1 InternalProcessRuntime (io.automatiko.engine.workflow.base.instance.InternalProcessRuntime)1 ProcessInstance (io.automatiko.engine.workflow.base.instance.ProcessInstance)1 ExceptionScopeInstance (io.automatiko.engine.workflow.base.instance.context.exception.ExceptionScopeInstance)1 HumanTaskWorkItemImpl (io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskWorkItemImpl)1