Index: lams_tool_forum/conf/hibernate/mappings/org/lamsfoundation/lams/tool/forum/persistence/Forum.hbm.xml
===================================================================
RCS file: /usr/local/cvsroot/lams_tool_forum/conf/hibernate/mappings/org/lamsfoundation/lams/tool/forum/persistence/Attic/Forum.hbm.xml,v
diff -u -r1.8 -r1.9
--- lams_tool_forum/conf/hibernate/mappings/org/lamsfoundation/lams/tool/forum/persistence/Forum.hbm.xml 1 Nov 2005 05:30:54 -0000 1.8
+++ lams_tool_forum/conf/hibernate/mappings/org/lamsfoundation/lams/tool/forum/persistence/Forum.hbm.xml 14 Nov 2005 03:09:58 -0000 1.9
@@ -83,23 +83,23 @@
javax.servlet.jsp.jstl.fmt.localizationContext
org.lamsfoundation.lams.tool.forum.web.ApplicationResources
+
contextConfigLocation
classpath:/org/lamsfoundation/lams/applicationContext.xml
classpath:/org/lamsfoundation/lams/contentrepository/applicationContext.xml
+ classpath:/org/lamsfoundation/lams/tool/toolApplicationContext.xml
classpath:/forumApplicationContext.xml
Index: lams_tool_forum/src/java/forumApplicationContext.xml
===================================================================
RCS file: /usr/local/cvsroot/lams_tool_forum/src/java/Attic/forumApplicationContext.xml,v
diff -u -r1.17 -r1.18
--- lams_tool_forum/src/java/forumApplicationContext.xml 14 Nov 2005 00:19:10 -0000 1.17
+++ lams_tool_forum/src/java/forumApplicationContext.xml 14 Nov 2005 03:09:59 -0000 1.18
@@ -85,6 +85,9 @@
+
+
+
Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/Attachment.java
===================================================================
RCS file: /usr/local/cvsroot/lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/Attachment.java,v
diff -u -r1.9 -r1.10
--- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/Attachment.java 14 Nov 2005 00:19:10 -0000 1.9
+++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/Attachment.java 14 Nov 2005 03:09:58 -0000 1.10
@@ -4,6 +4,7 @@
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.apache.log4j.Logger;
/**
* @author conradb
@@ -17,15 +18,58 @@
* @hibernate.query name="allAttachments" query="from Attachment attachment"
* @hibernate.query name="getAttachmentbyType" query="from Attachment attachment where file_type = ?"
*/
-public class Attachment {
+public class Attachment implements Cloneable{
+ private static final Logger log = Logger.getLogger(Attachment.class);
+
private Long uid;
private Long fileUuid;
private Long fileVersionId;
private String fileType;
private String fileName;
private Date created;
+
+ //Default contruction method
+ public Attachment(){
+
+ }
+// **********************************************************
+ // Function method for Attachment
+// **********************************************************
+ public Object clone(){
+ Object obj = null;
+ try {
+ obj = super.clone();
+ } catch (CloneNotSupportedException e) {
+ log.error("When clone " + Attachment.class + " failed");
+ }
+
+ return obj;
+ }
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (!(o instanceof Attachment))
+ return false;
+ final Attachment genericEntity = (Attachment) o;
+ return new EqualsBuilder()
+ .append(this.uid,genericEntity.uid)
+ .append(this.fileVersionId,genericEntity.fileVersionId)
+ .append(this.fileName,genericEntity.fileName)
+ .append(this.fileType,genericEntity.fileType)
+ .append(this.created,genericEntity.created)
+ .isEquals();
+ }
+
+ public int hashCode() {
+ return new HashCodeBuilder().append(uid).append(fileVersionId).append(fileName).append(fileType).append(created)
+ .toHashCode();
+ }
+
+// **********************************************************
+ // get/set methods
+// **********************************************************
/**
* @hibernate.id column="uid" generator-class="native"
*/
@@ -71,25 +115,7 @@
this.fileName = name;
}
- public boolean equals(Object o) {
- if (this == o)
- return true;
- if (!(o instanceof Attachment))
- return false;
- final Attachment genericEntity = (Attachment) o;
-
- return new EqualsBuilder()
- .append(this.uid,genericEntity.uid)
- .append(this.fileVersionId,genericEntity.fileVersionId)
- .append(this.fileName,genericEntity.fileName)
- .append(this.fileType,genericEntity.fileType)
- .isEquals();
- }
-
- public int hashCode() {
- return new HashCodeBuilder().append(uid).append(fileVersionId).append(fileName).append(fileType).toHashCode();
- }
/**
* @hibernate.property column="file_uuid"
* @return
Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/Forum.hbm.xml
===================================================================
RCS file: /usr/local/cvsroot/lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/Attic/Forum.hbm.xml,v
diff -u -r1.8 -r1.9
--- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/Forum.hbm.xml 1 Nov 2005 05:30:54 -0000 1.8
+++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/Forum.hbm.xml 14 Nov 2005 03:09:58 -0000 1.9
@@ -83,23 +83,23 @@
This method DOES NOT deep clone Forum
to avoid dead loop in clone.
+ */
+ public Object clone(){
+
+ Message msg = null;
+ try{
+ msg = (Message) super.clone();
+ if(parent != null){
+ msg.parent = (Message) parent.clone();
+ }
+ if(toolSession != null){
+ msg.toolSession = (ForumToolSession) toolSession.clone();
+ }
+ //don't deep clone forum to avoid dead loop in clone
+ if(createdBy != null){
+ msg.createdBy = (ForumUser) createdBy.clone();
+ }
+ if(modifiedBy != null)
+ msg.modifiedBy = (ForumUser) modifiedBy.clone();
+ //clone attachment
+ if(attachments != null){
+ Iterator iter = attachments.iterator();
+ Set set = new TreeSet();
+ while(iter.hasNext())
+ set.add(((Attachment)iter.next()).clone());
+ msg.attachments = set;
+ }
+ } catch (CloneNotSupportedException e) {
+ log.error("When clone " + Forum.class + " failed");
+ }
+
+ return msg;
+ }
+ /**
+ * Updates the modification data for this entity.
+ */
+ public void updateModificationData() {
+ long now = System.currentTimeMillis();
+ if (created == null) {
+ this.setCreated(new Date(now));
+ }
+ this.setUpdated(new Date(now));
+ }
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (!(o instanceof Message))
+ return false;
+
+ final Message genericEntity = (Message) o;
+
+ return new EqualsBuilder()
+ .append(this.uid,genericEntity.uid)
+ .append(this.subject,genericEntity.subject)
+ .append(this.body,genericEntity.body)
+ .append(this.created,genericEntity.created)
+ .append(this.updated,genericEntity.updated)
+ .append(this.createdBy,genericEntity.createdBy)
+ .append(this.modifiedBy,genericEntity.modifiedBy)
+ .isEquals();
+ }
+
+ public int hashCode() {
+ return new HashCodeBuilder().append(uid)
+ .append(subject).append(body)
+ .append(created)
+ .append(updated).append(createdBy)
+ .append(modifiedBy)
+ .toHashCode();
+ }
+
+// **********************************************************
+ // get/set methods
+// **********************************************************
+ /**
* Returns the object's creation date
*
* @return date
@@ -105,16 +192,6 @@
this.createdBy = createdBy;
}
- /**
- * Updates the modification data for this entity.
- */
- public void updateModificationData() {
- long now = System.currentTimeMillis();
- if (created == null) {
- this.setCreated(new Date(now));
- }
- this.setUpdated(new Date(now));
- }
/**
* @hibernate.many-to-one
@@ -276,33 +353,7 @@
public void setAttachments(Set attachments) {
this.attachments = attachments;
}
- public boolean equals(Object o) {
- if (this == o)
- return true;
- if (!(o instanceof Message))
- return false;
-
- final Message genericEntity = (Message) o;
-
- return new EqualsBuilder()
- .append(this.uid,genericEntity.uid)
- .append(this.subject,genericEntity.subject)
- .append(this.body,genericEntity.body)
- .append(this.created,genericEntity.created)
- .append(this.updated,genericEntity.updated)
- .append(this.createdBy,genericEntity.createdBy)
- .append(this.modifiedBy,genericEntity.modifiedBy)
- .isEquals();
- }
-
- public int hashCode() {
- return new HashCodeBuilder().append(uid)
- .append(subject).append(body)
- .append(created)
- .append(updated).append(createdBy)
- .append(modifiedBy)
- .toHashCode();
- }
+
/**
* @hibernate.many-to-one column="forum_uid"
* cascade="none"
Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/ForumService.java
===================================================================
RCS file: /usr/local/cvsroot/lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/ForumService.java,v
diff -u -r1.16 -r1.17
--- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/ForumService.java 14 Nov 2005 00:19:10 -0000 1.16
+++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/ForumService.java 14 Nov 2005 03:09:59 -0000 1.17
@@ -53,6 +53,7 @@
import org.lamsfoundation.lams.tool.forum.util.ForumConstants;
import org.lamsfoundation.lams.tool.forum.util.ForumToolContentHandler;
import org.lamsfoundation.lams.tool.forum.util.TopicComparator;
+import org.lamsfoundation.lams.tool.service.ILamsToolService;
import org.lamsfoundation.lams.usermanagement.User;
@@ -71,8 +72,8 @@
private MessageSeqDao messageSeqDao;
private ForumUserDao forumUserDao;
private ForumToolSessionDao forumToolSessionDao;
-
//system level handler and service
+ private ILamsToolService toolService;
private ForumToolContentHandler toolContentHandler;
private IRepositoryService repositoryService;
@@ -502,4 +503,43 @@
public void updateSession(ForumToolSession session) {
forumToolSessionDao.saveOrUpdate(session);
}
+ /* (non-Javadoc)
+ * @see org.lamsfoundation.lams.tool.sbmt.service.ISubmitFilesService#getToolDefaultContentIdBySignature(java.lang.Long)
+ */
+ public Long getToolDefaultContentIdBySignature(String toolSignature)
+ {
+ Long contentId = null;
+ contentId=new Long(toolService.getToolDefaultContentIdBySignature(toolSignature));
+ if (contentId == null)
+ {
+ String error="Could not retrieve default content id for this tool";
+ log.error(error);
+ throw new ForumException(error);
+ }
+ return contentId;
+ }
+ public Forum getDefaultForum(){
+ Long defaultForumId = getToolDefaultContentIdBySignature(ForumConstants.TOOLSIGNNATURE);
+ Forum defaultForum = getForum(defaultForumId);
+ if(defaultForum == null)
+ {
+ String error="Could not retrieve default content record for this tool";
+ log.error(error);
+ throw new ForumException(error);
+ }
+
+ //save default content by given ID.
+ Forum forum = new Forum();
+ forum = (Forum) defaultForum.clone();
+
+ return forum;
+
+ }
+ public ILamsToolService getToolService() {
+ return toolService;
+ }
+
+ public void setToolService(ILamsToolService toolService) {
+ this.toolService = toolService;
+ }
}
Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/IForumService.java
===================================================================
RCS file: /usr/local/cvsroot/lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/IForumService.java,v
diff -u -r1.13 -r1.14
--- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/IForumService.java 14 Nov 2005 00:19:10 -0000 1.13
+++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/IForumService.java 14 Nov 2005 03:09:59 -0000 1.14
@@ -5,9 +5,9 @@
import org.apache.struts.upload.FormFile;
import org.lamsfoundation.lams.tool.forum.persistence.Attachment;
import org.lamsfoundation.lams.tool.forum.persistence.Forum;
+import org.lamsfoundation.lams.tool.forum.persistence.ForumToolSession;
import org.lamsfoundation.lams.tool.forum.persistence.ForumUser;
import org.lamsfoundation.lams.tool.forum.persistence.Message;
-import org.lamsfoundation.lams.tool.forum.persistence.ForumToolSession;
import org.lamsfoundation.lams.tool.forum.persistence.PersistenceException;
/**
@@ -80,4 +80,14 @@
*/
public Long getRootTopicId(Long topicId);
public void updateSession(ForumToolSession session);
+
+ /**
+ * Get default content ID by tool signature.
+ * @param toolSignature
+ * @return
+ */
+ public Long getToolDefaultContentIdBySignature(String toolSignature);
+
+ public Forum getDefaultForum();
+
}
Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/util/ForumConstants.java
===================================================================
RCS file: /usr/local/cvsroot/lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/util/ForumConstants.java,v
diff -u -r1.13 -r1.14
--- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/util/ForumConstants.java 11 Nov 2005 02:48:23 -0000 1.13
+++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/util/ForumConstants.java 14 Nov 2005 03:09:59 -0000 1.14
@@ -1,13 +1,13 @@
package org.lamsfoundation.lams.tool.forum.util;
/**
- * Created by IntelliJ IDEA.
* User: conradb
* Date: 14/06/2005
* Time: 10:33:00
- * To change this template use File | Settings | File Templates.
*/
public interface ForumConstants {
+ public static final String TOOLSIGNNATURE = "lafrm11";
+
public final static int MAX_FILE_SIZE = 250 * 1000;
public final static String FORUM_SERVICE = "forumService";
Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/AuthoringAction.java
===================================================================
RCS file: /usr/local/cvsroot/lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/AuthoringAction.java,v
diff -u -r1.19 -r1.20
--- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/AuthoringAction.java 14 Nov 2005 00:19:11 -0000 1.19
+++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/AuthoringAction.java 14 Nov 2005 03:09:59 -0000 1.20
@@ -119,7 +119,9 @@
}
return mapping.findForward("error");
}
-
+ //******************************************************************************************************************
+ // Forum Author functions
+ //******************************************************************************************************************
/**
* This page will display initial submit tool content. Or just a blank page if the toolContentID does not
* exist before.
@@ -142,8 +144,13 @@
Forum forum = null;
try {
forum = forumService.getForumByContentId(contentId);
+ //if forum does not exist, try to use default content instead.
+ if(forum == null){
+ forum = forumService.getDefaultForum();
+ }
topics = forumService.getAuthoredTopics(contentId);
- forumForm.setForum(forum);
+ //tear down PO to normal object using clone() method
+ forumForm.setForum((Forum) forum.clone());
forumForm.setToolContentID(contentId);
} catch (Exception e) {
log.error(e);
@@ -155,7 +162,238 @@
request.getSession().setAttribute(ForumConstants.AUTHORING_TOPICS_LIST, topics);
return mapping.findForward("success");
}
+ /**
+ * Update all content for submit tool except online/offline instruction
+ * files list.
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
+ public ActionForward updateContent(ActionMapping mapping, ActionForm form,
+ HttpServletRequest request, HttpServletResponse response) {
+ ForumForm forumForm = (ForumForm)(form);
+ Forum forum = forumForm.getForum();
+ try {
+ forumService = getForumManager();
+ 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);
+// }
+ }
+ PropertyUtils.copyProperties(forumPO,forum);
+ //copy back
+ forumPO.setAttachments(attSet);
+ forumPO.setMessages(msgSet);
+ }else{
+ forumPO = forum;
+ forumPO.setContentId(forumForm.getToolContentID());
+ }
+ forumService.editForum(forumPO);
+ } catch (Exception e) {
+ log.error(e);
+ }
+ return mapping.findForward("success");
+ }
+
+ /**
+ * Handle upload online instruction files request.
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
+ public ActionForward uploadOnline(ActionMapping mapping, ActionForm form,
+ HttpServletRequest request, HttpServletResponse response) {
+ return uploadFile(mapping, form, IToolContentHandler.TYPE_ONLINE,request);
+ }
+ /**
+ * Handle upload offline instruction files request.
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
+ public ActionForward uploadOffline(ActionMapping mapping, ActionForm form,
+ HttpServletRequest request, HttpServletResponse response) {
+ return uploadFile(mapping, form, IToolContentHandler.TYPE_OFFLINE,request);
+ }
+ /**
+ * Common method to upload online or offline instruction files request.
+ * @param mapping
+ * @param form
+ * @param type
+ * @param request
+ * @return
+ */
+ private ActionForward uploadFile(ActionMapping mapping, ActionForm form,
+ String type,HttpServletRequest request) {
+
+ ForumForm forumForm = (ForumForm) form;
+
+ FormFile file;
+ if(StringUtils.equals(IToolContentHandler.TYPE_OFFLINE,type))
+ file = (FormFile) forumForm.getOfflineFile();
+ else
+ file = (FormFile) forumForm.getOnlineFile();
+
+ Forum content = getContent(form);
+ forumService = getForumManager();
+ Attachment att = forumService.uploadInstructionFile(content.getContentId(), file, type);
+ //update session
+ List list;
+ if(StringUtils.equals(IToolContentHandler.TYPE_OFFLINE,type)){
+ list = forumForm.getOfflineFileList();
+ if(list == null){
+ list = new ArrayList();
+ forumForm.setOfflineFileList(list);
+ }
+ }else{
+ list = forumForm.getOnlineFileList();
+ if(list == null){
+ list = new ArrayList();
+ forumForm.setOnlineFileList(list);
+ }
+ }
+ list.add(att);
+
+ return mapping.findForward("success");
+
+ }
+ /**
+ * Delete offline instruction file from current Forum authoring page.
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
+ public ActionForward deleteOfflineFile(ActionMapping mapping, ActionForm form,
+ HttpServletRequest request, HttpServletResponse response) {
+ return deleteFile(request, response,form, IToolContentHandler.TYPE_OFFLINE);
+ }
+ /**
+ * Delete online instruction file from current Forum authoring page.
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
+ public ActionForward deleteOnlineFile(ActionMapping mapping, ActionForm form,
+ HttpServletRequest request, HttpServletResponse response) {
+ return deleteFile(request, response,form, IToolContentHandler.TYPE_ONLINE);
+ }
+
+ /**
+ * @param request
+ * @param response
+ * @param form
+ * @param type
+ * @return
+ */
+ private ActionForward deleteFile(HttpServletRequest request, HttpServletResponse response, ActionForm form, String type) {
+ Long contentID = new Long(WebUtil.readLongParam(request,AttributeNames.PARAM_TOOL_CONTENT_ID));
+ 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;
+ if(StringUtils.equals(IToolContentHandler.TYPE_OFFLINE,type)){
+ attachmentList = ((ForumForm)form).getOfflineFileList();
+ }else{
+ attachmentList = ((ForumForm)form).getOnlineFileList();
+ }
+ Iterator iter = attachmentList.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();
+ while(iter.hasNext()){
+ Attachment file = (Attachment) iter.next();
+ sb.append("").append(file.getFileName()).append("\r\n");
+ sb.append(" ");
+ sb.append(this.getResources(request).getMessage("label.view"));
+ sb.append("\r\n");
+ sb.append(" ");
+ sb.append(this.getResources(request).getMessage("label.download"));
+ sb.append("\r\n");
+ sb.append("");
+
+ if(StringUtils.equals(type,IToolContentHandler.TYPE_OFFLINE))
+ sb.append(this.getResources(request).getMessage("label.authoring.offline.delete"));
+ else
+ sb.append(this.getResources(request).getMessage("label.authoring.online.delete"));
+ sb.append("\r\n");
+ }
+ try {
+ PrintWriter out = response.getWriter();
+ out.print(sb.toString());
+ out.flush();
+ } catch (IOException e) {
+ log.error(e);
+ }
+ return null;
+ }
+
+ //******************************************************************************************************************
+ // Topic functions
+ //******************************************************************************************************************
+ /**
+ * Display emtpy topic page for user input topic information. This page will contain all topics list which
+ * this author posted before.
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
private ActionForward newTopic(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
List topics = (List) request.getSession().getAttribute(ForumConstants.AUTHORING_TOPICS_LIST);
@@ -165,6 +403,18 @@
request.getSession().setAttribute(ForumConstants.AUTHORING_TOPICS_LIST, topics);
return mapping.findForward("success");
}
+ /**
+ * Create a topic in memory. This topic will be saved when user save entire authoring page.
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ * @throws IOException
+ * @throws ServletException
+ * @throws PersistenceException
+ */
public ActionForward createTopic(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException, PersistenceException {
@@ -214,7 +464,16 @@
request.getSession().setAttribute(ForumConstants.AUTHORING_TOPICS_LIST, topics);
return mapping.findForward("success");
}
-
+ /**
+ * Delete a topic form current topic list. But database record will be deleted only when user save whole authoring
+ * page.
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ * @throws PersistenceException
+ */
public ActionForward deleteTopic(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws PersistenceException {
@@ -233,6 +492,17 @@
request.setAttribute(ForumConstants.SUCCESS_FLAG,"DELETE_SUCCESS");
return mapping.getInputForward();
}
+ /**
+ * Diplay a special topic information. Only display author created root message content, even this topic already
+ * has some reply messages from learner in some cases.
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ * @throws PersistenceException
+ */
public ActionForward viewTopic(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws PersistenceException {
@@ -252,6 +522,17 @@
return mapping.findForward("success");
}
+ /**
+ * Display a HTML FORM which contains subject, body and attachment information from a special topic. This page
+ * is ready for user update this topic.
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ * @throws PersistenceException
+ */
public ActionForward editTopic(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws PersistenceException {
MessageForm msgForm = (MessageForm)form;
@@ -269,6 +550,17 @@
return mapping.findForward("success");
}
+ /**
+ * Submit user updated inforamion in a topic to memory. This update will be submit to database only when user
+ * save whole authoring page.
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ * @throws PersistenceException
+ */
public ActionForward updateTopic(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws PersistenceException {
//get value from HttpSession
@@ -307,7 +599,16 @@
request.setAttribute(ForumConstants.SUCCESS_FLAG,"EDIT_SUCCESS");
return mapping.findForward("success");
}
-
+ /**
+ * Delete a topic's attachment file. This update will be submit to database only when user
+ * save whole authoring page.
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ * @throws PersistenceException
+ */
public ActionForward deleteAttachment(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws PersistenceException {
Long versionID = new Long(WebUtil.readLongParam(request,"versionID"));
@@ -358,215 +659,12 @@
return mapping.findForward("success");
}
- /**
- * Update all content for submit tool except online/offline instruction
- * files list.
- *
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- */
- public ActionForward updateContent(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- ForumForm forumForm = (ForumForm)(form);
- Forum forum = forumForm.getForum();
- try {
- forumService = getForumManager();
- 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);
-// }
- }
- PropertyUtils.copyProperties(forumPO,forum);
- //copy back
- forumPO.setAttachments(attSet);
- forumPO.setMessages(msgSet);
- }else{
- forumPO = forum;
- forumPO.setContentId(forumForm.getToolContentID());
- }
- forumService.editForum(forumPO);
- } catch (Exception e) {
- log.error(e);
- }
- return mapping.findForward("success");
- }
- /**
- * Handle upload online instruction files request. Once the file uploaded successfully, database
- * will update accordingly.
- *
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- */
- public ActionForward uploadOnline(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- return uploadFile(mapping, form, IToolContentHandler.TYPE_ONLINE,request);
- }
- /**
- * Handle upload offline instruction files request. Once the file uploaded successfully, database
- * will update accordingly.
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- */
- public ActionForward uploadOffline(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- return uploadFile(mapping, form, IToolContentHandler.TYPE_OFFLINE,request);
- }
- /**
- * Common method to upload online or offline instruction files request.
- * @param mapping
- * @param form
- * @param type
- * @param request
- * @return
- */
- private ActionForward uploadFile(ActionMapping mapping, ActionForm form,
- String type,HttpServletRequest request) {
-
- ForumForm forumForm = (ForumForm) form;
-
- FormFile file;
- if(StringUtils.equals(IToolContentHandler.TYPE_OFFLINE,type))
- file = (FormFile) forumForm.getOfflineFile();
- else
- file = (FormFile) forumForm.getOnlineFile();
-
- Forum content = getContent(form);
- forumService = getForumManager();
- Attachment att = forumService.uploadInstructionFile(content.getContentId(), file, type);
- //update session
- List list;
- if(StringUtils.equals(IToolContentHandler.TYPE_OFFLINE,type)){
- list = forumForm.getOfflineFileList();
- if(list == null){
- list = new ArrayList();
- forumForm.setOfflineFileList(list);
- }
- }else{
- list = forumForm.getOnlineFileList();
- if(list == null){
- list = new ArrayList();
- forumForm.setOnlineFileList(list);
- }
- }
- list.add(att);
-
- return mapping.findForward("success");
-
- }
-
- public ActionForward deleteOfflineFile(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- return deleteFile(request, response,form, IToolContentHandler.TYPE_OFFLINE);
- }
- public ActionForward deleteOnlineFile(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- return deleteFile(request, response,form, IToolContentHandler.TYPE_ONLINE);
- }
-
- /**
- * @param request
- * @param response
- * @param form
- * @param type
- * @return
- */
- private ActionForward deleteFile(HttpServletRequest request, HttpServletResponse response, ActionForm form, String type) {
- Long contentID = new Long(WebUtil.readLongParam(request,AttributeNames.PARAM_TOOL_CONTENT_ID));
- 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;
- if(StringUtils.equals(IToolContentHandler.TYPE_OFFLINE,type)){
- attachmentList = ((ForumForm)form).getOfflineFileList();
- }else{
- attachmentList = ((ForumForm)form).getOnlineFileList();
- }
- Iterator iter = attachmentList.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();
- while(iter.hasNext()){
- Attachment file = (Attachment) iter.next();
- sb.append("").append(file.getFileName()).append("\r\n");
- sb.append(" ");
- sb.append(this.getResources(request).getMessage("label.view"));
- sb.append("\r\n");
- sb.append(" ");
- sb.append(this.getResources(request).getMessage("label.download"));
- sb.append("\r\n");
- sb.append("");
-
- if(StringUtils.equals(type,IToolContentHandler.TYPE_OFFLINE))
- sb.append(this.getResources(request).getMessage("label.authoring.offline.delete"));
- else
- sb.append(this.getResources(request).getMessage("label.authoring.online.delete"));
- sb.append("\r\n");
- }
- try {
- PrintWriter out = response.getWriter();
- out.print(sb.toString());
- out.flush();
- } catch (IOException e) {
- log.error(e);
- }
- return null;
- }
-
- /**
+ //******************************************************************************************************************
+ // Private method for internal functions
+ //******************************************************************************************************************
+ /*
* The private method to get content from ActionForm parameters (web page).
- *
* @param form
* @return
*/
Index: lams_tool_forum/web/WEB-INF/web.xml
===================================================================
RCS file: /usr/local/cvsroot/lams_tool_forum/web/WEB-INF/Attic/web.xml,v
diff -u -r1.12 -r1.13
--- lams_tool_forum/web/WEB-INF/web.xml 31 Oct 2005 23:49:36 -0000 1.12
+++ lams_tool_forum/web/WEB-INF/web.xml 14 Nov 2005 03:09:59 -0000 1.13
@@ -16,6 +16,7 @@
classpath:/org/lamsfoundation/lams/applicationContext.xml
classpath:/org/lamsfoundation/lams/contentrepository/applicationContext.xml
+ classpath:/org/lamsfoundation/lams/tool/toolApplicationContext.xml
classpath:/forumApplicationContext.xml