Class MultistepFormsService

java.lang.Object
sk.iway.iwcm.components.multistep_form.rest.MultistepFormsService

@Service public class MultistepFormsService extends Object
  • Field Details

    • SESSION_PREFIX

      public static final String 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

      public static final String MULTIUPLOAD_PREFIX
      See Also:
  • Constructor Details

  • 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

      public static final String getNewSessionKey(String formName, String csrf)
      Build a new session key for the given form and CSRF token.
      Parameters:
      formName - logical form name
      csrf - CSRF token value
      Returns:
      session key string
    • getFormName

      public static final String getFormName(Map<String,String> params)
      Extract and sanitize the formName from a params map.
      Parameters:
      params - map potentially containing key formName
      Returns:
      sanitized form name (safe for identifiers)
    • getFormName

      public static final String getFormName(javax.servlet.http.HttpServletRequest request)
      Extract and sanitize the formName from the request.
      Parameters:
      request - HTTP request containing parameter formName
      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 definitions
      request - request used to resolve localized titles
      Returns:
      list of label/value options
    • getFieldTypes

      public static final List<LabelValue> getFieldTypes(javax.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
    • 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 option allwaysHidden.
      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 name
      currentStepId - identifier of current step
      repo - repository used to fetch ordered steps
      Returns:
      next step entity or null if current step is the last
      Throws:
      IllegalStateException - when the provided step does not belong to the form/domain
    • getRowViewItemTypes

      public static final List<String> getRowViewItemTypes()
    • getFormDataAsMap

      public static final Map<String,String> getFormDataAsMap(FormsEntity form)
    • getFieldName

      public static final String getFieldName(FormItemEntity stepItem, Prop prop)
    • validateFormInfo

      public final boolean validateFormInfo(String formName, Long currentStepId, javax.servlet.http.HttpServletRequest request)
    • getFormStepsOptions

      public final List<LabelValue> getFormStepsOptions(String formName, Prop prop)
      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

      public final String getValidItemFormId(FormItemEntity entity)
      Generate a valid and unique itemFormId for a form item within a form.

      For radio fields, 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

      public final void updateFormPattern(String formName)
      Update or create the pattern entity (form definition) for the form by concatenating all unique itemFormIds in validation order. Multi-upload fields append the -fileNames postfix.
      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 name
      stepId - current step identifier
      request - HTTP request containing JSON body of field values
      response - JSON response to be enriched with errors, next step or forward
      Throws:
      SaveFormException - when validation or processing fails in a controlled way
      IOException - when reading request body fails
    • getFormItemsForValidation

      public static List<FormItemEntity> getFormItemsForValidation(String formName)
      Fetch distinct minimal form item definitions required for validation for the form.
      Parameters:
      formName - logical form name
      Returns:
      list of simplified FormItemEntity containing id, label, type, regex, required
    • updateStepsPositions

      public void updateStepsPositions(RowReorderDto rowReorderDto)
    • updateStepsPositions

      public void updateStepsPositions(String formName)