Skip to content

LUT-29523 A form with a single step generates an error on submission #417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/java/fr/paris/lutece/plugins/forms/business/IStepDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ public interface IStepDAO
*/
Step selectInitialStep( int nIdForm, Plugin plugin );

/**
* Load the final step of the given form
*
* @param nIdForm
* The identifier of the step form
* @param plugin
* the Plugin
* @return The final step of the given form
*/
Step selectFinalStep( int nIdForm, Plugin plugin );

/**
* Load the data of all the step objects and returns them as a list
*
Expand Down
21 changes: 21 additions & 0 deletions src/java/fr/paris/lutece/plugins/forms/business/StepDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public final class StepDAO implements IStepDAO
private static final String SQL_QUERY_SELECTALL = "SELECT id_step, title, description, id_form, is_initial, is_final FROM forms_step";
private static final String SQL_QUERY_SELECT = SQL_QUERY_SELECTALL + " WHERE id_step = ?";
private static final String SQL_QUERY_SELECT_INITIAL_STEP = SQL_QUERY_SELECTALL + " WHERE id_form = ? AND is_initial = 1";
private static final String SQL_QUERY_SELECT_FINAL_STEP = SQL_QUERY_SELECTALL + " WHERE id_form = ? AND is_final = 1";
private static final String SQL_QUERY_INSERT = "INSERT INTO forms_step ( title, description, id_form, is_initial, is_final ) VALUES ( ?, ?, ?, ?, ? ) ";
private static final String SQL_QUERY_DELETE = "DELETE FROM forms_step WHERE id_step = ? ";
private static final String SQL_QUERY_UPDATE = "UPDATE forms_step SET id_step = ?, title = ?, description = ?, id_form = ? ,is_initial = ?, is_final = ? WHERE id_step = ?";
Expand Down Expand Up @@ -120,6 +121,26 @@ public Step selectInitialStep( int nIdForm, Plugin plugin )
return step;
}

/**
* {@inheritDoc }
*/
@Override
public Step selectFinalStep( int nIdForm, Plugin plugin )
{
Step step = null;
try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_FINAL_STEP, plugin ) )
{
daoUtil.setInt( 1, nIdForm );
daoUtil.executeQuery( );

if ( daoUtil.next( ) )
{
step = dataToObject( daoUtil );
}
}
return step;
}

/**
* {@inheritDoc }
*/
Expand Down
19 changes: 19 additions & 0 deletions src/java/fr/paris/lutece/plugins/forms/business/StepHome.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,25 @@ public static Step getInitialStep( int nIdForm )
return step;
}

/**
* Returns the initial step of the given form id
*
* @param nIdForm
* The step form primary key
* @return the initial step of the given form id
*/
public static Step getFinalStep( int nIdForm )
{
String stepCacheKey = _cache.getFinalStepCacheKey( nIdForm );
Step step = (Step) _cache.getFromCache( stepCacheKey );
if ( step == null )
{
step = _dao.selectFinalStep( nIdForm, _plugin );
_cache.putInCache( stepCacheKey, step );
}
return step;
}

