use of org.jbpm.ruleflow.core.RuleFlowProcess in project jbpm by kiegroup.
the class BPMN2XMLTest method testXML.
public void testXML() throws IOException, SAXException {
SemanticModules modules = new SemanticModules();
modules.addSemanticModule(new BPMNSemanticModule());
modules.addSemanticModule(new BPMNDISemanticModule());
XmlProcessReader processReader = new XmlProcessReader(modules, getClass().getClassLoader());
for (String processName : processes) {
String original = slurp(BPMN2XMLTest.class.getResourceAsStream("/" + processName));
List<Process> processes = processReader.read(BPMN2XMLTest.class.getResourceAsStream("/" + processName));
assertNotNull(processes);
assertEquals(1, processes.size());
RuleFlowProcess p = (RuleFlowProcess) processes.get(0);
String result = XmlBPMNProcessDumper.INSTANCE.dump(p, XmlBPMNProcessDumper.META_DATA_USING_DI);
// Compare original with result using XMLUnit
Diff diff = new Diff(original, result);
// Ignore the sequence of nodes (or children nodes) when looking at these nodes
final HashSet<String> sequenceDoesNotMatter = new HashSet<String>();
sequenceDoesNotMatter.add("startEvent");
sequenceDoesNotMatter.add("scriptTask");
sequenceDoesNotMatter.add("endEvent");
sequenceDoesNotMatter.add("bpmndi:BPMNShape");
diff.overrideDifferenceListener(new DifferenceListener() {
public int differenceFound(Difference diff) {
String nodeName = diff.getTestNodeDetail().getNode().getNodeName();
if (sequenceDoesNotMatter.contains(nodeName) && diff.getId() == DifferenceConstants.CHILD_NODELIST_SEQUENCE_ID) {
return RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
}
logger.info("! {}", diff.getTestNodeDetail().getNode().getNodeName());
return RETURN_ACCEPT_DIFFERENCE;
}
public void skippedComparison(Node one, Node two) {
logger.info("{} : {}", one.getLocalName(), two.getLocalName());
}
});
// nodes should only be compared if their attributes are the same
diff.overrideElementQualifier(new ElementNameAndAttributeQualifier());
assertTrue("Original and generated output is not the same.", diff.identical());
}
}
use of org.jbpm.ruleflow.core.RuleFlowProcess in project jbpm by kiegroup.
the class ProcessHandler method linkBoundaryConditionEvent.
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);
}
}
use of org.jbpm.ruleflow.core.RuleFlowProcess 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.ruleflow.core.RuleFlowProcess in project jbpm by kiegroup.
the class SequenceFlowHandler method start.
@SuppressWarnings("unchecked")
public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
parser.startElementBuilder(localName, attrs);
final String id = attrs.getValue("id");
final String sourceRef = attrs.getValue("sourceRef");
final String targetRef = attrs.getValue("targetRef");
final String bendpoints = attrs.getValue("g:bendpoints");
final String name = attrs.getValue("name");
final String priority = attrs.getValue("http://www.jboss.org/drools", "priority");
NodeContainer nodeContainer = (NodeContainer) parser.getParent();
List<SequenceFlow> connections = null;
if (nodeContainer instanceof RuleFlowProcess) {
RuleFlowProcess process = (RuleFlowProcess) nodeContainer;
connections = (List<SequenceFlow>) process.getMetaData(ProcessHandler.CONNECTIONS);
if (connections == null) {
connections = new ArrayList<SequenceFlow>();
process.setMetaData(ProcessHandler.CONNECTIONS, connections);
}
} else if (nodeContainer instanceof CompositeNode) {
CompositeNode compositeNode = (CompositeNode) nodeContainer;
connections = (List<SequenceFlow>) compositeNode.getMetaData(ProcessHandler.CONNECTIONS);
if (connections == null) {
connections = new ArrayList<SequenceFlow>();
compositeNode.setMetaData(ProcessHandler.CONNECTIONS, connections);
}
}
SequenceFlow connection = new SequenceFlow(id, sourceRef, targetRef);
connection.setBendpoints(bendpoints);
connection.setName(name);
if (priority != null) {
connection.setPriority(Integer.parseInt(priority));
}
connections.add(connection);
return connection;
}
use of org.jbpm.ruleflow.core.RuleFlowProcess in project jbpm by kiegroup.
the class IntermediateCatchEventHandler method handleLinkNode.
protected void handleLinkNode(Element element, Node node, org.w3c.dom.Node xmlLinkNode, ExtensibleXmlParser parser) {
NodeContainer nodeContainer = (NodeContainer) parser.getParent();
node.setName(element.getAttribute("name"));
NamedNodeMap linkAttr = xmlLinkNode.getAttributes();
String name = linkAttr.getNamedItem("name").getNodeValue();
String id = element.getAttribute("id");
node.setMetaData("UniqueId", id);
node.setMetaData(LINK_NAME, name);
org.w3c.dom.Node xmlNode = xmlLinkNode.getFirstChild();
IntermediateLink aLink = new IntermediateLink();
aLink.setName(name);
aLink.setUniqueId(id);
while (null != xmlNode) {
String nodeName = xmlNode.getNodeName();
if ("target".equals(nodeName)) {
String target = xmlNode.getTextContent();
node.setMetaData("target", target);
aLink.setTarget(target);
}
if ("source".equals(nodeName)) {
String source = xmlNode.getTextContent();
node.setMetaData("source", source);
aLink.addSource(source);
}
xmlNode = xmlNode.getNextSibling();
}
if (nodeContainer instanceof RuleFlowProcess) {
RuleFlowProcess process = (RuleFlowProcess) nodeContainer;
List<IntermediateLink> links = (List<IntermediateLink>) process.getMetaData().get(ProcessHandler.LINKS);
if (null == links) {
links = new ArrayList<IntermediateLink>();
}
links.add(aLink);
process.setMetaData(ProcessHandler.LINKS, links);
} else if (nodeContainer instanceof CompositeNode) {
CompositeNode subprocess = (CompositeNode) nodeContainer;
List<IntermediateLink> links = (List<IntermediateLink>) subprocess.getMetaData().get(ProcessHandler.LINKS);
if (null == links) {
links = new ArrayList<IntermediateLink>();
}
links.add(aLink);
subprocess.setMetaData(ProcessHandler.LINKS, links);
}
}
Aggregations