Class SurveyDAO

All Implemented Interfaces:
LogEnabled, Component, Contextualizable, Serviceable

public class SurveyDAO extends AbstractDAO
DAO for manipulating surveys.
  • Field Details

  • Constructor Details

  • Method Details

    • service

      public void service(ServiceManager serviceManager) throws ServiceException
      Specified by:
      service in interface Serviceable
      Overrides:
      service in class AbstractDAO
      Throws:
      ServiceException
    • getSurvey

      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

      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 values
      siteName - The site name
      language - 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 values
      siteName - The site name
      language - 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 copy
      label - The label
      title - The title
      Returns:
      The id of the created survey
      Throws:
      Exception - if an error occurs during the survey copying process
    • deleteSurvey

      Deletes a survey.
      Parameters:
      id - The id of the survey to delete
      Returns:
      The id of the deleted survey
    • validateSurvey

      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 validate
      invalidate - 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

      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 name
      lang - The language
      surveyId - The id of survey
      Returns:
      The list of modified pages ids
    • getSurveyZoneItems

      Get all zone items which contains the survey
      Parameters:
      siteName - the site name
      lang - the language
      surveyId - the survey id
      Returns:
      the zone items
    • getParentSurvey

      Get the survey containing the given object.
      Parameters:
      obj - the object.
      Returns:
      the parent Survey.
    • createStatsMap

      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

      Transforms the statistics map into an array with some info.
      Parameters:
      survey - The survey
      stats - 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 id
      user - 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 id
      message - The message
      siteName - The site name
      Returns:
      The text body
    • getSurveyUri

      protected String getSurveyUri(String surveyId, String siteName)
      Get the survey page uri
      Parameters:
      surveyId - The survey id
      siteName - The site name
      Returns:
      The survey absolute uri