}
protected String completeFlow(FlowStateLifecycle nextFlowLifecycleState) {
String pageName = null;
if (!isCompleted()) {
FlowState continueWithFlow = null;
boolean verifyValues = nextFlowLifecycleState.isVerifyValues();
FlowValidationResult flowValidationResult = passivate(verifyValues, FlowStepDirection.inPlace);
if (verifyValues) {
FlowValidationException.valid(flowValidationResult);
saveChanges();
}
this.setFlowLifecycleState(nextFlowLifecycleState);
boolean success = false;
try {
// getting continueWithFlow should use FlowLauncher more correctly.
continueWithFlow = finishFlowActivities(verifyValues);
success = true;
} finally {
this.setCurrentActivityByName(null);
clearCache();
if (!success) {
getFlowManagement().dropFlowState(this);
}
}
// pass on the return flow to the continuation flow.
// need to set before starting continuation flow because continuation flow may run to completion.
// HACK : seems like the continueFlow should have picked this up automatically
String returnToFlow = this.getProperty(FSRETURN_TO_FLOW);
this.setProperty(FSRETURN_TO_FLOW, null);
// TODO: THIS block of code should be in the FlowManagement code.
// TODO: Put this in a FlowPropertyValueProvider !!
// OLD note but may still be valid:
// if continueWithFlow is not null then we do not want start
// any other flows except continueWithFlow. Autorun flows should
// start only if we have no flow specified by the finishingActivity. This
// caused bad UI behavior when we used TransitionFlowActivity to start new
// flow.
// make sure that don't get into trouble by a finishFlow that
// returns the current FlowState.
if (continueWithFlow == null || continueWithFlow == this) {
if ( nextFlowLifecycleState == successful && isNotBlank(returnToFlow)) {
FlowState returnFlow = getFlowManagement().getFlowState(returnToFlow);
Map exportedMap = this.getExportedValuesMap().getAsFlattenedStringMap();
returnFlow.setAllProperties(exportedMap);
}
pageName = getFlowManagement().completeFlowState(this, false, nextFlowLifecycleState);
} else {
if ( isNotBlank(returnToFlow)) {
continueWithFlow.setProperty(FSRETURN_TO_FLOW, returnToFlow);