Index: lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/util/NbMonitoringUtil.java =================================================================== diff -u -rc3062d66c22c0b36918ec54e995c4c8fa9081dc0 -r1fa952a7d56855ca8d295d038150661f0b8f9b93 --- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/util/NbMonitoringUtil.java (.../NbMonitoringUtil.java) (revision c3062d66c22c0b36918ec54e995c4c8fa9081dc0) +++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/util/NbMonitoringUtil.java (.../NbMonitoringUtil.java) (revision 1fa952a7d56855ca8d295d038150661f0b8f9b93) @@ -22,7 +22,10 @@ package org.lamsfoundation.lams.tool.noticeboard.util; import javax.servlet.http.HttpServletRequest; + +import org.lamsfoundation.lams.tool.noticeboard.NbApplicationException; import org.lamsfoundation.lams.tool.noticeboard.NoticeboardConstants; +import org.lamsfoundation.lams.tool.noticeboard.NoticeboardContent; /** * @author mtruong @@ -41,4 +44,40 @@ request.getSession().removeAttribute(NoticeboardConstants.ONLINE_INSTRUCTIONS); request.getSession().removeAttribute(NoticeboardConstants.CONTENT_IN_USE); } + + /** + *

This method checks the two tool content flags, defineLater and contentInUse + * to determine whether the tool content is modifiable or not. Returns true is content is + * modifiable and false otherwise + *
Tool content is modifiable if: + *

  • defineLater is set to true
  • + *
  • defineLater is set to false and contentInUse is set to false
  • + *
    Tool content is not modifiable if: + *
  • contentInUse is set to true
  • + * @param content The instance of NoticeboardContent to check + * @return true if content is modifiable and false otherwise + * @throws NbApplicationException + */ + public static boolean isContentEditable(NoticeboardContent content) throws NbApplicationException + { + if ( (content.isDefineLater() == true) && (content.isContentInUse()==true) ) + { + throw new NbApplicationException("An exception has occurred: There is a bug in this tool, conflicting flags are set"); + //return false; + } + else if ( (content.isDefineLater() == true) && (content.isContentInUse() == false)) + return true; + else if ( (content.isDefineLater() == false) && (content.isContentInUse() == false)) + return true; + else // (content.isContentInUse()==true && content.isDefineLater() == false) + return false; + } + + 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()); + } } Index: lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbAuthoringStarterAction.java =================================================================== diff -u -r3f27eea9deb1424106b5397c4559d3f609416399 -r1fa952a7d56855ca8d295d038150661f0b8f9b93 --- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbAuthoringStarterAction.java (.../NbAuthoringStarterAction.java) (revision 3f27eea9deb1424106b5397c4559d3f609416399) +++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbAuthoringStarterAction.java (.../NbAuthoringStarterAction.java) (revision 1fa952a7d56855ca8d295d038150661f0b8f9b93) @@ -48,9 +48,12 @@ import org.lamsfoundation.lams.tool.noticeboard.NbApplicationException; import org.lamsfoundation.lams.util.WebUtil; +import org.lamsfoundation.lams.tool.noticeboard.util.NbMonitoringUtil; +/**TODO: change into one utility class */ +import org.apache.struts.action.ActionMessages; +import org.apache.struts.action.ActionMessage; - /** * Creation Date: 19-05-05 * @@ -59,6 +62,7 @@ * @struts:action path="/tool/nb/starter/authoring" name="NbAuthoringForm" scope="session" type="org.lamsfoundation.lams.tool.noticeboard.web.NbAuthoringStarterAction" * input=".authoringStarter" validate="false" * @struts:action-forward name="basic" path=".nb_basic" + * @struts:action-forward name="displayMessage" path=".message" * ----------------XDoclet Tags-------------------- */ @@ -67,7 +71,7 @@ static Logger logger = Logger.getLogger(NbAuthoringAction.class.getName()); /** - * This struts action class gets called when the author double clicks + * This struts actionservlet gets called when the author double clicks * on the tool icon. If the toolContentId already exists in the tool content * table, the content is then extracted from the content table and is displayed. * Otherwise, if the toolContentId does not exist in the content table, a new @@ -83,8 +87,9 @@ NbAuthoringForm nbForm = (NbAuthoringForm)form; - // Long contentId = NbAuthoringUtil.convertToLong(request.getParameter(NoticeboardConstants.TOOL_CONTENT_ID)); - Long contentId = NbAuthoringUtil.convertToLong(nbForm.getToolContentId()); + Long contentId = NbAuthoringUtil.convertToLong(request.getParameter(NoticeboardConstants.TOOL_CONTENT_ID)); + nbForm.setToolContentId(contentId.toString()); + // Long contentId = NbAuthoringUtil.convertToLong(nbForm.getToolContentId()); if(contentId == null) { String error = "Tool content id missing. Unable to continue."; @@ -113,6 +118,8 @@ nb.getOfflineInstructions(), new Date(System.currentTimeMillis())); + nbContentNew.setDefineLater(true); //the author would currently be editing this content, so set defineLater to true so students cant access activity + //save new tool content into db nbService.saveNoticeboard(nbContentNew); @@ -121,13 +128,34 @@ } - else + else //content already exists on the database { //get the values from the database NoticeboardContent nb = nbService.retrieveNoticeboard(contentId); - nbForm.populateFormWithNbContentValues(nb); + /* If retrieving existing content, check whether the contentInUse flag is set, if set, the + * author is not allowed to edit content + */ + if (NbMonitoringUtil.isContentEditable(nb)) + { + /* 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.setDefineLater(true); + nbService.updateNoticeboard(nb); + } + else + { + //The contentInUse flag is set and a user has already reached this activity. + saveMessages(request, null); //ensure there are no existing messages + ActionMessages message = new ActionMessages(); + message.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("message.contentInUseSet")); + saveMessages(request, message); + return mapping.findForward(NoticeboardConstants.DISPLAY_MESSAGE); + + } + } Index: lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbLearnerStarterAction.java =================================================================== diff -u -r621d1c50c0bb02aa8221ca1ecfe7850b948f13d8 -r1fa952a7d56855ca8d295d038150661f0b8f9b93 --- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbLearnerStarterAction.java (.../NbLearnerStarterAction.java) (revision 621d1c50c0bb02aa8221ca1ecfe7850b948f13d8) +++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbLearnerStarterAction.java (.../NbLearnerStarterAction.java) (revision 1fa952a7d56855ca8d295d038150661f0b8f9b93) @@ -118,7 +118,7 @@ { /* Set the ContentInUse flag to true, and defineLater flag to false */ nbContent.setContentInUse(true); - nbContent.setDefineLater(false); + // nbContent.setDefineLater(false); /* defineLater should be false anyway */ nbService.updateNoticeboard(nbContent); if (nbSession != null)