use of org.jbpm.bpmn2.core.Message in project jbpm by kiegroup.
the class IntermediateEventTest method testMessageIntermediateThrowWithTransformation.
@Test
public void testMessageIntermediateThrowWithTransformation() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-IntermediateThrowEventMessageWithTransformation.bpmn2");
ksession = createKnowledgeSession(kbase);
final StringBuffer messageContent = new StringBuffer();
ksession.getWorkItemManager().registerWorkItemHandler("Send Task", new SendTaskHandler() {
@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
// collect message content for verification
messageContent.append(workItem.getParameter("Message"));
super.executeWorkItem(workItem, manager);
}
});
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "MyValue");
ProcessInstance processInstance = ksession.startProcess("MessageIntermediateEvent", params);
assertProcessInstanceCompleted(processInstance);
assertThat(messageContent.toString()).isEqualTo("MYVALUE");
}
use of org.jbpm.bpmn2.core.Message in project jbpm by kiegroup.
the class BPMN2XMLTest method testInvalidXMLInCompositeNode.
public void testInvalidXMLInCompositeNode() throws Exception, SAXException {
SemanticModules modules = new SemanticModules();
modules.addSemanticModule(new BPMNSemanticModule());
modules.addSemanticModule(new BPMNDISemanticModule());
XmlProcessReader processReader = new XmlProcessReader(modules, getClass().getClassLoader()) {
@Override
protected String processParserMessage(LinkedList<Object> parents, org.xml.sax.Attributes attr, String errorMessage) {
setErrorMessage(super.processParserMessage(parents, attr, errorMessage));
return errorMessage;
}
};
processReader.read(BPMN2XMLTest.class.getResourceAsStream("/BPMN2-XMLProcessWithErrorInCompositeNode.bpmn2"));
assertNotNull(getErrorMessage());
assertThat(getErrorMessage()).contains("Process Info: id:abc.abc, pkg:org.drools.bpmn2, name:abc, version:1.0 \n" + "Node Info: id:_47489F3D-FEBD-4452-B62E-B04EF191C6C3 name: \n" + "Parser message: (null: 24, 185): cvc-complex-type.2.4.a: Invalid content was found");
}
use of org.jbpm.bpmn2.core.Message in project jbpm by kiegroup.
the class LoggingTaskHandlerWrapperTest method testFormatLoggingError.
@Test
public void testFormatLoggingError() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-ExceptionThrowingServiceProcess.bpmn2");
ksession = createKnowledgeSession(kbase);
LoggingTaskHandlerDecorator loggingTaskHandlerWrapper = new LoggingTaskHandlerDecorator(ServiceTaskHandler.class, 2);
loggingTaskHandlerWrapper.setLoggedMessageFormat("{0} - {1} - {2} - {3}");
List<InputParameter> inputParameters = new ArrayList<LoggingTaskHandlerDecorator.InputParameter>();
inputParameters.add(InputParameter.EXCEPTION_CLASS);
inputParameters.add(InputParameter.WORK_ITEM_ID);
inputParameters.add(InputParameter.WORK_ITEM_NAME);
inputParameters.add(InputParameter.PROCESS_INSTANCE_ID);
loggingTaskHandlerWrapper.setLoggedMessageInput(inputParameters);
loggingTaskHandlerWrapper.setPrintStackTrace(false);
ksession.getWorkItemManager().registerWorkItemHandler("Service Task", loggingTaskHandlerWrapper);
Map<String, Object> params = new HashMap<String, Object>();
params.put("serviceInputItem", "exception message");
ksession.startProcess("ServiceProcess", params);
ksession.startProcess("ServiceProcess", params);
ksession.startProcess("ServiceProcess", params);
}
use of org.jbpm.bpmn2.core.Message in project jbpm by kiegroup.
the class IntermediateThrowEventHandler method handleMessageNode.
@SuppressWarnings("unchecked")
public void handleMessageNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
ActionNode actionNode = (ActionNode) node;
org.w3c.dom.Node xmlNode = element.getFirstChild();
while (xmlNode != null) {
String nodeName = xmlNode.getNodeName();
if ("dataInput".equals(nodeName)) {
String id = ((Element) xmlNode).getAttribute("id");
String inputName = ((Element) xmlNode).getAttribute("name");
dataInputs.put(id, inputName);
} else if ("dataInputAssociation".equals(nodeName)) {
readDataInputAssociation(xmlNode, actionNode);
} else if ("messageEventDefinition".equals(nodeName)) {
String messageRef = ((Element) xmlNode).getAttribute("messageRef");
Map<String, Message> messages = (Map<String, Message>) ((ProcessBuildData) parser.getData()).getMetaData("Messages");
if (messages == null) {
throw new IllegalArgumentException("No messages found");
}
Message message = messages.get(messageRef);
if (message == null) {
throw new IllegalArgumentException("Could not find message " + messageRef);
}
String variable = (String) actionNode.getMetaData("MappingVariable");
actionNode.setMetaData("MessageType", message.getType());
actionNode.setAction(new DroolsConsequenceAction("java", " Object tVariable = " + (variable == null ? "null" : variable) + ";" + "org.jbpm.workflow.core.node.Transformation transformation = (org.jbpm.workflow.core.node.Transformation)kcontext.getNodeInstance().getNode().getMetaData().get(\"Transformation\");" + "if (transformation != null) {" + " tVariable = new org.jbpm.process.core.event.EventTransformerImpl(transformation)" + " .transformEvent(" + (variable == null ? "null" : variable) + ");" + "}" + "org.drools.core.process.instance.impl.WorkItemImpl workItem = new org.drools.core.process.instance.impl.WorkItemImpl();" + EOL + "workItem.setName(\"Send Task\");" + EOL + "workItem.setProcessInstanceId(kcontext.getProcessInstance().getId());" + EOL + "workItem.setParameter(\"MessageType\", \"" + message.getType() + "\");" + EOL + "workItem.setNodeInstanceId(kcontext.getNodeInstance().getId());" + EOL + "workItem.setNodeId(kcontext.getNodeInstance().getNodeId());" + EOL + "workItem.setDeploymentId((String) kcontext.getKnowledgeRuntime().getEnvironment().get(\"deploymentId\"));" + EOL + (variable == null ? "" : "workItem.setParameter(\"Message\", tVariable);" + EOL) + "((org.drools.core.process.instance.WorkItemManager) kcontext.getKnowledgeRuntime().getWorkItemManager()).internalExecuteWorkItem(workItem);"));
}
xmlNode = xmlNode.getNextSibling();
}
}
use of org.jbpm.bpmn2.core.Message in project jbpm by kiegroup.
the class EndEventHandler method handleMessageNode.
@SuppressWarnings("unchecked")
public void handleMessageNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
EndNode endNode = (EndNode) node;
org.w3c.dom.Node xmlNode = element.getFirstChild();
while (xmlNode != null) {
String nodeName = xmlNode.getNodeName();
if ("dataInputAssociation".equals(nodeName)) {
readEndDataInputAssociation(xmlNode, endNode);
} else if ("messageEventDefinition".equals(nodeName)) {
String messageRef = ((Element) xmlNode).getAttribute("messageRef");
Map<String, Message> messages = (Map<String, Message>) ((ProcessBuildData) parser.getData()).getMetaData("Messages");
if (messages == null) {
throw new IllegalArgumentException("No messages found");
}
Message message = messages.get(messageRef);
if (message == null) {
throw new IllegalArgumentException("Could not find message " + messageRef);
}
String variable = (String) endNode.getMetaData("MappingVariable");
endNode.setMetaData("MessageType", message.getType());
List<DroolsAction> actions = new ArrayList<DroolsAction>();
actions.add(new DroolsConsequenceAction("java", "org.drools.core.process.instance.impl.WorkItemImpl workItem = new org.drools.core.process.instance.impl.WorkItemImpl();" + EOL + "workItem.setName(\"Send Task\");" + EOL + "workItem.setNodeInstanceId(kcontext.getNodeInstance().getId());" + EOL + "workItem.setProcessInstanceId(kcontext.getProcessInstance().getId());" + EOL + "workItem.setNodeId(kcontext.getNodeInstance().getNodeId());" + EOL + "workItem.setParameter(\"MessageType\", \"" + message.getType() + "\");" + EOL + (variable == null ? "" : "workItem.setParameter(\"Message\", " + variable + ");" + EOL) + "workItem.setDeploymentId((String) kcontext.getKnowledgeRuntime().getEnvironment().get(\"deploymentId\"));" + EOL + "((org.drools.core.process.instance.WorkItemManager) kcontext.getKnowledgeRuntime().getWorkItemManager()).internalExecuteWorkItem(workItem);"));
endNode.setActions(EndNode.EVENT_NODE_ENTER, actions);
}
xmlNode = xmlNode.getNextSibling();
}
}
Aggregations