Package org.ametys.plugins.survey.dao
Class SurveyDAO
- java.lang.Object
-
- org.ametys.runtime.plugin.component.AbstractLogEnabled
-
- org.ametys.plugins.survey.dao.AbstractDAO
-
- org.ametys.plugins.survey.dao.SurveyDAO
-
- All Implemented Interfaces:
LogEnabled
,Component
,Contextualizable
,Serviceable
public class SurveyDAO extends AbstractDAO
DAO for manipulating surveys.
-
-
Field Summary
Fields Modifier and Type Field Description protected PageDAO
_pageDAO
The page DAOprotected SiteConfigurationExtensionPoint
_siteConfiguration
The site configuration.protected SurveyAnswerDao
_surveyAnswerDao
The survey answer dao.static String
ROLE
The Avalon role-
Fields inherited from class org.ametys.plugins.survey.dao.AbstractDAO
_cocoonContext, _context, _currentUserProvider, _jsonUtils, _observationManager, _resolver, _siteManager, _uploadManager
-
-
Constructor Summary
Constructors Constructor Description SurveyDAO()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Map<String,String>
copySurvey(String surveyId, String label, String title)
Copies and pastes a survey.protected Map<String,Map<String,Map<String,Object>>>
createStatsMap(Survey survey)
Create the statistics Map for a survey.Map<String,String>
createSurvey(Map<String,Object> values, String siteName, String language)
Creates a survey.Map<String,String>
deleteSurvey(String id)
Deletes a survey.protected void
dispatchChoiceStats(SurveySession session, Map<String,Map<String,Object>> questionStats, Map<String,Set<String>> valueMap)
Dispatch stats on a choice question.protected void
dispatchMatrixStats(SurveySession session, Map<String,Map<String,Object>> questionStats, Map<String,Set<String>> valueMap)
Dispatch stats on a matrix question.protected void
dispatchStats(Survey survey, Collection<SurveySession> sessions, Map<String,Map<String,Map<String,Object>>> stats)
Dispatch the survey user sessions (input) in the statistics map.protected void
dispatchTextStats(SurveySession session, Map<String,Map<String,Object>> questionStats, Map<String,Set<String>> valueMap)
Dispatch stats on a text question.Map<String,String>
editSurvey(Map<String,Object> values, String siteName, String language)
Edits a survey.List<Object>
getChildren(String id)
Gets the children pages of a surveyprotected String
getChoiceLabel(SurveyQuestion question, String choiceId)
Get an option label, depending on the question type.protected String
getMailBody(String surveyId, String message, String siteName)
Get the email bodyprotected String
getMailSubject()
Get the email subjectprotected String
getOptionLabel(SurveyQuestion question, String optionId)
Get an option label, depending on the question type.protected Survey
getParentSurvey(JCRAmetysObject obj)
Get the survey containing the given object.Map<String,Object>
getStatistics(String id)
Generates statistics on each question of a survey.Map<String,Object>
getSurvey(String id)
Gets properties of a surveyMap<String,Object>
getSurvey(Survey survey)
Gets properties of a surveyprotected String
getSurveyUri(String surveyId, String siteName)
Get the survey page uriAmetysObjectIterable<ModifiableZoneItem>
getSurveyZoneItems(String siteName, String lang, String surveyId)
Get all zone items which contains the surveyprotected Map<String,Set<String>>
getValueMap(SurveyQuestion question, String value)
Get the user-input value as a Map from the database value, which is a single serialized string.protected boolean
hasAlreadyAnswered(String surveyId, UserIdentity user)
Determines if the user has already answered to the surveyMap<String,String>
isOnline(String id)
Gets the online status of a surveyboolean
isPrivate(Survey survey)
Determines if the survey is privateMap<String,String>
moveObject(String id, String oldParent, String newParent, long index)
Moves an element of the survey.Map<String,Object>
reinitSurvey(String id, boolean invalidate)
Reinitializes a survey.protected List<String>
removeExistingServices(String siteName, String lang, String surveyId)
Remove the existing services if existsMap<String,Object>
sendInvitations(String surveyId, String message, String siteName)
Sends invitations emails.void
service(ServiceManager serviceManager)
Map<String,String>
setRedirection(String surveyId, String pageId)
Sets a new redirection page to the survey.protected List<Map<String,Object>>
statsToArray(Survey survey, Map<String,Map<String,Map<String,Object>>> stats)
Transforms the statistics map into an array with some info.Map<String,String>
validateSurvey(String id)
Validates a survey.-
Methods inherited from class org.ametys.plugins.survey.dao.AbstractDAO
_getCurrentUser, contextualize, getPictureInfo, getSurveyRootNode, setPicture, updateReferencesAfterCopy, updateReferencesAfterCopy, updateReferencesAfterCopy
-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
-
-
-
Field Detail
-
_surveyAnswerDao
protected SurveyAnswerDao _surveyAnswerDao
The survey answer dao.
-
_siteConfiguration
protected SiteConfigurationExtensionPoint _siteConfiguration
The site configuration.
-
-
Constructor Detail
-
SurveyDAO
public SurveyDAO()
-
-
Method Detail
-
service
public void service(ServiceManager serviceManager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Overrides:
service
in classAbstractDAO
- Throws:
ServiceException
-
getSurvey
public Map<String,Object> getSurvey(String id)
Gets properties of a survey- Parameters:
id
- The id of the survey- Returns:
- The properties
-
getSurvey
public Map<String,Object> getSurvey(Survey survey)
Gets properties of a survey- Parameters:
survey
- The survey- Returns:
- The properties
-
isPrivate
public boolean isPrivate(Survey survey)
Determines if the survey is private- Parameters:
survey
- The survey- Returns:
- true if the survey is reading restricted
-
isOnline
public Map<String,String> isOnline(String id)
Gets the online status of a survey- Parameters:
id
- The id of the survey- Returns:
- A map indicating if the survey is valid and if it is online
-
getChildren
public List<Object> getChildren(String id)
Gets the children pages of a survey- Parameters:
id
- The id of the survey- Returns:
- A map of pages properties
-
createSurvey
public Map<String,String> createSurvey(Map<String,Object> values, String siteName, String language) throws Exception
Creates a survey.- Parameters:
values
- The survey valuessiteName
- The site namelanguage
- The language- Returns:
- The id of the created survey
- Throws:
Exception
- if an error occurs during the survey creation process
-
editSurvey
public Map<String,String> editSurvey(Map<String,Object> values, String siteName, String language)
Edits a survey.- Parameters:
values
- The survey valuessiteName
- The site namelanguage
- The language- Returns:
- The id of the edited survey
-
copySurvey
public Map<String,String> copySurvey(String surveyId, String label, String title) throws Exception
Copies and pastes a survey.- Parameters:
surveyId
- The id of the survey to copylabel
- The labeltitle
- The title- Returns:
- The id of the created survey
- Throws:
Exception
- if an error occurs during the survey copying process
-
deleteSurvey
public Map<String,String> deleteSurvey(String id)
Deletes a survey.- Parameters:
id
- The id of the survey to delete- Returns:
- The id of the deleted survey
-
validateSurvey
public Map<String,String> validateSurvey(String id)
Validates a survey.- Parameters:
id
- The id of the survey to validate- Returns:
- The id of the validated survey
-
reinitSurvey
public Map<String,Object> reinitSurvey(String id, boolean invalidate)
Reinitializes a survey.- Parameters:
id
- The id of the survey to validateinvalidate
- True to invalidate the survey- Returns:
- The id of the reinitialized survey
-
setRedirection
public Map<String,String> setRedirection(String surveyId, String pageId)
Sets a new redirection page to the survey.- Parameters:
surveyId
- The id of the survey to edit.pageId
- The id of the redirection page.- Returns:
- The id of the edited survey
-
moveObject
public Map<String,String> moveObject(String id, String oldParent, String newParent, long index) throws Exception
Moves an element of the survey.- Parameters:
id
- The id of the element to move.oldParent
- The id of the element's parent.newParent
- The id of the new element's parent.index
- The index where to move. null to place the element at the end.- Returns:
- A map with the ids of the element, the old parent and the new parent
- Throws:
Exception
- if an error occurs when moving an element of the survey
-
sendInvitations
public Map<String,Object> sendInvitations(String surveyId, String message, String siteName)
Sends invitations emails.- Parameters:
surveyId
- The id of the survey.message
- The message content.siteName
- The site name.- Returns:
- An empty map
-
getStatistics
public Map<String,Object> getStatistics(String id)
Generates statistics on each question of a survey.- Parameters:
id
- The survey id- Returns:
- A map containing the statistics
-
removeExistingServices
protected List<String> removeExistingServices(String siteName, String lang, String surveyId)
Remove the existing services if exists- Parameters:
siteName
- The site namelang
- The languagesurveyId
- The id of survey- Returns:
- The list of modified pages ids
-
getSurveyZoneItems
public AmetysObjectIterable<ModifiableZoneItem> getSurveyZoneItems(String siteName, String lang, String surveyId)
Get all zone items which contains the survey- Parameters:
siteName
- the site namelang
- the languagesurveyId
- the survey id- Returns:
- the zone items
-
getParentSurvey
protected Survey getParentSurvey(JCRAmetysObject obj)
Get the survey containing the given object.- Parameters:
obj
- the object.- Returns:
- the parent Survey.
-
createStatsMap
protected Map<String,Map<String,Map<String,Object>>> createStatsMap(Survey survey)
Create the statistics Map for a survey.- Parameters:
survey
- the survey.- Returns:
- the statistics Map. It is of the following form: questionId -> optionId ->choiceId -> count.
-
dispatchStats
protected void dispatchStats(Survey survey, Collection<SurveySession> sessions, Map<String,Map<String,Map<String,Object>>> stats)
Dispatch the survey user sessions (input) in the statistics map.- Parameters:
survey
- the survey.sessions
- the user sessions.stats
- the statistics Map to fill.
-
dispatchTextStats
protected void dispatchTextStats(SurveySession session, Map<String,Map<String,Object>> questionStats, Map<String,Set<String>> valueMap)
Dispatch stats on a text question.- Parameters:
session
- the survey session.questionStats
- the Map to fill with the stats.valueMap
- the value map.
-
dispatchChoiceStats
protected void dispatchChoiceStats(SurveySession session, Map<String,Map<String,Object>> questionStats, Map<String,Set<String>> valueMap)
Dispatch stats on a choice question.- Parameters:
session
- the survey session.questionStats
- the Map to fill with the stats.valueMap
- the value map.
-
dispatchMatrixStats
protected void dispatchMatrixStats(SurveySession session, Map<String,Map<String,Object>> questionStats, Map<String,Set<String>> valueMap)
Dispatch stats on a matrix question.- Parameters:
session
- the survey session.questionStats
- the Map to fill with the stats.valueMap
- the value map.
-
statsToArray
protected List<Map<String,Object>> statsToArray(Survey survey, Map<String,Map<String,Map<String,Object>>> stats)
Transforms the statistics map into an array with some info.- Parameters:
survey
- The surveystats
- The filled statistics Map.- Returns:
- A list of statistics.
-
getOptionLabel
protected String getOptionLabel(SurveyQuestion question, String optionId)
Get an option label, depending on the question type.- Parameters:
question
- the question.optionId
- the option ID.- Returns:
- the question label, can be the empty string.
-
getChoiceLabel
protected String getChoiceLabel(SurveyQuestion question, String choiceId)
Get an option label, depending on the question type.- Parameters:
question
- the question.choiceId
- the choice id.- Returns:
- the option label, can be the empty string.
-
getValueMap
protected Map<String,Set<String>> getValueMap(SurveyQuestion question, String value)
Get the user-input value as a Map from the database value, which is a single serialized string.- Parameters:
question
- the question.value
- the value from the database.- Returns:
- the value as a Map.
-
hasAlreadyAnswered
protected boolean hasAlreadyAnswered(String surveyId, UserIdentity user)
Determines if the user has already answered to the survey- Parameters:
surveyId
- The survey iduser
- the user- Returns:
true
if the user has already answered
-
getMailSubject
protected String getMailSubject()
Get the email subject- Returns:
- The subject
-
getMailBody
protected String getMailBody(String surveyId, String message, String siteName)
Get the email body- Parameters:
surveyId
- The survey idmessage
- The messagesiteName
- The site name- Returns:
- The text body
-
getSurveyUri
protected String getSurveyUri(String surveyId, String siteName)
Get the survey page uri- Parameters:
surveyId
- The survey idsiteName
- The site name- Returns:
- The survey absolute uri
-
-