Class MultistepFormsService
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMultistepFormsService(SaveFormService saveFormService, FormsRepository formsRepository, FormItemsRepository formItemsRepository, FormStepsRepository formStepsRepository, FormSettingsRepository formSettingsRepository) -
Method Summary
Modifier and TypeMethodDescriptionfinal List<LabelValue>getAutocompleteOptions(Long stepId, Long itemId, String term, jakarta.servlet.http.HttpServletRequest request) Return matching configured options for an autocomplete form item.final List<LabelValue>getAvailableConditionFields(String formName, Long stepId, Prop prop) Build available source fields for condition builder up to the current step.getChartStatInfo(jakarta.servlet.http.HttpServletRequest request) Extract chart statistics parameters from request.static final StringgetFieldName(FormItemEntity stepItem, Prop prop) Resolve human-readable field name for validation and UI messages.static final List<LabelValue>getFieldTabVisibility(jakarta.servlet.http.HttpServletRequest request) Provide tab visibility configuration per field type.static final Pair<List<LabelValue>,List<LabelValue>> getFieldTypes(jakarta.servlet.http.HttpServletRequest request) Provide supported form field types as label/value pairs.static final List<LabelValue>getFiledTypeVisibility(jakarta.servlet.http.HttpServletRequest request) Provide visibility configuration per field type (which technical fields are hidden).intgetFormCounter(String formName, jakarta.servlet.http.HttpServletRequest request) Retrieve the form instance counter for the current request.getFormDataAsMap(FormsEntity form) Convert serialized form data into a key/value map.final intstatic intgetFormIdStatic(String formName) static List<FormItemEntity>getFormItemsForValidation(String formName) Fetch distinct minimal form item definitions required for validation for the form.static final StringgetFormName(jakarta.servlet.http.HttpServletRequest request) Extract and sanitize theformNamefrom the request.static final StringgetFormName(Map<String, String> params) Extract and sanitize theformNamefrom a params map.final List<LabelValue>getFormStepsOptions(String formName, Prop prop) Build human-readable options for steps of a form suitable for selection inputs.static final StringgetNewSessionKey(String formName, String csrf) Build a new session key for the given form and CSRF token.static final FormStepEntitygetNextStep(String formName, FormStepEntity currentStep, FormStepsRepository repo) Get the next step following the provided step within a form sequence.static final List<LabelValue>getRegExOptions(RegExpRepository regExpRepository, jakarta.servlet.http.HttpServletRequest request) Provide available regular expression validations as label/value pairs for UI.Return technical field types used only for row/column layout in the form editor.static final StringgetSessionKey(String formName, jakarta.servlet.http.HttpServletRequest request) Build the session key used to store per-form, per-request step data.final StringgetValidItemFormId(FormItemEntity entity) Generate a valid and uniqueitemFormIdfor a form item within a form.static final booleanisFieldtypeIterable(String fieldType, jakarta.servlet.http.HttpServletRequest request) static final booleanisFileUploadField(String fieldType) Determine whether a form field stores an asynchronously uploaded attachment.final List<LabelValue>prepareConditionFieldOptions(List<FormItemEntity> fields, String formName, Prop prop) Build condition field options from arbitrary field collection.final voidsaveFormStep(String formName, Long stepId, jakarta.servlet.http.HttpServletRequest request, org.json.JSONObject response) Validate and persist a single step of a multistep form into session, and optionally finalize the form submission.final voidupdateFormPattern(String formName) Update or create the pattern entity (form definition) for the form by concatenating all uniqueitemFormIds in validation order.static final StringBuilderupdateFormValues(String formName, jakarta.servlet.http.HttpServletRequest request, StringBuilder formHtml) voidupdateStepsPositions(String formName) Recompute current and max positions for all steps in a form.voidupdateStepsPositions(RowReorderDto rowReorderDto) Refresh step positions after row reorder operation payload.final booleanvalidateFormInfo(String formName, Long currentStepId, jakarta.servlet.http.HttpServletRequest request) Validate whether provided form and step represent an allowed step for current session.
-
Field Details
-
SESSION_PREFIX
Service handling validation, session persistence and saving of multistep forms.Responsibilities: - Generate stable session keys per form and user request - Validate step inputs (required, regex, XSS, CAPTCHA, CSRF, file rules) - Orchestrate custom processors/interceptors for steps and final save - Persist intermediate step data into HTTP session and finalize DB save
- See Also:
-
MULTIUPLOAD_PREFIX
- See Also:
-
FILE_INPUT_FIELD_TYPE
- See Also:
-
VISIBILITY_TAB
- See Also:
-
REQUIREMENT_TAB
- See Also:
-
-
Constructor Details
-
MultistepFormsService
@Autowired public MultistepFormsService(SaveFormService saveFormService, FormsRepository formsRepository, FormItemsRepository formItemsRepository, FormStepsRepository formStepsRepository, FormSettingsRepository formSettingsRepository)
-
-
Method Details
-
getSessionKey
public static final String getSessionKey(String formName, jakarta.servlet.http.HttpServletRequest request) Build the session key used to store per-form, per-request step data.- Parameters:
formName- logical form name (will be sanitized elsewhere)request- HTTP request providing the CSRF token header- Returns:
- stable session key in format
MultistepForm_<formName>_<domainId>_<csrf>
-
getNewSessionKey
Build a new session key for the given form and CSRF token.- Parameters:
formName- logical form namecsrf- CSRF token value- Returns:
- session key string
-
getFormName
Extract and sanitize theformNamefrom a params map.- Parameters:
params- map potentially containing keyformName- Returns:
- sanitized form name (safe for identifiers)
-
getFormName
Extract and sanitize theformNamefrom the request.- Parameters:
request- HTTP request containing parameterformName- Returns:
- sanitized form name (safe for identifiers)
-
getRegExOptions
public static final List<LabelValue> getRegExOptions(RegExpRepository regExpRepository, jakarta.servlet.http.HttpServletRequest request) Provide available regular expression validations as label/value pairs for UI.- Parameters:
regExpRepository- repository of regex definitionsrequest- request used to resolve localized titles- Returns:
- list of label/value options
-
getFieldTypes
public static final Pair<List<LabelValue>,List<LabelValue>> getFieldTypes(jakarta.servlet.http.HttpServletRequest request) Provide supported form field types as label/value pairs.- Parameters:
request- request used to resolve localized labels- Returns:
- list of field type options
-
isFieldtypeIterable
public static final boolean isFieldtypeIterable(String fieldType, jakarta.servlet.http.HttpServletRequest request) -
isFileUploadField
Determine whether a form field stores an asynchronously uploaded attachment.- Parameters:
fieldType- configured form field type- Returns:
truefor multi-upload variants and the single-file input
-
getFiledTypeVisibility
public static final List<LabelValue> getFiledTypeVisibility(jakarta.servlet.http.HttpServletRequest request) Provide visibility configuration per field type (which technical fields are hidden). Adds a special optionallwaysHidden.- Parameters:
request- request used to resolve localized labels- Returns:
- list of visibility label/value pairs
-
getFieldTabVisibility
public static final List<LabelValue> getFieldTabVisibility(jakarta.servlet.http.HttpServletRequest request) Provide tab visibility configuration per field type.Depending on the field type, returns list of tabs that should be shown in admin: visibility conditions, requirement conditions, both, or none.
- Parameters:
request- request used to resolve localized labels and field metadata- Returns:
- list mapping field type to a comma-separated list of visible tabs
-
getNextStep
public static final FormStepEntity getNextStep(String formName, FormStepEntity currentStep, FormStepsRepository repo) Get the next step following the provided step within a form sequence.- Parameters:
formName- logical form namecurrentStep- current step entityrepo- repository used to fetch ordered steps- Returns:
- next step entity or
nullif current step is the last - Throws:
IllegalStateException- when the provided step does not belong to the form/domain
-
getRowViewItemTypes
Return technical field types used only for row/column layout in the form editor.- Returns:
- list of non-input layout item field types
-
getFormDataAsMap
Convert serialized form data into a key/value map.Input format is expected as
itemFormId~valuepairs separated by|. Multi-upload synthetic suffix-fileNamesis normalized away.- Parameters:
form- persisted form entity with serialized data- Returns:
- ordered map of field identifiers and their values
-
getFieldName
Resolve human-readable field name for validation and UI messages.- Parameters:
stepItem- form item definitionprop- localization provider- Returns:
- localized field label or plain text extracted from custom HTML label
-
getChartStatInfo
public static final Pair<String,String> getChartStatInfo(jakarta.servlet.http.HttpServletRequest request) Extract chart statistics parameters from request.- Parameters:
request- HTTP request containing optionalformNameanditemFormId- Returns:
- pair of
(formName, itemFormId)when both are present, otherwisenull
-
getFormId
-
getFormIdStatic
-
validateFormInfo
public final boolean validateFormInfo(String formName, Long currentStepId, jakarta.servlet.http.HttpServletRequest request) Validate whether provided form and step represent an allowed step for current session.- Parameters:
formName- logical form namecurrentStepId- step id to validaterequest- request with session context- Returns:
truewhen the step exists and is permitted in current session
-
getAutocompleteOptions
public final List<LabelValue> getAutocompleteOptions(Long stepId, Long itemId, String term, jakarta.servlet.http.HttpServletRequest request) Return matching configured options for an autocomplete form item.- Parameters:
stepId- current form stepitemId- autocomplete form itemterm- text entered by the user; at least two characters are requiredrequest- current form request- Returns:
- matching label/value options
-
getAvailableConditionFields
Build available source fields for condition builder up to the current step.- Parameters:
formName- logical form namestepId- current step idprop- localization provider- Returns:
- sorted condition field options grouped by step labels
-
prepareConditionFieldOptions
public final List<LabelValue> prepareConditionFieldOptions(List<FormItemEntity> fields, String formName, Prop prop) Build condition field options from arbitrary field collection.- Parameters:
fields- fields to transform into optionsformName- logical form name used to resolve step labels/positionsprop- localization provider- Returns:
- sorted options in format
(Step X) Field Name
-
getFormStepsOptions
Build human-readable options for steps of a form suitable for selection inputs.- Parameters:
formName- logical form name- Returns:
- list of label/value pairs ordered by step sorting
-
getValidItemFormId
Generate a valid and uniqueitemFormIdfor a form item within a form.For
radiofields, derives id from label/placeholder and required flag, allowing multiple radio buttons to share the same logical id. For other fields, generates a unique suffix (numeric) to avoid collisions within the form and domain.- Parameters:
entity- form item to generate id for- Returns:
- unique itemFormId string safe for storage and queries
-
updateFormPattern
Update or create the pattern entity (form definition) for the form by concatenating all uniqueitemFormIds in validation order. Multi-upload fields append the-fileNamespostfix.- Parameters:
formName- logical form name
-
saveFormStep
public final void saveFormStep(String formName, Long stepId, jakarta.servlet.http.HttpServletRequest request, org.json.JSONObject response) throws SaveFormException, IOException Validate and persist a single step of a multistep form into session, and optionally finalize the form submission. Performs CSRF/CAPTCHA/file validations and invokes custom processors. When the last step is completed, triggers final save into DB.- Parameters:
formName- logical form namestepId- current step identifierrequest- HTTP request containing JSON body of field valuesresponse- JSON response to be enriched with errors, next step or forward- Throws:
SaveFormException- when validation or processing fails in a controlled wayIOException- when reading request body fails
-
getFormItemsForValidation
Fetch distinct minimal form item definitions required for validation for the form.- Parameters:
formName- logical form name- Returns:
- list of simplified
FormItemEntitycontaining id, label, type, regex, required
-
updateStepsPositions
Refresh step positions after row reorder operation payload.- Parameters:
rowReorderDto- datatable row reorder payload
-
updateStepsPositions
Recompute current and max positions for all steps in a form.- Parameters:
formName- logical form name
-
getFormCounter
Retrieve the form instance counter for the current request.When multiple instances of the same form appear on a single page, each gets a unique counter value (1, 2, 3, ...) stored in session during
MultistepFormApp.view(org.springframework.ui.Model, jakarta.servlet.http.HttpServletRequest).- Parameters:
formName- logical form namerequest- HTTP request with session containing the counter- Returns:
- form instance counter (1-based), defaults to 1 when not set or invalid
-
updateFormValues
public static final StringBuilder updateFormValues(String formName, jakarta.servlet.http.HttpServletRequest request, StringBuilder formHtml)
-