use of io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemImpl in project automatiko-engine by automatiko-io.
the class AbstractProtobufProcessInstanceMarshaller method readWorkItem.
public static WorkItem readWorkItem(WorkflowProcessInstance processInstance, MarshallerReaderContext context, AutomatikoMessages.WorkItem _workItem) throws IOException {
WorkItemImpl workItem = new WorkItemImpl();
workItem.setId(_workItem.getId());
workItem.setProcessInstanceId(_workItem.getProcessInstancesId());
workItem.setName(_workItem.getName());
workItem.setState(_workItem.getState());
workItem.setDeploymentId(_workItem.getDeploymentId());
workItem.setNodeId(_workItem.getNodeId());
workItem.setNodeInstanceId(_workItem.getNodeInstanceId());
workItem.setPhaseId(_workItem.getPhaseId());
workItem.setPhaseStatus(_workItem.getPhaseStatus());
workItem.setStartDate(new Date(_workItem.getStartDate()));
workItem.setProcessInstance(processInstance);
if (_workItem.getCompleteDate() > 0) {
workItem.setCompleteDate(new Date(_workItem.getCompleteDate()));
}
for (AutomatikoMessages.Variable _variable : _workItem.getVariableList()) {
try {
Object value = ProtobufProcessMarshaller.unmarshallVariableValue(context, _variable);
workItem.setParameter(_variable.getName(), value);
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException(e);
}
}
return workItem;
}
use of io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemImpl in project automatiko-engine by automatiko-io.
the class TaskInputJqAssignmentAction method execute.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void execute(WorkItem workItem, ProcessContext context) throws Exception {
Object sdata = context.getVariable(JsonVariableScope.WORKFLOWDATA_KEY);
ExpressionEvaluator evaluator = (ExpressionEvaluator) ((WorkflowProcess) context.getProcessInstance().getProcess()).getDefaultContext(ExpressionEvaluator.EXPRESSION_EVALUATOR);
Map<String, Object> vars = new HashMap<>();
vars.put("workflowdata", sdata);
if (context.getVariable("$CONST") != null) {
vars.put("workflow_variables", Collections.singletonMap("CONST", context.getVariable("$CONST")));
}
if (inputFilterExpression != null) {
sdata = evaluator.evaluate(inputFilterExpression, vars);
}
if (context.getNodeInstance() instanceof ContextableInstance) {
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) ((ContextableInstance) context.getNodeInstance()).getContextInstance(VariableScope.VARIABLE_SCOPE);
variableScopeInstance.setVariable(JsonVariableScope.WORKFLOWDATA_KEY, sdata);
}
if (paramNames != null && !paramNames.isEmpty()) {
vars = new HashMap<>();
vars.put("workflowdata", sdata);
if (context.getVariable("$CONST") != null) {
vars.put("workflow_variables", Collections.singletonMap("CONST", context.getVariable("$CONST")));
}
for (String name : paramNames) {
Object param = workItem.getParameter(name);
if (param != null) {
param = evaluator.evaluate(param.toString(), vars);
((WorkItemImpl) workItem).setParameter(name, param);
}
}
} else {
((WorkItemImpl) workItem).setParameter("Parameter", sdata);
}
}
use of io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemImpl in project automatiko-engine by automatiko-io.
the class LightWorkItemManager method internalExecuteWorkItem.
public void internalExecuteWorkItem(WorkItem workItem) {
((WorkItemImpl) workItem).setId(UUID.randomUUID().toString());
internalAddWorkItem(workItem);
WorkItemHandler handler = this.workItemHandlers.get(workItem.getName());
if (handler != null) {
ProcessInstance processInstance = workItem.getProcessInstance();
Transition<?> transition = new TransitionToActive();
eventSupport.fireBeforeWorkItemTransition(processInstance, workItem, transition, null);
handler.executeWorkItem(workItem, this);
eventSupport.fireAfterWorkItemTransition(processInstance, workItem, transition, null);
} else
throw new WorkItemHandlerNotFoundException(workItem.getName());
}
use of io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemImpl in project automatiko-engine by automatiko-io.
the class LightWorkItemManager method abortWorkItem.
public void abortWorkItem(String id, Policy<?>... policies) {
WorkItemImpl workItem = (WorkItemImpl) workItems.get(id);
// work item may have been aborted
if (workItem != null) {
if (!workItem.enforce(policies)) {
throw new NotAuthorizedException("Work item can be aborted as it does not fulfil policies (e.g. security)");
}
ProcessInstance processInstance = workItem.getProcessInstance();
Transition<?> transition = new TransitionToAbort(Arrays.asList(policies));
eventSupport.fireBeforeWorkItemTransition(processInstance, workItem, transition, null);
workItem.setState(ABORTED);
abortPhase.apply(workItem, transition);
// process instance may have finished already
if (processInstance != null) {
processInstance.signalEvent("workItemAborted", workItem);
}
workItem.setPhaseId(ID);
workItem.setPhaseStatus(STATUS);
eventSupport.fireAfterWorkItemTransition(processInstance, workItem, transition, null);
workItems.remove(id);
}
}
use of io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemImpl in project automatiko-engine by automatiko-io.
the class DefaultExceptionScopeInstance method handleException.
public void handleException(io.automatiko.engine.api.runtime.process.NodeInstance nodeInstance, ExceptionHandler handler, String exception, Object params) {
if (handler instanceof ActionExceptionHandler) {
ActionExceptionHandler exceptionHandler = (ActionExceptionHandler) handler;
if (retryAvailable(nodeInstance, exceptionHandler)) {
Integer retryAttempts = ((NodeInstanceImpl) nodeInstance).getRetryAttempts();
if (retryAttempts == null) {
retryAttempts = 1;
} else {
retryAttempts = retryAttempts + 1;
}
long delay = calculateDelay(exceptionHandler.getRetryAfter().longValue(), retryAttempts, exceptionHandler.getRetryIncrement(), exceptionHandler.getRetryIncrementMultiplier());
DurationExpirationTime expirationTime = DurationExpirationTime.after(delay);
JobsService jobService = getProcessInstance().getProcessRuntime().getJobsService();
String jobId = jobService.scheduleProcessInstanceJob(ProcessInstanceJobDescription.of(nodeInstance.getNodeId(), "retry:" + nodeInstance.getId(), expirationTime, ((NodeInstanceImpl) nodeInstance).getProcessInstanceIdWithParent(), getProcessInstance().getRootProcessInstanceId(), getProcessInstance().getProcessId(), getProcessInstance().getProcess().getVersion(), getProcessInstance().getRootProcessId()));
((NodeInstanceImpl) nodeInstance).internalSetRetryJobId(jobId);
((NodeInstanceImpl) nodeInstance).internalSetRetryAttempts(retryAttempts);
((NodeInstanceImpl) nodeInstance).registerRetryEventListener();
if (nodeInstance instanceof WorkItemNodeInstance) {
((WorkItemImpl) ((WorkItemNodeInstance) nodeInstance).getWorkItem()).setState(WorkItem.RETRYING);
}
} else {
Action action = (Action) exceptionHandler.getAction().getMetaData("Action");
try {
ProcessInstance processInstance = getProcessInstance();
ProcessContext processContext = new ProcessContext(processInstance.getProcessRuntime());
ContextInstanceContainer contextInstanceContainer = getContextInstanceContainer();
if (contextInstanceContainer instanceof NodeInstance) {
processContext.setNodeInstance((NodeInstance) contextInstanceContainer);
} else {
processContext.setProcessInstance(processInstance);
}
String faultVariable = exceptionHandler.getFaultVariable();
if (faultVariable != null) {
processContext.setVariable(faultVariable, params);
}
action.execute(processContext);
} catch (Exception e) {
throw new RuntimeException("unable to execute Action", e);
}
}
} else {
throw new IllegalArgumentException("Unknown exception handler " + handler);
}
}
Aggregations