/** * Search for {@link JpaSurvey} specified by id. * * @param id * @return */ @Override @Transactional(readOnly = true, propagation = Propagation.SUPPORTS) public SurveyDTO getSurvey(long id) { JpaSurvey jpaSurvey = jpaSurveyDao.getSurvey(id); if (jpaSurvey == null) { return null; } SurveyDTO result = surveyMapper.toSurvey(jpaSurvey); result.retrieveText(this); return result; }
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS) @Override public SurveyDTO getSurveyByName(String surveyName) { JpaSurvey jpaSurvey = jpaSurveyDao.getSurveyByCanonicalName(surveyName); if (jpaSurvey == null) { return null; } SurveyDTO result = surveyMapper.toSurvey(jpaSurvey); result.retrieveText(this); return result; }
/** * Search for survey questions for the specified survey. Return only the question data. * * @param surveyId * @return */ @Transactional(readOnly = true, propagation = Propagation.SUPPORTS) @Override public List<SurveyQuestionDTO> getSurveyQuestions(Long surveyId) { JpaSurvey survey = jpaSurveyDao.getSurvey(surveyId); if (survey == null) { return null; } SurveyDTO surveyDTO = surveyMapper.toSurvey(survey); return Lists.newArrayList(surveyDTO.getSurveyQuestions()); }
/** * Return all surveys * * @return */ @Transactional(readOnly = true, propagation = Propagation.SUPPORTS) @Override public List<SurveyDTO> getAllSurveys() { List<JpaSurvey> surveyList = jpaSurveyDao.getAllSurveys(); if (surveyList == null) { return null; } List<SurveyDTO> results = surveyMapper.toSurveyList(surveyList); for (SurveyDTO surveyDTO : results) { surveyDTO.retrieveText(this); } return results; }
/** * Update base survey data. Questions/answer relationships will not be included in the update. * * @param survey * @return */ @Transactional @Override public SurveyDTO updateSurvey(SurveyDTO survey) { JpaSurvey existingSurvey = jpaSurveyDao.getSurvey(survey.getId()); if (existingSurvey == null || existingSurvey.getStatus() == PublishedState.PUBLISHED) { log.warn("Cannot update survey"); return null; } // remove question/answer elements survey.setSurveyQuestions(null); JpaSurvey jpaSurvey = surveyMapper.toJpaSurvey(survey); jpaSurvey.setLastUpdateDate(new Timestamp(new Date().getTime())); jpaSurvey = jpaSurveyDao.updateSurvey(jpaSurvey); return surveyMapper.toSurvey(jpaSurvey); }