[New] Update the order state of activity by Type and Id reference
This commit is contained in:
parent
76fb797102
commit
24b7f1d2bc
|
@ -90,17 +90,45 @@ public enum State {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if the state is {@link #CLOSED}
|
* @return true if the state is {@link #CREATED}
|
||||||
*/
|
*/
|
||||||
public boolean isClosed() {
|
public boolean isCreated() {
|
||||||
return this == CLOSED;
|
return this == State.CREATED;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if the state is {@link #PLANNING}
|
||||||
|
*/
|
||||||
|
public boolean isInPlanning() {
|
||||||
|
return this == State.PLANNING;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if the state is {@link #PLANNED}
|
||||||
|
*/
|
||||||
|
public boolean isInPlanned() {
|
||||||
|
return this == State.PLANNED;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if the state is {@link #EXECUTION}
|
||||||
|
*/
|
||||||
|
public boolean isInExecution() {
|
||||||
|
return this == State.EXECUTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if the state is {@link #EXECUTED}
|
||||||
|
*/
|
||||||
|
public boolean isExecuted() {
|
||||||
|
return this == EXECUTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if the state is {@link #CLOSED}
|
* @return true if the state is {@link #CLOSED}
|
||||||
*/
|
*/
|
||||||
public boolean isExecuted() {
|
public boolean isClosed() {
|
||||||
return this == EXECUTED;
|
return this == CLOSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package li.strolch.execution.command;
|
package li.strolch.execution.command;
|
||||||
|
|
||||||
import li.strolch.agent.api.ComponentContainer;
|
import li.strolch.agent.api.ComponentContainer;
|
||||||
|
import li.strolch.model.State;
|
||||||
import li.strolch.model.activity.Activity;
|
import li.strolch.model.activity.Activity;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
import li.strolch.utils.dbc.DBC;
|
import li.strolch.utils.dbc.DBC;
|
||||||
|
@ -24,8 +25,13 @@ public class ExecuteActivityCommand extends ExecutionCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doCommand() {
|
public void doCommand() {
|
||||||
tx().lock(this.activity.getRootElement());
|
Activity rootElement = this.activity.getRootElement();
|
||||||
|
tx().lock(rootElement);
|
||||||
|
|
||||||
|
State currentState = rootElement.getState();
|
||||||
this.activity.accept(this);
|
this.activity.accept(this);
|
||||||
|
|
||||||
|
updateOrderState(rootElement, currentState, rootElement.getState());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -7,9 +7,11 @@ import java.util.Map.Entry;
|
||||||
|
|
||||||
import li.strolch.agent.api.ComponentContainer;
|
import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.command.UpdateActivityCommand;
|
import li.strolch.command.UpdateActivityCommand;
|
||||||
|
import li.strolch.command.UpdateOrderCommand;
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.execution.policy.ConfirmationPolicy;
|
import li.strolch.execution.policy.ConfirmationPolicy;
|
||||||
import li.strolch.execution.policy.ExecutionPolicy;
|
import li.strolch.execution.policy.ExecutionPolicy;
|
||||||
|
import li.strolch.model.Order;
|
||||||
import li.strolch.model.Resource;
|
import li.strolch.model.Resource;
|
||||||
import li.strolch.model.State;
|
import li.strolch.model.State;
|
||||||
import li.strolch.model.activity.Action;
|
import li.strolch.model.activity.Action;
|
||||||
|
@ -41,6 +43,24 @@ public abstract class ExecutionCommand extends Command implements TimeOrderingVi
|
||||||
return resource;
|
return resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void updateOrderState(Activity rootElement, State currentState, State newState) {
|
||||||
|
if (currentState == newState)
|
||||||
|
return;
|
||||||
|
|
||||||
|
String type = rootElement.getType();
|
||||||
|
String id = rootElement.getId();
|
||||||
|
|
||||||
|
Order order = tx().getOrderBy(type, id);
|
||||||
|
if (order == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
order.setState(rootElement.getState());
|
||||||
|
|
||||||
|
UpdateOrderCommand cmd = new UpdateOrderCommand(getContainer(), tx());
|
||||||
|
cmd.setOrder(order);
|
||||||
|
cmd.doCommand();
|
||||||
|
}
|
||||||
|
|
||||||
protected ExecutionPolicy getExecutionPolicy(Action action) {
|
protected ExecutionPolicy getExecutionPolicy(Action action) {
|
||||||
Resource resource = getResource(tx(), action);
|
Resource resource = getResource(tx(), action);
|
||||||
PolicyDef executionPolicyDef = resource.getPolicyDefs().getPolicyDef(ExecutionPolicy.class.getSimpleName());
|
PolicyDef executionPolicyDef = resource.getPolicyDefs().getPolicyDef(ExecutionPolicy.class.getSimpleName());
|
||||||
|
|
|
@ -6,6 +6,7 @@ import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.State;
|
import li.strolch.model.State;
|
||||||
import li.strolch.model.activity.Action;
|
import li.strolch.model.activity.Action;
|
||||||
|
import li.strolch.model.activity.Activity;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
import li.strolch.utils.dbc.DBC;
|
import li.strolch.utils.dbc.DBC;
|
||||||
|
|
||||||
|
@ -34,10 +35,15 @@ public class SetActionToErrorCommand extends ExecutionCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doCommand() {
|
public void doCommand() {
|
||||||
tx().lock(this.action.getRootElement());
|
Activity rootElement = this.action.getRootElement();
|
||||||
|
tx().lock(rootElement);
|
||||||
|
|
||||||
|
State currentState = rootElement.getState();
|
||||||
|
|
||||||
getExecutionPolicy(this.action).toError(this.action);
|
getExecutionPolicy(this.action).toError(this.action);
|
||||||
getConfirmationPolicy(this.action).toError(this.action);
|
getConfirmationPolicy(this.action).toError(this.action);
|
||||||
|
|
||||||
|
updateOrderState(rootElement, currentState, rootElement.getState());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -6,6 +6,7 @@ import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.State;
|
import li.strolch.model.State;
|
||||||
import li.strolch.model.activity.Action;
|
import li.strolch.model.activity.Action;
|
||||||
|
import li.strolch.model.activity.Activity;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
import li.strolch.utils.dbc.DBC;
|
import li.strolch.utils.dbc.DBC;
|
||||||
|
|
||||||
|
@ -34,10 +35,15 @@ public class SetActionToExecutedCommand extends ExecutionCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doCommand() {
|
public void doCommand() {
|
||||||
tx().lock(this.action.getRootElement());
|
Activity rootElement = this.action.getRootElement();
|
||||||
|
tx().lock(rootElement);
|
||||||
|
|
||||||
|
State currentState = rootElement.getState();
|
||||||
|
|
||||||
getExecutionPolicy(this.action).toExecuted(this.action);
|
getExecutionPolicy(this.action).toExecuted(this.action);
|
||||||
getConfirmationPolicy(this.action).toExecuted(this.action);
|
getConfirmationPolicy(this.action).toExecuted(this.action);
|
||||||
|
|
||||||
|
updateOrderState(rootElement, currentState, rootElement.getState());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -6,6 +6,7 @@ import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.State;
|
import li.strolch.model.State;
|
||||||
import li.strolch.model.activity.Action;
|
import li.strolch.model.activity.Action;
|
||||||
|
import li.strolch.model.activity.Activity;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
import li.strolch.utils.dbc.DBC;
|
import li.strolch.utils.dbc.DBC;
|
||||||
|
|
||||||
|
@ -34,10 +35,15 @@ public class SetActionToStoppedCommand extends ExecutionCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doCommand() {
|
public void doCommand() {
|
||||||
tx().lock(this.action.getRootElement());
|
Activity rootElement = this.action.getRootElement();
|
||||||
|
tx().lock(rootElement);
|
||||||
|
|
||||||
|
State currentState = rootElement.getState();
|
||||||
|
|
||||||
getExecutionPolicy(this.action).toStopped(this.action);
|
getExecutionPolicy(this.action).toStopped(this.action);
|
||||||
getConfirmationPolicy(this.action).toStopped(this.action);
|
getConfirmationPolicy(this.action).toStopped(this.action);
|
||||||
|
|
||||||
|
updateOrderState(rootElement, currentState, rootElement.getState());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -6,6 +6,7 @@ import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.State;
|
import li.strolch.model.State;
|
||||||
import li.strolch.model.activity.Action;
|
import li.strolch.model.activity.Action;
|
||||||
|
import li.strolch.model.activity.Activity;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
import li.strolch.utils.dbc.DBC;
|
import li.strolch.utils.dbc.DBC;
|
||||||
|
|
||||||
|
@ -34,10 +35,15 @@ public class SetActionToWarningCommand extends ExecutionCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doCommand() {
|
public void doCommand() {
|
||||||
tx().lock(this.action.getRootElement());
|
Activity rootElement = this.action.getRootElement();
|
||||||
|
tx().lock(rootElement);
|
||||||
|
|
||||||
|
State currentState = rootElement.getState();
|
||||||
|
|
||||||
getExecutionPolicy(this.action).toWarning(this.action);
|
getExecutionPolicy(this.action).toWarning(this.action);
|
||||||
getConfirmationPolicy(this.action).toWarning(this.action);
|
getConfirmationPolicy(this.action).toWarning(this.action);
|
||||||
|
|
||||||
|
updateOrderState(rootElement, currentState, rootElement.getState());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue