Class ProcessFormHelper
- java.lang.Object
-
- org.ametys.runtime.plugin.component.AbstractLogEnabled
-
- org.ametys.plugins.forms.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 Classes Modifier and Type Class Description static class
ProcessFormHelper.FormInformations
Class representing form informations
-
Field Summary
Fields Modifier and Type Field Description protected AmetysObjectResolver
_ametysObjectResolver
The ametys object resolverprotected Context
_context
The contextprotected CurrentUserProvider
_currentUserProvied
current user providerprotected static DateFormat
_DATE_FORMAT
The date format pattern.protected static Pattern
_DATE_PATTERN
The integer validation pattern.protected static DateFormat
_DATETIME_FORMAT
The date and time format pattern.protected static Pattern
_DATETIME_PATTERN
The integer validation pattern.protected static Pattern
_EMAIL_PATTERN
The email validation pattern.protected static Pattern
_FLOAT_PATTERN
The integer validation pattern.protected FormPropertiesManager
_formPropertiesManager
Form properties manager.protected FormTableManager
_formTableManager
Form table manager.protected static Pattern
_INT_PATTERN
The integer validation pattern.protected static Pattern
_PHONE_PATTERN
The phone validation pattern.protected String
_pluginName
The plugin name.protected URIPrefixHandler
_prefixHandler
The URI prefix handlerprotected RightManager
_rightManager
Rights managerprotected SiteManager
_siteManager
The site manager.protected SourceResolver
_sourceResolver
The source resolver.protected SQLDatabaseTypeExtensionPoint
_sqlDatabaseTypeExtensionPoint
The SQLDatabaseTypeExtensionPoint instanceprotected static DateFormat
_TIME_FORMAT
The time format pattern.protected static Pattern
_TIME_PATTERN
The integer validation pattern.protected WorkflowHelper
_workflowHelper
The workflow helper componentprotected WorkflowProvider
_workflowProvider
The workflow providerprotected static String
PARAM_CONTENT_ID
The content ID parameter.static String
PARAM_FORM_ID
The form ID parameter.static String
ROLE
The Avalon role
-
Constructor Summary
Constructors Constructor Description ProcessFormHelper()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected 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 String
_getMail(String resource, Form form, Map<String,FieldValue> input)
Get 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)
Send the limit email.protected void
_sendNotificationEmails(Form form, Map<String,FieldValue> input, String sender)
Send the notification emails.protected void
_sendReceiptEmail(Form form, Map<String,FieldValue> input, String sender)
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.void
contextualize(Context context)
ProcessFormHelper.FormInformations
processForm(Form form, Site site, String pluginName)
Process formvoid
service(ServiceManager serviceManager)
-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
-
-
-
Field Detail
-
PARAM_FORM_ID
public static final String PARAM_FORM_ID
The form ID parameter.- See Also:
- Constant Field Values
-
PARAM_CONTENT_ID
protected static final String PARAM_CONTENT_ID
The content ID parameter.- See Also:
- Constant Field Values
-
_INT_PATTERN
protected static final Pattern _INT_PATTERN
The integer validation pattern.
-
_FLOAT_PATTERN
protected static final Pattern _FLOAT_PATTERN
The integer validation pattern.
-
_DATE_PATTERN
protected static final Pattern _DATE_PATTERN
The integer validation pattern.
-
_TIME_PATTERN
protected static final Pattern _TIME_PATTERN
The integer validation pattern.
-
_DATETIME_PATTERN
protected static final Pattern _DATETIME_PATTERN
The integer validation pattern.
-
_EMAIL_PATTERN
protected static final Pattern _EMAIL_PATTERN
The email validation pattern.
-
_PHONE_PATTERN
protected static final Pattern _PHONE_PATTERN
The phone validation pattern.
-
_DATE_FORMAT
protected static final DateFormat _DATE_FORMAT
The date format pattern.
-
_TIME_FORMAT
protected static final DateFormat _TIME_FORMAT
The time format pattern.
-
_DATETIME_FORMAT
protected static final DateFormat _DATETIME_FORMAT
The date and time format pattern.
-
_formPropertiesManager
protected FormPropertiesManager _formPropertiesManager
Form properties manager.
-
_formTableManager
protected FormTableManager _formTableManager
Form table manager.
-
_sourceResolver
protected SourceResolver _sourceResolver
The source resolver.
-
_ametysObjectResolver
protected AmetysObjectResolver _ametysObjectResolver
The ametys object resolver
-
_siteManager
protected SiteManager _siteManager
The site manager.
-
_pluginName
protected String _pluginName
The plugin name.
-
_prefixHandler
protected URIPrefixHandler _prefixHandler
The URI prefix handler
-
_workflowProvider
protected WorkflowProvider _workflowProvider
The workflow provider
-
_workflowHelper
protected WorkflowHelper _workflowHelper
The workflow helper component
-
_sqlDatabaseTypeExtensionPoint
protected SQLDatabaseTypeExtensionPoint _sqlDatabaseTypeExtensionPoint
The SQLDatabaseTypeExtensionPoint instance
-
_rightManager
protected RightManager _rightManager
Rights manager
-
_currentUserProvied
protected CurrentUserProvider _currentUserProvied
current user provider
-
-
Constructor Detail
-
ProcessFormHelper
public ProcessFormHelper()
-
-
Method Detail
-
contextualize
public void contextualize(Context context) throws ContextException
- Specified by:
contextualize
in interfaceContextualizable
- Throws:
ContextException
-
service
public void service(ServiceManager serviceManager) throws ServiceException
- Specified by:
service
in 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
protected String _getFormRedirection(Form form, String entryId)
Get the form redirection- Parameters:
form
- the formentryId
- the entryId- Returns:
- the form redirection url
-
_getInput
protected Map<String,FieldValue> _getInput(Form form, Request request, FormErrors errors)
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, InvalidModificationException
Insert 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.WorkflowException
Set 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
protected List<I18nizableText> _validateTextField(FieldValue entry, Request request)
Validate a text field.- Parameters:
entry
- the text field entry.request
- the user request.- Returns:
- the list of error messages.
-
_validatePassword
protected List<I18nizableText> _validatePassword(FieldValue entry, Request request)
Validate a password field.- Parameters:
entry
- the password field entry.request
- the user request.- Returns:
- the list of error messages.
-
_validateSelect
protected List<I18nizableText> _validateSelect(FieldValue entry, Request request)
Validate a select input.- Parameters:
entry
- the select input entry.request
- the user request.- Returns:
- the list of error messages.
-
_validateTextarea
protected List<I18nizableText> _validateTextarea(FieldValue entry, Request request)
Validate a textarea.- Parameters:
entry
- the textarea entry.request
- the user request.- Returns:
- the list of error messages.
-
_validateRadio
protected List<I18nizableText> _validateRadio(FieldValue entry, Request request)
Validate a radio input.- Parameters:
entry
- the radio input entry.request
- the user request.- Returns:
- the list of error messages.
-
_validateCheckbox
protected List<I18nizableText> _validateCheckbox(FieldValue entry, Request request)
Validate a checkbox input.- Parameters:
entry
- the checkbox entry.request
- the user request.- Returns:
- the list of error messages.
-
_validateFile
protected List<I18nizableText> _validateFile(FieldValue entry, Request request)
Validate a file input.- Parameters:
entry
- the file input entry.request
- the user request.- Returns:
- the list of error messages.
-
_validateCaptcha
protected List<I18nizableText> _validateCaptcha(FieldValue entry, Request request)
Validate a captcha.- Parameters:
entry
- the captcha entry.request
- the user request.- Returns:
- the list of error messages.
-
_validateMandatory
protected List<I18nizableText> _validateMandatory(FieldValue entry, String keyPrefix)
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
protected Collection<FieldValue> _getEntriesToInsert(Collection<FieldValue> entries)
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)
Send the notification emails.- Parameters:
form
- the form.input
- the user input.sender
- the sender e-mail.
-
_sendReceiptEmail
protected void _sendReceiptEmail(Form form, Map<String,FieldValue> input, String sender)
Send the receipt email.- Parameters:
form
- the form.input
- the user input.sender
- the sender e-mail.
-
_sendLimitEmail
protected void _sendLimitEmail(Form form, Map<String,FieldValue> input, String sender)
Send the limit email.- Parameters:
form
- the form.input
- the user input.sender
- the sender e-mail.
-
_getMail
protected String _getMail(String resource, Form form, Map<String,FieldValue> input) throws IOException
Get 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
protected Collection<File> _getFiles(Map<String,FieldValue> input)
Get the files of a user input.- Parameters:
input
- the user input.- Returns:
- the files submitted by the user.
-
-