Skip to content

Commit 83e3dbe

Browse files
committed
impl, added junit test
Issue #79
1 parent 6413263 commit 83e3dbe

4 files changed

Lines changed: 92 additions & 1 deletion

File tree

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,27 @@ public BPMNProcess openDefaultProcess() {
527527
}
528528
}
529529

530+
/**
531+
* Deletes a BPMNParticipant element from this model.
532+
* <p>
533+
*
534+
* @param id
535+
*/
536+
public void deleteBPMNParticipant(BPMNParticipant participant) {
537+
if (participant != null) {
538+
BPMNProcess process=participant.openProcess();
539+
this.definitions.removeChild(process.getElementNode());
540+
if (participant.hasPool()) {
541+
this.bpmnPlane.removeChild(participant.getBpmnShape());
542+
}
543+
this.collaborationElement.removeChild(participant.getElementNode());
544+
// remove the participant with its elements
545+
this.getProcesses().remove(process);
546+
this.getParticipants().remove(participant);
547+
}
548+
549+
}
550+
530551
public Element createElement(BPMNNS ns, String type) {
531552
Element element = this.getDoc().createElementNS(getNameSpaceUri(ns), ns.prefix + ":" + type);
532553
return element;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public void createPool() throws BPMNModelException {
4949
}
5050
}
5151

52+
public boolean hasPool() {
53+
return (bpmnShape != null);
54+
}
5255
/**
5356
* Returns the initialized BPMNProcess of this participant or returns null if no
5457
* proces exists

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,26 @@ public void init() throws BPMNModelException {
114114
}
115115
}
116116

117+
118+
/**
119+
* Returns all BPMNFlowElements contained in this process
120+
*
121+
* @return
122+
*/
123+
public Set<BPMNFlowElement> getBPMNFlowElements() {
124+
HashSet<BPMNFlowElement> result = new HashSet<BPMNFlowElement>();
125+
126+
result.addAll(this.getActivities());
127+
result.addAll(this.getEvents());
128+
result.addAll(this.getGateways());
129+
return result;
130+
}
131+
132+
/**
133+
* Returns all BPMNActivity elements contained in this process
134+
*
135+
* @return
136+
*/
117137
public Set<BPMNActivity> getActivities() {
118138
if (activities == null) {
119139
activities = new HashSet<BPMNActivity>();

open-bpmn.metamodel/src/test/java/org/openbpmn/metamodel/examples/TestDeleteModel.java

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.openbpmn.metamodel.examples;
22

3+
import static org.junit.jupiter.api.Assertions.assertEquals;
34
import static org.junit.jupiter.api.Assertions.assertNotNull;
45
import static org.junit.jupiter.api.Assertions.fail;
56

@@ -10,6 +11,7 @@
1011
import org.openbpmn.bpmn.BPMNModel;
1112
import org.openbpmn.bpmn.BPMNTypes;
1213
import org.openbpmn.bpmn.elements.BPMNActivity;
14+
import org.openbpmn.bpmn.elements.BPMNParticipant;
1315
import org.openbpmn.bpmn.elements.BPMNProcess;
1416
import org.openbpmn.bpmn.exceptions.BPMNModelException;
1517
import org.openbpmn.bpmn.util.BPMNModelFactory;
@@ -90,7 +92,7 @@ public void testBuildAndDelete() {
9092
processContext.addEvent("end_1", "End", BPMNTypes.END_EVENT);
9193
BPMNActivity task = processContext.addTask("task_1", "Task", BPMNTypes.TASK);
9294
task.getBounds().updateLocation(10.0, 10.0);
93-
task.getBounds().updateDimension( 140.0, 60.0);
95+
task.getBounds().updateDimension(140.0, 60.0);
9496

9597
processContext.addSequenceFlow("SequenceFlow_1", "start_1", "task_1");
9698
processContext.addSequenceFlow("SequenceFlow_2", "task_1", "end_1");
@@ -102,4 +104,49 @@ public void testBuildAndDelete() {
102104

103105
}
104106

107+
/**
108+
* This test build new model one participant and a task. The test delete
109+
* participant - we expect the task is also deleted, but we still have a default
110+
* process and a collaboration diagram.
111+
*/
112+
@Test
113+
public void testDeleteParticipant() {
114+
115+
String exporter = "demo";
116+
String version = "1.0.0";
117+
String targetNameSpace = "http://org.openbpmn";
118+
try {
119+
BPMNModel model = BPMNModelFactory.createInstance(exporter, version, targetNameSpace);
120+
BPMNProcess defaultProcess = model.openDefaultProcess();
121+
assertNotNull(defaultProcess);
122+
123+
// create Participant
124+
BPMNParticipant sales = model.addParticipant("Sales");
125+
126+
// add Task
127+
BPMNProcess privateProcess = sales.openProcess();
128+
// add a start and end event
129+
privateProcess.addEvent("start_1", "Start", BPMNTypes.START_EVENT);
130+
privateProcess.addEvent("end_1", "End", BPMNTypes.END_EVENT);
131+
privateProcess.addTask("task_1", "Task", BPMNTypes.TASK);
132+
privateProcess.addSequenceFlow("SequenceFlow_1", "start_1", "task_1");
133+
privateProcess.addSequenceFlow("SequenceFlow_2", "task_1", "end_1");
134+
135+
// we expect 3 Flow elements and 2 Processes
136+
assertEquals(3, privateProcess.getBPMNFlowElements().size());
137+
assertEquals(2, model.getProcesses().size());
138+
assertEquals(2, model.getParticipants().size());
139+
140+
// now delete the Participant
141+
model.deleteBPMNParticipant(sales);
142+
assertEquals(1, model.getParticipants().size());
143+
assertEquals(1, model.getProcesses().size());
144+
145+
} catch (BPMNModelException e) {
146+
e.printStackTrace();
147+
fail();
148+
}
149+
150+
}
151+
105152
}

0 commit comments

Comments
 (0)