Search in sources :

Example 1 with Expression

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);
        }
    }
}
Also used : EventFilter(org.jbpm.process.core.event.EventFilter) ConstraintTrigger(org.jbpm.workflow.core.node.ConstraintTrigger) CorrelationManager(org.jbpm.process.core.correlation.CorrelationManager) HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode) SequenceFlow(org.jbpm.bpmn2.core.SequenceFlow) LoggerFactory(org.slf4j.LoggerFactory) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) StartNode(org.jbpm.workflow.core.node.StartNode) CorrelationProperty(org.jbpm.bpmn2.core.CorrelationProperty) RuleFlowProcessValidator(org.jbpm.ruleflow.core.validation.RuleFlowProcessValidator) NodeImpl(org.jbpm.workflow.core.impl.NodeImpl) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) ItemDefinition(org.jbpm.bpmn2.core.ItemDefinition) Constraint(org.jbpm.workflow.core.Constraint) ExtensibleXmlParser(org.drools.core.xml.ExtensibleXmlParser) Association(org.jbpm.bpmn2.core.Association) Connection(org.jbpm.workflow.core.Connection) StateNode(org.jbpm.workflow.core.node.StateNode) ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) RuleSetNode(org.jbpm.workflow.core.node.RuleSetNode) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Signal(org.jbpm.bpmn2.core.Signal) SubProcessNode(org.jbpm.workflow.core.node.SubProcessNode) EventTrigger(org.jbpm.workflow.core.node.EventTrigger) CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) Collaboration(org.jbpm.bpmn2.core.Collaboration) Collection(java.util.Collection) Process(org.kie.api.definition.process.Process) Collectors(java.util.stream.Collectors) IntermediateLink(org.jbpm.bpmn2.core.IntermediateLink) ActionExceptionHandler(org.jbpm.process.core.context.exception.ActionExceptionHandler) Message(org.jbpm.bpmn2.core.Message) List(java.util.List) Error(org.jbpm.bpmn2.core.Error) Stream(java.util.stream.Stream) ContextContainer(org.jbpm.process.core.ContextContainer) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) SignalNodeInstanceAction(org.jbpm.process.instance.impl.SignalNodeInstanceAction) SAXException(org.xml.sax.SAXException) CorrelationKey(org.jbpm.bpmn2.core.CorrelationKey) Trigger(org.jbpm.workflow.core.node.Trigger) NodeContainer(org.kie.api.definition.process.NodeContainer) DataStore(org.jbpm.bpmn2.core.DataStore) ExceptionScope(org.jbpm.process.core.context.exception.ExceptionScope) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) StateBasedNode(org.jbpm.workflow.core.node.StateBasedNode) CompensationScope(org.jbpm.process.core.context.exception.CompensationScope) Escalation(org.jbpm.bpmn2.core.Escalation) CancelNodeInstanceAction(org.jbpm.process.instance.impl.CancelNodeInstanceAction) Split(org.jbpm.workflow.core.node.Split) HashMap(java.util.HashMap) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) ArrayList(java.util.ArrayList) Lane(org.jbpm.bpmn2.core.Lane) Timer(org.jbpm.process.core.timer.Timer) HashSet(java.util.HashSet) Expression(org.jbpm.bpmn2.core.Expression) Swimlane(org.jbpm.process.core.context.swimlane.Swimlane) Attributes(org.xml.sax.Attributes) BaseAbstractHandler(org.drools.core.xml.BaseAbstractHandler) ConnectionImpl(org.jbpm.workflow.core.impl.ConnectionImpl) FaultNode(org.jbpm.workflow.core.node.FaultNode) DroolsAction(org.jbpm.workflow.core.DroolsAction) LinkedHashSet(java.util.LinkedHashSet) CorrelationSubscription(org.jbpm.bpmn2.core.CorrelationSubscription) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) Interface(org.jbpm.bpmn2.core.Interface) ConnectionRef(org.jbpm.workflow.core.impl.ConnectionRef) ActionNode(org.jbpm.workflow.core.node.ActionNode) EndNode(org.jbpm.workflow.core.node.EndNode) Logger(org.slf4j.Logger) EventNode(org.jbpm.workflow.core.node.EventNode) ConstraintImpl(org.jbpm.workflow.core.impl.ConstraintImpl) Handler(org.drools.core.xml.Handler) MVELMessageExpressionEvaluator(org.jbpm.process.core.event.MVELMessageExpressionEvaluator) Node(org.kie.api.definition.process.Node) CompensationHandler(org.jbpm.process.core.context.exception.CompensationHandler) Definitions(org.jbpm.bpmn2.core.Definitions) ExtendedNodeImpl(org.jbpm.workflow.core.impl.ExtendedNodeImpl) MVELMessageExpressionEvaluator(org.jbpm.process.core.event.MVELMessageExpressionEvaluator) Message(org.jbpm.bpmn2.core.Message) CorrelationSubscription(org.jbpm.bpmn2.core.CorrelationSubscription) CorrelationManager(org.jbpm.process.core.correlation.CorrelationManager) CorrelationKey(org.jbpm.bpmn2.core.CorrelationKey) Expression(org.jbpm.bpmn2.core.Expression) Collaboration(org.jbpm.bpmn2.core.Collaboration) CorrelationProperty(org.jbpm.bpmn2.core.CorrelationProperty) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with Expression

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"));
}
Also used : ServiceTaskHandler(org.jbpm.bpmn2.handler.ServiceTaskHandler) DataTransformer(org.kie.api.runtime.process.DataTransformer) HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Test(org.junit.Test)

Example 3 with Expression

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;
}
Also used : Expression(org.jbpm.bpmn2.core.Expression) HashMap(java.util.HashMap) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element)

Example 4 with Expression

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());
}
Also used : Expression(org.jbpm.bpmn2.core.Expression) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element)

Example 5 with Expression

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());
}
Also used : Expression(org.jbpm.bpmn2.core.Expression) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element)

Aggregations

Element (org.w3c.dom.Element)10 HashMap (java.util.HashMap)8 Expression (org.jbpm.bpmn2.core.Expression)8 SequenceFlow (org.jbpm.bpmn2.core.SequenceFlow)7 Node (org.w3c.dom.Node)6 List (java.util.List)5 Map (java.util.Map)4 ItemDefinition (org.jbpm.bpmn2.core.ItemDefinition)4 ProcessBuildData (org.jbpm.compiler.xml.ProcessBuildData)4 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 HashSet (java.util.HashSet)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 BaseAbstractHandler (org.drools.core.xml.BaseAbstractHandler)3 ExtensibleXmlParser (org.drools.core.xml.ExtensibleXmlParser)3 Handler (org.drools.core.xml.Handler)3 Association (org.jbpm.bpmn2.core.Association)3 Definitions (org.jbpm.bpmn2.core.Definitions)3 Error (org.jbpm.bpmn2.core.Error)3 Lane (org.jbpm.bpmn2.core.Lane)3