Index: lams_tool_task/conf/language/lams/ApplicationResources_en_AU.properties =================================================================== RCS file: /usr/local/cvsroot/lams_tool_task/conf/language/lams/ApplicationResources_en_AU.properties,v diff -u -r1.2 -r1.3 --- lams_tool_task/conf/language/lams/ApplicationResources_en_AU.properties 14 Mar 2008 08:01:00 -0000 1.2 +++ lams_tool_task/conf/language/lams/ApplicationResources_en_AU.properties 7 Apr 2008 07:33:31 -0000 1.3 @@ -15,9 +15,11 @@ label.authoring.heading =Task List label.authoring.title =Task List Authoring label.authoring.heading.basic =Basic -label.authoring.heading.instructions =Instructions label.authoring.heading.basic.desc =Basic input information for task list +label.authoring.heading.instructions =Instructions label.authoring.heading.instructions.desc =Please input online and offline instructions +label.authoring.heading.conditions =Conditions +label.authoring.heading.instructions.desc =Please input conditions for task list label.authoring.heading.advance =Advanced label.authoring.heading.advance.desc =Please input advance options for task list label.authoring.basic.title =Title @@ -55,13 +57,25 @@ label.authoring.advanced.reflectOnActivity =Add Notebook at end of Task List with the following instructions: label.authoring.advance.run.content.sequentialOrder =Tasks have to be completed in sequential order label.authoring.cancel.button =Cancel +label.authoring.edit.conditions.button =Edit Conditions label.authoring.save.button =Save label.authoring.up =Move Up label.authoring.down =Move down +label.authoring.conditions.add.condition =Add Condition +label.authoring.conditions = +label.authoring.conditions = +label.authoring.conditions = +label.authoring.conditions = +label.authoring.conditions.list.title =Conditions +label.authoring.conditions.condition.name =Condition Name + authoring.exception =There is a problem in task list authoring page, the reason is {0} authoring.msg.cancel.save =Do you want to close this window without saving? authoring.msg.no.tasks.save =There must be at least one task to be saved. error.resource.item.title.blank =Title can not be blank. +error.condition.name.blank =Name can not be blank. +error.condition.duplicated.name =Duplicated name. Please choose unique one. +error.condition.no.tasklistitems.selected =There are no TaskListItems selected. Please select at least one. error.upload.failed =Upload file failed: {0} error.msg.upload.file.not.found =Could not find upload file {0}. error.msg.zip.file.exception =Could not handle zip file when uploading file. Index: lams_tool_task/conf/xdoclet/struts-actions.xml =================================================================== RCS file: /usr/local/cvsroot/lams_tool_task/conf/xdoclet/struts-actions.xml,v diff -u -r1.5 -r1.6 --- lams_tool_task/conf/xdoclet/struts-actions.xml 28 Mar 2008 02:21:26 -0000 1.5 +++ lams_tool_task/conf/xdoclet/struts-actions.xml 7 Apr 2008 07:33:30 -0000 1.6 @@ -1,5 +1,7 @@ + + - + + - + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + - - + @@ -160,7 +214,6 @@ parameter="finish" > - - + - - + + - - - + Index: lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/TaskListConstants.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/TaskListConstants.java,v diff -u -r1.6 -r1.7 --- lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/TaskListConstants.java 31 Mar 2008 06:09:45 -0000 1.6 +++ lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/TaskListConstants.java 7 Apr 2008 07:33:31 -0000 1.7 @@ -41,6 +41,7 @@ public static final String PARAM_FILE_VERSION_ID = "fileVersionId"; public static final String PARAM_FILE_UUID = "fileUuid"; public static final String PARAM_ITEM_INDEX = "itemIndex"; + public static final String PARAM_SEQUENCE_ID = "sequenceId"; public static final String PARAM_RESOURCE_ITEM_UID = "itemUid"; public static final String PARAM_CURRENT_INSTRUCTION_INDEX = "insIdx"; public static final String PARAM_RUN_OFFLINE = "runOffline"; @@ -51,8 +52,10 @@ public static final String ATTR_TOOL_CONTENT_ID = "toolContentID"; public static final String ATTR_TOOL_SESSION_ID = "toolSessionID"; public static final String ATTR_RESOURCE_ITEM_LIST = "taskListList"; + public static final String ATTR_CONDITION_LIST = "conditionList"; public static final String ATT_ATTACHMENT_LIST = "instructionAttachmentList"; public static final String ATTR_DELETED_RESOURCE_ITEM_LIST = "deleteTaskListList"; + public static final String ATTR_DELETED_CONDITION_LIST = "deleteConditionList"; public static final String ATTR_DELETED_ATTACHMENT_LIST = "deletedAttachmmentList"; public static final String ATTR_DELETED_RESOURCE_ITEM_ATTACHMENT_LIST = "deletedItemAttachmmentList";; public static final String ATT_LEARNING_OBJECT = "cpPackage"; @@ -81,6 +84,9 @@ //error message keys public static final String ERROR_MSG_TITLE_BLANK = "error.resource.item.title.blank"; + public static final String ERROR_MSG_NAME_BLANK = "error.condition.name.blank"; + public static final String ERROR_MSG_NO_TASK_LIST_ITEMS = "error.condition.no.tasklistitems.selected"; + public static final String ERROR_MSG_NAME_DUPLICATED = "error.condition.duplicated.name"; public static final String ERROR_MSG_UPLOAD_FAILED = "error.upload.failed"; public static final String PAGE_EDITABLE = "isPageEditable"; Index: lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/dto/ReflectDTO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/dto/ReflectDTO.java,v diff -u -r1.1 -r1.2 --- lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/dto/ReflectDTO.java 28 Feb 2008 03:50:18 -0000 1.1 +++ lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/dto/ReflectDTO.java 7 Apr 2008 07:33:30 -0000 1.2 @@ -3,9 +3,9 @@ import org.lamsfoundation.lams.tool.taskList.model.TaskListUser; /** + * DTO object used for representing reflection. * * @author Dapeng Ni - * */ public class ReflectDTO { private Long userUid; Index: lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/dto/Summary.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/dto/Attic/Summary.java,v diff -u -r1.4 -r1.5 --- lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/dto/Summary.java 31 Mar 2008 06:09:45 -0000 1.4 +++ lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/dto/Summary.java 7 Apr 2008 07:33:30 -0000 1.5 @@ -59,7 +59,7 @@ /** * Contruction method for monitoring summary function. * - * Don't not set isInitGroup and viewNumber fields + * Don't set isInitGroup and viewNumber fields * @param sessionName * @param item * @param isInitGroup Index: lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/dto/TaskSummary.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/dto/Attic/TaskSummary.java,v diff -u -r1.2 -r1.3 --- lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/dto/TaskSummary.java 31 Mar 2008 06:09:45 -0000 1.2 +++ lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/dto/TaskSummary.java 7 Apr 2008 07:33:30 -0000 1.3 @@ -50,13 +50,28 @@ // Get/Set methods // ********************************************************** + /** + * Returns TaskListItem described by this current TaskSummary. + * + * @return TaskListItem described by this current TaskSummary + */ public TaskListItem getTaskListItem() { return taskListItem; } + /** + * Sets TaskListItem described by this current TaskSummary. + * + * @param taskListItem TaskListItem described by this current TaskSummary + */ public void setTaskListItem(TaskListItem taskListItem) { this.taskListItem = taskListItem; } + /** + * Returns list of TaskSummaryItem, each one for every TaskListItem. + * + * @return + */ public List getTaskSummaryItems() { return taskSummaryItems; } Index: lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/dto/TaskSummaryItem.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/dto/Attic/TaskSummaryItem.java,v diff -u -r1.2 -r1.3 --- lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/dto/TaskSummaryItem.java 31 Mar 2008 06:09:45 -0000 1.2 +++ lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/dto/TaskSummaryItem.java 7 Apr 2008 07:33:30 -0000 1.3 @@ -56,37 +56,87 @@ // Get/Set methods // ********************************************************** + /** + * Returns user whom created this TaskListItem. + * + * @return user whom created this TaskListItem + */ public TaskListUser getUser() { return user; } + /** + * Returns user whom created this TaskListItem. + * + * @param user user whom created this TaskListItem + */ public void setUser(TaskListUser user) { this.user = user; } + /** + * Returns whether this TaskListItem was completed. + * + * @return boolean showing whether this TaskListItem was completed or not + */ public boolean getCompleted() { return completed; } + /** + * Sets whether this TaskListItem was completed. + * + * @param completed true if this TaskListItem was completed, false otherwise + */ public void setCompleted(boolean completed) { this.completed = completed; } + /** + * Returns the date of the completion. + * + * @return the date of the completion + */ public Date getDate() { return date; } + /** + * Sets the date of the completion. + * + * @param date the date of the completion + */ public void setDate(Date date) { this.date = date; } + /** + * Returns list of the comments done by this user for this particular TaskListItem. + * + * @return list of the comments done by this user for this particular TaskListItem + */ public List getComments() { return comments; } + /** + * Sets list of the comments done by this user for this particular TaskListItem. + * + * @param comments list of the comments done by this user for this particular TaskListItem + */ public void setComments(List comments) { this.comments = comments; } + /** + * Returns list of the attachments uploaded by this user for this particular TaskListItem. + * + * @return list of the attachments uploaded by this user for this particular TaskListItem + */ public List getAttachments() { return attachments; } + /** + * Sets list of the attachments uploaded by this user for this particular TaskListItem. + * + * @param attachments list of the attachments uploaded by this user for this particular TaskListItem. + */ public void setAttachments(List attachments) { this.attachments = attachments; } Index: lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/model/TaskList.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/model/TaskList.java,v diff -u -r1.4 -r1.5 --- lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/model/TaskList.java 31 Mar 2008 06:09:45 -0000 1.4 +++ lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/model/TaskList.java 7 Apr 2008 07:33:31 -0000 1.5 @@ -73,6 +73,8 @@ private String onlineInstructions; private String offlineInstructions; private Set attachments; + //conditions + private Set conditions; //general infomation private Date created; @@ -96,6 +98,7 @@ */ public TaskList(){ attachments = new HashSet(); + conditions = new HashSet(); taskListItems = new HashSet(); } @@ -151,6 +154,19 @@ } taskList.attachments = set; } + //clone conditions + if(conditions != null){ + Iterator iter = conditions.iterator(); + Set set = new HashSet(); + while(iter.hasNext()){ + TaskListCondition condition = (TaskListCondition)iter.next(); + TaskListCondition newCondition = (TaskListCondition) condition.clone(); + //just clone old file without duplicate it in repository + + set.add(newCondition); + } + taskList.conditions = set; + } //clone ReourceUser as well if(this.createdBy != null){ taskList.setCreatedBy((TaskListUser) this.createdBy.clone()); @@ -438,7 +454,33 @@ public void setAttachments(Set attachments) { this.attachments = attachments; } + + /** + * Returns a set of conditions belong to this tasklist. + * + * @return a set of conditions belong to this tasklist. + * + * @hibernate.set lazy="true" + * cascade="all" + * inverse="false" + * order-by="sequence_id asc" + * @hibernate.collection-key column="taskList_uid" + * @hibernate.collection-one-to-many + * class="org.lamsfoundation.lams.tool.taskList.model.TaskListCondition" + */ + public Set getConditions() { + return conditions; + } + /** + * Sets a set of Conditions belong to this tasklist + * + * @param conditions set of conditions to set + */ + public void setConditions(Set conditions) { + this.conditions = conditions; + } + /** * Return set of TaskListItems * Index: lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/model/TaskListItemComment.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/model/TaskListItemComment.java,v diff -u -r1.4 -r1.5 --- lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/model/TaskListItemComment.java 31 Mar 2008 06:09:45 -0000 1.4 +++ lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/model/TaskListItemComment.java 7 Apr 2008 07:33:31 -0000 1.5 @@ -46,8 +46,9 @@ private Date createDate; // ********************************************************** - // Function method for TaskListItemComment + // Function method for TaskListItemComment // ********************************************************** + public Object clone(){ TaskListItemComment taskListItemComment = null; try { @@ -85,7 +86,7 @@ } // ********************************************************** - // Get/Set methods + // Get/Set methods // ********************************************************** /** Index: lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/service/ITaskListService.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/service/ITaskListService.java,v diff -u -r1.8 -r1.9 --- lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/service/ITaskListService.java 2 Apr 2008 05:07:56 -0000 1.8 +++ lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/service/ITaskListService.java 7 Apr 2008 07:33:30 -0000 1.9 @@ -170,6 +170,13 @@ void deleteTaskListItem(Long uid); /** + * Delete tasklist condition from the database. + * + * @param uid + */ + void deleteTaskListCondition(Long uid); + + /** * Return all resource items within the given toolSessionID. * * @param sessionId @@ -325,10 +332,5 @@ */ TaskSummary getTaskSummary(Long contentId, Long taskListItemUid); - /** - * {@inheritDoc} - */ - public void deleteTaskListCondition(Long conditionUid); - } Index: lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/util/TaskListConditionComparator.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/util/TaskListConditionComparator.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/util/TaskListConditionComparator.java 7 Apr 2008 07:33:31 -0000 1.1 @@ -0,0 +1,51 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +/* $Id: TaskListConditionComparator.java,v 1.1 2008/04/07 07:33:31 andreyb Exp $ */ +package org.lamsfoundation.lams.tool.taskList.util; + +import java.util.Comparator; + +import org.lamsfoundation.lams.tool.taskList.model.TaskListCondition; + +/** + * Comparator for TaskListCondition. + * + * @author Andrey Balan + * @see org.lamsfoundation.lams.tool.taskList.model.TaskListCondition + */ +public class TaskListConditionComparator implements Comparator { + + /** + * {@inheritDoc} + */ + public int compare(TaskListCondition o1, TaskListCondition o2) { + if(o1 != null && o2 != null){ + return o1.getSequenceId() - o2.getSequenceId(); + }else if(o1 != null) + return 1; + else + return -1; + } + +} + \ No newline at end of file Index: lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/web/action/AuthoringAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/web/action/AuthoringAction.java,v diff -u -r1.4 -r1.5 --- lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/web/action/AuthoringAction.java 14 Mar 2008 08:01:00 -0000 1.4 +++ lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/web/action/AuthoringAction.java 7 Apr 2008 07:33:31 -0000 1.5 @@ -57,11 +57,13 @@ import org.lamsfoundation.lams.tool.taskList.TaskListConstants; import org.lamsfoundation.lams.tool.taskList.model.TaskList; import org.lamsfoundation.lams.tool.taskList.model.TaskListAttachment; +import org.lamsfoundation.lams.tool.taskList.model.TaskListCondition; import org.lamsfoundation.lams.tool.taskList.model.TaskListItem; import org.lamsfoundation.lams.tool.taskList.model.TaskListUser; import org.lamsfoundation.lams.tool.taskList.service.ITaskListService; import org.lamsfoundation.lams.tool.taskList.service.TaskListApplicationException; import org.lamsfoundation.lams.tool.taskList.service.UploadTaskListFileException; +import org.lamsfoundation.lams.tool.taskList.util.TaskListConditionComparator; import org.lamsfoundation.lams.tool.taskList.util.TaskListItemComparator; import org.lamsfoundation.lams.tool.taskList.web.form.TaskListForm; import org.lamsfoundation.lams.tool.taskList.web.form.TaskListItemForm; @@ -74,10 +76,14 @@ import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; - /** + * The main action in author mode. All the authoring operations are located in + * here. Except for operations dealing with TaskListCondition that are located + * in AuthoringTaskListConditionAction action. + * * @author Steve.Ni - * @version $Revision$ + * @author Andrey Balan + * @see org.lamsfoundation.lams.tool.taskList.web.action.AuthoringTaskListConditionAction */ public class AuthoringAction extends Action { @@ -86,7 +92,8 @@ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String param = mapping.getParameter(); - //-----------------------TaskList Author function --------------------------- + + //----------------------- solid taskList methods --------------------------- if(param.equals("start")){ ToolAccessMode mode = getAccessMode(request); //teacher mode "check for new" button enter. @@ -111,7 +118,6 @@ if (param.equals("initPage")) { return initPage(mapping, form, request, response); } - if (param.equals("updateContent")) { return updateContent(mapping, form, request, response); } @@ -127,7 +133,8 @@ if (param.equals("deleteOfflineFile")) { return deleteOfflineFile(mapping, form, request, response); } - //----------------------- Add taskList item function --------------------------- + + //----------------------- Add taskListItem methods --------------------------- if (param.equals("newItemInit")) { return newItemlInit(mapping, form, request, response); } @@ -146,190 +153,27 @@ if (param.equals("downItem")) { return downItem(mapping, form, request, response); } - + return mapping.findForward(TaskListConstants.ERROR); } - - /** - * 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 removeItem(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { - -// get back sessionMAP - String sessionMapID = WebUtil.readStrParam(request, TaskListConstants.ATTR_SESSION_MAP_ID); - SessionMap sessionMap = (SessionMap)request.getSession().getAttribute(sessionMapID); - - int itemIdx = NumberUtils.stringToInt(request.getParameter(TaskListConstants.PARAM_ITEM_INDEX),-1); - if(itemIdx != -1){ - SortedSet taskListList = getTaskListItemList(sessionMap); - List rList = new ArrayList(taskListList); - TaskListItem item = rList.remove(itemIdx); - taskListList.clear(); - taskListList.addAll(rList); - //add to delList - List delList = getDeletedTaskListItemList(sessionMap); - delList.add(item); - } - - request.setAttribute(TaskListConstants.ATTR_SESSION_MAP_ID, sessionMapID); - return mapping.findForward(TaskListConstants.SUCCESS); - } - /** - * Move up current item. - * - * @param mapping - * @param form - * @param request - * @param response - * @return - */ - private ActionForward upItem(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { - return switchItem(mapping, request, true); - } - - /** - * Move down current item. - * - * @param mapping - * @param form - * @param request - * @param response - * @return - */ - private ActionForward downItem(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { - return switchItem(mapping, request, false); - } + //********************************************************** + // Solid taskList methods + //********************************************************** - private ActionForward switchItem(ActionMapping mapping, HttpServletRequest request, boolean up) { -// get back sessionMAP - String sessionMapID = WebUtil.readStrParam(request, TaskListConstants.ATTR_SESSION_MAP_ID); - SessionMap sessionMap = (SessionMap)request.getSession().getAttribute(sessionMapID); - - int itemIdx = NumberUtils.stringToInt(request.getParameter(TaskListConstants.PARAM_ITEM_INDEX),-1); - if(itemIdx != -1){ - SortedSet taskListList = getTaskListItemList(sessionMap); - List rList = new ArrayList(taskListList); - //get current and the target item, and switch their sequnece - TaskListItem item = rList.get(itemIdx); - TaskListItem repItem; - if(up) - repItem = rList.get(--itemIdx); - else - repItem = rList.get(++itemIdx); - int upSeqId = repItem.getSequenceId(); - repItem.setSequenceId(item.getSequenceId()); - item.setSequenceId(upSeqId); - - //put back list, it will be sorted again - taskListList.clear(); - taskListList.addAll(rList); - } - - request.setAttribute(TaskListConstants.ATTR_SESSION_MAP_ID, sessionMapID); - return mapping.findForward(TaskListConstants.SUCCESS); - } - - /** - * Display edit page for existed taskList item. - * @param mapping - * @param form - * @param request - * @param response - * @return - */ - private ActionForward editItemInit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { - -// get back sessionMAP - String sessionMapID = WebUtil.readStrParam(request, TaskListConstants.ATTR_SESSION_MAP_ID); - SessionMap sessionMap = (SessionMap)request.getSession().getAttribute(sessionMapID); - - int itemIdx = NumberUtils.stringToInt(request.getParameter(TaskListConstants.PARAM_ITEM_INDEX),-1); - TaskListItem item = null; - if(itemIdx != -1){ - SortedSet taskListList = getTaskListItemList(sessionMap); - List rList = new ArrayList(taskListList); - item = rList.get(itemIdx); - if(item != null){ - populateItemToForm(itemIdx, item,(TaskListItemForm) form,request); - } - } - - return (item==null) ? null : mapping.findForward("task"); - } - /** - * Display empty page for new taskList item. - * @param mapping - * @param form - * @param request - * @param response - * @return - */ - private ActionForward newItemlInit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { - String sessionMapID = WebUtil.readStrParam(request, TaskListConstants.ATTR_SESSION_MAP_ID); - ((TaskListItemForm)form).setSessionMapID(sessionMapID); - - return mapping.findForward("task"); - } - /** - * This method will get necessary information from taskList item form and save or update into - * HttpSession TaskListItemList. 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 saveOrUpdateItem(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response){ - TaskListItemForm itemForm = (TaskListItemForm)form; - ActionErrors errors = validateTaskListItem(itemForm); - - if(!errors.isEmpty()){ - this.addErrors(request,errors); - return mapping.findForward("task"); - } - - try { - extractFormToTaskListItem(request, itemForm); - } catch (Exception e) { - //any upload exception will display as normal error message rather then throw exception directly - errors.add(ActionMessages.GLOBAL_MESSAGE,new ActionMessage(TaskListConstants.ERROR_MSG_UPLOAD_FAILED,e.getMessage())); - if(!errors.isEmpty()){ - this.addErrors(request,errors); - return mapping.findForward("task"); - } - } - //set session map ID so that itemlist.jsp can get sessionMAP - request.setAttribute(TaskListConstants.ATTR_SESSION_MAP_ID, itemForm.getSessionMapID()); - //return null to close this window - return mapping.findForward(TaskListConstants.SUCCESS); - } - - /** * Read taskList data from database and put them into HttpSession. It will redirect to init.do directly after this * method run successfully. * * This method will avoid read database again and lost un-saved resouce item lost when user "refresh page", * @throws ServletException - * */ private ActionForward start(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException { - //save toolContentID into HTTPSession + // save toolContentID into HTTPSession Long contentId = new Long(WebUtil.readLongParam(request,TaskListConstants.PARAM_TOOL_CONTENT_ID)); -// get back the taskList and item list and display them on page + // get back the taskList and item list and display them on page ITaskListService service = getTaskListService(); List items = null; @@ -368,6 +212,11 @@ throw new ServletException(e); } + //initialize conditions list + SortedSet conditionList = getTaskListConditionList(sessionMap); + conditionList.clear(); + conditionList.addAll(taskList.getConditions()); + //init it to avoid null exception in following handling if(items == null) items = new ArrayList(); @@ -394,8 +243,7 @@ sessionMap.put(TaskListConstants.ATTR_RESOURCE_FORM, taskListForm); return mapping.findForward(TaskListConstants.SUCCESS); } - - + /** * Display same entire authoring page content from HttpSession variable. * @param mapping @@ -405,8 +253,7 @@ * @return * @throws ServletException */ - private ActionForward initPage(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws ServletException { + private ActionForward initPage(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException { String sessionMapID = WebUtil.readStrParam(request, TaskListConstants.ATTR_SESSION_MAP_ID); SessionMap sessionMap = (SessionMap)request.getSession().getAttribute(sessionMapID); TaskListForm existForm = (TaskListForm) sessionMap.get(TaskListConstants.ATTR_RESOURCE_FORM); @@ -424,6 +271,7 @@ else return mapping.findForward(TaskListConstants.DEFINE_LATER); } + /** * This method will persist all inforamtion in this authoring page, include all taskList item, information etc. * @@ -434,8 +282,7 @@ * @return * @throws ServletException */ - private ActionForward updateContent(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws Exception { + private ActionForward updateContent(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { TaskListForm taskListForm = (TaskListForm)(form); //get back sessionMAP @@ -560,6 +407,20 @@ iter.remove(); } + //Handle taskList conditions + SortedSet conditions = getTaskListConditionList(sessionMap); + taskListPO.setConditions(conditions); + //delete instructino file from database. + List delTaskListConditionList = getDeletedTaskListConditionList(sessionMap); + iter = delTaskListConditionList.iterator(); + while(iter.hasNext()){ + TaskListCondition condition = (TaskListCondition) iter.next(); + iter.remove(); + if(condition.getUid() != null) + service.deleteTaskListCondition(condition.getUid()); + } + + //********************************************** //finally persist taskListPO again service.saveOrUpdateTaskList(taskListPO); @@ -575,7 +436,7 @@ else return mapping.findForward("monitor"); } - + /** * Handle upload online instruction files request. * @param mapping @@ -585,10 +446,11 @@ * @return * @throws UploadTaskListFileException */ - public ActionForward uploadOnline(ActionMapping mapping, ActionForm form, + private ActionForward uploadOnline(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws UploadTaskListFileException { return uploadFile(mapping, form, IToolContentHandler.TYPE_ONLINE,request); } + /** * Handle upload offline instruction files request. * @param mapping @@ -598,10 +460,11 @@ * @return * @throws UploadTaskListFileException */ - public ActionForward uploadOffline(ActionMapping mapping, ActionForm form, + private ActionForward uploadOffline(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws UploadTaskListFileException { return uploadFile(mapping, form, IToolContentHandler.TYPE_OFFLINE,request); } + /** * Common method to upload online or offline instruction files request. * @param mapping @@ -659,6 +522,7 @@ return mapping.findForward(TaskListConstants.SUCCESS); } + /** * Delete offline instruction file from current TaskList authoring page. * @param mapping @@ -667,10 +531,11 @@ * @param response * @return */ - public ActionForward deleteOfflineFile(ActionMapping mapping, ActionForm form, + private ActionForward deleteOfflineFile(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { return deleteFile(mapping,request, response,form, IToolContentHandler.TYPE_OFFLINE); } + /** * Delete online instruction file from current TaskList authoring page. * @param mapping @@ -679,7 +544,7 @@ * @param response * @return */ - public ActionForward deleteOnlineFile(ActionMapping mapping, ActionForm form, + private ActionForward deleteOnlineFile(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { return deleteFile(mapping, request, response,form, IToolContentHandler.TYPE_ONLINE); } @@ -721,8 +586,180 @@ return mapping.findForward(TaskListConstants.SUCCESS); } + + //********************************************************** + // Add taskListItem methods + //********************************************************** + + /** + * Display empty page for new taskList item. + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward newItemlInit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { + String sessionMapID = WebUtil.readStrParam(request, TaskListConstants.ATTR_SESSION_MAP_ID); + ((TaskListItemForm)form).setSessionMapID(sessionMapID); + + return mapping.findForward("task"); + } + + /** + * Display edit page for existed taskList item. + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward editItemInit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { + + // get back sessionMAP + String sessionMapID = WebUtil.readStrParam(request, TaskListConstants.ATTR_SESSION_MAP_ID); + SessionMap sessionMap = (SessionMap)request.getSession().getAttribute(sessionMapID); + + int itemIdx = NumberUtils.stringToInt(request.getParameter(TaskListConstants.PARAM_ITEM_INDEX),-1); + TaskListItem item = null; + if(itemIdx != -1){ + SortedSet taskListList = getTaskListItemList(sessionMap); + List rList = new ArrayList(taskListList); + item = rList.get(itemIdx); + if(item != null){ + populateItemToForm(itemIdx, item,(TaskListItemForm) form,request); + } + } + + return (item==null) ? null : mapping.findForward("task"); + } + + /** + * This method will get necessary information from taskList item form and save or update into + * HttpSession TaskListItemList. 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 saveOrUpdateItem(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response){ + TaskListItemForm itemForm = (TaskListItemForm)form; + ActionErrors errors = validateTaskListItem(itemForm); + + if(!errors.isEmpty()){ + this.addErrors(request,errors); + return mapping.findForward("task"); + } + + try { + extractFormToTaskListItem(request, itemForm); + } catch (Exception e) { + //any upload exception will display as normal error message rather then throw exception directly + errors.add(ActionMessages.GLOBAL_MESSAGE,new ActionMessage(TaskListConstants.ERROR_MSG_UPLOAD_FAILED,e.getMessage())); + if(!errors.isEmpty()){ + this.addErrors(request,errors); + return mapping.findForward("task"); + } + } + //set session map ID so that itemlist.jsp can get sessionMAP + request.setAttribute(TaskListConstants.ATTR_SESSION_MAP_ID, itemForm.getSessionMapID()); + //return null to close this window + return mapping.findForward(TaskListConstants.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 removeItem(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { + + // get back sessionMAP + String sessionMapID = WebUtil.readStrParam(request, TaskListConstants.ATTR_SESSION_MAP_ID); + SessionMap sessionMap = (SessionMap)request.getSession().getAttribute(sessionMapID); + + int itemIdx = NumberUtils.stringToInt(request.getParameter(TaskListConstants.PARAM_ITEM_INDEX),-1); + if(itemIdx != -1){ + SortedSet taskListList = getTaskListItemList(sessionMap); + List rList = new ArrayList(taskListList); + TaskListItem item = rList.remove(itemIdx); + taskListList.clear(); + taskListList.addAll(rList); + //add to delList + List delList = getDeletedTaskListItemList(sessionMap); + delList.add(item); + } + + request.setAttribute(TaskListConstants.ATTR_SESSION_MAP_ID, sessionMapID); + return mapping.findForward(TaskListConstants.SUCCESS); + } + + /** + * Move up current item. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward upItem(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { + return switchItem(mapping, request, true); + } + + /** + * Move down current item. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward downItem(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { + return switchItem(mapping, request, false); + } + + private ActionForward switchItem(ActionMapping mapping, HttpServletRequest request, boolean up) { +// get back sessionMAP + String sessionMapID = WebUtil.readStrParam(request, TaskListConstants.ATTR_SESSION_MAP_ID); + SessionMap sessionMap = (SessionMap)request.getSession().getAttribute(sessionMapID); + + int itemIdx = NumberUtils.stringToInt(request.getParameter(TaskListConstants.PARAM_ITEM_INDEX),-1); + if(itemIdx != -1){ + SortedSet taskListList = getTaskListItemList(sessionMap); + List rList = new ArrayList(taskListList); + //get current and the target item, and switch their sequnece + TaskListItem item = rList.get(itemIdx); + TaskListItem repItem; + if(up) + repItem = rList.get(--itemIdx); + else + repItem = rList.get(++itemIdx); + int upSeqId = repItem.getSequenceId(); + repItem.setSequenceId(item.getSequenceId()); + item.setSequenceId(upSeqId); + + //put back list, it will be sorted again + taskListList.clear(); + taskListList.addAll(rList); + } + + request.setAttribute(TaskListConstants.ATTR_SESSION_MAP_ID, sessionMapID); + return mapping.findForward(TaskListConstants.SUCCESS); + } + //************************************************************************************* - // Private method + // Private methods for internal needs //************************************************************************************* /** * Return TaskListService bean. @@ -757,12 +794,33 @@ sessionMap.put(TaskListConstants.ATTR_RESOURCE_ITEM_LIST,list); } return list; - } + } /** + * List save current taskList items. + * @param request + * @return + */ + private SortedSet getTaskListConditionList(SessionMap sessionMap) { + SortedSet list = (SortedSet) sessionMap.get(TaskListConstants.ATTR_CONDITION_LIST); + if(list == null){ + list = new TreeSet(new TaskListConditionComparator()); + sessionMap.put(TaskListConstants.ATTR_CONDITION_LIST,list); + } + return list; + } + /** * List save deleted taskList items, which could be persisted or non-persisted items. * @param request * @return */ + private List getDeletedTaskListConditionList(SessionMap sessionMap) { + return getListFromSession(sessionMap,TaskListConstants.ATTR_DELETED_CONDITION_LIST); + } + /** + * List save deleted taskList items, which could be persisted or non-persisted items. + * @param request + * @return + */ private List getDeletedTaskListItemList(SessionMap sessionMap) { return getListFromSession(sessionMap,TaskListConstants.ATTR_DELETED_RESOURCE_ITEM_LIST); } @@ -814,9 +872,9 @@ //FOR requirment from LDEV-754 //add extra blank line for instructions -// for(int idx=0;idxAuthoringAction action. + * + * @author Andrey Balan + * @see org.lamsfoundation.lams.tool.taskList.web.action.AuthoringAction + */ +public class AuthoringTaskListConditionAction extends Action { + + public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { + + String param = mapping.getParameter(); + + if (param.equals("showConditions")) { + return showConditions(mapping, form, request, response); + } + 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 mapping.findForward(TaskListConstants.ERROR); + } + + /** + * Display same entire authoring page content from HttpSession variable. + * @param mapping + * @param form + * @param request + * @param response + * @return + * @throws ServletException + */ + private ActionForward showConditions(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException { + String sessionMapID = WebUtil.readStrParam(request, TaskListConstants.ATTR_SESSION_MAP_ID); + SessionMap sessionMap = (SessionMap)request.getSession().getAttribute(sessionMapID); + TaskListForm existForm = (TaskListForm) sessionMap.get(TaskListConstants.ATTR_RESOURCE_FORM); + + TaskListForm taskListForm = (TaskListForm )form; + try { + PropertyUtils.copyProperties(taskListForm, existForm); + } catch (Exception e) { + throw new ServletException(e); + } + + ToolAccessMode mode = getAccessMode(request); + if(mode.isAuthor()) + return mapping.findForward(TaskListConstants.SUCCESS); + else + return mapping.findForward(TaskListConstants.DEFINE_LATER); + } + + /** + * 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, TaskListConstants.ATTR_SESSION_MAP_ID); + ((TaskListConditionForm)form).setSessionMapID(sessionMapID); + + populateFormWithPossibleItems(form, request); + 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) { + + // get back sessionMAP + String sessionMapID = WebUtil.readStrParam(request, TaskListConstants.ATTR_SESSION_MAP_ID); + SessionMap sessionMap = (SessionMap)request.getSession().getAttribute(sessionMapID); + + int sequenceId = NumberUtils.stringToInt(request.getParameter(TaskListConstants.PARAM_SEQUENCE_ID),-1); + TaskListCondition item = null; + if(sequenceId != -1){ + SortedSet conditionList = getTaskListConditionList(sessionMap); + List rList = new ArrayList(conditionList); + item = rList.get(sequenceId); + if(item != null){ + populateConditionToForm(sequenceId, item,(TaskListConditionForm) form,request); + } + } + + populateFormWithPossibleItems(form, request); + return (item==null) ? null : mapping.findForward("addcondition"); + } + + /** + * This method will get necessary information from taskList item form and save or update into + * HttpSession TaskListItemList. 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){ + + TaskListConditionForm conditionForm = (TaskListConditionForm)form; + ActionErrors errors = validateTaskListCondition(conditionForm, request); + + if(!errors.isEmpty()){ + populateFormWithPossibleItems(form, request); + this.addErrors(request,errors); + return mapping.findForward("addcondition"); + } + + try { + extractFormToTaskListCondition(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(TaskListConstants.ERROR_MSG_UPLOAD_FAILED,e.getMessage())); + if(!errors.isEmpty()){ + populateFormWithPossibleItems(form, request); + this.addErrors(request,errors); + return mapping.findForward("addcondition"); + } + } + //set session map ID so that itemlist.jsp can get sessionMAP + request.setAttribute(TaskListConstants.ATTR_SESSION_MAP_ID, conditionForm.getSessionMapID()); + //return null to close this window + return mapping.findForward(TaskListConstants.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, TaskListConstants.ATTR_SESSION_MAP_ID); + SessionMap sessionMap = (SessionMap)request.getSession().getAttribute(sessionMapID); + + int sequenceId = NumberUtils.stringToInt(request.getParameter(TaskListConstants.PARAM_SEQUENCE_ID),-1); + if(sequenceId != -1){ + SortedSet conditionList = getTaskListConditionList(sessionMap); + List rList = new ArrayList(conditionList); + TaskListCondition condition = rList.remove(sequenceId); + conditionList.clear(); + conditionList.addAll(rList); + //add to delList + List delList = getDeletedTaskListConditionList(sessionMap); + delList.add(condition); + } + + request.setAttribute(TaskListConstants.ATTR_SESSION_MAP_ID, sessionMapID); + return mapping.findForward(TaskListConstants.SUCCESS); + } + + /** + * Move up current item. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward upCondition(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { + return switchItem(mapping, request, true); + } + + /** + * Move down current item. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward downCondition(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { + return switchItem(mapping, request, false); + } + + private ActionForward switchItem(ActionMapping mapping, HttpServletRequest request, boolean up) { + // get back sessionMAP + String sessionMapID = WebUtil.readStrParam(request, TaskListConstants.ATTR_SESSION_MAP_ID); + SessionMap sessionMap = (SessionMap)request.getSession().getAttribute(sessionMapID); + + int sequenceId = NumberUtils.stringToInt(request.getParameter(TaskListConstants.PARAM_SEQUENCE_ID),-1); + if(sequenceId != -1){ + SortedSet conditionList = getTaskListConditionList(sessionMap); + List rList = new ArrayList(conditionList); + //get current and the target item, and switch their sequnece + TaskListCondition condition = rList.get(sequenceId); + TaskListCondition repCondition; + if(up) + repCondition = rList.get(--sequenceId); + else + repCondition = rList.get(++sequenceId); + int upSeqId = repCondition.getSequenceId(); + repCondition.setSequenceId(condition.getSequenceId()); + condition.setSequenceId(upSeqId); + + //put back list, it will be sorted again + conditionList.clear(); + conditionList.addAll(rList); + } + + request.setAttribute(TaskListConstants.ATTR_SESSION_MAP_ID, sessionMapID); + return mapping.findForward(TaskListConstants.SUCCESS); + } + + + + + + + + + + + + + + + + + + //************************************************************************************* + // Private methods for internal needs + //************************************************************************************* + /** + * Return TaskListService bean. + */ + private ITaskListService getTaskListService() { + WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet().getServletContext()); + return (ITaskListService) wac.getBean(TaskListConstants.RESOURCE_SERVICE); + } + + /** + * List save current taskList items. + * @param request + * @return + */ + private SortedSet getTaskListConditionList(SessionMap sessionMap) { + SortedSet list = (SortedSet) sessionMap.get(TaskListConstants.ATTR_CONDITION_LIST); + if(list == null){ + list = new TreeSet(new TaskListConditionComparator()); + sessionMap.put(TaskListConstants.ATTR_CONDITION_LIST,list); + } + return list; + } + + /** + * List save current taskList items. + * @param request + * @return + */ + private SortedSet getTaskListItemList(SessionMap sessionMap) { + SortedSet list = (SortedSet) sessionMap.get(TaskListConstants.ATTR_RESOURCE_ITEM_LIST); + if(list == null){ + list = new TreeSet(new TaskListItemComparator()); + sessionMap.put(TaskListConstants.ATTR_RESOURCE_ITEM_LIST,list); + } + return list; + } + + /** + * List save deleted taskList items, which could be persisted or non-persisted items. + * @param request + * @return + */ + private List getDeletedTaskListConditionList(SessionMap sessionMap) { + return getListFromSession(sessionMap,TaskListConstants.ATTR_DELETED_CONDITION_LIST); + } + + /** + * Get java.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 sequenceId + * @param condition + * @param form + * @param request + */ + private void populateConditionToForm(int sequenceId, TaskListCondition condition, TaskListConditionForm form, HttpServletRequest request) { + if(sequenceId >=0) + form.setSequenceId(new Integer(sequenceId).toString()); + form.setName(condition.getName()); + + Set itemList = condition.getTaskListItems(); + String[] selectedItems = new String[itemList.size()]; + int i = 0; + for (TaskListItem item:itemList) { + selectedItems[i++] = (new Integer(item.getSequenceId())).toString(); + } + form.setSelectedItems(selectedItems); + } + + /** + * This method will populate taskList item information to its form for edit use. + * @param sequenceId + * @param condition + * @param form + * @param request + */ + private void populateFormWithPossibleItems(ActionForm form, HttpServletRequest request) { + + // get back sessionMAP + String sessionMapID = WebUtil.readStrParam(request, TaskListConstants.ATTR_SESSION_MAP_ID); + SessionMap sessionMap = (SessionMap)request.getSession().getAttribute(sessionMapID); + + SortedSet itemList = getTaskListItemList(sessionMap); + + // Initialise the LabelValueBeans in the possibleOptions array. + LabelValueBean[] lvBeans = new LabelValueBean[itemList.size()]; + + int i = 0; + for (TaskListItem item:itemList) { + lvBeans[i++] = new LabelValueBean(item.getTitle(), (new Integer(item.getSequenceId())).toString()); + } + ((TaskListConditionForm)form).setPossibleItems(lvBeans); + } + + + /** + * Extract form content to taskListContent. + * @param request + * @param form + * @throws TaskListApplicationException + */ + private void extractFormToTaskListCondition(HttpServletRequest request, TaskListConditionForm form) throws Exception { + /* BE CAREFUL: This method will copy necessary info from request form to a old or new TaskListItem instance. + * It gets all info EXCEPT TaskListItem.createDate and TaskListItem.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 conditionList = getTaskListConditionList(sessionMap); + int sequenceId = NumberUtils.stringToInt(form.getSequenceId(),-1); + TaskListCondition condition = null; + + if(sequenceId == -1){ //add + condition = new TaskListCondition(); + int maxSeq = 1; + if(conditionList != null && conditionList.size() > 0){ + TaskListCondition last = conditionList.last(); + maxSeq = last.getSequenceId() + 1; + } + condition.setSequenceId(maxSeq); + conditionList.add(condition); + }else{ //edit + List rList = new ArrayList(conditionList); + condition = rList.get(sequenceId); + } + + condition.setName(form.getName()); + + String[] selectedItems = form.getSelectedItems(); + SortedSet itemList = getTaskListItemList(sessionMap); + SortedSet conditionItemList = new TreeSet(new TaskListItemComparator()); + + for (String selectedItem:selectedItems){ + for (TaskListItem item:itemList) { + if (selectedItem.equals((new Integer(item.getSequenceId())).toString())) + conditionItemList.add(item); + } + } + condition.setTaskListItems(conditionItemList); + + } + + /** + * Validate taskListCondition + * @param conditionForm + * @return + */ + private ActionErrors validateTaskListCondition(TaskListConditionForm conditionForm, HttpServletRequest request) { + ActionErrors errors = new ActionErrors(); + if(StringUtils.isBlank(conditionForm.getName())) { + errors.add(ActionMessages.GLOBAL_MESSAGE,new ActionMessage(TaskListConstants.ERROR_MSG_NAME_BLANK)); + } else { + String formConditionName = conditionForm.getName(); + String formConditionSequenceId = conditionForm.getSequenceId(); + + String sessionMapID = conditionForm.getSessionMapID(); + SessionMap sessionMap = (SessionMap)request.getSession().getAttribute(sessionMapID); + SortedSet conditionList = getTaskListConditionList(sessionMap); + for(TaskListCondition condition:conditionList) { + if (formConditionName.equals(condition.getName()) && !formConditionSequenceId.equals((new Integer(condition.getSequenceId() - 1)).toString())) { + errors.add(ActionMessages.GLOBAL_MESSAGE,new ActionMessage(TaskListConstants.ERROR_MSG_NAME_DUPLICATED)); + break; + } + } + } + + //should be selected at least one TaskListItem + String[] selectedItems = conditionForm.getSelectedItems(); + if ((selectedItems == null) || (selectedItems.length == 0)) { + errors.add(ActionMessages.GLOBAL_MESSAGE,new ActionMessage(TaskListConstants.ERROR_MSG_NO_TASK_LIST_ITEMS)); + } + + return errors; + } + + /** + * Get ToolAccessMode from HttpRequest parameters. Default value is AUTHOR mode. + * @param request + * @return + */ + private ToolAccessMode getAccessMode(HttpServletRequest request) { + ToolAccessMode mode; + String modeStr = request.getParameter(AttributeNames.ATTR_MODE); + if(StringUtils.equalsIgnoreCase(modeStr,ToolAccessMode.TEACHER.toString())) + mode = ToolAccessMode.TEACHER; + else + mode = ToolAccessMode.AUTHOR; + return mode; + } + + + private ActionMessages validate(TaskListForm taskListForm, ActionMapping mapping, HttpServletRequest request) { + ActionMessages errors = new ActionMessages(); + // if (StringUtils.isBlank(taskListForm.getTaskList().getTitle())) { + // ActionMessage error = new ActionMessage("error.resource.item.title.blank"); + // errors.add(ActionMessages.GLOBAL_MESSAGE, error); + // } + + //define it later mode(TEACHER) skip below validation. + String modeStr = request.getParameter(AttributeNames.ATTR_MODE); + if(StringUtils.equals(modeStr, ToolAccessMode.TEACHER.toString())){ + return errors; + } + + //Some other validation outside basic Tab. + + return errors; + } + +} + \ No newline at end of file Index: lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/web/form/TaskListConditionForm.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/web/form/TaskListConditionForm.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/web/form/TaskListConditionForm.java 7 Apr 2008 07:33:30 -0000 1.1 @@ -0,0 +1,166 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +/* $Id: TaskListConditionForm.java,v 1.1 2008/04/07 07:33:30 andreyb Exp $ */ +package org.lamsfoundation.lams.tool.taskList.web.form; + +import org.apache.struts.action.ActionForm; +import org.apache.struts.upload.FormFile; +import org.apache.struts.util.LabelValueBean; + +/** + * Form responsible for representing TaskListCondition objects on a view layer. + * + * @author Andrey Balan + * + * @struts.form name="taskListConditionForm" + */ +public class TaskListConditionForm extends ActionForm { + + //tool access mode; + private String mode; + private String sessionMapID; + + private String sequenceId; + private String name; +// private String taskListItemName; + private LabelValueBean[] possibleItems; + private String[] selectedItems; + + public TaskListConditionForm() { + super(); + LabelValueBean[] lvBeans = new LabelValueBean[4]; + + lvBeans[0] = new LabelValueBean("Alpha", "A"); + lvBeans[1] = new LabelValueBean("Beta", "B"); + lvBeans[2] = new LabelValueBean("Charlie", "C"); + lvBeans[3] = new LabelValueBean("Delta", "D"); + + this.possibleItems = lvBeans; + } + + /** + * Returns TaskListCondition name. + * + * @return TaskListCondition name + */ + public String getName() { + return name; + } + /** + * Sets TaskListCondition title. + * + * @param title TaskListCondition title + */ + public void setName(String name) { + this.name = name; + } + + /** + * Returns TaskListCondition sequence Id. + * + * @return TaskListCondition sequence Id + */ + public String getSequenceId() { + return sequenceId; + } + /** + * Sets TaskListCondition sequence Id. + * + * @param sequenceId TaskListCondition sequence Id + */ + public void setSequenceId(String sequenceId) { + this.sequenceId = sequenceId; + } + + /** + * Returns current SessionMapID. + * + * @return current SessionMapID + */ + public String getSessionMapID() { + return sessionMapID; + } + /** + * Sets current SessionMapID. + * + * @param sessionMapID current SessionMapID + */ + public void setSessionMapID(String sessionMapID) { + this.sessionMapID = sessionMapID; + } + + /** + * Returns working mode. + * + * @return working mode + */ + public String getMode() { + return mode; + } + /** + * Returns working mode. + * + * @param mode working mode + */ + public void setMode(String mode) { + this.mode = mode; + } + +// /** +// * Returns TaskLiskItem name. +// * +// * @return TaskLiskItem name +// */ +// public String getTaskListItemName() { +// return taskListItemName; +// } +// /** +// * Sets TaskLiskItem name. +// * +// * @param taskListItemName TaskLiskItem name +// */ +// public void setTaskListItemName(String taskListItemName) { +// this.taskListItemName = taskListItemName; +// } + + + + public LabelValueBean[] getPossibleItems() { + return possibleItems; + } + + public void setPossibleItems(LabelValueBean[] lvBeans) { + this.possibleItems = lvBeans; + } + + public String[] getSelectedItems() { + return selectedItems; + } + + public void setSelectedItems(String[] selectedItems) { + this.selectedItems = selectedItems; + } + +} + + \ No newline at end of file Index: lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/web/form/TaskListItemForm.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/web/form/TaskListItemForm.java,v diff -u -r1.5 -r1.6 --- lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/web/form/TaskListItemForm.java 31 Mar 2008 06:09:45 -0000 1.5 +++ lams_tool_task/src/java/org/lamsfoundation/lams/tool/taskList/web/form/TaskListItemForm.java 7 Apr 2008 07:33:30 -0000 1.6 @@ -25,12 +25,14 @@ import org.apache.struts.action.ActionForm; import org.apache.struts.upload.FormFile; + /** - * TaskList Item Form. - * @struts.form name="taskListItemForm" + * Form responsible for representing TaskListItem objects on a view layer. + * * @author Steve.Ni + * @author Andrey Balan * - * @version $Revision$ + * @struts.form name="taskListItemForm" */ public class TaskListItemForm extends ActionForm { private String itemIndex; @@ -52,82 +54,206 @@ private FormFile uploadedFile; private String comment; - public String getDescription() { - return description; - } - public void setDescription(String description) { - this.description = description; - } + /** + * Returns TaskListItem title. + * + * @return TaskListItem title + */ public String getTitle() { return title; } + /** + * Sets TaskListItem title. + * + * @param title TaskListItem title + */ public void setTitle(String title) { this.title = title; } + + /** + * Returns TaskListItem description. + * + * @return TaskListItem description + */ + public String getDescription() { + return description; + } + /** + * Sets TaskListItem description. + * + * @param description TaskListItem description + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * Returns TaskListItem order index. + * + * @return TaskListItem order index + */ public String getItemIndex() { return itemIndex; } + /** + * Sets TaskListItem order index. + * + * @param itemIndex TaskListItem order index + */ public void setItemIndex(String itemIndex) { this.itemIndex = itemIndex; } + + /** + * Returns current SessionMapID. + * + * @return current SessionMapID + */ public String getSessionMapID() { return sessionMapID; } + /** + * Sets current SessionMapID. + * + * @param sessionMapID current SessionMapID + */ public void setSessionMapID(String sessionMapID) { this.sessionMapID = sessionMapID; } + + /** + * Returns working mode. + * + * @return working mode + */ public String getMode() { return mode; } + /** + * Returns working mode. + * + * @param mode working mode + */ public void setMode(String mode) { this.mode = mode; } + /** + * Returns whether this TaskLiskItem is required to finish activity. + * + * @return true if the TaskLiskItem is required to finish activity, false otherwise. + */ public boolean isRequired() { return isRequired; } + /** + * Sets whether this TaskLiskItem is required to finish activity. + * + * @param isRequired true if the TaskLiskItem is required to finish activity, false otherwise. + */ public void setRequired(boolean isRequired) { this.isRequired = isRequired; } + /** + * Returns whether comments are allowed in this TaskLiskItem. + * + * @return true if comments are allowed in this TaskLiskItem, false otherwise. + */ public boolean isCommentsAllowed() { return isCommentsAllowed; } + /** + * Sets whether comments are allowed in this TaskLiskItem. + * + * @param isCommentsAllowed true if comments are allowed in this TaskLiskItem, false otherwise. + */ public void setCommentsAllowed(boolean isCommentsAllowed) { this.isCommentsAllowed = isCommentsAllowed; } + /** + * Returns whether comments are allowed to be shown to everybody for this TaskLiskItem. + * + * @return true if comments are allowed to be shown to everybody for this TaskLiskItem, false otherwise. + */ public boolean getShowCommentsToAll() { return showCommentsToAll; } + /** + * Sets whether comments are allowed to be shown to everybody for this TaskLiskItem or not. + * + * @param showCommentsToAll true if comments are allowed to be shown to everybody for this TaskLiskItem, false otherwise. + */ public void setShowCommentsToAll(boolean showCommentsToAll) { this.showCommentsToAll = showCommentsToAll; } + /** + * Returns whether this TaskLiskItem is a child task. + * + * @return true if this TaskLiskItem is a child task, false otherwise. + */ public boolean isChildTask() { return isChildTask; } + /** + * Sets whether this TaskLiskItem is a child task or not. + * + * @param isChildTask true if this TaskLiskItem is a child task, false otherwise. + */ public void setChildTask(boolean isChildTask) { this.isChildTask = isChildTask; } + /** + * If the TaskLiskItem is a child task then it has a parent. So this method returns its title. + * + * @return parent's title + */ public String getParentTaskName() { return parentTaskName; } + /** + * If the TaskLiskItem is a child task then it has a parent. So this method sets its title. + * + * @param parentTaskName parent's title + */ public void setParentTaskName(String parentTaskName) { this.parentTaskName = parentTaskName; } + /** + * Returns attachment for this TaskLiskItem. + * + * @return attachment for this TaskLiskItem + */ public FormFile getUploadedFile() { return uploadedFile; } + /** + * Sets attachment for this TaskLiskItem. + * + * @param uploadedFile attachment for this TaskLiskItem + */ public void setUploadedFile(FormFile uploadedFile) { this.uploadedFile = uploadedFile; } + /** + * Returns comment for this TaskLiskItem. + * + * @return comment for this TaskLiskItem + */ public String getComment() { return comment; } + /** + * Sets comment for this TaskLiskItem. + * + * @param comment comment for this TaskLiskItem + */ public void setComment(String comment) { this.comment = comment; } Index: lams_tool_task/web/pages/authoring/authoring.jsp =================================================================== RCS file: /usr/local/cvsroot/lams_tool_task/web/pages/authoring/authoring.jsp,v diff -u -r1.2 -r1.3 --- lams_tool_task/web/pages/authoring/authoring.jsp 14 Mar 2008 08:01:01 -0000 1.2 +++ lams_tool_task/web/pages/authoring/authoring.jsp 7 Apr 2008 07:33:31 -0000 1.3 @@ -27,6 +27,10 @@ var tag = document.getElementById("currentTab"); tag.value = tabId; // end optional tab controller stuff + + //if we're leaving Condition tab its addCondition area should be closed + if (tabId != 4) window.parent.hideConditionMessage(); + selectTab(tabId); } @@ -55,6 +59,7 @@ +
@@ -83,6 +88,9 @@ + + + <%-- Default value Index: lams_tool_task/web/pages/authoring/basic.jsp =================================================================== RCS file: /usr/local/cvsroot/lams_tool_task/web/pages/authoring/basic.jsp,v diff -u -r1.1 -r1.2 --- lams_tool_task/web/pages/authoring/basic.jsp 28 Feb 2008 03:50:18 -0000 1.1 +++ lams_tool_task/web/pages/authoring/basic.jsp 7 Apr 2008 07:33:31 -0000 1.2 @@ -128,7 +128,7 @@

