Skip to content

[incubator-kie-issues-1109] Add capability to extends the flow builder #3497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.jbpm.ruleflow.core.factory.EndNodeFactory;
import org.jbpm.ruleflow.core.factory.EventNodeFactory;
import org.jbpm.ruleflow.core.factory.EventSubProcessNodeFactory;
import org.jbpm.ruleflow.core.factory.ExtendedNodeFactory;
import org.jbpm.ruleflow.core.factory.FaultNodeFactory;
import org.jbpm.ruleflow.core.factory.ForEachNodeFactory;
import org.jbpm.ruleflow.core.factory.HumanTaskNodeFactory;
Expand All @@ -48,10 +49,32 @@
import org.jbpm.ruleflow.core.factory.ThrowLinkNodeFactory;
import org.jbpm.ruleflow.core.factory.TimerNodeFactory;
import org.jbpm.ruleflow.core.factory.WorkItemNodeFactory;
import org.jbpm.ruleflow.core.factory.provider.NodeFactoryProviderService;
import org.jbpm.workflow.core.Connection;
import org.jbpm.workflow.core.NodeContainer;
import org.jbpm.workflow.core.impl.ConnectionImpl;
import org.jbpm.workflow.core.impl.DroolsConsequenceAction;
import org.jbpm.workflow.core.node.ActionNode;
import org.jbpm.workflow.core.node.BoundaryEventNode;
import org.jbpm.workflow.core.node.CatchLinkNode;
import org.jbpm.workflow.core.node.CompositeContextNode;
import org.jbpm.workflow.core.node.DynamicNode;
import org.jbpm.workflow.core.node.EndNode;
import org.jbpm.workflow.core.node.EventNode;
import org.jbpm.workflow.core.node.EventSubProcessNode;
import org.jbpm.workflow.core.node.FaultNode;
import org.jbpm.workflow.core.node.ForEachNode;
import org.jbpm.workflow.core.node.HumanTaskNode;
import org.jbpm.workflow.core.node.Join;
import org.jbpm.workflow.core.node.MilestoneNode;
import org.jbpm.workflow.core.node.RuleSetNode;
import org.jbpm.workflow.core.node.Split;
import org.jbpm.workflow.core.node.StartNode;
import org.jbpm.workflow.core.node.StateNode;
import org.jbpm.workflow.core.node.SubProcessNode;
import org.jbpm.workflow.core.node.ThrowLinkNode;
import org.jbpm.workflow.core.node.TimerNode;
import org.jbpm.workflow.core.node.WorkItemNode;
import org.kie.api.definition.process.Node;
import org.kie.api.definition.process.WorkflowElementIdentifier;

Expand All @@ -60,97 +83,106 @@
import static org.jbpm.ruleflow.core.Metadata.UNIQUE_ID;
import static org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE;

