Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added customization of the reference to the message and the signal #367

Merged
merged 1 commit into from
Dec 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

import java.util.LinkedHashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;

import org.openbpmn.bpmn.BPMNModel;
@@ -46,39 +47,47 @@ public double getDefaultHeight() {
* @throws BPMNMissingElementException
*/
public void addEventDefinition(String type) throws BPMNModelException {

if (this.getElementNode() == null) {
throw new BPMNMissingElementException("Missing ElementNode!");
}
Element eventDefinition = model.createElement(BPMNNS.BPMN2, type);
eventDefinition.setAttribute("id", BPMNModel.generateShortID(type));

// in case of a Signal Definition we need to add a reference to the first
// existing Signal.
if (BPMNTypes.EVENT_DEFINITION_SIGNAL.equals(type)) {
// do we have at least one signal ?
if (model.getSignals().size() == 0) {
if (model.getSignals().isEmpty()) {
// create a dummy signal
model.addSignal("signal_1", "Signal 1");
}
// take the first one
Signal signal = model.getSignals().iterator().next();
eventDefinition.setAttribute("signalRef", signal.getId());

addEventDefinition(signal.getId(), type);
return;
}

// in case of a Message Definition we need to add a reference to the first
// existing Message.
if (BPMNTypes.EVENT_DEFINITION_MESSAGE.equals(type)) {
// do we have at least one message ?
if (model.getMessages().size() == 0) {
if (model.getMessages().isEmpty()) {
// create a dummy message
model.addMessage("message_1", "Message 1");
}
// take the first one
Message message = model.getMessages().iterator().next();
eventDefinition.setAttribute("messageRef", message.getId());
addEventDefinition(message.getId(), type);
}
}

public void addEventDefinition(String id, String type) throws BPMNModelException {
if (this.getElementNode() == null) {
throw new BPMNMissingElementException("Missing ElementNode!");
}
Element eventDefinition = model.createElement(BPMNNS.BPMN2, type);
eventDefinition.setAttribute("id", BPMNModel.generateShortID(type));

if (BPMNTypes.EVENT_DEFINITION_SIGNAL.equals(type)) {
eventDefinition.setAttribute("signalRef", id);
}

if (BPMNTypes.EVENT_DEFINITION_MESSAGE.equals(type)) {
eventDefinition.setAttribute("messageRef", id);
}
this.getElementNode().appendChild(eventDefinition);

@@ -210,6 +219,8 @@ public List<BPMNValidationMarker> validate() {
"A Catch Event must have at least one outgoing Sequence Flow!", this.getId(),
BPMNValidationMarker.ErrorType.ERROR));
}

Message message = model.getMessages().iterator().next();
}

// Throw Event?
@@ -222,6 +233,38 @@ public List<BPMNValidationMarker> validate() {

}

getEventDefinitionsByType(BPMNTypes.EVENT_DEFINITION_MESSAGE)
.forEach(ed -> {
boolean hasMessage =
model.getMessages().stream()
.anyMatch(m ->
Objects.equals(
ed.getAttribute("messageRef"),
m.getId()));
if (!hasMessage) {
this.addValidationMarker(
new BPMNValidationMarker("Event",
"A Event must have a corresponding Message!", this.getId(),
BPMNValidationMarker.ErrorType.ERROR));
}
});

getEventDefinitionsByType(BPMNTypes.EVENT_DEFINITION_SIGNAL)
.forEach(ed -> {
boolean hasMessage =
model.getSignals().stream()
.anyMatch(m ->
Objects.equals(
ed.getAttribute("signalRef"),
m.getId()));
if (!hasMessage) {
this.addValidationMarker(
new BPMNValidationMarker("Event",
"A Event must have a corresponding Signal!", this.getId(),
BPMNValidationMarker.ErrorType.ERROR));
}
});

return this.getValidationMarkers();
}