Skip to content

Commit

Permalink
fixed
Browse files Browse the repository at this point in the history
Issue #361
  • Loading branch information
rsoika committed Nov 9, 2024
1 parent b29dfe5 commit b0f85f4
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 2,042 deletions.
2,031 changes: 0 additions & 2,031 deletions open-bpmn.glsp-client/workspace/test/bpmn-io-test-model.bpmn

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ public GGraph buildGGraph(final BPMNModel model) {
List<GModelElement> gRootNodeList = new ArrayList<>();
Map<String, PoolGNode> poolGNodeList = new HashMap<String, PoolGNode>();

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

// finally add the root extensions
applyBPMNElementExtensions(newGModel, model.openDefaultProces());
applyBPMNElementExtensions(newGModel, defaultProcess);

return newGModel;
}
Expand Down Expand Up @@ -515,6 +516,7 @@ List<GModelElement> computeGModelElements(final BPMNProcess process, final Parti
List<GModelElement> gRootNodeList)
throws BPMNMissingElementException {

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

// Add all Lanes
Expand Down
2 changes: 1 addition & 1 deletion open-bpmn.metamodel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ You can easily extend a simple model to become a collaboration model by creating

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

Expand Down
49 changes: 43 additions & 6 deletions open-bpmn.metamodel/src/main/java/org/openbpmn/bpmn/BPMNModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,8 @@ public BPMNModel(Document doc) throws BPMNModelException {

// Load BPMNDiagram element....
loadBpmnDiagram();

// Load BPMNPlane element....
loadBpmnPlane();

// init the participant and process list
loadParticipantList();
loadProcessList();
Expand All @@ -190,6 +188,7 @@ public BPMNModel(Document doc) throws BPMNModelException {
loadMessageFlowList();
loadSignalList();
}

}

/**
Expand Down Expand Up @@ -353,6 +352,10 @@ public void setDirty(boolean isDirty) {
this.isDirty = isDirty;
}

public Element getCollaborationElement() {
return collaborationElement;
}

public Set<Participant> getParticipants() {
if (participants == null) {
participants = new LinkedHashSet<Participant>();
Expand Down Expand Up @@ -453,7 +456,7 @@ public boolean isCollaborationDiagram() {
* @return the BPMNParticipant
* @throws BPMNModelException
*/
public Participant addParticipant(String name) throws BPMNModelException {
public Participant addParticipant(String name, String processType) throws BPMNModelException {

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

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

/**
* Adds a new BPMNParticipant element and the corresponding BPMNProcess to
* collaboration diagram.
* <p>
* The method creates a process of the type 'Private' and updates the
* collaboration diagram structure.
*
* @param name
* @param processType
* @return
* @throws BPMNModelException
*/
public Participant addParticipant(String name) throws BPMNModelException {
return this.addParticipant(name, BPMNTypes.PROCESS_TYPE_PRIVATE);
}

/**
* This method creates a BPMNShape for this participant. The shape element
* represents the Pool within the BPMNDiagram section.
Expand Down Expand Up @@ -1949,7 +1968,6 @@ private void loadProcessList() throws BPMNModelException {
_new_participant.setBpmnProcess(bpmnProcess);
participants.add(_new_participant);
}

}

}
Expand All @@ -1958,7 +1976,26 @@ private void loadProcessList() throws BPMNModelException {
// if we do not have a process at all or a public default process is missing in
// the participant list, we create a default process now
if (processes.size() == 0 || (participants.size() > 0 && publicCount == 0)) {
buildProcess("process_" + (processes.size() + 1), "Default Process", BPMNTypes.PROCESS_TYPE_PUBLIC);
logger.warning(
"Invalid model structure: No public process node found - missing default process will be added...");
// Do we have a normal process diagram?
if (!isCollaborationDiagram()) {
// just create the missing public default process
BPMNProcess publicProcess = buildProcess("process_" + (processes.size() + 1), "Default Process",
BPMNTypes.PROCESS_TYPE_PUBLIC);
processes.add(publicProcess);
} else {
// we have collaboration diagram with a missing default process
// create a new default participant
addParticipant("Default Process", BPMNTypes.PROCESS_TYPE_PUBLIC);
}

// send a notification
this.setDirty(true);
this.getNotifications().add(new ModelNotification(ModelNotification.Severity.WARNING,
"Fixed missing default process!",
"Invalid model structure: No public process node was found. Missing default process was created automatically to fix this problem."));

} else if (publicCount > 1) {
getLogger().warning("Invalid model structure! The model contains more than one public process instance!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public void setProcessType(String processType) {
*/
public void init() throws BPMNModelException {
if (!initialized) {

// now find all relevant bpmn meta elements
NodeList childs = this.getElementNode().getChildNodes();
for (int j = 0; j < childs.getLength(); j++) {
Expand Down Expand Up @@ -132,10 +133,43 @@ public void init() throws BPMNModelException {
// logger.warning("Unsupported node type: " + child.getNodeType());
}
}

// In case of an collaboration diagram we also verify if TextAnnotations are
// assigned to the collaboration node. These TextAnnotations need to be assigned
// now to the default process
autoFixUnassignedTextAnnotations();

// initialization completed
initialized = true;
}
}

/**
* This helper method assigns TextAnnotations that are only part of a the
* collaboration node to the default process.
* This is an auto-fix method to migrate invalid external models (e.g. form
* bpmn.io).
*
* @throws BPMNModelException
*/
private void autoFixUnassignedTextAnnotations() throws BPMNModelException {
if (this.isPublicProcess() && this.model.isCollaborationDiagram()
&& this.model.getCollaborationElement() != null) {
NodeList textAnnotationNodeList = this.model.getCollaborationElement()
.getElementsByTagName(this.model.getPrefix(BPMNNS.BPMN2) + BPMNTypes.TEXTANNOTATION);
if (textAnnotationNodeList != null && textAnnotationNodeList.getLength() > 0) {
for (int i = 0; i < textAnnotationNodeList.getLength(); i++) {
Element item = (Element) textAnnotationNodeList.item(i);
// Migrate unassigned textAnnotation
String id = item.getAttribute("id");
logger.fine("TextAnnotation '" + id
+ "' is not assigned to a process. Element will be assigned to the default process");
createBPMNTextAnnotationByNode(item);
}
}
}
}

/**
* Returns true if the process contains no BPMNElementNodes.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.openbpmn.bpmn.exceptions.BPMNInvalidTypeException;
import org.openbpmn.bpmn.exceptions.BPMNMissingElementException;
import org.openbpmn.bpmn.exceptions.BPMNModelException;
import org.w3c.dom.DOMException;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

Expand Down Expand Up @@ -307,7 +308,12 @@ public void updateBPMNProcess(BPMNProcess newProcess) throws BPMNInvalidTypeExce
}

// remove element from old process and assign it ot the new
this.bpmnProcess.elementNode.removeChild(this.elementNode);
try {
this.bpmnProcess.elementNode.removeChild(this.elementNode);
} catch (DOMException e) {
// remove was not possible
logger.warning("Invalid dom structure: " + e.getMessage());
}
this.bpmnProcess = newProcess;
this.bpmnProcess.elementNode.appendChild(this.elementNode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.util.Set;
Expand All @@ -13,6 +14,7 @@
import org.openbpmn.bpmn.elements.Gateway;
import org.openbpmn.bpmn.elements.Participant;
import org.openbpmn.bpmn.elements.SequenceFlow;
import org.openbpmn.bpmn.elements.TextAnnotation;
import org.openbpmn.bpmn.elements.core.BPMNElementNode;
import org.openbpmn.bpmn.exceptions.BPMNModelException;
import org.openbpmn.bpmn.util.BPMNModelFactory;
Expand Down Expand Up @@ -42,7 +44,9 @@ public void testReadModel() {

Set<Participant> participants = model.getParticipants();
assertNotNull(participants);
assertEquals(2, participants.size());
assertEquals(3, participants.size());

assertTrue(model.isCollaborationDiagram());

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

// We expect 10 Text Annotations. But these are not assigned correctly. We
// expect an auto assignment to the default process
BPMNProcess defaultProcess = model.openDefaultProces();
Set<TextAnnotation> textAnnotations = defaultProcess.getTextAnnotations();
assertEquals(12, textAnnotations.size());

} catch (BPMNModelException e) {
e.printStackTrace();
fail();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class TestCollaborationModel {

/**
* This test reads a collaboration model
* The model does not have a default process. This process is automatically
* added by the BPMNModel.
*/
@SuppressWarnings("unused")
@Test
Expand All @@ -45,7 +47,7 @@ public void testReadCollaborationModel() {

Set<Participant> participants = model.getParticipants();
assertNotNull(participants);
assertEquals(2, participants.size());
assertEquals(3, participants.size());

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

0 comments on commit b0f85f4

Please sign in to comment.