Package org.ametys.plugins.survey.answer
Class ProcessInputAction
- java.lang.Object
-
- org.apache.avalon.framework.logger.AbstractLogEnabled
-
- org.apache.cocoon.acting.AbstractAction
-
- org.apache.cocoon.acting.ServiceableAction
-
- org.ametys.plugins.survey.answer.ProcessInputAction
-
- All Implemented Interfaces:
Component
,LogEnabled
,Serviceable
,Action
- Direct Known Subclasses:
ProcessMiniSurveyAction
public class ProcessInputAction extends ServiceableAction
Process the user answers to the survey.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
ProcessInputAction.SurveyInput
Survey session with answers.class
ProcessInputAction.SurveyInputAnswer
Class representing a survey answer, i.e.
-
Field Summary
Fields Modifier and Type Field Description protected SurveyAccessHelper
_accessHelper
The survey access helperprotected SurveyAnswerDao
_answerDao
The ametys object resolver.protected String
_pluginName
The plugin nameprotected URIPrefixHandler
_prefixHandler
The uri prefix handler.protected AmetysObjectResolver
_resolver
The ametys object resolver.protected CurrentUserProvider
_userProvider
The user provider.static String
COOKIE_NAME
The name of the cookie storing the taken surveys.-
Fields inherited from class org.apache.cocoon.acting.ServiceableAction
manager
-
Fields inherited from class org.apache.cocoon.acting.AbstractAction
EMPTY_MAP
-
-
Constructor Summary
Constructors Constructor Description ProcessInputAction()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Map
act(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters)
protected boolean
checkAccess(Survey survey, Request request, SurveyErrors errors)
Check if user can answer to the surveyprotected SurveyRule
evaluateChoiceRules(SurveyQuestion question, ProcessInputAction.SurveyInputAnswer answer)
Evaluate rules on a choice question.protected SurveyRule
evaluateMatrixRules(SurveyQuestion question, ProcessInputAction.SurveyInputAnswer answer)
Evaluate rules on a matrix question.protected SurveyRule
evaluateTextRules(SurveyQuestion question, ProcessInputAction.SurveyInputAnswer answer)
Evaluate rules on a text question.protected UserIdentity
getAuthenticatedUser(Request request)
Get the authenticated userprotected String
getClientIp(Request request)
Get a forwarded client IP address if available.protected ProcessInputAction.SurveyInput
getInput(Survey survey, Request request)
Get the user input.protected String
getPluginName(Request request)
Get the plugin nameprotected Map<String,Set<String>>
getValues(SurveyQuestion question, Request request)
Get an answer value from the request.protected boolean
isBlank(ProcessInputAction.SurveyInputAnswer answer)
Test if the answer is empty.protected boolean
processPage(SurveyPage page, SurveyRule rule)
Test if a page is to be processed, depending on the rule.void
service(ServiceManager serviceManager)
protected void
setCookie(Request request, Response response, String surveyId)
Indicate in a cookie that the survey was taken.protected List<I18nizableText>
validateChoice(ProcessInputAction.SurveyInputAnswer answer, Request request)
Validate a choice question answer.protected void
validateInput(Survey survey, ProcessInputAction.SurveyInput input, SurveyErrors errors, Request request)
Validate the user input.protected List<I18nizableText>
validateMatrix(ProcessInputAction.SurveyInputAnswer answer, Request request)
Validate a matrix question answer.protected List<I18nizableText>
validatePattern(ProcessInputAction.SurveyInputAnswer answer, String keyPrefix)
Validate an answer against a pattern.protected List<I18nizableText>
validateText(ProcessInputAction.SurveyInputAnswer answer, Request request)
Validate a text field.-
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
-
-
-
-
Field Detail
-
COOKIE_NAME
public static final String COOKIE_NAME
The name of the cookie storing the taken surveys.- See Also:
- Constant Field Values
-
_resolver
protected AmetysObjectResolver _resolver
The ametys object resolver.
-
_answerDao
protected SurveyAnswerDao _answerDao
The ametys object resolver.
-
_userProvider
protected CurrentUserProvider _userProvider
The user provider.
-
_prefixHandler
protected URIPrefixHandler _prefixHandler
The uri prefix handler.
-
_accessHelper
protected SurveyAccessHelper _accessHelper
The survey access helper
-
_pluginName
protected String _pluginName
The plugin name
-
-
Constructor Detail
-
ProcessInputAction
public ProcessInputAction()
-
-
Method Detail
-
service
public void service(ServiceManager serviceManager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Overrides:
service
in classServiceableAction
- Throws:
ServiceException
-
act
public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws Exception
- Throws:
Exception
-
getPluginName
protected String getPluginName(Request request)
Get the plugin name- Parameters:
request
- The request- Returns:
- The plugin name
-
checkAccess
protected boolean checkAccess(Survey survey, Request request, SurveyErrors errors)
Check if user can answer to the survey- Parameters:
survey
- The surveyrequest
- The requesterrors
- The survey errors- Returns:
- false if the access failed
-
getAuthenticatedUser
protected UserIdentity getAuthenticatedUser(Request request)
Get the authenticated user- Parameters:
request
- The request- Returns:
- The authenticated user
-
getInput
protected ProcessInputAction.SurveyInput getInput(Survey survey, Request request)
Get the user input.- Parameters:
survey
- the survey.request
- the request.- Returns:
- the user input.
-
getValues
protected Map<String,Set<String>> getValues(SurveyQuestion question, Request request)
Get an answer value from the request.- Parameters:
question
- the corresponding question.request
- the request.- Returns:
- the answer value.
-
validateInput
protected void validateInput(Survey survey, ProcessInputAction.SurveyInput input, SurveyErrors errors, Request request)
Validate the user input.- Parameters:
survey
- the survey.input
- the user input.errors
- the errors.request
- the request.
-
processPage
protected boolean processPage(SurveyPage page, SurveyRule rule)
Test if a page is to be processed, depending on the rule.- Parameters:
page
- the page to test.rule
- the rule to execute.- Returns:
- true to process the page, false otherwise.
-
evaluateTextRules
protected SurveyRule evaluateTextRules(SurveyQuestion question, ProcessInputAction.SurveyInputAnswer answer)
Evaluate rules on a text question.- Parameters:
question
- the text question.answer
- the user answer to the question.- Returns:
- the matched rule.
-
evaluateChoiceRules
protected SurveyRule evaluateChoiceRules(SurveyQuestion question, ProcessInputAction.SurveyInputAnswer answer)
Evaluate rules on a choice question.- Parameters:
question
- the choice question.answer
- the user answer to the question.- Returns:
- the matched rule.
-
evaluateMatrixRules
protected SurveyRule evaluateMatrixRules(SurveyQuestion question, ProcessInputAction.SurveyInputAnswer answer)
Evaluate rules on a matrix question.- Parameters:
question
- the matrix question.answer
- the user answer to the question.- Returns:
- the matched rule.
-
validateText
protected List<I18nizableText> validateText(ProcessInputAction.SurveyInputAnswer answer, Request request)
Validate a text field.- Parameters:
answer
- the user answer to the question.request
- the request.- Returns:
- the error list.
-
validateChoice
protected List<I18nizableText> validateChoice(ProcessInputAction.SurveyInputAnswer answer, Request request)
Validate a choice question answer.- Parameters:
answer
- the user answer to the question.request
- the request.- Returns:
- the error list.
-
validateMatrix
protected List<I18nizableText> validateMatrix(ProcessInputAction.SurveyInputAnswer answer, Request request)
Validate a matrix question answer.- Parameters:
answer
- the user answer to the question.request
- the request.- Returns:
- the error list.
-
validatePattern
protected List<I18nizableText> validatePattern(ProcessInputAction.SurveyInputAnswer answer, String keyPrefix)
Validate an answer against a pattern.- Parameters:
answer
- the user answer to the question.keyPrefix
- the error i18n key prefix.- Returns:
- the error list.
-
isBlank
protected boolean isBlank(ProcessInputAction.SurveyInputAnswer answer)
Test if the answer is empty.- Parameters:
answer
- the user answer.- Returns:
- true if the answer is empty.
-
setCookie
protected void setCookie(Request request, Response response, String surveyId)
Indicate in a cookie that the survey was taken.- Parameters:
request
- the request.response
- the response.surveyId
- the ID of the survey that was just taken.
-
getClientIp
protected final String getClientIp(Request request)
Get a forwarded client IP address if available.- Parameters:
request
- The servlet request object.- Returns:
- The HTTP
X-Forwarded-For
header value if present, or the default remote address if not.
-
-