Index: lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/NoticeboardAttachment.java =================================================================== diff -u -rd789031b1ec349fa6315006cff40f1abc607b932 -r89ae2d0b15d307b9dd4c20da0577481807524ce2 --- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/NoticeboardAttachment.java (.../NoticeboardAttachment.java) (revision d789031b1ec349fa6315006cff40f1abc607b932) +++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/NoticeboardAttachment.java (.../NoticeboardAttachment.java) (revision 89ae2d0b15d307b9dd4c20da0577481807524ce2) @@ -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 =================================================================== diff -u -rc37fcfa0e8e9c09a5ada45fba5af63e43b2bbef1 -r89ae2d0b15d307b9dd4c20da0577481807524ce2 --- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/NoticeboardContent.java (.../NoticeboardContent.java) (revision c37fcfa0e8e9c09a5ada45fba5af63e43b2bbef1) +++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/NoticeboardContent.java (.../NoticeboardContent.java) (revision 89ae2d0b15d307b9dd4c20da0577481807524ce2) @@ -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 =================================================================== diff -u -r74804514d697b22ea2afdb8d1daf1c3b7797e793 -r89ae2d0b15d307b9dd4c20da0577481807524ce2 --- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/util/NbWebUtil.java (.../NbWebUtil.java) (revision 74804514d697b22ea2afdb8d1daf1c3b7797e793) +++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/util/NbWebUtil.java (.../NbWebUtil.java) (revision 89ae2d0b15d307b9dd4c20da0577481807524ce2) @@ -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