Skip to content
Snippets Groups Projects
Verified Commit 8c69cf83 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

More cleanup and docs

parent f081a5f8
No related branches found
No related tags found
3 merge requests!21Release v0.4.0,!7F fsm,!6Draft: F acm permissions2
package org.caosdb.server.jobs; 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 { public class ScheduledJob {
long runtime = 0; long runtime = 0;
......
...@@ -52,6 +52,12 @@ public class CheckStateTransition extends EntityStateJob { ...@@ -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 { private void checkStateValid(State state) throws Message {
if (state.isFinal() || state.isInitial() || state.getStateModel().getStates().contains(state)) { if (state.isFinal() || state.isInitial() || state.getStateModel().getStates().contains(state)) {
return; return;
...@@ -59,7 +65,13 @@ public class CheckStateTransition extends EntityStateJob { ...@@ -59,7 +65,13 @@ public class CheckStateTransition extends EntityStateJob {
throw STATE_NOT_IN_STATE_MODEL; 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 { private void checkStateTransition(State fromState, State toState) throws Message {
if (fromState == null && toState == null) { if (fromState == null && toState == null) {
return; return;
...@@ -88,6 +100,12 @@ public class CheckStateTransition extends EntityStateJob { ...@@ -88,6 +100,12 @@ public class CheckStateTransition extends EntityStateJob {
throw TRANSITION_NOT_ALLOWED; 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 { private StateModel findMatchingStateModel(State fromState, State toState) throws Message {
if (fromState.getStateModel().equals(toState.getStateModel())) { if (fromState.getStateModel().equals(toState.getStateModel())) {
return fromState.getStateModel(); return fromState.getStateModel();
...@@ -95,6 +113,12 @@ public class CheckStateTransition extends EntityStateJob { ...@@ -95,6 +113,12 @@ public class CheckStateTransition extends EntityStateJob {
return null; 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 { private void checkFinalState(State fromState) throws Message {
if (!fromState.isFinal()) { if (!fromState.isFinal()) {
if ("true".equalsIgnoreCase(getTransaction().getContainer().getFlags().get(FORCE_FINAL_STATE)) if ("true".equalsIgnoreCase(getTransaction().getContainer().getFlags().get(FORCE_FINAL_STATE))
...@@ -107,6 +131,12 @@ public class CheckStateTransition extends EntityStateJob { ...@@ -107,6 +131,12 @@ public class CheckStateTransition extends EntityStateJob {
// TODO permissions // TODO permissions
} }
/**
* Check if the new state is an initial state.
*
* @param toState
* @throws Message if not
*/
private void checkInitialState(State toState) throws Message { private void checkInitialState(State toState) throws Message {
if (!toState.isInitial()) { if (!toState.isInitial()) {
throw INITIAL_STATE_NOT_ALLOWED; throw INITIAL_STATE_NOT_ALLOWED;
......
...@@ -51,7 +51,7 @@ public abstract class EntityStateJob extends EntityJob { ...@@ -51,7 +51,7 @@ public abstract class EntityStateJob extends EntityJob {
public static final String TO_STATE_PROPERTY_NAME = "to"; public static final String TO_STATE_PROPERTY_NAME = "to";
public static final String FROM_STATE_PROPERTY_NAME = "from"; public static final String FROM_STATE_PROPERTY_NAME = "from";
public static final String FINAL_STATE_PROPERTY_NAME = "final"; 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_RECORD_TYPE_NAME = "State";
public static final String STATE_MODEL_RECORD_TYPE_NAME = "StateModel"; public static final String STATE_MODEL_RECORD_TYPE_NAME = "StateModel";
public static final String TRANSITION_RECORD_TYPE_NAME = "Transition"; public static final String TRANSITION_RECORD_TYPE_NAME = "Transition";
...@@ -63,10 +63,10 @@ public abstract class EntityStateJob extends EntityJob { ...@@ -63,10 +63,10 @@ public abstract class EntityStateJob extends EntityJob {
new Message(MessageType.Error, "StateModel not found."); new Message(MessageType.Error, "StateModel not found.");
public static final Message STATE_NOT_IN_STATE_MODEL = public static final Message STATE_NOT_IN_STATE_MODEL =
new Message(MessageType.Error, "State does not exist in this StateModel."); new Message(MessageType.Error, "State does not exist in this StateModel.");
public static final Message COULD_NOT_GENERATE_STATE_MESSAGE = public static final Message COULD_NOT_CONSTRUCT_STATE_MESSAGE =
new Message(MessageType.Error, "Could not generate the state message."); new Message(MessageType.Error, "Could not construct the state message.");
public static final Message COULD_NOT_GENERATE_TRANSITIONS = public static final Message COULD_NOT_CONSTRUCT_TRANSITIONS =
new Message(MessageType.Error, "Could not generate transitions."); new Message(MessageType.Error, "Could not construct the transitions.");
public static final Message STATE_MODEL_NOT_SPECIFIED = public static final Message STATE_MODEL_NOT_SPECIFIED =
new Message(MessageType.Error, "State model not specified."); new Message(MessageType.Error, "State model not specified.");
public static final Message STATE_NOT_SPECIFIED = public static final Message STATE_NOT_SPECIFIED =
...@@ -353,7 +353,7 @@ public abstract class EntityStateJob extends EntityJob { ...@@ -353,7 +353,7 @@ public abstract class EntityStateJob extends EntityJob {
} }
} }
} catch (Exception e) { } catch (Exception e) {
throw COULD_NOT_GENERATE_TRANSITIONS; throw COULD_NOT_CONSTRUCT_TRANSITIONS;
} }
return result; return result;
} }
...@@ -526,7 +526,7 @@ public abstract class EntityStateJob extends EntityJob { ...@@ -526,7 +526,7 @@ public abstract class EntityStateJob extends EntityJob {
EntityInterface stateModelEntity = findStateModel(stateEntity); EntityInterface stateModelEntity = findStateModel(stateEntity);
return new State(stateEntity, stateModelEntity); return new State(stateEntity, stateModelEntity);
} catch (Exception e) { } catch (Exception e) {
throw COULD_NOT_GENERATE_STATE_MESSAGE; throw COULD_NOT_CONSTRUCT_STATE_MESSAGE;
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment