Index: lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/web/actions/LearningAction.java
===================================================================
diff -u -r7817bc4fce30416c9737875ae2d137be0c6aa8ba -r1db6d7173ac57f97493f84da903508f6a7c41918
--- lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/web/actions/LearningAction.java (.../LearningAction.java) (revision 7817bc4fce30416c9737875ae2d137be0c6aa8ba)
+++ lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/web/actions/LearningAction.java (.../LearningAction.java) (revision 1db6d7173ac57f97493f84da903508f6a7c41918)
@@ -44,7 +44,6 @@
import org.lamsfoundation.lams.tool.exception.DataMissingException;
import org.lamsfoundation.lams.tool.exception.ToolException;
import org.lamsfoundation.lams.tool.notebook.dto.NotebookDTO;
-import org.lamsfoundation.lams.tool.notebook.dto.NotebookUserDTO;
import org.lamsfoundation.lams.tool.notebook.model.Notebook;
import org.lamsfoundation.lams.tool.notebook.model.NotebookSession;
import org.lamsfoundation.lams.tool.notebook.model.NotebookUser;
@@ -64,197 +63,174 @@
* @author
* @version
*
- * @struts.action path="/learning" parameter="dispatch" scope="request"
- * name="learningForm"
+ * @struts.action path="/learning" parameter="dispatch" scope="request" name="learningForm"
* @struts.action-forward name="notebook" path="tiles:/learning/main"
* @struts.action-forward name="runOffline" path="tiles:/learning/runOffline"
* @struts.action-forward name="defineLater" path="tiles:/learning/defineLater"
*/
public class LearningAction extends LamsDispatchAction {
- private static Logger log = Logger.getLogger(LearningAction.class);
+ private static Logger log = Logger.getLogger(LearningAction.class);
- private static final boolean MODE_OPTIONAL = false;
+ private static final boolean MODE_OPTIONAL = false;
- private INotebookService notebookService;
+ private INotebookService notebookService;
- public ActionForward unspecified(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response)
- throws Exception {
+ @Override
+ public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws Exception {
- LearningForm learningForm = (LearningForm) form;
+ LearningForm learningForm = (LearningForm) form;
- // 'toolSessionID' and 'mode' paramters are expected to be present.
- // TODO need to catch exceptions and handle errors.
- ToolAccessMode mode = WebUtil.readToolAccessModeParam(request,
- AttributeNames.PARAM_MODE, MODE_OPTIONAL);
+ // 'toolSessionID' and 'mode' paramters are expected to be present.
+ // TODO need to catch exceptions and handle errors.
+ ToolAccessMode mode = WebUtil.readToolAccessModeParam(request, AttributeNames.PARAM_MODE,
+ LearningAction.MODE_OPTIONAL);
- Long toolSessionID = WebUtil.readLongParam(request,
- AttributeNames.PARAM_TOOL_SESSION_ID);
+ Long toolSessionID = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_SESSION_ID);
- // set up notebookService
- if (notebookService == null) {
- notebookService = NotebookServiceProxy.getNotebookService(this
- .getServlet().getServletContext());
- }
+ // set up notebookService
+ if (notebookService == null) {
+ notebookService = NotebookServiceProxy.getNotebookService(this.getServlet().getServletContext());
+ }
- // Retrieve the session and content.
- NotebookSession notebookSession = notebookService
- .getSessionBySessionId(toolSessionID);
- if (notebookSession == null) {
- throw new NotebookException(
- "Cannot retrieve session with toolSessionID"
- + toolSessionID);
- }
+ // Retrieve the session and content.
+ NotebookSession notebookSession = notebookService.getSessionBySessionId(toolSessionID);
+ if (notebookSession == null) {
+ throw new NotebookException("Cannot retrieve session with toolSessionID" + toolSessionID);
+ }
- Notebook notebook = notebookSession.getNotebook();
+ Notebook notebook = notebookSession.getNotebook();
- // check defineLater
- if (notebook.isDefineLater()) {
- return mapping.findForward("defineLater");
- }
+ // check defineLater
+ if (notebook.isDefineLater()) {
+ return mapping.findForward("defineLater");
+ }
- // set mode, toolSessionID and NotebookDTO
- request.setAttribute("mode", mode.toString());
- learningForm.setToolSessionID(toolSessionID);
+ // set mode, toolSessionID and NotebookDTO
+ request.setAttribute("mode", mode.toString());
+ learningForm.setToolSessionID(toolSessionID);
- NotebookDTO notebookDTO = new NotebookDTO();
- notebookDTO.title = notebook.getTitle();
- notebookDTO.instructions = notebook.getInstructions();
- notebookDTO.allowRichEditor = notebook.isAllowRichEditor();
- notebookDTO.lockOnFinish = notebook.isLockOnFinished();
-
- request.setAttribute("notebookDTO", notebookDTO);
+ NotebookDTO notebookDTO = new NotebookDTO();
+ notebookDTO.title = notebook.getTitle();
+ notebookDTO.instructions = notebook.getInstructions();
+ notebookDTO.allowRichEditor = notebook.isAllowRichEditor();
+ notebookDTO.lockOnFinish = notebook.isLockOnFinished();
- // Set the content in use flag.
- if (!notebook.isContentInUse()) {
- notebook.setContentInUse(new Boolean(true));
- notebookService.saveOrUpdateNotebook(notebook);
- }
-
- LearningWebUtil.putActivityPositionInRequestByToolSessionId(toolSessionID, request, getServlet()
- .getServletContext());
-
- // check runOffline
- if (notebook.isRunOffline()) {
- return mapping.findForward("runOffline");
- }
-
- NotebookUser notebookUser;
- if (mode.equals(ToolAccessMode.TEACHER)) {
- Long userID = WebUtil.readLongParam(request, AttributeNames.PARAM_USER_ID, false);
- notebookUser = notebookService.getUserByUserIdAndSessionId(userID, toolSessionID);
- } else {
- notebookUser = getCurrentUser(toolSessionID);
- }
-
- // get any existing notebook entry
- NotebookEntry nbEntry = null;
- if ( notebookUser != null ) {
- nbEntry = notebookService.getEntry(notebookUser.getEntryUID());
- }
- if (nbEntry != null) {
- learningForm.setEntryText(nbEntry.getEntry());
- }
-
- // set readOnly flag.
- if (mode.equals(ToolAccessMode.TEACHER) || (notebook.isLockOnFinished() && notebookUser.isFinishedActivity())) {
- request.setAttribute("contentEditable", false);
- } else {
- request.setAttribute("contentEditable", true);
- }
- request.setAttribute("finishedActivity", notebookUser.isFinishedActivity());
-
- request.setAttribute(AttributeNames.ATTR_LEARNER_CONTENT_FOLDER,
- notebookService.getLearnerContentFolder(toolSessionID, notebookUser.getUserId()));
-
- // date and time restriction LDEV-2657
- Date submissionDeadline = notebook.getSubmissionDeadline();
- if (submissionDeadline != null) {
- HttpSession ss = SessionManager.getSession();
- UserDTO learnerDto = (UserDTO) ss.getAttribute(AttributeNames.USER);
- TimeZone learnerTimeZone = learnerDto.getTimeZone();
- Date tzSubmissionDeadline = DateUtil.convertToTimeZoneFromDefault(learnerTimeZone, submissionDeadline);
- Date currentLearnerDate = DateUtil.convertToTimeZoneFromDefault(learnerTimeZone, new Date());
- notebookDTO.submissionDeadline = tzSubmissionDeadline;
+ request.setAttribute("notebookDTO", notebookDTO);
- //calculate whether deadline has passed, and if so forward to "runOffline"
- if (currentLearnerDate.after(tzSubmissionDeadline)) {
- return mapping.findForward("runOffline");
- }
- }
+ // Set the content in use flag.
+ if (!notebook.isContentInUse()) {
+ notebook.setContentInUse(new Boolean(true));
+ notebookService.saveOrUpdateNotebook(notebook);
+ }
+ LearningWebUtil.putActivityPositionInRequestByToolSessionId(toolSessionID, request, getServlet()
+ .getServletContext());
- return mapping.findForward("notebook");
+ // check runOffline
+ if (notebook.isRunOffline()) {
+ return mapping.findForward("runOffline");
}
- private NotebookUser getCurrentUser(Long toolSessionId) {
- UserDTO user = (UserDTO) SessionManager.getSession().getAttribute(
- AttributeNames.USER);
+ NotebookUser notebookUser;
+ if (mode.equals(ToolAccessMode.TEACHER)) {
+ Long userID = WebUtil.readLongParam(request, AttributeNames.PARAM_USER_ID, false);
+ notebookUser = notebookService.getUserByUserIdAndSessionId(userID, toolSessionID);
+ } else {
+ notebookUser = getCurrentUser(toolSessionID);
+ }
- // attempt to retrieve user using userId and toolSessionId
- NotebookUser notebookUser = notebookService
- .getUserByUserIdAndSessionId(new Long(user.getUserID()
- .intValue()), toolSessionId);
+ // get any existing notebook entry
+ NotebookEntry nbEntry = null;
+ if (notebookUser != null) {
+ nbEntry = notebookService.getEntry(notebookUser.getEntryUID());
+ }
+ if (nbEntry != null) {
+ learningForm.setEntryText(nbEntry.getEntry());
+ }
- if (notebookUser == null) {
- NotebookSession notebookSession = notebookService
- .getSessionBySessionId(toolSessionId);
- notebookUser = notebookService.createNotebookUser(user,
- notebookSession);
- }
-
- return notebookUser;
+ // set readOnly flag.
+ if (mode.equals(ToolAccessMode.TEACHER) || (notebook.isLockOnFinished() && notebookUser.isFinishedActivity())) {
+ request.setAttribute("contentEditable", false);
+ } else {
+ request.setAttribute("contentEditable", true);
}
+ request.setAttribute("finishedActivity", notebookUser.isFinishedActivity());
- public ActionForward finishActivity(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
+ request.setAttribute(AttributeNames.ATTR_LEARNER_CONTENT_FOLDER,
+ notebookService.getLearnerContentFolder(toolSessionID, notebookUser.getUserId()));
- Long toolSessionID = WebUtil.readLongParam(request, "toolSessionID");
+ // date and time restriction LDEV-2657
+ Date submissionDeadline = notebook.getSubmissionDeadline();
+ if (submissionDeadline != null) {
+ HttpSession ss = SessionManager.getSession();
+ UserDTO learnerDto = (UserDTO) ss.getAttribute(AttributeNames.USER);
+ TimeZone learnerTimeZone = learnerDto.getTimeZone();
+ Date tzSubmissionDeadline = DateUtil.convertToTimeZoneFromDefault(learnerTimeZone, submissionDeadline);
+ Date currentLearnerDate = DateUtil.convertToTimeZoneFromDefault(learnerTimeZone, new Date());
+ notebookDTO.submissionDeadline = tzSubmissionDeadline;
- NotebookUser notebookUser = getCurrentUser(toolSessionID);
+ // calculate whether deadline has passed, and if so forward to "runOffline"
+ if (currentLearnerDate.after(tzSubmissionDeadline)) {
+ return mapping.findForward("runOffline");
+ }
+ }
- if (notebookUser != null) {
+ return mapping.findForward("notebook");
+ }
- LearningForm learningForm = (LearningForm) form;
+ private NotebookUser getCurrentUser(Long toolSessionId) {
+ UserDTO user = (UserDTO) SessionManager.getSession().getAttribute(AttributeNames.USER);
- // TODO fix idType to use real value not 999
+ // attempt to retrieve user using userId and toolSessionId
+ NotebookUser notebookUser = notebookService.getUserByUserIdAndSessionId(new Long(user.getUserID().intValue()),
+ toolSessionId);
- if (notebookUser.getEntryUID() == null) {
- notebookUser.setEntryUID(notebookService.createNotebookEntry(
- toolSessionID, CoreNotebookConstants.NOTEBOOK_TOOL, NotebookConstants.TOOL_SIGNATURE,
- notebookUser.getUserId().intValue(), learningForm
- .getEntryText()));
- } else {
- // update existing entry.
- notebookService.updateEntry(notebookUser.getEntryUID(),
- learningForm.getEntryText());
- }
+ if (notebookUser == null) {
+ NotebookSession notebookSession = notebookService.getSessionBySessionId(toolSessionId);
+ notebookUser = notebookService.createNotebookUser(user, notebookSession);
+ }
- notebookUser.setFinishedActivity(true);
- notebookService.saveOrUpdateNotebookUser(notebookUser);
- } else {
- log.error("finishActivity(): couldn't find NotebookUser with id: "
- + notebookUser.getUserId() + "and toolSessionID: "
- + toolSessionID);
- }
+ return notebookUser;
+ }
- ToolSessionManager sessionMgrService = NotebookServiceProxy
- .getNotebookSessionManager(getServlet().getServletContext());
+ public ActionForward finishActivity(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) {
- String nextActivityUrl;
- try {
- nextActivityUrl = sessionMgrService.leaveToolSession(toolSessionID,
- notebookUser.getUserId());
- response.sendRedirect(nextActivityUrl);
- } catch (DataMissingException e) {
- throw new NotebookException(e);
- } catch (ToolException e) {
- throw new NotebookException(e);
- } catch (IOException e) {
- throw new NotebookException(e);
- }
+ Long toolSessionID = WebUtil.readLongParam(request, "toolSessionID");
+ LearningForm learningForm = (LearningForm) form;
+ NotebookUser notebookUser = getCurrentUser(toolSessionID);
+
+ if (learningForm.getContentEditable()) {
+ // TODO fix idType to use real value not 999
+ if (notebookUser.getEntryUID() == null) {
+ notebookUser.setEntryUID(notebookService.createNotebookEntry(toolSessionID,
+ CoreNotebookConstants.NOTEBOOK_TOOL, NotebookConstants.TOOL_SIGNATURE, notebookUser.getUserId()
+ .intValue(), learningForm.getEntryText()));
+ } else {
+ // update existing entry.
+ notebookService.updateEntry(notebookUser.getEntryUID(), learningForm.getEntryText());
+ }
- return null; // TODO need to return proper page.
+ notebookUser.setFinishedActivity(true);
+ notebookService.saveOrUpdateNotebookUser(notebookUser);
}
-}
+
+ ToolSessionManager sessionMgrService = NotebookServiceProxy.getNotebookSessionManager(getServlet()
+ .getServletContext());
+
+ try {
+ String nextActivityUrl = sessionMgrService.leaveToolSession(toolSessionID, notebookUser.getUserId());
+ response.sendRedirect(nextActivityUrl);
+ } catch (DataMissingException e) {
+ throw new NotebookException(e);
+ } catch (ToolException e) {
+ throw new NotebookException(e);
+ } catch (IOException e) {
+ throw new NotebookException(e);
+ }
+
+ return null; // TODO need to return proper page.
+ }
+}
\ No newline at end of file
Index: lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/web/forms/LearningForm.java
===================================================================
diff -u -r08950e1090443c3423a3d1c587416a2fccd8bbdf -r1db6d7173ac57f97493f84da903508f6a7c41918
--- lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/web/forms/LearningForm.java (.../LearningForm.java) (revision 08950e1090443c3423a3d1c587416a2fccd8bbdf)
+++ lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/web/forms/LearningForm.java (.../LearningForm.java) (revision 1db6d7173ac57f97493f84da903508f6a7c41918)
@@ -35,62 +35,71 @@
*/
public class LearningForm extends ActionForm {
- private static final long serialVersionUID = -4728946254882237144L;
-
- String title;
- String instructions;
-
- String dispatch;
- Long toolSessionID;
- String mode;
-
- String entryText;
+ private static final long serialVersionUID = -4728946254882237144L;
- public String getMode() {
- return mode;
- }
+ String title;
+ String instructions;
- public void setMode(String mode) {
- this.mode = mode;
- }
+ String dispatch;
+ Long toolSessionID;
+ String mode;
+ Boolean contentEditable;
- public String getDispatch() {
- return dispatch;
- }
+ String entryText;
- public void setDispatch(String dispatch) {
- this.dispatch = dispatch;
- }
+ public String getMode() {
+ return mode;
+ }
- public Long getToolSessionID() {
- return toolSessionID;
- }
+ public void setMode(String mode) {
+ this.mode = mode;
+ }
- public void setToolSessionID(Long toolSessionID) {
- this.toolSessionID = toolSessionID;
- }
+ public String getDispatch() {
+ return dispatch;
+ }
- public String getInstructions() {
- return instructions;
- }
+ public void setDispatch(String dispatch) {
+ this.dispatch = dispatch;
+ }
- public void setInstructions(String instructions) {
- this.instructions = instructions;
- }
+ public Long getToolSessionID() {
+ return toolSessionID;
+ }
- public String getTitle() {
- return title;
- }
+ public void setToolSessionID(Long toolSessionID) {
+ this.toolSessionID = toolSessionID;
+ }
- public void setTitle(String title) {
- this.title = title;
- }
+ public String getInstructions() {
+ return instructions;
+ }
- public String getEntryText() {
- return entryText;
- }
+ public void setInstructions(String instructions) {
+ this.instructions = instructions;
+ }
- public void setEntryText(String entryText) {
- this.entryText = entryText;
- }
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public Boolean getContentEditable() {
+ return contentEditable;
+ }
+
+ public void setContentEditable(Boolean contentEditable) {
+ this.contentEditable = contentEditable;
+ }
+
+ public String getEntryText() {
+ return entryText;
+ }
+
+ public void setEntryText(String entryText) {
+ this.entryText = entryText;
+ }
}
Index: lams_tool_notebook/web/pages/learning/notebook.jsp
===================================================================
diff -u -r7817bc4fce30416c9737875ae2d137be0c6aa8ba -r1db6d7173ac57f97493f84da903508f6a7c41918
--- lams_tool_notebook/web/pages/learning/notebook.jsp (.../notebook.jsp) (revision 7817bc4fce30416c9737875ae2d137be0c6aa8ba)
+++ lams_tool_notebook/web/pages/learning/notebook.jsp (.../notebook.jsp) (revision 1db6d7173ac57f97493f84da903508f6a7c41918)
@@ -79,7 +79,8 @@
onsubmit="return validateForm();" styleId="messageForm">