use of org.jbpm.bpmn2.core.Expression in project jbpm 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.correlationSuscription(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.jbpm.bpmn2.core.Expression in project jbpm 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;
}
});
KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-ServiceProcessWithCustomTransformation.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.getWorkItemManager().registerWorkItemHandler("Service Task", new ServiceTaskHandler());
Map<String, Object> params = new HashMap<String, Object>();
params.put("s", "john doe");
WorkflowProcessInstance processInstance = (WorkflowProcessInstance) ksession.startProcess("ServiceProcess", params);
assertProcessInstanceFinished(processInstance, ksession);
assertEquals("John doE", processInstance.getVariable("s"));
}
use of org.jbpm.bpmn2.core.Expression in project jbpm 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 jbpm 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 jbpm by kiegroup.
the class CorrelationPropertyHandler method buildMessagePathExpression.
private Expression buildMessagePathExpression(NodeList childNodes, ExtensibleXmlParser parser) {
for (int i = 0; i < childNodes.getLength(); i++) {
Node node = childNodes.item(i);
if ("messagePath".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());
}
Aggregations