Index: lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/web/actions/AuthoringAction.java =================================================================== diff -u -ra96c5d0aeb2e25ac3d9241c5b8ce836eb6248355 -r021a7a0c1e8d0a0592047fa4b3840872d8bfbc05 --- lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/web/actions/AuthoringAction.java (.../AuthoringAction.java) (revision a96c5d0aeb2e25ac3d9241c5b8ce836eb6248355) +++ lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/web/actions/AuthoringAction.java (.../AuthoringAction.java) (revision 021a7a0c1e8d0a0592047fa4b3840872d8bfbc05) @@ -54,7 +54,6 @@ import org.lamsfoundation.lams.web.util.AttributeNames; import org.lamsfoundation.lams.web.util.SessionMap; - /** * @author * @version @@ -96,11 +95,13 @@ // Extract toolContentID from parameters. Long toolContentID = new Long(WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID)); - - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - ToolAccessMode mode = WebUtil.readToolAccessModeParam(request, "mode", true); - + String contentFolderID = WebUtil.readStrParam(request, + AttributeNames.PARAM_CONTENT_FOLDER_ID); + + ToolAccessMode mode = WebUtil.readToolAccessModeParam(request, "mode", + true); + // set up chatService if (chatService == null) { chatService = ChatServiceProxy.getChatService(this.getServlet() @@ -123,9 +124,10 @@ request).getMessage("error.content.locked")); return mapping.findForward("message_page"); } - + if (mode != null && mode.isTeacher()) { - // Set the defineLater flag so that learners cannot use content while we + // Set the defineLater flag so that learners cannot use content + // while we // are editing. This flag is released when updateContent is called. chat.setDefineLater(true); chatService.saveOrUpdateChat(chat); @@ -134,17 +136,18 @@ // Set up the authForm. AuthoringForm authForm = (AuthoringForm) form; updateAuthForm(authForm, chat); - + // Set up sessionMap - SessionMap map = createSessionMap(chat, getAccessMode(request)); + SessionMap map = createSessionMap(chat, + getAccessMode(request)); authForm.setSessionMapID(map.getSessionID()); - + authForm.setContentFolderID(contentFolderID); // add the sessionMap to HTTPSession. request.getSession().setAttribute(map.getSessionID(), map); request.setAttribute(ChatConstants.ATTR_SESSION_MAP, map); - + return mapping.findForward("success"); } @@ -172,11 +175,11 @@ // leave in repository but remove from db attachments.remove(att); } - + // add unsaved attachments attachments.addAll(getAttList(KEY_UNSAVED_ONLINE_FILES, map)); attachments.addAll(getAttList(KEY_UNSAVED_OFFLINE_FILES, map)); - + // set attachments in case it didn't exist chat.setChatAttachments(attachments); @@ -190,12 +193,12 @@ request.setAttribute(AuthoringConstants.LAMS_AUTHORING_SUCCESS_FLAG, Boolean.TRUE); - + // add the sessionMapID to form authForm.setSessionMapID(map.getSessionID()); request.setAttribute(ChatConstants.ATTR_SESSION_MAP, map); - + return mapping.findForward("success"); } @@ -258,28 +261,30 @@ savedFiles = getAttList(KEY_ONLINE_FILES, map); } - // upload file to repository - ChatAttachment newAtt = chatService.uploadFileToContent(authForm - .getToolContentID(), file, type); + if (file.getFileName().length() != 0) { + // upload file to repository + ChatAttachment newAtt = chatService.uploadFileToContent(authForm + .getToolContentID(), file, type); - // Add attachment to unsavedFiles - // check to see if file with same name exists - ChatAttachment currAtt; - Iterator iter = savedFiles.iterator(); - while (iter.hasNext()) { - currAtt = (ChatAttachment) iter.next(); - if (StringUtils.equals(currAtt.getFileName(), newAtt.getFileName())) { - // move from this this list to deleted list. - getAttList(KEY_DELETED_FILES, map).add(currAtt); - iter.remove(); - break; + // Add attachment to unsavedFiles + // check to see if file with same name exists + ChatAttachment currAtt; + Iterator iter = savedFiles.iterator(); + while (iter.hasNext()) { + currAtt = (ChatAttachment) iter.next(); + if (StringUtils.equals(currAtt.getFileName(), newAtt + .getFileName())) { + // move from this this list to deleted list. + getAttList(KEY_DELETED_FILES, map).add(currAtt); + iter.remove(); + break; + } } - } - unsavedFiles.add(newAtt); + unsavedFiles.add(newAtt); - request.setAttribute(ChatConstants.ATTR_SESSION_MAP, map); - request.setAttribute("unsavedChanges", new Boolean(true)); - + request.setAttribute(ChatConstants.ATTR_SESSION_MAP, map); + request.setAttribute("unsavedChanges", new Boolean(true)); + } return mapping.findForward("success"); } @@ -388,19 +393,20 @@ * Updates SessionMap using Chat content. * * @param chat - * @param mode + * @param mode */ - private SessionMap createSessionMap(Chat chat, ToolAccessMode mode) { - + private SessionMap createSessionMap(Chat chat, + ToolAccessMode mode) { + SessionMap map = new SessionMap(); - + map.put(KEY_MODE, mode); map.put(KEY_ONLINE_FILES, new LinkedList()); map.put(KEY_OFFLINE_FILES, new LinkedList()); map.put(KEY_UNSAVED_ONLINE_FILES, new LinkedList()); map.put(KEY_UNSAVED_OFFLINE_FILES, new LinkedList()); - map.put(KEY_DELETED_FILES, new LinkedList()); - + map.put(KEY_DELETED_FILES, new LinkedList()); + Iterator iter = chat.getChatAttachments().iterator(); while (iter.hasNext()) { ChatAttachment attachment = (ChatAttachment) iter.next(); @@ -412,7 +418,7 @@ getAttList(KEY_ONLINE_FILES, map).add(attachment); } } - + return map; } @@ -441,7 +447,8 @@ * @param map * @param request */ - private void initSessionMap(SessionMap map, HttpServletRequest request) { + private void initSessionMap(SessionMap map, + HttpServletRequest request) { map.put(KEY_MODE, getAccessMode(request)); map.put(KEY_ONLINE_FILES, new LinkedList()); map.put(KEY_OFFLINE_FILES, new LinkedList()); @@ -457,7 +464,8 @@ * @param map * @return */ - private List getAttList(String key, SessionMap map) { + private List getAttList(String key, + SessionMap map) { List list = (List) map.get(key); return list; } @@ -469,8 +477,8 @@ * @param authForm * @return */ - private SessionMap getSessionMap(HttpServletRequest request, - AuthoringForm authForm) { + private SessionMap getSessionMap( + HttpServletRequest request, AuthoringForm authForm) { return (SessionMap) request.getSession().getAttribute( authForm.getSessionMapID()); } Index: lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/web/actions/AuthoringAction.java =================================================================== diff -u -r6469a3c8ad3e545e2f1929947d3c46b040896632 -r021a7a0c1e8d0a0592047fa4b3840872d8bfbc05 --- lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/web/actions/AuthoringAction.java (.../AuthoringAction.java) (revision 6469a3c8ad3e545e2f1929947d3c46b040896632) +++ lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/web/actions/AuthoringAction.java (.../AuthoringAction.java) (revision 021a7a0c1e8d0a0592047fa4b3840872d8bfbc05) @@ -99,8 +99,9 @@ String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - ToolAccessMode mode = WebUtil.readToolAccessModeParam(request, "mode", true); - + ToolAccessMode mode = WebUtil.readToolAccessModeParam(request, "mode", + true); + // set up notebookService if (notebookService == null) { notebookService = NotebookServiceProxy.getNotebookService(this @@ -124,13 +125,14 @@ request).getMessage("error.content.locked")); return mapping.findForward("message_page"); } - - if (mode != null && mode.isTeacher() ) { - // Set the defineLater flag so that learners cannot use content while we + + if (mode != null && mode.isTeacher()) { + // Set the defineLater flag so that learners cannot use content + // while we // are editing. This flag is released when updateContent is called. notebook.setDefineLater(true); notebookService.saveOrUpdateNotebook(notebook); - } + } // Set up the authForm. AuthoringForm authForm = (AuthoringForm) form; @@ -261,28 +263,31 @@ savedFiles = getAttList(KEY_ONLINE_FILES, map); } - // upload file to repository - NotebookAttachment newAtt = notebookService.uploadFileToContent( - authForm.getToolContentID(), file, type); + if (file.getFileName().length() != 0) { - // Add attachment to unsavedFiles - // check to see if file with same name exists - NotebookAttachment currAtt; - Iterator iter = savedFiles.iterator(); - while (iter.hasNext()) { - currAtt = (NotebookAttachment) iter.next(); - if (StringUtils.equals(currAtt.getFileName(), newAtt.getFileName())) { - // move from this this list to deleted list. - getAttList(KEY_DELETED_FILES, map).add(currAtt); - iter.remove(); - break; + // upload file to repository + NotebookAttachment newAtt = notebookService.uploadFileToContent( + authForm.getToolContentID(), file, type); + + // Add attachment to unsavedFiles + // check to see if file with same name exists + NotebookAttachment currAtt; + Iterator iter = savedFiles.iterator(); + while (iter.hasNext()) { + currAtt = (NotebookAttachment) iter.next(); + if (StringUtils.equals(currAtt.getFileName(), newAtt + .getFileName())) { + // move from this this list to deleted list. + getAttList(KEY_DELETED_FILES, map).add(currAtt); + iter.remove(); + break; + } } - } - unsavedFiles.add(newAtt); + unsavedFiles.add(newAtt); - request.setAttribute(NotebookConstants.ATTR_SESSION_MAP, map); - request.setAttribute("unsavedChanges", new Boolean(true)); - + request.setAttribute(NotebookConstants.ATTR_SESSION_MAP, map); + request.setAttribute("unsavedChanges", new Boolean(true)); + } return mapping.findForward("success"); } Index: lams_tool_scribe/src/java/org/lamsfoundation/lams/tool/scribe/web/actions/AuthoringAction.java =================================================================== diff -u -r6469a3c8ad3e545e2f1929947d3c46b040896632 -r021a7a0c1e8d0a0592047fa4b3840872d8bfbc05 --- lams_tool_scribe/src/java/org/lamsfoundation/lams/tool/scribe/web/actions/AuthoringAction.java (.../AuthoringAction.java) (revision 6469a3c8ad3e545e2f1929947d3c46b040896632) +++ lams_tool_scribe/src/java/org/lamsfoundation/lams/tool/scribe/web/actions/AuthoringAction.java (.../AuthoringAction.java) (revision 021a7a0c1e8d0a0592047fa4b3840872d8bfbc05) @@ -111,16 +111,16 @@ String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - - ToolAccessMode mode = WebUtil.readToolAccessModeParam(request, "mode", true); - + + ToolAccessMode mode = WebUtil.readToolAccessModeParam(request, "mode", + true); + // set up scribeService if (scribeService == null) { scribeService = ScribeServiceProxy.getScribeService(this .getServlet().getServletContext()); } - - + // retrieving Scribe with given toolContentID Scribe scribe = scribeService.getScribeByContentId(toolContentID); if (scribe == null) { @@ -137,9 +137,10 @@ request).getMessage("error.content.locked")); return mapping.findForward("message_page"); } - + if (mode != null && mode.isTeacher()) { - // Set the defineLater flag so that learners cannot use content while we + // Set the defineLater flag so that learners cannot use content + // while we // are editing. This flag is released when updateContent is called. scribe.setDefineLater(true); scribeService.saveOrUpdateScribe(scribe); @@ -197,10 +198,10 @@ // update headings. List updatedHeadings = getHeadingList(map); Set currentHeadings = scribe.getScribeHeadings(); - currentHeadings.clear(); + currentHeadings.clear(); for (ScribeHeading heading : updatedHeadings) { heading.setUid(null); - currentHeadings.add(heading); + currentHeadings.add(heading); } // set the update date @@ -265,14 +266,15 @@ HttpServletResponse response) { String sessionMapID = WebUtil.readStrParam(request, "sessionMapID"); - Integer headingIndex = WebUtil.readIntParam(request, "headingIndex", true); + Integer headingIndex = WebUtil.readIntParam(request, "headingIndex", + true); AuthoringForm authForm = ((AuthoringForm) form); - + if (headingIndex == null) { headingIndex = -1; } - + authForm.setHeadingIndex(headingIndex); authForm.setSessionMapID(sessionMapID); @@ -295,7 +297,7 @@ if (headingIndex == -1) { // create a new heading List headings = getHeadingList(map); - + ScribeHeading scribeHeading = new ScribeHeading(headings.size()); scribeHeading.setScribe(scribe); scribeHeading.setHeadingText(headingText); @@ -304,70 +306,69 @@ } else { // update the existing heading ScribeHeading heading = getHeadingList(map).get(headingIndex); - heading.setHeadingText(headingText); + heading.setHeadingText(headingText); } request.setAttribute("sessionMapID", map.getSessionID()); return mapping.findForward("heading_response"); } - - public ActionForward moveHeading(ActionMapping mapping, - ActionForm form, HttpServletRequest request, - HttpServletResponse response) { - + + public ActionForward moveHeading(ActionMapping mapping, ActionForm form, + HttpServletRequest request, HttpServletResponse response) { + AuthoringForm authForm = (AuthoringForm) form; SessionMap map = getSessionMap(request, authForm); - + int headingIndex = WebUtil.readIntParam(request, "headingIndex"); String direction = WebUtil.readStrParam(request, "direction"); - - ListIterator iter = getHeadingList(map).listIterator(headingIndex); - + + ListIterator iter = getHeadingList(map).listIterator( + headingIndex); + ScribeHeading heading = iter.next(); iter.remove(); - + // move to correct location if (direction.equals("up")) { if (iter.hasPrevious()) - iter.previous(); + iter.previous(); } else if (direction.equals("down")) { if (iter.hasNext()) iter.next(); } else { // invalid direction, don't move anywhere. log.error("moveHeading: received invalid direction : " + direction); } - + // adding heading back into list - iter.add(heading); - + iter.add(heading); + // update the displayOrder int i = 0; - for(ScribeHeading elem : getHeadingList(map)) { + for (ScribeHeading elem : getHeadingList(map)) { elem.setDisplayOrder(i); i++; } - + request.setAttribute("sessionMapID", map.getSessionID()); return mapping.findForward("heading_response"); } - public ActionForward deleteHeading(ActionMapping mapping, - ActionForm form, HttpServletRequest request, - HttpServletResponse response) { - + public ActionForward deleteHeading(ActionMapping mapping, ActionForm form, + HttpServletRequest request, HttpServletResponse response) { + AuthoringForm authForm = (AuthoringForm) form; SessionMap map = getSessionMap(request, authForm); - + Integer headingIndex = authForm.getHeadingIndex(); - - getHeadingList(map).remove(headingIndex.intValue()); - + + getHeadingList(map).remove(headingIndex.intValue()); + request.setAttribute("sessionMapID", map.getSessionID()); return mapping.findForward("heading_response"); - + } - + /* ========== Private Methods ********** */ private ActionForward uploadFile(ActionMapping mapping, @@ -389,28 +390,32 @@ savedFiles = getAttList(KEY_ONLINE_FILES, map); } - // upload file to repository - ScribeAttachment newAtt = scribeService.uploadFileToContent((Long) map - .get(KEY_TOOL_CONTENT_ID), file, type); + if (file.getFileName().length() != 0) { - // Add attachment to unsavedFiles - // check to see if file with same name exists - ScribeAttachment currAtt; - Iterator iter = savedFiles.iterator(); - while (iter.hasNext()) { - currAtt = (ScribeAttachment) iter.next(); - if (StringUtils.equals(currAtt.getFileName(), newAtt.getFileName())) { - // move from this this list to deleted list. - getAttList(KEY_DELETED_FILES, map).add(currAtt); - iter.remove(); - break; + // upload file to repository + ScribeAttachment newAtt = scribeService.uploadFileToContent( + (Long) map.get(KEY_TOOL_CONTENT_ID), file, type); + + // Add attachment to unsavedFiles + // check to see if file with same name exists + ScribeAttachment currAtt; + Iterator iter = savedFiles.iterator(); + while (iter.hasNext()) { + currAtt = (ScribeAttachment) iter.next(); + if (StringUtils.equals(currAtt.getFileName(), newAtt + .getFileName())) { + // move from this this list to deleted list. + getAttList(KEY_DELETED_FILES, map).add(currAtt); + iter.remove(); + break; + } } + unsavedFiles.add(newAtt); + + request.setAttribute(ScribeConstants.ATTR_SESSION_MAP, map); + request.setAttribute("unsavedChanges", new Boolean(true)); } - unsavedFiles.add(newAtt); - request.setAttribute(ScribeConstants.ATTR_SESSION_MAP, map); - request.setAttribute("unsavedChanges", new Boolean(true)); - return mapping.findForward("success"); } @@ -545,14 +550,14 @@ getAttList(KEY_ONLINE_FILES, map).add(attachment); } } - + // adding headings iter = scribe.getScribeHeadings().iterator(); while (iter.hasNext()) { ScribeHeading element = (ScribeHeading) iter.next(); getHeadingList(map).add(element); } - + // sorting headings according to displayOrder. Collections.sort(getHeadingList(map));