Add support for submachine refs

- Relates to #262
This commit is contained in:
Janne Valkealahti
2016-10-23 06:50:21 +01:00
parent 81e3c8697f
commit 83e59c2a60
5 changed files with 120 additions and 3 deletions

View File

@@ -96,4 +96,12 @@ public abstract class RepositoryState extends BaseRepositoryEntity {
* @return the deferred events
*/
public abstract Set<String> getDeferredEvents();
/**
* Gets the submachine id indicating that this is a submachine state
* and its structure is available from particular machine itself.
*
* @return the submachine id
*/
public abstract String getSubmachineId();
}

View File

@@ -85,6 +85,13 @@ public class RepositoryStateMachineModelFactory extends AbstractStateMachineMode
Collection<StateData<String, String>> stateDatas = new ArrayList<>();
for (RepositoryState s : stateRepository.findByMachineId(machineId)) {
// do recursive build to get states for a submachine
StateMachineModel<String, String> subStateMachineModel = null;
String submachineId = s.getSubmachineId();
if (submachineId != null) {
subStateMachineModel = build(submachineId);
}
Collection<Action<String, String>> stateActions = new ArrayList<Action<String, String>>();
Set<? extends RepositoryAction> repositoryStateActions = s.getStateActions();
if (repositoryStateActions != null) {
@@ -156,6 +163,18 @@ public class RepositoryStateMachineModelFactory extends AbstractStateMachineMode
}
}
stateData.setDeferred(s.getDeferredEvents());
if (subStateMachineModel != null) {
// copy are set parent as state we're currently on
Collection<StateData<String, String>> submachineStateData = new ArrayList<>();
Collection<StateData<String, String>> submachineStateDataOrig = subStateMachineModel.getStatesData().getStateData();
for (StateData<String, String> sd : submachineStateDataOrig) {
submachineStateData.add(new StateData<String, String>(s.getState(), sd.getRegion(), sd.getState(),
sd.getDeferred(), sd.getEntryActions(), sd.getExitActions(), sd.isInitial()));
}
stateData.setSubmachineStateData(submachineStateData);
}
stateDatas.add(stateData);
}
StatesData<String, String> statesData = new StatesData<>(stateDatas);