private List<KiePackage> getProcessTimer() { RuleFlowProcess process = new RuleFlowProcess(); process.setId( "org.drools.test.TestProcess" ); process.setName( "TestProcess" ); process.setPackageName( "org.drools.test" ); StartNode start = new StartNode(); start.setId( 1 ); start.setName( "Start" ); new ConnectionImpl( start, Node.CONNECTION_DEFAULT_TYPE, timerNode, Node.CONNECTION_DEFAULT_TYPE ); ActionNode actionNode = new ActionNode(); actionNode.setId( 3 ); actionNode.setName( "Action" ); DroolsConsequenceAction action = new DroolsConsequenceAction(); action.setDialect( "java" ); action.setConsequence( "System.out.println(\"Executed action\");" );
public void build(Process process, ProcessDescr processDescr, ProcessBuildContext context, Node node) { ActionNode actionNode = ( ActionNode ) node; DroolsConsequenceAction action = (DroolsConsequenceAction) actionNode.getAction(); ActionDescr actionDescr = new ActionDescr(); actionDescr.setText( action.getConsequence() ); actionDescr.setResource(processDescr.getResource()); ProcessDialect dialect = ProcessDialectRegistry.getDialect( action.getDialect() ); dialect.getActionBuilder().build( context, action, actionDescr, (NodeImpl) node ); }
public static void writeAction(final DroolsAction action, final StringBuilder xmlDump) { if (action instanceof DroolsConsequenceAction) { DroolsConsequenceAction consequenceAction = (DroolsConsequenceAction) action; xmlDump.append(" <action type=\"expression\" "); String name = consequenceAction.getName(); if (name != null) { xmlDump.append("name=\"" + name + "\" "); } String dialect = consequenceAction.getDialect(); if (dialect != null) { xmlDump.append("dialect=\"" + dialect + "\" "); } String consequence = consequenceAction.getConsequence(); if (consequence == null) { xmlDump.append("/>" + EOL); } else { xmlDump.append(">" + XmlDumper.replaceIllegalChars(consequence.trim()) + "</action>" + EOL); } } else { throw new IllegalArgumentException( "Unknown action " + action); } }
ActionNode actionNode = (ActionNode) node; node.setMetaData("NodeType", "ScriptTask"); DroolsConsequenceAction action = (DroolsConsequenceAction) actionNode.getAction(); if (action == null) { action = new DroolsConsequenceAction(); actionNode.setAction(action); action.setDialect(JavaDialect.ID); } else if (XmlBPMNProcessDumper.JAVASCRIPT_LANGUAGE.equals(language)) { action.setDialect("JavaScript"); action.setConsequence(""); org.w3c.dom.Node xmlNode = element.getFirstChild(); while (xmlNode != null) { if (xmlNode instanceof Element && "script".equals(xmlNode.getNodeName())) { action.setConsequence(xmlNode.getTextContent()); boolean isForCompensation = Boolean.parseBoolean(compensation); if( isForCompensation ) { actionNode.setMetaData("isForCompensation", isForCompensation );
private static void linkBoundarySignalEvent(NodeContainer nodeContainer, Node node, String attachedTo, Node attachedNode) { boolean cancelActivity = (Boolean) node.getMetaData().get("CancelActivity"); if (cancelActivity) { List<DroolsAction> actions = ((EventNode)node).getActions(EndNode.EVENT_NODE_EXIT); if (actions == null) { actions = new ArrayList<DroolsAction>(); } DroolsConsequenceAction action = new DroolsConsequenceAction("java", null); action.setMetaData("Action", new CancelNodeInstanceAction(attachedTo)); actions.add(action); ((EventNode)node).setActions(EndNode.EVENT_NODE_EXIT, actions); } }
DroolsConsequenceAction action = new DroolsConsequenceAction("dialect", "consequence"); exceptionHandler.setFaultVariable("faultVariable2"); action = new DroolsConsequenceAction("dialect2", "consequence2"); action = new DroolsConsequenceAction("dialect", "consequence"); timer.setDelay("100"); timer.setPeriod("100"); action = new DroolsConsequenceAction("dialect", "consequence"); ruleSetNode.addTimer(timer, action); timer = new Timer(); timer.setDelay("200"); timer.setPeriod("200"); action = new DroolsConsequenceAction("dialect", "consequence"); timer.setDelay("100"); timer.setPeriod("100"); action = new DroolsConsequenceAction("dialect", "consequence"); milestone.addTimer(timer, action); timer = new Timer(); timer.setDelay("200"); timer.setPeriod("200"); action = new DroolsConsequenceAction("dialect", "consequence"); milestone.addTimer(timer, action); List<DroolsAction> actions = new ArrayList<DroolsAction>(); DroolsAction action1 = new DroolsConsequenceAction("java", "System.out.println(\"action1\");"); actions.add(action1); DroolsAction action2 = new DroolsConsequenceAction("java", "System.out.println(\"action2\");");
if (nodeParent instanceof EventSubProcessNode) { boolean compensationEventSubProcess = false; List<Trigger> startTriggers = ((EventSubProcessNode) nodeParent).findStartNode().getTriggers(); CESP_CHECK: for (Trigger trigger : startTriggers) { if (trigger instanceof EventTrigger) { parentId = ((RuleFlowProcess) nodeParent).getId(); } else { parentId = (String) ((NodeImpl) nodeParent).getMetaData("UniqueId"); DroolsConsequenceAction compensationAction = new DroolsConsequenceAction("java", PROCESS_INSTANCE_SIGNAL_EVENT + "Compensation\", \"" + compensationEvent + "\");"); ((ActionNode) throwEventNode).setAction(compensationAction); } else if (throwEventNode instanceof EndNode) { List<DroolsAction> actions = new ArrayList<DroolsAction>(); actions.add(compensationAction); ((EndNode) throwEventNode).setActions(EndNode.EVENT_NODE_ENTER, actions);
ActionNode actionNode = new ActionNode(); DroolsAction action = new DroolsConsequenceAction("mvel", null); actionNode.setAction(action); ((MVELAction) actionNode.getAction().getMetaData("Action")).compile( data );
private static void linkBoundaryConditionEvent(NodeContainer nodeContainer, Node node, String attachedTo, Node attachedNode) { String processId = ((RuleFlowProcess) nodeContainer).getId(); String eventType = "RuleFlowStateEvent-" + processId + "-" + ((EventNode) node).getUniqueId() + "-" + attachedTo; ((EventTypeFilter) ((EventNode) node).getEventFilters().get(0)).setType(eventType); boolean cancelActivity = (Boolean) node.getMetaData().get("CancelActivity"); if (cancelActivity) { List<DroolsAction> actions = ((EventNode) node).getActions(EndNode.EVENT_NODE_EXIT); if (actions == null) { actions = new ArrayList<DroolsAction>(); } DroolsConsequenceAction action = new DroolsConsequenceAction("java", null); action.setMetaData("Action", new CancelNodeInstanceAction(attachedTo)); actions.add(action); ((EventNode) node).setActions(EndNode.EVENT_NODE_EXIT, actions); } }
public static DroolsAction extractAction(Element xmlNode) { String actionType = xmlNode.getAttribute("type"); if ("expression".equals(actionType)) { String consequence = xmlNode.getTextContent(); DroolsConsequenceAction action = new DroolsConsequenceAction(xmlNode.getAttribute("dialect"), consequence); return action; } else { throw new IllegalArgumentException( "Unknown action type " + actionType); } }
"Start has no outgoing connection."); if (endNode.getFrom() == null) { addErrorMessage(process, node, if (actionNode.getFrom() == null && !acceptsNoIncomingConnections(node)) { addErrorMessage(process, node, "Action has no incoming connection."); String actionString = droolsAction.getConsequence(); if (actionString == null) { addErrorMessage(process, errors, "Action has empty action."); } else if ("mvel".equals(droolsAction.getDialect())) { try { ParserContext parserContext = new ParserContext(); final List<Node> start = RuleFlowProcess.getStartNodes(forEachNode.getNodes()); if (start != null) { for (Node s : start) {
protected Node createNode(Attributes attrs) { ActionNode result = new ActionNode(); result.setAction(new DroolsConsequenceAction()); return result; }
actionNode.setMetaData("isForCompensation", true); actionNode.setName("Execute"); DroolsAction action = new DroolsConsequenceAction("java", null); action.setMetaData("Action", new Action() { public void execute(ProcessContext context) throws Exception { actionNode.setAction(action); connect( boundaryNode, actionNode );
public ActionNodeFactory action(String dialect, String action, boolean isDroolsAction) { if(isDroolsAction) { DroolsAction droolsAction = new DroolsAction(); droolsAction.setMetaData("Action", action); getActionNode().setAction(droolsAction); } else { getActionNode().setAction(new DroolsConsequenceAction(dialect, action)); } return this; }
ActionNode actionNode = (ActionNode) node; DroolsConsequenceAction action = null; if (actionNode.getAction() instanceof DroolsConsequenceAction) { action = (DroolsConsequenceAction) actionNode.getAction(); } else { logger.warn("Cannot serialize custom implementation of the Action interface to XML"); String eventType = (String) actionNode.getMetaData("EventType"); String ref = (String) actionNode.getMetaData("Ref"); String variableRef = (String) actionNode.getMetaData("Variable"); String s = action.getConsequence(); if (s.startsWith("org.drools.core.process.instance.impl.WorkItemImpl workItem = new org.drools.core.process.instance.impl.WorkItemImpl();")) { writeNode("intermediateThrowEvent", xmlDump, metaDataType); if (JavaDialect.ID.equals(action.getDialect())) { xmlDump.append("scriptFormat=\"" + XmlBPMNProcessDumper.JAVA_LANGUAGE + "\" "); } else if ("JavaScript".equals(action.getDialect())) { xmlDump.append("scriptFormat=\"" + XmlBPMNProcessDumper.JAVASCRIPT_LANGUAGE + "\" "); writeExtensionElements(actionNode, xmlDump); if (action.getConsequence() != null) { xmlDump.append(" <script>" + XmlDumper.replaceIllegalChars(action.getConsequence()) + "</script>" + EOL);
public void writeNode(Node node, StringBuilder xmlDump, int metaDataType) { EndNode endNode = (EndNode) node; String eventType = (String) endNode.getMetaData("EventType"); String ref = (String) endNode.getMetaData("Ref"); String variableRef = (String) endNode.getMetaData("Variable"); if (actions.size() == 1) { DroolsConsequenceAction action = (DroolsConsequenceAction) actions.get(0); String s = action.getConsequence(); if (s.startsWith("org.drools.core.process.instance.impl.WorkItemImpl workItem = new org.drools.core.process.instance.impl.WorkItemImpl();")) { xmlDump.append(">" + EOL);
protected void buildAction(DroolsAction droolsAction, ProcessBuildContext context, NodeImpl node) { DroolsConsequenceAction action = (DroolsConsequenceAction) droolsAction; ActionDescr actionDescr = new ActionDescr(); actionDescr.setText( action.getConsequence() ); actionDescr.setResource(context.getProcessDescr().getResource()); ProcessDialect dialect = ProcessDialectRegistry.getDialect( action.getDialect() ); dialect.getActionBuilder().build( context, action, actionDescr, node); }
if(actionNode.getAction() instanceof DroolsConsequenceAction) { DroolsConsequenceAction action = (DroolsConsequenceAction) actionNode.getAction(); if (action != null) { String s = action.getConsequence(); if (s.startsWith("org.drools.core.process.instance.context.exception.ExceptionScopeInstance scopeInstance = (org.drools.core.process.instance.context.exception.ExceptionScopeInstance) ((org.drools.workflow.instance.NodeInstance) kcontext.getNodeInstance()).resolveContextInstance(org.drools.core.process.core.context.exception.ExceptionScope.EXCEPTION_SCOPE, \"")) { s = s.substring(327);
if( nodeParent instanceof EventSubProcessNode ) { boolean compensationEventSubProcess = false; List<Trigger> startTriggers = ((EventSubProcessNode) nodeParent).findStartNode().getTriggers(); CESP_CHECK: for( Trigger trigger : startTriggers ) { if( trigger instanceof EventTrigger ) { parentId = ((RuleFlowProcess) nodeParent).getId(); } else { parentId = (String) ((NodeImpl) nodeParent).getMetaData("UniqueId"); DroolsConsequenceAction compensationAction = new DroolsConsequenceAction("java", PROCESS_INSTANCE_SIGNAL_EVENT + "Compensation\", \"" + compensationEvent + "\");"); ((ActionNode) throwEventNode).setAction(compensationAction); } else if( throwEventNode instanceof EndNode ) { List<DroolsAction> actions = new ArrayList<DroolsAction>(); actions.add(compensationAction); ((EndNode) throwEventNode).setActions(EndNode.EVENT_NODE_ENTER, actions);
private static void linkBoundarySignalEvent(NodeContainer nodeContainer, Node node, String attachedTo, Node attachedNode) { boolean cancelActivity = (Boolean) node.getMetaData().get("CancelActivity"); if (cancelActivity) { List<DroolsAction> actions = ((EventNode) node).getActions(EndNode.EVENT_NODE_EXIT); if (actions == null) { actions = new ArrayList<DroolsAction>(); } DroolsConsequenceAction action = new DroolsConsequenceAction("java", null); action.setMetaData("Action", new CancelNodeInstanceAction(attachedTo)); actions.add(action); ((EventNode) node).setActions(EndNode.EVENT_NODE_EXIT, actions); } }