Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/DisplayNotebookEntry.java =================================================================== diff -u --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/DisplayNotebookEntry.java (revision 0) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/DisplayNotebookEntry.java (revision 3ebc3946a5086e35a6be9a325f9d3207bdb6fdc8) @@ -0,0 +1,83 @@ +/* +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 +*/ + +package org.lamsfoundation.lams.learning.web.action; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionForward; +import org.apache.struts.action.ActionMapping; +import org.lamsfoundation.lams.learning.web.bean.SessionBean; +import org.lamsfoundation.lams.learning.web.form.NotebookForm; +import org.lamsfoundation.lams.learning.web.util.ActionMappings; +import org.lamsfoundation.lams.notebook.NotebookEntry; +import org.lamsfoundation.lams.notebook.service.INotebookService; +import org.lamsfoundation.lams.notebook.service.NotebookServiceProxy; + +/** + * @author daveg + * + * XDoclet definition: + * + * @struts:action path="/notebook/DisplayEntry" name="notebookForm" + * validate="false" scope="request" + * + * @struts:action-forward name="displayEntry" path=".journalDetail" + * + */ +public class DisplayNotebookEntry extends NotebookAction { + + protected static String className = "DisplayNotebookEntry"; + + public ActionForward execute( + ActionMapping mapping, + ActionForm actionForm, + HttpServletRequest request, + HttpServletResponse response) { + NotebookForm notebookForm = (NotebookForm)actionForm; + + SessionBean sessionBean = getSessionBean(request); + if (sessionBean == null) { + // forward to the no session error page + return mapping.findForward(ActionMappings.NO_SESSION_ERROR); + } + + NotebookEntry notebookEntry; + if (notebookForm.getNotebookEntryId() == null) { + notebookEntry = new NotebookEntry(); + } + else { + INotebookService notebookService = NotebookServiceProxy.getNotebookService(this.servlet.getServletContext()); + notebookEntry = notebookService.getNotebookEntry(notebookForm.getNotebookEntryId()); + // check whether user in session has access to this notebook entry + if (!notebookEntry.isViewable(sessionBean.getLearner())) { + log.error(className+": User with Id "+sessionBean.getLearner().getUserId()+" does not have access to NotebookEntry with Id "+notebookEntry.getNotebookEntryId()); + return mapping.findForward(ActionMappings.NO_ACCESS_ERROR); + } + } + notebookForm.setNotebookEntry(notebookEntry); + + return mapping.findForward("displayEntry"); + } + +} Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/NotebookAction.java =================================================================== diff -u --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/NotebookAction.java (revision 0) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/NotebookAction.java (revision 3ebc3946a5086e35a6be9a325f9d3207bdb6fdc8) @@ -0,0 +1,31 @@ +/* +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 +*/ + +package org.lamsfoundation.lams.learning.web.action; + +/** + * MyEclipse Struts + * Creation date: 01-12-2005 + * + */ +public class NotebookAction extends LearnerAction { + +} \ No newline at end of file Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/SaveNotebookEntry.java =================================================================== diff -u --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/SaveNotebookEntry.java (revision 0) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/SaveNotebookEntry.java (revision 3ebc3946a5086e35a6be9a325f9d3207bdb6fdc8) @@ -0,0 +1,95 @@ +/* +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 +*/ + +package org.lamsfoundation.lams.learning.web.action; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionForward; +import org.apache.struts.action.ActionMapping; +import org.lamsfoundation.lams.learning.web.bean.SessionBean; +import org.lamsfoundation.lams.learning.web.form.NotebookForm; +import org.lamsfoundation.lams.learning.web.util.ActionMappings; +import org.lamsfoundation.lams.notebook.NotebookEntry; +import org.lamsfoundation.lams.notebook.service.INotebookService; +import org.lamsfoundation.lams.notebook.service.NotebookServiceException; +import org.lamsfoundation.lams.notebook.service.NotebookServiceProxy; + +/** + * @author daveg + * + * XDoclet definition: + * + * @struts:action path="/notebook/SaveEntry" name="notebookForm" + * validate="false" scope="request" + * + * @struts:action-forward name="displayEntry" path="/DisplayEntry" redirect="true" + * + */ +public class SaveNotebookEntry extends NotebookAction { + + protected static String className = "SaveNotebookEntry"; + + public ActionForward execute( + ActionMapping mapping, + ActionForm actionForm, + HttpServletRequest request, + HttpServletResponse response) { + NotebookForm notebookForm = (NotebookForm)actionForm; + + SessionBean sessionBean = getSessionBean(request); + if (sessionBean == null) { + // forward to the no session error page + return mapping.findForward(ActionMappings.NO_SESSION_ERROR); + } + + INotebookService notebookService = NotebookServiceProxy.getNotebookService(this.servlet.getServletContext()); + NotebookEntry notebookEntry; + if (notebookForm.getNotebookEntryId() == null) { + notebookEntry = new NotebookEntry(); + notebookEntry.setUser(sessionBean.getLearner()); + notebookEntry.setLesson(sessionBean.getLesson()); + } + else { + notebookEntry = notebookService.getNotebookEntry(notebookForm.getNotebookEntryId()); + // check whether user in session has access to update this notebook entry + if (!notebookEntry.isUpdateable(sessionBean.getLearner())) { + log.error(className+": User with Id "+sessionBean.getLearner().getUserId()+" does not have access to NotebookEntry with Id "+notebookEntry.getNotebookEntryId()); + return mapping.findForward(ActionMappings.NO_ACCESS_ERROR); + } + } + + notebookEntry.setTitle(notebookForm.getTitle()); + notebookEntry.setBody(notebookForm.getBody()); + try { + notebookService.saveNotebookEntry(notebookEntry); + } + catch (NotebookServiceException e) { + log.error(className+": NootebookServiceException saving notebook entry", e); + return mapping.findForward(ActionMappings.ERROR); + } + + return mapping.findForward("displayEntry"); + } + +} Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/form/NotebookForm.java =================================================================== diff -u --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/form/NotebookForm.java (revision 0) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/form/NotebookForm.java (revision 3ebc3946a5086e35a6be9a325f9d3207bdb6fdc8) @@ -0,0 +1,134 @@ +/* +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 +*/ + +package org.lamsfoundation.lams.learning.web.form; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.TimeZone; + +import org.apache.struts.action.ActionForm; +import org.lamsfoundation.lams.notebook.JournalEntry; +import org.lamsfoundation.lams.notebook.NotebookEntry; + +/** + * @author daveg + * + * XDoclet definition: + * @struts:form name="notebookForm" + * + */ +public class NotebookForm extends ActionForm { + + private static String DATE_FORMAT = "HH:mm 'on' dd/MM/yyyy"; + + // properties for display + + private NotebookEntry notebookEntry; + private String timeZoneId; + + // properties for update + + private Long notebookEntryId; + private String title; + private String body; + + + public void setNotebookEntry(NotebookEntry notebookEntry) { + this.notebookEntry = notebookEntry; + this.notebookEntryId = notebookEntry.getNotebookEntryId(); + this.title = notebookEntry.getTitle(); + this.body = notebookEntry.getBody(); + } + + public void setTimeZoneId(String timeZoneId) { + this.timeZoneId = timeZoneId; + } + + + private String formatDateTime(Date date) { + TimeZone timeZone; + if (this.timeZoneId == null) timeZone = TimeZone.getDefault(); + else timeZone = TimeZone.getTimeZone(this.timeZoneId); + + SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT); + dateFormat.setTimeZone(timeZone); + return dateFormat.format(date); + } + + public String getCreatedDateTime() { + if (this.notebookEntry.getCreatedDateTime() == null) return null; + return formatDateTime(this.notebookEntry.getCreatedDateTime()); + } + + public String getUpdatedDateTime() { + if (this.notebookEntry.getUpdatedDateTime() == null) return null; + return formatDateTime(this.notebookEntry.getUpdatedDateTime()); + } + + public String getNoteType() { + String noteType = null; + if (this.notebookEntry instanceof NotebookEntry) noteType = "Notebook Entry"; + else if (this.notebookEntry instanceof JournalEntry) noteType = "Journal Entry"; + return noteType; + } + + public boolean isUpdateable() { + return this.notebookEntry.isUpdateable(); + } + + + /** + * Returns the notebookEntryId property. + */ + public Long getNotebookEntryId() { + return notebookEntryId; + } + + /** + * Sets notebookEntryId. If notebookEntryId is 0 then it is set as null. + */ + public void setNotebookEntryId(Long notebookEntryId) { + if ((notebookEntryId != null) && (notebookEntryId.longValue() == 0)) this.notebookEntryId = null; + else this.notebookEntryId = notebookEntryId; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getBody() { + return body; + } + + public String getBodyFormatted() { + String formatted = body.replaceAll("\n", "
"); + return formatted; + } + + public void setBody(String body) { + this.body = body; + } +}