spring-projects / spring-statemachine

Spring Statemachine is a framework for application developers to use state machine concepts with Spring.
1.55k stars 609 forks source link

RepositoryStateMachineModelFactory not resolving model properly from state/transition repository #552

Open yangzii0920 opened 6 years ago

yangzii0920 commented 6 years ago

Versions:

spring-boot-starter-parent: 1.5.10.RELEASE
spring-statemachine-data-jpa: 1.2.9.RELEASE
spring-statemachine-core: 1.2.9.RELEASE

Configuration: Using @EnableStateMachineFactory and extending StateMachineConfigurerAdapter, states and transitions configuration is done by repositoryStateMachineModelFactory as in example JPA Config.

Error log:

org.springframework.statemachine.config.model.MalformedConfigurationException: Must have at least one transition
    at org.springframework.statemachine.config.model.verifier.BaseStructureVerifier.verify(BaseStructureVerifier.java:43) ~[spring-statemachine-core-1.2.9.RELEASE.jar:1.2.9.RELEASE]
    at org.springframework.statemachine.config.model.verifier.CompositeStateMachineModelVerifier.verify(CompositeStateMachineModelVerifier.java:43) ~[spring-statemachine-core-1.2.9.RELEASE.jar:1.2.9.RELEASE]
    at org.springframework.statemachine.config.AbstractStateMachineFactory.getStateMachine(AbstractStateMachineFactory.java:170) ~[spring-statemachine-core-1.2.9.RELEASE.jar:1.2.9.RELEASE]
    at org.springframework.statemachine.config.AbstractStateMachineFactory.getStateMachine(AbstractStateMachineFactory.java:145) ~[spring-statemachine-core-1.2.9.RELEASE.jar:1.2.9.RELEASE]

Debug: When I step into stateMachineFactory.getStateMachine(), the method call flow is like this: stateMachineFactory.getStateMachine() --> AbstractStateMachineFactory.getStateMachine(machineId) -->getStateMachine(uuid, machineId) --> resolveStateMachineModel(machineId) --> stateMachineFactory.build(machineId) --> stateRepository.findByMachineId(machienId == null ? "" : machineId)

Issue While in the data source json file, machine_id is not specified and in database machine_id is null, you cannot find any state or transition record giving the condition of machine_id = "" as converted in the findByMachineId() method.

Not sure if this is a bug per your design. If not, just figured out specifying database column 'machine_id' in data.json as machineId

jvalkeal commented 6 years ago

This depends on your machine structure and if you're defining multiple machines. Do you have a json sample you used to import a config?

yangzii0920 commented 6 years ago

Hi @jvalkeal , I'm using the same json in the JPA sample except for that I added different values to machineId. But the error can be resolved now by adding the depency

<dependency>
    <groupId>org.springframework.statemachine</groupId>
    <artifactId>spring-statemachine-autoconfigure</artifactId>
    <version>2.0.1.RELEASE</version>
</dependency>