Index: lams_tool_forum/conf/hibernate/mappings/org/lamsfoundation/lams/tool/forum/persistence/Forum.hbm.xml =================================================================== diff -u -r37bc758b9d7d1ba5a285a640e6d58113126f9620 -r6847f3627bbb8393b88988cae6c3cd8ad97f1600 --- lams_tool_forum/conf/hibernate/mappings/org/lamsfoundation/lams/tool/forum/persistence/Forum.hbm.xml (.../Forum.hbm.xml) (revision 37bc758b9d7d1ba5a285a640e6d58113126f9620) +++ lams_tool_forum/conf/hibernate/mappings/org/lamsfoundation/lams/tool/forum/persistence/Forum.hbm.xml (.../Forum.hbm.xml) (revision 6847f3627bbb8393b88988cae6c3cd8ad97f1600) @@ -128,8 +128,8 @@ Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/dto/MessageDTO.java =================================================================== diff -u -r7d76f87c9256aa602c7f30415bb8cab963b07936 -r6847f3627bbb8393b88988cae6c3cd8ad97f1600 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/dto/MessageDTO.java (.../MessageDTO.java) (revision 7d76f87c9256aa602c7f30415bb8cab963b07936) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/dto/MessageDTO.java (.../MessageDTO.java) (revision 6847f3627bbb8393b88988cae6c3cd8ad97f1600) @@ -34,9 +34,10 @@ private boolean hasAttachment; private short level; private int threadNum; - + private boolean isAuthor; /** * Get a MessageDTO instance from a given Message. + * * @param msg * @return */ @@ -51,35 +52,11 @@ dto.setHasAttachment(false); else dto.setHasAttachment(true); + return dto; } + /** - * Get a list of MessageDTO according to given list of Message and author name. - * These returned MessageDTO will use same author name with the given author name. - * @param msgSet - * @param authorName - * @return - */ - public static List getMessageDTO(List msgSet,String authorName){ - List retSet = new ArrayList(); - if(msgSet == null || msgSet.isEmpty()) - return retSet; - - Iterator iter = msgSet.iterator(); - while(iter.hasNext()){ - Message msg = (Message) iter.next(); - MessageDTO msgDto = new MessageDTO(); - if(msg.getAttachments() == null || msg.getAttachments().isEmpty()) - msgDto.setHasAttachment(false); - else - msgDto.setHasAttachment(true); - msgDto.setMessage(msg); - msgDto.setAuthor(authorName); - retSet.add(msgDto); - } - return retSet; - } - /** * Get a list of MessageDTO according to given list of Message. * @param msgList * @return @@ -99,6 +76,7 @@ msgDto.setHasAttachment(true); msgDto.setMessage(msg); msgDto.setAuthor(msg.getCreatedBy().getFirstName()+" "+msg.getCreatedBy().getLastName()); + retSet.add(msgDto); } return retSet; @@ -134,5 +112,13 @@ public void setThreadNum(int threadNum) { this.threadNum = threadNum; } + + public boolean getIsAuthor() { + return isAuthor; + } + + public void setAuthor(boolean isAuthor) { + this.isAuthor = isAuthor; + } } Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/Forum.hbm.xml =================================================================== diff -u -r37bc758b9d7d1ba5a285a640e6d58113126f9620 -r6847f3627bbb8393b88988cae6c3cd8ad97f1600 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/Forum.hbm.xml (.../Forum.hbm.xml) (revision 37bc758b9d7d1ba5a285a640e6d58113126f9620) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/Forum.hbm.xml (.../Forum.hbm.xml) (revision 6847f3627bbb8393b88988cae6c3cd8ad97f1600) @@ -128,8 +128,8 @@ Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/Forum.java =================================================================== diff -u -r37bc758b9d7d1ba5a285a640e6d58113126f9620 -r6847f3627bbb8393b88988cae6c3cd8ad97f1600 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/Forum.java (.../Forum.java) (revision 37bc758b9d7d1ba5a285a640e6d58113126f9620) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/Forum.java (.../Forum.java) (revision 6847f3627bbb8393b88988cae6c3cd8ad97f1600) @@ -63,15 +63,15 @@ //clone message if(messages != null){ Iterator iter = messages.iterator(); - Set set = new TreeSet(); + Set set = new HashSet(); while(iter.hasNext()) set.add(((Message)iter.next()).clone()); forum.messages = set; } //clone attachment if(attachments != null){ Iterator iter = attachments.iterator(); - Set set = new TreeSet(); + Set set = new HashSet(); while(iter.hasNext()) set.add(((Attachment)iter.next()).clone()); forum.attachments = set; @@ -327,8 +327,8 @@ * * * @hibernate.set lazy="true" - * cascade="all" - * inverse="false" + * inverse="true" + * cascade="none" * order-by="create_date desc" * @hibernate.collection-key column="forum_uid" * @hibernate.collection-one-to-many class="org.lamsfoundation.lams.tool.forum.persistence.Message" Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/Message.java =================================================================== diff -u -r37bc758b9d7d1ba5a285a640e6d58113126f9620 -r6847f3627bbb8393b88988cae6c3cd8ad97f1600 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/Message.java (.../Message.java) (revision 37bc758b9d7d1ba5a285a640e6d58113126f9620) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/Message.java (.../Message.java) (revision 6847f3627bbb8393b88988cae6c3cd8ad97f1600) @@ -314,8 +314,8 @@ /** * @param toolSession The toolSession that this Message belongs to */ - public void setToolSession(ForumToolSession forum) { - this.toolSession = forum; + public void setToolSession(ForumToolSession session) { + this.toolSession = session; } /** Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/MessageDao.java =================================================================== diff -u -r5cf73c3c3892579e89ad206d4d04c97bda7fd949 -r6847f3627bbb8393b88988cae6c3cd8ad97f1600 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/MessageDao.java (.../MessageDao.java) (revision 5cf73c3c3892579e89ad206d4d04c97bda7fd949) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/MessageDao.java (.../MessageDao.java) (revision 6847f3627bbb8393b88988cae6c3cd8ad97f1600) @@ -18,6 +18,8 @@ + " where parent_uid is null and forum_session_uid=?"; private static final String SQL_QUERY_FIND_TOPICS_FROM_AUTHOR = "from " + Message.class.getName() + " where is_authored = true and forum_uid=?"; + private static final String SQL_QUERY_FIND_CHILDREN = "from " + Message.class.getName() + + " where parent=?"; public void saveOrUpdate(Message message) { message.updateModificationData(); @@ -72,5 +74,9 @@ } } + public List getChildrenTopics(Long parentId) { + return this.getHibernateTemplate().find(SQL_QUERY_FIND_CHILDREN, parentId); + } + } Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/ForumService.java =================================================================== diff -u -r37bc758b9d7d1ba5a285a640e6d58113126f9620 -r6847f3627bbb8393b88988cae6c3cd8ad97f1600 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/ForumService.java (.../ForumService.java) (revision 37bc758b9d7d1ba5a285a640e6d58113126f9620) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/ForumService.java (.../ForumService.java) (revision 6847f3627bbb8393b88988cae6c3cd8ad97f1600) @@ -4,16 +4,13 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Date; -import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.SortedMap; import java.util.TreeMap; import java.util.Map.Entry; -import org.apache.commons.beanutils.PropertyUtils; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import org.apache.struts.upload.FormFile; @@ -107,24 +104,29 @@ public Message createRootTopic(Long forumId, Long sessionId, Message message) throws PersistenceException { //get Forum and ForumToolSesion - Forum forum = getForumByContentId(forumId); - message.setForum(forum); + if(message.getForum() == null){ + Forum forum = new Forum(); + forum.setUid(forumId); + message.setForum(forum); + } //if topic created by author, sessionId will be null. if(sessionId != null){ ForumToolSession session = getSessionBySessionId(sessionId); message.setToolSession(session); } + + if(message.getUid() == null){ + //update message sequence + MessageSeq msgSeq = new MessageSeq(); + msgSeq.setMessage(message); + msgSeq.setMessageLevel((short) 0); + //set itself as root + msgSeq.setRootMessage(message); + messageSeqDao.save(msgSeq); + } //create message in database messageDao.saveOrUpdate(message); - //update message sequence - MessageSeq msgSeq = new MessageSeq(); - msgSeq.setMessage(message); - msgSeq.setMessageLevel((short) 0); - //set itself as root - msgSeq.setRootMessage(message); - messageSeqDao.save(msgSeq); - return message; } @@ -148,7 +150,15 @@ } public void deleteTopic(Long topicUid) throws PersistenceException { - //TODO: cascade delete children topic + List children = messageDao.getChildrenTopics(topicUid); + //cascade delete children topic by recursive + if(children != null){ + Iterator iter = children.iterator(); + while(iter.hasNext()){ + Message msg = (Message) iter.next(); + this.deleteTopic(msg.getUid()); + } + } messageSeqDao.deleteByTopicId(topicUid); messageDao.deleteById(topicUid); } @@ -157,6 +167,8 @@ //set parent Message parent = this.getMessage(parentId); replyMessage.setParent(parent); + replyMessage.setForum(parent.getForum()); + replyMessage.setToolSession(parent.getToolSession()); messageDao.saveOrUpdate(replyMessage); //get root topic and create record in MessageSeq table @@ -234,41 +246,21 @@ public void removeToolSession(Long toolSessionId) throws DataMissingException, ToolException { } - public Attachment uploadInstructionFile(Long contentId, FormFile uploadFile, String fileType) throws PersistenceException{ - Attachment refile = null; + public Attachment uploadInstructionFile(FormFile uploadFile, String fileType) throws PersistenceException{ if(uploadFile == null || StringUtils.isEmpty(uploadFile.getFileName())) throw new ForumException("Could not find upload file: " + uploadFile); - Forum content = getForumByContentId(contentId); - if ( content == null || !contentId.equals(content.getContentId())) { - content = new Forum(); - content.setContentId(contentId); - //user firstly upload file without any other input, even the not-null - //field "title". Set title as default title. - content.setTitle(ForumConstants.DEFAULT_TITLE); - } + //upload file to repository NodeKey nodeKey = processFile(uploadFile,fileType); - Set fileSet = content.getAttachments(); - if(fileSet == null){ - fileSet = new HashSet(); - content.setAttachments(fileSet); - } + //create new attachement Attachment file = new Attachment(); file.setFileType(fileType); file.setFileUuid(nodeKey.getUuid()); file.setFileVersionId(nodeKey.getVersion()); file.setFileName(uploadFile.getFileName()); - fileSet.add(file); - forumDao.saveOrUpdate(content); - refile = new Attachment(); - try { - PropertyUtils.copyProperties(refile,file); - } catch (Exception e) { - throw new ForumException("Could not get return InstructionFile instance" +e.getMessage()); - } - return refile; + return file; } /** Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/IForumService.java =================================================================== diff -u -r37bc758b9d7d1ba5a285a640e6d58113126f9620 -r6847f3627bbb8393b88988cae6c3cd8ad97f1600 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/IForumService.java (.../IForumService.java) (revision 37bc758b9d7d1ba5a285a640e6d58113126f9620) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/IForumService.java (.../IForumService.java) (revision 6847f3627bbb8393b88988cae6c3cd8ad97f1600) @@ -27,7 +27,7 @@ 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 Attachment uploadInstructionFile(FormFile file, String type) throws PersistenceException; public Message getMessage(Long messageUid) throws PersistenceException; Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/util/ForumConstants.java =================================================================== diff -u -r37bc758b9d7d1ba5a285a640e6d58113126f9620 -r6847f3627bbb8393b88988cae6c3cd8ad97f1600 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/util/ForumConstants.java (.../ForumConstants.java) (revision 37bc758b9d7d1ba5a285a640e6d58113126f9620) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/util/ForumConstants.java (.../ForumConstants.java) (revision 6847f3627bbb8393b88988cae6c3cd8ad97f1600) @@ -28,6 +28,19 @@ public static final int SESSION_STATUS_FINISHED = 1; public static final String ALLOW_EDIT = "allowEdit"; public static final String ALLOW_RICH_EDITOR = "allowRichEditor"; + + public static final String ONLINE_ATTACHMENT = "online_att"; + public static final String OFFLINE_ATTACHMENT = "offline_att"; + + public static final String ATTACHMENT_LIST = "attachmentList"; + public static final String DELETED_ATTACHMENT_LIST = "deletedAttachmentList"; + + public static final String TOPIC_DELETED_ATTACHMENT_LIST = "topicDeletedAttachmentList"; + + public static final String NEW_FORUM_USER = "newUser"; + + public static final String DELETED_AUTHORING_TOPICS_LIST = "deletedAuthoringTopicList"; + } Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/AuthoringAction.java =================================================================== diff -u -r7e5622f2a1facf741b442bd53556f769b51433b2 -r6847f3627bbb8393b88988cae6c3cd8ad97f1600 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/AuthoringAction.java (.../AuthoringAction.java) (revision 7e5622f2a1facf741b442bd53556f769b51433b2) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/AuthoringAction.java (.../AuthoringAction.java) (revision 6847f3627bbb8393b88988cae6c3cd8ad97f1600) @@ -34,7 +34,6 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; -import org.apache.commons.beanutils.PropertyUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.math.NumberUtils; import org.apache.log4j.Logger; @@ -148,6 +147,10 @@ forum = forumService.getDefaultForum(); } topics = forumService.getAuthoredTopics(contentId); + //initialize attachmentList + List attachmentList = getAttachmentList(request); + attachmentList.addAll(forum.getAttachments()); + //tear down PO to normal object using clone() method forumForm.setForum((Forum) forum.clone()); } catch (Exception e) { @@ -156,6 +159,9 @@ } //set back STRUTS component value + //init it to avoid null exception in following handling + if(topics == null) + topics = new ArrayList(); request.getSession().setAttribute(ForumConstants.AUTHORING_TOPICS_LIST, topics); return mapping.findForward("success"); } @@ -164,9 +170,9 @@ *
    *
  1. Forum authoring infomation, e.g. online/offline instruction, title, advacnce options, etc.
  2. *
  3. Uploaded offline/online instruction files
  4. - *
  5. Author user information
  6. *
  7. Topics author created
  8. *
  9. Topics' attachment file
  10. + *
  11. Author user information
  12. *
* * @param mapping @@ -182,41 +188,91 @@ Forum forum = forumForm.getForum(); try { forumService = getForumManager(); + //if there are new user + ForumUser forumUser = (ForumUser) request.getSession().getAttribute(ForumConstants.NEW_FORUM_USER); + if(forumUser != null){ + forumService.createUser(forumUser); + } + request.getSession().setAttribute(ForumConstants.NEW_FORUM_USER,null); + Forum forumPO = forumService.getForumByContentId(forumForm.getToolContentID()); if(forumPO != null && forumForm.getToolContentID().equals(forum.getContentId()) ){ //merge web page change into PO - Set msgSet = forumPO.getMessages(); - Set attSet = forumPO.getAttachments(); - if(forum.getMessages() != null){ - if(msgSet == null){ - msgSet = new HashSet(); - forumPO.setMessages(msgSet); - } - //restore new topic into ForumPO message set. - Message msg; - Iterator iter = forum.getMessages().iterator(); - while(iter.hasNext()){ - msg = (Message) iter.next(); - //new topic, then add to PO - if(msg.getUid() == null) - msgSet.add(msg); -// if (topic != null && topic.getMessage() != null && topic.getMessage().getUid() != null) { -// getForumManager().deleteTopic(topic.getMessage().getUid()); -// } - //TODO:above JavaDoc save content... - - } + + //merge attachment info + Set attPOSet = forumPO.getAttachments(); + List attachmentList = getAttachmentList(request); + List deleteAttachmentList = getDeletedAttachmentList(request); + Iterator iter = attachmentList.iterator(); + while(iter.hasNext()){ + Attachment newAtt = (Attachment) iter.next(); + //add new attachment, UID is not null + if(newAtt.getUid() == null) + attPOSet.add(newAtt); } - PropertyUtils.copyProperties(forumPO,forum); + attachmentList.clear(); + + iter = deleteAttachmentList.iterator(); + while(iter.hasNext()){ + Attachment delAtt = (Attachment) iter.next(); + //delete from repository + forumService.deleteFromRepository(delAtt.getFileUuid(),delAtt.getFileVersionId()); + //it is an existed att, then delete it from current attachmentPO + if(delAtt.getUid() != null){ + Iterator attIter = attPOSet.iterator(); + while(attIter.hasNext()){ + Attachment att = (Attachment) attIter.next(); + if(delAtt.getUid().equals(att.getUid())){ + attIter.remove(); + break; + } + } + forumService.deleteForumAttachment(delAtt.getUid()); + }//end remove from persist value + } + deleteAttachmentList.clear(); + //copy back - forumPO.setAttachments(attSet); - forumPO.setMessages(msgSet); + forumPO.setAttachments(attPOSet); }else{ //new Forum, create it. forumPO = forum; forumPO.setContentId(forumForm.getToolContentID()); } - forumService.editForum(forumPO); + forum = forumService.editForum(forumPO); + + //Handle message + //delete message attachment + List topicDeleteAttachmentList = getTopicDeletedAttachmentList(request); + Iterator iter = topicDeleteAttachmentList.iterator(); + while(iter.hasNext()){ + Attachment delAtt = (Attachment) iter.next(); + //delete from repository + forumService.deleteFromRepository(delAtt.getFileUuid(),delAtt.getFileVersionId()); + } + topicDeleteAttachmentList.clear(); + + //handle topic + List topics = getTopicList(request); + iter = topics.iterator(); + while(iter.hasNext()){ + MessageDTO dto = (MessageDTO) iter.next(); + if(dto.getMessage() != null) + forumService.createRootTopic(forum.getUid(),null,dto.getMessage()); + } + //delete them from database. + List delTopics = getDeletedTopicList(request); + iter = delTopics.iterator(); + while(iter.hasNext()){ + MessageDTO dto = (MessageDTO) iter.next(); + if(dto.getMessage() != null) + forumService.deleteTopic(dto.getMessage().getUid()); + } + delTopics.clear(); + + //re initialize attachmentList + List attachmentList = getAttachmentList(request); + attachmentList.addAll(forum.getAttachments()); } catch (Exception e) { log.error(e); } @@ -266,10 +322,29 @@ else file = (FormFile) forumForm.getOnlineFile(); - Forum content = getContent(form); forumService = getForumManager(); - Attachment att = forumService.uploadInstructionFile(content.getContentId(), file, type); - //update session + //upload to repository + Attachment att = forumService.uploadInstructionFile(file, type); + + //handle session value + List attachmentList = getAttachmentList(request); + List deleteAttachmentList = getDeletedAttachmentList(request); + //first check exist attachment and delete old one (if exist) to deletedAttachmentList + Iterator iter = attachmentList.iterator(); + Attachment existAtt; + while(iter.hasNext()){ + existAtt = (Attachment) iter.next(); + if(StringUtils.equals(existAtt.getFileName(),att.getFileName())){ + //if there is same name attachment, delete old one + deleteAttachmentList.add(existAtt); + iter.remove(); + break; + } + } + //add to attachmentList + attachmentList.add(att); + + //update Html FORM, this will echo back to web page for display List list; if(StringUtils.equals(IToolContentHandler.TYPE_OFFLINE,type)){ list = forumForm.getOfflineFileList(); @@ -289,6 +364,8 @@ return mapping.findForward("success"); } + + /** * Delete offline instruction file from current Forum authoring page. * @param mapping @@ -326,30 +403,39 @@ Long versionID = new Long(WebUtil.readLongParam(request,"versionID")); Long uuID = new Long(WebUtil.readLongParam(request,"uuID")); - forumService = getForumManager(); - forumService.deleteFromRepository(uuID,versionID); - Attachment attachment = null; - List attachmentList; + //handle session value + List attachmentList = getAttachmentList(request); + List deleteAttachmentList = getDeletedAttachmentList(request); + //first check exist attachment and delete old one (if exist) to deletedAttachmentList + Iterator iter = attachmentList.iterator(); + Attachment existAtt; + while(iter.hasNext()){ + existAtt = (Attachment) iter.next(); + if(existAtt.getFileUuid().equals(uuID) && existAtt.getFileVersionId().equals(versionID)){ + //if there is same name attachment, delete old one + deleteAttachmentList.add(existAtt); + iter.remove(); + break; + } + } + + //handle web page display + List leftAttachments; if(StringUtils.equals(IToolContentHandler.TYPE_OFFLINE,type)){ - attachmentList = ((ForumForm)form).getOfflineFileList(); + leftAttachments = ((ForumForm)form).getOfflineFileList(); }else{ - attachmentList = ((ForumForm)form).getOnlineFileList(); + leftAttachments = ((ForumForm)form).getOnlineFileList(); } - Iterator iter = attachmentList.iterator(); + iter = leftAttachments.iterator(); while(iter.hasNext()){ Attachment att = (Attachment) iter.next(); if(versionID.equals(att.getFileVersionId()) && uuID.equals(att.getFileUuid())){ iter.remove(); - attachment = att; break; } } - if (attachment!= null && attachment.getUid() != null) { - forumService.deleteInstructionFile(contentID,uuID,versionID,type); - } - StringBuffer sb = new StringBuffer(); - iter = attachmentList.iterator(); + iter = leftAttachments.iterator(); while(iter.hasNext()){ Attachment file = (Attachment) iter.next(); sb.append("
  • ").append(file.getFileName()).append("\r\n"); @@ -405,11 +491,7 @@ */ private ActionForward newTopic(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { - List topics = (List) request.getSession().getAttribute(ForumConstants.AUTHORING_TOPICS_LIST); - if (topics == null) { - topics = new ArrayList(); - } - request.getSession().setAttribute(ForumConstants.AUTHORING_TOPICS_LIST, topics); + return mapping.findForward("success"); } /** @@ -427,7 +509,7 @@ public ActionForward createTopic(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException, PersistenceException { - List topics = (List) request.getSession().getAttribute(ForumConstants.AUTHORING_TOPICS_LIST); + List topics = getTopicList(request); //get login user (author) HttpSession ss = SessionManager.getSession(); //get back login user DTO @@ -446,6 +528,7 @@ if(forumUser == null){ //if user not exist, create new one in database forumUser = new ForumUser(user); + request.getSession().setAttribute(ForumConstants.NEW_FORUM_USER,forumUser); } message.setCreatedBy(forumUser); //same person with create at first time @@ -462,14 +545,10 @@ } message.setAttachments(attSet); - if (topics == null) { - topics = new ArrayList(); - } //save the new message into HttpSession topics.add(MessageDTO.getMessageDTO(message)); //echo back to web page - request.getSession().setAttribute(ForumConstants.AUTHORING_TOPICS_LIST, topics); request.setAttribute(ForumConstants.SUCCESS_FLAG,"CREATE_SUCCESS"); return mapping.findForward("success"); } @@ -486,14 +565,14 @@ public ActionForward deleteTopic(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws PersistenceException { - List topics = (List) request.getSession().getAttribute(ForumConstants.AUTHORING_TOPICS_LIST); + List topics = getTopicList(request); String topicIndex = (String) request.getParameter(ForumConstants.AUTHORING_TOPICS_INDEX); int topicIdx = NumberUtils.stringToInt(topicIndex,-1); if(topicIdx != -1){ - topics.remove(topicIdx); - //reset it into HttpSession - request.getSession().setAttribute(ForumConstants.AUTHORING_TOPICS_LIST,topics); + Object obj = topics.remove(topicIdx); + List delList = getDeletedTopicList(request); + delList.add(obj); } request.setAttribute(ForumConstants.SUCCESS_FLAG,"DELETE_SUCCESS"); @@ -513,7 +592,7 @@ public ActionForward viewTopic(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws PersistenceException { - List topics = (List) request.getSession().getAttribute(ForumConstants.AUTHORING_TOPICS_LIST); + List topics = getTopicList(request); String topicIndex = (String) request.getParameter(ForumConstants.AUTHORING_TOPICS_INDEX); int topicIdx = NumberUtils.stringToInt(topicIndex,-1); @@ -548,7 +627,7 @@ HttpServletResponse response) throws PersistenceException { MessageForm msgForm = (MessageForm)form; - List topics = (List) request.getSession().getAttribute(ForumConstants.AUTHORING_TOPICS_LIST); + List topics = getTopicList(request); String topicIndex = (String) request.getParameter(ForumConstants.AUTHORING_TOPICS_INDEX); int topicIdx = NumberUtils.stringToInt(topicIndex,-1); if(topicIdx != -1){ @@ -589,7 +668,7 @@ public ActionForward updateTopic(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws PersistenceException { //get value from HttpSession - List topics = (List) request.getSession().getAttribute(ForumConstants.AUTHORING_TOPICS_LIST); + List topics = getTopicList(request); //get param from HttpServletRequest String topicIndex = (String) request.getParameter(ForumConstants.AUTHORING_TOPICS_INDEX); int topicIdx = NumberUtils.stringToInt(topicIndex,-1); @@ -619,7 +698,6 @@ } request.setAttribute(ForumConstants.AUTHORING_TOPICS_INDEX,topicIndex); - request.getSession().setAttribute(ForumConstants.AUTHORING_TOPICS_LIST, topics); request.setAttribute(ForumConstants.SUCCESS_FLAG,"EDIT_SUCCESS"); return mapping.findForward("success"); } @@ -635,12 +713,9 @@ */ public ActionForward deleteAttachment(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws PersistenceException { - Long versionID = new Long(WebUtil.readLongParam(request,"versionID")); - Long uuID = new Long(WebUtil.readLongParam(request,"uuid")); - forumService = getForumManager(); - forumService.deleteFromRepository(uuID,versionID); + // get value from HttpSession - List topics = (List) request.getSession().getAttribute(ForumConstants.AUTHORING_TOPICS_LIST); + List topics = getTopicList(request); //get param from HttpServletRequest String topicIndex = (String) request.getParameter(ForumConstants.AUTHORING_TOPICS_INDEX); @@ -650,29 +725,39 @@ MessageDTO newMsg = (MessageDTO) topics.get(topicIdx); if(newMsg.getMessage()== null) newMsg.setMessage(new Message()); + //add delete topic attachment to HTTPSession + Set attSet = newMsg.getMessage().getAttachments(); + if(attSet != null){ + //only one attachment for topic + Attachment att = (Attachment) attSet.iterator().next(); + if(att != null){ + List topicDeletedAttachmentList = getTopicDeletedAttachmentList(request); + topicDeletedAttachmentList.add(att); + } + } + //set other infor about attachment newMsg.getMessage().setUpdated(new Date()); newMsg.setHasAttachment(false); newMsg.getMessage().setAttachments(null); } + request.setAttribute(ForumConstants.SUCCESS_FLAG,"ATT_SUCCESS_FLAG"); request.setAttribute(ForumConstants.AUTHORING_TOPICS_INDEX,topicIndex); return mapping.findForward("success"); } public ActionForward finishTopic(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws PersistenceException { - List topics = (List) request.getSession().getAttribute(ForumConstants.AUTHORING_TOPICS_LIST); + List topics = getTopicList(request); ForumForm forumForm = (ForumForm)form; Forum forum = forumForm.getForum(); Set msgSet = new HashSet(); - if(topics != null){ - Iterator iter = topics.iterator(); - while(iter.hasNext()){ - MessageDTO dto = (MessageDTO) iter.next(); - msgSet.add(dto.getMessage()); - } - } + Iterator iter = topics.iterator(); + while(iter.hasNext()){ + MessageDTO dto = (MessageDTO) iter.next(); + msgSet.add(dto.getMessage()); + } forum.setMessages(msgSet); return mapping.findForward("success"); @@ -687,19 +772,19 @@ * @param form * @return */ - private Forum getContent(ActionForm form) { - ForumForm authForm = (ForumForm) form; - Forum forum = authForm.getForum(); - - Forum content = new Forum(); - try { - PropertyUtils.copyProperties(content,forum); - } catch (Exception e) { - log.error(e); - } - content.setContentId(authForm.getToolContentID()); - return content; - } +// private Forum getContent(ActionForm form) { +// ForumForm authForm = (ForumForm) form; +// Forum forum = authForm.getForum(); +// +// Forum content = new Forum(); +// try { +// PropertyUtils.copyProperties(content,forum); +// } catch (Exception e) { +// log.error(e); +// } +// content.setContentId(authForm.getToolContentID()); +// return content; +// } private IForumService getForumManager() { if ( forumService == null ) { @@ -708,4 +793,54 @@ } return forumService; } + /** + * @param request + * @return + */ + private List getAttachmentList(HttpServletRequest request) { + return getListFromSession(request,ForumConstants.ATTACHMENT_LIST); + } + /** + * @param request + * @return + */ + private List getDeletedAttachmentList(HttpServletRequest request) { + return getListFromSession(request,ForumConstants.DELETED_ATTACHMENT_LIST); + } + /** + * @param request + * @return + */ + private List getTopicList(HttpServletRequest request) { + return getListFromSession(request,ForumConstants.AUTHORING_TOPICS_LIST); + } + /** + * @param request + * @return + */ + private List getTopicDeletedAttachmentList(HttpServletRequest request) { + return getListFromSession(request,ForumConstants.DELETED_ATTACHMENT_LIST); + } + /** + * @param request + * @return + */ + private List getDeletedTopicList(HttpServletRequest request) { + return getListFromSession(request,ForumConstants.DELETED_AUTHORING_TOPICS_LIST); + } + /** + * Get java.util.List from HttpSession by given name. + * + * @param request + * @param name + * @return + */ + private List getListFromSession(HttpServletRequest request,String name) { + List list = (List) request.getSession().getAttribute(name); + if(list == null){ + list = new ArrayList(); + request.getSession().setAttribute(name,list); + } + return list; + } } Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/LearningAction.java =================================================================== diff -u -r7d76f87c9256aa602c7f30415bb8cab963b07936 -r6847f3627bbb8393b88988cae6c3cd8ad97f1600 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/LearningAction.java (.../LearningAction.java) (revision 7d76f87c9256aa602c7f30415bb8cab963b07936) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/LearningAction.java (.../LearningAction.java) (revision 6847f3627bbb8393b88988cae6c3cd8ad97f1600) @@ -3,6 +3,7 @@ import java.io.IOException; import java.util.Date; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Set; @@ -178,8 +179,25 @@ forumService = getForumManager(); //get root topic list List msgDtoList = forumService.getTopicThread(topicId); + + //set current user to web page, so that can display "edit" button correct. Only author alow to edit. + HttpSession ss = SessionManager.getSession(); + //get back login user DTO + UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); + Long currUserId = new Long(user.getUserID().intValue()); + Iterator iter = msgDtoList.iterator(); + while(iter.hasNext()){ + MessageDTO dto = (MessageDTO) iter.next(); + if(dto.getMessage().getCreatedBy() != null + && currUserId.equals(dto.getMessage().getCreatedBy().getUserId())) + dto.setAuthor(true); + else + dto.setAuthor(false); + } + request.setAttribute(ForumConstants.AUTHORING_TOPIC_THREAD,msgDtoList); return mapping.findForward("success"); + } /** * Create a new root topic. Index: lams_tool_forum/web/WEB-INF/struts-config.xml =================================================================== diff -u -r5cf73c3c3892579e89ad206d4d04c97bda7fd949 -r6847f3627bbb8393b88988cae6c3cd8ad97f1600 --- lams_tool_forum/web/WEB-INF/struts-config.xml (.../struts-config.xml) (revision 5cf73c3c3892579e89ad206d4d04c97bda7fd949) +++ lams_tool_forum/web/WEB-INF/struts-config.xml (.../struts-config.xml) (revision 6847f3627bbb8393b88988cae6c3cd8ad97f1600) @@ -130,6 +130,7 @@ parameter="editTopic" scope="session"> +
    + @@ -48,6 +49,7 @@ +