use of org.jbpm.workflow.core.node.Trigger in project jbpm by kiegroup.
the class StartEventHandler method writeNode.
public void writeNode(Node node, StringBuilder xmlDump, int metaDataType) {
StartNode startNode = (StartNode) node;
writeNode("startEvent", startNode, xmlDump, metaDataType);
xmlDump.append(" isInterrupting=\"");
if (startNode.isInterrupting()) {
xmlDump.append("true");
} else {
xmlDump.append("false");
}
xmlDump.append("\">" + EOL);
writeExtensionElements(startNode, xmlDump);
List<Trigger> triggers = startNode.getTriggers();
if (triggers != null) {
if (triggers.size() > 1) {
throw new IllegalArgumentException("Multiple start triggers not supported");
}
Trigger trigger = triggers.get(0);
if (trigger instanceof ConstraintTrigger) {
ConstraintTrigger constraintTrigger = (ConstraintTrigger) trigger;
if (constraintTrigger.getHeader() == null) {
xmlDump.append(" <conditionalEventDefinition>" + EOL);
xmlDump.append(" <condition xsi:type=\"tFormalExpression\" language=\"" + XmlBPMNProcessDumper.RULE_LANGUAGE + "\">" + constraintTrigger.getConstraint() + "</condition>" + EOL);
xmlDump.append(" </conditionalEventDefinition>" + EOL);
}
} else if (trigger instanceof EventTrigger) {
EventTrigger eventTrigger = (EventTrigger) trigger;
String mapping = null;
String nameMapping = "event";
if (!trigger.getInMappings().isEmpty()) {
mapping = eventTrigger.getInMappings().keySet().iterator().next();
nameMapping = eventTrigger.getInMappings().values().iterator().next();
} else {
mapping = (String) startNode.getMetaData("TriggerMapping");
}
if (mapping != null) {
xmlDump.append(" <dataOutput id=\"_" + startNode.getId() + "_Output\" name=\"" + nameMapping + "\" />" + EOL + " <dataOutputAssociation>" + EOL + " <sourceRef>_" + startNode.getId() + "_Output</sourceRef>" + EOL + " <targetRef>" + mapping + "</targetRef>" + EOL + " </dataOutputAssociation>" + EOL);
}
String type = ((EventTypeFilter) eventTrigger.getEventFilters().get(0)).getType();
if (type.startsWith("Message-")) {
type = type.substring(8);
xmlDump.append(" <messageEventDefinition messageRef=\"" + type + "\"/>" + EOL);
} else if (type.startsWith("Error-")) {
type = type.substring(6);
String errorId = getErrorIdForErrorCode(type, startNode);
xmlDump.append(" <errorEventDefinition errorRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(errorId) + "\"/>" + EOL);
} else if (type.startsWith("Escalation-")) {
type = type.substring(11);
xmlDump.append(" <escalationEventDefinition escalationRef=\"" + type + "\"/>" + EOL);
} else if (type.equals("Compensation")) {
xmlDump.append(" <compensateEventDefinition/>" + EOL);
} else {
xmlDump.append(" <signalEventDefinition signalRef=\"" + type + "\" />" + EOL);
}
} else {
throw new IllegalArgumentException("Unsupported trigger type " + trigger);
}
if (startNode.getTimer() != null) {
Timer timer = startNode.getTimer();
xmlDump.append(" <timerEventDefinition>" + EOL);
if (timer != null && (timer.getDelay() != null || timer.getDate() != null)) {
if (timer.getTimeType() == Timer.TIME_DATE) {
xmlDump.append(" <timeDate xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDate()) + "</timeDate>" + EOL);
} else if (timer.getTimeType() == Timer.TIME_DURATION) {
xmlDump.append(" <timeDuration xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDelay()) + "</timeDuration>" + EOL);
} else if (timer.getTimeType() == Timer.TIME_CYCLE) {
if (timer.getPeriod() != null) {
xmlDump.append(" <timeCycle xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDelay()) + "###" + XmlDumper.replaceIllegalChars(timer.getPeriod()) + "</timeCycle>" + EOL);
} else {
xmlDump.append(" <timeCycle xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDelay()) + "</timeCycle>" + EOL);
}
} else if (timer.getTimeType() == Timer.TIME_DATE) {
xmlDump.append(" <timeDate xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDelay()) + "</timeDate>" + EOL);
}
}
xmlDump.append(" </timerEventDefinition>" + EOL);
}
} else if (startNode.getTimer() != null) {
Timer timer = startNode.getTimer();
xmlDump.append(" <timerEventDefinition>" + EOL);
if (timer != null && (timer.getDelay() != null || timer.getDate() != null)) {
if (timer.getTimeType() == Timer.TIME_DATE) {
xmlDump.append(" <timeDate xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDate()) + "</timeDate>" + EOL);
} else if (timer.getTimeType() == Timer.TIME_DURATION) {
xmlDump.append(" <timeDuration xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDelay()) + "</timeDuration>" + EOL);
} else if (timer.getTimeType() == Timer.TIME_CYCLE) {
if (timer.getPeriod() != null) {
xmlDump.append(" <timeCycle xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDelay()) + "###" + XmlDumper.replaceIllegalChars(timer.getPeriod()) + "</timeCycle>" + EOL);
} else {
xmlDump.append(" <timeCycle xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDelay()) + "</timeCycle>" + EOL);
}
} else if (timer.getTimeType() == Timer.TIME_DATE) {
xmlDump.append(" <timeDate xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDelay()) + "</timeDate>" + EOL);
}
}
xmlDump.append(" </timerEventDefinition>" + EOL);
}
endNode("startEvent", xmlDump);
}
use of org.jbpm.workflow.core.node.Trigger in project jbpm by kiegroup.
the class StartEventHandler method handleCompensationNode.
protected void handleCompensationNode(final StartNode startNode, final Element element, final org.w3c.dom.Node xmlNode, final ExtensibleXmlParser parser) throws SAXException {
if (startNode.isInterrupting()) {
logger.warn("Compensation Event Sub-Processes [" + startNode.getMetaData("UniqueId") + "] may not be specified as interrupting:" + " overriding attribute and setting to not-interrupting.");
}
startNode.setInterrupting(false);
/**
* From the BPMN2 spec, P.264:
* "For a Start Event:
* This Event "catches" the compensation for an Event Sub-Process. No further information is required.
* The Event Sub-Process will provide the id necessary to match the Compensation Event with the Event
* that threw the compensation"
*
* In other words, the id of the Sub-Process containing this Event Sub-Process is what should be used
* as the activityRef value in any Intermediate (throw) or End compensation event that targets
* this particular Event Sub-Process.
*
* This is similar to the logic used for a Compensation Boundary Event: it's signaled using
* the id of the activity to which the CBE is attached to.
*/
String activityRef = ((Element) xmlNode).getAttribute("activityRef");
if (activityRef != null && activityRef.length() > 0) {
logger.warn("activityRef value [" + activityRef + "] on Start Event '" + startNode.getMetaData("UniqueId") + "' ignored per the BPMN2 specification.");
}
// so that this node will get processed in ProcessHandler.postProcessNodes(...)
EventTrigger startTrigger = new EventTrigger();
EventFilter eventFilter = new NonAcceptingEventTypeFilter();
((NonAcceptingEventTypeFilter) eventFilter).setType("Compensation");
startTrigger.addEventFilter(eventFilter);
List<Trigger> startTriggers = new ArrayList<Trigger>();
startTriggers.add(startTrigger);
startNode.setTriggers(startTriggers);
String mapping = (String) startNode.getMetaData("TriggerMapping");
if (mapping != null) {
startTrigger.addInMapping(mapping, startNode.getOutMapping(mapping));
}
}
use of org.jbpm.workflow.core.node.Trigger in project jbpm by kiegroup.
the class ProcessHandler method handleIntermediateOrEndThrowCompensationEvent.
protected void handleIntermediateOrEndThrowCompensationEvent(ExtendedNodeImpl throwEventNode) {
if (throwEventNode.getMetaData("compensation-activityRef") != null) {
String activityRef = (String) throwEventNode.getMetaData().remove("compensation-activityRef");
NodeContainer nodeParent = (NodeContainer) throwEventNode.getNodeContainer();
if (nodeParent instanceof EventSubProcessNode) {
boolean compensationEventSubProcess = false;
List<Trigger> startTriggers = ((EventSubProcessNode) nodeParent).findStartNode().getTriggers();
CESP_CHECK: for (Trigger trigger : startTriggers) {
if (trigger instanceof EventTrigger) {
for (EventFilter filter : ((EventTrigger) trigger).getEventFilters()) {
if (((EventTypeFilter) filter).getType().equals("Compensation")) {
compensationEventSubProcess = true;
break CESP_CHECK;
}
}
}
}
if (compensationEventSubProcess) {
// BPMN2 spec, p. 252, p. 248: intermediate and end compensation event visibility scope
nodeParent = (NodeContainer) ((NodeImpl) nodeParent).getNodeContainer();
}
}
String parentId;
if (nodeParent instanceof RuleFlowProcess) {
parentId = ((RuleFlowProcess) nodeParent).getId();
} else {
parentId = (String) ((NodeImpl) nodeParent).getMetaData("UniqueId");
}
String compensationEvent;
if (activityRef.length() == 0) {
// general/implicit compensation
compensationEvent = CompensationScope.IMPLICIT_COMPENSATION_PREFIX + parentId;
} else {
// specific compensation
compensationEvent = activityRef;
}
DroolsConsequenceAction compensationAction = new DroolsConsequenceAction("java", PROCESS_INSTANCE_SIGNAL_EVENT + "Compensation\", \"" + compensationEvent + "\");");
if (throwEventNode instanceof ActionNode) {
((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);
}
}
}
use of org.jbpm.workflow.core.node.Trigger in project jbpm by kiegroup.
the class StartNodeHandler method writeNode.
public void writeNode(Node node, StringBuilder xmlDump, boolean includeMeta) {
StartNode startNode = (StartNode) node;
writeNode("start", startNode, xmlDump, includeMeta);
List<Trigger> triggers = startNode.getTriggers();
if ((triggers == null || triggers.isEmpty()) && (!includeMeta || !containsMetaData(startNode))) {
endNode(xmlDump);
} else {
xmlDump.append(">" + EOL);
if (includeMeta) {
writeMetaData(startNode, xmlDump);
}
if (triggers != null) {
xmlDump.append(" <triggers>" + EOL);
for (Trigger trigger : triggers) {
if (trigger instanceof ConstraintTrigger) {
xmlDump.append(" <trigger type=\"constraint\" >" + EOL);
xmlDump.append(" <constraint type=\"rule\" dialect=\"mvel\" >" + ((ConstraintTrigger) trigger).getConstraint() + "</constraint>" + EOL);
Map<String, String> inMappings = trigger.getInMappings();
if (inMappings != null && !inMappings.isEmpty()) {
for (Map.Entry<String, String> entry : inMappings.entrySet()) {
xmlDump.append(" <mapping type=\"in\" from=\"" + XmlDumper.replaceIllegalChars(entry.getValue()) + "\" to=\"" + entry.getKey() + "\" />" + EOL);
}
}
xmlDump.append(" </trigger>" + EOL);
} else if (trigger instanceof EventTrigger) {
xmlDump.append(" <trigger type=\"event\" >" + EOL);
xmlDump.append(" <eventFilters>" + EOL);
for (EventFilter filter : ((EventTrigger) trigger).getEventFilters()) {
if (filter instanceof EventTypeFilter) {
xmlDump.append(" <eventFilter " + "type=\"eventType\" " + "eventType=\"" + ((EventTypeFilter) filter).getType() + "\" />" + EOL);
} else {
throw new IllegalArgumentException("Unknown filter type: " + filter);
}
}
xmlDump.append(" </eventFilters>" + EOL);
Map<String, String> inMappings = trigger.getInMappings();
if (inMappings != null && !inMappings.isEmpty()) {
for (Map.Entry<String, String> entry : inMappings.entrySet()) {
xmlDump.append(" <mapping type=\"in\" from=\"" + XmlDumper.replaceIllegalChars(entry.getValue()) + "\" to=\"" + entry.getKey() + "\" />" + EOL);
}
}
xmlDump.append(" </trigger>" + EOL);
} else {
throw new IllegalArgumentException("Unknown trigger type " + trigger);
}
}
xmlDump.append(" </triggers>" + EOL);
}
endNode("start", xmlDump);
}
}
use of org.jbpm.workflow.core.node.Trigger in project jbpm by kiegroup.
the class TriggerHandler method start.
public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
parser.startElementBuilder(localName, attrs);
StartNode startNode = (StartNode) parser.getParent();
String type = attrs.getValue("type");
emptyAttributeCheck(localName, "type", type, parser);
Trigger trigger = null;
if ("constraint".equals(type)) {
trigger = new ConstraintTrigger();
} else if ("event".equals(type)) {
trigger = new EventTrigger();
} else {
throw new SAXException("Unknown trigger type " + type);
}
startNode.addTrigger(trigger);
return trigger;
}
Aggregations