use of org.jbpm.compiler.xml.ProcessBuildData in project jbpm by kiegroup.
the class EndEventHandler method handleErrorNode.
@SuppressWarnings("unchecked")
public void handleErrorNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
FaultNode faultNode = (FaultNode) node;
org.w3c.dom.Node xmlNode = element.getFirstChild();
while (xmlNode != null) {
String nodeName = xmlNode.getNodeName();
if ("dataInputAssociation".equals(nodeName)) {
readFaultDataInputAssociation(xmlNode, faultNode);
} else if ("errorEventDefinition".equals(nodeName)) {
String errorRef = ((Element) xmlNode).getAttribute("errorRef");
if (errorRef != null && errorRef.trim().length() > 0) {
List<Error> errors = (List<Error>) ((ProcessBuildData) parser.getData()).getMetaData("Errors");
if (errors == null) {
throw new IllegalArgumentException("No errors found");
}
Error error = null;
for (Error listError : errors) {
if (errorRef.equals(listError.getId())) {
error = listError;
break;
}
}
if (error == null) {
throw new IllegalArgumentException("Could not find error " + errorRef);
}
faultNode.setFaultName(error.getErrorCode());
faultNode.setTerminateParent(true);
}
}
xmlNode = xmlNode.getNextSibling();
}
}
use of org.jbpm.compiler.xml.ProcessBuildData in project jbpm by kiegroup.
the class EndEventHandler method handleEscalationNode.
@SuppressWarnings("unchecked")
public void handleEscalationNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
FaultNode faultNode = (FaultNode) node;
org.w3c.dom.Node xmlNode = element.getFirstChild();
while (xmlNode != null) {
String nodeName = xmlNode.getNodeName();
if ("dataInputAssociation".equals(nodeName)) {
readFaultDataInputAssociation(xmlNode, faultNode);
} 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);
}
faultNode.setFaultName(escalation.getEscalationCode());
} else {
// are _required_ to reference a specific escalation(-code).
throw new IllegalArgumentException("End events throwing an escalation must throw *specific* escalations (and not general ones).");
}
}
xmlNode = xmlNode.getNextSibling();
}
}
use of org.jbpm.compiler.xml.ProcessBuildData 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.compiler.xml.ProcessBuildData in project jbpm by kiegroup.
the class EscalationHandler 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);
String id = attrs.getValue("id");
String escalationCode = attrs.getValue("escalationCode");
ProcessBuildData buildData = (ProcessBuildData) parser.getData();
Map<String, Escalation> escalations = (Map<String, Escalation>) buildData.getMetaData(ProcessHandler.ESCALATIONS);
if (escalations == null) {
escalations = new HashMap<String, Escalation>();
buildData.setMetaData(ProcessHandler.ESCALATIONS, escalations);
}
Escalation e = new Escalation(id, escalationCode);
escalations.put(id, e);
return e;
}
use of org.jbpm.compiler.xml.ProcessBuildData in project jbpm by kiegroup.
the class AbstractNodeHandler method checkSignalAndConvertToRealSignalNam.
protected String checkSignalAndConvertToRealSignalNam(ExtensibleXmlParser parser, String signalName) {
ProcessBuildData buildData = ((ProcessBuildData) parser.getData());
Set<String> signalNames = (Set<String>) buildData.getMetaData(SIGNAL_NAMES);
if (signalNames == null) {
signalNames = new HashSet<>();
buildData.setMetaData(SIGNAL_NAMES, signalNames);
}
signalNames.add(signalName);
Map<String, Signal> signals = (Map<String, Signal>) buildData.getMetaData("Signals");
if (signals != null) {
if (signals.containsKey(signalName)) {
Signal signal = signals.get(signalName);
signalName = signal.getName();
if (signalName == null) {
throw new IllegalArgumentException("Signal definition must have a name attribute");
}
}
}
return signalName;
}
Aggregations