Index: lams_tool_forum/conf/xdoclet/struts-actions.xml
===================================================================
diff -u -rcff06c3c3492ed5b4efc013a3e4d8b0f50933b93 -r86fab777fa621158cd635f297d3be6987b7d99f0
--- lams_tool_forum/conf/xdoclet/struts-actions.xml (.../struts-actions.xml) (revision cff06c3c3492ed5b4efc013a3e4d8b0f50933b93)
+++ lams_tool_forum/conf/xdoclet/struts-actions.xml (.../struts-actions.xml) (revision 86fab777fa621158cd635f297d3be6987b7d99f0)
@@ -144,45 +144,61 @@
+ name="messageForm"
+ validate="false"
+ parameter="newReplyTopic"
+ scope="request">
-
-
+
+
+
+
+ parameter="deleteTopic"
+ scope="request">
Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/MessageDao.java
===================================================================
diff -u -rcff06c3c3492ed5b4efc013a3e4d8b0f50933b93 -r86fab777fa621158cd635f297d3be6987b7d99f0
--- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/MessageDao.java (.../MessageDao.java) (revision cff06c3c3492ed5b4efc013a3e4d8b0f50933b93)
+++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/MessageDao.java (.../MessageDao.java) (revision 86fab777fa621158cd635f297d3be6987b7d99f0)
@@ -22,11 +22,13 @@
public void saveOrUpdate(Message message) {
message.updateModificationData();
this.getHibernateTemplate().saveOrUpdate(message);
+ this.getHibernateTemplate().flush();
}
public void save(Message message) {
message.updateModificationData();
this.getHibernateTemplate().save(message);
+ this.getHibernateTemplate().flush();
}
public Message getById(Long messageId) {
return (Message) getHibernateTemplate().get(Message.class,messageId);
@@ -64,8 +66,10 @@
public void deleteById(Long uid) {
Message msg = getById(uid);
- if(msg != null)
+ if(msg != null){
this.getHibernateTemplate().delete(msg);
+ this.getHibernateTemplate().flush();
+ }
}
Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/ForumService.java
===================================================================
diff -u -rdc2c4669a29d722cfee09e59636ea9677dcdf64d -r86fab777fa621158cd635f297d3be6987b7d99f0
--- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/ForumService.java (.../ForumService.java) (revision dc2c4669a29d722cfee09e59636ea9677dcdf64d)
+++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/ForumService.java (.../ForumService.java) (revision 86fab777fa621158cd635f297d3be6987b7d99f0)
@@ -98,10 +98,6 @@
forumDao.delete(forum);
}
- public List getTopics(Long forumId) throws PersistenceException {
- return messageDao.allAuthoredMessage(forumId);
- }
-
public void deleteForumAttachment(Long attachmentId) throws PersistenceException {
Attachment attachment = (Attachment) attachmentDao.getById(attachmentId);
attachmentDao.delete(attachment);
@@ -118,7 +114,7 @@
message.setToolSession(session);
}
//create message in database
- messageDao.save(message);
+ messageDao.saveOrUpdate(message);
//update message sequence
MessageSeq msgSeq = new MessageSeq();
@@ -146,13 +142,14 @@
return message;
}
- public Message getMessage(Long messageId) throws PersistenceException {
- return (Message) messageDao.getById(messageId);
+ public Message getMessage(Long messageUid) throws PersistenceException {
+ return (Message) messageDao.getById(messageUid);
}
public void deleteTopic(Long topicUid) throws PersistenceException {
+ //TODO: cascade delete children topic
+ messageSeqDao.deleteByTopicId(topicUid);
messageDao.deleteById(topicUid);
- messageSeqDao.deleteByTopicId(topicUid);
}
public Message replyTopic(Long parentId, Message replyMessage) throws PersistenceException {
@@ -459,7 +456,7 @@
Iterator iter;
MessageSeq msgSeq;
List msgDtoList = new ArrayList();
- iter =map.keySet().iterator();
+ iter =map.entrySet().iterator();
while(iter.hasNext()){
Map.Entry entry = (Entry) iter.next();
msgSeq = (MessageSeq) entry.getKey();
@@ -485,4 +482,13 @@
public void setForumToolSessionDao(ForumToolSessionDao forumToolSessionDao) {
this.forumToolSessionDao = forumToolSessionDao;
}
+
+ public Long getRootTopicId(Long topicId) {
+ MessageSeq seq = messageSeqDao.getByTopicId(topicId);
+ if(seq == null ||seq.getRootMessage() == null){
+ log.error("A sequence information can not be found for topic ID:" + topicId);
+ return null;
+ }
+ return seq.getRootMessage().getUid();
+ }
}
Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/IForumService.java
===================================================================
diff -u -rcff06c3c3492ed5b4efc013a3e4d8b0f50933b93 -r86fab777fa621158cd635f297d3be6987b7d99f0
--- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/IForumService.java (.../IForumService.java) (revision cff06c3c3492ed5b4efc013a3e4d8b0f50933b93)
+++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/IForumService.java (.../IForumService.java) (revision 86fab777fa621158cd635f297d3be6987b7d99f0)
@@ -24,13 +24,12 @@
public Forum getForumByContentId(Long contentID) throws PersistenceException;
public void deleteForum(Long forumId) throws PersistenceException;
- public List getTopics(Long forumId) throws PersistenceException;
public void deleteForumAttachment(Long attachmentId) throws PersistenceException;
public Forum createForum(Long contentId) throws PersistenceException;
public Attachment uploadInstructionFile(Long contentId, FormFile file, String type) throws PersistenceException;
- public Message getMessage(Long messageId) throws PersistenceException;
+ public Message getMessage(Long messageUid) throws PersistenceException;
public Message createRootTopic(Long forumId, Long sessionId, Message message) throws PersistenceException ;
public Message updateTopic(Message message) throws PersistenceException;
@@ -69,4 +68,10 @@
public ForumUser getUserByUserId(Long userId);
public void createUser(ForumUser forumUser);
public ForumToolSession getSessionBySessionId(Long sessionId);
+ /**
+ * This method will look up root topic ID by any level topicID.
+ * @param topicId
+ * @return
+ */
+ public Long getRootTopicId(Long topicId);
}
Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/util/DateComparator.java
===================================================================
diff -u -rdc2c4669a29d722cfee09e59636ea9677dcdf64d -r86fab777fa621158cd635f297d3be6987b7d99f0
--- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/util/DateComparator.java (.../DateComparator.java) (revision dc2c4669a29d722cfee09e59636ea9677dcdf64d)
+++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/util/DateComparator.java (.../DateComparator.java) (revision 86fab777fa621158cd635f297d3be6987b7d99f0)
@@ -34,7 +34,7 @@
log.error("Topic is not Date instance.");
return 0;
}
- return ((Date)arg0).after(((Date)arg0))?1:-1;
+ return ((Date)arg0).before(((Date)arg1))?1:-1;
}
}
Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/util/ForumConstants.java
===================================================================
diff -u -rff26fa967dd8f1982453cbe5c83381194a79f732 -r86fab777fa621158cd635f297d3be6987b7d99f0
--- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/util/ForumConstants.java (.../ForumConstants.java) (revision ff26fa967dd8f1982453cbe5c83381194a79f732)
+++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/util/ForumConstants.java (.../ForumConstants.java) (revision 86fab777fa621158cd635f297d3be6987b7d99f0)
@@ -16,7 +16,8 @@
public static final String AUTHORING_DTO = "authoring";
public static final String AUTHORING_TOPICS_LIST = "topicList";
public static final String AUTHORING_TOPICS_INDEX = "topicIndex";
- public static final String AUTHORING_TOPICS = "topic";
+ public static final String AUTHORING_TOPIC_THREAD = "topicThread";
+ public static final String AUTHORING_TOPIC = "topic";
public static final String DEFAULT_TITLE = "Forum";
//TODO:hard code!!! need to read from config
Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/util/TopicComparator.java
===================================================================
diff -u -rf88a2a4d76c8b1b50ef5a09a64c0564cc929cf11 -r86fab777fa621158cd635f297d3be6987b7d99f0
--- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/util/TopicComparator.java (.../TopicComparator.java) (revision f88a2a4d76c8b1b50ef5a09a64c0564cc929cf11)
+++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/util/TopicComparator.java (.../TopicComparator.java) (revision 86fab777fa621158cd635f297d3be6987b7d99f0)
@@ -46,7 +46,7 @@
Message parent1,parent2;
//choose the smaller level value
short lessLevel = level1>level2? level2:level1;
- for(int compareLevel=0;compareLevel < lessLevel;compareLevel++){
+ for(int compareLevel=0;compareLevel <= lessLevel;compareLevel++){
//init value, loop from current message
parent1 = msg1;
parent2 = msg2;
@@ -70,13 +70,23 @@
parent2 = parent2.getParent();
level2--;
}
+ //this comparation will handle different branch node
if(parent1 != parent2){
//compare last modified date, the latest is at beginning
- return parent1.getUpdated().after(parent2.getUpdated())?1:-1;
+ return parent1.getUpdated().before(parent2.getUpdated())?1:-1;
}
+ //this comparation will handle same branch node
+ //the direct parent level, their parent(or themselves) are still equal
+ if(compareLevel==lessLevel){
+ if(msgSeq1.getMessageLevel() != msgSeq2.getMessageLevel())
+ return msgSeq1.getMessageLevel() -msgSeq2.getMessageLevel();
+ else
+ return msg1.getUpdated().before(msg2.getUpdated())?1:-1;
+ }
+
}
- return msg1.getUpdated().after(msg2.getUpdated())?1:-1;
+ return msg1.getUpdated().before(msg2.getUpdated())?1:-1;
}
}
Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/AuthoringAction.java
===================================================================
diff -u -rcff06c3c3492ed5b4efc013a3e4d8b0f50933b93 -r86fab777fa621158cd635f297d3be6987b7d99f0
--- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/AuthoringAction.java (.../AuthoringAction.java) (revision cff06c3c3492ed5b4efc013a3e4d8b0f50933b93)
+++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/AuthoringAction.java (.../AuthoringAction.java) (revision 86fab777fa621158cd635f297d3be6987b7d99f0)
@@ -250,7 +250,7 @@
if(topicIdx != -1){
MessageDTO topic = (MessageDTO) topics.get(topicIdx);
request.setAttribute(ForumConstants.AUTHORING_TOPICS_INDEX,topicIndex);
- request.setAttribute(ForumConstants.AUTHORING_TOPICS,topic);
+ request.setAttribute(ForumConstants.AUTHORING_TOPIC,topic);
}
return mapping.findForward("success");
@@ -267,7 +267,7 @@
if (topic != null) {
msgForm.setMessage(topic.getMessage());
}
- request.setAttribute(ForumConstants.AUTHORING_TOPICS,topic);
+ request.setAttribute(ForumConstants.AUTHORING_TOPIC,topic);
}
request.setAttribute(ForumConstants.AUTHORING_TOPICS_INDEX,topicIndex);
return mapping.findForward("success");
Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/LearningAction.java
===================================================================
diff -u -rcff06c3c3492ed5b4efc013a3e4d8b0f50933b93 -r86fab777fa621158cd635f297d3be6987b7d99f0
--- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/LearningAction.java (.../LearningAction.java) (revision cff06c3c3492ed5b4efc013a3e4d8b0f50933b93)
+++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/LearningAction.java (.../LearningAction.java) (revision 86fab777fa621158cd635f297d3be6987b7d99f0)
@@ -160,7 +160,7 @@
forumService = getForumManager();
List msgDtoList = forumService.getTopicThread(topicId);
- request.setAttribute(ForumConstants.AUTHORING_TOPICS,msgDtoList);
+ request.setAttribute(ForumConstants.AUTHORING_TOPIC_THREAD,msgDtoList);
return mapping.findForward("success");
}
/**
@@ -196,6 +196,9 @@
Long sessionId = (Long) request.getSession().getAttribute(AttributeNames.PARAM_TOOL_SESSION_ID);
forumService.createRootTopic(forumId,sessionId,message);
+ //echo back current root topic to fourm init page
+ List rootTopics = forumService.getRootTopics(sessionId);
+ request.setAttribute(ForumConstants.AUTHORING_TOPICS_LIST,MessageDTO.getMessageDTO(rootTopics));
return mapping.findForward("success");
}
/**
@@ -221,7 +224,7 @@
}
//cache this parentId in order to create reply
- request.setAttribute("parentId",parentId);
+ request.getSession().setAttribute("parentId",parentId);
return mapping.findForward("success");
}
/**
@@ -235,7 +238,7 @@
*/
private ActionForward replyTopic(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
- Long parentId = new Long(WebUtil.readLongParam(request,"parentId"));
+ Long parentId = (Long) request.getSession().getAttribute("parentId");
MessageForm messageForm = (MessageForm) form;
Message message = messageForm.getMessage();
@@ -252,6 +255,12 @@
forumService = getForumManager();
forumService.replyTopic(parentId,message);
+ //echo back this topic thread into page
+ forumService = getForumManager();
+ Long rootTopicId = forumService.getRootTopicId(parentId);
+ List msgDtoList = forumService.getTopicThread(rootTopicId);
+ request.setAttribute(ForumConstants.AUTHORING_TOPIC_THREAD,msgDtoList);
+
return mapping.findForward("success");
}
/**
@@ -273,8 +282,11 @@
if(topic != null){
MessageForm msgForm = (MessageForm)form;
msgForm.setMessage(topic.getMessage());
+ request.setAttribute(ForumConstants.AUTHORING_TOPIC,topic);
}
-
+
+ //cache this topicId in order to create reply
+ request.getSession().setAttribute("topicId",topicId);
return mapping.findForward("success");
}
/**
@@ -290,7 +302,7 @@
public ActionForward updateTopic(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws PersistenceException {
//get value from HttpSession
- Long topicId = new Long(WebUtil.readLongParam(request,"topicId"));
+ Long topicId = (Long) request.getSession().getAttribute("topicId");
forumService = getForumManager();
MessageForm messageForm = (MessageForm) form;
@@ -305,6 +317,12 @@
//save message into database
forumService.updateTopic(messagePO);
+
+ //echo back this topic thread into page
+ forumService = getForumManager();
+ Long rootTopicId = forumService.getRootTopicId(topicId);
+ List msgDtoList = forumService.getTopicThread(rootTopicId);
+ request.setAttribute(ForumConstants.AUTHORING_TOPIC_THREAD,msgDtoList);
return mapping.findForward("success");
}
@@ -325,6 +343,14 @@
Long topicId = new Long(WebUtil.readLongParam(request,"topicId"));
getForumManager().deleteTopic(topicId);
+
+
+ //echo back this topic thread into page
+ forumService = getForumManager();
+ Long rootTopicId = forumService.getRootTopicId(topicId);
+ List msgDtoList = forumService.getTopicThread(rootTopicId);
+ request.setAttribute(ForumConstants.AUTHORING_TOPIC_THREAD,msgDtoList);
+
return mapping.findForward("success");
}
@@ -353,7 +379,7 @@
messagePO.setAttachments(null);
//save message into database
forumService.updateTopic(messagePO);
-
+
return mapping.findForward("success");
}
@@ -367,10 +393,7 @@
private MessageDTO getTopic(Long topicId) {
//get Topic content according to TopicID
forumService = getForumManager();
- List topics = forumService.getTopics(topicId);
- MessageDTO topic = null;
- if(topics != null && !topics.isEmpty())
- topic = MessageDTO.getMessageDTO((Message) topics.get(0));
+ MessageDTO topic = MessageDTO.getMessageDTO(forumService.getMessage(topicId));
return topic;
}
Index: lams_tool_forum/web/WEB-INF/struts-config.xml
===================================================================
diff -u -rcff06c3c3492ed5b4efc013a3e4d8b0f50933b93 -r86fab777fa621158cd635f297d3be6987b7d99f0
--- lams_tool_forum/web/WEB-INF/struts-config.xml (.../struts-config.xml) (revision cff06c3c3492ed5b4efc013a3e4d8b0f50933b93)
+++ lams_tool_forum/web/WEB-INF/struts-config.xml (.../struts-config.xml) (revision 86fab777fa621158cd635f297d3be6987b7d99f0)
@@ -176,42 +176,51 @@
+ name="messageForm"
+ validate="false"
+ parameter="newReplyTopic"
+ scope="request">
+ parameter="deleteTopic"
+ scope="request">
Index: lams_tool_forum/web/jsps/learning/edit.jsp
===================================================================
diff -u
--- lams_tool_forum/web/jsps/learning/edit.jsp (revision 0)
+++ lams_tool_forum/web/jsps/learning/edit.jsp (revision 86fab777fa621158cd635f297d3be6987b7d99f0)
@@ -0,0 +1,10 @@
+<%@ include file="/includes/taglibs.jsp" %>
+
+
+
+
+
+
Index: lams_tool_forum/web/jsps/learning/message/topiceditform.jsp
===================================================================
diff -u -rcff06c3c3492ed5b4efc013a3e4d8b0f50933b93 -r86fab777fa621158cd635f297d3be6987b7d99f0
--- lams_tool_forum/web/jsps/learning/message/topiceditform.jsp (.../topiceditform.jsp) (revision cff06c3c3492ed5b4efc013a3e4d8b0f50933b93)
+++ lams_tool_forum/web/jsps/learning/message/topiceditform.jsp (.../topiceditform.jsp) (revision 86fab777fa621158cd635f297d3be6987b7d99f0)
@@ -26,7 +26,7 @@
-
+
Index: lams_tool_forum/web/jsps/learning/message/topicview.jsp
===================================================================
diff -u -rcff06c3c3492ed5b4efc013a3e4d8b0f50933b93 -r86fab777fa621158cd635f297d3be6987b7d99f0
--- lams_tool_forum/web/jsps/learning/message/topicview.jsp (.../topicview.jsp) (revision cff06c3c3492ed5b4efc013a3e4d8b0f50933b93)
+++ lams_tool_forum/web/jsps/learning/message/topicview.jsp (.../topicview.jsp) (revision 86fab777fa621158cd635f297d3be6987b7d99f0)
@@ -1,58 +1,62 @@
-
-
Index: lams_tool_forum/web/jsps/learning/viewtopic.jsp
===================================================================
diff -u -rcff06c3c3492ed5b4efc013a3e4d8b0f50933b93 -r86fab777fa621158cd635f297d3be6987b7d99f0
--- lams_tool_forum/web/jsps/learning/viewtopic.jsp (.../viewtopic.jsp) (revision cff06c3c3492ed5b4efc013a3e4d8b0f50933b93)
+++ lams_tool_forum/web/jsps/learning/viewtopic.jsp (.../viewtopic.jsp) (revision 86fab777fa621158cd635f297d3be6987b7d99f0)
@@ -1,6 +1,4 @@
<%@ include file="/includes/taglibs.jsp" %>
-
- <%@ include file="/jsps/learning/message/topicview.jsp" %>
-
+<%@ include file="/jsps/learning/message/topicview.jsp" %>