- ');" class="button-add-item"> + ');" class="button-add-item">

Index: lams_tool_task/web/pages/authoring/conditions.jsp =================================================================== RCS file: /usr/local/cvsroot/lams_tool_task/web/pages/authoring/conditions.jsp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tool_task/web/pages/authoring/conditions.jsp 7 Apr 2008 07:33:31 -0000 1.1 @@ -0,0 +1,122 @@ +<%@ include file="/common/taglibs.jsp"%> + + + + + +
+ + <%@ include file="/pages/authoring/parts/conditionlist.jsp"%> +
+ +

+ ');" class="button-add-item"> + +

+ + +

+ +

Index: lams_tool_task/web/pages/authoring/parts/addcondition.jsp =================================================================== RCS file: /usr/local/cvsroot/lams_tool_task/web/pages/authoring/parts/addcondition.jsp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tool_task/web/pages/authoring/parts/addcondition.jsp 7 Apr 2008 07:33:30 -0000 1.1 @@ -0,0 +1,52 @@ + +<%@ include file="/common/taglibs.jsp"%> + + + + <%@ include file="/common/header.jsp"%> + + + + + + <%@ include file="/common/messages.jsp"%> + + + + +

+ +

+ +
+ +
+ +
+ +
+ + + + + + + + + + + +
+
+ +
+ + + + + + +
Index: lams_tool_task/web/pages/authoring/parts/addtask.jsp =================================================================== RCS file: /usr/local/cvsroot/lams_tool_task/web/pages/authoring/parts/addtask.jsp,v diff -u -r1.2 -r1.3 --- lams_tool_task/web/pages/authoring/parts/addtask.jsp 28 Feb 2008 09:06:23 -0000 1.2 +++ lams_tool_task/web/pages/authoring/parts/addtask.jsp 7 Apr 2008 07:33:30 -0000 1.3 @@ -14,7 +14,6 @@ -

Index: lams_tool_task/web/pages/authoring/parts/conditionlist.jsp =================================================================== RCS file: /usr/local/cvsroot/lams_tool_task/web/pages/authoring/parts/conditionlist.jsp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tool_task/web/pages/authoring/parts/conditionlist.jsp 7 Apr 2008 07:33:30 -0000 1.1 @@ -0,0 +1,73 @@ +<%@ include file="/common/taglibs.jsp"%> + + + + + + +
+

+ + +

+ + + + + + + + + + + + + + + +
+ ${condition.name} + + + " + onclick="upCondition(${status.index},'${sessionMapID}')"> + + "> + + + + + + "> + + + " + onclick="downCondition(${status.index},'${sessionMapID}')"> + + + " + onclick="editCondition(${status.index},'${sessionMapID}')" /> + + " + onclick="deleteCondition(${status.index},'${sessionMapID}')" /> +
+
+ +<%-- This script will works when a new resoruce Condition submit in order to refresh "TaskList List" panel. --%> +