Index: lams_build/lib/lams/lams.jar =================================================================== diff -u -ra627849a2ed5e825df33ae4bd8372d8c9deed13b -r00d5413cf23d20dae624c2bfbe17b3c914963945 Binary files differ Index: lams_central/src/java/org/lamsfoundation/lams/web/RedirectAction.java =================================================================== diff -u -re8f43f66612f0ccc2fc6479651004a2a054bdc6f -r00d5413cf23d20dae624c2bfbe17b3c914963945 --- lams_central/src/java/org/lamsfoundation/lams/web/RedirectAction.java (.../RedirectAction.java) (revision e8f43f66612f0ccc2fc6479651004a2a054bdc6f) +++ lams_central/src/java/org/lamsfoundation/lams/web/RedirectAction.java (.../RedirectAction.java) (revision 00d5413cf23d20dae624c2bfbe17b3c914963945) @@ -26,8 +26,8 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; -import org.apache.commons.codec.binary.Base64; +import org.apache.commons.codec.binary.Base64; import org.apache.log4j.Logger; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; @@ -47,34 +47,27 @@ import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; - /** * @author lfoxton * - * This action is used for notification emails. It is designed to enable direct - * linking to either monitor or learner so that links can be sent in the email. - * This must be done through LAMS central so it correctly redirects the user - * to the login page (if they have no session) before returning them to the - * correct location. + * This action is used for notification emails. It is designed to enable direct linking to either monitor or + * learner so that links can be sent in the email. This must be done through LAMS central so it correctly + * redirects the user to the login page (if they have no session) before returning them to the correct location. * - * This action takes one parameter "h" which is a Base64 hash of a - * comma-separated value (relativeUrlPath, toolSessionID, accessMode) - * where: - * relativeUrlPath = Relative path to resource eg /tool/lawiki10/learner.do - * toolSessionID = A valid tool session ID for the lesson - * accessMode = l or t (learner or teacher) + * This action takes one parameter "h" which is a Base64 hash of a comma-separated value (relativeUrlPath, + * toolSessionID, accessMode) where: relativeUrlPath = Relative path to resource eg /tool/lawiki10/learner.do + * toolSessionID = A valid tool session ID for the lesson accessMode = l or t (learner or teacher) * - * The parameters are hashed to prevent people from identifying the url, and - * attempting to access content to which they are unauthorised, see LDEV-1978 + * The parameters are hashed to prevent people from identifying the url, and attempting to access content to + * which they are unauthorised, see LDEV-1978 * - * The toolSessionID and accessMode are used to determine the permissions of - * this user so it someone forwards the email to an unauthorised user, they - * still cannot access the link unless they are part of the correct group. These - * checks may become unneccessary on the completion of LDEV-1978 + * The toolSessionID and accessMode are used to determine the permissions of this user so it someone forwards + * the email to an unauthorised user, they still cannot access the link unless they are part of the correct + * group. These checks may become unneccessary on the completion of LDEV-1978 * - * Note that parameter names have been made as short as possible here to - * attempt to shorten the entire link required, and hopefully prevent email - * clients cutting them off and making a newline which sometimes breaks links. + * Note that parameter names have been made as short as possible here to attempt to shorten the entire link + * required, and hopefully prevent email clients cutting them off and making a newline which sometimes breaks + * links. * * @struts:action path="/r" validate="false" * @struts:action-forward name="error" path=".error" @@ -93,22 +86,23 @@ private static ILamsToolService lamsToolService; private static IUserManagementService userService; - public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res) - throws Exception { + @Override + public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest req, + HttpServletResponse res) throws Exception { try { - String hash = WebUtil.readStrParam(req, PARAM_HASH); - + String hash = WebUtil.readStrParam(req, RedirectAction.PARAM_HASH); + // Un-hash the string to gain all the paramters String fullParams = new String(Base64.decodeBase64(hash.getBytes())); - + // Split the CSV parameters String[] split = fullParams.split(","); - + if (split.length != 3) { throw new Exception("Hash did not contain correct format (relative path, toolSessionID, toolaccess )"); } - + // Getting the parameters from the hash String relativePath = split[0]; Long toolSessionID = Long.parseLong(split[1]); @@ -117,40 +111,39 @@ // Get the user UserDTO user = getUser(); if (user == null) { - log.error("admin: User missing from session. "); + RedirectAction.log.error("admin: User missing from session. "); return mapping.findForward("error"); } // Get the tool session ToolSession toolSession = getToolSession(toolSessionID); if (toolSession == null) { - log.error("No ToolSession with ID " + toolSessionID + " found."); + RedirectAction.log.error("No ToolSession with ID " + toolSessionID + " found."); return mapping.findForward("error"); } - // Get the lesson Lesson lesson = toolSession.getLesson(); // Check the user's permissions, either learner or monitor - if (accessMode.equals(ACCESS_MODE_LEARNER)) { - if (lesson == null || !lesson.isLessonStarted()) { + if (accessMode.equals(RedirectAction.ACCESS_MODE_LEARNER)) { + if ((lesson == null) || !lesson.isLessonStarted()) { return displayMessage(mapping, req, "message.lesson.not.started.cannot.participate"); } // Check the learner is part of the group in question - if (toolSession.getLearners() == null || !toolSession.getLearners().contains(getRealUser(user))) { - log.error("learner: User " + user.getLogin() + if (!toolSession.getLearners().contains(getRealUser(user))) { + RedirectAction.log.error("learner: User " + user.getLogin() + " is not a learner in the requested group. Cannot access the lesson."); return displayMessage(mapping, req, "error.authorisation"); } - - } else if (accessMode.equals(ACCESS_MODE_TEACHER)) { + } else if (accessMode.equals(RedirectAction.ACCESS_MODE_TEACHER)) { + // Check this is a monitor for the lesson in question - if (lesson.getLessonClass() == null || !lesson.getLessonClass().isStaffMember(getRealUser(user))) { - log.error("learner: User " + user.getLogin() + if ((lesson.getLessonClass() == null) || !lesson.getLessonClass().isStaffMember(getRealUser(user))) { + RedirectAction.log.error("learner: User " + user.getLogin() + " is not a learner in the requested lesson. Cannot access the lesson."); return displayMessage(mapping, req, "error.authorisation"); } @@ -164,7 +157,7 @@ return null; } catch (Exception e) { - log.error("Failed redirect to url", e); + RedirectAction.log.error("Failed redirect to url", e); return mapping.findForward("error"); } } @@ -182,35 +175,34 @@ private User getRealUser(UserDTO dto) { return getUserService().getUserByLogin(dto.getLogin()); } - - private ToolSession getToolSession(Long toolSessionID) - { + + private ToolSession getToolSession(Long toolSessionID) { return getLamsToolService().getToolSession(toolSessionID); } private IUserManagementService getUserService() { - if (userService == null) { - WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet() - .getServletContext()); - userService = (IUserManagementService) ctx.getBean("userManagementService"); + if (RedirectAction.userService == null) { + WebApplicationContext ctx = WebApplicationContextUtils + .getRequiredWebApplicationContext(getServlet().getServletContext()); + RedirectAction.userService = (IUserManagementService) ctx.getBean("userManagementService"); } - return userService; + return RedirectAction.userService; } public static void setUserService(IUserManagementService userService) { RedirectAction.userService = userService; } - + private ILamsToolService getLamsToolService() { - if (lamsToolService == null) { - WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet() - .getServletContext()); - lamsToolService = (ILamsToolService) ctx.getBean("lamsToolService"); + if (RedirectAction.lamsToolService == null) { + WebApplicationContext ctx = WebApplicationContextUtils + .getRequiredWebApplicationContext(getServlet().getServletContext()); + RedirectAction.lamsToolService = (ILamsToolService) ctx.getBean("lamsToolService"); } - return lamsToolService; + return RedirectAction.lamsToolService; } public static void setLamsToolService(ILamsToolService lamsToolService) { - RedirectAction.lamsToolService = lamsToolService; + RedirectAction.lamsToolService = lamsToolService; } } \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/tool/GroupedToolSession.java =================================================================== diff -u -r08950e1090443c3423a3d1c587416a2fccd8bbdf -r00d5413cf23d20dae624c2bfbe17b3c914963945 --- lams_common/src/java/org/lamsfoundation/lams/tool/GroupedToolSession.java (.../GroupedToolSession.java) (revision 08950e1090443c3423a3d1c587416a2fccd8bbdf) +++ lams_common/src/java/org/lamsfoundation/lams/tool/GroupedToolSession.java (.../GroupedToolSession.java) (revision 00d5413cf23d20dae624c2bfbe17b3c914963945) @@ -24,69 +24,64 @@ package org.lamsfoundation.lams.tool; import java.util.Date; -import java.util.HashSet; import java.util.Set; import org.lamsfoundation.lams.learningdesign.Group; import org.lamsfoundation.lams.learningdesign.ToolActivity; import org.lamsfoundation.lams.lesson.Lesson; import org.lamsfoundation.lams.usermanagement.User; - /** - * This is the tool session shared within a learner group. It is meant to be - * unique against learner group and a tool activity instance. + * This is the tool session shared within a learner group. It is meant to be unique against learner group and a tool + * activity instance. * * @author daveg, Jacky Fang * */ public class GroupedToolSession extends ToolSession { + private static final long serialVersionUID = 8638128083435243375L; /** persistent field */ private Group sessionGroup; - /**default constructor*/ - public GroupedToolSession(){ } - + /** default constructor */ + public GroupedToolSession() { + } + /** * Grouped tool session initialization constructor. - * @param toolActivity the tool activity for that group - * @param createDateTime the time this tool session is created. - * @param toolSessionStateId the tool session status. - * @param group the target group + * + * @param toolActivity + * the tool activity for that group + * @param createDateTime + * the time this tool session is created. + * @param toolSessionStateId + * the tool session status. + * @param group + * the target group */ - public GroupedToolSession(ToolActivity toolActivity, - Date createDateTime, - int toolSessionStateId, - Group sessionGroup, - Lesson lesson) - { - super(null,toolActivity,createDateTime,toolSessionStateId,lesson); - super.setUniqueKey(UNIQUE_KEY_PREFIX - +"_" - +toolActivity.getActivityId().toString() - +"_" - +sessionGroup.getGroupId().toString()); - this.sessionGroup=sessionGroup; - //set toolSession name as same as name of relatived group. - this.setToolSessionName(sessionGroup.getGroupName()); + public GroupedToolSession(ToolActivity toolActivity, Date createDateTime, int toolSessionStateId, + Group sessionGroup, Lesson lesson) { + super(null, toolActivity, createDateTime, toolSessionStateId, lesson); + super.setUniqueKey(ToolSession.UNIQUE_KEY_PREFIX + "_" + toolActivity.getActivityId().toString() + "_" + + sessionGroup.getGroupId().toString()); + this.sessionGroup = sessionGroup; + //set toolSession name as same as name of relatived group. + this.setToolSessionName(sessionGroup.getGroupName()); } - - public Group getSessionGroup() { - return sessionGroup; - } - - public void setSessionGroup(Group sessionGroup) { - this.sessionGroup = sessionGroup; - } - + + public Group getSessionGroup() { + return sessionGroup; + } + + public void setSessionGroup(Group sessionGroup) { + this.sessionGroup = sessionGroup; + } + /** Get all the learners who may be part of this tool session. */ + @Override public Set getLearners() { - HashSet users = new HashSet(); - if ( sessionGroup != null ) { - users.addAll(sessionGroup.getUsers()); - } - return users; + // the collection is extra lazy and possibly very large so avoid initialisation if possible + return sessionGroup.getUsers(); } - -} +} \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/tool/NonGroupedToolSession.java =================================================================== diff -u -r08950e1090443c3423a3d1c587416a2fccd8bbdf -r00d5413cf23d20dae624c2bfbe17b3c914963945 --- lams_common/src/java/org/lamsfoundation/lams/tool/NonGroupedToolSession.java (.../NonGroupedToolSession.java) (revision 08950e1090443c3423a3d1c587416a2fccd8bbdf) +++ lams_common/src/java/org/lamsfoundation/lams/tool/NonGroupedToolSession.java (.../NonGroupedToolSession.java) (revision 00d5413cf23d20dae624c2bfbe17b3c914963945) @@ -32,9 +32,8 @@ import org.lamsfoundation.lams.usermanagement.User; /** - * Not used at present - creates a separate ToolSession for each learner. - * When we have a user interface that allows the author to select the whole of the class - * vs an individual learner for the tool session, then it will be used. + * Not used at present - creates a separate ToolSession for each learner. When we have a user interface that allows the + * author to select the whole of the class vs an individual learner for the tool session, then it will be used. * * @author daveg */ @@ -43,42 +42,36 @@ /** persistent field */ private User user; - public NonGroupedToolSession(ToolActivity toolActivity, - Date createDateTime, - int toolSessionStateId, - User user, - Lesson lesson) - { - super(null,toolActivity,createDateTime,toolSessionStateId,lesson); - super.setUniqueKey(UNIQUE_KEY_PREFIX - +"_" - +toolActivity.getActivityId().toString() - +"_" - +user.getUserId().toString()); - this.user=user; - //set toolSession name as same as login name of relatived user. - this.setToolSessionName(user.getLogin()); + public NonGroupedToolSession(ToolActivity toolActivity, Date createDateTime, int toolSessionStateId, User user, + Lesson lesson) { + super(null, toolActivity, createDateTime, toolSessionStateId, lesson); + super.setUniqueKey(ToolSession.UNIQUE_KEY_PREFIX + "_" + toolActivity.getActivityId().toString() + "_" + + user.getUserId().toString()); + this.user = user; + //set toolSession name as same as login name of relatived user. + this.setToolSessionName(user.getLogin()); } - /**default constructor*/ - public NonGroupedToolSession(){} - - public User getUser() - { - return user; - } - - public void setUser(User user) { - this.user = user; - } - - /** Get all the learners who may be part of this tool session. */ - public Set getLearners() { - HashSet users = new HashSet(); - if ( user != null ) { - users.add(user); - } - return users; + + /** default constructor */ + public NonGroupedToolSession() { } -} + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + + /** Get all the learners who may be part of this tool session. */ + @Override + public Set getLearners() { + HashSet users = new HashSet(); + if (user != null) { + users.add(user); + } + return users; + } +} \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/tool/dao/IToolSessionDAO.java =================================================================== diff -u -rf5cf4729d786b6f0459f5fc6ab6fda45aec2ed1e -r00d5413cf23d20dae624c2bfbe17b3c914963945 --- lams_common/src/java/org/lamsfoundation/lams/tool/dao/IToolSessionDAO.java (.../IToolSessionDAO.java) (revision f5cf4729d786b6f0459f5fc6ab6fda45aec2ed1e) +++ lams_common/src/java/org/lamsfoundation/lams/tool/dao/IToolSessionDAO.java (.../IToolSessionDAO.java) (revision 00d5413cf23d20dae624c2bfbe17b3c914963945) @@ -4,15 +4,15 @@ * License Information: http://lamsfoundation.org/licensing/lams/2.0/ * * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2.0 + * it under the terms of the GNU General License version 2.0 * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General License for more details. * - * You should have received a copy of the GNU General Public License + * You should have received a copy of the GNU General License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA @@ -32,55 +32,49 @@ /** * Inteface defines Lesson DAO Methods + * * @author chris, Jacky */ -public interface IToolSessionDAO -{ - +public interface IToolSessionDAO { + /** * Retrieves the ToolSession - * @param toolSessionId identifies the ToolSession to get + * + * @param toolSessionId + * identifies the ToolSession to get * @return the ToolSession */ - public ToolSession getToolSession(Long toolSessionId); - - public void saveToolSession(ToolSession toolSession); + ToolSession getToolSession(Long toolSessionId); - public void removeToolSession(ToolSession toolSession); - - /** - * Get the tool session by learner and activity. Will attempted to get an appropriate grouped - * tool session (the most common case as this covers a normal group or a whole of class group) - * and then attempts to get a non-grouped base tool session. The non-grouped tool session - * is meant to be unique against the user and activity. - * @returns toolSession may be of subclass NonGroupedToolSession or GroupedToolSession - */ - public ToolSession getToolSessionByLearner(final User learner,final Activity activity); + void saveToolSession(ToolSession toolSession); - /** - * Get all the tools for a lesson. Does not order the tool sessions with respect to their - * activities - to do that you need to get the activities first and get the tool session from - * the activity. - * - * @returns list of tool sessions. - */ - public List getToolSessionsByLesson(final Lesson lesson); + void removeToolSession(ToolSession toolSession); - /** - * Get the tool session by activity. A class-grouped activity should have only one tool session, - * per activity but a proper grouped activity or an individial activity may have more - * than one tool sesssion. - * @see org.lamsfoundation.lams.tool.dao.IToolSessionDAO#getToolSessionByActivity(org.lamsfoundation.lams.learningdesign.Activity) - * @returns List of toolSessions, may be of subclass NonGroupedToolSession or GroupedToolSession - */ - public List getToolSessionByActivity(final Activity activity); - - public void updateToolSession(ToolSession toolSession); - - /** - * Get a count of all the possible users for an activity connected to a tool session, where - * it is a GroupedToolSession ie discriminator-value="1". Don't call on any other type of - * tool session. - */ - public Integer getCountUsersGrouped(final long toolSessionId); -} + /** + * Get the tool session by learner and activity. Will attempted to get an appropriate grouped tool session (the most + * common case as this covers a normal group or a whole of class group) and then attempts to get a non-grouped base + * tool session. The non-grouped tool session is meant to be unique against the user and activity. + * + * @returns toolSession may be of subclass NonGroupedToolSession or GroupedToolSession + */ + ToolSession getToolSessionByLearner(final User learner, final Activity activity); + + /** + * Get all the tools for a lesson. Does not order the tool sessions with respect to their activities - to do that + * you need to get the activities first and get the tool session from the activity. + * + * @returns list of tool sessions. + */ + List getToolSessionsByLesson(final Lesson lesson); + + /** + * Get the tool session by activity. A class-grouped activity should have only one tool session, per activity but a + * proper grouped activity or an individial activity may have more than one tool sesssion. + * + * @see org.lamsfoundation.lams.tool.dao.IToolSessionDAO#getToolSessionByActivity(org.lamsfoundation.lams.learningdesign.Activity) + * @returns List of toolSessions, may be of subclass NonGroupedToolSession or GroupedToolSession + */ + List getToolSessionByActivity(final Activity activity); + + void updateToolSession(ToolSession toolSession); +} \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/tool/dao/hibernate/ToolSessionDAO.java =================================================================== diff -u -rf5cf4729d786b6f0459f5fc6ab6fda45aec2ed1e -r00d5413cf23d20dae624c2bfbe17b3c914963945 --- lams_common/src/java/org/lamsfoundation/lams/tool/dao/hibernate/ToolSessionDAO.java (.../ToolSessionDAO.java) (revision f5cf4729d786b6f0459f5fc6ab6fda45aec2ed1e) +++ lams_common/src/java/org/lamsfoundation/lams/tool/dao/hibernate/ToolSessionDAO.java (.../ToolSessionDAO.java) (revision 00d5413cf23d20dae624c2bfbe17b3c914963945) @@ -38,119 +38,104 @@ /** * Hibernate implementation of ILessonDAO + * * @author chris, Jacky Fang */ @Repository -public class ToolSessionDAO extends LAMSBaseDAO implements IToolSessionDAO -{ +public class ToolSessionDAO extends LAMSBaseDAO implements IToolSessionDAO { - protected static final String LOAD_NONGROUPED_TOOL_SESSION_BY_LEARNER = - "from NonGroupedToolSession s where s.user = :learner and s.toolActivity = :activity"; - protected static final String LOAD_GROUPED_TOOL_SESSION_BY_GROUP = - "from GroupedToolSession s where s.sessionGroup = :inputgroup and s.toolActivity = :activity"; - protected static final String LOAD_GROUPED_TOOL_SESSION_BY_GROUP2 = - "select s from GroupedToolSession as s inner join s.sessionGroup as sg inner join sg.users as u " - +" where :learner = u and s.toolActivity = :activity"; - protected static final String LOAD_TOOL_SESSION_BY_ACTIVITY = - "from ToolSession s where s.toolActivity = :activity"; - protected static final String LOAD_TOOL_SESSION_BY_LESSON = - "from ToolSession s where s.lesson = :lesson"; - private final static String COUNT_GROUPED_LEARNERS_SQL = "select count(*) from lams_user_group ug, lams_tool_session s " - + " where ug.group_id = s.group_id and s.tool_session_id = :toolSessionId"; - + private static final String LOAD_NONGROUPED_TOOL_SESSION_BY_LEARNER = "from NonGroupedToolSession s where s.user = :learner and s.toolActivity = :activity"; + private static final String LOAD_GROUPED_TOOL_SESSION_BY_GROUP2 = "select s from GroupedToolSession as s inner join s.sessionGroup as sg inner join sg.users as u " + + " where :learner = u and s.toolActivity = :activity"; + private static final String LOAD_TOOL_SESSION_BY_ACTIVITY = "from ToolSession s where s.toolActivity = :activity"; + private static final String LOAD_TOOL_SESSION_BY_LESSON = "from ToolSession s where s.lesson = :lesson"; + /** * Retrieves the ToolSession - * @param toolSessionId identifies the ToolSession to get + * + * @param toolSessionId + * identifies the ToolSession to get * @return the ToolSession */ - public ToolSession getToolSession(Long toolSessionId) - { - ToolSession session = (ToolSession) getSession().get(ToolSession.class, toolSessionId); - return session; + @Override + public ToolSession getToolSession(Long toolSessionId) { + ToolSession session = (ToolSession) getSession().get(ToolSession.class, toolSessionId); + return session; } - /** - * Get the tool session by learner and activity. Will attempted to get an appropriate grouped - * tool session (the most common case as this covers a normal group or a whole of class group) - * and then attempts to get a non-grouped base tool session. The non-grouped tool session - * is meant to be unique against the user and activity. - * @see org.lamsfoundation.lams.tool.dao.IToolSessionDAO#getToolSessionByLearner(org.lamsfoundation.lams.usermanagement.User, org.lamsfoundation.lams.learningdesign.Activity) - * @returns toolSession may be of subclass NonGroupedToolSession or GroupedToolSession - */ - public ToolSession getToolSessionByLearner(final User learner,final Activity activity) - { - Query query = getSessionFactory().getCurrentSession().createQuery(LOAD_GROUPED_TOOL_SESSION_BY_GROUP2); - query.setParameter("learner",learner); - query.setParameter("activity",activity); - GroupedToolSession groupedToolSession = (GroupedToolSession) query.uniqueResult(); - if ( groupedToolSession != null ) - return groupedToolSession; - - query = getSessionFactory().getCurrentSession().createQuery(LOAD_NONGROUPED_TOOL_SESSION_BY_LEARNER); - query.setParameter("learner",learner); - query.setParameter("activity",activity); - NonGroupedToolSession nonGroupedSession = (NonGroupedToolSession) query.uniqueResult(); - return nonGroupedSession; - + /** + * Get the tool session by learner and activity. Will attempted to get an appropriate grouped tool session (the most + * common case as this covers a normal group or a whole of class group) and then attempts to get a non-grouped base + * tool session. The non-grouped tool session is meant to be unique against the user and activity. + * + * @see org.lamsfoundation.lams.tool.dao.IToolSessionDAO#getToolSessionByLearner(org.lamsfoundation.lams.usermanagement.User, + * org.lamsfoundation.lams.learningdesign.Activity) + * @returns toolSession may be of subclass NonGroupedToolSession or GroupedToolSession + */ + @Override + public ToolSession getToolSessionByLearner(final User learner, final Activity activity) { + Query query = getSessionFactory().getCurrentSession() + .createQuery(ToolSessionDAO.LOAD_GROUPED_TOOL_SESSION_BY_GROUP2); + query.setParameter("learner", learner); + query.setParameter("activity", activity); + GroupedToolSession groupedToolSession = (GroupedToolSession) query.uniqueResult(); + if (groupedToolSession != null) { + return groupedToolSession; } - /** - * Get the tool session by activity. A class-grouped activity should have only one tool session, - * per activity but a proper grouped activity or an individial activity may have more - * than one tool sesssion. - * @see org.lamsfoundation.lams.tool.dao.IToolSessionDAO#getToolSessionByActivity(org.lamsfoundation.lams.learningdesign.Activity) - * @returns List of toolSessions, may be of subclass NonGroupedToolSession or GroupedToolSession - */ - public List getToolSessionByActivity(final Activity activity) - { - Query query = getSessionFactory().getCurrentSession().createQuery(LOAD_TOOL_SESSION_BY_ACTIVITY); - query.setParameter("activity",activity); - return (List) query.list(); - } - - - public void saveToolSession(ToolSession toolSession) - { - getSession().save(toolSession); + query = getSessionFactory().getCurrentSession() + .createQuery(ToolSessionDAO.LOAD_NONGROUPED_TOOL_SESSION_BY_LEARNER); + query.setParameter("learner", learner); + query.setParameter("activity", activity); + NonGroupedToolSession nonGroupedSession = (NonGroupedToolSession) query.uniqueResult(); + return nonGroupedSession; + } + /** + * Get the tool session by activity. A class-grouped activity should have only one tool session, per activity but a + * proper grouped activity or an individial activity may have more than one tool sesssion. + * + * @see org.lamsfoundation.lams.tool.dao.IToolSessionDAO#getToolSessionByActivity(org.lamsfoundation.lams.learningdesign.Activity) + * @returns List of toolSessions, may be of subclass NonGroupedToolSession or GroupedToolSession + */ + @Override + public List getToolSessionByActivity(final Activity activity) { + Query query = getSessionFactory().getCurrentSession().createQuery(ToolSessionDAO.LOAD_TOOL_SESSION_BY_ACTIVITY); + query.setParameter("activity", activity); + return query.list(); + } + + @Override + public void saveToolSession(ToolSession toolSession) { + getSession().save(toolSession); + } + + /** * @see org.lamsfoundation.lams.tool.dao.IToolSessionDAO#removeToolSession(org.lamsfoundation.lams.tool.ToolSession) */ - public void removeToolSession(ToolSession toolSession) - { - getSession().delete(toolSession); + @Override + public void removeToolSession(ToolSession toolSession) { + getSession().delete(toolSession); } /** * @see org.lamsfoundation.lams.tool.dao.IToolSessionDAO#getToolSessionsByLesson(org.lamsfoundation.lams.lesson.Lesson) */ - public List getToolSessionsByLesson(final Lesson lesson) { + @Override + public List getToolSessionsByLesson(final Lesson lesson) { - Query query = getSessionFactory().getCurrentSession().createQuery(LOAD_TOOL_SESSION_BY_LESSON); - query.setParameter("lesson",lesson); - return query.list(); + Query query = getSessionFactory().getCurrentSession().createQuery(ToolSessionDAO.LOAD_TOOL_SESSION_BY_LESSON); + query.setParameter("lesson", lesson); + return query.list(); - } + } /** * @see org.lamsfoundation.lams.tool.dao.IToolSessionDAO#updateToolSession(org.lamsfoundation.lams.tool.ToolSession) */ - public void updateToolSession(ToolSession toolSession) - { - getSession().update(toolSession); + @Override + public void updateToolSession(ToolSession toolSession) { + getSession().update(toolSession); } - - /** - * Get a count of all the possible users for an activity connected to a tool session, where - * it is a GroupedToolSession ie discriminator-value="1". Don't call on any other type of - * tool session. - */ - public Integer getCountUsersGrouped(final long toolSessionId) { - Query query = getSession().createSQLQuery(ToolSessionDAO.COUNT_GROUPED_LEARNERS_SQL); - query.setLong("toolSessionId", toolSessionId); - Object value = query.uniqueResult(); - return new Integer(((Number) value).intValue()); - } - - -} +} \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/tool/service/ILamsToolService.java =================================================================== diff -u -rf5cf4729d786b6f0459f5fc6ab6fda45aec2ed1e -r00d5413cf23d20dae624c2bfbe17b3c914963945 --- lams_common/src/java/org/lamsfoundation/lams/tool/service/ILamsToolService.java (.../ILamsToolService.java) (revision f5cf4729d786b6f0459f5fc6ab6fda45aec2ed1e) +++ lams_common/src/java/org/lamsfoundation/lams/tool/service/ILamsToolService.java (.../ILamsToolService.java) (revision 00d5413cf23d20dae624c2bfbe17b3c914963945) @@ -23,16 +23,12 @@ package org.lamsfoundation.lams.tool.service; import java.io.IOException; -import java.util.Set; import org.lamsfoundation.lams.tool.IToolVO; import org.lamsfoundation.lams.tool.Tool; import org.lamsfoundation.lams.tool.ToolSession; -import org.lamsfoundation.lams.tool.exception.LamsToolServiceException; -import org.lamsfoundation.lams.usermanagement.User; import org.lamsfoundation.lams.util.FileUtilException; - /** * This interface defines all the service available for self contained tool module from lams. Any service that would be * used by other lams module such as, lams_learning etc, should not appear in this interface. @@ -42,43 +38,30 @@ * @author Ozgur Demirtas 24/06/2005 */ public interface ILamsToolService { - /** - * Returns a list of all learners who can use a specific set of tool content. Note that none/some/all of these users - * may not reach the associated activity so they may not end up using the content. The purpose of this method is to - * provide a way for tools to do logic based on completions against potential completions. - * - * @param toolContentID - * a long value that identifies the tool content (in the Tool and in LAMS). - * @return a List of all the Learners who are scheduled to use the content. - * @exception in - * case of any problems. - */ - Set getAllPotentialLearners(long toolSessionID) throws LamsToolServiceException; - IToolVO getToolByID(Long toolId); - + IToolVO getToolBySignature(final String toolSignature); - + long getToolDefaultContentIdBySignature(final String toolSignature); String generateUniqueContentFolder() throws FileUtilException, IOException; - + /** - * Return content folder (unique to each learner and lesson) which is used for storing user generated content. - * It's been used by CKEditor. + * Return content folder (unique to each learner and lesson) which is used for storing user generated content. It's + * been used by CKEditor. * * @param toolSessionId * @param userId * @return */ String getLearnerContentFolder(Long toolSessionId, Long userId); - + void saveOrUpdateTool(Tool tool); - + Tool getPersistToolBySignature(final String toolSignature); - + ToolSession getToolSession(Long toolSessionId); - + /** * Allows the tool to ask whether or not the activity is grouped and therefore it should expect more than one tool * session. @@ -87,7 +70,7 @@ * @return */ Boolean isGroupedActivity(long toolContentID); - + /** * Returns leader's UserId from the nearest Leader Selection Tool (the nearest to the specified activity) , and null * if no Leader Selection Tools available. @@ -99,18 +82,9 @@ * @return */ Long getLeaderUserId(Long toolSessionId, Integer learnerId); - - /** - * Get all the potential users for an Activity - they may or may not have joined the lesson. - * Works for both grouped, non-grouped and whole class activities. - * @param toolSessionId - * @return - */ - Set getUsersForActivity(Long toolSessionId); /** * Get a count of all the users that would be returned by getUsersForActivity(Long toolSessionId); - */ + */ Integer getCountUsersForActivity(Long toolSessionId); - -} +} \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/tool/service/LamsToolService.java =================================================================== diff -u -rf5cf4729d786b6f0459f5fc6ab6fda45aec2ed1e -r00d5413cf23d20dae624c2bfbe17b3c914963945 --- lams_common/src/java/org/lamsfoundation/lams/tool/service/LamsToolService.java (.../LamsToolService.java) (revision f5cf4729d786b6f0459f5fc6ab6fda45aec2ed1e) +++ lams_common/src/java/org/lamsfoundation/lams/tool/service/LamsToolService.java (.../LamsToolService.java) (revision 00d5413cf23d20dae624c2bfbe17b3c914963945) @@ -25,10 +25,8 @@ import java.io.IOException; import java.util.Date; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; import org.apache.log4j.Logger; import org.hibernate.Hibernate; @@ -47,7 +45,6 @@ import org.lamsfoundation.lams.tool.dao.IToolContentDAO; import org.lamsfoundation.lams.tool.dao.IToolDAO; import org.lamsfoundation.lams.tool.dao.IToolSessionDAO; -import org.lamsfoundation.lams.tool.exception.LamsToolServiceException; import org.lamsfoundation.lams.usermanagement.User; import org.lamsfoundation.lams.util.FileUtil; import org.lamsfoundation.lams.util.FileUtilException; @@ -62,7 +59,7 @@ */ public class LamsToolService implements ILamsToolService { private static Logger log = Logger.getLogger(LamsToolService.class); - + //Leader selection tool Constants private static final String LEADER_SELECTION_TOOL_SIGNATURE = "lalead11"; private static final String LEADER_SELECTION_TOOL_OUTPUT_NAME_LEADER_USERID = "leader.user.id"; @@ -74,18 +71,6 @@ private ILessonService lessonService; @Override - public Set getAllPotentialLearners(long toolSessionId) throws LamsToolServiceException { - - ToolSession session = toolSessionDAO.getToolSession(toolSessionId); - if (session != null) { - return session.getLearners(); - } else { - log.error("No tool session found for " + toolSessionId + ". No potential learners being returned."); - return new HashSet(); - } - } - - @Override public IToolVO getToolByID(Long toolId) { Tool tool = toolDAO.getToolByID(toolId); return tool.createBasicToolVO(); @@ -139,22 +124,23 @@ return toolSessionDAO.getToolSession(toolSessionId); } + @SuppressWarnings("unchecked") @Override public Boolean isGroupedActivity(long toolContentID) { List activities = toolContentDAO.findByProperty(Activity.class, "toolContentId", toolContentID); if (activities.size() == 1) { Activity activity = activities.get(0); return activity.getApplyGrouping(); } else { - log.debug("ToolContent contains multiple activities, can't test whether grouping applies."); + LamsToolService.log.debug("ToolContent contains multiple activities, can't test whether grouping applies."); return null; } } - + @Override public Long getLeaderUserId(Long toolSessionId, Integer learnerId) { Long leaderUserId = null; - + ToolSession toolSession = this.getToolSession(toolSessionId); ToolActivity specifiedActivity = toolSession.getToolActivity(); Activity leaderSelectionActivity = getNearestLeaderSelectionActivity(specifiedActivity, learnerId, @@ -163,18 +149,18 @@ // check if there is leaderSelectionTool available if (leaderSelectionActivity != null) { User learner = (User) toolContentDAO.find(User.class, learnerId); - String outputName = LEADER_SELECTION_TOOL_OUTPUT_NAME_LEADER_USERID; + String outputName = LamsToolService.LEADER_SELECTION_TOOL_OUTPUT_NAME_LEADER_USERID; ToolSession leaderSelectionSession = toolSessionDAO.getToolSessionByLearner(learner, leaderSelectionActivity); if (leaderSelectionSession != null) { - ToolOutput output = lamsCoreToolService.getOutputFromTool(outputName, leaderSelectionSession, null); + ToolOutput output = lamsCoreToolService.getOutputFromTool(outputName, leaderSelectionSession, null); - // check if tool produced output - if (output != null && output.getValue() != null) { - leaderUserId = output.getValue().getLong(); + // check if tool produced output + if ((output != null) && (output.getValue() != null)) { + leaderUserId = output.getValue().getLong(); + } } } - } return leaderUserId; } @@ -183,8 +169,8 @@ * Finds the nearest Leader Select activity. Works recursively. Tries to find Leader Select activity in the previous * activities set first, and then inside the parent set. */ + @SuppressWarnings("rawtypes") private Activity getNearestLeaderSelectionActivity(Activity activity, Integer userId, Long lessonId) { - // check if current activity is Leader Select one. if so - stop searching and return it. Class activityClass = Hibernate.getClass(activity); if (activityClass.equals(ToolActivity.class)) { @@ -200,25 +186,26 @@ toolActivity = (ToolActivity) activity; } - if (LEADER_SELECTION_TOOL_SIGNATURE.equals(toolActivity.getTool().getToolSignature())) { + if (LamsToolService.LEADER_SELECTION_TOOL_SIGNATURE.equals(toolActivity.getTool().getToolSignature())) { return activity; } - - //in case of floating activity + + //in case of floating activity } else if (activityClass.equals(FloatingActivity.class)) { LearnerProgress learnerProgress = lessonService.getUserProgressForLesson(userId, lessonId); Map completedActivities = learnerProgress.getCompletedActivities(); - + //find the earliest finished Leader Select Activity Date leaderSelectActivityFinishDate = null; Activity leaderSelectionActivity = null; for (Activity completedActivity : completedActivities.keySet()) { - + if (completedActivity instanceof ToolActivity) { ToolActivity completedToolActivity = (ToolActivity) completedActivity; - if (LEADER_SELECTION_TOOL_SIGNATURE.equals(completedToolActivity.getTool().getToolSignature())) { + if (LamsToolService.LEADER_SELECTION_TOOL_SIGNATURE + .equals(completedToolActivity.getTool().getToolSignature())) { Date finishDate = completedActivities.get(completedActivity).getFinishDate(); - + if ((leaderSelectActivityFinishDate == null) || (finishDate.compareTo(leaderSelectActivityFinishDate) < 0)) { leaderSelectionActivity = completedToolActivity; @@ -227,9 +214,9 @@ } } - + } - + return leaderSelectionActivity; } @@ -250,21 +237,9 @@ } @Override - public Set getUsersForActivity(Long toolSessionId) { - ToolSession session = toolSessionDAO.getToolSession(toolSessionId); - return session != null ? session.getLearners() : new HashSet(); - } - - @Override public Integer getCountUsersForActivity(Long toolSessionId) { - ToolSession session = toolSessionDAO.getToolSession(toolSessionId); - if ( session.getToolSessionTypeId() == ToolSession.GROUPED_TYPE ) { - return toolSessionDAO.getCountUsersGrouped(toolSessionId); - } else { - // expect it to be 0 or 1 - return session.getLearners().size(); - } + return session.getLearners().size(); } /** @@ -305,16 +280,16 @@ public void setToolContentDAO(IToolContentDAO toolContentDAO) { this.toolContentDAO = toolContentDAO; } - + /** * * @param toolContentDAO */ public void setLamsCoreToolService(ILamsCoreToolService lamsCoreToolService) { this.lamsCoreToolService = lamsCoreToolService; } - + public void setLessonService(ILessonService lessonService) { this.lessonService = lessonService; } -} +} \ No newline at end of file