[New] Set action to Planning state before planning
This commit is contained in:
parent
988fdd4d73
commit
d7bd8bba39
|
@ -17,6 +17,7 @@ package li.strolch.execution.command;
|
|||
|
||||
import static li.strolch.execution.policy.NoPlanning.DEFAULT_PLANNING;
|
||||
|
||||
import li.strolch.execution.policy.ConfirmationPolicy;
|
||||
import li.strolch.execution.policy.PlanningPolicy;
|
||||
import li.strolch.model.Resource;
|
||||
import li.strolch.model.State;
|
||||
|
@ -34,7 +35,7 @@ import li.strolch.utils.dbc.DBC;
|
|||
* objects of the action are already constructed and {@link Action#getResourceId()} is set.
|
||||
*
|
||||
* <br>
|
||||
*
|
||||
* <p>
|
||||
* It iterates the {@link IValueChange} operators and registers the resulting changes on the {@link StrolchTimedState}
|
||||
* objects assigned to the {@link Resource}.
|
||||
*
|
||||
|
@ -67,11 +68,20 @@ public class PlanActionCommand extends PlanningCommand {
|
|||
|
||||
@Override
|
||||
public Void visitAction(Action action) {
|
||||
if (action.getState() != State.CREATED && action.getState() != State.PLANNING)
|
||||
throw new IllegalStateException("Can not plan action in state " + action.getState());
|
||||
ConfirmationPolicy confirmationPolicy = getConfirmationPolicy(action);
|
||||
|
||||
action.setState(State.PLANNING);
|
||||
confirmationPolicy.toPlanning(action);
|
||||
|
||||
PolicyDef planningPolicyDef = action.findPolicy(PlanningPolicy.class, DEFAULT_PLANNING);
|
||||
PlanningPolicy planningPolicy = tx().getPolicy(PlanningPolicy.class, planningPolicyDef);
|
||||
planningPolicy.plan(action);
|
||||
|
||||
if (action.getState() == State.PLANNED)
|
||||
getConfirmationPolicy(action).toPlanned(action);
|
||||
confirmationPolicy.toPlanned(action);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,6 +55,7 @@ public class SimplePlanning extends PlanningPolicy {
|
|||
for (IValueChange<?> change : changes) {
|
||||
@SuppressWarnings("rawtypes")
|
||||
StrolchTimedState timedState = resource.getTimedState(change.getStateId());
|
||||
//noinspection unchecked
|
||||
timedState.applyChange(change, true);
|
||||
}
|
||||
|
||||
|
@ -83,6 +84,7 @@ public class SimplePlanning extends PlanningPolicy {
|
|||
for (IValueChange<?> change : changes) {
|
||||
@SuppressWarnings("rawtypes")
|
||||
StrolchTimedState timedState = resource.getTimedState(change.getStateId());
|
||||
//noinspection unchecked
|
||||
timedState.applyChange(change.getInverse(), true);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue