diff --git a/src/main/java/org/caosdb/server/jobs/ScheduledJob.java b/src/main/java/org/caosdb/server/jobs/ScheduledJob.java index 94aebf1510b4c9657b3a2c172e734b6a76a54e09..d9fa9c42a8a2e703c48d2b9a841ddfdfd0e40017 100644 --- a/src/main/java/org/caosdb/server/jobs/ScheduledJob.java +++ b/src/main/java/org/caosdb/server/jobs/ScheduledJob.java @@ -1,5 +1,13 @@ package org.caosdb.server.jobs; +/** + * ScheduledJob is a wrapper class for jobs held by the Scheduler. + * + * <p>It is mainly a means to have simplified interface for the Scheduler which also measures the + * execution time of the job "from outside". + * + * @author Timm Fitschen (t.fitschen@indiscale.com) + */ public class ScheduledJob { long runtime = 0; diff --git a/src/main/java/org/caosdb/server/jobs/core/CheckStateTransition.java b/src/main/java/org/caosdb/server/jobs/core/CheckStateTransition.java index 35b0fdcfd24a3db356e4fa9f2debf20577ea4319..0f9c324aee1f6c5d5222164b3f3fe0f793b26545 100644 --- a/src/main/java/org/caosdb/server/jobs/core/CheckStateTransition.java +++ b/src/main/java/org/caosdb/server/jobs/core/CheckStateTransition.java @@ -52,6 +52,12 @@ public class CheckStateTransition extends EntityStateJob { } } + /** + * Check if the state belongs to the state model. + * + * @param state + * @throws Message + */ private void checkStateValid(State state) throws Message { if (state.isFinal() || state.isInitial() || state.getStateModel().getStates().contains(state)) { return; @@ -59,7 +65,13 @@ public class CheckStateTransition extends EntityStateJob { throw STATE_NOT_IN_STATE_MODEL; } - /** Check if state is valid and transition is allowed */ + /** + * Check if state is valid and transition is allowed. + * + * @param fromState + * @param toState + * @throws Message if not + */ private void checkStateTransition(State fromState, State toState) throws Message { if (fromState == null && toState == null) { return; @@ -88,6 +100,12 @@ public class CheckStateTransition extends EntityStateJob { throw TRANSITION_NOT_ALLOWED; } + /** + * @param fromState + * @param toState + * @return the state model which contains both of the states. + * @throws Message if the state model of one of the states cannot be constructed. + */ private StateModel findMatchingStateModel(State fromState, State toState) throws Message { if (fromState.getStateModel().equals(toState.getStateModel())) { return fromState.getStateModel(); @@ -95,6 +113,12 @@ public class CheckStateTransition extends EntityStateJob { return null; } + /** + * Check if the old state is final or if the {@link FORCE_FINAL_STATE} flag is true. + * + * @param fromState + * @throws Message if the state is not final. + */ private void checkFinalState(State fromState) throws Message { if (!fromState.isFinal()) { if ("true".equalsIgnoreCase(getTransaction().getContainer().getFlags().get(FORCE_FINAL_STATE)) @@ -107,6 +131,12 @@ public class CheckStateTransition extends EntityStateJob { // TODO permissions } + /** + * Check if the new state is an initial state. + * + * @param toState + * @throws Message if not + */ private void checkInitialState(State toState) throws Message { if (!toState.isInitial()) { throw INITIAL_STATE_NOT_ALLOWED; diff --git a/src/main/java/org/caosdb/server/jobs/core/EntityStateJob.java b/src/main/java/org/caosdb/server/jobs/core/EntityStateJob.java index 1aa9608107b470f167724c354388c2d9059a839d..0602c2025b58bba0bab4652b7654fe8cb418bba6 100644 --- a/src/main/java/org/caosdb/server/jobs/core/EntityStateJob.java +++ b/src/main/java/org/caosdb/server/jobs/core/EntityStateJob.java @@ -51,7 +51,7 @@ public abstract class EntityStateJob extends EntityJob { public static final String TO_STATE_PROPERTY_NAME = "to"; public static final String FROM_STATE_PROPERTY_NAME = "from"; public static final String FINAL_STATE_PROPERTY_NAME = "final"; - public static final String INITIAL_STATE_PROPERTY_NAME = "final"; + public static final String INITIAL_STATE_PROPERTY_NAME = "initial"; public static final String STATE_RECORD_TYPE_NAME = "State"; public static final String STATE_MODEL_RECORD_TYPE_NAME = "StateModel"; public static final String TRANSITION_RECORD_TYPE_NAME = "Transition"; @@ -63,10 +63,10 @@ public abstract class EntityStateJob extends EntityJob { new Message(MessageType.Error, "StateModel not found."); public static final Message STATE_NOT_IN_STATE_MODEL = new Message(MessageType.Error, "State does not exist in this StateModel."); - public static final Message COULD_NOT_GENERATE_STATE_MESSAGE = - new Message(MessageType.Error, "Could not generate the state message."); - public static final Message COULD_NOT_GENERATE_TRANSITIONS = - new Message(MessageType.Error, "Could not generate transitions."); + public static final Message COULD_NOT_CONSTRUCT_STATE_MESSAGE = + new Message(MessageType.Error, "Could not construct the state message."); + public static final Message COULD_NOT_CONSTRUCT_TRANSITIONS = + new Message(MessageType.Error, "Could not construct the transitions."); public static final Message STATE_MODEL_NOT_SPECIFIED = new Message(MessageType.Error, "State model not specified."); public static final Message STATE_NOT_SPECIFIED = @@ -353,7 +353,7 @@ public abstract class EntityStateJob extends EntityJob { } } } catch (Exception e) { - throw COULD_NOT_GENERATE_TRANSITIONS; + throw COULD_NOT_CONSTRUCT_TRANSITIONS; } return result; } @@ -526,7 +526,7 @@ public abstract class EntityStateJob extends EntityJob { EntityInterface stateModelEntity = findStateModel(stateEntity); return new State(stateEntity, stateModelEntity); } catch (Exception e) { - throw COULD_NOT_GENERATE_STATE_MESSAGE; + throw COULD_NOT_CONSTRUCT_STATE_MESSAGE; } }