Class ProcessFormHelper
java.lang.Object
org.ametys.runtime.plugin.component.AbstractLogEnabled
org.ametys.plugins.forms.content.processing.ProcessFormHelper
- All Implemented Interfaces:
LogEnabled,Component,Contextualizable,Serviceable
public class ProcessFormHelper
extends AbstractLogEnabled
implements Component, Serviceable, Contextualizable
Helper that processes the user submitted data on a form.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classClass representing form informations -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AmetysObjectResolverThe ametys object resolverprotected ContextThe contextprotected CurrentUserProvidercurrent user providerprotected static final DateFormatThe date format pattern.protected static final PatternThe integer validation pattern.protected static final DateFormatThe date and time format pattern.protected static final PatternThe integer validation pattern.protected static final PatternThe email validation pattern.protected static final PatternThe integer validation pattern.protected FormPropertiesManagerForm properties manager.protected FormTableManagerForm table manager.protected I18nUtilsThe i18n utilsprotected static final PatternThe integer validation pattern.protected static final PatternThe phone validation pattern.protected StringThe plugin name.protected URIPrefixHandlerThe URI prefix handlerprotected RightManagerRights managerprotected SiteManagerThe site manager.protected SourceResolverThe source resolver.protected SQLDatabaseTypeExtensionPointThe SQLDatabaseTypeExtensionPoint instanceprotected static final DateFormatThe time format pattern.protected static final PatternThe integer validation pattern.protected UserLanguagesManagerThe user languages managerprotected WorkflowHelperThe workflow helper componentprotected WorkflowProviderThe workflow providerprotected static final StringThe content ID parameter.static final StringThe form ID parameter.static final StringThe Avalon role -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Collection<FieldValue> _getEntriesToInsert(Collection<FieldValue> entries) Retain only the entries that are to be inserted in the database.protected FieldValue_getFileEntry(Request request, Field field, String id, String name, FormErrors errors) Get a file entry from the request.protected Collection<File> _getFiles(Map<String, FieldValue> input) Get the files of a user input.protected String_getFormRedirection(Form form, String entryId) Get the form redirectionprotected Map<String, FieldValue> _getInput(Form form, Request request, FormErrors errors) Get the user input.protected StringGet a mail pipeline's content.protected String_insertInput(Form form, Map<String, FieldValue> input, Map objectModel) Insert the user submission in the database.protected void_sendEmails(Form form, Map<String, FieldValue> input, Site site, Integer totalSubmissions) Send the receipt and notification emails.protected void_sendLimitEmail(Form form, Map<String, FieldValue> input, String sender, Site site, String language) Send the limit email.protected void_sendNotificationEmails(Form form, Map<String, FieldValue> input, String sender, Site site, String language) Send the notification emails.protected void_sendReceiptEmail(Form form, Map<String, FieldValue> input, String sender, String language) Send the receipt email.protected void_setParameters(Form form, Map<String, FieldValue> input, PreparedStatement stmt, String dbType) Set the parameters into the prepared statement.protected List<I18nizableText> _validateCaptcha(FieldValue entry, Request request) Validate a captcha.protected List<I18nizableText> _validateCheckbox(FieldValue entry, Request request) Validate a checkbox input.protected List<I18nizableText> _validateConfirmation(FieldValue entry, Request request, String keyPrefix) Validate a confirmation.protected List<I18nizableText> _validateFile(FieldValue entry, Request request) Validate a file input.protected void_validateInput(Form form, Map<String, FieldValue> input, FormErrors errors, Request request) Validate the user input.protected List<I18nizableText> _validateMandatory(FieldValue entry, String keyPrefix) Validate a mandatory field.protected List<I18nizableText> _validatePassword(FieldValue entry, Request request) Validate a password field.protected List<I18nizableText> _validateRadio(FieldValue entry, Request request) Validate a radio input.protected List<I18nizableText> _validateSelect(FieldValue entry, Request request) Validate a select input.protected List<I18nizableText> _validateTextarea(FieldValue entry, Request request) Validate a textarea.protected List<I18nizableText> _validateTextField(FieldValue entry, Request request) Validate a text field.voidcontextualize(Context context) processForm(Form form, Site site, String pluginName) Process formvoidservice(ServiceManager serviceManager) Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
Field Details
-
ROLE
The Avalon role -
PARAM_FORM_ID
The form ID parameter.- See Also:
-
PARAM_CONTENT_ID
The content ID parameter.- See Also:
-
_INT_PATTERN
The integer validation pattern. -
_FLOAT_PATTERN
The integer validation pattern. -
_DATE_PATTERN
The integer validation pattern. -
_TIME_PATTERN
The integer validation pattern. -
_DATETIME_PATTERN
The integer validation pattern. -
_EMAIL_PATTERN
The email validation pattern. -
_PHONE_PATTERN
The phone validation pattern. -
_DATE_FORMAT
The date format pattern. -
_TIME_FORMAT
The time format pattern. -
_DATETIME_FORMAT
The date and time format pattern. -
_formPropertiesManager
Form properties manager. -
_formTableManager
Form table manager. -
_sourceResolver
The source resolver. -
_ametysObjectResolver
The ametys object resolver -
_siteManager
The site manager. -
_pluginName
The plugin name. -
_prefixHandler
The URI prefix handler -
_workflowProvider
The workflow provider -
_workflowHelper
The workflow helper component -
_sqlDatabaseTypeExtensionPoint
The SQLDatabaseTypeExtensionPoint instance -
_context
The context -
_rightManager
Rights manager -
_currentUserProvied
current user provider -
_i18nUtils
The i18n utils -
_userLanguagesManager
The user languages manager
-
-
Constructor Details
-
ProcessFormHelper
public ProcessFormHelper()
-
-
Method Details
-
contextualize
- Specified by:
contextualizein interfaceContextualizable- Throws:
ContextException
-
service
- Specified by:
servicein interfaceServiceable- Throws:
ServiceException
-
processForm
public ProcessFormHelper.FormInformations processForm(Form form, Site site, String pluginName) throws Exception Process form- Parameters:
form- the formsite- the sitepluginName- the plugin name- Returns:
- the form informations
- Throws:
Exception- if an error occurred
-
_getFormRedirection
Get the form redirection- Parameters:
form- the formentryId- the entryId- Returns:
- the form redirection url
-
_getInput
Get the user input.- Parameters:
form- the Form object.request- the user request.errors- the input errors.- Returns:
- the user data as a Map of column name -> column entry.
-
_getFileEntry
protected FieldValue _getFileEntry(Request request, Field field, String id, String name, FormErrors errors) Get a file entry from the request.- Parameters:
request- the user request.field- the field.id- the entry ID.name- the field name.errors- the form errors.- Returns:
- the file entry.
-
_insertInput
protected String _insertInput(Form form, Map<String, FieldValue> input, Map objectModel) throws com.opensymphony.workflow.WorkflowException, InvalidModificationExceptionInsert the user submission in the database.- Parameters:
form- the Form object.input- the user input.objectModel- The object model- Returns:
- the entry id if the insertion has succeed, null in case of error
- Throws:
com.opensymphony.workflow.WorkflowException- if an exception occurs while initializing a workflow instance for a form entryInvalidModificationException- If an error occurs
-
_setParameters
protected void _setParameters(Form form, Map<String, FieldValue> input, PreparedStatement stmt, String dbType) throws SQLException, com.opensymphony.workflow.WorkflowExceptionSet the parameters into the prepared statement.- Parameters:
form- the form.input- the user input.stmt- the prepared statement.dbType- the database type.- Throws:
SQLException- if a SQL error occurs.com.opensymphony.workflow.WorkflowException- if an exception occurs while initializing a workflow instance for a form entry
-
_validateInput
protected void _validateInput(Form form, Map<String, FieldValue> input, FormErrors errors, Request request) Validate the user input.- Parameters:
form- the Form object.input- the user input.errors- the FormErrors object to fill.request- the user request.
-
_validateTextField
Validate a text field.- Parameters:
entry- the text field entry.request- the user request.- Returns:
- the list of error messages.
-
_validatePassword
Validate a password field.- Parameters:
entry- the password field entry.request- the user request.- Returns:
- the list of error messages.
-
_validateSelect
Validate a select input.- Parameters:
entry- the select input entry.request- the user request.- Returns:
- the list of error messages.
-
_validateTextarea
Validate a textarea.- Parameters:
entry- the textarea entry.request- the user request.- Returns:
- the list of error messages.
-
_validateRadio
Validate a radio input.- Parameters:
entry- the radio input entry.request- the user request.- Returns:
- the list of error messages.
-
_validateCheckbox
Validate a checkbox input.- Parameters:
entry- the checkbox entry.request- the user request.- Returns:
- the list of error messages.
-
_validateFile
Validate a file input.- Parameters:
entry- the file input entry.request- the user request.- Returns:
- the list of error messages.
-
_validateCaptcha
Validate a captcha.- Parameters:
entry- the captcha entry.request- the user request.- Returns:
- the list of error messages.
-
_validateMandatory
Validate a mandatory field.- Parameters:
entry- the field valuekeyPrefix- the key profix- Returns:
- the list of error messages.
-
_validateConfirmation
protected List<I18nizableText> _validateConfirmation(FieldValue entry, Request request, String keyPrefix) Validate a confirmation.- Parameters:
entry- the field valuerequest- the requestkeyPrefix- the key prefix- Returns:
- the list of error messages.
-
_getEntriesToInsert
Retain only the entries that are to be inserted in the database.- Parameters:
entries- the entries to filter.- Returns:
- the entries to insert in the database.
-
_sendEmails
protected void _sendEmails(Form form, Map<String, FieldValue> input, Site site, Integer totalSubmissions) Send the receipt and notification emails.- Parameters:
form- the Form object.input- the user input.site- the site.totalSubmissions- total number of submissions. Can be null if the form don't have limits.
-
_sendNotificationEmails
protected void _sendNotificationEmails(Form form, Map<String, FieldValue> input, String sender, Site site, String language) Send the notification emails.- Parameters:
form- the form.input- the user input.sender- the sender e-mail.site- the sitelanguage- The language to use in the mail
-
_sendReceiptEmail
protected void _sendReceiptEmail(Form form, Map<String, FieldValue> input, String sender, String language) Send the receipt email.- Parameters:
form- the form.input- the user input.sender- the sender e-mail.language- the language to use in the mail.
-
_sendLimitEmail
protected void _sendLimitEmail(Form form, Map<String, FieldValue> input, String sender, Site site, String language) Send the limit email.- Parameters:
form- the form.input- the user input.sender- the sender e-mail.site- the sitelanguage- the language to use in the mail
-
_getMail
protected String _getMail(String resource, Form form, Map<String, FieldValue> input) throws IOExceptionGet a mail pipeline's content.- Parameters:
resource- the mail resource pipeline (i.e. "results.html" or "receipt.txt").form- the Form.input- the user input.- Returns:
- the mail content.
- Throws:
IOException- if an error occurs.
-
_getFiles
Get the files of a user input.- Parameters:
input- the user input.- Returns:
- the files submitted by the user.
-