-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathActivity.java
133 lines (115 loc) · 4.45 KB
/
Activity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package org.openbpmn.bpmn.elements;
import java.util.ArrayList;
import java.util.List;
import org.openbpmn.bpmn.BPMNModel;
import org.openbpmn.bpmn.BPMNNS;
import org.openbpmn.bpmn.BPMNTypes;
import org.openbpmn.bpmn.elements.core.BPMNElementNode;
import org.openbpmn.bpmn.exceptions.BPMNModelException;
import org.openbpmn.bpmn.validation.BPMNValidationMarker;
import org.w3c.dom.Element;
/**
* An Activity is work that is performed within a Business Process. An Activity
* can be atomic or non-atomic (compound). The types of Activities that are a
* part of a Process are: Task, Sub-Process, and Call Activity, which allows the
* inclusion of re-usable Tasks and Processes in the diagram. However, a Process
* is not a specific graphical object. Instead, it is a set of graphical
* objects. The following sub clauses will focus on the graphical objects Sub-
* Process and Task. Activities represent points in a Process flow where work is
* performed. They are the executable elements of a BPMN Process. The Activity
* class is an abstract element, sub-classing from FlowElement
*
* @author rsoika
*
*/
public class Activity extends BPMNElementNode {
public final static double DEFAULT_WIDTH = 110.0;
public final static double DEFAULT_HEIGHT = 50.0;
protected Activity(BPMNModel model, Element node, String type, BPMNProcess bpmnProcess) throws BPMNModelException {
super(model, node, type, bpmnProcess);
}
@Override
public double getDefaultWidth() {
return DEFAULT_WIDTH;
}
@Override
public double getDefaultHeight() {
return DEFAULT_HEIGHT;
}
/**
* Remove any embedded bpmndi:BPMNLabel element within the bpmndi:BPMNShape
*
* Positioning of the label is part of the client. Any position update should
* ignore these settings in Open-BPMN.
*
*/
@Override
public void setPosition(double x, double y) {
super.setPosition(x, y);
// remove optional BPMNLabel
Element bpmnLabel = getModel().findChildNodeByName(this.bpmnShape, BPMNNS.BPMNDI, "BPMNLabel");
if (bpmnLabel != null) {
this.bpmnShape.removeChild(bpmnLabel);
}
}
/**
* This method adds a new Boundary Event this activity.
*
* The element has not position assigned yet!
*
* @return
* @throws BPMNModelException
*/
public Event addBoundaryEvent(String eventID, String name) throws BPMNModelException {
Event boundaryEvent;
boundaryEvent = bpmnProcess.addEvent(eventID, name, BPMNTypes.BOUNDARY_EVENT);
boundaryEvent.setAttribute("attachedToRef", this.getId());
return boundaryEvent;
}
/**
* This method returns a list of all boundaray Events attached to this activity.
*
* @return
*/
public List<Event> getAllBoundaryEvents() {
List<Event> result = new ArrayList<>();
for (Event e : bpmnProcess.getEvents()) {
if (BPMNTypes.BOUNDARY_EVENT.equals(e.getType())) {
// test ref....
if (this.getId().equals(e.getAttribute("attachedToRef"))) {
result.add(e);
}
}
}
return result;
}
/**
* Validate Activity element.
*
* We Expect at least one incoming message flow or sequence flow and at least
* one outgoing sequence flow
*
* Spec:
*
* A Receive Task is often used to start a Process. In a sense, the Process is
* bootstrapped by the receipt of the
* Message. In order for the Receive Task to instantiate the Process its
* instantiate attribute MUST be set to true
* and it MUST NOT have any incoming Sequence Flow.
*/
@Override
public List<BPMNValidationMarker> validate() {
resetValidation();
if (this.getIngoingSequenceFlows().size() == 0 && this.getIngoingMessageFlows().size() == 0) {
this.addValidationMarker(new BPMNValidationMarker("Task",
"A Task must have at least one ingoing Message Flow or Sequence Flow!", this.getId(),
BPMNValidationMarker.ErrorType.ERROR));
}
if (this.getOutgoingSequenceFlows().size() == 0) {
this.addValidationMarker(new BPMNValidationMarker("Task",
"A Task must have at least one outgoing Sequence Flow!", this.getId(),
BPMNValidationMarker.ErrorType.ERROR));
}
return this.getValidationMarkers();
}
}