diff --git a/open-bpmn.metamodel/src/main/java/org/openbpmn/bpmn/BPMNModel.java b/open-bpmn.metamodel/src/main/java/org/openbpmn/bpmn/BPMNModel.java
index 4df3392e..a06f0dd1 100644
--- a/open-bpmn.metamodel/src/main/java/org/openbpmn/bpmn/BPMNModel.java
+++ b/open-bpmn.metamodel/src/main/java/org/openbpmn/bpmn/BPMNModel.java
@@ -911,9 +911,7 @@ public Message addMessage(String id, String name) throws BPMNModelException {
* @throws BPMNMissingElementException
* @throws BPMNInvalidTypeException
*/
- public Signal findSignalByName(String name)
- throws BPMNInvalidReferenceException, BPMNMissingElementException, BPMNInvalidTypeException {
-
+ public Signal findSignalByName(String name) {
if (name == null || name.isEmpty()) {
return null;
}
@@ -926,16 +924,19 @@ public Signal findSignalByName(String name)
}
/**
- * Deletes a Signal element from this diagram.
+ * Finds a Signal element by its ID withing the diagram
*
+ *
*
- * @param id
+ * @param name - name of the signal
+ * @throws BPMNInvalidReferenceException
+ * @throws BPMNMissingElementException
+ * @throws BPMNInvalidTypeException
*/
- public void deleteSignal(String id) {
+ public Signal findSignal(String id) {
if (id == null || id.isEmpty()) {
- return;
+ return null;
}
-
Signal signal = null;
for (Signal _signal : getSignals()) {
if (id.equals(_signal.getId())) {
@@ -944,7 +945,17 @@ public void deleteSignal(String id) {
}
}
+ return signal;
+ }
+ /**
+ * Deletes a Signal element from this diagram.
+ *
+ *
+ * @param id
+ */
+ public void deleteSignal(String id) {
+ Signal signal = findSignal(id);
if (signal == null) {
// does not exist
return;
@@ -1346,14 +1357,16 @@ public Participant findParticipantByPoint(BPMNPoint point) throws BPMNInvalidTyp
*
* @param name
* @return
+ * @throws BPMNModelException
*/
- public BPMNProcess findProcessByName(String processName) {
+ public BPMNProcess findProcessByName(String processName) throws BPMNModelException {
if (processName == null || processName.isEmpty()) {
return null; // no name provided!
}
Set processList = getProcesses();
for (BPMNProcess _process : processList) {
if (processName.equals(_process.getName())) {
+ _process.init();
return _process;
}
}
diff --git a/open-bpmn.metamodel/src/main/java/org/openbpmn/bpmn/elements/core/BPMNElementNode.java b/open-bpmn.metamodel/src/main/java/org/openbpmn/bpmn/elements/core/BPMNElementNode.java
index b3ec0605..530e3ab4 100644
--- a/open-bpmn.metamodel/src/main/java/org/openbpmn/bpmn/elements/core/BPMNElementNode.java
+++ b/open-bpmn.metamodel/src/main/java/org/openbpmn/bpmn/elements/core/BPMNElementNode.java
@@ -1,5 +1,6 @@
package org.openbpmn.bpmn.elements.core;
+import java.util.HashSet;
import java.util.Set;
import java.util.logging.Logger;
import java.util.stream.Collectors;
@@ -572,4 +573,29 @@ public Set getAssociations() {
return result;
}
+
+ /**
+ * Returns a List of all DataObjects associated with this element
+ *
+ * @param event
+ * @return
+ */
+ public Set getDataObjects() {
+ Set result = new HashSet();
+ Set associations = this.getAssociations();
+ // find Data objects...
+ for (Association association : associations) {
+ BPMNElementNode source = association.getSourceElement();
+ BPMNElementNode target = association.getTargetElement();
+ if (source instanceof DataObject) {
+ result.add((DataObject) source);
+ }
+ if (target instanceof DataObject) {
+ result.add((DataObject) target);
+ }
+
+ }
+ return result;
+ }
+
}
diff --git a/open-bpmn.metamodel/src/main/java/org/openbpmn/bpmn/navigation/BPMNStartElementIterator.java b/open-bpmn.metamodel/src/main/java/org/openbpmn/bpmn/navigation/BPMNStartElementIterator.java
new file mode 100644
index 00000000..08a5b338
--- /dev/null
+++ b/open-bpmn.metamodel/src/main/java/org/openbpmn/bpmn/navigation/BPMNStartElementIterator.java
@@ -0,0 +1,82 @@
+package org.openbpmn.bpmn.navigation;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.function.Predicate;
+import java.util.logging.Logger;
+
+import org.openbpmn.bpmn.BPMNTypes;
+import org.openbpmn.bpmn.elements.BPMNProcess;
+import org.openbpmn.bpmn.elements.Event;
+import org.openbpmn.bpmn.elements.core.BPMNElement;
+import org.openbpmn.bpmn.elements.core.BPMNElementNode;
+import org.openbpmn.bpmn.exceptions.BPMNValidationException;
+
+/**
+ * The BPMNStartElementIterator returns Elements that immediately follow a start
+ * event. This can be either an Intermediate Catch/Throw Events or an Activity
+ * (Task).
+ *
+ *
+ * With the filter argument (Functional Interface Predicate) an argument can be
+ * provided to return only specific elements.
+ *
+ *
+ */
+public class BPMNStartElementIterator implements Iterator {
+
+ protected static Logger logger = Logger.getLogger(BPMNElementNode.class.getName());
+ Set _startEventNodes;
+
+ private List resultElementList;
+ private Iterator allStartElementsIterator;
+
+ /**
+ * Creates an Iterator with a given filter criteria.
+ * The method collects all BPMNElements following the given start element and
+ * matching the given filter
+ *
+ * @param bpmnElementNode
+ * @param filter
+ * @throws BPMNValidationException
+ */
+ public BPMNStartElementIterator(BPMNProcess process, Predicate filter) {
+ resultElementList = new ArrayList<>();
+
+ // First find all Start Events in the model
+ _startEventNodes = new HashSet<>();
+ Set allEventNodes = process.getEvents();
+ for (Event _event : allEventNodes) {
+ if (BPMNTypes.START_EVENT.equals(_event.getType())) {
+ _startEventNodes.add(_event);
+ }
+ }
+
+ // next resolve all follow up tasks and events based on the given Predicate
+ for (BPMNElement element : _startEventNodes) {
+ BPMNFlowIterator followUpElements = new BPMNFlowIterator(
+ (BPMNElementNode) element,
+ filter);
+ // add the followup elements to the result list
+ while (followUpElements.hasNext()) {
+ resultElementList.add(followUpElements.next());
+ }
+ }
+ // create a local iterator instance
+ allStartElementsIterator = resultElementList.iterator();
+ }
+
+ @Override
+ public boolean hasNext() {
+ return allStartElementsIterator.hasNext();
+ }
+
+ @Override
+ public BPMNElementNode next() {
+ return allStartElementsIterator.next();
+ }
+
+}
diff --git a/open-bpmn.metamodel/src/test/java/org/openbpmn/metamodel/navigation/TestStartNavigation.java b/open-bpmn.metamodel/src/test/java/org/openbpmn/metamodel/navigation/TestStartNavigation.java
new file mode 100644
index 00000000..c456d3d2
--- /dev/null
+++ b/open-bpmn.metamodel/src/test/java/org/openbpmn/metamodel/navigation/TestStartNavigation.java
@@ -0,0 +1,118 @@
+package org.openbpmn.metamodel.navigation;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Logger;
+
+import org.junit.jupiter.api.Test;
+import org.openbpmn.bpmn.BPMNModel;
+import org.openbpmn.bpmn.elements.Activity;
+import org.openbpmn.bpmn.elements.BPMNProcess;
+import org.openbpmn.bpmn.elements.Event;
+import org.openbpmn.bpmn.elements.core.BPMNElementNode;
+import org.openbpmn.bpmn.exceptions.BPMNModelException;
+import org.openbpmn.bpmn.navigation.BPMNStartElementIterator;
+import org.openbpmn.bpmn.util.BPMNModelFactory;
+import org.openbpmn.metamodel.examples.TestCreateEdges;
+
+/**
+ * Test class to test the StartNavigator.
+ *
+ */
+public class TestStartNavigation {
+ private static Logger logger = Logger.getLogger(TestCreateEdges.class.getName());
+
+ /**
+ * This test loads model 'refmodel-navigation-01.bpmn' and finds the start
+ * task-1.
+ *
+ * @throws BPMNModelException
+ *
+ */
+ @SuppressWarnings("rawtypes")
+ @Test
+ public void testFindStartTask1() throws BPMNModelException {
+
+ logger.info("...read model");
+ BPMNModel model = BPMNModelFactory.read("/refmodel-navigation-01.bpmn");
+ BPMNProcess process = model.openDefaultProces();
+
+ // get start Task1
+ BPMNStartElementIterator startElements = new BPMNStartElementIterator<>(process, n -> n instanceof Activity);
+ assertNotNull(startElements);
+ assertTrue(startElements.hasNext());
+
+ BPMNElementNode task1 = startElements.next();
+ assertNotNull(task1);
+
+ assertEquals("Task-1", task1.getName());
+ // no more elements exprected
+ assertFalse(startElements.hasNext());
+ }
+
+ /**
+ * This test loads model 'refmodel-navigation-01.bpmn' and finds the start
+ * task-1.
+ *
+ * @throws BPMNModelException
+ *
+ */
+ @SuppressWarnings("rawtypes")
+ @Test
+ public void testFindStartTask1WithEvents() throws BPMNModelException {
+
+ logger.info("...read model");
+ BPMNModel model = BPMNModelFactory.read("/refmodel-navigation-01.bpmn");
+ BPMNProcess process = model.openDefaultProces();
+
+ // get start Task1
+ BPMNStartElementIterator startElements = new BPMNStartElementIterator<>(process,
+ node -> (node instanceof Activity || node instanceof Event));
+ assertNotNull(startElements);
+ assertTrue(startElements.hasNext());
+
+ BPMNElementNode task1 = startElements.next();
+ assertNotNull(task1);
+
+ assertEquals("Task-1", task1.getName());
+ // no more elements expected
+ assertFalse(startElements.hasNext());
+ }
+
+ /**
+ * This test loads model 'refmodel-navigation-04.bpmn' and finds all conditional
+ * start events.
+ *
+ * In this test we ignore all conditions and expect 3 events
+ *
+ * @throws BPMNModelException
+ *
+ */
+ @SuppressWarnings("rawtypes")
+ @Test
+ public void testFindConditionalStartEvents() throws BPMNModelException {
+
+ logger.info("...read model");
+ BPMNModel model = BPMNModelFactory.read("/refmodel-navigation-04.bpmn");
+ BPMNProcess process = model.openDefaultProces();
+
+ // get start Task1
+ BPMNStartElementIterator startElements = new BPMNStartElementIterator<>(process,
+ node -> (node instanceof Activity || node instanceof Event));
+ assertNotNull(startElements);
+ assertTrue(startElements.hasNext());
+
+ List resultList = new ArrayList<>();
+ while (startElements.hasNext()) {
+ resultList.add(startElements.next());
+ }
+
+ assertEquals(3, resultList.size());
+ }
+
+}
diff --git a/open-bpmn.metamodel/src/test/resources/refmodel-navigation-04.bpmn b/open-bpmn.metamodel/src/test/resources/refmodel-navigation-04.bpmn
new file mode 100644
index 00000000..252da5eb
--- /dev/null
+++ b/open-bpmn.metamodel/src/test/resources/refmodel-navigation-04.bpmn
@@ -0,0 +1,174 @@
+
+
+
+ true
+
+
+
+
+
+ sequenceFlow_rstY8Q
+
+
+
+ sequenceFlow_NVfK3w
+ sequenceFlow_MNZU9g
+ sequenceFlow_Y0i62A
+ sequenceFlow_gZSk0Q
+
+
+
+ sequenceFlow_gZSk0Q
+ sequenceFlow_ES26Kg
+
+
+
+ sequenceFlow_NVfK3w
+ sequenceFlow_NPmh3w
+
+
+
+
+
+
+
+
+
+ sequenceFlow_MNZU9g
+
+
+
+
+
+
+ sequenceFlow_f4hhBA
+ sequenceFlow_NPmh3w
+
+
+
+ sequenceFlow_Y0i62A
+ sequenceFlow_TIcibw
+
+
+
+
+
+
+
+
+
+ sequenceFlow_ES26Kg
+ sequenceFlow_TIcibw
+ sequenceFlow_f4hhBA
+ sequenceFlow_rstY8Q
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+