use of org.jbpm.workflow.core.impl.DroolsConsequenceAction in project jbpm by kiegroup.
the class IntermediateThrowEventHandler method handleEscalationNode.
@SuppressWarnings("unchecked")
public void handleEscalationNode(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 ("dataInputAssociation".equals(nodeName)) {
readDataInputAssociation(xmlNode, actionNode);
} else if ("escalationEventDefinition".equals(nodeName)) {
String escalationRef = ((Element) xmlNode).getAttribute("escalationRef");
if (escalationRef != null && escalationRef.trim().length() > 0) {
Map<String, Escalation> escalations = (Map<String, Escalation>) ((ProcessBuildData) parser.getData()).getMetaData(ProcessHandler.ESCALATIONS);
if (escalations == null) {
throw new IllegalArgumentException("No escalations found");
}
Escalation escalation = escalations.get(escalationRef);
if (escalation == null) {
throw new IllegalArgumentException("Could not find escalation " + escalationRef);
}
String faultName = escalation.getEscalationCode();
String variable = (String) actionNode.getMetaData("MappingVariable");
actionNode.setAction(new DroolsConsequenceAction("java", "org.jbpm.process.instance.context.exception.ExceptionScopeInstance scopeInstance = (org.jbpm.process.instance.context.exception.ExceptionScopeInstance) ((org.jbpm.workflow.instance.NodeInstance) kcontext.getNodeInstance()).resolveContextInstance(org.jbpm.process.core.context.exception.ExceptionScope.EXCEPTION_SCOPE, \"" + faultName + "\");" + EOL + "if (scopeInstance != null) {" + EOL + " 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) + ");" + "}" + " scopeInstance.handleException(\"" + faultName + "\", tVariable);" + EOL + "} else {" + EOL + " ((org.jbpm.process.instance.ProcessInstance) kcontext.getProcessInstance()).setState(org.jbpm.process.instance.ProcessInstance.STATE_ABORTED);" + EOL + "}"));
} else {
throw new IllegalArgumentException("General escalation is not yet supported");
}
}
xmlNode = xmlNode.getNextSibling();
}
}
use of org.jbpm.workflow.core.impl.DroolsConsequenceAction 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.workflow.core.impl.DroolsConsequenceAction 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();
}
}
use of org.jbpm.workflow.core.impl.DroolsConsequenceAction in project jbpm by kiegroup.
the class AbstractNodeHandler method extractScript.
public static DroolsAction extractScript(Element xmlNode) {
String dialect = "mvel";
if ("http://www.java.com/java".equals(xmlNode.getAttribute("scriptFormat"))) {
dialect = "java";
} else if ("http://www.javascript.com/javascript".equals(xmlNode.getAttribute("scriptFormat"))) {
dialect = "JavaScript";
}
NodeList subNodeList = xmlNode.getChildNodes();
for (int j = 0; j < subNodeList.getLength(); j++) {
if (subNodeList.item(j) instanceof Element) {
Element subXmlNode = (Element) subNodeList.item(j);
if ("script".equals(subXmlNode.getNodeName())) {
String consequence = subXmlNode.getTextContent();
DroolsConsequenceAction action = new DroolsConsequenceAction(dialect, consequence);
return action;
}
}
}
return new DroolsConsequenceAction("mvel", "");
}
use of org.jbpm.workflow.core.impl.DroolsConsequenceAction in project jbpm by kiegroup.
the class ActionNodeHandler method writeNode.
public void writeNode(Node node, StringBuilder xmlDump, int metaDataType) {
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");
if (action != null) {
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", actionNode, xmlDump, metaDataType);
xmlDump.append(">" + EOL);
writeExtensionElements(actionNode, xmlDump);
String variable = (String) actionNode.getMetaData("MappingVariable");
if (variable != null) {
xmlDump.append(" <dataInput id=\"" + XmlBPMNProcessDumper.getUniqueNodeId(actionNode) + "_Input\" />" + EOL + " <dataInputAssociation>" + EOL + " <sourceRef>" + XmlDumper.replaceIllegalChars(variable) + "</sourceRef>" + EOL + " <targetRef>" + XmlBPMNProcessDumper.getUniqueNodeId(actionNode) + "_Input</targetRef>" + EOL + " </dataInputAssociation>" + EOL + " <inputSet>" + EOL + " <dataInputRefs>" + XmlBPMNProcessDumper.getUniqueNodeId(actionNode) + "_Input</dataInputRefs>" + EOL + " </inputSet>" + EOL);
}
xmlDump.append(" <messageEventDefinition messageRef=\"" + XmlBPMNProcessDumper.getUniqueNodeId(actionNode) + "_Message\"/>" + EOL);
endNode("intermediateThrowEvent", xmlDump);
} else if ("signal".equals(eventType)) {
writeNode("intermediateThrowEvent", actionNode, xmlDump, metaDataType);
xmlDump.append(">" + EOL);
writeExtensionElements(actionNode, xmlDump);
if (!s.startsWith("null")) {
xmlDump.append(" <dataInput id=\"" + XmlBPMNProcessDumper.getUniqueNodeId(actionNode) + "_Input\" />" + EOL + " <dataInputAssociation>" + EOL + " <sourceRef>" + XmlDumper.replaceIllegalChars(variableRef) + "</sourceRef>" + EOL + " <targetRef>" + XmlBPMNProcessDumper.getUniqueNodeId(actionNode) + "_Input</targetRef>" + EOL + " </dataInputAssociation>" + EOL + " <inputSet>" + EOL + " <dataInputRefs>" + XmlBPMNProcessDumper.getUniqueNodeId(actionNode) + "_Input</dataInputRefs>" + EOL + " </inputSet>" + EOL);
}
xmlDump.append(" <signalEventDefinition signalRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(ref) + "\"/>" + EOL);
endNode("intermediateThrowEvent", xmlDump);
} else if (s.startsWith(RUNTIME_SIGNAL_EVENT)) {
writeNode("intermediateThrowEvent", actionNode, xmlDump, metaDataType);
xmlDump.append(">" + EOL);
writeExtensionElements(actionNode, xmlDump);
s = s.substring(44);
String type = s.substring(0, s.indexOf("\""));
s = s.substring(s.indexOf(",") + 2);
String variable = null;
if (!s.startsWith("null")) {
variable = s.substring(0, s.indexOf(")"));
xmlDump.append(" <dataInput id=\"" + XmlBPMNProcessDumper.getUniqueNodeId(actionNode) + "_Input\" />" + EOL + " <dataInputAssociation>" + EOL + " <sourceRef>" + XmlDumper.replaceIllegalChars(variable) + "</sourceRef>" + EOL + " <targetRef>" + XmlBPMNProcessDumper.getUniqueNodeId(actionNode) + "_Input</targetRef>" + EOL + " </dataInputAssociation>" + EOL + " <inputSet>" + EOL + " <dataInputRefs>" + XmlBPMNProcessDumper.getUniqueNodeId(actionNode) + "_Input</dataInputRefs>" + EOL + " </inputSet>" + EOL);
}
xmlDump.append(" <signalEventDefinition signalRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(type) + "\"/>" + EOL);
endNode("intermediateThrowEvent", xmlDump);
} else if (s.startsWith(PROCESS_INSTANCE_SIGNAL_EVENT)) {
writeNode("intermediateThrowEvent", actionNode, xmlDump, metaDataType);
xmlDump.append(">" + EOL);
writeExtensionElements(actionNode, xmlDump);
s = s.substring(43);
assert "Compensation".equals(s.substring(0, s.indexOf("\""))) : "Type is not \"Compensation\" but \"" + s.substring(0, s.indexOf("\"")) + "\"";
String activityRef = "";
// : Compensation
int begin = 12;
// ");
int end = s.length() - 3;
String compensationEvent = s.substring(begin, end);
if (!compensationEvent.startsWith(CompensationScope.IMPLICIT_COMPENSATION_PREFIX)) {
// specific
activityRef = "activityRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(activityRef) + "\" ";
}
// else general: activityRef = "" (above)
xmlDump.append(" <compensateEventDefinition " + activityRef + "/>" + EOL);
endNode("intermediateThrowEvent", xmlDump);
} else 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, \"")) {
writeNode("intermediateThrowEvent", actionNode, xmlDump, metaDataType);
xmlDump.append(">" + EOL);
writeExtensionElements(actionNode, xmlDump);
s = s.substring(327);
String type = s.substring(0, s.indexOf("\""));
xmlDump.append(" <escalationEventDefinition escalationRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(type) + "\"/>" + EOL);
endNode("intermediateThrowEvent", xmlDump);
} else if ("IntermediateThrowEvent-None".equals(actionNode.getMetaData("NodeType"))) {
writeNode("intermediateThrowEvent", actionNode, xmlDump, metaDataType);
xmlDump.append(">" + EOL);
writeExtensionElements(actionNode, xmlDump);
endNode("intermediateThrowEvent", xmlDump);
} else {
writeNode("scriptTask", actionNode, 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 + "\" ");
}
Object isForCompensationObj = actionNode.getMetaData("isForCompensation");
if (isForCompensationObj != null && (Boolean) isForCompensationObj) {
xmlDump.append("isForCompensation=\"true\" ");
}
xmlDump.append(">" + EOL);
writeExtensionElements(actionNode, xmlDump);
if (action.getConsequence() != null) {
xmlDump.append(" <script>" + XmlDumper.replaceIllegalChars(action.getConsequence()) + "</script>" + EOL);
}
endNode("scriptTask", xmlDump);
}
} else {
writeNode("scriptTask", actionNode, xmlDump, metaDataType);
xmlDump.append(">" + EOL);
writeExtensionElements(actionNode, xmlDump);
endNode("scriptTask", xmlDump);
}
}
Aggregations