Hook StateMachineModelFactory and StateMachineFactory together

- Change so that machine id used in StateMachineFactory
  can use same id in StateMachineModelFactory which now
  extended with method build(String machineId).
- Polish repo and jpa classes.
- Fixes #255
This commit is contained in:
Janne Valkealahti
2016-09-25 10:08:57 +01:00
parent 842442520c
commit 49bae38eb3
13 changed files with 191 additions and 24 deletions

View File

@@ -23,11 +23,24 @@ package org.springframework.statemachine.data;
*/
public interface RepositoryState {
/**
* Gets the machine id.
*
* @return the machine id
*/
String getMachineId();
/**
* Gets the state.
*
* @return the state
*/
String getState();
void setState(String state);
/**
* Checks if is initial.
*
* @return true, if is initial
*/
boolean isInitial();
void setInitial(boolean initial);
}

View File

@@ -53,16 +53,21 @@ public class RepositoryStateMachineModelFactory implements StateMachineModelFact
@Override
public StateMachineModel<String, String> build() {
return build(null);
}
@Override
public StateMachineModel<String, String> build(String machineId) {
ConfigurationData<String, String> configurationData = new ConfigurationData<>();
Collection<StateData<String, String>> stateData = new ArrayList<>();
for (RepositoryState s : stateRepository.findAll()) {
for (RepositoryState s : stateRepository.findByMachineId(machineId)) {
stateData.add(new StateData<String, String>(s.getState(), s.isInitial()));
}
StatesData<String, String> statesData = new StatesData<>(stateData);
Collection<TransitionData<String, String>> transitionData = new ArrayList<>();
for (RepositoryTransition t : transitionRepository.findAll()) {
for (RepositoryTransition t : transitionRepository.findByMachineId(machineId)) {
transitionData.add(new TransitionData<String, String>(t.getSource(), t.getTarget(), t.getEvent()));
}
TransitionsData<String, String> transitionsData = new TransitionsData<>(transitionData);

View File

@@ -23,15 +23,31 @@ package org.springframework.statemachine.data;
*/
public interface RepositoryTransition {
/**
* Gets the machine id.
*
* @return the machine id
*/
String getMachineId();
/**
* Gets the source.
*
* @return the source
*/
String getSource();
void setSource(String source);
/**
* Gets the target.
*
* @return the target
*/
String getTarget();
void setTarget(String target);
/**
* Gets the event.
*
* @return the event
*/
String getEvent();
void setEvent(String event);
}

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.statemachine.data;
import java.util.List;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.repository.Repository;
@@ -28,4 +30,12 @@ import org.springframework.data.repository.Repository;
*/
@NoRepositoryBean
public interface StateRepository<S extends RepositoryState> extends CrudRepository<S, Long> {
/**
* Find states by machine id.
*
* @param machineId the machine id
* @return the list of transitions
*/
List<S> findByMachineId(String machineId);
}

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.statemachine.data;
import java.util.List;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.repository.Repository;
@@ -28,4 +30,12 @@ import org.springframework.data.repository.Repository;
*/
@NoRepositoryBean
public interface TransitionRepository<T extends RepositoryTransition> extends CrudRepository<T, Long> {
/**
* Find transitions by machine id.
*
* @param machineId the machine id
* @return the list of transitions
*/
List<T> findByMachineId(String machineId);
}