transition enricher
This commit is contained in:
33
state_machines/complex_multi_module_sm/domain/.gitignore
vendored
Normal file
33
state_machines/complex_multi_module_sm/domain/.gitignore
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
HELP.md
|
||||
target/
|
||||
.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
24
state_machines/complex_multi_module_sm/domain/pom.xml
Normal file
24
state_machines/complex_multi_module_sm/domain/pom.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>click.kamil.complex</groupId>
|
||||
<artifactId>complex-multi-module-sm</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>domain</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.statemachine</groupId>
|
||||
<artifactId>spring-statemachine-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,4 @@
|
||||
package click.kamil.domain;
|
||||
|
||||
public interface IEvent {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package click.kamil.domain;
|
||||
|
||||
public interface IState {
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package click.kamil.domain;
|
||||
|
||||
public enum OrderEvent implements IEvent {
|
||||
PROCESS, COMPLETE, CANCEL
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package click.kamil.domain;
|
||||
|
||||
public enum OrderState implements IState {
|
||||
NEW, PROCESSING, COMPLETED, CANCELLED
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package click.kamil.domain;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.statemachine.config.EnableStateMachine;
|
||||
import org.springframework.statemachine.config.EnumStateMachineConfigurerAdapter;
|
||||
import org.springframework.statemachine.config.builders.StateMachineStateConfigurer;
|
||||
import org.springframework.statemachine.config.builders.StateMachineTransitionConfigurer;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
@Configuration
|
||||
@EnableStateMachine
|
||||
public class StateMachineConfig extends EnumStateMachineConfigurerAdapter<OrderState, OrderEvent> {
|
||||
|
||||
@Override
|
||||
public void configure(StateMachineStateConfigurer<OrderState, OrderEvent> states) throws Exception {
|
||||
states
|
||||
.withStates()
|
||||
.initial(OrderState.NEW)
|
||||
.states(EnumSet.allOf(OrderState.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(StateMachineTransitionConfigurer<OrderState, OrderEvent> transitions) throws Exception {
|
||||
transitions
|
||||
.withExternal()
|
||||
.source(OrderState.NEW).target(OrderState.PROCESSING).event(OrderEvent.PROCESS)
|
||||
.and()
|
||||
.withExternal()
|
||||
.source(OrderState.PROCESSING).target(OrderState.COMPLETED).event(OrderEvent.COMPLETE)
|
||||
.and()
|
||||
.withExternal()
|
||||
.source(OrderState.NEW).target(OrderState.CANCELLED).event(OrderEvent.CANCEL)
|
||||
.and()
|
||||
.withExternal()
|
||||
.source(OrderState.PROCESSING).target(OrderState.CANCELLED).event(OrderEvent.CANCEL);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user