Index: lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/NoticeboardAttachment.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/Attic/NoticeboardAttachment.java,v diff -u -r1.8 -r1.9 --- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/NoticeboardAttachment.java 16 Nov 2005 00:37:50 -0000 1.8 +++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/NoticeboardAttachment.java 21 Nov 2005 04:52:42 -0000 1.9 @@ -28,6 +28,7 @@ import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.log4j.Logger; /** @@ -40,9 +41,10 @@ * * @author mtruong */ -public class NoticeboardAttachment implements Serializable { +public class NoticeboardAttachment implements Serializable, Cloneable { private static final long serialVersionUID = -3471513404550541296L; + private static Logger log = Logger.getLogger(NoticeboardAttachment.class); /** identifier field */ private Long attachmentId; @@ -93,8 +95,16 @@ this.onlineFile = isOnline; } - - + /** Clone this attachment, including the unique id */ + public Object clone(){ + Object obj = null; + try { + obj = super.clone(); + } catch (CloneNotSupportedException e) { + log.error("Clone " + NoticeboardAttachment.class + " not supported"); + } + return obj; + } /** * @return Returns the attachmentId. */ Index: lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/NoticeboardContent.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/NoticeboardContent.java,v diff -u -r1.8 -r1.9 --- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/NoticeboardContent.java 10 Aug 2005 06:49:31 -0000 1.8 +++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/NoticeboardContent.java 21 Nov 2005 04:52:42 -0000 1.9 @@ -22,6 +22,7 @@ import java.io.Serializable; import java.util.Date; +import java.util.Iterator; import java.util.Set; import java.util.HashSet; @@ -352,6 +353,10 @@ /** + * Creates a new NoticeboardContent object from the supplied object. + * Assigns it the toContendId. Also copies all the items in the attachment set + * to the new object's attachment set. So while the two contents have different + * attachment records, they point to the same entries in the database. * * @param nb NoticeboardContent object containing the content to copy from * @param toContentId The new Id of the new noticeboard object @@ -370,6 +375,20 @@ nb.getCreatorUserId(), nb.getDateCreated(), nb.getDateUpdated()); + + if ( nb.getNbAttachments() != null && nb.getNbAttachments().size() > 0 ) { + HashSet newAttachmentSet = new HashSet(); + Iterator iter = nb.getNbAttachments().iterator(); + while (iter.hasNext()) { + NoticeboardAttachment element = (NoticeboardAttachment) iter.next(); + NoticeboardAttachment newAttachment = (NoticeboardAttachment) element.clone(); + newAttachment.setAttachmentId(null); + newAttachment.setNbContent(newContent); + newAttachmentSet.add(newAttachment); + } + newContent.setNbAttachments(newAttachmentSet); + } + return newContent; } Index: lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/util/NbWebUtil.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/util/NbWebUtil.java,v diff -u -r1.7 -r1.8 --- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/util/NbWebUtil.java 17 Nov 2005 23:14:13 -0000 1.7 +++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/util/NbWebUtil.java 21 Nov 2005 04:52:42 -0000 1.8 @@ -160,25 +160,22 @@ * If NoticeboardContent content does not exist, set nb=null and an empty list will be created. * * @param nbService - * @param attachmentMap * @param nb - * @return the updated attachmentMap + * @return the attachmentList */ - public static List setupAttachmentList(INoticeboardService nbService, List attachmentList, NoticeboardContent nb) { + public static List setupAttachmentList(INoticeboardService nbService, NoticeboardContent nb) { - List updatedList = attachmentList != null ? attachmentList : new ArrayList(); + List attachmentList = new ArrayList(); if ( nbService!=null && nb!=null ) { List attachmentIdList = nbService.getAttachmentIdsFromContent(nb); for (int i=0; i