From 15db21b45e2f806a564b0360cdb48762a5707372 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 23 Aug 2018 10:50:51 +0200 Subject: [PATCH] [Major] Call validate() in EventBasedExecutionHandler and lock action/activie --- .../li/strolch/execution/EventBasedExecutionHandler.java | 8 +++++++- .../strolch/execution/command/ExecuteActivityCommand.java | 1 + .../execution/command/SetActionToErrorCommand.java | 2 ++ .../execution/command/SetActionToExecutedCommand.java | 2 ++ .../execution/command/SetActionToStoppedCommand.java | 2 ++ .../execution/command/SetActionToWarningCommand.java | 2 ++ 6 files changed, 16 insertions(+), 1 deletion(-) diff --git a/li.strolch.service/src/main/java/li/strolch/execution/EventBasedExecutionHandler.java b/li.strolch.service/src/main/java/li/strolch/execution/EventBasedExecutionHandler.java index 7c2462c80..d938aefd4 100644 --- a/li.strolch.service/src/main/java/li/strolch/execution/EventBasedExecutionHandler.java +++ b/li.strolch.service/src/main/java/li/strolch/execution/EventBasedExecutionHandler.java @@ -308,6 +308,7 @@ public class EventBasedExecutionHandler extends ExecutionHandler { ExecuteActivityCommand command = new ExecuteActivityCommand(getContainer(), tx); command.setActivity(activity); + command.validate(); command.doCommand(); tx.commitOnClose(); @@ -327,9 +328,10 @@ public class EventBasedExecutionHandler extends ExecutionHandler { // set this action to executed SetActionToExecutedCommand command = new SetActionToExecutedCommand(getContainer(), tx); command.setAction(action); + command.validate(); command.doCommand(); - // flush so we can see that changes performed + // flush so we can see the changes performed tx.flush(); // if the activity is now executed, remove it from the registered activities @@ -349,6 +351,7 @@ public class EventBasedExecutionHandler extends ExecutionHandler { ExecuteActivityCommand execCommand = new ExecuteActivityCommand(getContainer(), tx); execCommand.setActivity(activity); + execCommand.validate(); execCommand.doCommand(); // flush so we can see the changes performed @@ -372,6 +375,7 @@ public class EventBasedExecutionHandler extends ExecutionHandler { SetActionToWarningCommand command = new SetActionToWarningCommand(getContainer(), tx); command.setAction((Action) elem); + command.validate(); command.doCommand(); tx.commitOnClose(); @@ -388,6 +392,7 @@ public class EventBasedExecutionHandler extends ExecutionHandler { SetActionToErrorCommand command = new SetActionToErrorCommand(getContainer(), tx); command.setAction((Action) elem); + command.validate(); command.doCommand(); tx.commitOnClose(); @@ -404,6 +409,7 @@ public class EventBasedExecutionHandler extends ExecutionHandler { SetActionToStoppedCommand command = new SetActionToStoppedCommand(getContainer(), tx); command.setAction((Action) elem); + command.validate(); command.doCommand(); tx.commitOnClose(); diff --git a/li.strolch.service/src/main/java/li/strolch/execution/command/ExecuteActivityCommand.java b/li.strolch.service/src/main/java/li/strolch/execution/command/ExecuteActivityCommand.java index 1eb1890b7..b7615c13a 100644 --- a/li.strolch.service/src/main/java/li/strolch/execution/command/ExecuteActivityCommand.java +++ b/li.strolch.service/src/main/java/li/strolch/execution/command/ExecuteActivityCommand.java @@ -21,6 +21,7 @@ public class ExecuteActivityCommand extends ExecutionCommand { @Override public void validate() { DBC.PRE.assertNotNull("activity can not be null!", this.activity); + tx().lock(this.activity.getRootElement()); } @Override diff --git a/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToErrorCommand.java b/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToErrorCommand.java index 883005962..780dbf88d 100644 --- a/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToErrorCommand.java +++ b/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToErrorCommand.java @@ -26,6 +26,8 @@ public class SetActionToErrorCommand extends ExecutionCommand { public void validate() { DBC.PRE.assertNotNull("action can not be null", this.action); + tx().lock(this.action.getRootElement()); + if (!this.action.getState().canSetToError()) { String msg = "Current state is {0} and canot be changed to {1} for action {2}"; msg = MessageFormat.format(msg, this.action.getState(), State.ERROR, this.action.getLocator()); diff --git a/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToExecutedCommand.java b/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToExecutedCommand.java index b7d124ede..6da8eabd7 100644 --- a/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToExecutedCommand.java +++ b/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToExecutedCommand.java @@ -26,6 +26,8 @@ public class SetActionToExecutedCommand extends ExecutionCommand { public void validate() { DBC.PRE.assertNotNull("action can not be null", this.action); + tx().lock(this.action.getRootElement()); + if (!this.action.getState().canSetToExecuted()) { String msg = "State {0} and canot be changed to {1} for action {2}"; msg = MessageFormat.format(msg, this.action.getState(), State.EXECUTED, this.action.getLocator()); diff --git a/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToStoppedCommand.java b/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToStoppedCommand.java index c299aa530..c5979ee7c 100644 --- a/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToStoppedCommand.java +++ b/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToStoppedCommand.java @@ -26,6 +26,8 @@ public class SetActionToStoppedCommand extends ExecutionCommand { public void validate() { DBC.PRE.assertNotNull("action can not be null", this.action); + tx().lock(this.action.getRootElement()); + if (!this.action.getState().canSetToStopped()) { String msg = "State {0} and canot be changed to {1} for action {2}"; msg = MessageFormat.format(msg, this.action.getState(), State.STOPPED, this.action.getLocator()); diff --git a/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToWarningCommand.java b/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToWarningCommand.java index 267cf3984..0918d9ab9 100644 --- a/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToWarningCommand.java +++ b/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToWarningCommand.java @@ -26,6 +26,8 @@ public class SetActionToWarningCommand extends ExecutionCommand { public void validate() { DBC.PRE.assertNotNull("action can not be null", this.action); + tx().lock(this.action.getRootElement()); + if (!this.action.getState().canSetToWarning()) { String msg = "State {0} and canot be changed to {1} for action {2}"; msg = MessageFormat.format(msg, this.action.getState(), State.WARNING, this.action.getLocator());