From 77183412531ff3ede2ffa3492e1ec9d244e0a9ac Mon Sep 17 00:00:00 2001 From: Ralph Soika Date: Sat, 24 Feb 2024 09:57:01 +0100 Subject: [PATCH] fixed Issue #336 --- open-bpmn.glsp-client/.gitignore | 2 + .../java/org/openbpmn/bpmn/BPMNModel.java | 11 +++- .../metamodel/test/elements/TestSignal.java | 37 ++++++++++-- .../src/test/resources/refmodel-17.bpmn | 60 +++++++++++++++++++ 4 files changed, 103 insertions(+), 7 deletions(-) create mode 100644 open-bpmn.glsp-client/.gitignore create mode 100644 open-bpmn.metamodel/src/test/resources/refmodel-17.bpmn diff --git a/open-bpmn.glsp-client/.gitignore b/open-bpmn.glsp-client/.gitignore new file mode 100644 index 00000000..beb605e2 --- /dev/null +++ b/open-bpmn.glsp-client/.gitignore @@ -0,0 +1,2 @@ +# ignore dev model files +workspace/dev/ \ No newline at end of file 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 365a1f94..359d184d 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 @@ -1873,16 +1873,25 @@ private void loadMessageFlowList() throws BPMNModelException { * This helper method loads the Signal elements from the diagram - * 'bpmn2:signal' . * + * The method detects duplicates and prints a warning if found. + * * @throws BPMNModelException */ private void loadSignalList() throws BPMNModelException { signals = new LinkedHashSet(); + List duplicates = new ArrayList<>(); NodeList signalNodeList = definitions.getElementsByTagName(getPrefix(BPMNNS.BPMN2) + ":" + BPMNTypes.SIGNAL); if (signalNodeList != null && signalNodeList.getLength() > 0) { for (int i = 0; i < signalNodeList.getLength(); i++) { Element item = (Element) signalNodeList.item(i); Signal signal = new Signal(this, item); - signals.add(signal); + String id = signal.getId(); + if (duplicates.contains(id)) { + logger.warning("Duplicate bpmn2:signal '" + id + "'' found, signal will be ignored!"); + } else { + duplicates.add(id); + signals.add(signal); + } } } } diff --git a/open-bpmn.metamodel/src/test/java/org/openbpmn/metamodel/test/elements/TestSignal.java b/open-bpmn.metamodel/src/test/java/org/openbpmn/metamodel/test/elements/TestSignal.java index d810c796..cd221d35 100644 --- a/open-bpmn.metamodel/src/test/java/org/openbpmn/metamodel/test/elements/TestSignal.java +++ b/open-bpmn.metamodel/src/test/java/org/openbpmn/metamodel/test/elements/TestSignal.java @@ -52,7 +52,7 @@ public void testReadSignal() { fail(); } - logger.info("...model read sucessful "); + logger.info("...model read successful "); } /** @@ -87,7 +87,7 @@ public void testCreateSignal() { } model.save(out); - logger.info("...model created sucessful: " + out); + logger.info("...model created successful: " + out); } @@ -129,13 +129,13 @@ public void testCreateSignalDefinition() { } model.save(out); - logger.info("...model created sucessful: " + out); + logger.info("...model created successful: " + out); } /** - * This test parses a bpmn file and removes singnal_1 which is referred by an - * event + * This test parses a bpmn file and warns if duplicate signal ids are found. + * */ @Test public void testDeleteSignal() { @@ -165,7 +165,32 @@ public void testDeleteSignal() { } model.save(out); - logger.info("...model update sucessful: " + out); + logger.info("...model update successful: " + out); + + } + + /** + * This test parses a bpmn file that causes errors by not computing the signal + * list correctly + */ + @Test + public void testSignalDuplicates() { + BPMNModel model = null; + + logger.info("...read model"); + try { + model = BPMNModelFactory.read("/refmodel-17.bpmn"); + logger.info("...read model"); + // read tasks.... + BPMNProcess process = model.openProcess(null); + assertNotNull(process); + // We expect 2 signals! + assertEquals(2, model.getSignals().size()); + + } catch (BPMNModelException e) { + e.printStackTrace(); + fail(); + } } diff --git a/open-bpmn.metamodel/src/test/resources/refmodel-17.bpmn b/open-bpmn.metamodel/src/test/resources/refmodel-17.bpmn new file mode 100644 index 00000000..2f20c7ba --- /dev/null +++ b/open-bpmn.metamodel/src/test/resources/refmodel-17.bpmn @@ -0,0 +1,60 @@ + + + + + + + + + + SequenceFlow_2 + + + SequenceFlow_2 + + + DataOutput_1 + + + DataOutput_1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file