toolContentID
will be passed in. This will be used to retrieve content for this tool.
+ *
+ */
+ @Override
+ protected ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) {
+
+ // 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.readToolAccessModeAuthorDefaulted(request);
+
+ // set up notebookService
+ if (notebookService == null) {
+ notebookService = NotebookServiceProxy.getNotebookService(this.getServlet().getServletContext());
+ }
+
+ // retrieving Notebook with given toolContentID
+ Notebook notebook = notebookService.getNotebookByContentId(toolContentID);
+ if (notebook == null) {
+ notebook = notebookService.copyDefaultContent(toolContentID);
+ notebook.setCreateDate(new Date());
+ notebookService.saveOrUpdateNotebook(notebook);
+ // TODO NOTE: this causes DB orphans when LD not saved.
+ }
+
+ if (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);
+
+ //audit log the teacher has started editing activity in monitor
+ notebookService.auditLogStartEditingActivityInMonitor(toolContentID);
+ }
+
+ // Set up the authForm.
+ AuthoringForm authForm = (AuthoringForm) form;
+ updateAuthForm(authForm, notebook);
+
+ // Set up sessionMap
+ SessionMaptoolContentID
will be passed in. This will be used to retrieve content for this tool.
+ *
+ */
+// @RequestMapping("/")
+ protected String unspecified(AuthoringForm authForm, HttpServletRequest request) {
+
+ // 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.readToolAccessModeAuthorDefaulted(request);
+
+ // set up notebookService
+ if (notebookService == null) {
+ notebookService = NotebookServiceProxy.getNotebookService(this.applicationContext.getServletContext());
+ }
+
+ // retrieving Notebook with given toolContentID
+ Notebook notebook = notebookService.getNotebookByContentId(toolContentID);
+ if (notebook == null) {
+ notebook = notebookService.copyDefaultContent(toolContentID);
+ notebook.setCreateDate(new Date());
+ notebookService.saveOrUpdateNotebook(notebook);
+ // TODO NOTE: this causes DB orphans when LD not saved.
+ }
+
+ if (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);
+
+ //audit log the teacher has started editing activity in monitor
+ notebookService.auditLogStartEditingActivityInMonitor(toolContentID);
+ }
+
+ // Set up the authForm.
+ updateAuthForm(authForm, notebook);
+
+ // Set up sessionMap
+ SessionMapAuthoringAction
action.
+ *
+ * @author Marcin Cieslak
+ * @see org.lamsfoundation.lams.tool.notebook.web.action.AuthoringAction
+ *
+ */
+public class AuthoringNotebookConditionAction extends Action {
+ public INotebookService notebookService;
+
+ @Override
+ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws Exception {
+
+ String param = mapping.getParameter();
+
+ if (param.equals("newConditionInit")) {
+ return newConditionInit(mapping, form, request, response);
+ }
+ if (param.equals("editCondition")) {
+ return editCondition(mapping, form, request, response);
+ }
+ if (param.equals("saveOrUpdateCondition")) {
+ return saveOrUpdateCondition(mapping, form, request, response);
+ }
+ if (param.equals("removeCondition")) {
+ return removeCondition(mapping, form, request, response);
+ }
+ if (param.equals("upCondition")) {
+ return upCondition(mapping, form, request, response);
+ }
+ if (param.equals("downCondition")) {
+ return downCondition(mapping, form, request, response);
+ }
+
+ return null;
+ }
+
+ /**
+ * Display empty page for new taskList item.
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
+ private ActionForward newConditionInit(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) {
+ String sessionMapID = WebUtil.readStrParam(request, NotebookConstants.ATTR_SESSION_MAP_ID);
+ ((NotebookConditionForm) form).setSessionMapID(sessionMapID);
+ ((NotebookConditionForm) form).setOrderId(-1);
+ return mapping.findForward("addcondition");
+ }
+
+ /**
+ * Display edit page for existed taskList item.
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
+ private ActionForward editCondition(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) {
+
+ NotebookConditionForm notebookConditionForm = (NotebookConditionForm) form;
+ String sessionMapID = notebookConditionForm.getSessionMapID();
+ SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID);
+
+ int orderId = NumberUtils.stringToInt(request.getParameter(NotebookConstants.PARAM_ORDER_ID), -1);
+ NotebookCondition condition = null;
+ if (orderId != -1) {
+ SortedSetHttpSession
NotebookItemList. Notice, this save is not persist them into database, just save
+ * HttpSession
temporarily. Only they will be persist when the entire authoring page is being
+ * persisted.
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ * @throws ServletException
+ */
+ private ActionForward saveOrUpdateCondition(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) {
+
+ NotebookConditionForm conditionForm = (NotebookConditionForm) form;
+ ActionErrors errors = validateNotebookCondition(conditionForm, request);
+
+ if (!errors.isEmpty()) {
+ this.addErrors(request, errors);
+ return mapping.findForward("addcondition");
+ }
+
+ try {
+ extractFormToNotebookCondition(request, conditionForm);
+ } catch (Exception e) {
+ // any upload exception will display as normal error message rather then throw exception directly
+ errors.add(ActionMessages.GLOBAL_MESSAGE,
+ new ActionMessage(NotebookConstants.ERROR_MSG_CONDITION, e.getMessage()));
+ if (!errors.isEmpty()) {
+ this.addErrors(request, errors);
+ return mapping.findForward("addcondition");
+ }
+ }
+ // set session map ID so that itemlist.jsp can get sessionMAP
+ request.setAttribute(NotebookConstants.ATTR_SESSION_MAP_ID, conditionForm.getSessionMapID());
+ // return null to close this window
+ return mapping.findForward(NotebookConstants.SUCCESS);
+ }
+
+ /**
+ * Remove taskList item from HttpSession list and update page display. As authoring rule, all persist only happen
+ * when user submit whole page. So this remove is just impact HttpSession values.
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
+ private ActionForward removeCondition(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) {
+
+ // get back sessionMAP
+ String sessionMapID = WebUtil.readStrParam(request, NotebookConstants.ATTR_SESSION_MAP_ID);
+ SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID);
+
+ int orderId = NumberUtils.stringToInt(request.getParameter(NotebookConstants.PARAM_ORDER_ID), -1);
+ if (orderId != -1) {
+ SortedSetjava.util.List
from HttpSession by given name.
+ *
+ * @param request
+ * @param name
+ * @return
+ */
+ private List getListFromSession(SessionMap sessionMap, String name) {
+ List list = (List) sessionMap.get(name);
+ if (list == null) {
+ list = new ArrayList();
+ sessionMap.put(name, list);
+ }
+ return list;
+ }
+
+ /**
+ * This method will populate taskList item information to its form for edit use.
+ *
+ * @param orderId
+ * @param condition
+ * @param form
+ * @param request
+ */
+ private void populateConditionToForm(int orderId, NotebookCondition condition, NotebookConditionForm form,
+ HttpServletRequest request) {
+ form.populateForm(condition);
+ if (orderId >= 0) {
+ form.setOrderId(orderId + 1);
+ }
+ }
+
+ /**
+ * Extract form content to taskListContent.
+ *
+ * @param request
+ * @param form
+ * @throws NotebookException
+ */
+ private void extractFormToNotebookCondition(HttpServletRequest request, NotebookConditionForm form)
+ throws Exception {
+ /*
+ * BE CAREFUL: This method will copy necessary info from request form to a old or new NotebookItem instance. It
+ * gets all info EXCEPT NotebookItem.createDate and NotebookItem.createBy, which need be set when persisting
+ * this taskList item.
+ */
+
+ SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(form.getSessionMapID());
+ // check whether it is "edit(old item)" or "add(new item)"
+ SortedSetAuthoringAction
action.
+ *
+ * @author Marcin Cieslak
+ * @see org.lamsfoundation.lams.tool.notebook.web.action.AuthoringAction
+ *
+ */
+@Controller
+@RequestMapping("/authoring")
+public class AuthoringNotebookConditionController{
+
+ @Autowired
+ @Qualifier("notebookService")
+ private INotebookService notebookService;
+
+ @Autowired
+ @Qualifier("notebookMessageService")
+ private MessageService messageService;
+
+ /**
+ * Display empty page for new taskList item.
+ *
+ * @param notebookConditionForm
+ * @param request
+ * @return
+ */
+ @RequestMapping("newConditionInit")
+ private String newConditionInit(NotebookConditionForm notebookConditionForm, HttpServletRequest request) {
+ String sessionMapID = WebUtil.readStrParam(request, NotebookConstants.ATTR_SESSION_MAP_ID);
+ notebookConditionForm.setSessionMapID(sessionMapID);
+ notebookConditionForm.setOrderId(-1);
+ return "pages/authoring/addCondition";
+ }
+
+ /**
+ * Display edit page for existed taskList item.
+ *
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
+ @RequestMapping("/editCondition")
+ private String editCondition(NotebookConditionForm notebookConditionForm, HttpServletRequest request) {
+
+ String sessionMapID = notebookConditionForm.getSessionMapID();
+ SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID);
+
+ int orderId = NumberUtils.stringToInt(request.getParameter(NotebookConstants.PARAM_ORDER_ID), -1);
+ NotebookCondition condition = null;
+ if (orderId != -1) {
+ SortedSetHttpSession
NotebookItemList. Notice, this save is not persist them into database, just save
+ * HttpSession
temporarily. Only they will be persist when the entire authoring page is being
+ * persisted.
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ * @throws ServletException
+ */
+ @RequestMapping("/saveOrUpdateCondition")
+ private String saveOrUpdateCondition(NotebookConditionForm notebookConditionForm, Errors errors, HttpServletRequest request,
+ HttpServletResponse response) {
+
+ validateNotebookCondition(notebookConditionForm, errors, request);
+
+ if (errors.hasErrors()) {
+ return "pages/authoring/addCondition";
+ }
+
+ try {
+ extractFormToNotebookCondition(request, notebookConditionForm);
+ } catch (Exception e) {
+ // any upload exception will display as normal error message rather then throw exception directly
+ errors.reject(null, null, messageService.getMessage(NotebookConstants.ERROR_MSG_CONDITION, e.getMessage()));
+ if (errors.hasErrors()) {
+ return "pages/authoring/addCondition";
+ }
+ }
+ // set session map ID so that itemlist.jsp can get sessionMAP
+ request.setAttribute(NotebookConstants.ATTR_SESSION_MAP_ID, notebookConditionForm.getSessionMapID());
+ // return null to close this window
+ return "pages/authoring/conditionList";
+ }
+
+ /**
+ * Remove taskList item from HttpSession list and update page display. As authoring rule, all persist only happen
+ * when user submit whole page. So this remove is just impact HttpSession values.
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
+ @RequestMapping("/removeCondition")
+ private String removeCondition(HttpServletRequest request) {
+
+ // get back sessionMAP
+ String sessionMapID = WebUtil.readStrParam(request, NotebookConstants.ATTR_SESSION_MAP_ID);
+ SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID);
+
+ int orderId = NumberUtils.stringToInt(request.getParameter(NotebookConstants.PARAM_ORDER_ID), -1);
+ if (orderId != -1) {
+ SortedSetjava.util.List
from HttpSession by given name.
+ *
+ * @param request
+ * @param name
+ * @return
+ */
+ private List getListFromSession(SessionMap sessionMap, String name) {
+ List list = (List) sessionMap.get(name);
+ if (list == null) {
+ list = new ArrayList();
+ sessionMap.put(name, list);
+ }
+ return list;
+ }
+
+ /**
+ * This method will populate taskList item information to its form for edit use.
+ *
+ * @param orderId
+ * @param condition
+ * @param form
+ * @param request
+ */
+ private void populateConditionToForm(int orderId, NotebookCondition condition, NotebookConditionForm form,
+ HttpServletRequest request) {
+ form.populateForm(condition);
+ if (orderId >= 0) {
+ form.setOrderId(orderId + 1);
+ }
+ }
+
+ /**
+ * Extract form content to taskListContent.
+ *
+ * @param request
+ * @param form
+ * @throws NotebookException
+ */
+ private void extractFormToNotebookCondition(HttpServletRequest request, NotebookConditionForm form)
+ throws Exception {
+ /*
+ * BE CAREFUL: This method will copy necessary info from request form to a old or new NotebookItem instance. It
+ * gets all info EXCEPT NotebookItem.createDate and NotebookItem.createBy, which need be set when persisting
+ * this taskList item.
+ */
+
+ SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(form.getSessionMapID());
+ // check whether it is "edit(old item)" or "add(new item)"
+ SortedSet