use of org.drools.core.common.InternalKnowledgeRuntime in project jbpm by kiegroup.
the class StartCaseCommand method execute.
@SuppressWarnings("unchecked")
@Override
public Void execute(Context context) {
CaseEventSupport caseEventSupport = getCaseEventSupport(context);
caseEventSupport.fireBeforeCaseStarted(caseId, deploymentId, caseDefinitionId, caseFile);
logger.debug("Inserting case file into working memory");
List<Command<?>> commands = new ArrayList<>();
commands.add(commandsFactory.newInsert(caseFile));
commands.add(commandsFactory.newFireAllRules());
BatchExecutionCommand batch = commandsFactory.newBatchExecution(commands);
processService.execute(deploymentId, CaseContext.get(caseId), batch);
logger.debug("Starting process instance for case {} and case definition {}", caseId, caseDefinitionId);
CorrelationKey correlationKey = correlationKeyFactory.newCorrelationKey(caseId);
Map<String, Object> params = new HashMap<>();
// set case id to allow it to use CaseContext when creating runtime engine
params.put(EnvironmentName.CASE_ID, caseId);
final long processInstanceId = processService.startProcess(deploymentId, caseDefinitionId, correlationKey, params);
logger.debug("Case {} successfully started (process instance id {})", caseId, processInstanceId);
final Map<String, Object> caseData = caseFile.getData();
if (caseData != null && !caseData.isEmpty()) {
processService.execute(deploymentId, CaseContext.get(caseId), new ExecutableCommand<Void>() {
private static final long serialVersionUID = -7093369406457484236L;
@Override
public Void execute(Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
ProcessInstance pi = (ProcessInstance) ksession.getProcessInstance(processInstanceId);
if (pi != null) {
ProcessEventSupport processEventSupport = ((InternalProcessRuntime) ((InternalKnowledgeRuntime) ksession).getProcessRuntime()).getProcessEventSupport();
for (Entry<String, Object> entry : caseData.entrySet()) {
String name = "caseFile_" + entry.getKey();
processEventSupport.fireAfterVariableChanged(name, name, null, entry.getValue(), pi, (KieRuntime) ksession);
}
}
return null;
}
});
}
caseEventSupport.fireAfterCaseStarted(caseId, deploymentId, caseDefinitionId, caseFile, processInstanceId);
return null;
}
use of org.drools.core.common.InternalKnowledgeRuntime in project jbpm by kiegroup.
the class TimerNodeInstance method internalTrigger.
public void internalTrigger(NodeInstance from, String type) {
if (!org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
throw new IllegalArgumentException("A TimerNode only accepts default incoming connections!");
}
InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime();
timerInstance = createTimerInstance(kruntime);
if (getTimerInstances() == null) {
addTimerListener();
}
((InternalProcessRuntime) kruntime.getProcessRuntime()).getTimerManager().registerTimer(timerInstance, (ProcessInstance) getProcessInstance());
timerId = timerInstance.getId();
}
use of org.drools.core.common.InternalKnowledgeRuntime in project jbpm by kiegroup.
the class EndNodeInstance method internalTrigger.
public void internalTrigger(final NodeInstance from, String type) {
super.internalTrigger(from, type);
if (!org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
throw new IllegalArgumentException("An EndNode only accepts default incoming connections!");
}
boolean hidden = false;
if (getNode().getMetaData().get("hidden") != null) {
hidden = true;
}
InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime();
if (!hidden) {
((InternalProcessRuntime) kruntime.getProcessRuntime()).getProcessEventSupport().fireBeforeNodeLeft(this, kruntime);
}
((NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this);
if (getEndNode().isTerminate()) {
if (getNodeInstanceContainer() instanceof CompositeNodeInstance) {
if (getEndNode().getScope() == EndNode.PROCESS_SCOPE) {
getProcessInstance().setState(ProcessInstance.STATE_COMPLETED);
} else {
while (!getNodeInstanceContainer().getNodeInstances().isEmpty()) {
((org.jbpm.workflow.instance.NodeInstance) getNodeInstanceContainer().getNodeInstances().iterator().next()).cancel();
}
((NodeInstanceContainer) getNodeInstanceContainer()).nodeInstanceCompleted(this, null);
}
} else {
((NodeInstanceContainer) getNodeInstanceContainer()).setState(ProcessInstance.STATE_COMPLETED);
}
} else {
((NodeInstanceContainer) getNodeInstanceContainer()).nodeInstanceCompleted(this, null);
}
if (!hidden) {
((InternalProcessRuntime) kruntime.getProcessRuntime()).getProcessEventSupport().fireAfterNodeLeft(this, kruntime);
}
}
use of org.drools.core.common.InternalKnowledgeRuntime in project jbpm by kiegroup.
the class NodeInstanceImpl method cancel.
public void cancel() {
nodeInstanceContainer.removeNodeInstance(this);
boolean hidden = false;
Node node = getNode();
if (node != null && node.getMetaData().get("hidden") != null) {
hidden = true;
}
if (!hidden) {
InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime();
((InternalProcessRuntime) kruntime.getProcessRuntime()).getProcessEventSupport().fireAfterNodeLeft(this, kruntime);
}
}
use of org.drools.core.common.InternalKnowledgeRuntime in project jbpm by kiegroup.
the class NodeInstanceImpl method trigger.
public final void trigger(NodeInstance from, String type) {
boolean hidden = false;
if (getNode().getMetaData().get("hidden") != null) {
hidden = true;
}
if (from != null) {
int level = ((org.jbpm.workflow.instance.NodeInstance) from).getLevel();
((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()).setCurrentLevel(level);
Collection<Connection> incoming = getNode().getIncomingConnections(type);
for (Connection conn : incoming) {
if (conn.getFrom().getId() == from.getNodeId()) {
this.metaData.put("IncomingConnection", conn.getMetaData().get("UniqueId"));
break;
}
}
}
configureSla();
InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime();
if (!hidden) {
((InternalProcessRuntime) kruntime.getProcessRuntime()).getProcessEventSupport().fireBeforeNodeTriggered(this, kruntime);
}
try {
getExecutionErrorHandler().processing(this);
internalTrigger(from, type);
} catch (WorkflowRuntimeException e) {
throw e;
} catch (Exception e) {
throw new WorkflowRuntimeException(this, getProcessInstance(), e);
}
if (!hidden) {
((InternalProcessRuntime) kruntime.getProcessRuntime()).getProcessEventSupport().fireAfterNodeTriggered(this, kruntime);
}
}
Aggregations