Skip to content

Commit b0f85f4

Browse files
committed
fixed
Issue #361
1 parent b29dfe5 commit b0f85f4

8 files changed

Lines changed: 102 additions & 2042 deletions

File tree

open-bpmn.glsp-client/workspace/test/bpmn-io-test-model.bpmn

Lines changed: 0 additions & 2031 deletions
This file was deleted.

open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/model/BPMNGModelFactory.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ public GGraph buildGGraph(final BPMNModel model) {
215215
List<GModelElement> gRootNodeList = new ArrayList<>();
216216
Map<String, PoolGNode> poolGNodeList = new HashMap<String, PoolGNode>();
217217

218+
BPMNProcess defaultProcess = model.openDefaultProces();
218219
try {
219220
// In case we have collaboration diagram we iterate over all participants and
220221
// create a pool if the contained process is private. Otherwise we create the
@@ -306,7 +307,7 @@ public GGraph buildGGraph(final BPMNModel model) {
306307
GGraph newGModel = rootBuilder.build();
307308

308309
// finally add the root extensions
309-
applyBPMNElementExtensions(newGModel, model.openDefaultProces());
310+
applyBPMNElementExtensions(newGModel, defaultProcess);
310311

311312
return newGModel;
312313
}
@@ -515,6 +516,7 @@ List<GModelElement> computeGModelElements(final BPMNProcess process, final Parti
515516
List<GModelElement> gRootNodeList)
516517
throws BPMNMissingElementException {
517518

519+
logger.debug("...computeGModel for process '" + process.getId() + "' type=" + process.getProcessType());
518520
List<GModelElement> gNodeList = new ArrayList<>();
519521

520522
// Add all Lanes

open-bpmn.metamodel/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ You can easily extend a simple model to become a collaboration model by creating
5151

5252
```java
5353
BPMNModel model = BPMNModelFactory.createInstance(exporter, version, targetNameSpace);
54-
BPMNProcess processContext = model.addParticipant("participant_1", "Sales Team");
54+
BPMNProcess processContext = model.addParticipant("Sales Team");
5555
model.save("src/test/resources/create-process_1.bpmn");
5656
```
5757

open-bpmn.metamodel/src/main/java/org/openbpmn/bpmn/BPMNModel.java

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,8 @@ public BPMNModel(Document doc) throws BPMNModelException {
178178

179179
// Load BPMNDiagram element....
180180
loadBpmnDiagram();
181-
182181
// Load BPMNPlane element....
183182
loadBpmnPlane();
184-
185183
// init the participant and process list
186184
loadParticipantList();
187185
loadProcessList();
@@ -190,6 +188,7 @@ public BPMNModel(Document doc) throws BPMNModelException {
190188
loadMessageFlowList();
191189
loadSignalList();
192190
}
191+
193192
}
194193

195194
/**
@@ -353,6 +352,10 @@ public void setDirty(boolean isDirty) {
353352
this.isDirty = isDirty;
354353
}
355354

355+
public Element getCollaborationElement() {
356+
return collaborationElement;
357+
}
358+
356359
public Set<Participant> getParticipants() {
357360
if (participants == null) {
358361
participants = new LinkedHashSet<Participant>();
@@ -453,7 +456,7 @@ public boolean isCollaborationDiagram() {
453456
* @return the BPMNParticipant
454457
* @throws BPMNModelException
455458
*/
456-
public Participant addParticipant(String name) throws BPMNModelException {
459+
public Participant addParticipant(String name, String processType) throws BPMNModelException {
457460

458461
// first verify if the model already is a Collaboration model. If not we create
459462
// a bpmn2:collaboration
@@ -500,7 +503,7 @@ public Participant addParticipant(String name) throws BPMNModelException {
500503
// definitionalCollaborationRef="Collaboration_1" isExecutable="false"/>
501504
int processNumber = this.getProcesses().size() + 1;
502505
BPMNProcess process = buildProcess(BPMNModel.generateShortID("process"), "Process " + processNumber,
503-
BPMNTypes.PROCESS_TYPE_PRIVATE);
506+
processType);
504507
process.setAttribute("definitionalCollaborationRef", collaborationElement.getAttribute("id"));
505508
process.setName(name);
506509

@@ -512,6 +515,22 @@ public Participant addParticipant(String name) throws BPMNModelException {
512515
return bpmnParticipant;
513516
}
514517

518+
/**
519+
* Adds a new BPMNParticipant element and the corresponding BPMNProcess to
520+
* collaboration diagram.
521+
* <p>
522+
* The method creates a process of the type 'Private' and updates the
523+
* collaboration diagram structure.
524+
*
525+
* @param name
526+
* @param processType
527+
* @return
528+
* @throws BPMNModelException
529+
*/
530+
public Participant addParticipant(String name) throws BPMNModelException {
531+
return this.addParticipant(name, BPMNTypes.PROCESS_TYPE_PRIVATE);
532+
}
533+
515534
/**
516535
* This method creates a BPMNShape for this participant. The shape element
517536
* represents the Pool within the BPMNDiagram section.
@@ -1949,7 +1968,6 @@ private void loadProcessList() throws BPMNModelException {
19491968
_new_participant.setBpmnProcess(bpmnProcess);
19501969
participants.add(_new_participant);
19511970
}
1952-
19531971
}
19541972

19551973
}
@@ -1958,7 +1976,26 @@ private void loadProcessList() throws BPMNModelException {
19581976
// if we do not have a process at all or a public default process is missing in
19591977
// the participant list, we create a default process now
19601978
if (processes.size() == 0 || (participants.size() > 0 && publicCount == 0)) {
1961-
buildProcess("process_" + (processes.size() + 1), "Default Process", BPMNTypes.PROCESS_TYPE_PUBLIC);
1979+
logger.warning(
1980+
"Invalid model structure: No public process node found - missing default process will be added...");
1981+
// Do we have a normal process diagram?
1982+
if (!isCollaborationDiagram()) {
1983+
// just create the missing public default process
1984+
BPMNProcess publicProcess = buildProcess("process_" + (processes.size() + 1), "Default Process",
1985+
BPMNTypes.PROCESS_TYPE_PUBLIC);
1986+
processes.add(publicProcess);
1987+
} else {
1988+
// we have collaboration diagram with a missing default process
1989+
// create a new default participant
1990+
addParticipant("Default Process", BPMNTypes.PROCESS_TYPE_PUBLIC);
1991+
}
1992+
1993+
// send a notification
1994+
this.setDirty(true);
1995+
this.getNotifications().add(new ModelNotification(ModelNotification.Severity.WARNING,
1996+
"Fixed missing default process!",
1997+
"Invalid model structure: No public process node was found. Missing default process was created automatically to fix this problem."));
1998+
19621999
} else if (publicCount > 1) {
19632000
getLogger().warning("Invalid model structure! The model contains more than one public process instance!");
19642001
}

open-bpmn.metamodel/src/main/java/org/openbpmn/bpmn/elements/BPMNProcess.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public void setProcessType(String processType) {
9999
*/
100100
public void init() throws BPMNModelException {
101101
if (!initialized) {
102+
102103
// now find all relevant bpmn meta elements
103104
NodeList childs = this.getElementNode().getChildNodes();
104105
for (int j = 0; j < childs.getLength(); j++) {
@@ -132,10 +133,43 @@ public void init() throws BPMNModelException {
132133
// logger.warning("Unsupported node type: " + child.getNodeType());
133134
}
134135
}
136+
137+
// In case of an collaboration diagram we also verify if TextAnnotations are
138+
// assigned to the collaboration node. These TextAnnotations need to be assigned
139+
// now to the default process
140+
autoFixUnassignedTextAnnotations();
141+
142+
// initialization completed
135143
initialized = true;
136144
}
137145
}
138146

147+
/**
148+
* This helper method assigns TextAnnotations that are only part of a the
149+
* collaboration node to the default process.
150+
* This is an auto-fix method to migrate invalid external models (e.g. form
151+
* bpmn.io).
152+
*
153+
* @throws BPMNModelException
154+
*/
155+
private void autoFixUnassignedTextAnnotations() throws BPMNModelException {
156+
if (this.isPublicProcess() && this.model.isCollaborationDiagram()
157+
&& this.model.getCollaborationElement() != null) {
158+
NodeList textAnnotationNodeList = this.model.getCollaborationElement()
159+
.getElementsByTagName(this.model.getPrefix(BPMNNS.BPMN2) + BPMNTypes.TEXTANNOTATION);
160+
if (textAnnotationNodeList != null && textAnnotationNodeList.getLength() > 0) {
161+
for (int i = 0; i < textAnnotationNodeList.getLength(); i++) {
162+
Element item = (Element) textAnnotationNodeList.item(i);
163+
// Migrate unassigned textAnnotation
164+
String id = item.getAttribute("id");
165+
logger.fine("TextAnnotation '" + id
166+
+ "' is not assigned to a process. Element will be assigned to the default process");
167+
createBPMNTextAnnotationByNode(item);
168+
}
169+
}
170+
}
171+
}
172+
139173
/**
140174
* Returns true if the process contains no BPMNElementNodes.
141175
*

open-bpmn.metamodel/src/main/java/org/openbpmn/bpmn/elements/core/BPMNElementNode.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.openbpmn.bpmn.exceptions.BPMNInvalidTypeException;
2525
import org.openbpmn.bpmn.exceptions.BPMNMissingElementException;
2626
import org.openbpmn.bpmn.exceptions.BPMNModelException;
27+
import org.w3c.dom.DOMException;
2728
import org.w3c.dom.Element;
2829
import org.w3c.dom.NodeList;
2930

@@ -307,7 +308,12 @@ public void updateBPMNProcess(BPMNProcess newProcess) throws BPMNInvalidTypeExce
307308
}
308309

309310
// remove element from old process and assign it ot the new
310-
this.bpmnProcess.elementNode.removeChild(this.elementNode);
311+
try {
312+
this.bpmnProcess.elementNode.removeChild(this.elementNode);
313+
} catch (DOMException e) {
314+
// remove was not possible
315+
logger.warning("Invalid dom structure: " + e.getMessage());
316+
}
311317
this.bpmnProcess = newProcess;
312318
this.bpmnProcess.elementNode.appendChild(this.elementNode);
313319
}

open-bpmn.metamodel/src/test/java/org/openbpmn/metamodel/external/TestBPMN_IO_Model.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
44
import static org.junit.jupiter.api.Assertions.assertNotNull;
5+
import static org.junit.jupiter.api.Assertions.assertTrue;
56
import static org.junit.jupiter.api.Assertions.fail;
67

78
import java.util.Set;
@@ -13,6 +14,7 @@
1314
import org.openbpmn.bpmn.elements.Gateway;
1415
import org.openbpmn.bpmn.elements.Participant;
1516
import org.openbpmn.bpmn.elements.SequenceFlow;
17+
import org.openbpmn.bpmn.elements.TextAnnotation;
1618
import org.openbpmn.bpmn.elements.core.BPMNElementNode;
1719
import org.openbpmn.bpmn.exceptions.BPMNModelException;
1820
import org.openbpmn.bpmn.util.BPMNModelFactory;
@@ -42,7 +44,9 @@ public void testReadModel() {
4244

4345
Set<Participant> participants = model.getParticipants();
4446
assertNotNull(participants);
45-
assertEquals(2, participants.size());
47+
assertEquals(3, participants.size());
48+
49+
assertTrue(model.isCollaborationDiagram());
4650

4751
// get first participant and load the process context
4852
Participant bpmnParticipant = participants.iterator().next();
@@ -64,6 +68,12 @@ public void testReadModel() {
6468
assertNotNull(sourceElement);
6569
assertEquals("subProcess", sourceElement.getType());
6670

71+
// We expect 10 Text Annotations. But these are not assigned correctly. We
72+
// expect an auto assignment to the default process
73+
BPMNProcess defaultProcess = model.openDefaultProces();
74+
Set<TextAnnotation> textAnnotations = defaultProcess.getTextAnnotations();
75+
assertEquals(12, textAnnotations.size());
76+
6777
} catch (BPMNModelException e) {
6878
e.printStackTrace();
6979
fail();

open-bpmn.metamodel/src/test/java/org/openbpmn/metamodel/test/elements/TestCollaborationModel.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public class TestCollaborationModel {
3434

3535
/**
3636
* This test reads a collaboration model
37+
* The model does not have a default process. This process is automatically
38+
* added by the BPMNModel.
3739
*/
3840
@SuppressWarnings("unused")
3941
@Test
@@ -45,7 +47,7 @@ public void testReadCollaborationModel() {
4547

4648
Set<Participant> participants = model.getParticipants();
4749
assertNotNull(participants);
48-
assertEquals(2, participants.size());
50+
assertEquals(3, participants.size());
4951

5052
// get first participant and load the process context
5153
Participant bpmnParticipant = participants.iterator().next();

0 commit comments

Comments
 (0)