Class FormsService<R extends FormsRepositoryInterface<E>,E extends FormsEntityBasic>

java.lang.Object
sk.iway.iwcm.components.forms.FormsService<R,E>
Type Parameters:
R - repository type used to access form entities
E - form entity type handled by the repository
Direct Known Subclasses:
FormsArchiveServiceImpl, FormsServiceImpl

public class FormsService<R extends FormsRepositoryInterface<E>,E extends FormsEntityBasic> extends Object
Provides form administration, submission searching, access control, export, and rendering operations. The service supports repository implementations for both form definitions and submitted records while consistently restricting data to the current domain and the pages editable by the current user.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Identifies the supported form layouts and their persisted values.
  • Constructor Summary

    Constructors
    Constructor
    Description
    FormsService(R formsRepository, FormSettingsRepository formSettingsRepository, FormStepsRepository formStepsRepository, FormItemsRepository formItemsRepository)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    deleteItem(E entity, long id, FormStepsRepository formStepsRepository, FormItemsRepository formItemsRepository, FormSettingsRepository formSettingsRepository)
    Deletes one submission or all records and structure belonging to a form definition.
    downloadAttachment(String name, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
    Authorizes and streams a stored form attachment to the HTTP response.
    org.springframework.data.domain.Page<E>
    findByColumns(Map<String,String> params, org.springframework.data.domain.Pageable pageable, E search, jakarta.servlet.http.HttpServletRequest request, Identity user)
    Searches submissions of the form selected by the request using DataTable filter parameters.
    org.springframework.data.domain.Page<E>
    findInDataByColumns(String formName, UserDetails user, Map<String,String> params, org.springframework.data.domain.Pageable pageable)
    Searches submitted form records using server-side DataTable filters.
    org.springframework.data.domain.Page<E>
    getAllItems(org.springframework.data.domain.Page<E> page, org.springframework.data.domain.Pageable pageable, jakarta.servlet.http.HttpServletRequest request, Identity user)
    Returns either form definitions or submissions of the form selected by the request.
    getById(long id)
    Finds a form record by identifier in the current domain.
    getColumnNames(String formName, UserDetails user, Prop prop)
    Resolves submission columns and display labels for a form.
    static Map<String,String>
    getFieldReplacementMap(org.json.JSONObject item, String id, String label, String labelSanitized, String value, String placeholder, String classes, String tooltip)
    Creates the placeholder map shared by form field and tooltip templates.
    getFormName(jakarta.servlet.http.HttpServletRequest request)
    Resolves the selected form name when the request displays form submission details.
    Returns distinct form definitions that the user is allowed to manage.
    protected org.springframework.data.jpa.domain.Specification<E>
    getSearchConditions(String formName, Integer domainId, Map<String,String> params)
    Builds database predicates for form identity, domain, submission state, and supported column filters.
    boolean
    isExport(jakarta.servlet.http.HttpServletRequest request)
     
    boolean
    Checks whether the user can manage a form through its associated page or directory.
    boolean
     
    protected Pair<Date,Date>
    parseDate(String dateRange)
    Parses a daterange:from-to value into optional lower and upper date bounds.
    static String[]
    Resolves configured options, including options backed by an enumeration.
    void
    prepareForm(E entity, int domainId)
    Enriches a form definition with its submission count and latest submission metadata.
    static final String
    replaceFields(String html, String formName, String recipients, org.json.JSONObject item, String requiredLabelAdd, boolean isEmailRender, boolean rowView, Set<String> firstTimeHeadingSet, Prop prop, jakarta.servlet.http.HttpServletRequest request)
    Renders a form field template by replacing form, item, label, value, validation, and iterable placeholders.
    static String
    Replaces form placeholders in one pass without interpreting placeholders contained in replacement values.
    void
    Sets the last-export date of the supplied form records using batched repository updates.
    void
    updateNote(String note, long id)
    Updates the note of an existing form record.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • getFormName

      public String getFormName(jakarta.servlet.http.HttpServletRequest request)
      Resolves the selected form name when the request displays form submission details.
      Parameters:
      request - request containing the detail flag and form name
      Returns:
      selected form name, or null when detail mode is disabled
    • isExport

      public boolean isExport(jakarta.servlet.http.HttpServletRequest request)
    • getAllItems

      public org.springframework.data.domain.Page<E> getAllItems(org.springframework.data.domain.Page<E> page, org.springframework.data.domain.Pageable pageable, jakarta.servlet.http.HttpServletRequest request, Identity user)
      Returns either form definitions or submissions of the form selected by the request. Submission exports also update the last-export date of the returned records.
      Parameters:
      page - page supplied by the DataTable request pipeline
      pageable - requested pagination and sorting
      request - request that selects detail and export modes
      user - user whose editable pages determine form access
      Returns:
      page of form definitions or submissions, or null when access is denied
    • findByColumns

      public org.springframework.data.domain.Page<E> findByColumns(Map<String,String> params, org.springframework.data.domain.Pageable pageable, E search, jakarta.servlet.http.HttpServletRequest request, Identity user)
      Searches submissions of the form selected by the request using DataTable filter parameters. Request parameters are merged into the supplied parameter map before the repository query is built.
      Parameters:
      params - mutable map that receives request parameters used for filtering
      pageable - requested pagination and sorting
      search - search entity supplied by the DataTable pipeline
      request - request that selects the form and export mode
      user - user whose editable pages determine form access
      Returns:
      matching submissions, or null when no form is selected or access is denied
    • prepareForm

      public void prepareForm(E entity, int domainId)
      Enriches a form definition with its submission count and latest submission metadata.
      Parameters:
      entity - form definition to enrich
      domainId - domain containing the form and its submissions
    • getFormsList

      public List<E> getFormsList(UserDetails user)
      Returns distinct form definitions that the user is allowed to manage.
      Parameters:
      user - user whose editable pages and groups determine form access
      Returns:
      accessible form definitions in the current domain
    • isFormAccessible

      public boolean isFormAccessible(String formName, UserDetails user)
      Checks whether the user can manage a form through its associated page or directory.
      Parameters:
      formName - name of the form to check in the current domain
      user - user whose editable pages and groups are evaluated
      Returns:
      true when the form is accessible to the user
    • getColumnNames

      public FormColumns getColumnNames(String formName, UserDetails user, Prop prop)
      Resolves submission columns and display labels for a form. Multistep form fields are labeled from their item definitions and associated steps. The result also includes the submission count, form type, and double opt-in state when available.
      Parameters:
      formName - name of the form in the current domain
      user - user whose access to the form is verified
      prop - localization provider used to build field and step labels
      Returns:
      form column metadata, or null when access is denied
    • findInDataByColumns

      public org.springframework.data.domain.Page<E> findInDataByColumns(String formName, UserDetails user, Map<String,String> params, org.springframework.data.domain.Pageable pageable)
      Searches submitted form records using server-side DataTable filters.
      Parameters:
      formName - name of the form in the current domain
      user - user whose access to the form is verified
      params - filter parameters from the DataTable request
      pageable - requested pagination and sorting
      Returns:
      matching submitted records, or null when access is denied
    • getSearchConditions

      protected org.springframework.data.jpa.domain.Specification<E> getSearchConditions(String formName, Integer domainId, Map<String,String> params)
      Builds database predicates for form identity, domain, submission state, and supported column filters.
      Parameters:
      formName - name of the form whose submissions are searched
      domainId - domain containing the form submissions
      params - DataTable search parameters to convert into predicates
      Returns:
      specification representing the supported search conditions
    • parseDate

      protected Pair<Date,Date> parseDate(String dateRange)
      Parses a daterange:from-to value into optional lower and upper date bounds.
      Parameters:
      dateRange - serialized date range; either bound may be omitted
      Returns:
      parsed date bounds with null for an omitted bound, or null for an empty value
    • getById

      public E getById(long id)
      Finds a form record by identifier in the current domain.
      Parameters:
      id - database identifier of the form record
      Returns:
      matching form record, or null when no record exists in the current domain
    • updateNote

      public void updateNote(String note, long id)
      Updates the note of an existing form record.
      Parameters:
      note - note to store
      id - database identifier of the form record
    • setExportDate

      public void setExportDate(List<E> forms)
      Sets the last-export date of the supplied form records using batched repository updates.
      Parameters:
      forms - form records marked as exported
    • deleteItem

      public boolean deleteItem(E entity, long id, FormStepsRepository formStepsRepository, FormItemsRepository formItemsRepository, FormSettingsRepository formSettingsRepository)
      Deletes one submission or all records and structure belonging to a form definition. Deleting a management record, identified by a missing creation date, removes all submissions, steps, and items with the same form name. Form settings are intentionally preserved.
      Parameters:
      entity - entity carrying the form name to delete
      id - database identifier of the record initiating the deletion
      formStepsRepository - repository used to remove multistep form steps
      formItemsRepository - repository used to remove multistep form items
      formSettingsRepository - settings repository retained for deletion workflow compatibility
      Returns:
      true when deletion succeeds; false for another domain or on failure
    • downloadAttachment

      public String downloadAttachment(String name, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws IOException
      Authorizes and streams a stored form attachment to the HTTP response. Access requires an authenticated administrator with form permissions and, when the owning form can be resolved, edit access to that form. Invalid sessions or permissions return a login redirect.
      Parameters:
      name - stored attachment name, optionally prefixed by its form record ID
      request - current HTTP request used for authentication and access checks
      response - response receiving attachment headers and file content
      Returns:
      login redirect for an unauthorized request, otherwise null
      Throws:
      IOException - if the response stream cannot be opened or written
    • getFieldReplacementMap

      public static Map<String,String> getFieldReplacementMap(org.json.JSONObject item, String id, String label, String labelSanitized, String value, String placeholder, String classes, String tooltip)
      Creates the placeholder map shared by form field and tooltip templates.
      Parameters:
      item - form item metadata
      id - rendered field identifier
      label - label rendered by the target template
      labelSanitized - label without HTML markup
      value - field value
      placeholder - field placeholder
      classes - CSS classes added to the field
      tooltip - rendered tooltip HTML
      Returns:
      mutable placeholder map
    • replaceFields

      public static String replaceFields(String html, Map<String,String> fields)
      Replaces form placeholders in one pass without interpreting placeholders contained in replacement values.
      Parameters:
      html - template containing placeholders in the ${name} format
      fields - placeholder values
      Returns:
      template with known placeholders replaced
    • replaceFields

      public static final String replaceFields(String html, String formName, String recipients, org.json.JSONObject item, String requiredLabelAdd, boolean isEmailRender, boolean rowView, Set<String> firstTimeHeadingSet, Prop prop, jakarta.servlet.http.HttpServletRequest request)
      Renders a form field template by replacing form, item, label, value, validation, and iterable placeholders. Selected item metadata is filtered before being inserted into HTML, optional first-use headings are applied, and user-specific expressions are resolved in the completed fragment.
      Parameters:
      html - HTML template containing supported placeholders
      formName - form name inserted into form-related placeholders
      recipients - recipient value inserted into the template
      item - form item metadata, or null for a template without item placeholders
      requiredLabelAdd - marker appended to required labels and placeholders
      isEmailRender - whether the fragment is rendered for email rather than an interactive form
      rowView - whether non-closing fragments are wrapped in a row column
      firstTimeHeadingSet - mutable set used to prevent repeated first-use headings
      prop - localization provider for tooltip, iterable, and heading templates
      request - request used to resolve user-specific expressions
      Returns:
      rendered HTML fragment
    • parseIterableValues

      public static String[] parseIterableValues(String value)
      Resolves configured options, including options backed by an enumeration.
      Parameters:
      value - serialized options
      Returns:
      resolved option tokens, or an empty array for an empty or invalid enumeration configuration
    • isFormNameUnique

      public boolean isFormNameUnique(String formName)