public abstract class RuleFlowNodeContainerFactory<T extends RuleFlowNodeContainerFactory<T, P>, P extends RuleFlowNodeContainerFactory<P, ?>> extends NodeFactory<T, P> {
public abstract class RuleFlowNodeContainerFactory<T extends RuleFlowNodeContainerFactory<T, P>, P extends RuleFlowNodeContainerFactory<P, ?>> extends ExtendedNodeFactory<T, P> {

public static final String METHOD_CONNECTION = "connection";
public static final String METHOD_ASSOCIATION = "association";

protected RuleFlowNodeContainerFactory(P nodeContainerFactory, NodeContainer nodeContainer, NodeContainer node, WorkflowElementIdentifier id) {
private NodeFactoryProviderService provider;

public RuleFlowNodeContainerFactory(P nodeContainerFactory, NodeContainer nodeContainer, org.jbpm.workflow.core.Node node, WorkflowElementIdentifier id) {
super(nodeContainerFactory, nodeContainer, node, id);
provider = new NodeFactoryProviderService();
}

protected abstract NodeContainer getNodeContainer();

public <R extends NodeFactory<R, T>> R newNode(Class<?> node, WorkflowElementIdentifier id) {
return provider.newNodeFactory(node, (T) this, getNodeContainer(), id);
}

public StartNodeFactory<T> startNode(WorkflowElementIdentifier id) {
return new StartNodeFactory<>((T) this, (NodeContainer) node, id);
return newNode(StartNode.class, id);
}

public EndNodeFactory<T> endNode(WorkflowElementIdentifier id) {
return new EndNodeFactory<>((T) this, (NodeContainer) node, id);
return newNode(EndNode.class, id);
}

public CatchLinkNodeFactory<T> catchLinkNode(WorkflowElementIdentifier id) {
return new CatchLinkNodeFactory<>((T) this, (NodeContainer) node, id);
return newNode(CatchLinkNode.class, id);
}

public ThrowLinkNodeFactory<T> throwLinkNode(WorkflowElementIdentifier id) {
return new ThrowLinkNodeFactory<>((T) this, (NodeContainer) node, id);
return newNode(ThrowLinkNode.class, id);
}

public ActionNodeFactory<T> actionNode(WorkflowElementIdentifier id) {
return new ActionNodeFactory<>((T) this, (NodeContainer) node, id);
return newNode(ActionNode.class, id);
}

public MilestoneNodeFactory<T> milestoneNode(WorkflowElementIdentifier id) {
return new MilestoneNodeFactory<>((T) this, (NodeContainer) node, id);
return newNode(MilestoneNode.class, id);
}

public TimerNodeFactory<T> timerNode(WorkflowElementIdentifier id) {
return new TimerNodeFactory<>((T) this, (NodeContainer) node, id);
return newNode(TimerNode.class, id);
}

public HumanTaskNodeFactory<T> humanTaskNode(WorkflowElementIdentifier id) {
return new HumanTaskNodeFactory<>((T) this, (NodeContainer) node, id);
return newNode(HumanTaskNode.class, id);
}

public SubProcessNodeFactory<T> subProcessNode(WorkflowElementIdentifier id) {
return new SubProcessNodeFactory<>((T) this, (NodeContainer) node, id);
return newNode(SubProcessNode.class, id);
}

public SplitFactory<T> splitNode(WorkflowElementIdentifier id) {
return new SplitFactory<>((T) this, (NodeContainer) node, id);
return newNode(Split.class, id);
}

public JoinFactory<T> joinNode(WorkflowElementIdentifier id) {
return new JoinFactory<>((T) this, (NodeContainer) node, id);
return newNode(Join.class, id);
}

public RuleSetNodeFactory<T> ruleSetNode(WorkflowElementIdentifier id) {
return new RuleSetNodeFactory<>((T) this, (NodeContainer) node, id);
return newNode(RuleSetNode.class, id);
}

public FaultNodeFactory<T> faultNode(WorkflowElementIdentifier id) {
return new FaultNodeFactory<>((T) this, (NodeContainer) node, id);
return newNode(FaultNode.class, id);
}

public EventNodeFactory<T> eventNode(WorkflowElementIdentifier id) {
return new EventNodeFactory<>((T) this, (NodeContainer) node, id);
return newNode(EventNode.class, id);
}

public BoundaryEventNodeFactory<T> boundaryEventNode(WorkflowElementIdentifier id) {
return new BoundaryEventNodeFactory<>((T) this, (NodeContainer) node, id);
return newNode(BoundaryEventNode.class, id);
}

public CompositeContextNodeFactory<T> compositeContextNode(WorkflowElementIdentifier id) {
return new CompositeContextNodeFactory<>((T) this, (NodeContainer) node, id);
return newNode(CompositeContextNode.class, id);
}

public ForEachNodeFactory<T> forEachNode(WorkflowElementIdentifier id) {
return new ForEachNodeFactory<>((T) this, (NodeContainer) node, id);
return newNode(ForEachNode.class, id);
}

public DynamicNodeFactory<T> dynamicNode(WorkflowElementIdentifier id) {
return new DynamicNodeFactory<>((T) this, (NodeContainer) node, id);
return newNode(DynamicNode.class, id);
}

public WorkItemNodeFactory<T> workItemNode(WorkflowElementIdentifier id) {
return new WorkItemNodeFactory<>((T) this, (NodeContainer) node, id);
return newNode(WorkItemNode.class, id);
}

public EventSubProcessNodeFactory<T> eventSubProcessNode(WorkflowElementIdentifier id) {
return new EventSubProcessNodeFactory<>((T) this, (NodeContainer) node, id);
return newNode(EventSubProcessNode.class, id);
}

public StateNodeFactory<T> stateNode(WorkflowElementIdentifier id) {
return new StateNodeFactory<>((T) this, (NodeContainer) node, id);
return newNode(StateNode.class, id);
}

public T connection(WorkflowElementIdentifier fromId, WorkflowElementIdentifier toId) {
Expand All @@ -170,8 +202,8 @@ public T association(WorkflowElementIdentifier fromId, WorkflowElementIdentifier
}

private Connection getConnection(WorkflowElementIdentifier fromId, WorkflowElementIdentifier toId, String uniqueId) {
Node from = ((NodeContainer) node).getNode(fromId);
Node to = ((NodeContainer) node).getNode(toId);
Node from = ((NodeContainer) getNodeContainer()).getNode(fromId);
Node to = ((NodeContainer) getNodeContainer()).getNode(toId);
Connection connection = new ConnectionImpl(from, CONNECTION_DEFAULT_TYPE, to, CONNECTION_DEFAULT_TYPE);
if (uniqueId != null) {
connection.setMetaData(UNIQUE_ID, uniqueId);
Expand Down Expand Up @@ -212,7 +244,7 @@ public T errorExceptionHandler(String signalType, String faultCode, String fault
public abstract T variable(String name, DataType type, Object value, String metaDataName, Object metaDataValue);

private <S extends Context> S getScope(String scopeType, Class<S> scopeClass) {
ContextContainer contextContainer = (ContextContainer) node;
ContextContainer contextContainer = (ContextContainer) getNodeContainer();
Context scope = contextContainer.getDefaultContext(scopeType);
if (scope == null) {
try {
Expand All @@ -227,9 +259,9 @@ private <S extends Context> S getScope(String scopeType, Class<S> scopeClass) {
}

public RuleFlowNodeContainerFactory<T, P> addCompensationContext(String contextId) {
if (node instanceof ContextContainer) {
if (getNodeContainer() instanceof ContextContainer) {
CompensationScope compensationScope = new CompensationScope();
ContextContainer contextNode = (ContextContainer) node;
ContextContainer contextNode = (ContextContainer) getNodeContainer();
contextNode.addContext(compensationScope);
contextNode.setDefaultContext(compensationScope);
compensationScope.setContextContainerId(contextId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,13 @@ public static RuleFlowProcessFactory createProcess(String id, boolean autoComple
return new RuleFlowProcessFactory(id, autoComplete);
}

@Override
protected org.jbpm.workflow.core.NodeContainer getNodeContainer() {
return nodeContainer;
}

protected RuleFlowProcessFactory(String id, boolean autoComplete) {
super(null, null, new RuleFlowProcess(), WorkflowElementIdentifierFactory.fromExternalFormat(id));
super(null, new RuleFlowProcess(), null, WorkflowElementIdentifierFactory.fromExternalFormat(id));
getRuleFlowProcess().setAutoComplete(autoComplete);
}

Expand All @@ -111,7 +116,7 @@ public RuleFlowProcessFactory expressionLanguage(String exprLanguage) {
}

protected RuleFlowProcess getRuleFlowProcess() {
return (RuleFlowProcess) node;
return (RuleFlowProcess) nodeContainer;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,15 @@ public abstract class AbstractCompositeNodeFactory<T extends RuleFlowNodeContain
private WorkflowElementIdentifier linkedIncomingNodeId;
private WorkflowElementIdentifier linkedOutgoingNodeId;

protected AbstractCompositeNodeFactory(P nodeContainerFactory, NodeContainer nodeContainer, NodeContainer node, WorkflowElementIdentifier id) {
protected AbstractCompositeNodeFactory(P nodeContainerFactory, NodeContainer nodeContainer, org.jbpm.workflow.core.Node node, WorkflowElementIdentifier id) {
super(nodeContainerFactory, nodeContainer, node, id);
}

@Override
protected NodeContainer getNodeContainer() {
return getCompositeNode();
}

protected CompositeContextNode getCompositeNode() {
return (CompositeContextNode) node;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,5 @@ public ActionNodeFactory<T> action(Action action) {
getActionNode().setAction(droolsAction);
return this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ public DynamicNodeFactory<T> completionExpression(Predicate<ProcessContext> comp
getDynamicNode().setCompletionExpression(completionExpression);
return this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@
*/
package org.jbpm.ruleflow.core.factory;

import java.util.ArrayList;

import org.jbpm.process.instance.impl.Action;
import org.jbpm.ruleflow.core.RuleFlowNodeContainerFactory;
import org.jbpm.workflow.core.Node;
import org.jbpm.workflow.core.NodeContainer;
import org.jbpm.workflow.core.impl.DroolsConsequenceAction;
import org.jbpm.workflow.core.impl.ExtendedNodeImpl;
import org.kie.api.definition.process.WorkflowElementIdentifier;

Expand All @@ -34,4 +38,23 @@ protected ExtendedNodeImpl getExtendedNode() {
return (ExtendedNodeImpl) getNode();
}

public T onEntryAction(String dialect, String action) {
return onActionScript(ExtendedNodeImpl.EVENT_NODE_ENTER, dialect, action, null);
}

public T onExitAction(String dialect, String action) {
return onActionScript(ExtendedNodeImpl.EVENT_NODE_EXIT, dialect, action, null);
}

public T onActionScript(String type, String dialect, String script, Action compiledScript) {
DroolsConsequenceAction action = new DroolsConsequenceAction(dialect, script);
if (compiledScript != null) {
action.setMetaData("Action", compiledScript);
}
if (getExtendedNode().getActions(type) == null) {
getExtendedNode().setActions(type, new ArrayList<>());
}
getExtendedNode().getActions(type).add(action);
return (T) this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,10 @@
*/
package org.jbpm.ruleflow.core.factory;

import java.util.ArrayList;

import org.jbpm.process.core.context.variable.Mappable;
import org.jbpm.process.instance.impl.Action;
import org.jbpm.ruleflow.core.RuleFlowNodeContainerFactory;
import org.jbpm.workflow.core.Node;
import org.jbpm.workflow.core.NodeContainer;
import org.jbpm.workflow.core.impl.DroolsConsequenceAction;
import org.jbpm.workflow.core.impl.ExtendedNodeImpl;
import org.kie.api.definition.process.WorkflowElementIdentifier;

public abstract class NodeFactory<T extends NodeFactory<T, P>, P extends RuleFlowNodeContainerFactory<P, ?>> implements MappableNodeFactory<T> {
Expand Down Expand Up @@ -76,27 +71,4 @@ public Mappable getMappableNode() {
return (Mappable) node;
}

public T onEntryAction(String dialect, String action) {
return onActionScript(ExtendedNodeImpl.EVENT_NODE_ENTER, dialect, action, null);
}

public T onExitAction(String dialect, String action) {
return onActionScript(ExtendedNodeImpl.EVENT_NODE_EXIT, dialect, action, null);
}

public T onActionScript(String type, String dialect, String script, Action compiledScript) {
DroolsConsequenceAction action = new DroolsConsequenceAction(dialect, script);
if (compiledScript != null) {
action.setMetaData("Action", compiledScript);
}
if (getExtendedNode().getActions(type) == null) {
getExtendedNode().setActions(type, new ArrayList<>());
}
getExtendedNode().getActions(type).add(action);
return (T) this;
}

private ExtendedNodeImpl getExtendedNode() {
return (ExtendedNodeImpl) getNode();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jbpm.ruleflow.core.factory.provider;

import org.jbpm.ruleflow.core.RuleFlowNodeContainerFactory;
import org.jbpm.ruleflow.core.factory.ActionNodeFactory;
import org.jbpm.ruleflow.core.factory.NodeFactory;
import org.jbpm.workflow.core.NodeContainer;
import org.jbpm.workflow.core.node.ActionNode;
import org.kie.api.definition.process.WorkflowElementIdentifier;

public class ActionNodeFactoryProvider implements NodeFactoryProvider {
@Override
public boolean accept(Class<?> type) {
return ActionNode.class.equals(type);
}

@Override
public <R extends NodeFactory<R, P>, P extends RuleFlowNodeContainerFactory<P, ?>> R provide(P nodeContainerFactory, NodeContainer container, WorkflowElementIdentifier id) {
return (R) new ActionNodeFactory<P>(nodeContainerFactory, container, id);
}
}
Loading
Loading