public boolean loadQuestionRevision(HttpSession session, Long questionNumber) { String countryrevision = ConcurrencyKeys.COUNTRY_REVISION.toString(); User usr = (User) session.getAttribute(SESSION_USER); String iso3 = UserUtil.getSingleIso3(usr); QuestionsUserTable qut = (QuestionsUserTable) context.getAttribute(USER_MAP_NAME); if (qut == null) { qut = new QuestionsUserTable(); context.setAttribute(USER_MAP_NAME, qut); context.getAttribute(USER_MAP_NAME); } boolean amITheFirst = qut.amITheFirst(usr, questionNumber.intValue()); qut.addUser(usr, questionNumber.intValue()); session.removeAttribute(countryrevision); Question question = surveyService.findQuestion(questionNumber); Country countryEntity = surveyService.searchCountry(iso3); QuestionRevision qr = surveyService.getQuestionRevisionNumber(countryEntity, question); if (qr == null) { QuestionRevision qrNew = new QuestionRevision(); qrNew.setVersion(0l); qrNew.setQuestion(question); qrNew.setCountry(countryEntity); surveyService.insertQuestionRevisionNumber(qrNew); qr = surveyService.getQuestionRevisionNumber(countryEntity, question); } session.setAttribute(countryrevision, qr); return amITheFirst; }
@Override public boolean updateQuestionRevision(QuestionRevision revision) { QuestionRevision lastRevision = findQuestionRevision(revision.getCountry(), revision.getQuestion()); Long version = lastRevision.getVersion(); if (lastRevision.getVersion() <= revision.getVersion()) { if (!questionRevisionDAO.remove(revision)) { return false; } else { lastRevision.setVersion(version + 1); questionRevisionDAO.merge(lastRevision); return true; } } return false; }