Index: lams_tool_nb/conf/language/ApplicationResources.properties =================================================================== RCS file: /usr/local/cvsroot/lams_tool_nb/conf/language/Attic/ApplicationResources.properties,v diff -u -r1.11 -r1.12 --- lams_tool_nb/conf/language/ApplicationResources.properties 14 Jul 2006 04:56:51 -0000 1.11 +++ lams_tool_nb/conf/language/ApplicationResources.properties 19 Jul 2006 05:15:49 -0000 1.12 @@ -41,8 +41,8 @@ titleHeading.editActivity =Edit Activity titleHeading.exportPortfolio =Export Portfolio heading.group =Group {0}: -heading.totalLearners =Number of Learners: -heading.totalLearnersInGroup =Total Number of Learners in Group: +heading.totalLearners =Total Number of Learners: +heading.totalLearnersInGroup =Number of Learners in Group: message.contentInUseSet =The modification of content is not allowed since one or more students has attempted the activity. message.summary =There is no summary available for this tool. button.cancel =Cancel Index: lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/NoticeboardConstants.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/NoticeboardConstants.java,v diff -u -r1.21 -r1.22 --- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/NoticeboardConstants.java 6 Apr 2006 07:05:07 -0000 1.21 +++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/NoticeboardConstants.java 19 Jul 2006 05:15:49 -0000 1.22 @@ -84,12 +84,9 @@ public static final String DEFINE_LATER = "defineLater"; public static final String PAGE_EDITABLE = "isPageEditable"; - public static final String TOTAL_LEARNERS = "totalLearners"; - public static final String GROUP_STATS_MAP = "groupStatsMap"; public static final String EXPORT_PORTFOLIO = "exportPortfolio"; //used in authoring - public static final String MODE = "mode"; public static final String TOOL_CONTENT_ID = "toolContentID"; //request + session variable public static final String RICH_TEXT_TITLE = "richTextTitle"; public static final String RICH_TEXT_CONTENT = "richTextContent"; 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.10 -r1.11 --- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/util/NbWebUtil.java 6 Apr 2006 07:05:07 -0000 1.10 +++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/util/NbWebUtil.java 19 Jul 2006 05:15:49 -0000 1.11 @@ -25,6 +25,7 @@ package org.lamsfoundation.lams.tool.noticeboard.util; import java.util.ArrayList; +import java.util.LinkedList; import java.util.List; import javax.servlet.http.HttpServletRequest; @@ -34,6 +35,7 @@ import org.lamsfoundation.lams.tool.noticeboard.NoticeboardConstants; import org.lamsfoundation.lams.tool.noticeboard.NoticeboardContent; import org.lamsfoundation.lams.tool.noticeboard.service.INoticeboardService; +import org.lamsfoundation.lams.web.util.SessionMap; /** * This Web Utility class contains helper methods used in the Action Servlets @@ -58,34 +60,6 @@ } - public static void cleanAuthoringSession(HttpServletRequest request) - { - request.getSession().removeAttribute(NoticeboardConstants.TOOL_CONTENT_ID); - request.getSession().removeAttribute(NoticeboardConstants.MODE); - request.getSession().removeAttribute(NoticeboardConstants.ATTACHMENT_LIST); - request.getSession().removeAttribute(NoticeboardConstants.DELETED_ATTACHMENT_LIST); - } - - public static void cleanLearnerSession(HttpServletRequest request) - { - request.getSession().removeAttribute(NoticeboardConstants.READ_ONLY_MODE); - // request.getSession().removeAttribute(NoticeboardConstants.IS_TOOL_COMPLETED); - } - - public static void cleanMonitoringSession(HttpServletRequest request) - { - //request.getSession().removeAttribute(NoticeboardConstants.TOOL_CONTENT_ID_INMONITORMODE); - request.getSession().removeAttribute(NoticeboardConstants.TITLE); - request.getSession().removeAttribute(NoticeboardConstants.CONTENT); - request.getSession().removeAttribute(NoticeboardConstants.OFFLINE_INSTRUCTIONS); - request.getSession().removeAttribute(NoticeboardConstants.ONLINE_INSTRUCTIONS); - request.getSession().removeAttribute(NoticeboardConstants.ATTACHMENT_LIST); - // deleted attachments probably isn't used in monitoring, but included - // here to keep it consistent with authoring. - request.getSession().removeAttribute(NoticeboardConstants.DELETED_ATTACHMENT_LIST); - - } - /** *
This method checks the two tool content flags, defineLater and contentInUse * to determine whether the tool content is modifiable or not. Returns true if the content is @@ -113,23 +87,8 @@ else // (content.isContentInUse()==true && content.isDefineLater() == false) return false; } - - /** - * Used in the monitoring environment. - * Copies the values of the pojo/bean properties title, content, onlineInstructions and offlineInstructions - * into the session scope variables title, content, onlineInstructions and offlineInstructions respectively. - * @param request the HttpServletRequest which is used to obtain the HttpSession, in which is used to store the session variables for the 4 properties. - * @param content the bean in which to copy the 4 properties from - */ - public static void copyValuesIntoSession(HttpServletRequest request, NoticeboardContent content) - { - request.getSession().setAttribute(NoticeboardConstants.TITLE, content.getTitle()); - request.getSession().setAttribute(NoticeboardConstants.CONTENT, content.getContent()); - request.getSession().setAttribute(NoticeboardConstants.ONLINE_INSTRUCTIONS, content.getOnlineInstructions()); - request.getSession().setAttribute(NoticeboardConstants.OFFLINE_INSTRUCTIONS, content.getOfflineInstructions()); - } - - /** + + /** *
This method is used in authoring and monitoring to display the list of files that have been uploaded. * Contents of the collections are NoticeboardAttachments. The current files are included in the attachmentList, * files that the user has nominated to delete are in the deletedAttachementList.
@@ -141,20 +100,15 @@ * @param attachmentList * @param deletedAttachmentList */ - public static void addUploadsToSession(HttpServletRequest request, List attachmentList, List deletedAttachmentList) + public static SessionMap addUploadsToSession(SessionMap sessionMap, HttpServletRequest request, List attachmentList, List deletedAttachmentList) { - if ( attachmentList != null ) { - request.getSession().setAttribute(NoticeboardConstants.ATTACHMENT_LIST, attachmentList); - } - - // deleted will be empty most of the time - if ( deletedAttachmentList != null ) { - request.getSession().setAttribute(NoticeboardConstants.DELETED_ATTACHMENT_LIST, deletedAttachmentList); - } - + SessionMap map = sessionMap != null ? sessionMap : new SessionMap(); + map.put(NoticeboardConstants.ATTACHMENT_LIST, attachmentList != null ? attachmentList : new ArrayList()); + map.put(NoticeboardConstants.DELETED_ATTACHMENT_LIST, deletedAttachmentList != null ? deletedAttachmentList : new ArrayList()); + request.getSession().setAttribute(map.getSessionID(), map); + return map; } - /** Setup the map containing the files that have been uploaded for this particular tool content id. * If NoticeboardContent content does not exist, set nb=null and an empty list will be created. * Index: lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/ClearSessionAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/ClearSessionAction.java,v diff -u -r1.2 -r1.3 --- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/ClearSessionAction.java 11 Jul 2006 00:58:12 -0000 1.2 +++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/ClearSessionAction.java 19 Jul 2006 05:15:48 -0000 1.3 @@ -28,7 +28,6 @@ import org.lamsfoundation.lams.authoring.web.LamsAuthoringFinishAction; import org.lamsfoundation.lams.tool.ToolAccessMode; -import org.lamsfoundation.lams.tool.noticeboard.NoticeboardConstants; /** * This class give a chance to clear HttpSession when user save/close authoring page. @@ -44,11 +43,7 @@ @Override public void clearSession(String customiseSessionID,HttpSession session, ToolAccessMode mode) { if(mode.isAuthor()){ - session.removeAttribute(NoticeboardConstants.TOOL_CONTENT_ID); - session.removeAttribute(NoticeboardConstants.ATTACHMENT_LIST); - session.removeAttribute(NoticeboardConstants.DELETED_ATTACHMENT_LIST); - session.removeAttribute(NoticeboardConstants.MODE); - session.removeAttribute(NbAuthoringAction.FORM); + session.removeAttribute(customiseSessionID); } } Index: lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbAuthoringAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbAuthoringAction.java,v diff -u -r1.25 -r1.26 --- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbAuthoringAction.java 15 May 2006 06:57:14 -0000 1.25 +++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbAuthoringAction.java 19 Jul 2006 05:15:48 -0000 1.26 @@ -60,6 +60,7 @@ import org.lamsfoundation.lams.web.action.LamsLookupDispatchAction; import org.lamsfoundation.lams.web.session.SessionManager; import org.lamsfoundation.lams.web.util.AttributeNames; +import org.lamsfoundation.lams.web.util.SessionMap; /** * @author mtruong @@ -77,7 +78,7 @@ * * ----------------XDoclet Tags-------------------- * - * @struts:action path="/authoring" name="NbAuthoringForm" scope="session" + * @struts:action path="/authoring" name="NbAuthoringForm" scope="request" * type="org.lamsfoundation.lams.tool.noticeboard.web.NbAuthoringAction" * parameter="method" validate="true" input="/author_page.jsp" * @@ -100,11 +101,6 @@ static Logger logger = Logger.getLogger(NbAuthoringAction.class.getName()); public final static String FORM="NbAuthoringForm"; - public static final String AUTHOR_MODE = "authorMode"; - public static final String DEFINE_LATER_MODE = "defineLaterMode"; - public static final String SHOW_BASIC_TAB = "showBasicContent"; - - /** Get the user from the shared session */ public UserDTO getUser(HttpServletRequest request) { // set up the user details @@ -130,46 +126,26 @@ return map; } + public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws NbApplicationException { - MessageResources resources = getResources(request); - //to ensure that we are working with a new form, not one from previous session NbAuthoringForm nbForm = new NbAuthoringForm(); - NbWebUtil.cleanAuthoringSession(request); - Long contentId = NbWebUtil.convertToLong(request.getParameter(NoticeboardConstants.TOOL_CONTENT_ID)); - - if(contentId == null) - { - //String error = "Tool content id missing. Unable to continue."; - String error = resources.getMessage(NoticeboardConstants.ERR_MISSING_PARAM, "Tool Content Id"); - logger.error(error); - throw new NbApplicationException(error); - } + Long contentId = WebUtil.readLongParam(request, NoticeboardConstants.TOOL_CONTENT_ID); nbForm.setToolContentID(contentId.toString()); - /* if there is a defineLater request parameter, set the form value - * If a defineLater request parameter is not present, then it is just set to null. - * This is used in the basic screen, if defineLater is set, then in the authoring page, + /* DefineLater is used in the basic screen. If defineLater is set, then in the authoring page, * the two tabs {Advanced, Instructions} are not visible. - * - * If defineLater is set to true, then mode is set to Monitor. The request scope parameter - * showBasicContent is set to true so that the authoring page will only show the basic tab. - * - * If defineLater is not set, then mode is set to Author */ - nbForm.setDefineLater((String)request.getParameter(NoticeboardConstants.DEFINE_LATER)); - setModeOfUse(request, nbForm.getDefineLater()); - - request.getSession().setAttribute(NoticeboardConstants.TOOL_CONTENT_ID, contentId); + nbForm.setDefineLater(request.getParameter(NoticeboardConstants.DEFINE_LATER)); /* * Retrieve the Service */ INoticeboardService nbService = NoticeboardServiceProxy.getNbService(getServlet().getServletContext()); - List attachmentList = (List) request.getSession().getAttribute(NoticeboardConstants.ATTACHMENT_LIST); + List attachmentList = null; if (!contentExists(nbService, contentId)) { // Pre-fill the form with the default content @@ -209,7 +185,7 @@ /* Define later set to true when the edit activity tab is brought up * So that users cannot start using the content while the staff member is editing the content */ nbForm.populateFormWithNbContentValues(nb); - nb = setTrueIfDefineLaterIsSet(nbForm, nb); + nb.setDefineLater(Boolean.parseBoolean(nbForm.getDefineLater())); nbService.saveNoticeboard(nb); /** TODO: setup values in the instructions map */ @@ -230,365 +206,344 @@ attachmentList = NbWebUtil.setupAttachmentList(nbService,nb); } - NbWebUtil.addUploadsToSession(request, attachmentList, NbWebUtil.setupDeletedAttachmentList()); - request.getSession().setAttribute(FORM, nbForm); - - return mapping.findForward(NoticeboardConstants.AUTHOR_PAGE); + + SessionMap map = NbWebUtil.addUploadsToSession(null, request, attachmentList, NbWebUtil.setupDeletedAttachmentList()); + nbForm.setSessionMapID(map.getSessionID()); + + request.setAttribute(FORM, nbForm); + return mapping.findForward(NoticeboardConstants.AUTHOR_PAGE); } - - /** - * Checks the session to see if the title and content session variables exist or not. - * - * @param session The HttpSession to check. - * @return true if the parameters title and content exists in the session, false otherwise - */ - private boolean contentExists(INoticeboardService service, Long id) - { - NoticeboardContent nb = service.retrieveNoticeboard(id); - if (nb == null) - return false; - else - return true; - - } - - private NoticeboardContent setTrueIfDefineLaterIsSet(NbAuthoringForm form, NoticeboardContent content) - { - if(form.getDefineLater() != null) - { - if (form.getDefineLater().equals("true")) - { - //if the defineLater flag is set to true, then set defineLater in the NoticeboardContent object to true too - content.setDefineLater(true); - } - } - return content; - } - - public ActionForward save(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws NbApplicationException { - - NbAuthoringForm nbForm = (NbAuthoringForm)form; - //copyAuthoringFormValuesIntoFormBean(request, nbForm); - - INoticeboardService nbService = NoticeboardServiceProxy.getNbService(getServlet().getServletContext()); - String idAsString = nbForm.getToolContentID(); - if (idAsString == null) - { - MessageResources resources = getResources(request); - String error = resources.getMessage(NoticeboardConstants.ERR_MISSING_PARAM, "Tool Content Id"); - logger.error(error); - throw new NbApplicationException(error); - } - Long content_id = NbWebUtil.convertToLong(nbForm.getToolContentID()); - - //throws exception if the content id does not exist - checkContentId(content_id); - - NoticeboardContent nbContent = nbService.retrieveNoticeboard(content_id); - if ( nbContent == null ) { - //create a new noticeboard object - nbContent = new NoticeboardContent(); - nbContent.setNbContentId(content_id); - } - - nbForm.copyValuesIntoNbContent(nbContent); - if ( nbContent.getDateCreated() == null ) - nbContent.setDateCreated(nbContent.getDateUpdated()); - UserDTO user = getUser(request); - nbContent.setCreatorUserId(new Long(user.getUserID().longValue())); - - // Author has finished editing the content and mark the defineLater flag to false - nbContent.setDefineLater(false); - nbService.saveNoticeboard(nbContent); - - // Save the attachments then update the attachment collections in the session. - List attachmentList = (List) request.getSession().getAttribute(NoticeboardConstants.ATTACHMENT_LIST); - List deletedAttachmentList = (List) request.getSession().getAttribute(NoticeboardConstants.DELETED_ATTACHMENT_LIST); - deletedAttachmentList = saveAttachments(nbService, nbContent, attachmentList, deletedAttachmentList, mapping, request); - NbWebUtil.addUploadsToSession(request, attachmentList, deletedAttachmentList); + /** + * Checks the session to see if the title and content session variables exist or not. + * + * @param session The HttpSession to check. + * @return true if the parameters title and content exists in the session, false otherwise + */ + private boolean contentExists(INoticeboardService service, Long id) + { + NoticeboardContent nb = service.retrieveNoticeboard(id); + if (nb == null) + return false; + else + return true; + + } + + public ActionForward save(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws NbApplicationException { + + NbAuthoringForm nbForm = (NbAuthoringForm)form; + //copyAuthoringFormValuesIntoFormBean(request, nbForm); + + INoticeboardService nbService = NoticeboardServiceProxy.getNbService(getServlet().getServletContext()); + String idAsString = nbForm.getToolContentID(); + if (idAsString == null) + { + MessageResources resources = getResources(request); + String error = resources.getMessage(NoticeboardConstants.ERR_MISSING_PARAM, "Tool Content Id"); + logger.error(error); + throw new NbApplicationException(error); + } + Long content_id = NbWebUtil.convertToLong(nbForm.getToolContentID()); + + //throws exception if the content id does not exist + checkContentId(content_id); + + NoticeboardContent nbContent = nbService.retrieveNoticeboard(content_id); + if ( nbContent == null ) { + //create a new noticeboard object + nbContent = new NoticeboardContent(); + nbContent.setNbContentId(content_id); + } + + nbForm.copyValuesIntoNbContent(nbContent); + if ( nbContent.getDateCreated() == null ) + nbContent.setDateCreated(nbContent.getDateUpdated()); + + UserDTO user = getUser(request); + nbContent.setCreatorUserId(new Long(user.getUserID().longValue())); + + // Author has finished editing the content and mark the defineLater flag to false + nbContent.setDefineLater(false); + nbService.saveNoticeboard(nbContent); + + // Save the attachments then update the attachment collections in the session. + SessionMap sessionMap = getSessionMap(request, nbForm); + List attachmentList = (List) sessionMap.get(NoticeboardConstants.ATTACHMENT_LIST); + List deletedAttachmentList = (List) sessionMap.get(NoticeboardConstants.DELETED_ATTACHMENT_LIST); + deletedAttachmentList = saveAttachments(nbService, nbContent, attachmentList, deletedAttachmentList, mapping, request); + sessionMap = NbWebUtil.addUploadsToSession(sessionMap, request, attachmentList, deletedAttachmentList); + + request.setAttribute(AuthoringConstants.LAMS_AUTHORING_SUCCESS_FLAG,Boolean.TRUE); + return mapping.findForward(NoticeboardConstants.AUTHOR_PAGE); + + } + + /** + * Go through the attachments collections. Remove any content repository or tool objects + * matching entries in the the deletedAttachments collection, add any new attachments in the + * attachments collection. Clear the deletedAttachments collection, ready for new editing. + */ + private List saveAttachments (INoticeboardService nbService, NoticeboardContent nbContent, + List attachmentList, List deletedAttachmentList, + ActionMapping mapping, HttpServletRequest request) { - if (request.getSession().getAttribute(NoticeboardConstants.MODE).equals(DEFINE_LATER_MODE)) - request.setAttribute(SHOW_BASIC_TAB, "true"); - - request.setAttribute(AuthoringConstants.LAMS_AUTHORING_SUCCESS_FLAG,Boolean.TRUE); - return mapping.findForward(NoticeboardConstants.AUTHOR_PAGE); - - } - - - - /** - * Go through the attachments collections. Remove any content repository or tool objects - * matching entries in the the deletedAttachments collection, add any new attachments in the - * attachments collection. Clear the deletedAttachments collection, ready for new editing. - */ - private List saveAttachments (INoticeboardService nbService, NoticeboardContent nbContent, - List attachmentList, List deletedAttachmentList, - ActionMapping mapping, HttpServletRequest request) { + if ( deletedAttachmentList != null ) { + Iterator iter = deletedAttachmentList.iterator(); + while (iter.hasNext()) { + NoticeboardAttachment attachment = (NoticeboardAttachment) iter.next(); + + try + { + // remove tool entry from db, includies removing entry from the content repository + // deleting a non-existent entry shouldn't cause any errors. + if ( attachment.getAttachmentId() != null ) { + nbService.removeAttachment(nbContent, attachment); + } + } catch (RepositoryCheckedException e) { + logger.error("Unable to delete file",e); + ActionMessages am = new ActionMessages(); + am.add( ActionMessages.GLOBAL_MESSAGE, + new ActionMessage( NoticeboardConstants.ERROR_FILE_UPLOAD_CONTENT_REPOSITORY , + attachment.getFilename())); + saveErrors( request, am ); + } + } + deletedAttachmentList.clear(); + } + + if ( attachmentList != null ) { + Iterator iter = attachmentList.iterator(); + while (iter.hasNext()) { + NoticeboardAttachment attachment = (NoticeboardAttachment) iter.next(); - if ( deletedAttachmentList != null ) { - Iterator iter = deletedAttachmentList.iterator(); - while (iter.hasNext()) { - NoticeboardAttachment attachment = (NoticeboardAttachment) iter.next(); - - try - { - // remove tool entry from db, includies removing entry from the content repository - // deleting a non-existent entry shouldn't cause any errors. - if ( attachment.getAttachmentId() != null ) { - nbService.removeAttachment(nbContent, attachment); - } - } catch (RepositoryCheckedException e) { - logger.error("Unable to delete file",e); - ActionMessages am = new ActionMessages(); - am.add( ActionMessages.GLOBAL_MESSAGE, - new ActionMessage( NoticeboardConstants.ERROR_FILE_UPLOAD_CONTENT_REPOSITORY , - attachment.getFilename())); - saveErrors( request, am ); - } - } - deletedAttachmentList.clear(); - } - - if ( attachmentList != null ) { - Iterator iter = attachmentList.iterator(); - while (iter.hasNext()) { - NoticeboardAttachment attachment = (NoticeboardAttachment) iter.next(); + if ( attachment.getAttachmentId() == null ) { + // add entry to tool table - file already in content repository + nbService.saveAttachment(nbContent, attachment); + } + } + } + + return deletedAttachmentList; + } + + /** + * This method will either upload an online instructions file or an offline instructions file. + * It will upload an online file if the bean property onlineFile is not null and similarly, + * will upload an offline file if the bean property offlineFile is not null. + * By using the term "upload", we are saving the file information on the local database (?) + * + * @param mapping + * @param form + * @param request + * @param response + * @return + * @throws NbApplicationException + */ + public ActionForward upload(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) + throws InvalidParameterException, FileNotFoundException, RepositoryCheckedException, IOException, NbApplicationException { + + + //set up the values in the map + //call the uploadFile method from toolContentHandler + NbAuthoringForm nbForm = (NbAuthoringForm)form; + //copyAuthoringFormValuesIntoFormBean(request, nbForm); + FormFile theFile; + INoticeboardService nbService = NoticeboardServiceProxy.getNbService(getServlet().getServletContext()); + + Long content_id = NbWebUtil.convertToLong(nbForm.getToolContentID()); + //throws exception if the content id does not exist + checkContentId(content_id); + NoticeboardContent nbContent = nbService.retrieveNoticeboard(content_id); + + //check if the file uploaded is an online instructions file or offline instructions file. + //if one of the types is null, then the other one must have been uploaded. + //here we check if the file is an online one + + if ((nbForm.getOnlineFile() != null && (nbForm.getOnlineFile().getFileName().trim().length() != 0)) || + (nbForm.getOfflineFile() != null && (nbForm.getOfflineFile().getFileName().trim().length() != 0))) + { + boolean isOnlineFile = ((nbForm.getOnlineFile() != null && (nbForm.getOnlineFile().getFileName().trim().length() != 0)) ? true: false ); + theFile = (isOnlineFile ? nbForm.getOnlineFile() : nbForm.getOfflineFile()); + String fileType = isOnlineFile ? IToolContentHandler.TYPE_ONLINE : IToolContentHandler.TYPE_OFFLINE; - if ( attachment.getAttachmentId() == null ) { - // add entry to tool table - file already in content repository - nbService.saveAttachment(nbContent, attachment); + SessionMap map = getSessionMap(request, nbForm); + List attachmentList = (List) map.get(NoticeboardConstants.ATTACHMENT_LIST); + List deletedAttachmentList = (List) map.get(NoticeboardConstants.DELETED_ATTACHMENT_LIST); + + // if a file with the same name already exists then move the old one to deleted + deletedAttachmentList = moveToDelete(theFile.getFileName(), isOnlineFile, attachmentList, deletedAttachmentList ); + + try + { + // This is a new file and so is saved to the content repository. Add it to the + // attachments collection, but don't add it to the tool's tables yet. + NodeKey node = nbService.uploadFile(theFile.getInputStream(), theFile.getFileName(), theFile.getContentType(), fileType); + NoticeboardAttachment file = new NoticeboardAttachment(); + file.setFilename(theFile.getFileName()); + file.setOnlineFile(isOnlineFile); + file.setNbContent(nbContent); + file.setUuid(node.getUuid()); + file.setVersionId(node.getVersion()); + + // add the files to the attachment collection - if one existed, it should have already been removed. + attachmentList.add(file); + map = NbWebUtil.addUploadsToSession(map, request, attachmentList, deletedAttachmentList); + + //reset the fields so that more files can be uploaded + nbForm.setOfflineFile(null); + nbForm.setOnlineFile(null); + } + catch (FileNotFoundException e) { + logger.error("Unable to uploadfile",e); + throw new NbApplicationException("Unable to upload file, exception was "+e.getMessage()); + } catch (IOException e) { + logger.error("Unable to uploadfile",e); + throw new NbApplicationException("Unable to upload file, exception was "+e.getMessage()); + } catch (RepositoryCheckedException e) { + logger.error("Unable to uploadfile",e); + throw new NbApplicationException("Unable to upload file, exception was "+e.getMessage()); + } + } + + nbForm.setMethod(NoticeboardConstants.INSTRUCTIONS); + + return mapping.findForward(NoticeboardConstants.AUTHOR_PAGE); + } + + /** If this file exists in attachments list, move it to the deleted attachments list. + * Returns the updated deletedAttachments list, creating a new one if needed. Uses the filename + * and isOnline flag to match up the attachment entry */ + private List moveToDelete(String filename, boolean isOnline, List attachmentsList, List deletedAttachmentsList ) { + return moveToDelete(filename, isOnline, null, attachmentsList, deletedAttachmentsList); + } + /** If this file exists in attachments list, move it to the deleted attachments list. + * Returns the updated deletedAttachments list, creating a new one if needed. Uses the uuid of the + * file to match up the attachment entry */ + private List moveToDelete(Long uuid, List attachmentsList, List deletedAttachmentsList ) { + return moveToDelete(null, false, uuid, attachmentsList, deletedAttachmentsList); + } + + /** If this file exists in attachments map, move it to the deleted attachments map. + * Returns the updated deletedAttachments map, creating a new one if needed. If uuid supplied + * then tries to match on that, otherwise uses filename and isOnline. */ + private List moveToDelete(String filename, boolean isOnline, Long uuid, List attachmentsList, List deletedAttachmentsList ) { + + List deletedList = deletedAttachmentsList != null ? deletedAttachmentsList : NbWebUtil.setupDeletedAttachmentList(); + + if ( attachmentsList != null ) { + Iterator iter = attachmentsList.iterator(); + NoticeboardAttachment attachment = null; + while ( iter.hasNext() && attachment == null ) { + NoticeboardAttachment value = (NoticeboardAttachment) iter.next(); + + if ( uuid != null ) { + // compare using uuid + if ( uuid.equals(value.getUuid()) ) { + attachment = value; } - } - } - - return deletedAttachmentList; - } - - /** - * This method will either upload an online instructions file or an offline instructions file. - * It will upload an online file if the bean property onlineFile is not null and similarly, - * will upload an offline file if the bean property offlineFile is not null. - * By using the term "upload", we are saving the file information on the local database (?) - * - * @param mapping - * @param form - * @param request - * @param response - * @return - * @throws NbApplicationException - */ - public ActionForward upload(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) - throws InvalidParameterException, FileNotFoundException, RepositoryCheckedException, IOException, NbApplicationException { - - - //set up the values in the map - //call the uploadFile method from toolContentHandler - NbAuthoringForm nbForm = (NbAuthoringForm)form; - //copyAuthoringFormValuesIntoFormBean(request, nbForm); - FormFile theFile; - INoticeboardService nbService = NoticeboardServiceProxy.getNbService(getServlet().getServletContext()); - - Long content_id = NbWebUtil.convertToLong(nbForm.getToolContentID()); - //throws exception if the content id does not exist - checkContentId(content_id); - NoticeboardContent nbContent = nbService.retrieveNoticeboard(content_id); - - //check if the file uploaded is an online instructions file or offline instructions file. - //if one of the types is null, then the other one must have been uploaded. - //here we check if the file is an online one - - if ((nbForm.getOnlineFile() != null && (nbForm.getOnlineFile().getFileName().trim().length() != 0)) || - (nbForm.getOfflineFile() != null && (nbForm.getOfflineFile().getFileName().trim().length() != 0))) - { - boolean isOnlineFile = ((nbForm.getOnlineFile() != null && (nbForm.getOnlineFile().getFileName().trim().length() != 0)) ? true: false ); - theFile = (isOnlineFile ? nbForm.getOnlineFile() : nbForm.getOfflineFile()); - String fileType = isOnlineFile ? IToolContentHandler.TYPE_ONLINE : IToolContentHandler.TYPE_OFFLINE; + } else { + // compare using filename and online/offline flag + if ( value.isOnlineFile() == isOnline && value.getFilename().equals(filename) ) { + attachment = value; + } + } + } + if ( attachment != null ) { + deletedList.add(attachment); + attachmentsList.remove(attachment); + } + } + + return deletedList; + } + + public ActionForward deleteAttachment(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) + throws InvalidParameterException, RepositoryCheckedException, NbApplicationException { + + Long uuid = NbWebUtil.convertToLong(request.getParameter(NoticeboardConstants.UUID)); + if (uuid == null) + { + String error = "Unable to continue. The file uuid is missing."; + logger.error(error); + throw new NbApplicationException(error); + } + + // move the file's details from the attachment collection to the deleted attachments collection + // the attachment will be delete on saving. + NbAuthoringForm nbForm = (NbAuthoringForm)form; + SessionMap map = getSessionMap(request, nbForm); + List attachmentList = (List) map.get(NoticeboardConstants.ATTACHMENT_LIST); + List deletedAttachmentList = (List) map.get(NoticeboardConstants.DELETED_ATTACHMENT_LIST); + deletedAttachmentList = moveToDelete(uuid, attachmentList, deletedAttachmentList ); + + nbForm.setMethod(NoticeboardConstants.INSTRUCTIONS); + + return mapping.findForward(NoticeboardConstants.AUTHOR_PAGE); + } + - List attachmentList = (List) request.getSession().getAttribute(NoticeboardConstants.ATTACHMENT_LIST); - List deletedAttachmentList = (List) request.getSession().getAttribute(NoticeboardConstants.DELETED_ATTACHMENT_LIST); - - // if a file with the same name already exists then move the old one to deleted - deletedAttachmentList = moveToDelete(theFile.getFileName(), isOnlineFile, attachmentList, deletedAttachmentList ); - - try - { - // This is a new file and so is saved to the content repository. Add it to the - // attachments collection, but don't add it to the tool's tables yet. - NodeKey node = nbService.uploadFile(theFile.getInputStream(), theFile.getFileName(), theFile.getContentType(), fileType); - NoticeboardAttachment file = new NoticeboardAttachment(); - file.setFilename(theFile.getFileName()); - file.setOnlineFile(isOnlineFile); - file.setNbContent(nbContent); - file.setUuid(node.getUuid()); - file.setVersionId(node.getVersion()); - - // add the files to the attachment collection - if one existed, it should have already been removed. - attachmentList.add(file); - - NbWebUtil.addUploadsToSession(request, attachmentList, deletedAttachmentList); - //reset the fields so that more files can be uploaded - nbForm.setOfflineFile(null); - nbForm.setOnlineFile(null); - } - catch (FileNotFoundException e) { - logger.error("Unable to uploadfile",e); - throw new NbApplicationException("Unable to upload file, exception was "+e.getMessage()); - } catch (IOException e) { - logger.error("Unable to uploadfile",e); - throw new NbApplicationException("Unable to upload file, exception was "+e.getMessage()); - } catch (RepositoryCheckedException e) { - logger.error("Unable to uploadfile",e); - throw new NbApplicationException("Unable to upload file, exception was "+e.getMessage()); - } - } - - nbForm.setMethod(NoticeboardConstants.INSTRUCTIONS); - - return mapping.findForward(NoticeboardConstants.AUTHOR_PAGE); - } - - /** If this file exists in attachments list, move it to the deleted attachments list. - * Returns the updated deletedAttachments list, creating a new one if needed. Uses the filename - * and isOnline flag to match up the attachment entry */ - private List moveToDelete(String filename, boolean isOnline, List attachmentsList, List deletedAttachmentsList ) { - return moveToDelete(filename, isOnline, null, attachmentsList, deletedAttachmentsList); - } - /** If this file exists in attachments list, move it to the deleted attachments list. - * Returns the updated deletedAttachments list, creating a new one if needed. Uses the uuid of the - * file to match up the attachment entry */ - private List moveToDelete(Long uuid, List attachmentsList, List deletedAttachmentsList ) { - return moveToDelete(null, false, uuid, attachmentsList, deletedAttachmentsList); - } - - /** If this file exists in attachments map, move it to the deleted attachments map. - * Returns the updated deletedAttachments map, creating a new one if needed. If uuid supplied - * then tries to match on that, otherwise uses filename and isOnline. */ - private List moveToDelete(String filename, boolean isOnline, Long uuid, List attachmentsList, List deletedAttachmentsList ) { + /** + * It is assumed that the contentId is passed as a http parameter + * if the contentId is null, an exception is thrown, otherwise proceed as normal + * + * @param contentId thetoolContentId
to check
+ */
+ private void checkContentId(Long contentId)
+ {
+ if (contentId == null)
+ {
+ String error = "Unable to continue. Tool content id missing.";
+
+ throw new NbApplicationException(error);
+ }
+ }
+
+ /**
+ * Retrieve the SessionMap from the HttpSession.
+ *
+ * @param request
+ * @param authForm
+ * @return
+ */
+ private SessionMap getSessionMap(HttpServletRequest request, NbAuthoringForm nbForm) {
+ return (SessionMap) request.getSession().getAttribute(nbForm.getSessionMapID());
+ }
+
+ /**
+ * This method copies the values of the request parameters richTextOnlineInstructions
+ * richTextOfflineInstructions
richTextContent
into the form properties
+ * onlineInstructions, offlineInstructions and content respectively.
+ *
+ * @param request HttpServlet request
+ * @param form The ActionForm class containing data submitted by the forms.
+ */
+ /* private void copyAuthoringFormValuesIntoFormBean(HttpServletRequest request, NbAuthoringForm form)
+ {
+ String onlineInstruction = WebUtil.readStrParam(request, NoticeboardConstants.RICH_TEXT_ONLINE_INSTRN, true);
+ String offlineInstruction = WebUtil.readStrParam(request, NoticeboardConstants.RICH_TEXT_OFFLINE_INSTRN, true);
+ String content = WebUtil.readStrParam(request, NoticeboardConstants.RICH_TEXT_CONTENT, true);
+ String title = WebUtil.readStrParam(request, NoticeboardConstants.RICH_TEXT_TITLE, true);
- List deletedList = deletedAttachmentsList != null ? deletedAttachmentsList : NbWebUtil.setupDeletedAttachmentList();
-
- if ( attachmentsList != null ) {
- Iterator iter = attachmentsList.iterator();
- NoticeboardAttachment attachment = null;
- while ( iter.hasNext() && attachment == null ) {
- NoticeboardAttachment value = (NoticeboardAttachment) iter.next();
-
- if ( uuid != null ) {
- // compare using uuid
- if ( uuid.equals(value.getUuid()) ) {
- attachment = value;
- }
- } else {
- // compare using filename and online/offline flag
- if ( value.isOnlineFile() == isOnline && value.getFilename().equals(filename) ) {
- attachment = value;
- }
- }
- }
- if ( attachment != null ) {
- deletedList.add(attachment);
- attachmentsList.remove(attachment);
- }
- }
-
- return deletedList;
- }
-
- public ActionForward deleteAttachment(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
- throws InvalidParameterException, RepositoryCheckedException, NbApplicationException {
-
- Long uuid = NbWebUtil.convertToLong(request.getParameter(NoticeboardConstants.UUID));
- if (uuid == null)
- {
- String error = "Unable to continue. The file uuid is missing.";
- logger.error(error);
- throw new NbApplicationException(error);
- }
-
- // move the file's details from the attachment collection to the deleted attachments collection
- // the attachment will be delete on saving.
- NbAuthoringForm nbForm = (NbAuthoringForm)form;
- List attachmentList = (List) request.getSession().getAttribute(NoticeboardConstants.ATTACHMENT_LIST);
- List deletedAttachmentList = (List) request.getSession().getAttribute(NoticeboardConstants.DELETED_ATTACHMENT_LIST);
- deletedAttachmentList = moveToDelete(uuid, attachmentList, deletedAttachmentList );
-
- nbForm.setMethod(NoticeboardConstants.INSTRUCTIONS);
-
- return mapping.findForward(NoticeboardConstants.AUTHOR_PAGE);
- }
-
-
- /**
- * It is assumed that the contentId is passed as a http parameter
- * if the contentId is null, an exception is thrown, otherwise proceed as normal
- *
- * @param contentId the toolContentId
to check
- */
- private void checkContentId(Long contentId)
- {
- if (contentId == null)
- {
- String error = "Unable to continue. Tool content id missing.";
-
- throw new NbApplicationException(error);
- }
- }
-
- /**
- * This method copies the values of the request parameters richTextOnlineInstructions
- * richTextOfflineInstructions
richTextContent
into the form properties
- * onlineInstructions, offlineInstructions and content respectively.
- *
- * @param request HttpServlet request
- * @param form The ActionForm class containing data submitted by the forms.
- */
- /* private void copyAuthoringFormValuesIntoFormBean(HttpServletRequest request, NbAuthoringForm form)
- {
- String onlineInstruction = WebUtil.readStrParam(request, NoticeboardConstants.RICH_TEXT_ONLINE_INSTRN, true);
- String offlineInstruction = WebUtil.readStrParam(request, NoticeboardConstants.RICH_TEXT_OFFLINE_INSTRN, true);
- String content = WebUtil.readStrParam(request, NoticeboardConstants.RICH_TEXT_CONTENT, true);
- String title = WebUtil.readStrParam(request, NoticeboardConstants.RICH_TEXT_TITLE, true);
-
-
- form.setTitle(title);
-
- form.setContent(content);
-
- form.setOnlineInstructions(onlineInstruction);
-
- form.setOfflineInstructions(offlineInstruction);
-
- } */
-
- /* private void copyFormValuesIntoNbContent(HttpServletRequest request, NoticeboardContent nbContent)
- {
- nbContent.setTitle((String)request.getParameter(NoticeboardConstants.RICH_TEXT_TITLE));
- nbContent.setContent((String)request.getParameter(NoticeboardConstants.RICH_TEXT_CONTENT));
- nbContent.setOnlineInstructions((String)request.getParameter(NoticeboardConstants.RICH_TEXT_ONLINE_INSTRN));
- nbContent.setOfflineInstructions((String)request.getParameter(NoticeboardConstants.RICH_TEXT_OFFLINE_INSTRN));
-
- } */
-
- /**
- *
- */
- private void setModeOfUse(HttpServletRequest request, String defineLater)
- {
- if (defineLater != null )
- {
- if (defineLater.equals("true"))
- {
- request.getSession().setAttribute(NoticeboardConstants.MODE, DEFINE_LATER_MODE);
- request.setAttribute(SHOW_BASIC_TAB, "true");
- }
- }
- else
- request.getSession().setAttribute(NoticeboardConstants.MODE, AUTHOR_MODE);
-
- }
-
-
+
+ form.setTitle(title);
+
+ form.setContent(content);
+
+ form.setOnlineInstructions(onlineInstruction);
+
+ form.setOfflineInstructions(offlineInstruction);
+
+ } */
+
+ /* private void copyFormValuesIntoNbContent(HttpServletRequest request, NoticeboardContent nbContent)
+ {
+ nbContent.setTitle((String)request.getParameter(NoticeboardConstants.RICH_TEXT_TITLE));
+ nbContent.setContent((String)request.getParameter(NoticeboardConstants.RICH_TEXT_CONTENT));
+ nbContent.setOnlineInstructions((String)request.getParameter(NoticeboardConstants.RICH_TEXT_ONLINE_INSTRN));
+ nbContent.setOfflineInstructions((String)request.getParameter(NoticeboardConstants.RICH_TEXT_OFFLINE_INSTRN));
+
+ } */
+
}
Index: lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbAuthoringForm.java
===================================================================
RCS file: /usr/local/cvsroot/lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbAuthoringForm.java,v
diff -u -r1.14 -r1.15
--- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbAuthoringForm.java 6 Apr 2006 07:05:06 -0000 1.14
+++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbAuthoringForm.java 19 Jul 2006 05:15:48 -0000 1.15
@@ -82,6 +82,9 @@
private FormFile offlineFile;
private String currentTab;
+ private String sessionMapID;
+
+
/**
* @return Returns the offlineFile.
*/
@@ -276,6 +279,12 @@
public void setCurrentTab(String currentTab) {
this.currentTab = currentTab;
}
+ public String getSessionMapID() {
+ return sessionMapID;
+ }
+ public void setSessionMapID(String sessionMapID) {
+ this.sessionMapID = sessionMapID;
+ }
}
Index: lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbExportAction.java
===================================================================
RCS file: /usr/local/cvsroot/lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbExportAction.java,v
diff -u -r1.8 -r1.9
--- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbExportAction.java 6 Apr 2006 07:05:06 -0000 1.8
+++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbExportAction.java 19 Jul 2006 05:15:48 -0000 1.9
@@ -54,7 +54,7 @@
/**
* ----------------XDoclet Tags--------------------
*
- * @struts:action path="/exportPortfolio" name="NbExportForm" scope="session" type="org.lamsfoundation.lams.tool.noticeboard.web.NbExportAction"
+ * @struts:action path="/exportPortfolio" name="NbExportForm" scope="request" type="org.lamsfoundation.lams.tool.noticeboard.web.NbExportAction"
* validate="false" parameter="mode"
* @struts.action-exception key="error.exception.NbApplication" scope="request"
* type="org.lamsfoundation.lams.tool.noticeboard.NbApplicationException"
Index: lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbLearnerAction.java
===================================================================
RCS file: /usr/local/cvsroot/lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbLearnerAction.java,v
diff -u -r1.14 -r1.15
--- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbLearnerAction.java 27 Jun 2006 00:57:38 -0000 1.14
+++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbLearnerAction.java 19 Jul 2006 05:15:48 -0000 1.15
@@ -71,7 +71,7 @@
*
* ----------------XDoclet Tags--------------------
*
- * @struts:action path="/learner" name="NbLearnerForm" scope="session" type="org.lamsfoundation.lams.tool.noticeboard.web.NbLearnerAction"
+ * @struts:action path="/learner" name="NbLearnerForm" scope="request" type="org.lamsfoundation.lams.tool.noticeboard.web.NbLearnerAction"
* input=".learnerContent" validate="false" parameter="method"
* @struts.action-exception key="error.exception.NbApplication" scope="request"
* type="org.lamsfoundation.lams.tool.noticeboard.NbApplicationException"
@@ -163,7 +163,7 @@
}
- request.getSession().setAttribute(NoticeboardConstants.READ_ONLY_MODE, "true");
+ request.setAttribute(NoticeboardConstants.READ_ONLY_MODE, "true");
return mapping.findForward(NoticeboardConstants.DISPLAY_LEARNER_CONTENT);
Index: lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbLearnerForm.java
===================================================================
RCS file: /usr/local/cvsroot/lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbLearnerForm.java,v
diff -u -r1.6 -r1.7
--- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbLearnerForm.java 6 Apr 2006 07:05:06 -0000 1.6
+++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbLearnerForm.java 19 Jul 2006 05:15:48 -0000 1.7
@@ -54,6 +54,7 @@
private String mode;
+ private Boolean readOnly;
/**
* @return Returns the toolSessionID.
@@ -115,10 +116,12 @@
}
- public void copyValuesIntoForm(NoticeboardContent content)
+ public void copyValuesIntoForm(NoticeboardContent content, boolean readOnly, String mode)
{
setTitle(content.getTitle());
setContent(content.getContent());
+ setMode(mode);
+ setReadOnly(new Boolean(readOnly));
}
/**
@@ -133,4 +136,10 @@
public void setMode(String mode) {
this.mode = mode;
}
+ public Boolean getReadOnly() {
+ return readOnly;
+ }
+ public void setReadOnly(Boolean readOnly) {
+ this.readOnly = readOnly;
+ }
}
Index: lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbLearnerStarterAction.java
===================================================================
RCS file: /usr/local/cvsroot/lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbLearnerStarterAction.java,v
diff -u -r1.19 -r1.20
--- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbLearnerStarterAction.java 14 Jul 2006 04:56:51 -0000 1.19
+++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbLearnerStarterAction.java 19 Jul 2006 05:15:48 -0000 1.20
@@ -67,7 +67,7 @@
*
* ----------------XDoclet Tags--------------------
*
- * @struts:action path="/starter/learner" name="NbLearnerForm" scope="session" type="org.lamsfoundation.lams.tool.noticeboard.web.NbLearnerStarterAction"
+ * @struts:action path="/starter/learner" name="NbLearnerForm" scope="request" type="org.lamsfoundation.lams.tool.noticeboard.web.NbLearnerStarterAction"
* validate="false" parameter="mode"
* @struts.action-exception key="error.exception.NbApplication" scope="request"
* type="org.lamsfoundation.lams.tool.noticeboard.NbApplicationException"
@@ -112,7 +112,6 @@
NoticeboardContent nbContent = null;
NoticeboardUser nbUser = null;
- NbWebUtil.cleanLearnerSession(request);
saveMessages(request, null);
NbLearnerForm learnerForm = (NbLearnerForm)form;
@@ -158,29 +157,33 @@
return mapping.findForward(NoticeboardConstants.DISPLAY_MESSAGE);
}
+ boolean readOnly = false;
ToolAccessMode mode = WebUtil.readToolAccessModeParam(request, AttributeNames.PARAM_MODE,false);
if (mode == ToolAccessMode.LEARNER || mode == ToolAccessMode.AUTHOR )
{
- /* Set the ContentInUse flag to true, and defineLater flag to false */
- nbContent.setContentInUse(true);
- // nbContent.setDefineLater(false); /* defineLater should be false anyway */
- nbService.saveNoticeboard(nbContent);
-
+ if ( ! nbContent.isContentInUse() ) {
+ /* Set the ContentInUse flag to true, and defineLater flag to false */
+ nbContent.setContentInUse(true);
+ nbService.saveNoticeboard(nbContent);
+ }
+
if (nbUser != null)
{
- if (nbUser.getUserStatus().equals(NoticeboardUser.COMPLETED))
- request.getSession().setAttribute(NoticeboardConstants.READ_ONLY_MODE, "true");
+ if (nbUser.getUserStatus().equals(NoticeboardUser.COMPLETED)) {
+ readOnly = true;
+ }
}
else
{
//create a new user with this session id
NoticeboardUser newUser = new NoticeboardUser(userID);
nbService.addUser(toolSessionID, newUser);
}
-
-
- }
- learnerForm.copyValuesIntoForm(nbContent);
+ } else {
+ readOnly = true;
+ }
+
+ learnerForm.copyValuesIntoForm(nbContent, readOnly, mode.toString());
return mapping.findForward(NoticeboardConstants.DISPLAY_LEARNER_CONTENT);
}
@@ -262,27 +265,5 @@
return false;
}
- private boolean displayMessageToAuthor(NoticeboardContent content, ActionMessages message)
- {
- boolean isDefineLaterSet = isFlagSet(content, NoticeboardConstants.FLAG_DEFINE_LATER);
- boolean isRunOfflineSet = isFlagSet(content, NoticeboardConstants.FLAG_RUN_OFFLINE);
- if(isDefineLaterSet || isRunOfflineSet)
- {
- if (isDefineLaterSet)
- {
- message.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("message.author.defineLaterSet1"));
- message.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("message.author.defineLaterSet2"));
- }
- if (isRunOfflineSet)
- {
- message.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("message.runOfflineSet"));
- }
- return true;
- }
- else
- return false;
- }
-
-
}
\ No newline at end of file
Index: lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbMonitoringAction.java
===================================================================
RCS file: /usr/local/cvsroot/lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbMonitoringAction.java,v
diff -u -r1.19 -r1.20
--- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbMonitoringAction.java 6 Apr 2006 07:05:07 -0000 1.19
+++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbMonitoringAction.java 19 Jul 2006 05:15:48 -0000 1.20
@@ -26,8 +26,8 @@
import java.util.HashMap;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
+import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -39,6 +39,7 @@
import org.lamsfoundation.lams.tool.noticeboard.NbApplicationException;
import org.lamsfoundation.lams.tool.noticeboard.NoticeboardConstants;
import org.lamsfoundation.lams.tool.noticeboard.NoticeboardContent;
+import org.lamsfoundation.lams.tool.noticeboard.NoticeboardSession;
import org.lamsfoundation.lams.tool.noticeboard.service.INoticeboardService;
import org.lamsfoundation.lams.tool.noticeboard.service.NoticeboardServiceProxy;
import org.lamsfoundation.lams.tool.noticeboard.util.NbWebUtil;
@@ -58,7 +59,7 @@
*
* ----------------XDoclet Tags--------------------
*
- * @struts:action path="/monitoring" name="NbMonitoringForm" scope="session" type="org.lamsfoundation.lams.tool.noticeboard.web.NbMonitoringAction"
+ * @struts:action path="/monitoring" name="NbMonitoringForm" scope="request" type="org.lamsfoundation.lams.tool.noticeboard.web.NbMonitoringAction"
* input=".monitoringContent" validate="false" parameter="method"
* @struts.action-exception key="error.exception.NbApplication" scope="request"
* type="org.lamsfoundation.lams.tool.noticeboard.NbApplicationException"
@@ -82,182 +83,62 @@
public static final String EDITACTIVITY_TABID = "3";
public static final String STATISTICS_TABID = "4";
- /**
- * If no method parameter, or an unknown key, it will
- * Setup the monitoring environment, and places values in the
- * formbean in session scope and then go to the summary tab.
- */
public ActionForward unspecified(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws NbApplicationException
{
- NbMonitoringForm monitorForm = new NbMonitoringForm();
- NbWebUtil.cleanMonitoringSession(request);
- Long toolContentId = NbWebUtil.convertToLong(request.getParameter(NoticeboardConstants.TOOL_CONTENT_ID));
-
- if (toolContentId == null)
+ Long toolContentId = NbWebUtil.convertToLong(request.getParameter(NoticeboardConstants.TOOL_CONTENT_ID));
+ if (toolContentId == null)
{
String error = "Unable to continue. Tool content id missing";
logger.error(error);
throw new NbApplicationException(error);
}
- monitorForm.setToolContentID(toolContentId.toString());
- request.getSession().setAttribute(FORM, monitorForm);
- return summary(mapping, form, request, response);
+
+ NbMonitoringForm monitorForm = new NbMonitoringForm();
- }
-
- /**
- * Will forward to the jsp
- * and will display the edit activity page, which shows the content of the noticeboard
- * and will show an edit button which allows an author to modify the noticeboard content.
- * When this edit button is clicked, it appends defineLater=true to the authoring URL.
- * However, if the contents is not editable (ie. the contents are in use which means a learner
- * already reached the activity) it will display a message saying so.
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- */
- public ActionForward editActivity(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
-
- NbMonitoringForm monitorForm = (NbMonitoringForm)form;
-
INoticeboardService nbService = NoticeboardServiceProxy.getNbService(getServlet().getServletContext());
- Long toolContentId = NbWebUtil.convertToLong(monitorForm.getToolContentID());
NoticeboardContent content = nbService.retrieveNoticeboard(toolContentId);
- NbWebUtil.copyValuesIntoSession(request, content);
- if (NbWebUtil.isContentEditable(content))
- {
- // request.getSession().setAttribute(NoticeboardConstants.CONTENT_IN_USE, "false"); //used in jsp page to allow the edit button to show, so that author can edit page
- // request.getSession().setAttribute(NoticeboardConstants.DEFINE_LATER, "true");
- request.setAttribute(NoticeboardConstants.PAGE_EDITABLE, "true");
-
+
+ monitorForm.setToolContentID(toolContentId.toString());
+ monitorForm.setTitle(content.getTitle());
+ monitorForm.setContent(content.getContent());
+ monitorForm.setOnlineInstructions(content.getOnlineInstructions());
+ monitorForm.setOfflineInstructions(content.getOfflineInstructions());
+ monitorForm.setAttachmentsList(NbWebUtil.setupAttachmentList(nbService, content));
+
+ if ( NbWebUtil.isContentEditable(content) ) {
+ monitorForm.setContentEditable("true");
//set up the request parameters to append to the URL
Map