mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-20 14:10:44 +00:00
CE-1955 - Add back to processes
This commit is contained in:
@ -122,6 +122,12 @@ public class RunProcessAction
|
||||
UUIDAndTypeStateKey stateKey = new UUIDAndTypeStateKey(UUID.fromString(runProcessInput.getProcessUUID()), StateType.PROCESS_STATUS);
|
||||
ProcessState processState = primeProcessState(runProcessInput, stateKey, process);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// these should always be clear when we're starting a run - so make sure they haven't leaked from previous //
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
processState.clearNextStepName();
|
||||
processState.clearBackStepName();
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
// if process is 'basepull' style, keep track of 'now' //
|
||||
/////////////////////////////////////////////////////////
|
||||
@ -188,14 +194,35 @@ public class RunProcessAction
|
||||
private void runLinearStepLoop(QProcessMetaData process, ProcessState processState, UUIDAndTypeStateKey stateKey, RunProcessInput runProcessInput, RunProcessOutput runProcessOutput) throws Exception
|
||||
{
|
||||
String lastStepName = runProcessInput.getStartAfterStep();
|
||||
String startAtStep = runProcessInput.getStartAtStep();
|
||||
|
||||
while(true)
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// always refresh the step list - as any step that runs can modify it (in the process state). //
|
||||
// this is why we don't do a loop over the step list - as we'd get ConcurrentModificationExceptions. //
|
||||
// deal with if we were told, from the input, to start After a step, or start At a step. //
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
List<QStepMetaData> stepList = getAvailableStepList(processState, process, lastStepName);
|
||||
List<QStepMetaData> stepList;
|
||||
if(startAtStep == null)
|
||||
{
|
||||
stepList = getAvailableStepList(processState, process, lastStepName, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
stepList = getAvailableStepList(processState, process, startAtStep, true);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// clear this field - so after we run a step, we'll then loop in last-step mode. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
startAtStep = null;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// if we're going to run a backend step now, let it see that this is a step-back //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
processState.setIsStepBack(true);
|
||||
}
|
||||
|
||||
if(stepList.isEmpty())
|
||||
{
|
||||
break;
|
||||
@ -232,7 +259,18 @@ public class RunProcessAction
|
||||
//////////////////////////////////////////////////
|
||||
throw (new QException("Unsure how to run a step of type: " + step.getClass().getName()));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// only let this value be set for the original back step - don't let it stick around. //
|
||||
// if a process wants to keep track of this itself, it can, but in a different slot. //
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
processState.setIsStepBack(false);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// in case we broke from the loop above (e.g., by going directly into a frontend step), once again make sure to lower this flag. //
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
processState.setIsStepBack(false);
|
||||
}
|
||||
|
||||
|
||||
@ -264,6 +302,12 @@ public class RunProcessAction
|
||||
processFrontendStepFieldDefaultValues(processState, step);
|
||||
processFrontendComponents(processState, step);
|
||||
processState.setNextStepName(step.getName());
|
||||
|
||||
if(StringUtils.hasContent(step.getBackStepName()) && processState.getBackStepName().isEmpty())
|
||||
{
|
||||
processState.setBackStepName(step.getBackStepName());
|
||||
}
|
||||
|
||||
return LoopTodo.BREAK;
|
||||
}
|
||||
case SKIP ->
|
||||
@ -317,6 +361,7 @@ public class RunProcessAction
|
||||
// else run the given lastStepName //
|
||||
/////////////////////////////////////
|
||||
processState.clearNextStepName();
|
||||
processState.clearBackStepName();
|
||||
step = process.getStep(lastStepName);
|
||||
if(step == null)
|
||||
{
|
||||
@ -398,6 +443,7 @@ public class RunProcessAction
|
||||
// its sub-steps, or, to fall out of the loop and end the process. //
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
processState.clearNextStepName();
|
||||
processState.clearBackStepName();
|
||||
runStateMachineStep(nextStepName.get(), process, processState, stateKey, runProcessInput, runProcessOutput, stackDepth + 1);
|
||||
return;
|
||||
}
|
||||
@ -621,8 +667,10 @@ public class RunProcessAction
|
||||
|
||||
/*******************************************************************************
|
||||
** Get the list of steps which are eligible to run.
|
||||
**
|
||||
** lastStep will be included in the list, or not, based on includeLastStep.
|
||||
*******************************************************************************/
|
||||
private List<QStepMetaData> getAvailableStepList(ProcessState processState, QProcessMetaData process, String lastStep) throws QException
|
||||
static List<QStepMetaData> getAvailableStepList(ProcessState processState, QProcessMetaData process, String lastStep, boolean includeLastStep) throws QException
|
||||
{
|
||||
if(lastStep == null)
|
||||
{
|
||||
@ -649,6 +697,10 @@ public class RunProcessAction
|
||||
if(stepName.equals(lastStep))
|
||||
{
|
||||
foundLastStep = true;
|
||||
if(includeLastStep)
|
||||
{
|
||||
validStepNames.add(stepName);
|
||||
}
|
||||
}
|
||||
}
|
||||
return (stepNamesToSteps(process, validStepNames));
|
||||
@ -660,7 +712,7 @@ public class RunProcessAction
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private List<QStepMetaData> stepNamesToSteps(QProcessMetaData process, List<String> stepNames) throws QException
|
||||
private static List<QStepMetaData> stepNamesToSteps(QProcessMetaData process, List<String> stepNames) throws QException
|
||||
{
|
||||
List<QStepMetaData> result = new ArrayList<>();
|
||||
|
||||
|
@ -40,6 +40,8 @@ public class ProcessState implements Serializable
|
||||
private Map<String, Serializable> values = new HashMap<>();
|
||||
private List<String> stepList = new ArrayList<>();
|
||||
private Optional<String> nextStepName = Optional.empty();
|
||||
private Optional<String> backStepName = Optional.empty();
|
||||
private boolean isStepBack = false;
|
||||
|
||||
private ProcessMetaDataAdjustment processMetaDataAdjustment = null;
|
||||
|
||||
@ -122,6 +124,39 @@ public class ProcessState implements Serializable
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for backStepName
|
||||
**
|
||||
*******************************************************************************/
|
||||
public Optional<String> getBackStepName()
|
||||
{
|
||||
return backStepName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for backStepName
|
||||
**
|
||||
*******************************************************************************/
|
||||
public void setBackStepName(String backStepName)
|
||||
{
|
||||
this.backStepName = Optional.of(backStepName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** clear out the value of backStepName (set the Optional to empty)
|
||||
**
|
||||
*******************************************************************************/
|
||||
public void clearBackStepName()
|
||||
{
|
||||
this.backStepName = Optional.empty();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for stepList
|
||||
**
|
||||
@ -176,4 +211,35 @@ public class ProcessState implements Serializable
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for isStepBack
|
||||
*******************************************************************************/
|
||||
public boolean getIsStepBack()
|
||||
{
|
||||
return (this.isStepBack);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for isStepBack
|
||||
*******************************************************************************/
|
||||
public void setIsStepBack(boolean isStepBack)
|
||||
{
|
||||
this.isStepBack = isStepBack;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for isStepBack
|
||||
*******************************************************************************/
|
||||
public ProcessState withIsStepBack(boolean isStepBack)
|
||||
{
|
||||
this.isStepBack = isStepBack;
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -419,6 +419,17 @@ public class RunBackendStepInput extends AbstractActionInput
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Accessor for processState's isStepBack attribute
|
||||
**
|
||||
*******************************************************************************/
|
||||
public boolean getIsStepBack()
|
||||
{
|
||||
return processState.getIsStepBack();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Accessor for processState - protected, because we generally want to access
|
||||
** its members through wrapper methods, we think
|
||||
|
@ -49,6 +49,7 @@ public class RunProcessInput extends AbstractActionInput
|
||||
private ProcessState processState;
|
||||
private FrontendStepBehavior frontendStepBehavior = FrontendStepBehavior.BREAK;
|
||||
private String startAfterStep;
|
||||
private String startAtStep;
|
||||
private String processUUID;
|
||||
private AsyncJobCallback asyncJobCallback;
|
||||
|
||||
@ -451,4 +452,35 @@ public class RunProcessInput extends AbstractActionInput
|
||||
{
|
||||
return asyncJobCallback;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for startAtStep
|
||||
*******************************************************************************/
|
||||
public String getStartAtStep()
|
||||
{
|
||||
return (this.startAtStep);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for startAtStep
|
||||
*******************************************************************************/
|
||||
public void setStartAtStep(String startAtStep)
|
||||
{
|
||||
this.startAtStep = startAtStep;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for startAtStep
|
||||
*******************************************************************************/
|
||||
public RunProcessInput withStartAtStep(String startAtStep)
|
||||
{
|
||||
this.startAtStep = startAtStep;
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -48,6 +48,7 @@ public class QFrontendStepMetaData extends QStepMetaData
|
||||
private Map<String, QFieldMetaData> formFieldMap;
|
||||
|
||||
private String format;
|
||||
private String backStepName;
|
||||
|
||||
private List<QHelpContent> helpContents;
|
||||
|
||||
@ -436,4 +437,35 @@ public class QFrontendStepMetaData extends QStepMetaData
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for backStepName
|
||||
*******************************************************************************/
|
||||
public String getBackStepName()
|
||||
{
|
||||
return (this.backStepName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for backStepName
|
||||
*******************************************************************************/
|
||||
public void setBackStepName(String backStepName)
|
||||
{
|
||||
this.backStepName = backStepName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for backStepName
|
||||
*******************************************************************************/
|
||||
public QFrontendStepMetaData withBackStepName(String backStepName)
|
||||
{
|
||||
this.backStepName = backStepName;
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user