Search in sources :

Example 1 with Definitions

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

the class DataTest method testDataStore.

@Test
public void testDataStore() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-DataStore.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ProcessInstance processInstance = ksession.startProcess("Evaluation");
    Definitions def = (Definitions) processInstance.getProcess().getMetaData().get("Definitions");
    assertNotNull(def.getDataStores());
    assertTrue(def.getDataStores().size() == 1);
    DataStore dataStore = def.getDataStores().get(0);
    assertEquals("employee", dataStore.getId());
    assertEquals("employeeStore", dataStore.getName());
    assertEquals(String.class.getCanonicalName(), ((ObjectDataType) dataStore.getType()).getClassName());
}
Also used : KieBase(org.kie.api.KieBase) Definitions(org.jbpm.bpmn2.core.Definitions) DataStore(org.jbpm.bpmn2.core.DataStore) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 2 with Definitions

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

the class SubProcessHandler method handleForEachNode.

@SuppressWarnings("unchecked")
protected void handleForEachNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser, boolean isAsync) throws SAXException {
    super.handleNode(node, element, uri, localName, parser);
    ForEachNode forEachNode = (ForEachNode) node;
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("ioSpecification".equals(nodeName)) {
            readIoSpecification(xmlNode, dataInputs, dataOutputs);
        } else if ("dataInputAssociation".equals(nodeName)) {
            readDataInputAssociation(xmlNode, inputAssociation);
        } else if ("dataOutputAssociation".equals(nodeName)) {
            readDataOutputAssociation(xmlNode, outputAssociation);
        } else if ("multiInstanceLoopCharacteristics".equals(nodeName)) {
            readMultiInstanceLoopCharacteristics(xmlNode, forEachNode, parser);
        }
        xmlNode = xmlNode.getNextSibling();
    }
    handleScript(forEachNode, element, "onEntry");
    handleScript(forEachNode, element, "onExit");
    List<SequenceFlow> connections = (List<SequenceFlow>) forEachNode.getMetaData(ProcessHandler.CONNECTIONS);
    ProcessHandler.linkConnections(forEachNode, connections);
    ProcessHandler.linkBoundaryEvents(forEachNode);
    // This must be done *after* linkConnections(process, connections)
    // because it adds hidden connections for compensations
    List<Association> associations = (List<Association>) forEachNode.getMetaData(ProcessHandler.ASSOCIATIONS);
    ProcessHandler.linkAssociations((Definitions) forEachNode.getMetaData("Definitions"), forEachNode, associations);
    applyAsync(node, isAsync);
}
Also used : Association(org.jbpm.bpmn2.core.Association) SequenceFlow(org.jbpm.bpmn2.core.SequenceFlow) ForEachNode(org.jbpm.workflow.core.node.ForEachNode) List(java.util.List)

Example 3 with Definitions

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

the class SubProcessHandler method handleCompositeContextNode.

@SuppressWarnings("unchecked")
protected void handleCompositeContextNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    super.handleNode(node, element, uri, localName, parser);
    CompositeContextNode compositeNode = (CompositeContextNode) node;
    List<SequenceFlow> connections = (List<SequenceFlow>) compositeNode.getMetaData(ProcessHandler.CONNECTIONS);
    handleScript(compositeNode, element, "onEntry");
    handleScript(compositeNode, element, "onExit");
    List<IntermediateLink> throwLinks = (List<IntermediateLink>) compositeNode.getMetaData(ProcessHandler.LINKS);
    ProcessHandler.linkIntermediateLinks(compositeNode, throwLinks);
    ProcessHandler.linkConnections(compositeNode, connections);
    ProcessHandler.linkBoundaryEvents(compositeNode);
    // This must be done *after* linkConnections(process, connections)
    // because it adds hidden connections for compensations
    List<Association> associations = (List<Association>) compositeNode.getMetaData(ProcessHandler.ASSOCIATIONS);
    ProcessHandler.linkAssociations((Definitions) compositeNode.getMetaData("Definitions"), compositeNode, associations);
// TODO: do we fully support interruping ESP's?
/**
 *        for( org.kie.api.definition.process.Node subNode : compositeNode.getNodes() ) {
 *            if( subNode instanceof StartNode ) {
 *                if( ! ((StartNode) subNode).isInterrupting() ) {
 *                    throw new IllegalArgumentException("Non-interrupting event subprocesses are not yet fully supported." );
 *                }
 *            }
 *        }
 */
}
Also used : Association(org.jbpm.bpmn2.core.Association) CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) SequenceFlow(org.jbpm.bpmn2.core.SequenceFlow) List(java.util.List) IntermediateLink(org.jbpm.bpmn2.core.IntermediateLink)

Example 4 with Definitions

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

the class ProcessHandler method linkAssociations.

