Skip to content

Commit

Permalink
Updated Event Meta model, updated property Panel
Browse files Browse the repository at this point in the history
Issue #173
  • Loading branch information
rsoika committed Feb 13, 2023
1 parent 21eb405 commit a65423c
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.openbpmn.extension;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand All @@ -39,6 +40,7 @@
import org.openbpmn.bpmn.exceptions.BPMNInvalidReferenceException;
import org.openbpmn.bpmn.exceptions.BPMNInvalidTypeException;
import org.openbpmn.bpmn.exceptions.BPMNMissingElementException;
import org.openbpmn.bpmn.exceptions.BPMNModelException;
import org.openbpmn.glsp.bpmn.LabelGNode;
import org.openbpmn.glsp.jsonforms.DataBuilder;
import org.openbpmn.glsp.jsonforms.SchemaBuilder;
Expand Down Expand Up @@ -137,8 +139,9 @@ public void buildPropertiesForm(final BPMNElement bpmnElement, final DataBuilder
}

/**
* Builds the different property tabs for the core attributes and the event
* definitions
* Updates the core attributes of the BPMN element and also the
* eventDefinitions based on the different property tabs for each definition
* type.
*/
@Override
public void updatePropertiesData(final JsonObject json, final BPMNElement bpmnElement,
Expand Down Expand Up @@ -169,7 +172,7 @@ public void updatePropertiesData(final JsonObject json, final BPMNElement bpmnEl
continue;
}

// Update eventDefinitions...
// Update eventDefinitions for each definition type...
Set<Element> eventDefinitions = bpmnEvent.getEventDefinitions();
if ("signals".equals(feature)) {
JsonArray signalDataList = json.getJsonArray("signals");
Expand All @@ -179,12 +182,8 @@ public void updatePropertiesData(final JsonObject json, final BPMNElement bpmnEl
updateSignalEventDefinitions(signalEventDefinitions, signalDataList);
}
if ("conditions".equals(feature)) {
JsonArray signalDataList = json.getJsonArray("conditions");
// find all Signal definitions of this event
List<Element> conditionalEventDefinitions = eventDefinitions.stream()
.filter(c -> "conditionalEventDefinition".equals(c.getLocalName()))
.collect(Collectors.toList());
updateConditionalEventDefinitions(conditionalEventDefinitions, signalDataList);
JsonArray conditionsDataList = json.getJsonArray("conditions");
updateConditionalEventDefinitions(bpmnEvent, conditionsDataList);
}
if ("links".equals(feature)) {
JsonArray signalDataList = json.getJsonArray("links");
Expand All @@ -197,8 +196,11 @@ public void updatePropertiesData(final JsonObject json, final BPMNElement bpmnEl

}

/*
* See addSignalEventDefinitions how we map between the signal name and its id.
*/
private void updateSignalEventDefinitions(final List<Element> eventDefinitions, final JsonArray dataList) {
// If the size of the singnalDataList is not equals the size of the known
// If the size of the signalDataList is not equals the size of the known
// eventSignalDefinitions we print a warning
if (eventDefinitions.size() != dataList.size()) {
logger.warn("dataList does not match the EventDefinition list!");
Expand All @@ -223,21 +225,50 @@ private void updateSignalEventDefinitions(final List<Element> eventDefinitions,
}
}

private void updateConditionalEventDefinitions(final List<Element> eventDefinitions, final JsonArray dataList) {
// If the size of the conditionalDataList is not equals the size of the known
// eventConditionalDefinitions we print a warning
if (eventDefinitions.size() != dataList.size()) {
logger.warn("dataList does not match the EventDefinition list!");
/**
* This method updates the conditionalEventDefinitions. The method expects a
* dataList containing all
* conditions with its values (including the id).
* The method simpl overwrites all conditionalEventDefinitions.
*
* @param bpmnEvent
* @param dataList
*/
private void updateConditionalEventDefinitions(final Event bpmnEvent, final JsonArray dataList) {
// find all conditionalEventDefinitions for this event
Set<Element> conditionalEventDefinitions = bpmnEvent.getEventDefinitionsByType("conditionalEventDefinition");
// If the size of the conditionalDataList is not equals the size of the
// DefinitionList we add or
// remove conditions...
while (conditionalEventDefinitions.size() != dataList.size()) {
try {
if (conditionalEventDefinitions.size() < dataList.size()) {
// add a new empty condition placeholder...
bpmnEvent.addEventDefinition("conditionalEventDefinition");
}
if (conditionalEventDefinitions.size() > dataList.size()) {
// delete last condition from the list
bpmnEvent.deleteEventDefinition(
conditionalEventDefinitions.iterator().next().getAttributeNode("id").toString());
}
} catch (BPMNModelException e) {
logger.error("Failed to update BPMN Event Definition list: " + e.getMessage());
e.printStackTrace();
}
// Update event definition list
conditionalEventDefinitions = bpmnEvent.getEventDefinitionsByType("conditionalEventDefinition");
}
// just update the values one by one by referring to the signalRef id by
// comparing the name
for (int i = 0; i < eventDefinitions.size(); i++) {
Element eventDefinitionElement = eventDefinitions.get(i);
// now we can update the values one by one
Iterator<Element> iter = conditionalEventDefinitions.iterator();
int i = 0;
while (iter.hasNext()) {
Element eventDefinitionElement = iter.next();
JsonObject jsonData = dataList.getJsonObject(i); // .get(i);
if (jsonData != null) {
eventDefinitionElement.setAttribute("language", jsonData.getString("language", ""));
eventDefinitionElement.setAttribute("expression", jsonData.getString("expression", ""));
}
i++;
// update completed
}
}
Expand Down Expand Up @@ -323,6 +354,14 @@ private void addConditionalEventDefinitions(final List<Element> eventDefinitions

/**
* Adds the SignalEvent definitions
* <p>
* Note: Internally we need a mapping between the Signal name (Label) and the
* Signal id (value). As
* discussed here
* (https://jsonforms.discourse.group/t/how-to-separate-value-and-label-in-a-combobox/1200)
* we do not have this feature yet. Currently the efforts seems to be to high to
* implement a new
* renderer for JsonForms.
*
* @param eventDefinitions
* @param dataBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,28 @@ public void addEventDefinition(String type) throws BPMNModelException {
// existing Signal.
if (BPMNTypes.EVENT_DEFINITION_SIGNAL.equals(type)) {
// do we have at least one signal ?
if ( model.getSignals().size()==0) {
if (model.getSignals().size() == 0) {
// create a dummy signal
model.addSignal("signal_1", "Signal 1");
}
// take the first one
Signal signal= model.getSignals().iterator().next();
eventDefintion.setAttribute("signalRef", signal.getId());
// take the first one
Signal signal = model.getSignals().iterator().next();
eventDefintion.setAttribute("signalRef", signal.getId());

}

// 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().size() == 0) {
// create a dummy message
model.addMessage("message_1", "Message 1");
}
// take the first one
Message message= model.getMessages().iterator().next();
eventDefintion.setAttribute("messageRef", message.getId());
// take the first one
Message message = model.getMessages().iterator().next();
eventDefintion.setAttribute("messageRef", message.getId());

}
this.getElementNode().appendChild(eventDefintion);

Expand All @@ -95,7 +95,7 @@ public void deleteEventDefinition(String id) throws BPMNModelException {
}

/**
* Returns a list of EventDefintions associated with this element.
* Returns a list of all EventDefinitions associated with this element.
* <p>
* The return type is a list of eventDefinition Nodes
* <p>
Expand All @@ -106,6 +106,28 @@ public void deleteEventDefinition(String id) throws BPMNModelException {
* @throws BPMNModelException
*/
public Set<Element> getEventDefinitions() {
return getEventDefinitionsByType(null);

}

/**
* Returns a list of all EventDefinitions of a given type, associated with this
* element.
* <p>
* The return type is a list of eventDefinition Nodes of this type.
* <p>
* If the element has no EventDefinitions of this type, the method returns an
* empty list.
* <p>
* E.g:
*
* bpmn2:conditionalEventDefinition
*
* @return - list of EventDefinitions - can be empty if no EventDefinitions
* exist or no EventDefintion is matching the type
* @throws BPMNModelException
*/
public Set<Element> getEventDefinitionsByType(String definitionType) {

Set<Element> result = new LinkedHashSet<Element>();

Expand All @@ -122,8 +144,17 @@ public Set<Element> getEventDefinitions() {
if (!child.getNodeName().isEmpty() && child.hasAttributes()) {
String name = child.getNodeName();
// check if this is a EventDefinition
if (name.endsWith("EventDefinition")) {
result.add((Element) child);
// if we have a definitionType than we check the full name
if (definitionType != null && !definitionType.isEmpty()) {
if (name.endsWith(definitionType)) {
result.add((Element) child);
}
} else {
// We do not have a definition type, so we return all EventDefinitions
if (name.endsWith("EventDefinition")) {
result.add((Element) child);
}

}
}
}
Expand Down

0 comments on commit a65423c

Please sign in to comment.