Search in sources :

Example 1 with NamedDataType

use of org.kie.kogito.process.NamedDataType in project kogito-runtimes by kiegroup.

the class WorkflowProcessInstanceImpl method getEventDescriptions.

@Override
public Set<EventDescription<?>> getEventDescriptions() {
    if (getState() == KogitoProcessInstance.STATE_COMPLETED || getState() == KogitoProcessInstance.STATE_ABORTED) {
        return Collections.emptySet();
    }
    VariableScope variableScope = (VariableScope) ((ContextContainer) getProcess()).getDefaultContext(VariableScope.VARIABLE_SCOPE);
    Set<EventDescription<?>> eventDesciptions = new LinkedHashSet<>();
    List<KogitoEventListener> activeListeners = eventListeners.values().stream().flatMap(List::stream).collect(Collectors.toList());
    activeListeners.addAll(externalEventListeners.values().stream().flatMap(List::stream).collect(Collectors.toList()));
    activeListeners.forEach(el -> eventDesciptions.addAll(el.getEventDescriptions()));
    ((org.jbpm.workflow.core.WorkflowProcess) getProcess()).getNodesRecursively().stream().filter(n -> n instanceof EventNodeInterface).forEach(n -> {
        NamedDataType dataType = null;
        if (((EventNodeInterface) n).getVariableName() != null) {
            Variable eventVar = variableScope.findVariable(((EventNodeInterface) n).getVariableName());
            if (eventVar != null) {
                dataType = new NamedDataType(eventVar.getName(), eventVar.getType());
            }
        }
        if (n instanceof BoundaryEventNode) {
            BoundaryEventNode boundaryEventNode = (BoundaryEventNode) n;
            StateBasedNodeInstance attachedToNodeInstance = (StateBasedNodeInstance) getNodeInstances(true).stream().filter(ni -> ni.getNode().getMetaData().get(UNIQUE_ID).equals(boundaryEventNode.getAttachedToNodeId())).findFirst().orElse(null);
            if (attachedToNodeInstance != null) {
                Map<String, String> properties = new HashMap<>();
                properties.put("AttachedToID", attachedToNodeInstance.getNodeDefinitionId());
                properties.put("AttachedToName", attachedToNodeInstance.getNodeName());
                String eventType = EVENT_TYPE_SIGNAL;
                String eventName = boundaryEventNode.getType();
                Map<String, String> timerProperties = attachedToNodeInstance.extractTimerEventInformation();
                if (timerProperties != null) {
                    properties.putAll(timerProperties);
                    eventType = "timer";
                    eventName = "timerTriggered";
                }
                eventDesciptions.add(new BaseEventDescription(eventName, (String) n.getMetaData().get(UNIQUE_ID), n.getName(), eventType, null, getStringId(), dataType, properties));
            }
        } else if (n instanceof EventSubProcessNode) {
            EventSubProcessNode eventSubProcessNode = (EventSubProcessNode) n;
            org.kie.api.definition.process.Node startNode = eventSubProcessNode.findStartNode();
            Map<Timer, DroolsAction> timers = eventSubProcessNode.getTimers();
            if (timers != null && !timers.isEmpty()) {
                getNodeInstances(eventSubProcessNode.getId()).forEach(ni -> {
                    Map<String, String> timerProperties = ((StateBasedNodeInstance) ni).extractTimerEventInformation();
                    if (timerProperties != null) {
                        eventDesciptions.add(new BaseEventDescription("timerTriggered", (String) startNode.getMetaData().get("UniqueId"), startNode.getName(), "timer", ni.getStringId(), getStringId(), null, timerProperties));
                    }
                });
            } else {
                for (String eventName : eventSubProcessNode.getEvents()) {
                    eventDesciptions.add(new BaseEventDescription(eventName, (String) startNode.getMetaData().get("UniqueId"), startNode.getName(), "signal", null, getStringId(), dataType));
                }
            }
        } else if (n instanceof EventNode) {
            NamedDataType finalDataType = dataType;
            getNodeInstances(n.getId()).forEach(ni -> eventDesciptions.add(new BaseEventDescription(((EventNode) n).getType(), (String) n.getMetaData().get(UNIQUE_ID), n.getName(), (String) n.getMetaData().getOrDefault(EVENT_TYPE, EVENT_TYPE_SIGNAL), ni.getStringId(), getStringId(), finalDataType)));
        } else if (n instanceof StateNode) {
            getNodeInstances(n.getId()).forEach(ni -> eventDesciptions.add(new BaseEventDescription((String) n.getMetaData().get(CONDITION), (String) n.getMetaData().get(UNIQUE_ID), n.getName(), (String) n.getMetaData().getOrDefault(EVENT_TYPE, EVENT_TYPE_SIGNAL), ni.getStringId(), getStringId(), null)));
        }
    });
    return eventDesciptions;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Milestone(org.kie.kogito.process.flexible.Milestone) ProcessInstanceJobDescription(org.kie.kogito.jobs.ProcessInstanceJobDescription) Date(java.util.Date) EventNodeInstanceInterface(org.jbpm.workflow.instance.node.EventNodeInstanceInterface) EventBasedNodeInstanceInterface(org.jbpm.workflow.instance.node.EventBasedNodeInstanceInterface) LoggerFactory(org.slf4j.LoggerFactory) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) DynamicNode(org.jbpm.workflow.core.node.DynamicNode) StartNode(org.jbpm.workflow.core.node.StartNode) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) PatternConstants(org.jbpm.util.PatternConstants) NamedDataType(org.kie.kogito.process.NamedDataType) NodeImpl(org.jbpm.workflow.core.impl.NodeImpl) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) EventSubProcessNodeInstance(org.jbpm.workflow.instance.node.EventSubProcessNodeInstance) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) KogitoNodeInstanceContainer(org.kie.kogito.internal.process.runtime.KogitoNodeInstanceContainer) StateNode(org.jbpm.workflow.core.node.StateNode) Matcher(java.util.regex.Matcher) EventNodeInterface(org.jbpm.workflow.core.node.EventNodeInterface) ContextInstance(org.jbpm.process.instance.ContextInstance) CORRELATION_KEY(org.jbpm.ruleflow.core.Metadata.CORRELATION_KEY) Map(java.util.Map) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) UUID(java.util.UUID) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) DurationExpirationTime(org.kie.kogito.jobs.DurationExpirationTime) VariableScope(org.jbpm.process.core.context.variable.VariableScope) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) IS_FOR_COMPENSATION(org.jbpm.ruleflow.core.Metadata.IS_FOR_COMPENSATION) List(java.util.List) Stream(java.util.stream.Stream) ContextContainer(org.jbpm.process.core.ContextContainer) ProcessInstance(org.kie.kogito.process.ProcessInstance) Node(org.jbpm.workflow.core.Node) COMPENSATION(org.jbpm.ruleflow.core.Metadata.COMPENSATION) BusinessCalendar(org.jbpm.process.core.timer.BusinessCalendar) MilestoneNode(org.jbpm.workflow.core.node.MilestoneNode) ACTIVE(org.kie.kogito.process.flexible.ItemDescription.Status.ACTIVE) Optional(java.util.Optional) COMPLETED(org.kie.kogito.process.flexible.ItemDescription.Status.COMPLETED) NodeContainer(org.kie.api.definition.process.NodeContainer) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) StateBasedNodeInstance(org.jbpm.workflow.instance.node.StateBasedNodeInstance) DateTimeUtils(org.jbpm.process.core.timer.DateTimeUtils) EndNodeInstance(org.jbpm.workflow.instance.node.EndNodeInstance) AdHocFragment(org.kie.kogito.process.flexible.AdHocFragment) HashMap(java.util.HashMap) Function(java.util.function.Function) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) ArrayList(java.util.ArrayList) Timer(org.jbpm.process.core.timer.Timer) NodeInstance(org.jbpm.workflow.instance.NodeInstance) FaultNodeInstance(org.jbpm.workflow.instance.node.FaultNodeInstance) CUSTOM_SLA_DUE_DATE(org.jbpm.ruleflow.core.Metadata.CUSTOM_SLA_DUE_DATE) CONDITION(org.jbpm.ruleflow.core.Metadata.CONDITION) EventNodeInstance(org.jbpm.workflow.instance.node.EventNodeInstance) CompositeNodeInstance(org.jbpm.workflow.instance.node.CompositeNodeInstance) DroolsAction(org.jbpm.workflow.core.DroolsAction) LinkedHashSet(java.util.LinkedHashSet) MVELEvaluator(org.drools.mvel.util.MVELEvaluator) Variable(org.jbpm.process.core.context.variable.Variable) AVAILABLE(org.kie.kogito.process.flexible.ItemDescription.Status.AVAILABLE) UNIQUE_ID(org.jbpm.ruleflow.core.Metadata.UNIQUE_ID) InternalKnowledgeRuntime(org.drools.core.common.InternalKnowledgeRuntime) Logger(org.slf4j.Logger) CorrelationKey(org.kie.internal.process.CorrelationKey) Metadata(org.jbpm.ruleflow.core.Metadata) VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) EventNode(org.jbpm.workflow.core.node.EventNode) BaseEventDescription(org.kie.kogito.process.BaseEventDescription) VariableScopeInstance(org.jbpm.process.instance.context.variable.VariableScopeInstance) AgendaFilter(org.kie.api.runtime.rule.AgendaFilter) ProcessInstanceImpl(org.jbpm.process.instance.impl.ProcessInstanceImpl) EVENT_TYPE_SIGNAL(org.jbpm.ruleflow.core.Metadata.EVENT_TYPE_SIGNAL) TimerInstance(org.kie.kogito.timer.TimerInstance) InternalProcessRuntime(org.jbpm.process.instance.InternalProcessRuntime) TimerJobId(org.kie.kogito.jobs.TimerJobId) KogitoEventListener(org.kie.kogito.internal.process.event.KogitoEventListener) ItemDescription(org.kie.kogito.process.flexible.ItemDescription) EventDescription(org.kie.kogito.process.EventDescription) KogitoWorkflowProcess(org.kie.kogito.internal.process.runtime.KogitoWorkflowProcess) Collections(java.util.Collections) EVENT_TYPE(org.jbpm.ruleflow.core.Metadata.EVENT_TYPE) EMPTY_EVENT_LISTENER(org.jbpm.workflow.instance.impl.DummyEventListener.EMPTY_EVENT_LISTENER) Variable(org.jbpm.process.core.context.variable.Variable) HashMap(java.util.HashMap) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) DynamicNode(org.jbpm.workflow.core.node.DynamicNode) StartNode(org.jbpm.workflow.core.node.StartNode) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) StateNode(org.jbpm.workflow.core.node.StateNode) Node(org.jbpm.workflow.core.Node) MilestoneNode(org.jbpm.workflow.core.node.MilestoneNode) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) EventNode(org.jbpm.workflow.core.node.EventNode) StateNode(org.jbpm.workflow.core.node.StateNode) KogitoEventListener(org.kie.kogito.internal.process.event.KogitoEventListener) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventNode(org.jbpm.workflow.core.node.EventNode) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) StateBasedNodeInstance(org.jbpm.workflow.instance.node.StateBasedNodeInstance) EventNodeInterface(org.jbpm.workflow.core.node.EventNodeInterface) BaseEventDescription(org.kie.kogito.process.BaseEventDescription) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) NamedDataType(org.kie.kogito.process.NamedDataType) BaseEventDescription(org.kie.kogito.process.BaseEventDescription) EventDescription(org.kie.kogito.process.EventDescription) Map(java.util.Map) HashMap(java.util.HashMap) VariableScope(org.jbpm.process.core.context.variable.VariableScope)