public static void linkAssociations(Definitions definitions, NodeContainer nodeContainer, List<Association> associations) {
    if (associations != null) {
        for (Association association : associations) {
            String sourceRef = association.getSourceRef();
            Object source = null;
            try {
                source = findNodeOrDataStoreByUniqueId(definitions, nodeContainer, sourceRef, "Could not find source [" + sourceRef + "] for association " + association.getId() + "]");
            } catch (IllegalArgumentException e) {
            // source not found
            }
            String targetRef = association.getTargetRef();
            Object target = null;
            try {
                target = findNodeOrDataStoreByUniqueId(definitions, nodeContainer, targetRef, "Could not find target [" + targetRef + "] for association [" + association.getId() + "]");
            } catch (IllegalArgumentException e) {
            // target not found
            }
            if (source == null || target == null) {
            // TODO: ignoring this association for now
            } else if (target instanceof DataStore || source instanceof DataStore) {
            // TODO: ignoring data store associations for now
            } else if (source instanceof EventNode) {
                EventNode sourceNode = (EventNode) source;
                Node targetNode = (Node) target;
                checkBoundaryEventCompensationHandler(association, sourceNode, targetNode);
                // make sure IsForCompensation is set to true on target
                NodeImpl targetNodeImpl = (NodeImpl) target;
                String isForCompensation = "isForCompensation";
                Object compensationObject = targetNodeImpl.getMetaData(isForCompensation);
                if (compensationObject == null) {
                    targetNodeImpl.setMetaData(isForCompensation, true);
                    logger.warn("Setting {} attribute to true for node {}", isForCompensation, targetRef);
                } else if (!Boolean.parseBoolean(compensationObject.toString())) {
                    throw new IllegalArgumentException(isForCompensation + " attribute [" + compensationObject + "] should be true for Compensation Activity [" + targetRef + "]");
                }
                // put Compensation Handler in CompensationHandlerNode
                NodeContainer sourceParent = sourceNode.getNodeContainer();
                NodeContainer targetParent = targetNode.getNodeContainer();
                if (!sourceParent.equals(targetParent)) {
                    throw new IllegalArgumentException("Compensation Associations may not cross (sub-)process boundaries,");
                }
                // connect boundary event to compensation activity
                ConnectionImpl connection = new ConnectionImpl(sourceNode, NodeImpl.CONNECTION_DEFAULT_TYPE, targetNode, NodeImpl.CONNECTION_DEFAULT_TYPE);
                connection.setMetaData("UniqueId", null);
                connection.setMetaData("hidden", true);
                connection.setMetaData("association", true);
            // Compensation use cases:
            // - boundary event --associated-> activity
            // - implicit sub process compensation handler + recursive?
            /**
             * BPMN2 spec, p.442:
             *   "A Compensation Event Sub-process becomes enabled when its parent Activity transitions into state
             *  Completed. At that time, a snapshot of the data associated with the parent Acitivity is taken and kept for
             *  later usage by the Compensation Event Sub-Process."
             */
            }
        }
    }
}
Also used : BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventNode(org.jbpm.workflow.core.node.EventNode) Association(org.jbpm.bpmn2.core.Association) NodeImpl(org.jbpm.workflow.core.impl.NodeImpl) ExtendedNodeImpl(org.jbpm.workflow.core.impl.ExtendedNodeImpl) DataStore(org.jbpm.bpmn2.core.DataStore) HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) StartNode(org.jbpm.workflow.core.node.StartNode) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) StateNode(org.jbpm.workflow.core.node.StateNode) RuleSetNode(org.jbpm.workflow.core.node.RuleSetNode) SubProcessNode(org.jbpm.workflow.core.node.SubProcessNode) CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) StateBasedNode(org.jbpm.workflow.core.node.StateBasedNode) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) FaultNode(org.jbpm.workflow.core.node.FaultNode) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) ActionNode(org.jbpm.workflow.core.node.ActionNode) EndNode(org.jbpm.workflow.core.node.EndNode) EventNode(org.jbpm.workflow.core.node.EventNode) Node(org.kie.api.definition.process.Node) ConnectionImpl(org.jbpm.workflow.core.impl.ConnectionImpl) NodeContainer(org.kie.api.definition.process.NodeContainer)

Example 5 with Definitions

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

the class DefinitionsHandler method end.

public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    final Element element = parser.endElementBuilder();
    Definitions definitions = (Definitions) parser.getCurrent();
    String namespace = element.getAttribute("targetNamespace");
    List<Process> processes = ((ProcessBuildData) parser.getData()).getProcesses();
    Map<String, ItemDefinition> itemDefinitions = (Map<String, ItemDefinition>) ((ProcessBuildData) parser.getData()).getMetaData("ItemDefinitions");
    List<Interface> interfaces = (List<Interface>) ((ProcessBuildData) parser.getData()).getMetaData("Interfaces");
    for (Process process : processes) {
        RuleFlowProcess ruleFlowProcess = (RuleFlowProcess) process;
        ruleFlowProcess.setMetaData("TargetNamespace", namespace);
        postProcessItemDefinitions(ruleFlowProcess, itemDefinitions, parser.getClassLoader());
        postProcessInterfaces(ruleFlowProcess, interfaces);
    }
    definitions.setTargetNamespace(namespace);
    return definitions;
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) Element(org.w3c.dom.Element) Definitions(org.jbpm.bpmn2.core.Definitions) ItemDefinition(org.jbpm.bpmn2.core.ItemDefinition) Process(org.kie.api.definition.process.Process) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) List(java.util.List) Map(java.util.Map) Interface(org.jbpm.bpmn2.core.Interface)

Aggregations

List (java.util.List)6 Association (org.jbpm.bpmn2.core.Association)5 Definitions (org.jbpm.bpmn2.core.Definitions)4 Error (org.jbpm.bpmn2.core.Error)4 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 DataStore (org.jbpm.bpmn2.core.DataStore)3 ItemDefinition (org.jbpm.bpmn2.core.ItemDefinition)3 SequenceFlow (org.jbpm.bpmn2.core.SequenceFlow)3 ProcessBuildData (org.jbpm.compiler.xml.ProcessBuildData)3 ActionNode (org.jbpm.workflow.core.node.ActionNode)3 EndNode (org.jbpm.workflow.core.node.EndNode)3 EventNode (org.jbpm.workflow.core.node.EventNode)3 ForEachNode (org.jbpm.workflow.core.node.ForEachNode)3 StartNode (org.jbpm.workflow.core.node.StartNode)3 HashSet (java.util.HashSet)2 IntermediateLink (org.jbpm.bpmn2.core.IntermediateLink)2 Node (org.jbpm.workflow.core.Node)2 CompositeContextNode (org.jbpm.workflow.core.node.CompositeContextNode)2