Index: lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbLearnerAction.java =================================================================== diff -u --- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbLearnerAction.java (revision 0) +++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbLearnerAction.java (revision 66acb270990a4bff8eae2f48a20cd6aef44f06e3) @@ -0,0 +1,116 @@ +/* + *Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * + *This program is free software; you can redistribute it and/or modify + *it under the terms of the GNU General Public License as published by + *the Free Software Foundation; either version 2 of the License, or + *(at your option) any later version. + * + *This program is distributed in the hope that it will be useful, + *but WITHOUT ANY WARRANTY; without even the implied warranty of + *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + *GNU General Public License for more details. + * + *You should have received a copy of the GNU General Public License + *along with this program; if not, write to the Free Software + *Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + *USA + * + *http://www.gnu.org/licenses/gpl.txt + */ + + + +/* + * Created on Jun 29, 2005 + * + */ +package org.lamsfoundation.lams.tool.noticeboard.web; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.apache.struts.actions.LookupDispatchAction; +import org.apache.log4j.Logger; + + +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionForward; +import org.apache.struts.action.ActionMapping; +import org.lamsfoundation.lams.tool.noticeboard.NbApplicationException; +import org.lamsfoundation.lams.tool.noticeboard.NoticeboardConstants; +import org.lamsfoundation.lams.tool.noticeboard.service.INoticeboardService; +import org.lamsfoundation.lams.tool.noticeboard.service.NoticeboardServiceProxy; +import org.lamsfoundation.lams.tool.noticeboard.NoticeboardSession; +import org.lamsfoundation.lams.tool.noticeboard.NoticeboardUser; +import org.lamsfoundation.lams.learning.service.ILearnerService; +import org.lamsfoundation.lams.learning.service.LearnerServiceProxy; +import org.lamsfoundation.lams.usermanagement.User; + + +/** + * Creation Date: 29-06-05 + * + * ----------------XDoclet Tags-------------------- + * + * @struts:action path="/tool/nb/learner" name="NbLearnerForm" scope="session" type="org.lamsfoundation.lams.tool.noticeboard.web.NbLearnerAction" + * input=".learnerContent" validate="false" parameter="method" + * @struts:action-forward name="displayLearnerContent" path=".learnerContent" + * ----------------XDoclet Tags-------------------- + */ +public class NbLearnerAction extends LookupDispatchAction { + + static Logger logger = Logger.getLogger(NbLearnerAction.class.getName()); + + protected Map getKeyMethodMap() + { + Map map = new HashMap(); + map.put(NoticeboardConstants.BUTTON_FINISH, "finish"); + return map; + } + + /** + * Indicates that the user has finished viewing the noticeboard. + * The session is set to complete and leaveToolSession is called. + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + public ActionForward finish(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { + + NbLearnerForm learnerForm = (NbLearnerForm)form; + Long toolSessionID = learnerForm.getToolSessionID(); + Long userID = learnerForm.getUserID(); + INoticeboardService nbService = NoticeboardServiceProxy.getNbService(getServlet().getServletContext()); + /** TODO: learnerServiceProxy causes an exception, fix this up later */ + // ILearnerService learnerService = LearnerServiceProxy.getLearnerService(getServlet().getServletContext()); + + if (learnerForm.getMode().equals(NoticeboardConstants.TOOL_ACCESS_MODE_LEARNER)) + { + NoticeboardSession nbSession = nbService.retrieveNoticeboardSession(toolSessionID); + NoticeboardUser nbUser = nbService.retrieveNoticeboardUser(userID); + //do not set session status to complete, as it might be a grouping activity and so you dont know when all the users are finished or not + //nbSession.setSessionStatus(NoticeboardSession.COMPLETED); + //nbSession.setSessionEndDate(new Date(System.currentTimeMillis())); + nbUser.setUserStatus(NoticeboardUser.COMPLETED); + nbService.updateNoticeboardSession(nbSession); + nbService.updateNoticeboardUser(nbUser); + + //Notify the progress engine of the user's completion + User user = new User(); + user.setUserId(new Integer(learnerForm.getUserID().toString())); + /** TODO: cannot use this yet as learnerservice causes an exception, fix this up later */ + // learnerService.completeToolSession(learnerForm.getToolSessionID(), user); + + } + request.getSession().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 =================================================================== diff -u --- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbLearnerForm.java (revision 0) +++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbLearnerForm.java (revision 66acb270990a4bff8eae2f48a20cd6aef44f06e3) @@ -0,0 +1,162 @@ +/* + *Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * + *This program is free software; you can redistribute it and/or modify + *it under the terms of the GNU General Public License as published by + *the Free Software Foundation; either version 2 of the License, or + *(at your option) any later version. + * + *This program is distributed in the hope that it will be useful, + *but WITHOUT ANY WARRANTY; without even the implied warranty of + *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + *GNU General Public License for more details. + * + *You should have received a copy of the GNU General Public License + *along with this program; if not, write to the Free Software + *Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + *USA + * + *http://www.gnu.org/licenses/gpl.txt + */ + +/* + * Created on Jun 27, 2005 + */ + + +package org.lamsfoundation.lams.tool.noticeboard.web; + +import org.apache.log4j.Logger; +import org.apache.struts.action.ActionForm; +import org.lamsfoundation.lams.tool.noticeboard.NoticeboardContent; + +/** + * Creation Date: 19-05-05 + * + * ----------------XDoclet Tags-------------------- + * + * @struts:form name="NbLearnerForm" type="org.lamsfoundation.lams.tool.noticeboard.web.NbLearnerForm" + * + * ----------------XDoclet Tags-------------------- + */ + +public class NbLearnerForm extends ActionForm{ + + static Logger logger = Logger.getLogger(NbLearnerForm.class.getName()); + + private String title; + + private String content; + + private Long userID; + + private Long toolSessionID; + + private Long toolContentID; + + private String method; + + private String mode; + + + + /** + * @return Returns the toolContentID. + */ + public Long getToolContentID() { + return toolContentID; + } + /** + * @param toolContentID The toolContentID to set. + */ + public void setToolContentID(Long toolContentID) { + this.toolContentID = toolContentID; + } + /** + * @return Returns the toolSessionID. + */ + public Long getToolSessionID() { + return toolSessionID; + } + /** + * @param toolSessionID The toolSessionID to set. + */ + public void setToolSessionID(Long toolSessionID) { + this.toolSessionID = toolSessionID; + } + /** + * @return Returns the userID. + */ + public Long getUserID() { + return userID; + } + /** + * @param userID The userID to set. + */ + public void setUserID(Long userID) { + this.userID = userID; + } + /** + * @return Returns the content. + */ + public String getContent() { + return content; + } + /** + * @param content The content to set. + */ + public void setContent(String content) { + this.content = content; + } + /** + * @return Returns the title. + */ + public String getTitle() { + return title; + } + /** + * @param title The title to set. + */ + public void setTitle(String title) { + this.title = title; + } + + /** + * @return Returns the method. + */ + public String getMethod() { + return method; + } + /** + * @param method The method to set. + */ + public void setMethod(String method) { + this.method = method; + } + + public void reset() + { + this.content = null; + this.title = null; + + } + + public void copyValuesIntoForm(NoticeboardContent content) + { + setTitle(content.getTitle()); + setContent(content.getContent()); + } + + /** + * @return Returns the mode. + */ + public String getMode() { + return mode; + } + /** + * @param mode The mode to set. + */ + public void setMode(String mode) { + this.mode = mode; + } +} Index: lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbLearnerStarterAction.java =================================================================== diff -u --- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbLearnerStarterAction.java (revision 0) +++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbLearnerStarterAction.java (revision 66acb270990a4bff8eae2f48a20cd6aef44f06e3) @@ -0,0 +1,274 @@ +/* + *Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * + *This program is free software; you can redistribute it and/or modify + *it under the terms of the GNU General Public License as published by + *the Free Software Foundation; either version 2 of the License, or + *(at your option) any later version. + * + *This program is distributed in the hope that it will be useful, + *but WITHOUT ANY WARRANTY; without even the implied warranty of + *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + *GNU General Public License for more details. + * + *You should have received a copy of the GNU General Public License + *along with this program; if not, write to the Free Software + *Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + *USA + * + *http://www.gnu.org/licenses/gpl.txt + */ + +/* + * Created on Jun 27, 2005 + * + */ + +/** + * TODO: internationalisation of error messages. + */ + +package org.lamsfoundation.lams.tool.noticeboard.web; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; +import org.apache.struts.actions.DispatchAction; +import org.apache.struts.action.Action; +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionForward; +import org.apache.struts.action.ActionMapping; +import org.lamsfoundation.lams.tool.noticeboard.NbApplicationException; + +import org.lamsfoundation.lams.tool.noticeboard.NoticeboardConstants; +import org.lamsfoundation.lams.tool.noticeboard.NoticeboardSession; +import org.lamsfoundation.lams.tool.noticeboard.NoticeboardContent; +import org.lamsfoundation.lams.tool.noticeboard.NoticeboardUser; +import org.lamsfoundation.lams.tool.noticeboard.service.INoticeboardService; +import org.lamsfoundation.lams.tool.noticeboard.service.NoticeboardServiceProxy; +import org.lamsfoundation.lams.tool.noticeboard.web.NbLearnerForm; + +import org.lamsfoundation.lams.tool.noticeboard.util.NbLearnerUtil; +import org.lamsfoundation.lams.util.WebUtil; +import org.apache.struts.util.MessageResources; +import org.lamsfoundation.lams.tool.ToolAccessMode; +import org.apache.struts.action.ActionMessages; +import org.apache.struts.action.ActionMessage; +/** + * Creation Date: 27-06-05 + * + * ----------------XDoclet Tags-------------------- + * + * @struts:action path="/tool/nb/starter/learner" name="NbLearnerForm" scope="session" type="org.lamsfoundation.lams.tool.noticeboard.web.NbLearnerStarterAction" + * input=".learnerStarter" validate="false" parameter="mode" + * @struts:action-forward name="displayLearnerContent" path=".learnerContent" + * @struts:action-forward name="displayMessage" path=".message" + * ----------------XDoclet Tags-------------------- + */ + +public class NbLearnerStarterAction extends DispatchAction { + + static Logger logger = Logger.getLogger(NbLearnerStarterAction.class.getName()); + + + public ActionForward learner(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws NbApplicationException { + + NoticeboardContent nbContent = null; + NoticeboardSession nbSession = null; + NoticeboardUser nbUser = null; + NbLearnerUtil.cleanSession(request); + saveMessages(request, null); + + NbLearnerForm learnerForm = (NbLearnerForm)form; + + ActionMessages message = new ActionMessages(); + INoticeboardService nbService = NoticeboardServiceProxy.getNbService(getServlet().getServletContext()); + + Long userId = learnerForm.getUserID(); + Long toolSessionId = learnerForm.getToolSessionID(); + Long toolContentId = learnerForm.getToolContentID(); + + if(userId == null || toolSessionId ==null || toolContentId==null) + { + String error = "userId, tool session id or tool content id is missing. Unable to continue"; + log.error(error); + throw new NbApplicationException(error); + } + + nbContent = nbService.retrieveNoticeboard(toolContentId); + nbSession = nbService.retrieveNoticeboardSession(toolSessionId); + nbUser = nbService.retrieveNoticeboardUser(userId); + /* + * Checks to see if the defineLater or runOffline flag is set. + * If the particular flag is set, control is forwarded to jsp page + * displaying to the user the message according to what flag is set. + */ + if (displayMessageToUser(nbContent, message)) + { + saveMessages(request, message); + return mapping.findForward(NoticeboardConstants.DISPLAY_MESSAGE); + } + if (learnerForm.getMode().equals(NoticeboardConstants.TOOL_ACCESS_MODE_LEARNER)) + { + /* Set the ContentInUse flag to true, and defineLater flag to false */ + nbContent.setContentInUse(true); + nbContent.setDefineLater(false); + nbService.updateNoticeboard(nbContent); + + if (nbSession != null) + { + if (nbUser != null) + { + //check user status, if completed, set session attribue readOnlyMode to true + //copy values into content, then thats it + if (nbUser.getUserStatus().equals(NoticeboardUser.COMPLETED)) + request.getSession().setAttribute(NoticeboardConstants.READ_ONLY_MODE, "true"); + + } + else //user is new + { + NoticeboardUser newUser = new NoticeboardUser(userId); + nbService.addUser(toolSessionId, newUser); + } + + + } + else + { + NoticeboardSession newSession = new NoticeboardSession(toolSessionId); + nbService.addSession(toolContentId, newSession); + NoticeboardUser newUser = new NoticeboardUser(userId); + nbService.addUser(toolSessionId, newUser); + + } + } + learnerForm.copyValuesIntoForm(nbContent); + return mapping.findForward(NoticeboardConstants.DISPLAY_LEARNER_CONTENT); + + } + + public ActionForward teacher(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws NbApplicationException { + return learner(mapping, form, request, response); + //return mapping.findForward(NoticeboardConstants.DISPLAY_LEARNER_CONTENT); + } + + public ActionForward author(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws NbApplicationException { + + /* will show a different screen if defineLater flag is set and running in preview mode */ + NbLearnerForm nbForm = (NbLearnerForm)form; + NbLearnerUtil.cleanSession(request); + Long toolContentId = nbForm.getToolContentID(); + saveMessages(request, null); + + ActionMessages message = new ActionMessages(); + INoticeboardService nbService = NoticeboardServiceProxy.getNbService(getServlet().getServletContext()); + NoticeboardContent nbContent = nbService.retrieveNoticeboard(toolContentId); + + if (displayMessageToAuthor(nbContent, message)) + { + saveMessages(request, message); + return mapping.findForward(NoticeboardConstants.DISPLAY_MESSAGE); + } + + + nbForm.copyValuesIntoForm(nbContent); + return mapping.findForward(NoticeboardConstants.DISPLAY_LEARNER_CONTENT); + } + + + + + /** + *

Performs a check on the flag indicated by flag + * In this noticeboard tool, there are 3 possible flags: + *

  • defineLater
  • + *
  • contentInUse
  • + *
  • runOffline
  • + *
    Returns true if the flag is set, false otherwise

    + * + * @param content The instance of NoticeboardContent + * @param flag The flag to check, can take the following set of values (defineLater, contentInUse, runOffline) + * @return Returns true if flag is set, false otherwise + */ + private boolean isFlagSet(NoticeboardContent content, int flag) throws NbApplicationException + { + switch (flag) + { + case NoticeboardConstants.FLAG_DEFINE_LATER: + return (content.isDefineLater()); + // break; + case NoticeboardConstants.FLAG_CONTENT_IN_USE: + return (content.isContentInUse()); + // break; + case NoticeboardConstants.FLAG_RUN_OFFLINE: + return(content.isForceOffline()); + // break; + default: + throw new NbApplicationException("Invalid flag"); + } + + } + + /** + *

    This methods checks the defineLater and runOffline flag. + * If defineLater flag is set, then a message is added to an ActionMessages + * object saying that the contents have not been defined yet. If the runOffline + * flag is set, a message is added to ActionMessages saying that the contents + * are not being run online. + * This method will return true if any one of the defineLater or runOffline flag is set. + * Otherwise false will be returned.

    + * + * @param content The instance of NoticeboardContent + * @param message the instance of ActtionMessages + * @return true if any of the flags are set, false otherwise + */ + private boolean displayMessageToUser(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.defineLaterSet")); + } + if (isRunOfflineSet) + { + message.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("message.runOfflineSet")); + } + return true; + } + else + 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