extended analysis
This commit is contained in:
33
state_machines/inheritance_sample/build.gradle
Normal file
33
state_machines/inheritance_sample/build.gradle
Normal file
@@ -0,0 +1,33 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'org.springframework.boot' version '3.5.3'
|
||||
id 'io.spring.dependency-management' version '1.1.7'
|
||||
}
|
||||
|
||||
group = 'click.kamil'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion = JavaLanguageVersion.of(21)
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||
implementation 'org.springframework.statemachine:spring-statemachine-starter:3.2.0'
|
||||
compileOnly 'org.projectlombok:lombok'
|
||||
annotationProcessor 'org.projectlombok:lombok'
|
||||
}
|
||||
|
||||
bootJar {
|
||||
enabled = false
|
||||
}
|
||||
|
||||
jar {
|
||||
enabled = true
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package click.kamil.examples.statemachine.inheritance.api;
|
||||
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
@RequestMapping("/api/v2/orders")
|
||||
public interface OrderApi {
|
||||
|
||||
@PostMapping("/submit")
|
||||
void submitOrder();
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package click.kamil.examples.statemachine.inheritance.api;
|
||||
|
||||
import click.kamil.examples.statemachine.inheritance.service.ProcessingService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class OrderControllerImpl implements OrderApi {
|
||||
|
||||
private final ProcessingService processingService;
|
||||
|
||||
public OrderControllerImpl(ProcessingService processingService) {
|
||||
this.processingService = processingService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void submitOrder() {
|
||||
processingService.doProcess();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package click.kamil.examples.statemachine.inheritance.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.statemachine.config.EnableStateMachine;
|
||||
import org.springframework.statemachine.config.StateMachineConfigurerAdapter;
|
||||
import org.springframework.statemachine.config.builders.StateMachineStateConfigurer;
|
||||
import org.springframework.statemachine.config.builders.StateMachineTransitionConfigurer;
|
||||
|
||||
@Configuration
|
||||
@EnableStateMachine
|
||||
public class InheritanceStateMachineConfig extends StateMachineConfigurerAdapter<String, String> {
|
||||
|
||||
@Override
|
||||
public void configure(StateMachineStateConfigurer<String, String> states) throws Exception {
|
||||
states
|
||||
.withStates()
|
||||
.initial("START")
|
||||
.state("WORKING");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(StateMachineTransitionConfigurer<String, String> transitions) throws Exception {
|
||||
transitions
|
||||
.withExternal()
|
||||
.source("START").target("WORKING")
|
||||
.event("INHERITED_SUBMIT");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package click.kamil.examples.statemachine.inheritance.service;
|
||||
|
||||
public interface ProcessingService {
|
||||
void doProcess();
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package click.kamil.examples.statemachine.inheritance.service;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.statemachine.StateMachine;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ProcessingServiceImpl implements ProcessingService {
|
||||
|
||||
private final StateMachine<String, String> stateMachine;
|
||||
|
||||
@Override
|
||||
public void doProcess() {
|
||||
stateMachine.sendEvent("INHERITED_SUBMIT");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user