Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/forumApplicationContext.xml =================================================================== diff -u -r24ca84b9e61b98c068eaa369cb194a35e5511162 -r33a3ed3f118b3e599ed6ef024c1b92a6f94225b1 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/forumApplicationContext.xml (.../forumApplicationContext.xml) (revision 24ca84b9e61b98c068eaa369cb194a35e5511162) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/forumApplicationContext.xml (.../forumApplicationContext.xml) (revision 33a3ed3f118b3e599ed6ef024c1b92a6f94225b1) @@ -138,6 +138,7 @@ PROPAGATION_REQUIRED,-java.lang.Exception PROPAGATION_REQUIRED,-java.lang.Exception PROPAGATION_REQUIRED,-java.lang.Exception + PROPAGATION_REQUIRED,-java.lang.Exception PROPAGATION_REQUIRED,-java.lang.Exception PROPAGATION_REQUIRED,-java.lang.Exception @@ -147,4 +148,4 @@ - + \ No newline at end of file Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/MessageDao.java =================================================================== diff -u -r27d386f3472e12afab03d53dfde3ed9b1c9a44d3 -r33a3ed3f118b3e599ed6ef024c1b92a6f94225b1 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/MessageDao.java (.../MessageDao.java) (revision 27d386f3472e12afab03d53dfde3ed9b1c9a44d3) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/MessageDao.java (.../MessageDao.java) (revision 33a3ed3f118b3e599ed6ef024c1b92a6f94225b1) @@ -39,6 +39,9 @@ private static final String SQL_QUERY_FIND_TOPICS_FROM_AUTHOR = "from " + Message.class.getName() + " where is_authored = true and forum_uid=? order by create_date"; + private static final String SQL_QUERY_COUNT_SESSION_TOPICS_FROM_AUTHOR = "select count(*) from " + Message.class.getName() + + " as m where m.isAuthored = true and m.toolSession.uid=?"; + private static final String SQL_QUERY_FIND_CHILDREN = "from " + Message.class.getName() + " where parent=?"; @@ -127,5 +130,12 @@ else return 0; } + public boolean hasAuthoredTopics(Long sessionId) { + List list = this.getHibernateTemplate().find(SQL_QUERY_COUNT_SESSION_TOPICS_FROM_AUTHOR,new Object[]{sessionId}); + if(list != null && list.size() > 0) + return ((Integer)list.get(0)).intValue() > 0 ? true:false; + else + return false; + } } Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/ForumService.java =================================================================== diff -u -r24ca84b9e61b98c068eaa369cb194a35e5511162 -r33a3ed3f118b3e599ed6ef024c1b92a6f94225b1 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/ForumService.java (.../ForumService.java) (revision 24ca84b9e61b98c068eaa369cb194a35e5511162) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/ForumService.java (.../ForumService.java) (revision 33a3ed3f118b3e599ed6ef024c1b92a6f94225b1) @@ -459,7 +459,25 @@ currentUser.setSessionFinished(true); forumUserDao.save(currentUser); } - + + public void cloneContentTopics(Long contentID, Long sessionID) { + //only session does not have content topcis + if(!messageDao.hasAuthoredTopics(sessionID)){ + Forum forum = (Forum) forumDao.getByContentId(contentID); + Set contentTopcis = forum.getMessages(); + + //only forum has content topics, clone happens + if(contentTopcis != null && contentTopcis.size() > 0){ + Iterator iter = contentTopcis.iterator(); + ForumToolSession session = forumToolSessionDao.getBySessionId(sessionID); + while(iter.hasNext()){ + Message msg = (Message) iter.next(); + msg.setToolSession(session); + messageDao.update(msg); + } + } + } + } //*************************************************************************************************************** // Private methods //*************************************************************************************************************** @@ -583,6 +601,7 @@ continue; msg.setReplyNumber(0); msg.setCreated(new Date()); + msg.setUpdated(new Date()); msg.setLastReplyDate(new Date()); msg.setHideFlag(false); msg.setForum(toContent); @@ -718,34 +737,11 @@ Forum forum = forumDao.getByContentId(toolContentId); session.setForum(forum); forumToolSessionDao.saveOrUpdate(session); - - //also clone author created topic from this forum tool content!!! - //this can avoid topic record information conflict when multiple sessions are against same tool content - //for example, the reply number maybe various for different sessions. - List topicsFromAuthor = messageDao.getTopicsFromAuthor(session.getForum().getUid()); - - //sorted by last post date - Message msg; - SortedMap map = new TreeMap(new DateComparator()); - Iterator iter = topicsFromAuthor.iterator(); - while(iter.hasNext()){ - msg = (Message) iter.next(); - //Don't copy other session's topic, only from tool content!!!. - if(msg.getToolSession() != null) - continue; - //set this message forum Uid as toContent - if(!msg.getIsAuthored()) - continue; - Message newMsg = (Message) msg.clone(); - //reset some value. - newMsg.setReplyNumber(0); - newMsg.setHideFlag(false); - //it should be new message - newMsg.setUid(null); - //!!! set current session to authored message - newMsg.setToolSession(session); - createRootTopic(toolContentId,null,newMsg); - } + + //Update(29/08/2006): Do not clone author topic BUG: LDEV-649. +// also clone author created topic from this forum tool content!!! +// this can avoid topic record information conflict when multiple sessions are against same tool content +// for example, the reply number maybe various for different sessions. } public String leaveToolSession(Long toolSessionId, Long learnerId) throws DataMissingException, ToolException { @@ -1030,4 +1026,6 @@ this.forumReportDAO = forumReportDAO; } + + } \ No newline at end of file Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/IForumService.java =================================================================== diff -u -rf6f0e93d2134d055aadd9414aee1b588f0669c19 -r33a3ed3f118b3e599ed6ef024c1b92a6f94225b1 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/IForumService.java (.../IForumService.java) (revision f6f0e93d2134d055aadd9414aee1b588f0669c19) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/IForumService.java (.../IForumService.java) (revision 33a3ed3f118b3e599ed6ef024c1b92a6f94225b1) @@ -90,6 +90,18 @@ * @throws PersistenceException */ public void deleteForumAttachment(Long attachmentId) throws PersistenceException; + + /** + * Clone topics from tool content and give these new topics with given SessionID if + * this session has not such topics yet. + * This method will be called once learner page open. Program does not + * clone content topics when createToolSession() is called, the reason is define later + * page could change content topics. For more detail see LDEV-649. + * + * @param contentID + * @param sessionID + */ + public void cloneContentTopics(Long contentID, Long sessionID); //************************************************************************************ //Topic Method //************************************************************************************ Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/AuthoringAction.java =================================================================== diff -u -rc261f143be0756641bb0423662c0175aeb91ed7b -r33a3ed3f118b3e599ed6ef024c1b92a6f94225b1 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/AuthoringAction.java (.../AuthoringAction.java) (revision c261f143be0756641bb0423662c0175aeb91ed7b) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/AuthoringAction.java (.../AuthoringAction.java) (revision 33a3ed3f118b3e599ed6ef024c1b92a6f94225b1) @@ -178,7 +178,7 @@ //get back the topic list and display them on page forumService = getForumManager(); - List topics = null; + List topics = null; Forum forum = null; try { forum = forumService.getForumByContentId(contentId); @@ -213,7 +213,7 @@ //set back STRUTS component value //init it to avoid null exception in following handling if(topics == null) - topics = new ArrayList(); + topics = new ArrayList(); sessionMap.put(ForumConstants.AUTHORING_TOPICS_LIST, topics); return mapping.findForward("success"); Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/LearningAction.java =================================================================== diff -u -rffabb2dde38a13ce01088c5787de450db4f271db -r33a3ed3f118b3e599ed6ef024c1b92a6f94225b1 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/LearningAction.java (.../LearningAction.java) (revision ffabb2dde38a13ce01088c5787de450db4f271db) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/LearningAction.java (.../LearningAction.java) (revision 33a3ed3f118b3e599ed6ef024c1b92a6f94225b1) @@ -127,10 +127,11 @@ /** * Display root topics of a forum. This page will be the initial page of * Learner page. + * @throws Exception * */ private ActionForward viewForm(ActionMapping mapping, ActionForm form, - HttpServletRequest request, HttpServletResponse response) { + HttpServletRequest request, HttpServletResponse response) throws Exception { //initial Session Map String sessionMapID = request.getParameter(ForumConstants.ATTR_SESSION_MAP_ID); @@ -161,11 +162,12 @@ // Try to get ForumID according to sessionId forumService = getForumManager(); ForumToolSession session = forumService.getSessionBySessionId(sessionId); + if (session == null || session.getForum() == null) { log.error("Failed on getting session by given sessionID:" + sessionId); - return mapping.findForward("error"); + throw new Exception("Failed on getting session by given sessionID:" + sessionId); } - + Forum forum = session.getForum(); //lock on finish ForumUser forumUser = getCurrentUser(request,sessionId); @@ -180,6 +182,12 @@ return mapping.findForward("runOffline"); } + + //try to clone topics from :See bug LDEV-649 + Long contentId = forum.getContentId(); + forumService.cloneContentTopics(contentId, sessionId); + + //set some option flag to HttpSession Long forumId = forum.getUid(); Boolean allowRichEditor = new Boolean(forum.isAllowRichEditor()); int allowNumber = forum.getLimitedChar();