Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/Forum.java =================================================================== diff -u -r811003bdaefc92c8f7ddc49a1caaa9116cb8f729 -rc0758b4553e9608cf15b7722e371efbdc6246908 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/Forum.java (.../Forum.java) (revision 811003bdaefc92c8f7ddc49a1caaa9116cb8f729) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/Forum.java (.../Forum.java) (revision c0758b4553e9608cf15b7722e371efbdc6246908) @@ -9,6 +9,7 @@ import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; import org.apache.log4j.Logger; +import org.lamsfoundation.lams.tool.forum.util.ForumToolContentHandler; /** * Forum @@ -409,4 +410,9 @@ public void setAllowRichEditor(boolean allowRichEditor) { this.allowRichEditor = allowRichEditor; } + + public static Forum newInstance(Forum defaultContent, Long contentID2, ForumToolContentHandler forumToolContentHandler) { + + return null; + } } Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/ForumDao.java =================================================================== diff -u -rfd1d19665518ba6781ce9e3851889c077e8efff4 -rc0758b4553e9608cf15b7722e371efbdc6246908 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/ForumDao.java (.../ForumDao.java) (revision fd1d19665518ba6781ce9e3851889c077e8efff4) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/ForumDao.java (.../ForumDao.java) (revision c0758b4553e9608cf15b7722e371efbdc6246908) @@ -72,4 +72,8 @@ this.getHibernateTemplate().flush(); } + public void flush() { + this.getHibernateTemplate().flush(); + } + } Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/ForumToolSessionDao.java =================================================================== diff -u -r811003bdaefc92c8f7ddc49a1caaa9116cb8f729 -rc0758b4553e9608cf15b7722e371efbdc6246908 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/ForumToolSessionDao.java (.../ForumToolSessionDao.java) (revision 811003bdaefc92c8f7ddc49a1caaa9116cb8f729) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/ForumToolSessionDao.java (.../ForumToolSessionDao.java) (revision c0758b4553e9608cf15b7722e371efbdc6246908) @@ -48,4 +48,14 @@ return list; } + public void remove(Long sessionId) { + ForumToolSession session = getBySessionId(sessionId); + this.getHibernateTemplate().delete(session); + this.getHibernateTemplate().flush(); + } + + public void delete(ForumToolSession session){ + this.getHibernateTemplate().delete(session); + this.getHibernateTemplate().flush(); + } } Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/ForumService.java =================================================================== diff -u -rbbe88a48d8e196a1c6df3d8d915142c19857b052 -rc0758b4553e9608cf15b7722e371efbdc6246908 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/ForumService.java (.../ForumService.java) (revision bbe88a48d8e196a1c6df3d8d915142c19857b052) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/ForumService.java (.../ForumService.java) (revision c0758b4553e9608cf15b7722e371efbdc6246908) @@ -454,18 +454,57 @@ // ToolContentManager and ToolSessionManager methods //*************************************************************************************************************** public void copyToolContent(Long fromContentId, Long toContentId) throws ToolException { + if (fromContentId == null || toContentId == null) + throw new ToolException( + "Failed to create the SubmitFiles tool seession"); + + Forum fromContent = forumDao.getByContentId(fromContentId); + if ( fromContent == null ) { + fromContent = createDefaultContent(fromContentId); + } + Forum toContent = Forum.newInstance(fromContent,toContentId,forumToolContentHandler); + + forumDao.save(toContent); + } public void setAsDefineLater(Long toolContentId) throws DataMissingException, ToolException { + Forum forum = forumDao.getByContentId(toolContentId); + if(forum == null){ + throw new ToolException("No found tool content by given content ID:" + toolContentId); + } + forum.setDefineLater(true); + forumDao.flush(); } public void setAsRunOffline(Long toolContentId) throws DataMissingException, ToolException { + Forum forum = forumDao.getByContentId(toolContentId); + if(forum == null){ + throw new ToolException("No found tool content by given content ID:" + toolContentId); + } + forum.setRunOffline(true); + forumDao.flush(); } public void removeToolContent(Long toolContentId, boolean removeSessionData) throws SessionDataExistsException, ToolException { + Forum forum = forumDao.getByContentId(toolContentId); + if(removeSessionData){ + List list = forumToolSessionDao.getByContentId(toolContentId); + Iterator iter = list.iterator(); + while(iter.hasNext()){ + ForumToolSession session = (ForumToolSession) iter.next(); + forumToolSessionDao.delete(session); + } + } + forumDao.delete(forum); } public void createToolSession(Long toolSessionId, Long toolContentId) throws ToolException { + ForumToolSession session = new ForumToolSession(); + session.setSessionId(toolSessionId); + Forum forum = forumDao.getByContentId(toolContentId); + session.setForum(forum); + forumToolSessionDao.saveOrUpdate(session); } public String leaveToolSession(Long toolSessionId, Long learnerId) throws DataMissingException, ToolException { @@ -481,8 +520,27 @@ } public void removeToolSession(Long toolSessionId) throws DataMissingException, ToolException { + forumToolSessionDao.remove(toolSessionId); } - + + /* (non-Javadoc) + * @see org.lamsfoundation.lams.tool.sbmt.service.ISubmitFilesService#createDefaultContent(java.lang.Long) + */ + public Forum createDefaultContent(Long contentID) { + if (contentID == null) + { + String error="Could not retrieve default content id for Forum tool"; + log.error(error); + throw new ForumException(error); + } + + Forum defaultContent = getDefaultForum(); + //save default content by given ID. + Forum content = new Forum(); + content = Forum.newInstance(defaultContent,contentID,forumToolContentHandler); + + return content; + } //*************************************************************************************************************** // Get / Set methods //***************************************************************************************************************