use of org.kie.kogito.internal.process.runtime.KogitoNodeInstance in project kogito-runtimes by kiegroup.
the class TimerNodeInstance method internalTrigger.
@Override
public void internalTrigger(KogitoNodeInstance from, String type) {
if (!Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
throw new IllegalArgumentException("A TimerNode only accepts default incoming connections!");
}
triggerTime = new Date();
ExpirationTime expirationTime = createTimerInstance(getTimerNode().getTimer());
if (getTimerInstances() == null) {
addTimerListener();
}
ProcessInstanceJobDescription jobDescription = ProcessInstanceJobDescription.of(new TimerJobId(getTimerNode().getTimer().getId()), expirationTime, getProcessInstance().getStringId(), getProcessInstance().getRootProcessInstanceId(), getProcessInstance().getProcessId(), getProcessInstance().getRootProcessId(), Optional.ofNullable(from).map(KogitoNodeInstance::getStringId).orElse(null));
JobsService jobService = InternalProcessRuntime.asKogitoProcessRuntime(getProcessInstance().getKnowledgeRuntime().getProcessRuntime()).getJobsService();
timerId = jobService.scheduleProcessInstanceJob(jobDescription);
}
use of org.kie.kogito.internal.process.runtime.KogitoNodeInstance in project kogito-runtimes by kiegroup.
the class AbstractProcessInstance method workItems.
@Override
public List<WorkItem> workItems(Predicate<KogitoNodeInstance> p, Policy<?>... policies) {
List<WorkItem> list = new ArrayList<>();
for (NodeInstance ni : processInstance().getNodeInstances(true)) {
if (p.test(ni) && ((WorkItemNodeInstance) ni).getWorkItem().enforce(policies)) {
BaseWorkItem taskName = new BaseWorkItem(ni.getStringId(), ((WorkItemNodeInstance) ni).getWorkItemId(), Long.toString(ni.getNode().getId()), (String) ((WorkItemNodeInstance) ni).getWorkItem().getParameters().getOrDefault("TaskName", ni.getNodeName()), ((WorkItemNodeInstance) ni).getWorkItem().getState(), ((WorkItemNodeInstance) ni).getWorkItem().getPhaseId(), ((WorkItemNodeInstance) ni).getWorkItem().getPhaseStatus(), ((WorkItemNodeInstance) ni).getWorkItem().getParameters(), ((WorkItemNodeInstance) ni).getWorkItem().getResults());
list.add(taskName);
}
}
return list;
}
use of org.kie.kogito.internal.process.runtime.KogitoNodeInstance in project kogito-runtimes by kiegroup.
the class MockNodeInstance method internalTrigger.
public void internalTrigger(KogitoNodeInstance from, String type) {
if (type == null) {
throw new IllegalArgumentException("Trigger type is null!");
}
triggerTime = new Date();
List<NodeInstance> list = triggers.get(type);
if (list == null) {
list = new ArrayList<NodeInstance>();
triggers.put(type, list);
}
list.add(from);
}
use of org.kie.kogito.internal.process.runtime.KogitoNodeInstance in project kogito-runtimes by kiegroup.
the class ProtobufProcessInstanceReader method buildWorkflow.
private RuleFlowProcessInstance buildWorkflow(KogitoProcessInstanceProtobuf.ProcessInstance processInstanceProtobuf) {
RuleFlowProcessInstance processInstance = ruleFlowProcessInstance;
processInstance.setProcess(((AbstractProcess<?>) context.get(MarshallerContextName.MARSHALLER_PROCESS)).get());
processInstance.setId(processInstanceProtobuf.getId());
processInstance.setProcessId(processInstanceProtobuf.getProcessId());
processInstance.setState(processInstanceProtobuf.getState());
processInstance.setSignalCompletion(processInstanceProtobuf.getSignalCompletion());
processInstance.setStartDate(new Date(processInstanceProtobuf.getStartDate()));
processInstance.setDescription(processInstanceProtobuf.getDescription());
processInstance.setDeploymentId(processInstanceProtobuf.getDeploymentId());
for (String completedNodeId : processInstanceProtobuf.getCompletedNodeIdsList()) {
processInstance.addCompletedNodeId(completedNodeId);
}
processInstance.setCorrelationKey(processInstanceProtobuf.getBusinessKey());
SLAContext slaContext = processInstanceProtobuf.getSla();
if (slaContext.getSlaDueDate() > 0) {
processInstance.internalSetSlaDueDate(new Date(slaContext.getSlaDueDate()));
}
processInstance.internalSetSlaTimerId(slaContext.getSlaTimerId());
processInstance.internalSetSlaCompliance(slaContext.getSlaCompliance());
processInstance.setParentProcessInstanceId(processInstanceProtobuf.getParentProcessInstanceId());
processInstance.setRootProcessInstanceId(processInstanceProtobuf.getRootProcessInstanceId());
processInstance.setRootProcessId(processInstanceProtobuf.getRootProcessId());
processInstance.internalSetErrorNodeId(processInstanceProtobuf.getErrorNodeId());
processInstance.internalSetErrorMessage(processInstanceProtobuf.getErrorMessage());
processInstance.setReferenceId(processInstanceProtobuf.getReferenceId());
if (processInstanceProtobuf.getSwimlaneContextCount() > 0) {
SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance) processInstance.getContextInstance(SwimlaneContext.SWIMLANE_SCOPE);
for (KogitoTypesProtobuf.SwimlaneContext _swimlane : processInstanceProtobuf.getSwimlaneContextList()) {
swimlaneContextInstance.setActorId(_swimlane.getSwimlane(), _swimlane.getActorId());
}
}
WorkflowContext workflowContext = processInstanceProtobuf.getContext();
for (KogitoTypesProtobuf.NodeInstance nodeInstanceProtobuf : workflowContext.getNodeInstanceList()) {
NodeInstanceImpl nodeInstanceImpl = buildNodeInstance(nodeInstanceProtobuf, processInstance);
if (nodeInstanceProtobuf.hasTriggerDate()) {
nodeInstanceImpl.internalSetTriggerTime(new Date(nodeInstanceProtobuf.getTriggerDate()));
}
}
for (KogitoTypesProtobuf.NodeInstanceGroup group : workflowContext.getExclusiveGroupList()) {
Function<String, KogitoNodeInstance> finder = nodeInstanceId -> processInstance.getNodeInstance(nodeInstanceId, true);
processInstance.addContextInstance(ExclusiveGroup.EXCLUSIVE_GROUP, buildExclusiveGroupInstance(group, finder));
}
processInstance.addContextInstance(VariableScope.VARIABLE_SCOPE, new VariableScopeInstance());
if (workflowContext.getVariableCount() > 0) {
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) processInstance.getContextInstance(VariableScope.VARIABLE_SCOPE);
varReader.buildVariables(workflowContext.getVariableList()).forEach(v -> variableScopeInstance.internalSetVariable(v.getName(), v.getValue()));
}
if (workflowContext.getIterationLevelsCount() > 0) {
processInstance.getIterationLevels().putAll(buildIterationLevels(workflowContext.getIterationLevelsList()));
}
return processInstance;
}
use of org.kie.kogito.internal.process.runtime.KogitoNodeInstance in project kogito-runtimes by kiegroup.
the class ProtobufProcessInstanceReader method buildWorkflowContext.
private void buildWorkflowContext(CompositeContextNodeInstance container, WorkflowContext workflowContext) {
if (workflowContext.getNodeInstanceCount() > 0) {
for (KogitoTypesProtobuf.NodeInstance nodeInstanceProtobuf : workflowContext.getNodeInstanceList()) {
buildNodeInstance(nodeInstanceProtobuf, container);
}
}
for (KogitoTypesProtobuf.NodeInstanceGroup group : workflowContext.getExclusiveGroupList()) {
Function<String, KogitoNodeInstance> finder = nodeInstanceId -> container.getNodeInstance(nodeInstanceId, true);
container.addContextInstance(ExclusiveGroup.EXCLUSIVE_GROUP, buildExclusiveGroupInstance(group, finder));
}
container.addContextInstance(VariableScope.VARIABLE_SCOPE, new VariableScopeInstance());
if (workflowContext.getVariableCount() > 0) {
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) container.getContextInstance(VariableScope.VARIABLE_SCOPE);
varReader.buildVariables(workflowContext.getVariableList()).forEach(v -> variableScopeInstance.internalSetVariable(v.getName(), v.getValue()));
}
if (workflowContext.getIterationLevelsCount() > 0) {
container.getIterationLevels().putAll(buildIterationLevels(workflowContext.getIterationLevelsList()));
}
}
Aggregations