Add repository config transition type
- Add transition type to RepositoryTransition - Relates to #262
This commit is contained in:
@@ -36,7 +36,8 @@
|
||||
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryTransition",
|
||||
"source": "S1",
|
||||
"target": "S2",
|
||||
"event": "E1"
|
||||
"event": "E1",
|
||||
"kind": "EXTERNAL"
|
||||
},
|
||||
{
|
||||
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryTransition",
|
||||
|
||||
@@ -26,6 +26,7 @@ import javax.persistence.Id;
|
||||
import javax.persistence.OneToMany;
|
||||
|
||||
import org.springframework.statemachine.data.RepositoryTransition;
|
||||
import org.springframework.statemachine.transition.TransitionKind;
|
||||
|
||||
/**
|
||||
* JPA entity for transitions.
|
||||
@@ -44,10 +45,12 @@ public class JpaRepositoryTransition implements RepositoryTransition {
|
||||
private String source;
|
||||
private String target;
|
||||
private String event;
|
||||
private TransitionKind kind;
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||
private Set<JpaRepositoryAction> actions;
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new jpa repository transition.
|
||||
*/
|
||||
@@ -139,4 +142,13 @@ public class JpaRepositoryTransition implements RepositoryTransition {
|
||||
public void setActions(Set<JpaRepositoryAction> actions) {
|
||||
this.actions = actions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransitionKind getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
public void setKind(TransitionKind kind) {
|
||||
this.kind = kind;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ import org.springframework.statemachine.data.StateRepository;
|
||||
import org.springframework.statemachine.data.TransitionRepository;
|
||||
import org.springframework.statemachine.test.StateMachineTestPlan;
|
||||
import org.springframework.statemachine.test.StateMachineTestPlanBuilder;
|
||||
import org.springframework.statemachine.transition.TransitionKind;
|
||||
|
||||
public class JpaRepositoryTests extends AbstractJpaRepositoryTests {
|
||||
|
||||
@@ -66,11 +67,13 @@ public class JpaRepositoryTests extends AbstractJpaRepositoryTests {
|
||||
|
||||
JpaTransitionRepository transitionsRepository = context.getBean(JpaTransitionRepository.class);
|
||||
JpaRepositoryTransition transition = new JpaRepositoryTransition("S1", "S2", "E1");
|
||||
transition.setKind(TransitionKind.EXTERNAL);
|
||||
transitionsRepository.save(transition);
|
||||
JpaRepositoryTransition transition2 = transitionsRepository.findAll().iterator().next();
|
||||
assertThat(transition2.getSource(), is("S1"));
|
||||
assertThat(transition2.getTarget(), is("S2"));
|
||||
assertThat(transition2.getEvent(), is("E1"));
|
||||
assertThat(transition2.getKind(), is(TransitionKind.EXTERNAL));
|
||||
|
||||
context.close();
|
||||
}
|
||||
|
||||
@@ -18,12 +18,20 @@
|
||||
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryTransition",
|
||||
"source": "S1",
|
||||
"target": "S2",
|
||||
"event": "E1"
|
||||
"event": "E1",
|
||||
"kind": "EXTERNAL"
|
||||
},
|
||||
{
|
||||
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryTransition",
|
||||
"source": "S2",
|
||||
"target": "S3",
|
||||
"event": "E2"
|
||||
},
|
||||
{
|
||||
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryTransition",
|
||||
"source": "S2",
|
||||
"target": "S3",
|
||||
"event": "E3",
|
||||
"kind": "LOCAL"
|
||||
}
|
||||
]
|
||||
|
||||
@@ -160,7 +160,8 @@ public class RepositoryStateMachineModelFactory extends AbstractStateMachineMode
|
||||
}
|
||||
}
|
||||
|
||||
transitionData.add(new TransitionData<>(t.getSource(), t.getTarget(), t.getEvent(), actions, null, TransitionKind.EXTERNAL));
|
||||
TransitionKind kind = t.getKind();
|
||||
transitionData.add(new TransitionData<>(t.getSource(), t.getTarget(), t.getEvent(), actions, null, kind != null ? kind : TransitionKind.EXTERNAL));
|
||||
}
|
||||
TransitionsData<String, String> transitionsData = new TransitionsData<>(transitionData);
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ package org.springframework.statemachine.data;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.statemachine.transition.TransitionKind;
|
||||
|
||||
/**
|
||||
* Generic interface representing transition entity.
|
||||
*
|
||||
@@ -59,4 +61,11 @@ public interface RepositoryTransition {
|
||||
* @return the actions
|
||||
*/
|
||||
Set<? extends RepositoryAction> getActions();
|
||||
|
||||
/**
|
||||
* Gets the transition kind.
|
||||
*
|
||||
* @return the transition kind
|
||||
*/
|
||||
TransitionKind getKind();
|
||||
}
|
||||
|
||||
@@ -36,7 +36,8 @@
|
||||
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryTransition",
|
||||
"source": "S1",
|
||||
"target": "S2",
|
||||
"event": "E1"
|
||||
"event": "E1",
|
||||
"kind": "EXTERNAL"
|
||||
},
|
||||
{
|
||||
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryTransition",
|
||||
|
||||
Reference in New Issue
Block a user