Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/LearnerController.java =================================================================== diff -u -r3d9c6d823f8b59f95278f92c1c88038b21511f80 -r74cb30ff6ae06357ce3a28b12c574bbf92b814a4 --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/LearnerController.java (.../LearnerController.java) (revision 3d9c6d823f8b59f95278f92c1c88038b21511f80) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/LearnerController.java (.../LearnerController.java) (revision 74cb30ff6ae06357ce3a28b12c574bbf92b814a4) @@ -23,23 +23,9 @@ package org.lamsfoundation.lams.learning.web.controller; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Map.Entry; -import java.util.TimeZone; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; - +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.ObjectNode; import org.apache.log4j.Logger; import org.lamsfoundation.lams.flux.FluxMap; import org.lamsfoundation.lams.flux.FluxRegistry; @@ -75,6 +61,7 @@ import org.lamsfoundation.lams.util.DateUtil; import org.lamsfoundation.lams.util.MessageService; import org.lamsfoundation.lams.util.WebUtil; +import org.lamsfoundation.lams.util.hibernate.HibernateSessionManager; import org.lamsfoundation.lams.web.session.SessionManager; import org.lamsfoundation.lams.web.util.AttributeNames; import org.springframework.beans.factory.annotation.Autowired; @@ -86,13 +73,24 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.util.UriUtils; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.node.JsonNodeFactory; -import com.fasterxml.jackson.databind.node.ObjectNode; - import reactor.core.publisher.Flux; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Map.Entry; +import java.util.TimeZone; + /** *
* The action servlet that interacts with learner to start a lams learner module, join a user to the lesson and allows a @@ -148,21 +146,25 @@ public LearnerController() { FluxRegistry.initFluxMap(LEARNER_TIMELINE_FLUX_NAME, CommonConstants.ACTIVITY_ENTERED_SINK_NAME, - (LearnerActivityCompleteFluxItem item, - LearnerActivityCompleteFluxItem key) -> item.getLessonId() == key.getLessonId() - && item.getUserId() == key.getUserId(), + (LearnerActivityCompleteFluxItem item, LearnerActivityCompleteFluxItem key) -> + item.getLessonId() == key.getLessonId() && item.getUserId() == key.getUserId(), (LearnerActivityCompleteFluxItem item) -> { - ObjectNode responseJSON = null; try { - responseJSON = getLearnerProgress(item.getLessonId(), item.getUserId(), true); - if (responseJSON != null) { - return UriUtils.encode(responseJSON.toString(), StandardCharsets.UTF_8.toString()); + // without separate session the flux fetches cached data + HibernateSessionManager.openSession(); + ObjectNode responseJSON = null; + try { + responseJSON = getLearnerProgress(item.getLessonId(), item.getUserId(), true); + if (responseJSON != null) { + return UriUtils.encode(responseJSON.toString(), StandardCharsets.UTF_8.toString()); + } + } catch (Exception e) { + log.error("Error while getting learner timeline flux", e); } - } catch (Exception e) { - log.error("Error while getting learner timeline flux", e); + return ""; + } finally { + HibernateSessionManager.closeSession(); } - return ""; - }, FluxMap.STANDARD_THROTTLE, FluxMap.STANDARD_TIMEOUT); } @@ -184,18 +186,16 @@ *
* * @param mapping - * An ActionMapping class that will be used by the Action class to tell the ActionServlet where to send - * the end-user. - * + * An ActionMapping class that will be used by the Action class to tell the ActionServlet where to send the + * end-user. * @param form - * The ActionForm class that will contain any data submitted by the end-user via a form. + * The ActionForm class that will contain any data submitted by the end-user via a form. * @param request - * A standard Servlet HttpServletRequest class. + * A standard Servlet HttpServletRequest class. * @param response - * A standard Servlet HttpServletResponse class. + * A standard Servlet HttpServletResponse class. * @return An ActionForward class that will be returned to the ActionServlet indicating where the user is to go - * next. - * + * next. * @throws IOException * @throws ServletException */ @@ -490,8 +490,9 @@ if (activity.getChildActivities() != null) { for (ActivityURL childActivity : activity.getChildActivities()) { - activityJSON.withArray("childActivities").add( - activityProgressToJSON(childActivity, currentActivityId, lessonId, learnerId, monitorMode)); + activityJSON.withArray("childActivities") + .add(activityProgressToJSON(childActivity, currentActivityId, lessonId, learnerId, + monitorMode)); } }