Search in sources :

Example 1 with UNIQUE_ID

use of org.jbpm.ruleflow.core.Metadata.UNIQUE_ID 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) 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)

Aggregations

ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1 UUID (java.util.UUID)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 Matcher (java.util.regex.Matcher)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 InternalKnowledgeRuntime (org.drools.core.common.InternalKnowledgeRuntime)1 MVELEvaluator (org.drools.mvel.util.MVELEvaluator)1