Skip to content

Commit

Permalink
[Trigger] Fix the the disappearance of conditions and impact
Browse files Browse the repository at this point in the history
  • Loading branch information
maxencelaurent committed Nov 28, 2023
1 parent 2ac2ac7 commit ca7bac0
Showing 1 changed file with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,21 @@ public abstract class AbstractStateMachineDescriptor< T extends AbstractState<U>
@WegasEntityProperty(ignoreNull = true, protectionLevel = ProtectionLevel.INHERITED,
optional = false, nullable = false, proposal = EmptyMap.class,
view = @View(label = "", value = Hidden.class))
private Set<T> states = new HashSet<>();
/*
* // DON'T DO THAT:
* private Set<T> states = new HashSet<>();
*
* `this#states` should be of type `Set<T>`, nonetheless, such a typing leads to very
* unexpected behaviour.
*
* For instance, regarding `TriggerDescriptor`, the `states` field would always be null.
* It seems JPA is unable to load data from database (despite data exists in DB) if the relation
* is defined with `T`.
*
* Workaround:
* Defining `states` as a set of `AbstractState` is working well:
*/
private Set<AbstractState<U>> states = new HashSet<>();

/**
*
Expand All @@ -80,7 +94,7 @@ public Set<T> getInternalStates() {

@JsonIgnore
public void setInternalStates(Set<T> states) {
this.states = (Set<T>) states;
this.states = (Set<AbstractState<U>>) states;
for (T state : states) {
state.setStateMachine(this);
}
Expand All @@ -90,7 +104,7 @@ public void setInternalStates(Set<T> states) {
public Map<Long, T> getStates() {
Map<Long, T> tMap = new TreeMap<>();

this.states.forEach(state -> {
((Set<T>) this.states).forEach(state -> {
tMap.put(state.getIndex(), state);
});

Expand All @@ -116,8 +130,8 @@ public void setStates(Map<Long, T> states) {
}

@JsonIgnore
public T getState(Long currentStateId) {
for (T state : this.states) {
public AbstractState<U> getState(Long currentStateId) {
for (AbstractState<U> state : this.states) {
if (state.getIndex().equals(currentStateId)) {
return state;
}
Expand Down

0 comments on commit ca7bac0

Please sign in to comment.