Example 2 with NamedDataType

use of org.kie.kogito.process.NamedDataType in project kogito-runtimes by kiegroup.

the class WorkItemNodeInstance method getEventDescriptions.

@Override
public Set<EventDescription<?>> getEventDescriptions() {
    List<NamedDataType> inputs = new ArrayList<>();
    for (ParameterDefinition paramDef : getWorkItemNode().getWork().getParameterDefinitions()) {
        inputs.add(new NamedDataType(paramDef.getName(), paramDef.getType()));
    }
    List<NamedDataType> outputs = new ArrayList<>();
    VariableScope variableScope = (VariableScope) getProcessInstance().getContextContainer().getDefaultContext(VARIABLE_SCOPE);
    getWorkItemNode().getOutAssociations().forEach(da -> da.getSources().forEach(s -> outputs.add(new NamedDataType(s.getLabel(), variableScope.findVariable(da.getTarget().getLabel()).getType()))));
    GroupedNamedDataType dataTypes = new GroupedNamedDataType();
    dataTypes.add("Input", inputs);
    dataTypes.add("Output", outputs);
    // return just the main completion type of an event
    return Collections.singleton(new IOEventDescription("workItemCompleted", getNodeDefinitionId(), getNodeName(), "workItem", getWorkItemId(), getProcessInstance().getStringId(), dataTypes));
}
Also used : Arrays(java.util.Arrays) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) NamedDataType(org.kie.kogito.process.NamedDataType) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) GroupedNamedDataType(org.kie.kogito.process.GroupedNamedDataType) STATE_COMPLETED(org.kie.kogito.internal.process.runtime.KogitoProcessInstance.STATE_COMPLETED) ProcessInstance(org.jbpm.process.instance.ProcessInstance) Context(org.jbpm.process.core.Context) ContextInstance(org.jbpm.process.instance.ContextInstance) Map(java.util.Map) WorkItemExecutionException(org.kie.kogito.process.workitem.WorkItemExecutionException) KogitoWorkItemNodeInstance(org.kie.kogito.internal.process.runtime.KogitoWorkItemNodeInstance) ABORTED(org.kie.api.runtime.process.WorkItem.ABORTED) Collection(java.util.Collection) Set(java.util.Set) VARIABLE_SCOPE(org.jbpm.process.core.context.variable.VariableScope.VARIABLE_SCOPE) KogitoProcessContextImpl(org.jbpm.process.instance.KogitoProcessContextImpl) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) VariableScope(org.jbpm.process.core.context.variable.VariableScope) List(java.util.List) ContextContainer(org.jbpm.process.core.ContextContainer) Node(org.jbpm.workflow.core.Node) KieRuntime(org.kie.api.runtime.KieRuntime) Model(org.kie.kogito.Model) ExceptionScopeInstance(org.jbpm.process.instance.context.exception.ExceptionScopeInstance) Entry(java.util.Map.Entry) Work(org.jbpm.process.core.Work) ParameterDefinition(org.jbpm.process.core.ParameterDefinition) InternalKogitoWorkItem(org.kie.kogito.process.workitems.InternalKogitoWorkItem) ExceptionScope(org.jbpm.process.core.context.exception.ExceptionScope) WorkflowRuntimeException(org.jbpm.workflow.instance.WorkflowRuntimeException) AbstractProcessInstance(org.kie.kogito.process.impl.AbstractProcessInstance) ProcessWorkItemHandlerException(org.kie.api.runtime.process.ProcessWorkItemHandlerException) HashMap(java.util.HashMap) KogitoProcessRuntime(org.kie.kogito.internal.process.runtime.KogitoProcessRuntime) Function(java.util.function.Function) ArrayList(java.util.ArrayList) EventListener(org.kie.api.runtime.process.EventListener) NodeIoHelper(org.jbpm.workflow.core.impl.NodeIoHelper) DataAssociation(org.jbpm.workflow.core.impl.DataAssociation) ContextInstanceFactoryRegistry(org.jbpm.process.instance.impl.ContextInstanceFactoryRegistry) ContextInstanceContainer(org.jbpm.process.instance.ContextInstanceContainer) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) Logger(org.slf4j.Logger) STATE_ABORTED(org.kie.kogito.internal.process.runtime.KogitoProcessInstance.STATE_ABORTED) EnvironmentName(org.kie.api.runtime.EnvironmentName) VariableScopeInstance(org.jbpm.process.instance.context.variable.VariableScopeInstance) IOEventDescription(org.kie.kogito.process.IOEventDescription) COMPLETED(org.kie.api.runtime.process.WorkItem.COMPLETED) KogitoWorkItemImpl(org.kie.kogito.process.workitems.impl.KogitoWorkItemImpl) InternalProcessRuntime(org.jbpm.process.instance.InternalProcessRuntime) WorkItemHandlerNotFoundException(org.drools.core.WorkItemHandlerNotFoundException) ContextInstanceFactory(org.jbpm.process.instance.impl.ContextInstanceFactory) EventDescription(org.kie.kogito.process.EventDescription) InternalKogitoWorkItemManager(org.kie.kogito.process.workitems.InternalKogitoWorkItemManager) Processes(org.kie.kogito.process.Processes) Collections(java.util.Collections) NamedDataType(org.kie.kogito.process.NamedDataType) GroupedNamedDataType(org.kie.kogito.process.GroupedNamedDataType) GroupedNamedDataType(org.kie.kogito.process.GroupedNamedDataType) ArrayList(java.util.ArrayList) IOEventDescription(org.kie.kogito.process.IOEventDescription) VariableScope(org.jbpm.process.core.context.variable.VariableScope) ParameterDefinition(org.jbpm.process.core.ParameterDefinition)

