use of io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl in project automatiko-engine by automatiko-io.
the class AbstractProcessInstance method startFrom.
@Override
public void startFrom(String nodeId, String referenceId) {
lock();
((WorkflowProcessInstanceImpl) processInstance).setStartDate(new Date());
((WorkflowProcessInstanceImpl) processInstance).setState(STATE_ACTIVE);
((InternalProcessRuntime) getProcessRuntime()).getProcessInstanceManager().addProcessInstance(this.processInstance, this.correlationKey);
this.id = processInstance.getId();
addCompletionEventListener();
if (referenceId != null) {
((WorkflowProcessInstanceImpl) processInstance).setReferenceId(referenceId);
}
((WorkflowProcessInstanceImpl) processInstance).setMetaData("AutomatikProcessInstance", this);
triggerNode(nodeId);
syncProcessInstance((WorkflowProcessInstance) processInstance);
addToUnitOfWork(pi -> ((MutableProcessInstances<T>) process.instances()).update(pi.id(), pi));
unlock(false);
unbind(variables, processInstance.getVariables());
if (processInstance != null) {
this.status = processInstance.getState();
}
}
use of io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl in project automatiko-engine by automatiko-io.
the class WorkflowFunction method callTemplate.
public void callTemplate($Type$ resource) {
AtomicBoolean hasData = new AtomicBoolean(true);
if (resource == null) {
resource = new $Type$();
hasData.set(false);
}
String typePrefix = "$TypePrefix$";
final $Type$ value = resource;
identitySupplier.buildIdentityProvider(null, Collections.emptyList());
FunctionContext ctx = io.automatiko.engine.services.uow.UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> {
String startFromNode = "$StartFromNode$";
ProcessInstance<$Type$> pi = value.getId() == null ? null : process.instances().findById(value.getId()).orElse(null);
if (pi != null) {
if (hasData.get()) {
pi.updateVariables(value);
}
pi.triggerNode(startFromNode);
} else {
pi = process.createInstance(value.getId(), value);
pi.startFrom(startFromNode);
}
String pid = (String) ((WorkflowProcessInstanceImpl) ((AbstractProcessInstance<$Type$>) pi).processInstance()).getMetaData().remove("ATK_FUNC_FLOW_ID");
if (pid == null) {
pid = id(pi);
}
((WorkflowProcessInstanceImpl) ((AbstractProcessInstance<$Type$>) pi).processInstance()).getMetaData().remove("ATK_FUNC_FLOW_COUNTER");
return new FunctionContext(pid, (List<String>) ((WorkflowProcessInstanceImpl) ((AbstractProcessInstance<$Type$>) pi).processInstance()).getMetaData().remove("ATK_FUNC_FLOW_NEXT"), getModel(pi));
});
if (ctx.nextNodes != null && eventSource != null) {
for (String nextNode : ctx.nextNodes) {
LOGGER.debug("Next function to trigger {}", sanitizeIdentifier(nextNode));
eventSource.produce(sanitizeIdentifier(nextNode), typePrefix + sanitizeIdentifier("$ThisNode$".toLowerCase()) + ctx.id, ctx.model);
}
}
}
use of io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl in project automatiko-engine by automatiko-io.
the class Controller method reconcile.
@Override
public synchronized UpdateControl<$DataType$> reconcile($DataType$ resource, Context context) {
if (!acceptedPayload(resource)) {
LOGGER.debug("Event has been rejected by the filter expression");
return UpdateControl.noUpdate();
}
String trigger = "$Trigger$";
IdentityProvider.set(new TrustedIdentityProvider("System<messaging>"));
final $Type$ model = new $Type$();
return io.automatiko.engine.services.uow.UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> {
try {
String correlation = resource.getMetadata().getName();
if (correlation != null) {
LOGGER.debug("Correlation ({}) is set, attempting to find if there is matching instance already active", correlation);
Optional<? extends ProcessInstance> possiblyFound = (Optional<? extends ProcessInstance>) process.instances().findById(correlation);
if (possiblyFound.isPresent()) {
ProcessInstance pInstance = (ProcessInstance) possiblyFound.get();
LOGGER.debug("Found process instance {} matching correlation {}, signaling instead of starting new instance", pInstance.id(), correlation);
pInstance.send(Sig.of("Message-updated", resource));
$DataType$ updated = ($DataType$) ((Model) pInstance.variables()).toMap().get("resource");
if (updated == null || Boolean.TRUE.equals(((WorkflowProcessInstanceImpl) ((AbstractProcessInstance<?>) pInstance).processInstance()).getVariable("skipResourceUpdate"))) {
LOGGER.debug("Signalled and returned updated {} no need to updated custom resource", updated);
return UpdateControl.noUpdate();
}
LOGGER.debug("Signalled and returned updated {} that requires update of the custom resource", updated);
return UpdateControl.updateResourceAndStatus(updated);
}
}
if (canStartInstance()) {
LOGGER.debug("Received message without reference id and no correlation is set/matched, staring new process instance with trigger '{}'", trigger);
ProcessInstance<?> pi = process.createInstance(correlation, model);
pi.start(trigger, null, resource);
$DataType$ updated = ($DataType$) ((Model) pi.variables()).toMap().get("resource");
if (updated == null || Boolean.TRUE.equals(((WorkflowProcessInstanceImpl) ((AbstractProcessInstance<?>) pi).processInstance()).getVariable("skipResourceUpdate"))) {
LOGGER.debug("New instance started and not need to update custom resource");
return UpdateControl.noUpdate();
}
LOGGER.debug("New instance started and with the need to update custom resource");
return UpdateControl.updateResourceAndStatus(updated);
} else {
LOGGER.warn("Received message without reference id and no correlation is set/matched, for trigger not capable of starting new instance '{}'", trigger);
}
} catch (Throwable t) {
LOGGER.error("Encountered problems while creating/updating instance", t);
}
return UpdateControl.noUpdate();
});
}
use of io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl in project automatiko-engine by automatiko-io.
the class ProtobufProcessMarshaller method readProcessInstances.
public List<ProcessInstance> readProcessInstances(MarshallerReaderContext context) throws IOException {
AutomatikoMessages.ProcessData _pdata = (AutomatikoMessages.ProcessData) context.parameterObject;
List<ProcessInstance> processInstanceList = new ArrayList<ProcessInstance>();
for (AutomatikoMessages.ProcessInstance _instance : _pdata.getExtension(AutomatikoMessages.processInstance)) {
context.parameterObject = _instance;
ProcessInstance processInstance = ProcessMarshallerRegistry.INSTANCE.getMarshaller(_instance.getProcessType()).readProcessInstance(context);
((WorkflowProcessInstanceImpl) processInstance).reconnect();
processInstanceList.add(processInstance);
}
return processInstanceList;
}
use of io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl in project automatiko-engine by automatiko-io.
the class JbpmBpmn2TestCase method assertNumOfIncommingConnections.
public void assertNumOfIncommingConnections(ProcessInstance process, String nodeName, int num) {
assertNodeExists(process, nodeName);
WorkflowProcessInstanceImpl instance = (WorkflowProcessInstanceImpl) process;
for (Node node : instance.getNodeContainer().getNodes()) {
if (node.getName().equals(nodeName)) {
if (node.getIncomingConnections().size() != num) {
fail("Expected incomming connections: " + num + " - found " + node.getIncomingConnections().size());
} else {
break;
}
}
}
}
Aggregations