Index: lams_central/src/java/org/lamsfoundation/lams/webservice/xml/LessonManagerServlet.java =================================================================== diff -u -rf3c1df459a445f75ad8279cf72cf5a1e97bd3112 -r7d898ea4d62e737512701712ddf4c5e1e0ac3021 --- lams_central/src/java/org/lamsfoundation/lams/webservice/xml/LessonManagerServlet.java (.../LessonManagerServlet.java) (revision f3c1df459a445f75ad8279cf72cf5a1e97bd3112) +++ lams_central/src/java/org/lamsfoundation/lams/webservice/xml/LessonManagerServlet.java (.../LessonManagerServlet.java) (revision 7d898ea4d62e737512701712ddf4c5e1e0ac3021) @@ -3,7 +3,6 @@ import java.io.File; import java.io.IOException; import java.io.PrintWriter; -import java.io.StringWriter; import java.rmi.RemoteException; import java.util.ArrayList; import java.util.Date; @@ -12,6 +11,7 @@ import java.util.List; import java.util.Set; import java.util.SortedMap; +import java.util.TreeSet; import java.util.Vector; import javax.servlet.ServletException; @@ -22,12 +22,8 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; @@ -61,20 +57,19 @@ import org.lamsfoundation.lams.util.DateUtil; import org.lamsfoundation.lams.web.session.SessionManager; import org.lamsfoundation.lams.web.util.AttributeNames; -import org.lamsfoundation.lams.workspace.service.IWorkspaceManagementService; import org.springframework.web.context.support.WebApplicationContextUtils; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; +import org.w3c.dom.ls.DOMImplementationLS; +import org.w3c.dom.ls.LSSerializer; public class LessonManagerServlet extends HttpServlet { private static Logger log = Logger.getLogger(LessonManagerServlet.class); private static IntegrationService integrationService = null; - private static IWorkspaceManagementService service = null; - private static IMonitoringService monitoringService = null; private static ILessonService lessonService = null; @@ -218,20 +213,20 @@ } else if (method.equals("toolOutputsAllUsers")) { lsId = new Long(lsIdStr); - element = getToolOutputs(document, serverId, datetime, hashValue, username, lsId, courseId, false); + element = getToolOutputs(document, serverId, datetime, hashValue, username, lsId, courseId, false, null); } else if (method.equals("authoredToolOutputsAllUsers")) { lsId = new Long(lsIdStr); - element = getToolOutputs(document, serverId, datetime, hashValue, username, lsId, courseId, true); + element = getToolOutputs(document, serverId, datetime, hashValue, username, lsId, courseId, true, null); } else if (method.equals("toolOutputsUser")) { lsId = new Long(lsIdStr); - element = getToolOutputsForUser(document, serverId, datetime, hashValue, username, lsId, courseId, + element = getToolOutputs(document, serverId, datetime, hashValue, username, lsId, courseId, false, outputsUser); } else if (method.equals("authoredToolOutputsUser")) { lsId = new Long(lsIdStr); - element = getToolOutputsForUser(document, serverId, datetime, hashValue, username, lsId, courseId, + element = getToolOutputs(document, serverId, datetime, hashValue, username, lsId, courseId, true, outputsUser); } else if (method.equals(CentralConstants.METHOD_VERIFY_EXT_SERVER)) { @@ -249,16 +244,13 @@ } document.appendChild(element); - + // write out the xml document. - DOMSource domSource = new DOMSource(document); - StringWriter writer = new StringWriter(); - StreamResult result = new StreamResult(writer); - TransformerFactory tf = TransformerFactory.newInstance(); - Transformer transformer = tf.newTransformer(); - transformer.transform(domSource, result); + DOMImplementationLS domImplementation = (DOMImplementationLS) document.getImplementation(); + LSSerializer lsSerializer = domImplementation.createLSSerializer(); + String documentStr = lsSerializer.writeToString(document); - out.write(writer.toString()); + out.write(documentStr); } catch (NumberFormatException nfe) { LessonManagerServlet.log.error("lsId or ldId is not an integer" + lsIdStr + ldIdStr, nfe); @@ -594,8 +586,6 @@ */ @Override public void init() throws ServletException { - LessonManagerServlet.service = (IWorkspaceManagementService) WebApplicationContextUtils - .getRequiredWebApplicationContext(getServletContext()).getBean("workspaceManagementService"); LessonManagerServlet.integrationService = (IntegrationService) WebApplicationContextUtils .getRequiredWebApplicationContext(getServletContext()).getBean("integrationService"); @@ -738,127 +728,144 @@ } /** + * This method gets the tool outputs for a lesson or a specific user and returns them in XML format. * - * This method gets the tool outputs for an entire lesson and returns them in an XML format. - * * @param document * @param serverId + * @param datetime * @param hashValue * @param username - * @param lsId + * @param lessonId * @param courseID * @param isAuthoredToolOutputs - * @throws Exception + * @param outputsUser if outputsUser is null return results for the whole lesson, otherwise - for the specified learner * @return + * @throws Exception */ @SuppressWarnings("unchecked") public Element getToolOutputs(Document document, String serverId, String datetime, String hashValue, - String username, Long lsId, String courseID, boolean isAuthoredToolOutputs) throws Exception { + String username, Long lessonId, String courseID, boolean isAuthoredToolOutputs, String outputsUser) + throws Exception { try { - ExtServerOrgMap serverMap = LessonManagerServlet.integrationService.getExtServerOrgMap(serverId); + ExtServerOrgMap serverMap = integrationService.getExtServerOrgMap(serverId); Authenticator.authenticate(serverMap, datetime, username, hashValue); + + Lesson lesson = lessonService.getLesson(lessonId); + if (lesson == null) { + // TODO: handle this error instead of throwing an exception + log.debug("No lesson exists for: " + lessonId + ". Cannot get tool outputs report."); + throw new Exception("Lesson with lessonID: " + lessonId + " could not be found for learner progresses"); + } - // Get the lesson and activitied given an lsId - Lesson lesson = LessonManagerServlet.lessonService.getLesson(lsId); - Set activities = lesson.getLearningDesign().getActivities(); - - // Create the root node of the xml document - Element toolOutputsElement = document.createElement("ToolOutputs"); - - if (lesson != null) { - LessonManagerServlet.log.debug("Getting tool ouputs report for: " + lsId + ". With learning design: " - + lesson.getLearningDesign().getLearningDesignId()); - - toolOutputsElement.setAttribute(CentralConstants.ATTR_LESSON_ID, "" + lsId); - toolOutputsElement.setAttribute("name", lesson.getLessonName()); - - Iterator learnerIterator = lesson.getAllLearners().iterator(); - while (learnerIterator.hasNext()) { - User learner = (User) learnerIterator.next(); - - String userNoPrefixName = learner.getLogin().substring(serverMap.getPrefix().length() + 1); - toolOutputsElement.appendChild(getLearnerOutputsElement(document, learner, lesson, activities, - isAuthoredToolOutputs, userNoPrefixName)); + Set activities = getLessonActivities(lesson); + + Set learners = new TreeSet(); + // if outputsUser is null we build results for the whole lesson, otherwise - for the specified learner + if (outputsUser != null) { + + ExtUserUseridMap userMap = integrationService.getExistingExtUserUseridMap(serverMap, outputsUser); + if (userMap == null) { + // TODO: handle this error instead of throwing an exception + log.debug("No user exists for: " + outputsUser + ". Cannot get tool outputs report."); + throw new Exception("No user exists for: " + outputsUser + ". Cannot get tool outputs report."); } + learners.add(userMap.getUser()); + } else { - // TODO: handle this error instead of throwing an exception - LessonManagerServlet.log.debug("No lesson exists for: " + lsId + ". Cannot get tool outputs report."); - throw new Exception("Lesson with lessonID: " + lsId + " could not be found for learner progresses"); + learners.addAll(lesson.getAllLearners()); + log.debug("Getting tool ouputs report for: " + lessonId + ". With learning design: " + + lesson.getLearningDesign().getLearningDesignId()); } - return toolOutputsElement; - - } catch (Exception e) { - LessonManagerServlet.log.error("Problem creating tool output report for lesson: " + lsId.toString(), e); - throw new Exception(e); - } - - } - - /** - * - * This method gets the tool outputs for a specific user in a lesson and returns them in XML format. - * - * @param document - * @param serverId - * @param hashValue - * @param username - * @param lsId - * @param courseID - * @param isAuthoredToolOutputs - * @param userId - * @throws Exception - * @return - */ - @SuppressWarnings("unchecked") - public Element getToolOutputsForUser(Document document, String serverId, String datetime, String hashValue, - String username, Long lsId, String courseID, boolean isAuthoredToolOutputs, String userStr) - throws Exception { - try { // Create the root node of the xml document Element toolOutputsElement = document.createElement("ToolOutputs"); - ExtServerOrgMap serverMap = LessonManagerServlet.integrationService.getExtServerOrgMap(serverId); + toolOutputsElement.setAttribute(CentralConstants.ATTR_LESSON_ID, "" + lessonId); + toolOutputsElement.setAttribute("name", lesson.getLessonName()); - Authenticator.authenticate(serverMap, datetime, username, hashValue); + List learnerProgresses = lessonService.getUserProgressForLesson(lesson.getLessonId()); + List toolSessions = toolService.getToolSessionsByLesson(lesson); + + for (User learner : learners) { - ExtUserUseridMap userMap = LessonManagerServlet.integrationService.getExistingExtUserUseridMap(serverMap, - userStr); - if (userMap != null) { - User learner = userMap.getUser(); + Element learnerElement = document.createElement("LearnerOutput"); - // Get the lesson and activitied given an lsId - Lesson lesson = LessonManagerServlet.lessonService.getLesson(lsId); - Set activities = lesson.getLearningDesign().getActivities(); + String userNoPrefixName = learner.getLogin().substring(serverMap.getPrefix().length() + 1); + learnerElement.setAttribute("userName", userNoPrefixName); + learnerElement.setAttribute("lamsUserName", learner.getLogin()); + learnerElement.setAttribute("lamsUserId", learner.getUserId().toString()); + learnerElement.setAttribute("firstName", learner.getFirstName()); + learnerElement.setAttribute("lastName", learner.getLastName()); - if (lesson != null) { - LessonManagerServlet.log.debug("Getting tool ouputs report for: " + lsId - + ". With learning design: " + lesson.getLearningDesign().getLearningDesignId()); + // find required learnerProgress from learnerProgresses (this way we don't querying DB). + LearnerProgress learnerProgress = null; + for (LearnerProgress dbLearnerProgress : learnerProgresses) { + if (dbLearnerProgress.getUser().getUserId().equals(learner.getUserId())) { + learnerProgress = dbLearnerProgress; + } + } + if (learnerProgress != null) { + learnerElement.setAttribute("completedLesson", "" + learnerProgress.isComplete()); + } - toolOutputsElement.setAttribute(CentralConstants.ATTR_LESSON_ID, "" + lsId); - toolOutputsElement.setAttribute("name", lesson.getLessonName()); - - String userNoPrefixName = learner.getLogin().substring(serverMap.getPrefix().length() + 1); - toolOutputsElement.appendChild(getLearnerOutputsElement(document, learner, lesson, activities, - isAuthoredToolOutputs, userNoPrefixName)); + for (ToolActivity activity : activities) { + // find required toolSession from toolSessions (this way we don't querying DB). + ToolSession toolSession = null; + for (ToolSession dbToolSession : toolSessions) { + if (dbToolSession.getToolActivity().getActivityId().equals(activity.getActivityId()) + && dbToolSession.getLearners().contains(learner)) { + toolSession = dbToolSession; + } + } + + learnerElement.appendChild(getActivityOutputsElement(document, activity, learner, learnerProgress, + toolSession, isAuthoredToolOutputs)); } - } else { - // TODO: handle this error instead of throwing an exception - LessonManagerServlet.log.debug("No user exists for: " + userStr + ". Cannot get tool outputs report."); - throw new Exception("No user exists for: " + userStr + ". Cannot get tool outputs report."); + + toolOutputsElement.appendChild(learnerElement); } return toolOutputsElement; } catch (Exception e) { - LessonManagerServlet.log.error("Problem creating tool output report for lesson: " + lsId.toString(), e); + LessonManagerServlet.log.error("Problem creating tool output report for lesson: " + lessonId.toString(), e); throw new Exception(e); } } /** + * Returns lesson tool activities. It works almost the same as lesson.getLearningDesign().getActivities() except it solves + * problem with first activity unable to cast to ToolActivity. + */ + private Set getLessonActivities(Lesson lesson) { + Set activities = new TreeSet(); + Set toolActivities = new TreeSet(); + + /* + * Hibernate CGLIB is failing to load the first activity in the sequence as a ToolActivity for some mysterious + * reason Causes a ClassCastException when you try to cast it, even if it is a ToolActivity. + * + * THIS IS A HACK to retrieve the first tool activity manually so it can be cast as a ToolActivity - if it is + * one + */ + Activity firstActivity = monitoringService.getActivityById(lesson.getLearningDesign().getFirstActivity() + .getActivityId()); + activities.add(firstActivity); + activities.addAll(lesson.getLearningDesign().getActivities()); + + for (Activity activity : activities) { + if (activity instanceof ToolActivity) { + ToolActivity toolActivity = (ToolActivity) activity; + toolActivities.add(toolActivity); + } + } + + return toolActivities; + } + + /** * Verifies external server. Also it has a WSDL analog * org.lamsfoundation.lams.webservice.VerificationServiceSoapBindingImpl * @@ -868,7 +875,7 @@ * @return * @throws Exception */ - public boolean verify(String serverId, String datetime, String hash) throws Exception { + private boolean verify(String serverId, String datetime, String hash) throws Exception { try { ExtServerOrgMap serverMap = integrationService.getExtServerOrgMap(serverId); Authenticator.authenticate(serverMap, datetime, hash); @@ -880,89 +887,30 @@ } /** - * Gets the outputs for an activity for a specific learner and returns them in XML format - * - * @param document - * @param learner - * @param lesson - * @param activities - * @param isAuthoredToolOutputs - * @return - */ - private Element getLearnerOutputsElement(Document document, User learner, Lesson lesson, Set activities, - boolean isAuthoredToolOutputs, String userNoPrefixName) { - Element learnerElement = document.createElement("LearnerOutput"); - - learnerElement.setAttribute("userName", userNoPrefixName); - learnerElement.setAttribute("lamsUserName", learner.getLogin()); - learnerElement.setAttribute("lamsUserId", learner.getUserId().toString()); - learnerElement.setAttribute("firstName", learner.getFirstName()); - learnerElement.setAttribute("lastName", learner.getLastName()); - - LearnerProgress learnerProgress = LessonManagerServlet.monitoringService.getLearnerProgress( - learner.getUserId(), lesson.getLessonId()); - - if (learnerProgress != null) { - learnerElement.setAttribute("completedLesson", "" + learnerProgress.isComplete()); - } - - /* - * Hibernate CGLIB is failing to load the first activity in the sequence as a ToolActivity for some mysterious - * reason Causes a ClassCastException when you try to cast it, even if it is a ToolActivity. - * - * THIS IS A HACK to retrieve the first tool activity manually so it can be cast as a ToolActivity - */ - Activity firstActivity = LessonManagerServlet.monitoringService.getActivityById(lesson.getLearningDesign() - .getFirstActivity().getActivityId()); - LessonManagerServlet.log.debug("Getting tool ouputs for first activity: " + firstActivity.getActivityId() - + ". For user: " + learner.getUserId()); - if (firstActivity.isToolActivity() && (firstActivity instanceof ToolActivity)) { - learnerElement.appendChild(getActivityOutputsElement(document, (ToolActivity) firstActivity, learner, - learnerProgress, isAuthoredToolOutputs)); - } - - for (Activity activity : activities) { - - if (activity.getActivityId().longValue() != firstActivity.getActivityId().longValue()) { - - LessonManagerServlet.log.debug("Getting tool ouputs for activity: " + activity.getActivityId() - + ". For user: " + learner.getUserId()); - - if (activity.isToolActivity() && (activity instanceof ToolActivity)) { - - learnerElement.appendChild(getActivityOutputsElement(document, (ToolActivity) activity, learner, - learnerProgress, isAuthoredToolOutputs)); - } - } - } - return learnerElement; - } - - /** * Gets the tool output for a specified activity and learner and returns an XML representation of the data * * @param document - * @param toolAct + * @param activity * @param learner * @param progress * @param isAuthoredToolOutputs * @return */ - private Element getActivityOutputsElement(Document document, ToolActivity toolAct, User learner, - LearnerProgress progress, boolean isAuthoredToolOutputs) { + private Element getActivityOutputsElement(Document document, ToolActivity activity, User learner, + LearnerProgress progress, ToolSession toolSession, boolean isAuthoredToolOutputs) { Element activityElement = document.createElement("Activity"); - activityElement.setAttribute("title", toolAct.getTitle()); - activityElement.setAttribute("activityId", toolAct.getActivityId().toString()); - if (toolAct.getOrderId() != null) { - activityElement.setAttribute("orderId", toolAct.getOrderId().toString()); + activityElement.setAttribute("title", activity.getTitle()); + activityElement.setAttribute("activityId", activity.getActivityId().toString()); + if (activity.getOrderId() != null) { + activityElement.setAttribute("orderId", activity.getOrderId().toString()); } boolean activityAttempted = false; if (progress != null) { - boolean completed = progress.getProgressState(toolAct) == LearnerProgress.ACTIVITY_COMPLETED; + boolean completed = progress.getProgressState(activity) == LearnerProgress.ACTIVITY_COMPLETED; activityElement.setAttribute("completed", "" + completed); - activityAttempted = completed || (progress.getProgressState(toolAct) == LearnerProgress.ACTIVITY_ATTEMPTED); + activityAttempted = completed || (progress.getProgressState(activity) == LearnerProgress.ACTIVITY_ATTEMPTED); activityElement.setAttribute("attempted", "" + activityAttempted); } else { @@ -971,10 +919,8 @@ } if (activityAttempted) { - ToolSession toolSession = LessonManagerServlet.toolService.getToolSessionByLearner(learner, toolAct); - SortedMap map = LessonManagerServlet.toolService - .getOutputDefinitionsFromTool(toolAct.getToolContentId(), - ToolOutputDefinition.DATA_OUTPUT_DEFINITION_TYPE_CONDITION); + SortedMap map = toolService.getOutputDefinitionsFromTool( + activity.getToolContentId(), ToolOutputDefinition.DATA_OUTPUT_DEFINITION_TYPE_CONDITION); if (toolSession != null) { @@ -984,19 +930,19 @@ ToolOutputDefinition definition = map.get(outputName); if (isAuthoredToolOutputs) { - Set activityEvaluations = toolAct.getActivityEvaluations(); + Set activityEvaluations = activity.getActivityEvaluations(); if (activityEvaluations != null) { for (ActivityEvaluation evaluation : activityEvaluations) { if (outputName.equals(evaluation.getToolOutputDefinition())) { - ToolOutput toolOutput = LessonManagerServlet.toolService.getOutputFromTool( - outputName, toolSession, learner.getUserId()); + ToolOutput toolOutput = toolService.getOutputFromTool(outputName, toolSession, + learner.getUserId()); activityElement.appendChild(getOutputElement(document, toolOutput, definition)); } } } } else { - ToolOutput toolOutput = LessonManagerServlet.toolService.getOutputFromTool(outputName, - toolSession, learner.getUserId()); + ToolOutput toolOutput = toolService.getOutputFromTool(outputName, toolSession, + learner.getUserId()); if (toolOutput != null) { activityElement.appendChild(getOutputElement(document, toolOutput, definition)); @@ -1006,8 +952,8 @@ } } catch (RuntimeException e) { - LessonManagerServlet.log.debug("Runtime exception when attempted to get outputs for activity: " - + toolAct.getActivityId() + ", continuing for other activities", e); + log.debug("Runtime exception when attempted to get outputs for activity: " + + activity.getActivityId() + ", continuing for other activities", e); } } Index: lams_common/src/java/org/lamsfoundation/lams/lesson/dao/ILearnerProgressDAO.java =================================================================== diff -u -rc5afbded875388afbb25dcdc972af56bf021658a -r7d898ea4d62e737512701712ddf4c5e1e0ac3021 --- lams_common/src/java/org/lamsfoundation/lams/lesson/dao/ILearnerProgressDAO.java (.../ILearnerProgressDAO.java) (revision c5afbded875388afbb25dcdc972af56bf021658a) +++ lams_common/src/java/org/lamsfoundation/lams/lesson/dao/ILearnerProgressDAO.java (.../ILearnerProgressDAO.java) (revision 7d898ea4d62e737512701712ddf4c5e1e0ac3021) @@ -35,109 +35,129 @@ /** * Inteface defines Lesson DAO Methods + * * @author chris */ -public interface ILearnerProgressDAO -{ - +public interface ILearnerProgressDAO { + /** * Retrieves the Lesson - * @param lessonId identifies the lesson to get + * + * @param lessonId + * identifies the lesson to get * @return the lesson */ - public LearnerProgress getLearnerProgress(Long learnerProgressId); - + LearnerProgress getLearnerProgress(Long learnerProgressId); + /** * Retrieves the learner progress object for user in a lesson. - * @param learnerId the user who owns the learner progress data. - * @param lessonId the lesson for which the progress data applies + * + * @param learnerId + * the user who owns the learner progress data. + * @param lessonId + * the lesson for which the progress data applies * @return the user's progress data */ - public LearnerProgress getLearnerProgressByLearner(final Integer learnerId, final Long lessonId); - + LearnerProgress getLearnerProgressByLearner(final Integer learnerId, final Long lessonId); + /** * Saves or Updates learner progress data. - * @param learnerProgress holds the learne progress data + * + * @param learnerProgress + * holds the learne progress data */ - public void saveLearnerProgress(LearnerProgress learnerProgress); - + void saveLearnerProgress(LearnerProgress learnerProgress); + /** * Deletes a LearnerProgress data permanently. - * @param learnerProgress + * + * @param learnerProgress */ - public void deleteLearnerProgress(LearnerProgress learnerProgress); - + void deleteLearnerProgress(LearnerProgress learnerProgress); + /** * Update learner progress data. + * * @param learnerProgress */ - public void updateLearnerProgress(LearnerProgress learnerProgress); + void updateLearnerProgress(LearnerProgress learnerProgress); /** * Get all the learner progress records where the current, previous or next activity is the given activity. + * * @param activity * @return List */ - public List getLearnerProgressReferringToActivity(final Activity activity); - + List getLearnerProgressReferringToActivity(final Activity activity); + /** * Get all the learner progress records for a lesson where the progress is marked as completed. + * * @param lessonId * @return List */ - public List getCompletedLearnerProgressForLesson(final Long lessonId); - + List getCompletedLearnerProgressForLesson(final Long lessonId); + /** - * Get all the users records where the user has attempted the given activity. Uses the progress records - * to determine the users. + * Get all the learner progress records for a lesson. * + * @param lessonId + * @return + */ + List getLearnerProgressForLesson(final Long lessonId); + + /** + * Get all the users records where the user has attempted the given activity. Uses the progress records to determine + * the users. + * * @param activityId * @return List */ - public List getLearnersHaveAttemptedActivity(final Activity activity); - - /** - * Get all the users records where the user has completed the given activity. Uses the progress records - * to determine the users. + List getLearnersHaveAttemptedActivity(final Activity activity); + + /** + * Get all the users records where the user has completed the given activity. Uses the progress records to determine + * the users. * * @param activityId * @return List */ - public List getLearnersHaveCompletedActivity(final Activity activity); - - /** - * Count of the number of users that have attempted or completed an activity. Useful for activities that don't have + List getLearnersHaveCompletedActivity(final Activity activity); + + /** + * Count of the number of users that have attempted or completed an activity. Useful for activities that don't have * tool sessions. * * @param activityId * @return List */ - public Integer getNumUsersAttemptedActivity(final Activity activity); + Integer getNumUsersAttemptedActivity(final Activity activity); - - /** - * Count of the number of users that have completed an activity. Useful for activities that don't have - * tool sessions. + /** + * Count of the number of users that have completed an activity. Useful for activities that don't have tool + * sessions. * * @param activityId * @return List */ - public Integer getNumUsersCompletedActivity(final Activity activity) ; - - /** + Integer getNumUsersCompletedActivity(final Activity activity); + + /** * Get the count of all learner progress records for an lesson without loading the records. + * * @return Number of learner progress records for this lesson */ - public Integer getNumAllLearnerProgress(final Long lessonId); + Integer getNumAllLearnerProgress(final Long lessonId); - /** - * Get a batch of learner progress records (size batchSize) for an lesson, sorted by surname and the first name. Start at the beginning - * of the table if no previousUserId is given, otherwise get the batch after lastUserId. + /** + * Get a batch of learner progress records (size batchSize) for an lesson, sorted by surname and the first name. + * Start at the beginning of the table if no previousUserId is given, otherwise get the batch after lastUserId. + * * @param lessonId * @param lastUserId * @param batchSize * @return List */ - public List getBatchLearnerProgress(final Long lessonId, final User lastUser, final int batchSize); + List getBatchLearnerProgress(final Long lessonId, final User lastUser, final int batchSize); - } +} Index: lams_common/src/java/org/lamsfoundation/lams/lesson/dao/hibernate/LearnerProgressDAO.java =================================================================== diff -u -racc8d2acf5b6b0002e0c8129947040a779ab4077 -r7d898ea4d62e737512701712ddf4c5e1e0ac3021 --- lams_common/src/java/org/lamsfoundation/lams/lesson/dao/hibernate/LearnerProgressDAO.java (.../LearnerProgressDAO.java) (revision acc8d2acf5b6b0002e0c8129947040a779ab4077) +++ lams_common/src/java/org/lamsfoundation/lams/lesson/dao/hibernate/LearnerProgressDAO.java (.../LearnerProgressDAO.java) (revision 7d898ea4d62e737512701712ddf4c5e1e0ac3021) @@ -37,294 +37,194 @@ import org.springframework.orm.hibernate3.support.HibernateDaoSupport; /** - * Hibernate implementation of ILessonDAO + * Hibernate implementation of ILearnerProgressDAO + * * @author chris */ -public class LearnerProgressDAO extends HibernateDaoSupport implements ILearnerProgressDAO -{ +public class LearnerProgressDAO extends HibernateDaoSupport implements ILearnerProgressDAO { - protected Logger log = Logger.getLogger(LearnerProgressDAO.class); + protected Logger log = Logger.getLogger(LearnerProgressDAO.class); - private final static String LOAD_PROGRESS_BY_LEARNER = - "from LearnerProgress p where p.user.id = :learnerId and p.lesson.id = :lessonId"; - private final static String LOAD_PROGRESS_BY_ACTIVITY = - "from LearnerProgress p where p.previousActivity = :activity or p.currentActivity = :activity or p.nextActivity = :activity "; - // + - // "or activity in elements(p.previousActivity) or activity in elements(p.completedActivities)"; - private final static String LOAD_COMPLETED_PROGRESS_BY_LESSON = - "from LearnerProgress p where p.lessonComplete > 0 and p.lesson.id = :lessonId"; + private final static String LOAD_PROGRESS_BY_LEARNER = "from LearnerProgress p where p.user.id = :learnerId and p.lesson.id = :lessonId"; + private final static String LOAD_PROGRESS_BY_ACTIVITY = "from LearnerProgress p where p.previousActivity = :activity or p.currentActivity = :activity or p.nextActivity = :activity "; + // + + // "or activity in elements(p.previousActivity) or activity in elements(p.completedActivities)"; + private final static String LOAD_COMPLETED_PROGRESS_BY_LESSON = "from LearnerProgress p where p.lessonComplete > 0 and p.lesson.id = :lessonId"; - private final static String COUNT_ATTEMPTED_ACTIVITY ="select count(*) from LearnerProgress prog, " - +" Activity act join prog.attemptedActivities attAct " - +" where act.id = :activityId and " - +" index(attAct) = act"; - private final static String COUNT_COMPLETED_ACTIVITY ="select count(*) from LearnerProgress prog, " - +" Activity act join prog.completedActivities compAct " - +" where act.id = :activityId and " - +" index(compAct) = act"; + private final static String COUNT_ATTEMPTED_ACTIVITY = "select count(*) from LearnerProgress prog, " + + " Activity act join prog.attemptedActivities attAct " + " where act.id = :activityId and " + + " index(attAct) = act"; + private final static String COUNT_COMPLETED_ACTIVITY = "select count(*) from LearnerProgress prog, " + + " Activity act join prog.completedActivities compAct " + " where act.id = :activityId and " + + " index(compAct) = act"; - private final static String COUNT_PROGRESS_BY_LESSON = - "select count(*) from LearnerProgress p where p.lesson.id = :lessonId"; - private final static String LOAD_PROGRESS_BY_LESSON = - "from LearnerProgress p where p.lesson.id = :lessonId order by p.user.lastName, p.user.firstName, p.user.userId"; - private final static String LOAD_NEXT_BATCH_PROGRESS_BY_LESSON = - "from LearnerProgress p where p.lesson.id = :lessonId " - +" and (( p.user.lastName > :lastUserLastName)" - +" or ( p.user.lastName = :lastUserLastName and p.user.firstName > :lastUserFirstName) " - +" or ( p.user.lastName = :lastUserLastName and p.user.firstName = :lastUserFirstName and p.user.userId > :lastUserId))" - +" order by p.user.lastName, p.user.firstName, p.user.userId"; + private final static String COUNT_PROGRESS_BY_LESSON = "select count(*) from LearnerProgress p where p.lesson.id = :lessonId"; + private final static String LOAD_PROGRESS_BY_LESSON = "from LearnerProgress p where p.lesson.id = :lessonId order by p.user.lastName, p.user.firstName, p.user.userId"; + private final static String LOAD_NEXT_BATCH_PROGRESS_BY_LESSON = "from LearnerProgress p where p.lesson.id = :lessonId " + + " and (( p.user.lastName > :lastUserLastName)" + + " or ( p.user.lastName = :lastUserLastName and p.user.firstName > :lastUserFirstName) " + + " or ( p.user.lastName = :lastUserLastName and p.user.firstName = :lastUserFirstName and p.user.userId > :lastUserId))" + + " order by p.user.lastName, p.user.firstName, p.user.userId"; - /** - * Retrieves the Lesson - * @param lessonId identifies the lesson to get - * @return the lesson - */ - public LearnerProgress getLearnerProgress(Long learnerProgressId) - { - return (LearnerProgress)getHibernateTemplate().get(LearnerProgress.class, learnerProgressId); + @Override + public LearnerProgress getLearnerProgress(Long learnerProgressId) { + return (LearnerProgress) getHibernateTemplate().get(LearnerProgress.class, learnerProgressId); } - - /** - * Saves or Updates learner progress data. - * @param learnerProgress holds the learner progress data - */ - public void saveLearnerProgress(LearnerProgress learnerProgress) - { - getHibernateTemplate().save(learnerProgress); + + @Override + public void saveLearnerProgress(LearnerProgress learnerProgress) { + getHibernateTemplate().save(learnerProgress); } - - /** - * Deletes a LearnerProgress data permanently. - * @param learnerProgress - */ - public void deleteLearnerProgress(LearnerProgress learnerProgress) - { - getHibernateTemplate().delete(learnerProgress); + + @Override + public void deleteLearnerProgress(LearnerProgress learnerProgress) { + getHibernateTemplate().delete(learnerProgress); } - /** - * @see org.lamsfoundation.lams.lesson.dao.ILearnerProgressDAO#getLearnerProgressByLeaner(java.lang.Integer,java.lang.Long) - */ - public LearnerProgress getLearnerProgressByLearner(final Integer learnerId, final Long lessonId) - { - HibernateTemplate hibernateTemplate = new HibernateTemplate(this.getSessionFactory()); + @Override + public LearnerProgress getLearnerProgressByLearner(final Integer learnerId, final Long lessonId) { + HibernateTemplate hibernateTemplate = new HibernateTemplate(this.getSessionFactory()); - return (LearnerProgress)hibernateTemplate.execute( - new HibernateCallback() - { - public Object doInHibernate(Session session) throws HibernateException - { - return session.createQuery(LOAD_PROGRESS_BY_LEARNER) - .setInteger("learnerId",learnerId) - .setLong("lessonId",lessonId) - .uniqueResult(); - } - } - ); + return (LearnerProgress) hibernateTemplate.execute(new HibernateCallback() { + public Object doInHibernate(Session session) throws HibernateException { + return session.createQuery(LOAD_PROGRESS_BY_LEARNER).setInteger("learnerId", learnerId) + .setLong("lessonId", lessonId).uniqueResult(); + } + }); } - /** - * @see org.lamsfoundation.lams.lesson.dao.ILearnerProgressDAO#updateLearnerProgress(org.lamsfoundation.lams.lesson.LearnerProgress) - */ - public void updateLearnerProgress(LearnerProgress learnerProgress) - { - this.getHibernateTemplate().update(learnerProgress); + @Override + public void updateLearnerProgress(LearnerProgress learnerProgress) { + this.getHibernateTemplate().update(learnerProgress); } - - /** - * Get all the learner progress records where the current, previous or next activity is the given activity. - * @param activity - * @return List - */ - public List getLearnerProgressReferringToActivity(final Activity activity) - { - HibernateTemplate hibernateTemplate = new HibernateTemplate(this.getSessionFactory()); - return (List)hibernateTemplate.execute( - new HibernateCallback() - { - public Object doInHibernate(Session session) throws HibernateException - { - return session.createQuery(LOAD_PROGRESS_BY_ACTIVITY) - .setEntity("activity",activity) - .list(); - } - } - ); + @Override + public List getLearnerProgressReferringToActivity(final Activity activity) { + HibernateTemplate hibernateTemplate = new HibernateTemplate(this.getSessionFactory()); + + return (List) hibernateTemplate.execute(new HibernateCallback() { + public Object doInHibernate(Session session) throws HibernateException { + return session.createQuery(LOAD_PROGRESS_BY_ACTIVITY).setEntity("activity", activity).list(); + } + }); } - /** - * Get all the learner progress records for a lesson where the progress is marked as completed. - * @param lessonId - * @return List - */ - public List getCompletedLearnerProgressForLesson(final Long lessonId) - { - HibernateTemplate hibernateTemplate = new HibernateTemplate(this.getSessionFactory()); + @Override + public List getCompletedLearnerProgressForLesson(final Long lessonId) { + HibernateTemplate hibernateTemplate = new HibernateTemplate(this.getSessionFactory()); - return (List)hibernateTemplate.execute( - new HibernateCallback() - { - public Object doInHibernate(Session session) throws HibernateException - { - return session.createQuery(LOAD_COMPLETED_PROGRESS_BY_LESSON) - .setLong("lessonId",lessonId) - .list(); - } - } - ); + return (List) hibernateTemplate.execute(new HibernateCallback() { + public Object doInHibernate(Session session) throws HibernateException { + return session.createQuery(LOAD_COMPLETED_PROGRESS_BY_LESSON).setLong("lessonId", lessonId).list(); + } + }); } + + @Override + public List getLearnerProgressForLesson(final Long lessonId) { + HibernateTemplate hibernateTemplate = new HibernateTemplate(this.getSessionFactory()); - /** - * Get all the users records where the user has attempted the given activity. Uses the progress records - * to determine the users. - * - * @param activityId - * @return List - */ - @SuppressWarnings("unchecked") - public List getLearnersHaveAttemptedActivity(final Activity activity) - { - List learners = null; - - HibernateTemplate hibernateTemplate = new HibernateTemplate(this.getSessionFactory()); - learners = (List) hibernateTemplate.execute( - new HibernateCallback() { - public Object doInHibernate(Session session) throws HibernateException { - return session.getNamedQuery("usersAttemptedActivity") - .setLong("activityId", activity.getActivityId().longValue()) - .list(); - } - } - ); - - return learners; + return (List) hibernateTemplate.execute(new HibernateCallback() { + public Object doInHibernate(Session session) throws HibernateException { + return session.createQuery(LOAD_PROGRESS_BY_LESSON).setLong("lessonId", lessonId).list(); + } + }); } - - /** - * Count of the number of users that have attempted or completed an activity. Useful for activities that don't have - * tool sessions. - * - * @param activityId - * @return List - */ - public Integer getNumUsersAttemptedActivity(final Activity activity) - { - HibernateTemplate hibernateTemplate = new HibernateTemplate(this.getSessionFactory()); - Integer attempted = (Integer) hibernateTemplate.execute(new HibernateCallback() { - public Object doInHibernate(Session session) - throws HibernateException { - Object value = session.createQuery(COUNT_ATTEMPTED_ACTIVITY) - .setLong("activityId", activity.getActivityId().longValue()) - .uniqueResult(); - return new Integer (((Number)value).intValue()); - } - }); - return new Integer(attempted.intValue() + getNumUsersCompletedActivity(activity).intValue()); + + @Override + @SuppressWarnings("unchecked") + public List getLearnersHaveAttemptedActivity(final Activity activity) { + List learners = null; + + HibernateTemplate hibernateTemplate = new HibernateTemplate(this.getSessionFactory()); + learners = (List) hibernateTemplate.execute(new HibernateCallback() { + public Object doInHibernate(Session session) throws HibernateException { + return session.getNamedQuery("usersAttemptedActivity") + .setLong("activityId", activity.getActivityId().longValue()).list(); + } + }); + + return learners; } - - /** - * Get all the users records where the user has completed the given activity. Uses the progress records - * to determine the users. - * - * @param activityId - * @return List - */ - @SuppressWarnings("unchecked") - public List getLearnersHaveCompletedActivity(final Activity activity) - { - List learners = null; - - HibernateTemplate hibernateTemplate = new HibernateTemplate(this.getSessionFactory()); - learners = (List) hibernateTemplate.execute( - new HibernateCallback() { - public Object doInHibernate(Session session) throws HibernateException { - return session.getNamedQuery("usersCompletedActivity") - .setLong("activityId", activity.getActivityId().longValue()) - .list(); - } - } - ); - - return learners; + @Override + public Integer getNumUsersAttemptedActivity(final Activity activity) { + HibernateTemplate hibernateTemplate = new HibernateTemplate(this.getSessionFactory()); + Integer attempted = (Integer) hibernateTemplate.execute(new HibernateCallback() { + public Object doInHibernate(Session session) throws HibernateException { + Object value = session.createQuery(COUNT_ATTEMPTED_ACTIVITY) + .setLong("activityId", activity.getActivityId().longValue()).uniqueResult(); + return new Integer(((Number) value).intValue()); + } + }); + return new Integer(attempted.intValue() + getNumUsersCompletedActivity(activity).intValue()); } - - /** - * Count of the number of users that have completed an activity. Useful for activities that don't have - * tool sessions. - * - * @param activityId - * @return List - */ - public Integer getNumUsersCompletedActivity(final Activity activity) - { - HibernateTemplate hibernateTemplate = new HibernateTemplate(this.getSessionFactory()); - return (Integer) hibernateTemplate.execute(new HibernateCallback() { - public Object doInHibernate(Session session) - throws HibernateException { - Object value = session.createQuery(COUNT_COMPLETED_ACTIVITY) - .setLong("activityId", activity.getActivityId().longValue()) - .uniqueResult(); - return new Integer (((Number)value).intValue()); - } - }); + + @Override + @SuppressWarnings("unchecked") + public List getLearnersHaveCompletedActivity(final Activity activity) { + List learners = null; + + HibernateTemplate hibernateTemplate = new HibernateTemplate(this.getSessionFactory()); + learners = (List) hibernateTemplate.execute(new HibernateCallback() { + public Object doInHibernate(Session session) throws HibernateException { + return session.getNamedQuery("usersCompletedActivity") + .setLong("activityId", activity.getActivityId().longValue()).list(); + } + }); + + return learners; } - /** - * Get the count of all learner progress records for an lesson without loading the records. - * @return Number of learner progress records for this lesson - */ - public Integer getNumAllLearnerProgress(final Long lessonId) - { - HibernateTemplate hibernateTemplate = new HibernateTemplate(this.getSessionFactory()); - return (Integer) hibernateTemplate.execute(new HibernateCallback() { - public Object doInHibernate(Session session) - throws HibernateException { - Object value = session.createQuery(COUNT_PROGRESS_BY_LESSON) - .setLong("lessonId", lessonId.longValue()) - .uniqueResult(); - return new Integer (((Number)value).intValue()); - } - }); + @Override + public Integer getNumUsersCompletedActivity(final Activity activity) { + HibernateTemplate hibernateTemplate = new HibernateTemplate(this.getSessionFactory()); + return (Integer) hibernateTemplate.execute(new HibernateCallback() { + public Object doInHibernate(Session session) throws HibernateException { + Object value = session.createQuery(COUNT_COMPLETED_ACTIVITY) + .setLong("activityId", activity.getActivityId().longValue()).uniqueResult(); + return new Integer(((Number) value).intValue()); + } + }); } - /** - * Get a batch of learner progress records (size batchSize) for an lesson, sorted by surname and the first name. Start at the beginning - * of the table if no lastUser is given, otherwise get the batch after lastUser. - * @param lessonId - * @param lastUser - * @param batchSize - * @return List - */ - @SuppressWarnings("unchecked") - public List getBatchLearnerProgress(final Long lessonId, final User lastUser, final int batchSize) - { - HibernateTemplate hibernateTemplate = new HibernateTemplate(this.getSessionFactory()); - if ( lastUser == null ) { - return (List) hibernateTemplate.execute(new HibernateCallback() { - public Object doInHibernate(Session session) - throws HibernateException { - return session.createQuery(LOAD_PROGRESS_BY_LESSON) - .setLong("lessonId", lessonId.longValue()) - .setMaxResults(batchSize) - .list(); - } - }); - } else { - return (List) hibernateTemplate.execute(new HibernateCallback() { - public Object doInHibernate(Session session) - throws HibernateException { - return session.createQuery(LOAD_NEXT_BATCH_PROGRESS_BY_LESSON) - .setLong("lessonId", lessonId.longValue()) - .setString("lastUserLastName", lastUser.getLastName()) - .setString("lastUserFirstName", lastUser.getFirstName()) - .setInteger("lastUserId", lastUser.getUserId().intValue()) - .setMaxResults(batchSize) - .list(); - } - }); - } + @Override + public Integer getNumAllLearnerProgress(final Long lessonId) { + HibernateTemplate hibernateTemplate = new HibernateTemplate(this.getSessionFactory()); + return (Integer) hibernateTemplate.execute(new HibernateCallback() { + public Object doInHibernate(Session session) throws HibernateException { + Object value = session.createQuery(COUNT_PROGRESS_BY_LESSON).setLong("lessonId", lessonId.longValue()) + .uniqueResult(); + return new Integer(((Number) value).intValue()); + } + }); } + @Override + @SuppressWarnings("unchecked") + public List getBatchLearnerProgress(final Long lessonId, final User lastUser, final int batchSize) { + HibernateTemplate hibernateTemplate = new HibernateTemplate(this.getSessionFactory()); + + if (lastUser == null) { + return (List) hibernateTemplate.execute(new HibernateCallback() { + public Object doInHibernate(Session session) throws HibernateException { + return session.createQuery(LOAD_PROGRESS_BY_LESSON) + .setLong("lessonId", lessonId.longValue()) + .setMaxResults(batchSize).list(); + } + }); + + } else { + return (List) hibernateTemplate.execute(new HibernateCallback() { + public Object doInHibernate(Session session) throws HibernateException { + return session.createQuery(LOAD_NEXT_BATCH_PROGRESS_BY_LESSON) + .setLong("lessonId", lessonId.longValue()) + .setString("lastUserLastName", lastUser.getLastName()) + .setString("lastUserFirstName", lastUser.getFirstName()) + .setInteger("lastUserId", lastUser.getUserId().intValue()).setMaxResults(batchSize).list(); + } + }); + } + } + } Index: lams_common/src/java/org/lamsfoundation/lams/lesson/service/ILessonService.java =================================================================== diff -u -r6950295e2d5e90ffae268faeae946718654ddc7b -r7d898ea4d62e737512701712ddf4c5e1e0ac3021 --- lams_common/src/java/org/lamsfoundation/lams/lesson/service/ILessonService.java (.../ILessonService.java) (revision 6950295e2d5e90ffae268faeae946718654ddc7b) +++ lams_common/src/java/org/lamsfoundation/lams/lesson/service/ILessonService.java (.../ILessonService.java) (revision 7d898ea4d62e737512701712ddf4c5e1e0ac3021) @@ -55,25 +55,24 @@ * the functionality at present. If this is required later it should be combined with the user's shared session logic * and will need to purge users who haven't done anything for a while - otherwise a user whose PC has crashed and then * never returns to a lesson will staying in the cache forever. - */ -/** + * * @author lfoxton - * + * */ public interface ILessonService { /** Get all the learners who have started the lesson. They may not be currently online. */ - public abstract List getActiveLessonLearners(Long lessonId); + abstract List getActiveLessonLearners(Long lessonId); /** * Get all the learners who have started the lesson and are part of a given group. They may not be currently online. */ - public abstract List getActiveLessonLearnersByGroup(Long lessonId, Long groupId); + abstract List getActiveLessonLearnersByGroup(Long lessonId, Long groupId); /** * Get the count of all the learners who have started the lesson. They may not be currently online. */ - public Integer getCountActiveLessonLearners(Long lessonId); + Integer getCountActiveLessonLearners(Long lessonId); /** * Get the lesson details for the LAMS client. Suitable for the monitoring client. Contains a count of the total @@ -83,15 +82,15 @@ * @param lessonId * @return lesson details */ - public abstract LessonDetailsDTO getLessonDetails(Long lessonId); + abstract LessonDetailsDTO getLessonDetails(Long lessonId); /** * Get the lesson object. * * @param lessonId * @return lesson details */ - public abstract Lesson getLesson(Long lessonId); + abstract Lesson getLesson(Long lessonId); /** * Get the lesson details for the LAMS client. Suitable for the learner client. Contains a reduced number of fields @@ -100,7 +99,7 @@ * @param lessonId * @return lesson details */ - public abstract LessonDTO getLessonData(Long lessonId); + abstract LessonDTO getLessonData(Long lessonId); /** * If the supplied learner is not already in a group, then perform grouping for the learners who have started the @@ -115,8 +114,7 @@ * @param learner * the learner to be check before grouping. (mandatory) */ - public void performGrouping(Long lessonId, GroupingActivity groupingActivity, User learner) - throws LessonServiceException; + void performGrouping(Long lessonId, GroupingActivity groupingActivity, User learner) throws LessonServiceException; /** * Perform the grouping, setting the given list of learners as one group. @@ -128,7 +126,7 @@ * @param learners * to form one group (mandatory) */ - public void performGrouping(GroupingActivity groupingActivity, String groupName, List learners) + void performGrouping(GroupingActivity groupingActivity, String groupName, List learners) throws LessonServiceException; /** @@ -142,7 +140,7 @@ * @param learners * to form one group (mandatory) */ - public void performGrouping(Grouping grouping, String groupName, List learners) throws LessonServiceException; + void performGrouping(Grouping grouping, String groupName, List learners) throws LessonServiceException; /** * Perform grouping for all the learners who have started the lesson, based on the grouping. Currently used for @@ -155,7 +153,7 @@ * @param grouping * the object on which to perform the grouing. (mandatory) */ - public void performGrouping(Grouping grouping, Long groupId, List learners) throws LessonServiceException; + void performGrouping(Grouping grouping, Long groupId, List learners) throws LessonServiceException; /** * Perform grouping for the given learner. @@ -168,7 +166,7 @@ * learner to group (mandatory) * @throws LessonServiceException */ - public void performGrouping(Grouping grouping, Long groupId, User learner) throws LessonServiceException; + void performGrouping(Grouping grouping, Long groupId, User learner) throws LessonServiceException; /** * Remove learners from the given group. @@ -180,8 +178,7 @@ * @param learners * the learners to be removed (mandatory) */ - public void removeLearnersFromGroup(Grouping grouping, Long groupId, List learners) - throws LessonServiceException; + void removeLearnersFromGroup(Grouping grouping, Long groupId, List learners) throws LessonServiceException; /** * Create an empty group for the given grouping. If the group name already exists then it will force the name to be @@ -193,7 +190,7 @@ * (mandatory) * @return the new group */ - public Group createGroup(Grouping grouping, String name) throws LessonServiceException; + Group createGroup(Grouping grouping, String name) throws LessonServiceException; /** * Remove a group for the given grouping. If the group is already used (e.g. a tool session exists) then it throws a @@ -204,15 +201,15 @@ * @param groupName * (mandatory) */ - public void removeGroup(Grouping grouping, Long groupId) throws LessonServiceException; + void removeGroup(Grouping grouping, Long groupId) throws LessonServiceException; /** * Add a learner to the lesson class. Checks for duplicates. * * @paran userId new learner id * @return true if added user, returns false if the user already a learner and hence not added. */ - public boolean addLearner(Long lessonId, Integer userId) throws LessonServiceException; + boolean addLearner(Long lessonId, Integer userId) throws LessonServiceException; /** * Add a set of learners to the lesson class. @@ -226,7 +223,7 @@ * @param userIds * array of new learner ids */ - public void addLearners(Long lessonId, Integer[] userIds) throws LessonServiceException; + void addLearners(Long lessonId, Integer[] userIds) throws LessonServiceException; /** * Add a set of learners to the lesson class. To be called within LAMS - see addLearners(Long lessonId, Integer[] @@ -237,26 +234,26 @@ * @param users * the users to add as learners */ - public void addLearners(Lesson lesson, Collection users) throws LessonServiceException; + void addLearners(Lesson lesson, Collection users) throws LessonServiceException; /** - * Set the learners in a lesson class. Learners not in the users collection will be removed. - * To be called within LAMS. + * Set the learners in a lesson class. Learners not in the users collection will be removed. To be called within + * LAMS. * * @param lesson * lesson * @param users * the users to set as staff */ - public void setLearners(Lesson lesson, Collection users) throws LessonServiceException; - + void setLearners(Lesson lesson, Collection users) throws LessonServiceException; + /** * Add a new staff member to the lesson class. Checks for duplicates. * * @paran userId new learner id * @return true if added user, returns false if the user already a staff member and hence not added. */ - public boolean addStaffMember(Long lessonId, Integer userId) throws LessonServiceException; + boolean addStaffMember(Long lessonId, Integer userId) throws LessonServiceException; /** * Add a set of staff to the lesson class. @@ -269,7 +266,7 @@ * @param userIds * array of new staff ids */ - public void addStaffMembers(Long lessonId, Integer[] userIds) throws LessonServiceException; + void addStaffMembers(Long lessonId, Integer[] userIds) throws LessonServiceException; /** * Add a set of staff members to the lesson class. To be called within LAMS - see addLearners(Long lessonId, @@ -280,27 +277,27 @@ * @param users * the users to add as learners */ - public void addStaffMembers(Lesson lesson, Collection users) throws LessonServiceException; - + void addStaffMembers(Lesson lesson, Collection users) throws LessonServiceException; + /** - * Set the staff members in a lesson class. Staff members not in the users collection will be removed. - * To be called within LAMS. + * Set the staff members in a lesson class. Staff members not in the users collection will be removed. To be called + * within LAMS. * * @param lesson * lesson * @param users * the users to set as staff */ - public void setStaffMembers(Lesson lesson, Collection users) throws LessonServiceException; - + void setStaffMembers(Lesson lesson, Collection users) throws LessonServiceException; + /** * Remove references to an activity from all learner progress entries. Used by Live Edit, to remove any references * to the system gates * * @param activity * The activity for which learner progress references should be removed. */ - public void removeProgressReferencesToActivity(Activity activity) throws LessonServiceException; + void removeProgressReferencesToActivity(Activity activity) throws LessonServiceException; /** * Mark any learner progresses for this lesson as not completed. Called when Live Edit ends, to ensure that if there @@ -309,46 +306,48 @@ * @param lessonId * The lesson for which learner progress entries should be updated. */ - public void performMarkLessonUncompleted(Long lessonId) throws LessonServiceException; + void performMarkLessonUncompleted(Long lessonId) throws LessonServiceException; /** * Get the list of users who have attempted an activity. This is based on the progress engine records. This will * give the users in all tool sessions for an activity (if it is a tool activity) or it will give all the users who * have attempted an activity that doesn't have any tool sessions, i.e. system activities such as branching. */ - public List getLearnersHaveAttemptedActivity(Activity activity) throws LessonServiceException; + List getLearnersHaveAttemptedActivity(Activity activity) throws LessonServiceException; /** * Get the list of users who have completed an activity. This is based on the progress engine records. This will * give the users in all tool sessions for an activity (if it is a tool activity) or it will give all the users who * have attempted an activity that doesn't have any tool sessions, i.e. system activities such as branching. */ - public List getLearnersHaveCompletedActivity(Activity activity) throws LessonServiceException; + List getLearnersHaveCompletedActivity(Activity activity) throws LessonServiceException; /** * Gets the count of the users who have attempted an activity. This is based on the progress engine records. This * will work on all activities, including ones that don't have any tool sessions, i.e. system activities such as * branching. */ - public Integer getCountLearnersHaveAttemptedActivity(Activity activity) throws LessonServiceException; + Integer getCountLearnersHaveAttemptedActivity(Activity activity) throws LessonServiceException; /** * Gets the count of the users who have completed an activity. This is based on the progress engine records. This * will work on all activities, including ones that don't have any tool sessions, i.e. system activities such as * branching. */ - public Integer getCountLearnersHaveCompletedActivity(Activity activity) throws LessonServiceException; + Integer getCountLearnersHaveCompletedActivity(Activity activity) throws LessonServiceException; /** * Returns map of lessons in an organisation for a particular learner or staff user. * - * @param userId user's id - * @param orgId org's id - * @param userRole return lessons where user is learner or monitor. or returns all lessons in case of group manager + * @param userId + * user's id + * @param orgId + * org's id + * @param userRole + * return lessons where user is learner or monitor. or returns all lessons in case of group manager * @return map of lesson beans used in the index page */ - public Map getLessonsByOrgAndUserWithCompletedFlag(Integer userId, Integer orgId, - Integer userRole); + Map getLessonsByOrgAndUserWithCompletedFlag(Integer userId, Integer orgId, Integer userRole); /** * @@ -358,16 +357,16 @@ * @param organisationId * @return list of lessons */ - public abstract List getLessonsByGroupAndUser(Integer userId, Integer organisationId); + abstract List getLessonsByGroupAndUser(Integer userId, Integer organisationId); /** * Return list of organisation's non-removed lessons. * * @param organisationId * @return list of lessons */ - public List getLessonsByGroup(Integer organisationId); - + List getLessonsByGroup(Integer organisationId); + /** * Gets the learner's progress details for a particular lesson. Will return null if the user has not started the * lesson. @@ -378,16 +377,25 @@ * lesson's id * @return learner's progress or null */ - public LearnerProgress getUserProgressForLesson(Integer learnerId, Long lessonId); + LearnerProgress getUserProgressForLesson(Integer learnerId, Long lessonId); /** + * Gets the progresses for learners in a particular lesson. + * + * @param lessonId + * lesson's id + * @return learner's progress + */ + List getUserProgressForLesson(Long lessonId); + + /** * Gets list of lessons which are originally based on the given learning design id. * * @param ldId * @param orgId * @return list of lessons */ - public List getLessonsByOriginalLearningDesign(Long ldId, Integer orgId); + List getLessonsByOriginalLearningDesign(Long ldId, Integer orgId); /** * Finds out which lesson the given tool content belongs to and returns its monitoring users. @@ -396,7 +404,7 @@ * tool session ID * @return list of teachers that monitor the lesson which contains the tool with given session ID */ - public List getMonitorsByToolSessionId(Long sessionId); + List getMonitorsByToolSessionId(Long sessionId); /** * Gets all lessons that are active for a learner, in a given organisation @@ -407,24 +415,23 @@ * the desired organisation. * @return a List with all active lessons in it. */ - public List getActiveLessonsForLearner(final Integer learnerId, final Integer organisationId); - - + List getActiveLessonsForLearner(final Integer learnerId, final Integer organisationId); + /** * Gets lesson details for tools based on toolSessionID * * @param sessionID * @return */ - public LessonDetailsDTO getLessonDetailsFromSessionID(Long toolSessionID); - + LessonDetailsDTO getLessonDetailsFromSessionID(Long toolSessionID); + /** * Check if preceding lessons have been completed and the given lesson is available to the user. */ - public boolean checkLessonReleaseConditions(Long lessonId, Integer learnerId); - + boolean checkLessonReleaseConditions(Long lessonId, Integer learnerId); + /** * Find lessons which just got available after the given lesson has been completed. */ - public Set getReleasedSucceedingLessons(Long completedLessonId, Integer learnerId); + Set getReleasedSucceedingLessons(Long completedLessonId, Integer learnerId); } \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/lesson/service/LessonService.java =================================================================== diff -u -rde3706d9ff6d4d4768a805e5f40bd8851634174f -r7d898ea4d62e737512701712ddf4c5e1e0ac3021 --- lams_common/src/java/org/lamsfoundation/lams/lesson/service/LessonService.java (.../LessonService.java) (revision de3706d9ff6d4d4768a805e5f40bd8851634174f) +++ lams_common/src/java/org/lamsfoundation/lams/lesson/service/LessonService.java (.../LessonService.java) (revision 7d898ea4d62e737512701712ddf4c5e1e0ac3021) @@ -106,40 +106,22 @@ this.baseDAO = baseDAO; } - /* Service methods */ - /* - * (non-Javadoc) - * - * @see org.lamsfoundation.lams.lesson.service.ILessonService#getActiveLessonLearners(java.lang.Long) - */ + @Override public List getActiveLessonLearners(Long lessonId) { return lessonDAO.getActiveLearnerByLesson(lessonId); } - /* - * (non-Javadoc) - * - * @see org.lamsfoundation.lams.lesson.service.ILessonService#getActiveLessonLearnersByGroup(java.lang.Long, - * java.lang.Long) - */ + @Override public List getActiveLessonLearnersByGroup(Long lessonId, Long groupId) { return lessonDAO.getActiveLearnerByLessonAndGroup(lessonId, groupId); } - /* - * (non-Javadoc) - * - * @see org.lamsfoundation.lams.lesson.service.ILessonService#getCountActiveLessonLearners(java.lang.Long) - */ + @Override public Integer getCountActiveLessonLearners(Long lessonId) { return lessonDAO.getCountActiveLearnerByLesson(lessonId); } - /* - * (non-Javadoc) - * - * @see org.lamsfoundation.lams.lesson.service.ILessonService#getLessonDetails(java.lang.Long) - */ + @Override public LessonDetailsDTO getLessonDetails(Long lessonId) { Lesson lesson = lessonDAO.getLesson(lessonId); LessonDetailsDTO dto = null; @@ -151,11 +133,7 @@ return dto; } - /* - * (non-Javadoc) - * - * @see org.lamsfoundation.lams.lesson.service.ILessonService#getLessonData(java.lang.Long) - */ + @Override public LessonDTO getLessonData(Long lessonId) { Lesson lesson = lessonDAO.getLesson(lessonId); LessonDTO dto = null; @@ -165,29 +143,12 @@ return dto; } - /** - * Get the lesson object. - * - * @param lessonId - * @return lesson details - */ + @Override public Lesson getLesson(Long lessonId) { return lessonDAO.getLesson(lessonId); } - /** - * If the supplied learner is not already in a group, then perform grouping for the learners who have started the - * lesson, based on the grouping activity. The grouper decides who goes in which group. - * - * Can only be run on a Random Grouping - * - * @param lessonId - * lesson id (mandatory) - * @param groupingActivity - * the activity that has create grouping. (mandatory) - * @param learner - * the learner to be check before grouping. (mandatory) - */ + @Override public void performGrouping(Long lessonId, GroupingActivity groupingActivity, User learner) throws LessonServiceException { Grouping grouping = groupingActivity.getCreateGrouping(); @@ -221,34 +182,15 @@ } } - /** - * Perform the grouping, setting the given list of learners as one group. - * - * @param groupingActivity - * the activity that has create grouping. (mandatory) - * @param groupName - * (optional) - * @param learners - * to form one group (mandatory) - */ + @Override public void performGrouping(GroupingActivity groupingActivity, String groupName, List learners) throws LessonServiceException { Grouping grouping = groupingActivity.getCreateGrouping(); performGrouping(grouping, groupName, learners); } - /** - * Perform the grouping, setting the given list of learners as one group. Used in situations where there is a - * grouping but no grouping activity (e.g. in branching). - * - * @param groupingActivity - * the activity that has create grouping. (mandatory) - * @param groupName - * (optional) - * @param learners - * to form one group (mandatory) - */ + @Override public void performGrouping(Grouping grouping, String groupName, List learners) throws LessonServiceException { if (grouping != null) { @@ -267,17 +209,7 @@ } } - /** - * Perform grouping for the given learner. - * - * @param grouping - * the object on which to perform the grouing. (mandatory) - * @param groupId - * group id (mandatory) - * @param learner - * learner to group (mandatory) - * @throws LessonServiceException - */ + @Override public void performGrouping(Grouping grouping, Long groupId, User learner) throws LessonServiceException { if (grouping != null) { // Ensure we have a real grouping object, not just a CGLIB version (LDEV-1817) @@ -297,18 +229,7 @@ } } - /** - * Perform the grouping, setting the given list of learners as one group. Currently used for chosen grouping and - * teacher chosen branching, and for group based branching in preview (when the user selects a branch that would not - * be their normal branch). - * - * @param grouping - * The grouping that needs to have the grouping performed.. (mandatory) - * @param the - * id of the preferred group (optional) - * @param learners - * to form one group (mandatory) - */ + @Override public void performGrouping(Grouping grouping, Long groupId, List learners) throws LessonServiceException { if (grouping != null) { Grouper grouper = grouping.getGrouper(); @@ -329,16 +250,7 @@ } } - /** - * Remove learners from the given group. - * - * @param grouping - * the grouping that contains the users to be removed (mandatory) - * @param groupID - * if not null only remove user from this group, if null remove learner from any group. - * @param learners - * the learners to be removed (mandatory) - */ + @Override public void removeLearnersFromGroup(Grouping grouping, Long groupID, List learners) throws LessonServiceException { if (grouping != null) { @@ -356,16 +268,7 @@ } } - /** - * Create an empty group for the given grouping. Create an empty group for the given grouping. If the group name - * already exists then it will force the name to be unique. - * - * @param grouping - * the grouping. (mandatory) - * @param groupName - * (mandatory) - * @return the new group - */ + @Override public Group createGroup(Grouping grouping, String name) throws LessonServiceException { Group newGroup = null; if (grouping != null) { @@ -384,15 +287,7 @@ return newGroup; } - /** - * Remove a group for the given grouping. If the group is already used (e.g. a tool session exists) then it throws a - * GroupingException. - * - * @param grouping - * the grouping that contains the group to be removed (mandatory) - * @param groupID - * (mandatory) - */ + @Override public void removeGroup(Grouping grouping, Long groupID) throws LessonServiceException { if (grouping != null) { // get the real objects, not the CGLIB version @@ -409,13 +304,7 @@ } } - /** - * Add a learner to the lesson class. Checks for duplicates. - * - * @param userId - * new learner id - * @return true if added user, returns false if the user already a learner and hence not added. - */ + @Override public boolean addLearner(Long lessonId, Integer userId) throws LessonServiceException { Lesson lesson = lessonDAO.getLesson(lessonId); if (lesson == null) { @@ -444,17 +333,7 @@ return ret; } - /** - * Add a set of learners to the lesson class. - * - * If version of the method is designed to be called from Moodle or some other external system, and is less - * efficient in that it has to look up the user from the user id. If we don't do this, then we may get a a session - * closed issue if this code is called from the LoginRequestValve (as the users will be from a previous session) - * - * @param lessonId - * @param userIds - * array of new learner ids - */ + @Override public void addLearners(Long lessonId, Integer[] userIds) throws LessonServiceException { Lesson lesson = lessonDAO.getLesson(lessonId); @@ -483,15 +362,7 @@ addLearners(lesson, users); } - /** - * Add a set of learners to the lesson class. To be called within LAMS - see addLearners(Long lessonId, Integer[] - * userIds) if calling from an external system. - * - * @param lesson - * lesson - * @param users - * the users to add as learners - */ + @Override public void addLearners(Lesson lesson, Collection users) throws LessonServiceException { LessonClass lessonClass = lesson.getLessonClass(); @@ -504,14 +375,7 @@ } } - /** - * Set the learners in a lesson class. To be called within LAMS. - * - * @param lesson - * lesson - * @param users - * the users to set as learners - */ + @Override public void setLearners(Lesson lesson, Collection users) throws LessonServiceException { LessonClass lessonClass = lesson.getLessonClass(); int numberOfLearners = lessonClass.setLearners(users); @@ -522,13 +386,7 @@ } } - /** - * Add a new staff member to the lesson class. Checks for duplicates. - * - * @param userId - * new learner id - * @return true if added user, returns false if the user already a staff member and hence not added. - */ + @Override public boolean addStaffMember(Long lessonId, Integer userId) { Lesson lesson = lessonDAO.getLesson(lessonId); if (lesson == null) { @@ -553,17 +411,7 @@ return ret; } - /** - * Add a set of staff to the lesson class. - * - * If version of the method is designed to be called from Moodle or some other external system, and is less - * efficient in that it has to look up the user from the user id. If we don't do this, then we may get a a session - * closed issue if this code is called from the LoginRequestValve (as the users will be from a previous session) - * - * @param lessonId - * @param userIds - * array of new staff ids - */ + @Override public void addStaffMembers(Long lessonId, Integer[] userIds) throws LessonServiceException { Lesson lesson = lessonDAO.getLesson(lessonId); @@ -589,15 +437,7 @@ addStaffMembers(lesson, users); } - /** - * Add a set of staff members to the lesson class. To be called within LAMS - see addLearners(Long lessonId, - * Integer[] userIds) if calling from an external system. - * - * @param lesson - * lesson - * @param users - * the users to add as learners - */ + @Override public void addStaffMembers(Lesson lesson, Collection users) throws LessonServiceException { LessonClass lessonClass = lesson.getLessonClass(); @@ -611,14 +451,7 @@ } } - /** - * Set the staff members in a lesson class. To be called within LAMS. - * - * @param lesson - * lesson - * @param users - * the users to set as staff - */ + @Override public void setStaffMembers(Lesson lesson, Collection users) throws LessonServiceException { LessonClass lessonClass = lesson.getLessonClass(); @@ -630,13 +463,7 @@ } } - /** - * Remove references to an activity from all learner progress entries. Used by Live Edit, to remove any references - * to the system gates - * - * @param activity - * The activity for which learner progress references should be removed. - */ + @Override public void removeProgressReferencesToActivity(Activity activity) throws LessonServiceException { if (activity != null) { LessonService.log.debug("Processing learner progress for activity " + activity.getActivityId()); @@ -696,13 +523,7 @@ return recordUpdated; } - /** - * Mark any learner progresses for this lesson as not completed. Called when Live Edit ends, to ensure that if there - * were any completed progress records, and the design was extended, then they are no longer marked as completed. - * - * @param lessonId - * The lesson for which learner progress entries should be updated. - */ + @Override public void performMarkLessonUncompleted(Long lessonId) throws LessonServiceException { int count = 0; if (lessonId != null) { @@ -725,42 +546,27 @@ } } - /** - * Get the list of users who have attempted an activity. This is based on the progress engine records. This will - * give the users in all tool sessions for an activity (if it is a tool activity) or it will give all the users who - * have attempted an activity that doesn't have any tool sessions, i.e. system activities such as branching. - */ + @Override public List getLearnersHaveAttemptedActivity(Activity activity) throws LessonServiceException { return learnerProgressDAO.getLearnersHaveAttemptedActivity(activity); } - /** - * Get the list of users who have completed an activity. This is based on the progress engine records. This will - * give the users in all tool sessions for an activity (if it is a tool activity) or it will give all the users who - * have attempted an activity that doesn't have any tool sessions, i.e. system activities such as branching. - */ + @Override public List getLearnersHaveCompletedActivity(Activity activity) throws LessonServiceException { return learnerProgressDAO.getLearnersHaveCompletedActivity(activity); } - /** - * Gets the count of the users who have attempted an activity. This is based on the progress engine records. This - * will work on all activities, including ones that don't have any tool sessions, i.e. system activities such as - * branching. - */ + @Override public Integer getCountLearnersHaveAttemptedActivity(Activity activity) throws LessonServiceException { return learnerProgressDAO.getNumUsersAttemptedActivity(activity); } - /** - * Gets the count of the users who have completed an activity. This is based on the progress engine records. This - * will work on all activities, including ones that don't have any tool sessions, i.e. system activities such as - * branching. - */ + @Override public Integer getCountLearnersHaveCompletedActivity(Activity activity) throws LessonServiceException { return learnerProgressDAO.getNumUsersCompletedActivity(activity); } + @Override public Map getLessonsByOrgAndUserWithCompletedFlag(Integer userId, Integer orgId, Integer userRole) { TreeMap map = new TreeMap(); @@ -788,48 +594,45 @@ return map; } + @Override public List getLessonsByGroupAndUser(Integer userId, Integer organisationId) { List list = lessonDAO.getLessonsByGroupAndUser(userId, organisationId); return list; } + @Override public List getLessonsByGroup(Integer organisationId) { List list = lessonDAO.getLessonsByGroup(organisationId); return list; } - /** - * Gets the learner's progress details for a particular lesson. Will return null if the user has not started the - * lesson. - * - * @param learnerId - * user's id - * @param lessonId - * lesson's id - * @return learner's progress or null - */ + @Override public LearnerProgress getUserProgressForLesson(Integer learnerId, Long lessonId) { return learnerProgressDAO.getLearnerProgressByLearner(learnerId, lessonId); } - - /** - * Gets list of lessons which are originally based on the given learning design id. - */ + + @Override + public List getUserProgressForLesson(Long lessonId) { + List list = learnerProgressDAO.getLearnerProgressForLesson(lessonId); + return list; + } + + @Override public List getLessonsByOriginalLearningDesign(Long ldId, Integer orgId) { return lessonDAO.getLessonsByOriginalLearningDesign(ldId, orgId); } + @Override public List getMonitorsByToolSessionId(Long sessionId) { return lessonDAO.getMonitorsByToolSessionId(sessionId); } + @Override public List getActiveLessonsForLearner(Integer learnerId, Integer organisationId) { return lessonDAO.getActiveLessonsForLearner(learnerId, organisationId); } - /** - * @see org.lamsfoundation.lams.lesson.service.ILessonService#getLessonDetailsFromSessionID(java.lang.Long) - */ + @Override public LessonDetailsDTO getLessonDetailsFromSessionID(Long toolSessionID) { Lesson lesson = this.lessonDAO.getLessonFromSessionID(toolSessionID); if (lesson != null) { @@ -838,9 +641,7 @@ return null; } - /** - * Check if preceding lessons have been completed and the given lesson is available to the user. - */ + @Override public boolean checkLessonReleaseConditions(Long lessonId, Integer learnerId) { Lesson lesson = getLesson(lessonId); if (lesson != null) { @@ -854,9 +655,7 @@ return true; } - /** - * Find lessons which just got available after the given lesson has been completed. - */ + @Override public Set getReleasedSucceedingLessons(Long completedLessonId, Integer learnerId) { Set releasedSucceedingLessons = new HashSet(); Lesson lesson = getLesson(completedLessonId);