use of org.drools.core.xml.ExtensibleXmlParser in project jbpm by kiegroup.
the class EndEventHandler method handleSignalNode.
public void handleSignalNode(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 ("dataInput".equals(nodeName)) {
String id = ((Element) xmlNode).getAttribute("id");
String inputName = ((Element) xmlNode).getAttribute("name");
dataInputs.put(id, inputName);
} else if ("dataInputAssociation".equals(nodeName)) {
readEndDataInputAssociation(xmlNode, endNode);
} else if ("signalEventDefinition".equals(nodeName)) {
String signalName = ((Element) xmlNode).getAttribute("signalRef");
String variable = (String) endNode.getMetaData("MappingVariable");
signalName = checkSignalAndConvertToRealSignalNam(parser, signalName, s -> s.addOutgoingNode(node));
endNode.setMetaData("EventType", "signal");
endNode.setMetaData("Ref", signalName);
endNode.setMetaData("Variable", variable);
endNode.setActions(EndNode.EVENT_NODE_ENTER, Collections.singletonList(new JavaDroolsAction(new SendSignalAction(endNode, variable, signalName, dataInputs.containsValue("async")))));
}
xmlNode = xmlNode.getNextSibling();
}
}
use of org.drools.core.xml.ExtensibleXmlParser in project kogito-runtimes by kiegroup.
the class ProcessHandler method postProcessCollaborations.
private void postProcessCollaborations(RuleFlowProcess process, ExtensibleXmlParser parser) {
// now we wire correlation process subscriptions
CorrelationManager correlationManager = process.getCorrelationManager();
for (Message message : HandlerUtil.messages(parser).values()) {
correlationManager.newMessage(message.getId(), message.getName(), message.getType());
}
// only the ones this process is member of
List<Collaboration> collaborations = HandlerUtil.collaborations(parser).values().stream().filter(c -> c.getProcessesRef().contains(process.getId())).collect(Collectors.toList());
for (Collaboration collaboration : collaborations) {
for (CorrelationKey key : collaboration.getCorrelationKeys()) {
correlationManager.newCorrelation(key.getId(), key.getName());
List<CorrelationProperty> properties = key.getPropertiesRef().stream().map(k -> HandlerUtil.correlationProperties(parser).get(k)).collect(Collectors.toList());
for (CorrelationProperty correlationProperty : properties) {
correlationProperty.getMessageRefs().forEach(messageRef -> {
// for now only MVEL expressions
MVELMessageExpressionEvaluator evaluator = new MVELMessageExpressionEvaluator(correlationProperty.getRetrievalExpression(messageRef).getScript());
correlationManager.addMessagePropertyExpression(key.getId(), messageRef, correlationProperty.getId(), evaluator);
});
}
}
}
// we create the correlations
for (CorrelationSubscription subscription : HandlerUtil.correlationSubscription(process).values()) {
correlationManager.subscribeTo(subscription.getCorrelationKeyRef());
for (Map.Entry<String, Expression> binding : subscription.getPropertyExpressions().entrySet()) {
MVELMessageExpressionEvaluator evaluator = new MVELMessageExpressionEvaluator(binding.getValue().getScript());
correlationManager.addProcessSubscriptionPropertyExpression(subscription.getCorrelationKeyRef(), binding.getKey(), evaluator);
}
}
}
use of org.drools.core.xml.ExtensibleXmlParser in project kogito-runtimes by kiegroup.
the class AbstractNodeHandler method findVariable.
/**
* Finds the right variable by its name to make sure that when given as id it will be also matched
*
* @param variableName name or id of the variable
* @param parser parser instance
* @return returns found variable name or given 'variableName' otherwise
*/
protected String findVariable(String variableName, final ExtensibleXmlParser parser) {
if (variableName == null) {
return null;
}
Collection<?> parents = parser.getParents();
for (Object parent : parents) {
if (parent instanceof ContextContainer) {
ContextContainer contextContainer = (ContextContainer) parent;
VariableScope variableScope = (VariableScope) contextContainer.getDefaultContext(VariableScope.VARIABLE_SCOPE);
return variableScope.getVariables().stream().filter(v -> v.matchByIdOrName(variableName)).map(v -> v.getName()).findFirst().orElse(variableName);
}
}
return variableName;
}
use of org.drools.core.xml.ExtensibleXmlParser in project kogito-runtimes by kiegroup.
the class AbstractNodeHandler method readThrowSpecification.
protected IOSpecification readThrowSpecification(ExtensibleXmlParser parser, Element element) {
IOSpecification ioSpec = new IOSpecification();
ioSpec.getDataInputs().addAll(readDataInput(parser, element));
org.w3c.dom.Node xmlNode = element.getFirstChild();
while (xmlNode != null) {
String nodeName = xmlNode.getNodeName();
if ("dataInputAssociation".equals(nodeName)) {
readDataAssociation(parser, (Element) xmlNode, id -> getVariableDataSpec(parser, id), id -> ioSpec.getDataInput().get(id)).ifPresent(e -> ioSpec.getDataInputAssociation().add(e));
}
xmlNode = xmlNode.getNextSibling();
}
return ioSpec;
}
use of org.drools.core.xml.ExtensibleXmlParser in project kogito-runtimes by kiegroup.
the class AbstractNodeHandler method getVariableDataSpec.
protected DataDefinition getVariableDataSpec(ExtensibleXmlParser parser, String propertyIdRef) {
RuleFlowProcess process = (RuleFlowProcess) ((ProcessBuildData) parser.getData()).getMetaData(ProcessHandler.CURRENT_PROCESS);
Optional<Variable> var = process.getVariableScope().getVariables().stream().filter(e -> e.getId().equals(propertyIdRef)).findAny();
if (var.isEmpty()) {
return null;
}
Variable variable = var.get();
return new DataDefinition(variable.getId(), variable.getName(), variable.getType().getStringType());
}
Aggregations