Index: lams_common/src/java/org/lamsfoundation/lams/applicationContext.xml =================================================================== diff -u -ra6641bf9262a01d07740a517643f8fe187ec5b1f -r0b8f5f74ece9677e18c0eb54194c6cec604d5769 --- lams_common/src/java/org/lamsfoundation/lams/applicationContext.xml (.../applicationContext.xml) (revision a6641bf9262a01d07740a517643f8fe187ec5b1f) +++ lams_common/src/java/org/lamsfoundation/lams/applicationContext.xml (.../applicationContext.xml) (revision 0b8f5f74ece9677e18c0eb54194c6cec604d5769) @@ -49,5 +49,6 @@ In case of optimistic locking exceptions it retrires the transaction up to 5 times --> + \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/web/filter/TransactionRetryInterceptor.java =================================================================== diff -u -re5d5c08d34883b3336660cc68cb576ef1494671a -r0b8f5f74ece9677e18c0eb54194c6cec604d5769 --- lams_common/src/java/org/lamsfoundation/lams/web/filter/TransactionRetryInterceptor.java (.../TransactionRetryInterceptor.java) (revision e5d5c08d34883b3336660cc68cb576ef1494671a) +++ lams_common/src/java/org/lamsfoundation/lams/web/filter/TransactionRetryInterceptor.java (.../TransactionRetryInterceptor.java) (revision 0b8f5f74ece9677e18c0eb54194c6cec604d5769) @@ -25,12 +25,17 @@ import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; +import org.apache.commons.lang.mutable.MutableInt; import org.apache.log4j.Logger; +import org.hibernate.FlushMode; +import org.hibernate.Session; +import org.hibernate.SessionFactory; import org.hibernate.exception.ConstraintViolationException; import org.hibernate.exception.LockAcquisitionException; import org.lamsfoundation.lams.util.ITransactionRetryService; import org.springframework.dao.CannotAcquireLockException; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.orm.hibernate3.SessionFactoryUtils; import org.springframework.transaction.UnexpectedRollbackException; /** @@ -44,50 +49,53 @@ private static final Logger log = Logger.getLogger(TransactionRetryInterceptor.class); private ITransactionRetryService transactionRetryService; + private SessionFactory sessionFactory; private static final int MAX_ATTEMPTS = 5; @Override public Object invoke(MethodInvocation invocation) throws Throwable { - int attempt = 1; + MutableInt attempt = new MutableInt(1); Throwable exception = null; do { try { - if (attempt == 1) { + if (attempt.intValue() == 1) { return invocation.proceed(); } else { return transactionRetryService.retry(invocation); } } catch (DataIntegrityViolationException e) { exception = e; - attempt++; - TransactionRetryInterceptor.processException(e, invocation, attempt); + processException(e, invocation, attempt); } catch (ConstraintViolationException e) { exception = e; - attempt++; - TransactionRetryInterceptor.processException(e, invocation, attempt); + processException(e, invocation, attempt); } catch (CannotAcquireLockException e) { exception = e; - attempt++; - TransactionRetryInterceptor.processException(e, invocation, attempt); + processException(e, invocation, attempt); } catch (LockAcquisitionException e) { exception = e; - attempt++; - TransactionRetryInterceptor.processException(e, invocation, attempt); + processException(e, invocation, attempt); } catch (UnexpectedRollbackException e) { exception = e; - attempt++; - TransactionRetryInterceptor.processException(e, invocation, attempt); + processException(e, invocation, attempt); } - } while (attempt <= TransactionRetryInterceptor.MAX_ATTEMPTS); + } while (attempt.intValue() <= TransactionRetryInterceptor.MAX_ATTEMPTS); throw exception; } - private static void processException(Exception e, MethodInvocation invocation, int attempt) { + private void processException(Exception e, MethodInvocation invocation, MutableInt attempt) { StringBuilder message = new StringBuilder("When invoking method \"").append(invocation.getMethod().getName()) - .append("\" caught ").append(e.getMessage()).append(". Attempt #").append(attempt - 1); - if (attempt <= TransactionRetryInterceptor.MAX_ATTEMPTS) { + .append("\" caught \"").append(e.getMessage()).append("\". Attempt #").append(attempt); + + attempt.increment(); + if (attempt.intValue() <= TransactionRetryInterceptor.MAX_ATTEMPTS) { message.append(". Retrying."); + + // the exception could have closed the session; try to recreate it here + Session session = SessionFactoryUtils.getSession(sessionFactory, true); + // same as in CustomizedOpenSessionInViewFilter + session.setFlushMode(FlushMode.AUTO); } else { message.append(". Giving up."); } @@ -97,4 +105,8 @@ public void setTransactionRetryService(ITransactionRetryService transactionRetryService) { this.transactionRetryService = transactionRetryService; } + + public void setSessionFactory(SessionFactory sessionFactory) { + this.sessionFactory = sessionFactory; + } } \ No newline at end of file Index: lams_tool_assessment/src/java/org/lamsfoundation/lams/tool/assessment/service/AssessmentServiceImpl.java =================================================================== diff -u -r8fd538f0e69320e969865342d94c7c1cbc936977 -r0b8f5f74ece9677e18c0eb54194c6cec604d5769 --- lams_tool_assessment/src/java/org/lamsfoundation/lams/tool/assessment/service/AssessmentServiceImpl.java (.../AssessmentServiceImpl.java) (revision 8fd538f0e69320e969865342d94c7c1cbc936977) +++ lams_tool_assessment/src/java/org/lamsfoundation/lams/tool/assessment/service/AssessmentServiceImpl.java (.../AssessmentServiceImpl.java) (revision 0b8f5f74ece9677e18c0eb54194c6cec604d5769) @@ -169,8 +169,7 @@ AssessmentSession session = getAssessmentSessionBySessionId(toolSessionId); AssessmentUser groupLeader = session.getGroupLeader(); - boolean isUserLeader = (groupLeader != null) && user.getUid().equals(groupLeader.getUid()); - return isUserLeader; + return (groupLeader != null) && user.getUserId().equals(groupLeader.getUserId()); } @Override Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/action/LearningAction.java =================================================================== diff -u -r3b18838d7e4786ef34e83e7c9fc3740553279510 -r0b8f5f74ece9677e18c0eb54194c6cec604d5769 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/action/LearningAction.java (.../LearningAction.java) (revision 3b18838d7e4786ef34e83e7c9fc3740553279510) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/action/LearningAction.java (.../LearningAction.java) (revision 0b8f5f74ece9677e18c0eb54194c6cec604d5769) @@ -33,15 +33,13 @@ import java.util.List; import java.util.Set; import java.util.TimeZone; -import java.util.concurrent.Callable; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.apache.commons.lang.StringEscapeUtils; -import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.math.NumberUtils; import org.apache.log4j.Logger; import org.apache.struts.action.Action; @@ -75,7 +73,6 @@ import org.lamsfoundation.lams.web.session.SessionManager; import org.lamsfoundation.lams.web.util.AttributeNames; import org.lamsfoundation.lams.web.util.SessionMap; -import org.springframework.dao.CannotAcquireLockException; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; @@ -90,8 +87,8 @@ @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException, JSONException, - ScratchieApplicationException { + HttpServletResponse response) + throws IOException, ServletException, JSONException, ScratchieApplicationException { String param = mapping.getParameter(); // -----------------------Scratchie Learner function --------------------------- @@ -160,12 +157,7 @@ user = getCurrentUser(toolSessionId); } - final ScratchieUser groupLeader = (ScratchieUser) tryExecute(new Callable() { - @Override - public Object call() throws ScratchieApplicationException { - return LearningAction.service.checkLeaderSelectToolForSessionLeader(user, toolSessionId); - } - }); + ScratchieUser groupLeader = LearningAction.service.checkLeaderSelectToolForSessionLeader(user, toolSessionId); // forwards to the leaderSelection page if ((groupLeader == null) && !mode.isTeacher()) { @@ -216,24 +208,24 @@ sessionMap.put(ScratchieConstants.ATTR_REFLECTION_ON, isReflectOnActivity); sessionMap.put(ScratchieConstants.ATTR_REFLECTION_INSTRUCTION, scratchie.getReflectInstructions()); sessionMap.put(ScratchieConstants.ATTR_REFLECTION_ENTRY, entryText); - //add all answer uids to one set + // add all answer uids to one set if (isUserLeader) { Set answerUids = new HashSet(); - for (ScratchieItem item : (Set)scratchie.getScratchieItems()) { - for (ScratchieAnswer answer : (Set)item.getAnswers()) { + for (ScratchieItem item : scratchie.getScratchieItems()) { + for (ScratchieAnswer answer : (Set) item.getAnswers()) { answerUids.add(answer.getUid()); } } - sessionMap.put(ScratchieConstants.ATTR_ANSWER_UIDS, answerUids); + sessionMap.put(ScratchieConstants.ATTR_ANSWER_UIDS, answerUids); } // add define later support if (scratchie.isDefineLater()) { return mapping.findForward("defineLater"); } - ActivityPositionDTO activityPosition = LearningWebUtil.putActivityPositionInRequestByToolSessionId( - toolSessionId, request, getServlet().getServletContext()); + ActivityPositionDTO activityPosition = LearningWebUtil + .putActivityPositionInRequestByToolSessionId(toolSessionId, request, getServlet().getServletContext()); sessionMap.put(AttributeNames.ATTR_ACTIVITY_POSITION, activityPosition); // check if there is submission deadline @@ -266,22 +258,22 @@ List burningQuestions = null; if (scratchie.isBurningQuestionsEnabled()) { - burningQuestions = LearningAction.service - .getBurningQuestionsBySession(toolSessionId); + burningQuestions = LearningAction.service.getBurningQuestionsBySession(toolSessionId); for (ScratchieItem item : items) { // find corresponding burningQuestion String question = ""; for (ScratchieBurningQuestion burningQuestion : burningQuestions) { - if (!burningQuestion.isGeneralQuestion() && burningQuestion.getScratchieItem().getUid().equals(item.getUid())) { + if (!burningQuestion.isGeneralQuestion() + && burningQuestion.getScratchieItem().getUid().equals(item.getUid())) { question = burningQuestion.getQuestion(); break; } } item.setBurningQuestion(question); } - - //find general burning question + + // find general burning question String generalBurningQuestion = ""; for (ScratchieBurningQuestion burningQuestion : burningQuestions) { if (burningQuestion.isGeneralQuestion()) { @@ -301,44 +293,44 @@ sessionMap.put(ScratchieConstants.ATTR_ITEM_LIST, items); sessionMap.put(ScratchieConstants.ATTR_SCRATCHIE, scratchie); sessionMap.put(ScratchieConstants.ATTR_MAX_SCORE, maxScore); - + boolean isScratchingFinished = toolSession.isScratchingFinished(); boolean isWaitingForLeaderToSubmitNotebook = isReflectOnActivity && (notebookEntry == null); boolean isWaitingForLeaderToSubmitBurningQuestions = scratchie.isBurningQuestionsEnabled() - && (burningQuestions == null || burningQuestions.isEmpty()) && !toolSession.isSessionFinished(); - boolean isShowResults = (isScratchingFinished && !isWaitingForLeaderToSubmitNotebook && !isWaitingForLeaderToSubmitBurningQuestions) - && !mode.isTeacher(); + && ((burningQuestions == null) || burningQuestions.isEmpty()) && !toolSession.isSessionFinished(); + boolean isShowResults = (isScratchingFinished && !isWaitingForLeaderToSubmitNotebook + && !isWaitingForLeaderToSubmitBurningQuestions) && !mode.isTeacher(); - //show leader showBurningQuestions page + // show leader showBurningQuestions page if (isUserLeader && isScratchingFinished && isWaitingForLeaderToSubmitBurningQuestions) { ActionRedirect redirect = new ActionRedirect(mapping.findForwardConfig("showBurningQuestions")); redirect.addParameter(ScratchieConstants.ATTR_SESSION_MAP_ID, sessionMap.getSessionID()); return redirect; - - //show leader notebook page + + // show leader notebook page } else if (isUserLeader && isScratchingFinished && isWaitingForLeaderToSubmitNotebook) { ActionRedirect redirect = new ActionRedirect(mapping.findForwardConfig("newReflection")); redirect.addParameter(ScratchieConstants.ATTR_SESSION_MAP_ID, sessionMap.getSessionID()); redirect.addParameter(AttributeNames.ATTR_MODE, mode); return redirect; - - // show results page + + // show results page } else if (isShowResults) { - + ActionRedirect redirect = new ActionRedirect(mapping.findForwardConfig("showResults")); redirect.addParameter(ScratchieConstants.ATTR_SESSION_MAP_ID, sessionMap.getSessionID()); redirect.addParameter(AttributeNames.ATTR_MODE, mode); return redirect; - - //show learning.jsp page + + // show learning.jsp page } else { - - //make non leaders also wait for burning questions submit + + // make non leaders also wait for burning questions submit isWaitingForLeaderToSubmitNotebook |= isWaitingForLeaderToSubmitBurningQuestions; - - sessionMap.put(ScratchieConstants.ATTR_IS_SCRATCHING_FINISHED, (Boolean) isScratchingFinished); + + sessionMap.put(ScratchieConstants.ATTR_IS_SCRATCHING_FINISHED, isScratchingFinished); sessionMap.put(ScratchieConstants.ATTR_IS_WAITING_FOR_LEADER_TO_SUBMIT_NOTEBOOK, - (Boolean) isWaitingForLeaderToSubmitNotebook); + isWaitingForLeaderToSubmitNotebook); return mapping.findForward(ScratchieConstants.SUCCESS); } @@ -370,46 +362,48 @@ // refresh ScratchingFinished status sessionMap.put(ScratchieConstants.ATTR_IS_SCRATCHING_FINISHED, toolSession.isScratchingFinished()); - + return mapping.findForward(ScratchieConstants.SUCCESS); } - + /** * Return whether leader still needs submit notebook. */ - private ActionForward checkLeaderSubmittedNotebook(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws JSONException, IOException { + private ActionForward checkLeaderSubmittedNotebook(ActionMapping mapping, ActionForm form, + HttpServletRequest request, HttpServletResponse response) throws JSONException, IOException { initializeScratchieService(); - + // get back SessionMap String sessionMapID = request.getParameter(ScratchieConstants.ATTR_SESSION_MAP_ID); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute( - sessionMapID); + SessionMap sessionMap = (SessionMap) request.getSession() + .getAttribute(sessionMapID); boolean isReflectOnActivity = (Boolean) sessionMap.get(ScratchieConstants.ATTR_REFLECTION_ON); - boolean isBurningQuestionsEnabled = (Boolean) sessionMap.get(ScratchieConstants.ATTR_IS_BURNING_QUESTIONS_ENABLED); + boolean isBurningQuestionsEnabled = (Boolean) sessionMap + .get(ScratchieConstants.ATTR_IS_BURNING_QUESTIONS_ENABLED); Long toolSessionId = (Long) sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID); - - ScratchieSession toolSession = service.getScratchieSessionBySessionId(toolSessionId); + + ScratchieSession toolSession = LearningAction.service.getScratchieSessionBySessionId(toolSessionId); ScratchieUser groupLeader = toolSession.getGroupLeader(); - + // get notebook entry NotebookEntry notebookEntry = null; if (isReflectOnActivity && (groupLeader != null)) { - notebookEntry = service.getEntry(toolSessionId, CoreNotebookConstants.NOTEBOOK_TOOL, + notebookEntry = LearningAction.service.getEntry(toolSessionId, CoreNotebookConstants.NOTEBOOK_TOOL, ScratchieConstants.TOOL_SIGNATURE, groupLeader.getUserId().intValue()); } boolean isWaitingForLeaderToSubmitNotebook = isReflectOnActivity && (notebookEntry == null); - + // make non leaders also wait for burning questions submit List burningQuestions = null; if (isBurningQuestionsEnabled) { burningQuestions = LearningAction.service.getBurningQuestionsBySession(toolSessionId); } isWaitingForLeaderToSubmitNotebook |= isBurningQuestionsEnabled - && (burningQuestions == null || burningQuestions.isEmpty()) && !toolSession.isSessionFinished(); + && ((burningQuestions == null) || burningQuestions.isEmpty()) && !toolSession.isSessionFinished(); JSONObject JSONObject = new JSONObject(); - JSONObject.put(ScratchieConstants.ATTR_IS_WAITING_FOR_LEADER_TO_SUBMIT_NOTEBOOK, isWaitingForLeaderToSubmitNotebook); + JSONObject.put(ScratchieConstants.ATTR_IS_WAITING_FOR_LEADER_TO_SUBMIT_NOTEBOOK, + isWaitingForLeaderToSubmitNotebook); response.setContentType("application/x-json;charset=utf-8"); response.getWriter().print(JSONObject); @@ -425,26 +419,26 @@ HttpServletResponse response) throws JSONException, IOException, ScratchieApplicationException { initializeScratchieService(); String sessionMapID = WebUtil.readStrParam(request, ScratchieConstants.ATTR_SESSION_MAP_ID); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute( - sessionMapID); - final Long toolSessionId = (Long) sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID); + SessionMap sessionMap = (SessionMap) request.getSession() + .getAttribute(sessionMapID); + final Long toolSessionId = (Long) sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID); final Long answerUid = NumberUtils.createLong(request.getParameter(ScratchieConstants.PARAM_ANSWER_UID)); - + ScratchieSession toolSession = LearningAction.service.getScratchieSessionBySessionId(toolSessionId); ScratchieUser leader = this.getCurrentUser(toolSessionId); // only leader is allowed to scratch answers if (!toolSession.isUserGroupLeader(leader.getUid())) { return null; } - - //check answer is belong to current session + + // check answer is belong to current session Set answerUids = (Set) sessionMap.get(ScratchieConstants.ATTR_ANSWER_UIDS); if (!answerUids.contains(answerUid)) { return null; } - //Return whether scratchie answer is correct or not + // Return whether scratchie answer is correct or not ScratchieAnswer answer = LearningAction.service.getScratchieAnswerByUid(answerUid); if (answer == null) { return null; @@ -460,18 +454,7 @@ Thread recordItemScratchedThread = new Thread(new Runnable() { @Override public void run() { - - try { - tryExecute(new Callable() { - @Override - public Object call() throws ScratchieApplicationException { - LearningAction.service.recordItemScratched(toolSessionId, answerUid); - return null; - } - }); - } catch (ScratchieApplicationException e) { - log.error(e); - } + LearningAction.service.recordItemScratched(toolSessionId, answerUid); } }, "LAMS_recordItemScratched_thread"); recordItemScratchedThread.start(); @@ -494,64 +477,60 @@ initializeScratchieService(); // get back SessionMap String sessionMapID = request.getParameter(ScratchieConstants.ATTR_SESSION_MAP_ID); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute( - sessionMapID); + SessionMap sessionMap = (SessionMap) request.getSession() + .getAttribute(sessionMapID); request.setAttribute(ScratchieConstants.ATTR_SESSION_MAP_ID, sessionMapID); boolean isReflectOnActivity = (Boolean) sessionMap.get(ScratchieConstants.ATTR_REFLECTION_ON); - boolean isBurningQuestionsEnabled = (Boolean) sessionMap.get(ScratchieConstants.ATTR_IS_BURNING_QUESTIONS_ENABLED); + boolean isBurningQuestionsEnabled = (Boolean) sessionMap + .get(ScratchieConstants.ATTR_IS_BURNING_QUESTIONS_ENABLED); final Long toolSessionId = (Long) sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID); ScratchieSession toolSession = LearningAction.service.getScratchieSessionBySessionId(toolSessionId); Long userUid = (Long) sessionMap.get(ScratchieConstants.ATTR_USER_UID); - // in case of the leader (and if he hasn't done this when accessing notebook) we should let all other learners see Next Activity button + // in case of the leader (and if he hasn't done this when accessing notebook) we should let all other learners + // see Next Activity button if (toolSession.isUserGroupLeader(userUid) && !toolSession.isScratchingFinished()) { - tryExecute(new Callable() { - @Override - public Object call() throws ScratchieApplicationException { - LearningAction.service.setScratchingFinished(toolSessionId); - return null; - } - }); + LearningAction.service.setScratchingFinished(toolSessionId); } // get updated score from ScratchieSession int score = toolSession.getMark(); int maxScore = (Integer) sessionMap.get(ScratchieConstants.ATTR_MAX_SCORE); double percentage = (maxScore == 0) ? 0 : ((score * 100) / maxScore); request.setAttribute(ScratchieConstants.ATTR_SCORE, (int) percentage); - + // display other groups' BurningQuestions if (isBurningQuestionsEnabled) { Scratchie scratchie = toolSession.getScratchie(); - List burningQuestionDtos = service.getBurningQuestionDtos(scratchie); + List burningQuestionDtos = LearningAction.service.getBurningQuestionDtos(scratchie); request.setAttribute(ScratchieConstants.ATTR_BURNING_QUESTIONS_DTOS, burningQuestionDtos); } // display other groups' notebooks if (isReflectOnActivity) { - List reflections = LearningAction.service.getReflectionList(toolSession.getScratchie() - .getContentId()); + List reflections = LearningAction.service + .getReflectionList(toolSession.getScratchie().getContentId()); // remove current session leader reflection Iterator refIterator = reflections.iterator(); while (refIterator.hasNext()) { ReflectDTO reflection = refIterator.next(); if (toolSession.getSessionName().equals(reflection.getGroupName())) { - - //store for displaying purposes + + // store for displaying purposes String reflectEntry = StringEscapeUtils.unescapeJavaScript(reflection.getReflection()); sessionMap.put(ScratchieConstants.ATTR_REFLECTION_ENTRY, reflectEntry); - - //remove from list to display other groups' notebooks + + // remove from list to display other groups' notebooks refIterator.remove(); break; } } request.setAttribute(ScratchieConstants.ATTR_REFLECTIONS, reflections); } - + return mapping.findForward(ScratchieConstants.SUCCESS); } @@ -569,8 +548,8 @@ initializeScratchieService(); // get back SessionMap String sessionMapID = request.getParameter(ScratchieConstants.ATTR_SESSION_MAP_ID); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute( - sessionMapID); + SessionMap sessionMap = (SessionMap) request.getSession() + .getAttribute(sessionMapID); final Long toolSessionId = (Long) sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID); HttpSession ss = SessionManager.getSession(); UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); @@ -579,20 +558,15 @@ String nextActivityUrl = null; try { - nextActivityUrl = (String) tryExecute(new Callable() { - @Override - public Object call() throws ScratchieApplicationException { - return LearningAction.service.finishToolSession(toolSessionId, userId); - } - }); + nextActivityUrl = LearningAction.service.finishToolSession(toolSessionId, userId); request.setAttribute(ScratchieConstants.ATTR_NEXT_ACTIVITY_URL, nextActivityUrl); } catch (ScratchieApplicationException e) { LearningAction.log.error("Failed get next activity url:" + e.getMessage()); } return mapping.findForward(ScratchieConstants.SUCCESS); } - + /** * Displays burning questions page. * @@ -607,30 +581,25 @@ HttpServletResponse response) throws ScratchieApplicationException { initializeScratchieService(); String sessionMapID = WebUtil.readStrParam(request, ScratchieConstants.ATTR_SESSION_MAP_ID); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); + SessionMap sessionMap = (SessionMap) request.getSession() + .getAttribute(sessionMapID); request.setAttribute(ScratchieConstants.ATTR_SESSION_MAP_ID, sessionMapID); final Long toolSessionId = (Long) sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID); Long userUid = (Long) sessionMap.get(ScratchieConstants.ATTR_USER_UID); - + // set scratched flag for display purpose Collection items = (Collection) sessionMap.get(ScratchieConstants.ATTR_ITEM_LIST); LearningAction.service.getItemsWithIndicatedScratches(toolSessionId, items); // in case of the leader we should let all other learners see Next Activity button ScratchieSession toolSession = LearningAction.service.getScratchieSessionBySessionId(toolSessionId); if (toolSession.isUserGroupLeader(userUid) && !toolSession.isScratchingFinished()) { - tryExecute(new Callable() { - @Override - public Object call() throws ScratchieApplicationException { - LearningAction.service.setScratchingFinished(toolSessionId); - return null; - } - }); + LearningAction.service.setScratchingFinished(toolSessionId); } return mapping.findForward(ScratchieConstants.SUCCESS); } - + /** * Submit reflection form input database. Only leaders can submit reflections. * @@ -646,12 +615,12 @@ initializeScratchieService(); String sessionMapID = WebUtil.readStrParam(request, ScratchieConstants.ATTR_SESSION_MAP_ID); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute( - sessionMapID); + SessionMap sessionMap = (SessionMap) request.getSession() + .getAttribute(sessionMapID); Scratchie scratchie = (Scratchie) sessionMap.get(ScratchieConstants.ATTR_SCRATCHIE); final Long sessionId = (Long) sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID); - Collection items = (Collection) sessionMap.get(ScratchieConstants.ATTR_ITEM_LIST); - + Collection items = (Collection) sessionMap.get(ScratchieConstants.ATTR_ITEM_LIST); + for (int i = 0; i < items.size(); i++) { final Long itemUid = WebUtil.readLongParam(request, ScratchieConstants.ATTR_ITEM_UID + i); ScratchieItem item = null; @@ -662,22 +631,20 @@ } } - String oldQuestion = item.getBurningQuestion(); final String question = request.getParameter(ScratchieConstants.ATTR_BURNING_QUESTION_PREFIX + i); // update question in sessionMap item.setBurningQuestion(question); // update new entry - saveBurningQuestions(sessionId, itemUid, question, oldQuestion); + LearningAction.service.saveBurningQuestion(sessionId, itemUid, question); } - - //handle general burning question + + // handle general burning question final String generalQuestion = request.getParameter(ScratchieConstants.ATTR_GENERAL_BURNING_QUESTION); - String oldGeneralQuestion = (String) sessionMap.get(ScratchieConstants.ATTR_GENERAL_BURNING_QUESTION); - saveBurningQuestions(sessionId, null, generalQuestion, oldGeneralQuestion); + LearningAction.service.saveBurningQuestion(sessionId, null, generalQuestion); // update general question in sessionMap sessionMap.put(ScratchieConstants.ATTR_GENERAL_BURNING_QUESTION, generalQuestion); - + boolean isNotebookSubmitted = sessionMap.get(ScratchieConstants.ATTR_REFLECTION_ENTRY) != null; if (scratchie.isReflectOnActivity() && !isNotebookSubmitted) { return newReflection(mapping, form, request, response); @@ -686,18 +653,6 @@ } } - - private void saveBurningQuestions(final Long sessionId, final Long itemUid, final String question, - String oldQuestion) throws ScratchieApplicationException { - // update new entry - tryExecute(new Callable() { - @Override - public Object call() throws ScratchieApplicationException { - LearningAction.service.saveBurningQuestion(sessionId, itemUid, question); - return null; - } - }); - } /** * Display empty reflection form. @@ -707,14 +662,15 @@ * @param request * @param response * @return - * @throws ScratchieApplicationException + * @throws ScratchieApplicationException */ private ActionForward newReflection(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ScratchieApplicationException { initializeScratchieService(); String sessionMapID = WebUtil.readStrParam(request, ScratchieConstants.ATTR_SESSION_MAP_ID); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); + SessionMap sessionMap = (SessionMap) request.getSession() + .getAttribute(sessionMapID); final Long toolSessionId = (Long) sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID); Long userUid = (Long) sessionMap.get(ScratchieConstants.ATTR_USER_UID); @@ -724,26 +680,20 @@ ReflectionForm refForm = (ReflectionForm) form; refForm.setUserID(user.getUserID()); refForm.setSessionMapID(sessionMapID); - + // get the existing reflection entry NotebookEntry entry = LearningAction.service.getEntry(toolSessionId, CoreNotebookConstants.NOTEBOOK_TOOL, ScratchieConstants.TOOL_SIGNATURE, user.getUserID()); if (entry != null) { refForm.setEntryText(entry.getEntry()); } - + ScratchieSession toolSession = LearningAction.service.getScratchieSessionBySessionId(toolSessionId); // in case of the leader we should let all other learners see Next Activity button if (toolSession.isUserGroupLeader(userUid) && !toolSession.isScratchingFinished()) { - tryExecute(new Callable() { - @Override - public Object call() throws ScratchieApplicationException { - LearningAction.service.setScratchingFinished(toolSessionId); - return null; - } - }); + LearningAction.service.setScratchingFinished(toolSessionId); } return mapping.findForward(ScratchieConstants.NOTEBOOK); @@ -767,8 +717,8 @@ final String entryText = refForm.getEntryText(); String sessionMapID = WebUtil.readStrParam(request, ScratchieConstants.ATTR_SESSION_MAP_ID); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute( - sessionMapID); + SessionMap sessionMap = (SessionMap) request.getSession() + .getAttribute(sessionMapID); final Long sessionId = (Long) sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID); // check for existing notebook entry @@ -777,25 +727,13 @@ if (entry == null) { // create new entry - tryExecute(new Callable() { - @Override - public Object call() throws ScratchieApplicationException { - LearningAction.service.createNotebookEntry(sessionId, CoreNotebookConstants.NOTEBOOK_TOOL, - ScratchieConstants.TOOL_SIGNATURE, userId, entryText); - return null; - } - }); + LearningAction.service.createNotebookEntry(sessionId, CoreNotebookConstants.NOTEBOOK_TOOL, + ScratchieConstants.TOOL_SIGNATURE, userId, entryText); } else { // update existing entry entry.setEntry(entryText); entry.setLastModified(new Date()); - tryExecute(new Callable() { - @Override - public Object call() throws ScratchieApplicationException { - LearningAction.service.updateEntry(entry); - return null; - } - }); + LearningAction.service.updateEntry(entry); } sessionMap.put(ScratchieConstants.ATTR_REFLECTION_ENTRY, entryText); @@ -806,35 +744,10 @@ // Private method // ************************************************************************************* - /** - * Tries to execute supplied command. If it fails due to CannotAcquireLockException it tries again, and gives up - * after 5 consecutive fails. - */ - private Object tryExecute(Callable command) throws ScratchieApplicationException { - final int MAX_TRANSACTION_RETRIES = 5; - Object returnValue = null; - - for (int i = 0; i < MAX_TRANSACTION_RETRIES; i++) { - try { - returnValue = command.call(); - break; - } catch (CannotAcquireLockException e) { - if (i == (MAX_TRANSACTION_RETRIES - 1)) { - throw new ScratchieApplicationException(e); - } - } catch (Exception e) { - throw new ScratchieApplicationException(e); - } - LearningAction.log.warn("Transaction retry: " + (i + 1)); - } - - return returnValue; - } - private void initializeScratchieService() { if (LearningAction.service == null) { - WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet() - .getServletContext()); + WebApplicationContext wac = WebApplicationContextUtils + .getRequiredWebApplicationContext(getServlet().getServletContext()); LearningAction.service = (IScratchieService) wac.getBean(ScratchieConstants.SCRATCHIE_SERVICE); } } @@ -850,13 +763,7 @@ if (scratchieUser == null) { ScratchieSession session = LearningAction.service.getScratchieSessionBySessionId(sessionId); final ScratchieUser newScratchieUser = new ScratchieUser(user, session); - tryExecute(new Callable() { - @Override - public Object call() throws ScratchieApplicationException { - LearningAction.service.createUser(newScratchieUser); - return null; - } - }); + LearningAction.service.createUser(newScratchieUser); scratchieUser = newScratchieUser; }