Search in sources :

Example 6 with Collaboration

use of org.jbpm.bpmn2.core.Collaboration in project kogito-runtimes by kiegroup.

the class AssociationHandler method start.

public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
    parser.startElementBuilder(localName, attrs);
    Association association = new Association();
    association.setId(attrs.getValue("id"));
    association.setSourceRef(attrs.getValue("sourceRef"));
    association.setTargetRef(attrs.getValue("targetRef"));
    String direction = attrs.getValue("associationDirection");
    if (direction != null) {
        boolean acceptableDirection = false;
        direction = direction.toLowerCase();
        String[] possibleDirections = { "none", "one", "both" };
        for (String acceptable : possibleDirections) {
            if (acceptable.equals(direction)) {
                acceptableDirection = true;
                break;
            }
        }
        if (!acceptableDirection) {
            throw new ProcessParsingValidationException("Unknown direction '" + direction + "' used in Association " + association.getId());
        }
    }
    association.setDirection(direction);
    /**
     * BPMN2 spec, p. 66:
     * "At this point, BPMN provides three standard Artifacts: Associations,
     * Groups, and Text Annotations.
     * ...
     * When an Artifact is defined it is contained within a Collaboration
     * or a FlowElementsContainer (a Process or Choreography)."
     *
     * (In other words: associations must be defined within a process, not outside)
     */
    List<Association> associations = null;
    NodeContainer nodeContainer = (NodeContainer) parser.getParent();
    if (nodeContainer instanceof Process) {
        RuleFlowProcess process = (RuleFlowProcess) nodeContainer;
        associations = (List<Association>) process.getMetaData(ASSOCIATIONS);
        if (associations == null) {
            associations = new ArrayList<>();
            process.setMetaData(ASSOCIATIONS, associations);
        }
    } else if (nodeContainer instanceof CompositeNode) {
        CompositeContextNode compositeNode = (CompositeContextNode) nodeContainer;
        associations = (List<Association>) compositeNode.getMetaData(ASSOCIATIONS);
        if (associations == null) {
            associations = new ArrayList<>();
            compositeNode.setMetaData(ProcessHandler.ASSOCIATIONS, associations);
        }
    } else {
        associations = new ArrayList<>();
    }
    associations.add(association);
    return association;
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) ArrayList(java.util.ArrayList) NodeContainer(org.jbpm.workflow.core.NodeContainer) Process(org.kie.api.definition.process.Process) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) Association(org.jbpm.bpmn2.core.Association) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with Collaboration

use of org.jbpm.bpmn2.core.Collaboration in project jbpm by kiegroup.

the class AssociationHandler method start.

public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
    parser.startElementBuilder(localName, attrs);
    Association association = new Association();
    association.setId(attrs.getValue("id"));
    association.setSourceRef(attrs.getValue("sourceRef"));
    association.setTargetRef(attrs.getValue("targetRef"));
    String direction = attrs.getValue("associationDirection");
    if (direction != null) {
        boolean acceptableDirection = false;
        direction = direction.toLowerCase();
        String[] possibleDirections = { "none", "one", "both" };
        for (String acceptable : possibleDirections) {
            if (acceptable.equals(direction)) {
                acceptableDirection = true;
                break;
            }
        }
        if (!acceptableDirection) {
            throw new IllegalArgumentException("Unknown direction '" + direction + "' used in Association " + association.getId());
        }
    }
    association.setDirection(direction);
    /**
     * BPMN2 spec, p. 66:
     * "At this point, BPMN provides three standard Artifacts: Associations,
     *  Groups, and Text Annotations.
     * ...
     *  When an Artifact is defined it is contained within a Collaboration
     *  or a FlowElementsContainer (a Process or Choreography)."
     *
     * (In other words: associations must be defined within a process, not outside)
     */
    List<Association> associations = null;
    NodeContainer nodeContainer = (NodeContainer) parser.getParent();
    if (nodeContainer instanceof Process) {
        RuleFlowProcess process = (RuleFlowProcess) nodeContainer;
        associations = (List<Association>) process.getMetaData(ASSOCIATIONS);
        if (associations == null) {
            associations = new ArrayList<>();
            process.setMetaData(ASSOCIATIONS, associations);
        }
    } else if (nodeContainer instanceof CompositeNode) {
        CompositeContextNode compositeNode = (CompositeContextNode) nodeContainer;
        associations = (List<Association>) compositeNode.getMetaData(ASSOCIATIONS);
        if (associations == null) {
            associations = new ArrayList<>();
            compositeNode.setMetaData(ProcessHandler.ASSOCIATIONS, associations);
        }
    } else {
        associations = new ArrayList<>();
    }
    associations.add(association);
    return association;
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) ArrayList(java.util.ArrayList) NodeContainer(org.jbpm.workflow.core.NodeContainer) Process(org.kie.api.definition.process.Process) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) Association(org.jbpm.bpmn2.core.Association) ArrayList(java.util.ArrayList) List(java.util.List)

