Package sk.iway.iwcm.components.forms
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 entitiesE- 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 ClassesModifier and TypeClassDescriptionstatic enumIdentifies the supported form layouts and their persisted values. -
Constructor Summary
ConstructorsConstructorDescriptionFormsService(R formsRepository, FormSettingsRepository formSettingsRepository, FormStepsRepository formStepsRepository, FormItemsRepository formItemsRepository) -
Method Summary
Modifier and TypeMethodDescriptionbooleandeleteItem(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.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.getFormsList(UserDetails user) Returns distinct form definitions that the user is allowed to manage.protected org.springframework.data.jpa.domain.Specification<E>Builds database predicates for form identity, domain, submission state, and supported column filters.booleanisExport(jakarta.servlet.http.HttpServletRequest request) booleanisFormAccessible(String formName, UserDetails user) Checks whether the user can manage a form through its associated page or directory.booleanisFormNameUnique(String formName) Parses adaterange:from-tovalue into optional lower and upper date bounds.static String[]parseIterableValues(String value) Resolves configured options, including options backed by an enumeration.voidprepareForm(E entity, int domainId) Enriches a form definition with its submission count and latest submission metadata.static final StringreplaceFields(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 StringreplaceFields(String html, Map<String, String> fields) Replaces form placeholders in one pass without interpreting placeholders contained in replacement values.voidsetExportDate(List<E> forms) Sets the last-export date of the supplied form records using batched repository updates.voidupdateNote(String note, long id) Updates the note of an existing form record.
-
Constructor Details
-
FormsService
public FormsService(R formsRepository, FormSettingsRepository formSettingsRepository, FormStepsRepository formStepsRepository, FormItemsRepository formItemsRepository)
-
-
Method Details
-
getFormName
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
nullwhen 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 pipelinepageable- requested pagination and sortingrequest- request that selects detail and export modesuser- user whose editable pages determine form access- Returns:
- page of form definitions or submissions, or
nullwhen 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 filteringpageable- requested pagination and sortingsearch- search entity supplied by the DataTable pipelinerequest- request that selects the form and export modeuser- user whose editable pages determine form access- Returns:
- matching submissions, or
nullwhen no form is selected or access is denied
-
prepareForm
Enriches a form definition with its submission count and latest submission metadata.- Parameters:
entity- form definition to enrichdomainId- domain containing the form and its submissions
-
getFormsList
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
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 domainuser- user whose editable pages and groups are evaluated- Returns:
truewhen the form is accessible to the user
-
getColumnNames
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 domainuser- user whose access to the form is verifiedprop- localization provider used to build field and step labels- Returns:
- form column metadata, or
nullwhen 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 domainuser- user whose access to the form is verifiedparams- filter parameters from the DataTable requestpageable- requested pagination and sorting- Returns:
- matching submitted records, or
nullwhen 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 searcheddomainId- domain containing the form submissionsparams- DataTable search parameters to convert into predicates- Returns:
- specification representing the supported search conditions
-
parseDate
Parses adaterange:from-tovalue into optional lower and upper date bounds.- Parameters:
dateRange- serialized date range; either bound may be omitted- Returns:
- parsed date bounds with
nullfor an omitted bound, ornullfor an empty value
-
getById
Finds a form record by identifier in the current domain.- Parameters:
id- database identifier of the form record- Returns:
- matching form record, or
nullwhen no record exists in the current domain
-
updateNote
Updates the note of an existing form record.- Parameters:
note- note to storeid- database identifier of the form record
-
setExportDate
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 deleteid- database identifier of the record initiating the deletionformStepsRepository- repository used to remove multistep form stepsformItemsRepository- repository used to remove multistep form itemsformSettingsRepository- settings repository retained for deletion workflow compatibility- Returns:
truewhen deletion succeeds;falsefor 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 IDrequest- current HTTP request used for authentication and access checksresponse- 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 metadataid- rendered field identifierlabel- label rendered by the target templatelabelSanitized- label without HTML markupvalue- field valueplaceholder- field placeholderclasses- CSS classes added to the fieldtooltip- rendered tooltip HTML- Returns:
- mutable placeholder map
-
replaceFields
Replaces form placeholders in one pass without interpreting placeholders contained in replacement values.- Parameters:
html- template containing placeholders in the${name}formatfields- 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 placeholdersformName- form name inserted into form-related placeholdersrecipients- recipient value inserted into the templateitem- form item metadata, ornullfor a template without item placeholdersrequiredLabelAdd- marker appended to required labels and placeholdersisEmailRender- whether the fragment is rendered for email rather than an interactive formrowView- whether non-closing fragments are wrapped in a row columnfirstTimeHeadingSet- mutable set used to prevent repeated first-use headingsprop- localization provider for tooltip, iterable, and heading templatesrequest- request used to resolve user-specific expressions- Returns:
- rendered HTML fragment
-
parseIterableValues
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
-