Class MultistepFormsService
java.lang.Object
sk.iway.iwcm.components.multistep_form.rest.MultistepFormsService
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMultistepFormsService(SaveFormService saveFormService, FormsRepository formsRepository, FormItemsRepository formItemsRepository, FormStepsRepository formStepsRepository, FormSettingsRepository formSettingsRepository) -
Method Summary
Modifier and TypeMethodDescriptionstatic final StringgetFieldName(FormItemEntity stepItem, Prop prop) static final List<LabelValue>getFieldTypes(javax.servlet.http.HttpServletRequest request) Provide supported form field types as label/value pairs.static final List<LabelValue>getFiledTypeVisibility(javax.servlet.http.HttpServletRequest request) Provide visibility configuration per field type (which technical fields are hidden).getFormDataAsMap(FormsEntity form) static List<FormItemEntity>getFormItemsForValidation(String formName) Fetch distinct minimal form item definitions required for validation for the form.static final StringgetFormName(Map<String, String> params) Extract and sanitize theformNamefrom a params map.static final StringgetFormName(javax.servlet.http.HttpServletRequest request) Extract and sanitize theformNamefrom the request.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, javax.servlet.http.HttpServletRequest request) Provide available regular expression validations as label/value pairs for UI.static final StringgetSessionKey(String formName, javax.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.final voidsaveFormStep(String formName, Long stepId, javax.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.voidupdateStepsPositions(String formName) voidupdateStepsPositions(RowReorderDto rowReorderDto) final booleanvalidateFormInfo(String formName, Long currentStepId, javax.servlet.http.HttpServletRequest request)
-
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:
-
-
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, javax.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, javax.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
Provide supported form field types as label/value pairs.- Parameters:
request- request used to resolve localized labels- Returns:
- list of field type options
-
getFiledTypeVisibility
public static final List<LabelValue> getFiledTypeVisibility(javax.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
-
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 namecurrentStepId- identifier of current steprepo- 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
-
getFormDataAsMap
-
getFieldName
-
validateFormInfo
-
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 among the same field type.- 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, javax.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
-
updateStepsPositions
-