/**
* Load the data of all the step objects and returns them as a list
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,7 @@ error.step.isnot.final=The current step is not final.
error.form.inactive=Form inactive
error.form.MaxResponse=Form unavailable because maximum number of responses reached
error.form.noStep=No content available
error.form.noFinalStep=No final step found

warning.deleteComposite.confirmRemoveActiveForm=The form {0} is currently active.
warning.deleteComposite.confirmRemoveQuestion=Do you really want to delete the question "{0}" and all its associated responses?
Expand Down Expand Up @@ -1055,4 +1056,4 @@ error_form_response.pageTitle=Error
# Portlet
portlet.formsList.name=List of forms
portlet.formsList.titleAvailableFormsList=Available forms
portlet.formsList.titlePublishedFormsList=Published forms
portlet.formsList.titlePublishedFormsList=Published forms
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,8 @@ error.step.isnot.final=L'\u00e9tape courante n'est pas finale.
error.form.inactive=Formulaire indisponible
error.form.MaxResponse=Formulaire indisponible car nombre de reponses est atteint
error.form.noStep=Pas de contenu disponible
error.form.noFinalStep=Aucune \u00e9tape finale trouv\u00e9e


warning.deleteComposite.confirmRemoveActiveForm=Le formulaire {0} est actuellement activ\u00e9.
warning.deleteComposite.confirmRemoveQuestion=Voulez-vous vraiment supprimer la question "{0}" et toutes ses r\u00e9ponses associ\u00e9es ?
Expand Down Expand Up @@ -1060,4 +1062,4 @@ error_form_response.pageTitle=Erreur
# Portlet
portlet.formsList.name=Liste de formulaires
portlet.formsList.titleAvailableFormsList=Formulaires disponibles
portlet.formsList.titlePublishedFormsList=Formulaires publi\u00e9s
portlet.formsList.titlePublishedFormsList=Formulaires publi\u00e9s
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public String getInitialStepCacheKey( int nIdForm )
return new StringBuilder( "Initial-Step-For-Form-id:" ).append( nIdForm ).toString( );
}

public String getFinalStepCacheKey( int nIdForm )
{
return new StringBuilder( "Final-Step-For-Form-id:" ).append( nIdForm ).toString( );
}

public String getFormCacheKey( int nIdForm )
{
return new StringBuilder( "Form-id:" ).append( nIdForm ).toString( );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ public final class FormsConstants
public static final String MESSAGE_LOAD_BACKUP = "forms.message.view.loadBackUp";
public static final String MESSAGE_SUMMARY_TITLE = "forms.summary.title";
public static final String MESSAGE_ERROR_NO_STEP = "forms.error.form.noStep";
public static final String MESSAGE_ERROR_NO_FINAL_STEP = "forms.error.form.noFinalStep";


// Jsp
Expand Down
19 changes: 18 additions & 1 deletion src/java/fr/paris/lutece/plugins/forms/web/FormXPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,12 @@ public synchronized XPage getStepView( HttpServletRequest request ) throws SiteM
return null;
}

if ( !isFinalStepExist( nIdForm ) )
{
SiteMessageService.setMessage( request, FormsConstants.MESSAGE_ERROR_NO_FINAL_STEP, SiteMessage.TYPE_ERROR );
return null;
}

Form form = FormHome.findByPrimaryKey( _currentStep.getIdForm( ) );
checkAuthentication( form, request );

Expand Down Expand Up @@ -1394,7 +1400,7 @@ private void init( int nIdForm )
}

/**
* ckeck if the session has expired
* check if the session has expired
*
*
*/
Expand All @@ -1403,4 +1409,15 @@ private boolean isSessionLost( )
return ( _currentStep == null && _formResponseManager == null && _stepDisplayTree == null && _breadcrumb == null );
}

/**
* check if the final step exist
*
* @param nIdForm
* id form
*/
private boolean isFinalStepExist( int nIdForm )
{
return StepHome.getFinalStep(nIdForm) != null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ public String getStepView( HttpServletRequest request )
return redirectView(request, VIEW_ERROR );
}

if ( !isFinalStepExist( nIdForm ) )
{
addError( FormsConstants.MESSAGE_ERROR_NO_FINAL_STEP, getLocale( ) );
return redirectView(request, VIEW_ERROR );
}

Form form = FormHome.findByPrimaryKey( _currentStep.getIdForm( ) );
if ( !(FormsResponseUtils.checkNumberMaxResponseForm( form ) ) )
{
Expand Down Expand Up @@ -747,4 +753,15 @@ private String getBackUrl( Form form, boolean bIsEndMessageDisplayed )
return url.getUrl( );
}
}

/**
* check if the final step exist
*
* @param nIdForm
* id form
*/
private boolean isFinalStepExist( int nIdForm )
{
return StepHome.getFinalStep(nIdForm) != null;
}
}