Example 3 with NamedDataType

use of org.kie.kogito.process.NamedDataType in project kogito-runtimes by kiegroup.

the class EventNodeInstance method getEventDescriptions.

@Override
public Set<EventDescription<?>> getEventDescriptions() {
    NamedDataType dataType = null;
    if (getEventNode().getVariableName() != null) {
        VariableScope variableScope = (VariableScope) getEventNode().getContext(VariableScope.VARIABLE_SCOPE);
        Variable variable = variableScope.findVariable(getEventNode().getVariableName());
        dataType = new NamedDataType(variable.getName(), variable.getType());
    }
    return Collections.singleton(new BaseEventDescription(getEventType(), getNodeDefinitionId(), getNodeName(), "signal", getStringId(), getProcessInstance().getStringId(), dataType));
}
Also used : NamedDataType(org.kie.kogito.process.NamedDataType) Variable(org.jbpm.process.core.context.variable.Variable) BaseEventDescription(org.kie.kogito.process.BaseEventDescription) VariableScope(org.jbpm.process.core.context.variable.VariableScope)

Aggregations

VariableScope (org.jbpm.process.core.context.variable.VariableScope)3 NamedDataType (org.kie.kogito.process.NamedDataType)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Function (java.util.function.Function)2 ContextContainer (org.jbpm.process.core.ContextContainer)2 Variable (org.jbpm.process.core.context.variable.Variable)2 ContextInstance (org.jbpm.process.instance.ContextInstance)2 InternalProcessRuntime (org.jbpm.process.instance.InternalProcessRuntime)2 VariableScopeInstance (org.jbpm.process.instance.context.variable.VariableScopeInstance)2 Node (org.jbpm.workflow.core.Node)2 WorkflowProcessInstance (org.jbpm.workflow.instance.WorkflowProcessInstance)2 KogitoNodeInstance (org.kie.kogito.internal.process.runtime.KogitoNodeInstance)2 EventDescription (org.kie.kogito.process.EventDescription)2