Example 8 with Collaboration

use of org.jbpm.bpmn2.core.Collaboration in project jbpm by kiegroup.

the class CollaborationHandler method start.

@Override
public Object start(String uri, String localName, Attributes attrs, ExtensibleXmlParser parser) throws SAXException {
    parser.startElementBuilder(localName, attrs);
    String collaborationPropertyId = attrs.getValue("id");
    String collaborationPropertyName = attrs.getValue("name");
    Collaboration collaboration = new Collaboration();
    collaboration.setId(collaborationPropertyId);
    collaboration.setName(collaborationPropertyName);
    HandlerUtil.collaborations(parser).put(collaborationPropertyId, collaboration);
    return collaboration;
}
Also used : Collaboration(org.jbpm.bpmn2.core.Collaboration)

Example 9 with Collaboration

use of org.jbpm.bpmn2.core.Collaboration 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);
        }
    }
}
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) CancelNodeInstanceAction(org.jbpm.process.instance.impl.actions.CancelNodeInstanceAction) 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) VariableScope(org.jbpm.process.core.context.variable.VariableScope) KogitoNode(org.kie.kogito.internal.process.runtime.KogitoNode) 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) SAXException(org.xml.sax.SAXException) CorrelationKey(org.jbpm.bpmn2.core.CorrelationKey) ProcessInstanceCompensationAction(org.jbpm.process.instance.impl.actions.ProcessInstanceCompensationAction) 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) SignalProcessInstanceAction(org.jbpm.process.instance.impl.actions.SignalProcessInstanceAction) 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) 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) Metadata(org.jbpm.ruleflow.core.Metadata) 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) Action(org.jbpm.process.instance.impl.Action) KogitoWorkflowProcess(org.kie.kogito.internal.process.runtime.KogitoWorkflowProcess) 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 10 with Collaboration

use of org.jbpm.bpmn2.core.Collaboration in project kogito-runtimes by kiegroup.

the class CollaborationHandler method end.

@Override
public Object end(String uri, String localName, ExtensibleXmlParser parser) throws SAXException {
    Element element = parser.endElementBuilder();
    Collaboration collaboration = (Collaboration) parser.getCurrent();
    buildCorrelationKeys(collaboration, element.getChildNodes());
    return null;
}
Also used : Collaboration(org.jbpm.bpmn2.core.Collaboration) Element(org.w3c.dom.Element)

Aggregations

Collaboration (org.jbpm.bpmn2.core.Collaboration)6 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Association (org.jbpm.bpmn2.core.Association)4 CorrelationKey (org.jbpm.bpmn2.core.CorrelationKey)4 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)4 CompositeContextNode (org.jbpm.workflow.core.node.CompositeContextNode)4 CompositeNode (org.jbpm.workflow.core.node.CompositeNode)4 Process (org.kie.api.definition.process.Process)4 Element (org.w3c.dom.Element)3 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 Map (java.util.Map)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 BaseAbstractHandler (org.drools.core.xml.BaseAbstractHandler)2 ExtensibleXmlParser (org.drools.core.xml.ExtensibleXmlParser)2