use of io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemImpl in project automatiko-engine by automatiko-io.
the class ProtobufProcessMarshaller method readWorkItem.
public static WorkItem readWorkItem(MarshallerReaderContext context, AutomatikoMessages.WorkItem _workItem, boolean includeVariables) throws IOException {
WorkItemImpl workItem = new WorkItemImpl();
workItem.setId(_workItem.getId());
workItem.setProcessInstanceId(_workItem.getProcessInstancesId());
workItem.setName(_workItem.getName());
workItem.setState(_workItem.getState());
workItem.setNodeId(_workItem.getNodeId());
workItem.setNodeInstanceId(_workItem.getNodeInstanceId());
if (includeVariables) {
for (AutomatikoMessages.Variable _variable : _workItem.getVariableList()) {
try {
Object value = unmarshallVariableValue(context, _variable);
workItem.setParameter(_variable.getName(), value);
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException("Could not reload parameter " + _variable.getName() + " for work item " + _workItem);
}
}
}
return workItem;
}
use of io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemImpl in project automatiko-engine by automatiko-io.
the class WorkItemNodeInstance method internalTrigger.
@Override
public void internalTrigger(final NodeInstance from, String type) {
super.internalTrigger(from, type);
// if node instance was cancelled, abort
if (getNodeInstanceContainer().getNodeInstance(getId()) == null) {
return;
}
WorkItemNode workItemNode = getWorkItemNode();
createWorkItem(workItemNode);
if (workItemNode.isWaitForCompletion()) {
addWorkItemListener();
}
((WorkItemImpl) workItem).setNodeInstanceId(this.getId());
((WorkItemImpl) workItem).setNodeId(getNodeId());
workItem.setNodeInstance(this);
workItem.setProcessInstance(getProcessInstance());
setProcessId();
try {
((DefaultWorkItemManager) getProcessInstance().getProcessRuntime().getWorkItemManager()).internalExecuteWorkItem(workItem);
} catch (WorkItemHandlerNotFoundException wihnfe) {
getProcessInstance().setState(STATE_ABORTED);
throw wihnfe;
} catch (ProcessWorkItemHandlerException handlerException) {
this.workItemId = workItem.getId();
removeEventListeners();
handleWorkItemHandlerException(handlerException, workItem);
} catch (WorkItemExecutionError e) {
removeEventListeners();
handleException(e.getErrorCode(), e);
} catch (Exception e) {
removeEventListeners();
String exceptionName = e.getClass().getName();
handleException(exceptionName, e);
}
if (!workItemNode.isWaitForCompletion()) {
triggerCompleted();
}
this.workItemId = workItem.getId();
}
use of io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemImpl in project automatiko-engine by automatiko-io.
the class StartNodeInstance method handleAssignment.
private void handleAssignment(Assignment assignment, Object result) {
AssignmentAction action = (AssignmentAction) assignment.getMetaData("Action");
if (action == null) {
return;
}
try {
ProcessContext context = new ProcessContext(getProcessInstance().getProcessRuntime());
context.setNodeInstance(this);
WorkItemImpl workItem = new WorkItemImpl();
workItem.setResult("workflowdata", result);
workItem.setResult("event", result);
action.execute(workItem, context);
} catch (WorkItemExecutionError e) {
throw e;
} catch (Exception e) {
throw new RuntimeException("unable to execute Assignment", e);
}
}
use of io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemImpl in project automatiko-engine by automatiko-io.
the class HumanTaskNodeInstance method assignWorkItem.
protected String assignWorkItem(WorkItem workItem) {
String actorId = null;
// if this human task node is part of a swimlane, check whether an actor
// has already been assigned to this swimlane
String swimlaneName = getHumanTaskNode().getSwimlane();
SwimlaneContextInstance swimlaneContextInstance = getSwimlaneContextInstance(swimlaneName);
if (swimlaneContextInstance != null) {
actorId = swimlaneContextInstance.getActorId(swimlaneName);
((WorkItemImpl) workItem).setParameter("SwimlaneActorId", actorId);
}
// actor is specified for this human task
if (actorId == null) {
actorId = (String) workItem.getParameter(ACTOR_ID);
if (actorId != null && swimlaneContextInstance != null && actorId.split(separator).length == 1) {
swimlaneContextInstance.setActorId(swimlaneName, actorId);
((WorkItemImpl) workItem).setParameter("SwimlaneActorId", actorId);
}
}
processAssigment(ACTOR_ID, workItem, ((HumanTaskWorkItemImpl) workItem).getPotentialUsers());
processAssigment(GROUP_ID, workItem, ((HumanTaskWorkItemImpl) workItem).getPotentialGroups());
processAssigment(GROUPS, workItem, ((HumanTaskWorkItemImpl) workItem).getPotentialGroups());
processAssigment(EXCLUDED_OWNER_ID, workItem, ((HumanTaskWorkItemImpl) workItem).getExcludedUsers());
processAssigment(BUSINESSADMINISTRATOR_ID, workItem, ((HumanTaskWorkItemImpl) workItem).getAdminUsers());
processAssigment(BUSINESSADMINISTRATOR_GROUP_ID, workItem, ((HumanTaskWorkItemImpl) workItem).getAdminGroups());
// parameter
return (String) workItem.getParameter(ACTOR_ID);
}
use of io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemImpl in project automatiko-engine by automatiko-io.
the class LightWorkItemManager method internalAbortWorkItem.
public void internalAbortWorkItem(String id) {
WorkItemImpl workItem = (WorkItemImpl) workItems.get(id);
// work item may have been aborted
if (workItem != null) {
workItem.setCompleteDate(new Date());
WorkItemHandler handler = this.workItemHandlers.get(workItem.getName());
if (handler != null) {
ProcessInstance processInstance = workItem.getProcessInstance();
Transition<?> transition = new TransitionToAbort(Collections.emptyList());
eventSupport.fireBeforeWorkItemTransition(processInstance, workItem, transition, null);
handler.abortWorkItem(workItem, this);
workItem.setPhaseId(ID);
workItem.setPhaseStatus(STATUS);
eventSupport.fireAfterWorkItemTransition(processInstance, workItem, transition, null);
} else {
workItems.remove(workItem.getId());
throw new WorkItemHandlerNotFoundException(workItem.getName());
}
workItems.remove(workItem.getId());
}
}
Aggregations