use of org.jbpm.bpmn2.core.Expression in project kogito-runtimes by kiegroup.
the class SequenceFlowHandler method end.
public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
final Element element = parser.endElementBuilder();
SequenceFlow sequenceFlow = (SequenceFlow) parser.getCurrent();
org.w3c.dom.Node xmlNode = element.getFirstChild();
while (xmlNode != null) {
String nodeName = xmlNode.getNodeName();
if ("conditionExpression".equals(nodeName)) {
String expression = xmlNode.getTextContent();
org.w3c.dom.Node languageNode = xmlNode.getAttributes().getNamedItem("language");
if (languageNode != null) {
String language = languageNode.getNodeValue();
if (XmlBPMNProcessDumper.JAVA_LANGUAGE.equals(language)) {
sequenceFlow.setLanguage("java");
} else if (XmlBPMNProcessDumper.MVEL_LANGUAGE.equals(language)) {
sequenceFlow.setLanguage("mvel");
} else if (XmlBPMNProcessDumper.RULE_LANGUAGE.equals(language)) {
sequenceFlow.setType("rule");
} else if (XmlBPMNProcessDumper.XPATH_LANGUAGE.equals(language)) {
sequenceFlow.setLanguage("XPath");
} else if (XmlBPMNProcessDumper.FEEL_LANGUAGE.equals(language) || XmlBPMNProcessDumper.DMN_FEEL_LANGUAGE.equals(language)) {
sequenceFlow.setLanguage("FEEL");
} else {
throw new ProcessParsingValidationException("Unknown language " + language);
}
}
sequenceFlow.setExpression(expression);
}
xmlNode = xmlNode.getNextSibling();
}
return sequenceFlow;
}
use of org.jbpm.bpmn2.core.Expression in project kogito-runtimes by kiegroup.
the class CorrelationSubscriptionHandler method buildPropertyProcessBindings.
private Map<String, Expression> buildPropertyProcessBindings(NodeList childNodes, ExtensibleXmlParser parser) {
Map<String, Expression> correlationKeys = new HashMap<>();
for (int i = 0; i < childNodes.getLength(); i++) {
Node node = childNodes.item(i);
if ("correlationPropertyBinding".equals(node.getNodeName())) {
Element elementBinding = (Element) node;
correlationKeys.put(elementBinding.getAttribute("correlationPropertyRef"), buildBindingExpression(elementBinding.getChildNodes(), parser));
}
}
return correlationKeys;
}
use of org.jbpm.bpmn2.core.Expression in project kogito-runtimes by kiegroup.
the class CorrelationSubscriptionHandler method buildBindingExpression.
private Expression buildBindingExpression(NodeList childNodes, ExtensibleXmlParser parser) {
for (int i = 0; i < childNodes.getLength(); i++) {
Node node = childNodes.item(i);
if ("dataPath".equals(node.getNodeName())) {
Element expressionElement = (Element) node;
Expression expression = new Expression();
expression.setId(expressionElement.getAttribute("id"));
expression.setLang(expressionElement.getAttribute("language"));
expression.setScript(expressionElement.getTextContent());
expression.setOutcomeType(HandlerUtil.definitions(parser).get(expressionElement.getAttribute("evaluatesToTypeRef")).getStructureRef());
return expression;
}
}
throw new RuntimeException("message Path not found for correlation property " + parser.getCurrent());
}
use of org.jbpm.bpmn2.core.Expression in project kogito-runtimes by kiegroup.
the class ActivityTest method testServiceTaskWithCustomTransformation.
@Test
public void testServiceTaskWithCustomTransformation() throws Exception {
DataTransformerRegistry.get().register("http://custom/transformer", new DataTransformer() {
@Override
public Object transform(Object expression, Map<String, Object> parameters) {
// support only single object
String value = parameters.values().iterator().next().toString();
Object result = null;
if ("caplitalizeFirst".equals(expression)) {
String first = value.substring(0, 1);
String main = value.substring(1, value.length());
result = first.toUpperCase() + main;
} else if ("caplitalizeLast".equals(expression)) {
String last = value.substring(value.length() - 1);
String main = value.substring(0, value.length() - 1);
result = main + last.toUpperCase();
} else {
throw new IllegalArgumentException("Unknown expression " + expression);
}
return result;
}
@Override
public Object compile(String expression, Map<String, Object> parameters) {
// compilation not supported
return expression;
}
});
kruntime = createKogitoProcessRuntime("BPMN2-ServiceProcessWithCustomTransformation.bpmn2");
kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Service Task", new ServiceTaskHandler());
Map<String, Object> params = new HashMap<>();
params.put("s", "john doe");
KogitoWorkflowProcessInstance processInstance = (KogitoWorkflowProcessInstance) kruntime.startProcess("ServiceProcess", params);
assertProcessInstanceFinished(processInstance, kruntime);
assertEquals("John doE", processInstance.getVariable("s"));
}
use of org.jbpm.bpmn2.core.Expression in project kogito-runtimes by kiegroup.
the class AbstractNodeHandler method decorateMultiInstanceSpecification.
protected ForEachNode decorateMultiInstanceSpecification(NodeImpl nodeTarget, MultiInstanceSpecification multiInstanceSpecification) {
ForEachNode forEachNode = new ForEachNode();
forEachNode.setId(nodeTarget.getId());
forEachNode.setName(nodeTarget.getName());
nodeTarget.setMetaData("hidden", true);
forEachNode.setIoSpecification(nodeTarget.getIoSpecification());
DataDefinition dataInput = multiInstanceSpecification.getInputDataItem();
DataDefinition dataOutput = multiInstanceSpecification.getOutputDataItem();
if (dataInput != null) {
forEachNode.setInputRef(dataInput.getLabel());
forEachNode.addContextVariable(dataInput.getId(), dataInput.getLabel(), fromType(dataInput.getType(), currentThread().getContextClassLoader()));
forEachNode.getIoSpecification().getDataInputAssociation().stream().filter(e -> !e.getSources().isEmpty() && e.getSources().get(0).getId().equals(dataInput.getId())).forEach(da -> {
da.getSources().clear();
da.getSources().add(dataInput);
});
}
if (dataOutput != null) {
forEachNode.setOutputRef(dataOutput.getLabel());
forEachNode.addContextVariable(dataOutput.getId(), dataOutput.getLabel(), fromType(dataOutput.getType(), currentThread().getContextClassLoader()));
forEachNode.getIoSpecification().getDataOutputAssociation().stream().filter(e -> e.getTarget().getId().equals(dataOutput.getId())).forEach(da -> {
da.setTarget(dataOutput);
});
}
if (multiInstanceSpecification.hasLoopDataInputRef()) {
DataDefinition dataInputRef = multiInstanceSpecification.getLoopDataInputRef();
// inputs and outputs are still processes so we need to get rid of the input of belonging to the
// loop
nodeTarget.getMetaData().put("MICollectionInput", dataInputRef.getLabel());
// this is a correction as the input collection is the source of the expr (target)
// so target is the input collection of the node
// so we look in the source of the data input a target is equal to the data input getting the source we get the source
// collection at context level (subprocess or activity)
forEachNode.getIoSpecification().getDataInputAssociation().stream().filter(e -> e.getTarget().getId().equals(dataInputRef.getId())).findAny().ifPresent(pVar -> {
String expr = pVar.getSources().get(0).getLabel();
forEachNode.setCollectionExpression(expr);
});
}
if (multiInstanceSpecification.hasLoopDataOutputRef()) {
// same correction as input
// we determine the output ref and locate the source. if set the target we get the variable at that level.
DataDefinition dataOutputRef = multiInstanceSpecification.getLoopDataOutputRef();
nodeTarget.getMetaData().put("MICollectionOutput", dataOutputRef.getLabel());
forEachNode.getIoSpecification().getDataOutputAssociation().stream().filter(e -> e.getSources().get(0).getId().equals(dataOutputRef.getId())).findAny().ifPresent(e -> {
forEachNode.setOutputCollectionExpression(e.getTarget().getLabel());
});
// another correction colletion output is not being stored in the composite context multiinstance
// we use foreach_output
Iterator<DataAssociation> iterator = forEachNode.getIoSpecification().getDataOutputAssociation().iterator();
while (iterator.hasNext()) {
DataAssociation current = iterator.next();
if (!current.getSources().isEmpty() && current.getSources().get(0).equals(dataOutputRef)) {
iterator.remove();
}
}
}
// this is just an expression
forEachNode.setCompletionConditionExpression(multiInstanceSpecification.getCompletionCondition());
forEachNode.setMultiInstanceSpecification(multiInstanceSpecification);
// This variable is used for adding items computed by each subcontext.
// after foreach is finished it will be moved to the data output ref collection of the multiinstance
// this is the context of each subprocess
VariableScope foreachContext = ((VariableScope) forEachNode.getCompositeNode().getDefaultContext(VariableScope.VARIABLE_SCOPE));
Variable forEach = new Variable();
forEach.setId("foreach_output");
forEach.setName("foreach_output");
forEach.setType(DataTypeResolver.fromType(Collection.class.getCanonicalName(), Thread.currentThread().getContextClassLoader()));
foreachContext.addVariable(forEach);
return forEachNode;
}
Aggregations