Ticket
to login and access the Content Repository.
- *
- * A valid ticket is needed in order to access the content from the
- * repository. This method would be called evertime the tool needs to
- * upload/download files from the content repository.
- *
- * @return ITicket The ticket for repostory access
- * @throws SubmitFilesException
- */
- private ITicket getRepositoryLoginTicket() throws NotebookException {
- repositoryService = RepositoryProxy.getRepositoryService();
- ICredentials credentials = new SimpleCredentials(
- NotebookToolContentHandler.repositoryUser,
- NotebookToolContentHandler.repositoryId);
- try {
- ITicket ticket = repositoryService.login(credentials,
- NotebookToolContentHandler.repositoryWorkspaceName);
- return ticket;
- } catch (AccessDeniedException ae) {
- throw new NotebookException("Access Denied to repository."
- + ae.getMessage());
- } catch (WorkspaceNotFoundException we) {
- throw new NotebookException("Workspace not found."
- + we.getMessage());
- } catch (LoginException e) {
- throw new NotebookException("Login failed." + e.getMessage());
- }
+ /**
+ * This method verifies the credentials of the SubmitFiles Tool and gives it the Ticket
to login and
+ * access the Content Repository.
+ *
+ * A valid ticket is needed in order to access the content from the repository. This method would be called evertime
+ * the tool needs to upload/download files from the content repository.
+ *
+ * @return ITicket The ticket for repostory access
+ * @throws SubmitFilesException
+ */
+ private ITicket getRepositoryLoginTicket() throws NotebookException {
+ repositoryService = RepositoryProxy.getRepositoryService();
+ ICredentials credentials = new SimpleCredentials(NotebookToolContentHandler.repositoryUser,
+ NotebookToolContentHandler.repositoryId);
+ try {
+ ITicket ticket = repositoryService.login(credentials, NotebookToolContentHandler.repositoryWorkspaceName);
+ return ticket;
+ } catch (AccessDeniedException ae) {
+ throw new NotebookException("Access Denied to repository." + ae.getMessage());
+ } catch (WorkspaceNotFoundException we) {
+ throw new NotebookException("Workspace not found." + we.getMessage());
+ } catch (LoginException e) {
+ throw new NotebookException("Login failed." + e.getMessage());
}
+ }
- /* ===============Methods implemented from ToolContentImport102Manager =============== */
-
+ /* ===============Methods implemented from ToolContentImport102Manager =============== */
/**
* Import the data for a 1.0.2 Notebook
*/
- public void import102ToolContent(Long toolContentId, UserDTO user, Hashtable importValues)
- {
- Date now = new Date();
- Notebook notebook = new Notebook();
- notebook.setContentInUse(Boolean.FALSE);
- notebook.setCreateBy(new Long(user.getUserID().longValue()));
- notebook.setCreateDate(now);
- notebook.setDefineLater(Boolean.FALSE);
- notebook.setInstructions(WebUtil.convertNewlines((String)importValues.get(ToolContentImport102Manager.CONTENT_BODY)));
- notebook.setLockOnFinished(Boolean.TRUE);
- notebook.setOfflineInstructions(null);
- notebook.setOnlineInstructions(null);
- notebook.setRunOffline(Boolean.FALSE);
- notebook.setTitle((String)importValues.get(ToolContentImport102Manager.CONTENT_TITLE));
- notebook.setToolContentId(toolContentId);
- notebook.setUpdateDate(now);
- notebook.setAllowRichEditor(Boolean.FALSE);
- // leave as empty, no need to set them to anything.
- //setNotebookAttachments(Set notebookAttachments);
- //setNotebookSessions(Set notebookSessions);
- notebookDAO.saveOrUpdate(notebook);
+ public void import102ToolContent(Long toolContentId, UserDTO user, Hashtable importValues) {
+ Date now = new Date();
+ Notebook notebook = new Notebook();
+ notebook.setContentInUse(Boolean.FALSE);
+ notebook.setCreateBy(new Long(user.getUserID().longValue()));
+ notebook.setCreateDate(now);
+ notebook.setDefineLater(Boolean.FALSE);
+ notebook.setInstructions(WebUtil.convertNewlines((String) importValues
+ .get(ToolContentImport102Manager.CONTENT_BODY)));
+ notebook.setLockOnFinished(Boolean.TRUE);
+ notebook.setOfflineInstructions(null);
+ notebook.setOnlineInstructions(null);
+ notebook.setRunOffline(Boolean.FALSE);
+ notebook.setTitle((String) importValues.get(ToolContentImport102Manager.CONTENT_TITLE));
+ notebook.setToolContentId(toolContentId);
+ notebook.setUpdateDate(now);
+ notebook.setAllowRichEditor(Boolean.FALSE);
+ // leave as empty, no need to set them to anything.
+ // setNotebookAttachments(Set notebookAttachments);
+ // setNotebookSessions(Set notebookSessions);
+ notebookDAO.saveOrUpdate(notebook);
}
/** Set the description, throws away the title value as this is not supported in 2.0 */
- public void setReflectiveData(Long toolContentId, String title, String description)
- throws ToolException, DataMissingException {
+ public void setReflectiveData(Long toolContentId, String title, String description) throws ToolException,
+ DataMissingException {
- logger.warn("Setting the reflective field on a notebook. This doesn't make sense as the notebook is for reflection and we don't reflect on reflection!");
- Notebook notebook = getNotebookByContentId(toolContentId);
- if ( notebook == null ) {
- throw new DataMissingException("Unable to set reflective data titled "+title
- +" on activity toolContentId "+toolContentId
- +" as the tool content does not exist.");
- }
-
- notebook.setInstructions(description);
+ NotebookService.logger
+ .warn("Setting the reflective field on a notebook. This doesn't make sense as the notebook is for reflection and we don't reflect on reflection!");
+ Notebook notebook = getNotebookByContentId(toolContentId);
+ if (notebook == null) {
+ throw new DataMissingException("Unable to set reflective data titled " + title
+ + " on activity toolContentId " + toolContentId + " as the tool content does not exist.");
+ }
+
+ notebook.setInstructions(description);
}
-
- //=========================================================================================
- /* ********** Used by Spring to "inject" the linked objects ************* */
- public INotebookAttachmentDAO getNotebookAttachmentDAO() {
- return notebookAttachmentDAO;
- }
+ // =========================================================================================
+ /* ********** Used by Spring to "inject" the linked objects ************* */
- public void setNotebookAttachmentDAO(INotebookAttachmentDAO attachmentDAO) {
- this.notebookAttachmentDAO = attachmentDAO;
- }
+ public INotebookAttachmentDAO getNotebookAttachmentDAO() {
+ return notebookAttachmentDAO;
+ }
- public INotebookDAO getNotebookDAO() {
- return notebookDAO;
- }
+ public void setNotebookAttachmentDAO(INotebookAttachmentDAO attachmentDAO) {
+ notebookAttachmentDAO = attachmentDAO;
+ }
- public void setNotebookDAO(INotebookDAO notebookDAO) {
- this.notebookDAO = notebookDAO;
- }
+ public INotebookDAO getNotebookDAO() {
+ return notebookDAO;
+ }
- public IToolContentHandler getNotebookToolContentHandler() {
- return notebookToolContentHandler;
- }
+ public void setNotebookDAO(INotebookDAO notebookDAO) {
+ this.notebookDAO = notebookDAO;
+ }
- public void setNotebookToolContentHandler(
- IToolContentHandler notebookToolContentHandler) {
- this.notebookToolContentHandler = notebookToolContentHandler;
- }
+ public IToolContentHandler getNotebookToolContentHandler() {
+ return notebookToolContentHandler;
+ }
- public INotebookSessionDAO getNotebookSessionDAO() {
- return notebookSessionDAO;
- }
+ public void setNotebookToolContentHandler(IToolContentHandler notebookToolContentHandler) {
+ this.notebookToolContentHandler = notebookToolContentHandler;
+ }
- public void setNotebookSessionDAO(INotebookSessionDAO sessionDAO) {
- this.notebookSessionDAO = sessionDAO;
- }
+ public INotebookSessionDAO getNotebookSessionDAO() {
+ return notebookSessionDAO;
+ }
- public ILamsToolService getToolService() {
- return toolService;
- }
+ public void setNotebookSessionDAO(INotebookSessionDAO sessionDAO) {
+ notebookSessionDAO = sessionDAO;
+ }
- public void setToolService(ILamsToolService toolService) {
- this.toolService = toolService;
- }
+ public ILamsToolService getToolService() {
+ return toolService;
+ }
- public INotebookUserDAO getNotebookUserDAO() {
- return notebookUserDAO;
- }
+ public void setToolService(ILamsToolService toolService) {
+ this.toolService = toolService;
+ }
- public void setNotebookUserDAO(INotebookUserDAO userDAO) {
- this.notebookUserDAO = userDAO;
- }
+ public INotebookUserDAO getNotebookUserDAO() {
+ return notebookUserDAO;
+ }
- public ILearnerService getLearnerService() {
- return learnerService;
- }
+ public void setNotebookUserDAO(INotebookUserDAO userDAO) {
+ notebookUserDAO = userDAO;
+ }
- public void setLearnerService(ILearnerService learnerService) {
- this.learnerService = learnerService;
- }
+ public ILearnerService getLearnerService() {
+ return learnerService;
+ }
- public IExportToolContentService getExportContentService() {
- return exportContentService;
- }
+ public void setLearnerService(ILearnerService learnerService) {
+ this.learnerService = learnerService;
+ }
- public void setExportContentService(
- IExportToolContentService exportContentService) {
- this.exportContentService = exportContentService;
- }
+ public IExportToolContentService getExportContentService() {
+ return exportContentService;
+ }
- public ICoreNotebookService getCoreNotebookService() {
- return coreNotebookService;
- }
+ public void setExportContentService(IExportToolContentService exportContentService) {
+ this.exportContentService = exportContentService;
+ }
- public void setCoreNotebookService(ICoreNotebookService coreNotebookService) {
- this.coreNotebookService = coreNotebookService;
+ public ICoreNotebookService getCoreNotebookService() {
+ return coreNotebookService;
+ }
+
+ public void setCoreNotebookService(ICoreNotebookService coreNotebookService) {
+ this.coreNotebookService = coreNotebookService;
+ }
+
+ public NotebookOutputFactory getNotebookOutputFactory() {
+ return notebookOutputFactory;
+ }
+
+ public void setNotebookOutputFactory(NotebookOutputFactory notebookOutputFactory) {
+ this.notebookOutputFactory = notebookOutputFactory;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String createConditionName(CollectionNotebookCondition
. Only the order ID is compared.
+ *
+ * @author Marcin Cieslak
+ * @see org.lamsfoundation.lams.tool.notebook.NotebookCondition
+ */
+public class NotebookConditionComparator implements ComparatortoolContentID
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) {
- private static final String KEY_MODE = "mode";
+ // Extract toolContentID from parameters.
+ Long toolContentID = new Long(WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID));
- private static final String KEY_ONLINE_FILES = "onlineFiles";
+ String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID);
- private static final String KEY_OFFLINE_FILES = "offlineFiles";
+ ToolAccessMode mode = WebUtil.readToolAccessModeParam(request, "mode", true);
- private static final String KEY_UNSAVED_ONLINE_FILES = "unsavedOnlineFiles";
+ // set up notebookService
+ if (notebookService == null) {
+ notebookService = NotebookServiceProxy.getNotebookService(this.getServlet().getServletContext());
+ }
- private static final String KEY_UNSAVED_OFFLINE_FILES = "unsavedOfflineFiles";
+ // 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.
+ }
- private static final String KEY_DELETED_FILES = "deletedFiles";
+ if (mode != null && 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);
+ }
- /**
- * Default method when no dispatch parameter is specified. It is expected
- * that the parameter toolContentID
will be passed in. This
- * will be used to retrieve content for this tool.
- *
- */
- protected ActionForward unspecified(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
+ // Set up the authForm.
+ AuthoringForm authForm = (AuthoringForm) form;
+ updateAuthForm(authForm, notebook);
- // Extract toolContentID from parameters.
- Long toolContentID = new Long(WebUtil.readLongParam(request,
- AttributeNames.PARAM_TOOL_CONTENT_ID));
+ // 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)"
+ SortedSet
+ |
+
+ |
+
+ |
+
+ |
+
+ |
+
+ |
+
+ |
+
+ |
+
+ |
+
+ |
+ |||
---|---|---|---|---|
+ |
+ ||||
+ ${status.index + 1} + | + ++ ${condition.displayName} + | + +
+ ![]() ![]() ![]() ![]() |
+
+
+ ![]() |
+
+
+ ![]() |
+
+ ');" class="button-add-item">
+
+ +
Index: lams_tool_notebook/web/pages/authoring/headItems.jsp =================================================================== RCS file: /usr/local/cvsroot/lams_tool_notebook/web/pages/authoring/headItems.jsp,v diff -u -r1.2 -r1.3 --- lams_tool_notebook/web/pages/authoring/headItems.jsp 31 Aug 2006 00:29:51 -0000 1.2 +++ lams_tool_notebook/web/pages/authoring/headItems.jsp 4 Oct 2008 02:47:52 -0000 1.3 @@ -1,9 +1,10 @@ <%@ include file="/common/taglibs.jsp"%> - +