Index: lams_tool_lamc/conf/hibernate/mappings/org/lamsfoundation/lams/tool/mc/pojos/McContent.hbm.xml =================================================================== diff -u -rbe07c35c372d904a65581d98660e73f3b13b69db -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/conf/hibernate/mappings/org/lamsfoundation/lams/tool/mc/pojos/McContent.hbm.xml (.../McContent.hbm.xml) (revision be07c35c372d904a65581d98660e73f3b13b69db) +++ lams_tool_lamc/conf/hibernate/mappings/org/lamsfoundation/lams/tool/mc/pojos/McContent.hbm.xml (.../McContent.hbm.xml) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -110,14 +110,6 @@ column="created_by" length="20" /> - - - @@ -98,21 +97,5 @@ /> - - - - - - - - - Fisheye: Tag 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f refers to a dead (removed) revision in file `lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/EditActivityDTO.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McAppConstants.java =================================================================== diff -u -rbe07c35c372d904a65581d98660e73f3b13b69db -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McAppConstants.java (.../McAppConstants.java) (revision be07c35c372d904a65581d98660e73f3b13b69db) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McAppConstants.java (.../McAppConstants.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -35,12 +35,8 @@ /* * Struts level constants */ - public static final String LOAD = "load"; - public static final String LOAD_QUESTIONS = "load"; - public static final String LOAD_STARTER = "starter"; - public static final String AUTHORING_STARTER = "starter"; + public static final String LOAD_AUTHORING = "authoringTabsHolder"; public static final String LEARNING_STARTER = "learningStarter"; - public static final String MONITORING_STARTER = "monitoringStarter"; public static final String LOAD_LEARNER = "loadLearner"; public static final String LOAD_MONITORING_CONTENT = "loadMonitoring"; public static final String LOAD_MONITORING = "refreshMonitoring"; @@ -56,40 +52,26 @@ public static final String LEARNER_PROGRESS_USERID = "learnerProgressUserId"; public static final String ACTIVITY_TITLE_KEY = "activityTitleKey"; public static final String ACTIVITY_INSTRUCTIONS_KEY = "activityInstructionsKey"; - public static final String LIST_QUESTION_CONTENT_DTO = "listQuestionContentDTO"; - public static final String LIST_QUESTION_CONTENT_DTO_KEY = "listQuestionContentDTOKey"; - public static final String MAP_QUESTION_CONTENT_KEY = "mapQuestionContentKey"; + public static final String LIST_QUESTION_DTOS = "listQuestionContentDTO"; + public static final String LIST_DELETED_QUESTION_DTOS = "deletedQuestionDTOs"; public static final String LOAD_VIEW_ONLY = "loadViewOnly"; public static final String MC_GENERAL_AUTHORING_DTO = "mcGeneralAuthoringDTO"; - public static final String DEFAULT_CONTENT_ID_STR = "defaultContentIdStr"; public static final String LIST_ADD_QUESTION_CONTENT_DTO_KEY = "listAddQuestionContentDtoKey"; public static final String NEW_QUESTION_CONTENT_DTO = "newQuestionContentDTO"; - public static final Integer MAX_QUESTION_COUNT = new Integer(50); - public static final String EDIT_ACTIVITY_DTO = "editActivityDTO"; public static final String LIST_CANDIDATE_ANSWERS_DTO = "listCandidateAnswersDTO"; public static final String CURRENT_EDITABLE_QUESTION_INDEX = "currentEditableQuestionIndex"; public static final String MC_GENERAL_MONITORING_DTO = "mcGeneralMonitoringDTO"; public static final String NOTEBOOK_ENTRIES_EXIST = "notebookEntriesExist"; public static final String NO_SESSIONS_NOTEBOOK_ENTRIES_EXIST = "noSessionsNotebookEntriesExist"; public static final String MONITORING = "monitoring"; public static final String RESPONSE_ID = "responseId"; - public static final String CURRENT_UID = "currentUid"; public static final String NEW_QUESTION_BOX_DTO = "newQuestionBoxDTO"; - public static final String NEW_QUESTION_BOX_DTO_KEY = "newQuestionBoxDTOKey"; - public static final String PASSMARK_MAP = "passmarkMap"; - public static final String NEW_ADDABLE_QUESTION_CONTENT = "newAddableQuestionContent"; - public static final String NEW_ADDABLE_QUESTION_CONTENT_KEY = "newAddableQuestionContentKey"; - public static final String NEW_ADDABLE_QUESTION_CONTENT_LIST = "newAddableQuestionContentList"; + public static final String NEW_QUESTION_DTO = "newQuestionDTO"; public static final String TOTAL_MARKS_POSSIBLE = "totalMarksPossible"; - public static final String AUTHORING = "authoring"; - public static final String SOURCE_MC_STARTER = "sourceMcStarter"; - public static final String TARGET_MODE_AUTHORING = "Authoring"; public static final String AUTHORING_CANCELLED = "authoringCancelled"; public static final String DEFINE_LATER_EDIT_ACTIVITY = "defineLaterEditActivity"; - public static final String ACTIVE_MODULE = "activeModule"; public static final String EDIT_OPTIONS_MODE = "editOptionsMode"; - public static final String DEFINE_LATER_IN_EDIT_MODE = "defineLaterInEditMode"; public static final String SUBMIT_SUCCESS = "sbmtSuccess"; public static final String QUESTION_INDEX = "questionIndex"; public static final String REFLECTION_SUBJECT = "reflectionSubject"; @@ -113,17 +95,10 @@ public static final String MAX_QUESTION_INDEX = "maxQuestionIndex"; public static final String COPY_TOOL_CONTENT = "copyToolContent"; public static final String REMOVE_TOOL_CONTENT = "removeToolContent"; - public static final String SIMPLE_LEARNING_ERROR = "simpleLearningError"; public static final String DEFAULT_MCQ_TITLE = "MCQ"; - public static final String DEFAULT_MCQ_INSTRUCTIONS = "Instructions"; - /* - * refers to number of questions presented initially, we have a single record for default content - */ - public static final Long INITIAL_QUESTION_COUNT = new Long(1); public static final int MAX_OPTION_COUNT = 25; - public static final int MAX_ATTEMPT_HISTORY = 30; public static final String QUESTION_AND_CANDIDATE_ANSWERS_KEY = "questionAndCandidateAnswersKey"; /* @@ -177,8 +152,7 @@ public static final String TITLE = "title"; public static final String INSTRUCTIONS = "instructions"; public static final String CREATION_DATE = "creationDate"; - public static final String DEFINE_LATER = "defineLater"; - public static final String WAIT_FOR_LEADER = "waitForLeader"; + public static final String WAIT_FOR_LEADER = "waitForLeader"; public static final String RETRIES = "retries"; public static final String PASSMARK = "passMark"; public static final String VIEW_ANSWERS = "viewAnswers"; @@ -213,7 +187,6 @@ /* * the learner or monitoring environment provides toolSessionId */ - public final long ONE_DAY = 60 * 60 * 1000 * 24; public final static String NOT_ATTEMPTED = "NOT_ATTEMPTED"; public final static String INCOMPLETE = "INCOMPLETE"; public static final String COMPLETED = "COMPLETED"; Fisheye: Tag 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f refers to a dead (removed) revision in file `lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McCandidateAnswersDTO.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McGeneralAuthoringDTO.java =================================================================== diff -u -rbe07c35c372d904a65581d98660e73f3b13b69db -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McGeneralAuthoringDTO.java (.../McGeneralAuthoringDTO.java) (revision be07c35c372d904a65581d98660e73f3b13b69db) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McGeneralAuthoringDTO.java (.../McGeneralAuthoringDTO.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -24,51 +24,29 @@ /* $$Id$$ */ package org.lamsfoundation.lams.tool.mc; -import java.util.List; import java.util.Map; -import org.apache.commons.lang.builder.ToStringBuilder; - /** - *

* DTO that holds authoring properties for authoring jsps - *

* * @author Ozgur Demirtas */ public class McGeneralAuthoringDTO implements Comparable { protected String toolContentID; protected String currentTab; - protected String activeModule; - protected String defineLaterInEditMode; - protected String showAuthoringTabs; - protected String monitoringOriginatedDefineLater; - protected String targetMode; - protected String defaultQuestionContent; - protected String defaultContentIdStr; protected String activityTitle; protected String activityInstructions; protected String usernameVisible; protected String reflect; - protected String synchInMonitor; protected String questionsSequenced; protected String randomize; protected String displayAnswers; - protected String editActivityEditMode; protected String reflectionSubject; protected String showMarks; - protected String monitoredContentInUse; - protected String httpSessionID; - protected String requestedModule; - protected String isDefineLater; - protected Map mapQuestionContent; - protected String sbmtSuccess; - protected String userExceptionQuestionsDuplicate; - protected String contentFolderID; protected String editableQuestionText; protected String editableQuestionFeedback; @@ -84,43 +62,7 @@ protected String totalMarks; - public String toString() { - return new ToStringBuilder(this).append("toolContentID: ", toolContentID) - .append("contentFolderID: ", contentFolderID).append("httpSessionID: ", httpSessionID) - .append("editableQuestionText: ", editableQuestionText).append("passMarksMap: ", passMarksMap) - .append("totalMarks: ", totalMarks).append("marksMap: ", marksMap).append("currentTab: ", currentTab) - .append("markValue: ", markValue).append("activeModule: ", activeModule) - .append("defineLaterInEditMode: ", defineLaterInEditMode) - .append("showAuthoringTabs: ", showAuthoringTabs) - .append("monitoringOriginatedDefineLater: ", monitoringOriginatedDefineLater) - .append("targetMode: ", targetMode).append("defaultQuestionContent: ", defaultQuestionContent) - .append("defaultContentIdStr: ", defaultContentIdStr).append("activityTitle: ", activityTitle) - .append("activityInstructions: ", activityInstructions).append("reflect: ", reflect) - .append("usernameVisible: ", usernameVisible) - .append("synchInMonitor: ", synchInMonitor).append("questionsSequenced: ", questionsSequenced) - .append("editActivityEditMode: ", editActivityEditMode) - .append("reflectionSubject: ", reflectionSubject).append("requestedModule: ", requestedModule) - .append("isDefineLater: ", isDefineLater).append("monitoredContentInUse: ", monitoredContentInUse) - .append("mapQuestionContent: ", mapQuestionContent).append("sbmtSuccess: ", sbmtSuccess) - .append("userExceptionQuestionsDuplicate: ", userExceptionQuestionsDuplicate).toString(); - } - /** - * @return Returns the userExceptionQuestionsDuplicate. - */ - public String getUserExceptionQuestionsDuplicate() { - return userExceptionQuestionsDuplicate; - } - - /** - * @param userExceptionQuestionsDuplicate - * The userExceptionQuestionsDuplicate to set. - */ - public void setUserExceptionQuestionsDuplicate(String userExceptionQuestionsDuplicate) { - this.userExceptionQuestionsDuplicate = userExceptionQuestionsDuplicate; - } - - /** * @return Returns the httpSessionID. */ public String getHttpSessionID() { @@ -136,66 +78,6 @@ } /** - * @return Returns the monitoredContentInUse. - */ - public String getMonitoredContentInUse() { - return monitoredContentInUse; - } - - /** - * @param monitoredContentInUse - * The monitoredContentInUse to set. - */ - public void setMonitoredContentInUse(String monitoredContentInUse) { - this.monitoredContentInUse = monitoredContentInUse; - } - - /** - * @return Returns the editActivityEditMode. - */ - public String getEditActivityEditMode() { - return editActivityEditMode; - } - - /** - * @param editActivityEditMode - * The editActivityEditMode to set. - */ - public void setEditActivityEditMode(String editActivityEditMode) { - this.editActivityEditMode = editActivityEditMode; - } - - /** - * @return Returns the mapQuestionContent. - */ - public Map getMapQuestionContent() { - return mapQuestionContent; - } - - /** - * @param mapQuestionContent - * The mapQuestionContent to set. - */ - public void setMapQuestionContent(Map mapQuestionContent) { - this.mapQuestionContent = mapQuestionContent; - } - - /** - * @return Returns the isDefineLater. - */ - public String getIsDefineLater() { - return isDefineLater; - } - - /** - * @param isDefineLater - * The isDefineLater to set. - */ - public void setIsDefineLater(String isDefineLater) { - this.isDefineLater = isDefineLater; - } - - /** * @return Returns the toolContentID. */ public String getToolContentID() { @@ -210,81 +92,6 @@ this.toolContentID = toolContentID; } - /** - * @return Returns the targetMode. - */ - public String getTargetMode() { - return targetMode; - } - - /** - * @param targetMode - * The targetMode to set. - */ - public void setTargetMode(String targetMode) { - this.targetMode = targetMode; - } - - /** - * @return Returns the monitoringOriginatedDefineLater. - */ - public String getMonitoringOriginatedDefineLater() { - return monitoringOriginatedDefineLater; - } - - /** - * @param monitoringOriginatedDefineLater - * The monitoringOriginatedDefineLater to set. - */ - public void setMonitoringOriginatedDefineLater(String monitoringOriginatedDefineLater) { - this.monitoringOriginatedDefineLater = monitoringOriginatedDefineLater; - } - - /** - * @return Returns the activeModule. - */ - public String getActiveModule() { - return activeModule; - } - - /** - * @param activeModule - * The activeModule to set. - */ - public void setActiveModule(String activeModule) { - this.activeModule = activeModule; - } - - /** - * @return Returns the defineLaterInEditMode. - */ - public String getDefineLaterInEditMode() { - return defineLaterInEditMode; - } - - /** - * @param defineLaterInEditMode - * The defineLaterInEditMode to set. - */ - public void setDefineLaterInEditMode(String defineLaterInEditMode) { - this.defineLaterInEditMode = defineLaterInEditMode; - } - - /** - * @return Returns the showAuthoringTabs. - */ - public String getShowAuthoringTabs() { - return showAuthoringTabs; - } - - /** - * @param showAuthoringTabs - * The showAuthoringTabs to set. - */ - public void setShowAuthoringTabs(String showAuthoringTabs) { - this.showAuthoringTabs = showAuthoringTabs; - } - public int compareTo(Object o) { McGeneralAuthoringDTO mcGeneralAuthoringDTO = (McGeneralAuthoringDTO) o; @@ -295,51 +102,6 @@ } /** - * @return Returns the defaultContentIdStr. - */ - public String getDefaultContentIdStr() { - return defaultContentIdStr; - } - - /** - * @param defaultContentIdStr - * The defaultContentIdStr to set. - */ - public void setDefaultContentIdStr(String defaultContentIdStr) { - this.defaultContentIdStr = defaultContentIdStr; - } - - /** - * @return Returns the defaultQuestionContent. - */ - public String getDefaultQuestionContent() { - return defaultQuestionContent; - } - - /** - * @param defaultQuestionContent - * The defaultQuestionContent to set. - */ - public void setDefaultQuestionContent(String defaultQuestionContent) { - this.defaultQuestionContent = defaultQuestionContent; - } - - /** - * @return Returns the requestedModule. - */ - public String getRequestedModule() { - return requestedModule; - } - - /** - * @param requestedModule - * The requestedModule to set. - */ - public void setRequestedModule(String requestedModule) { - this.requestedModule = requestedModule; - } - - /** * @return Returns the activityInstructions. */ public String getActivityInstructions() { @@ -385,21 +147,6 @@ } /** - * @return Returns the synchInMonitor. - */ - public String getSynchInMonitor() { - return synchInMonitor; - } - - /** - * @param synchInMonitor - * The synchInMonitor to set. - */ - public void setSynchInMonitor(String synchInMonitor) { - this.synchInMonitor = synchInMonitor; - } - - /** * @return Returns the usernameVisible. */ public String getUsernameVisible() { @@ -430,21 +177,6 @@ } /** - * @return Returns the sbmtSuccess. - */ - public String getSbmtSuccess() { - return sbmtSuccess; - } - - /** - * @param sbmtSuccess - * The sbmtSuccess to set. - */ - public void setSbmtSuccess(String sbmtSuccess) { - this.sbmtSuccess = sbmtSuccess; - } - - /** * @return Returns the contentFolderID. */ public String getContentFolderID() { Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McGeneralMonitoringDTO.java =================================================================== diff -u -rbe07c35c372d904a65581d98660e73f3b13b69db -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McGeneralMonitoringDTO.java (.../McGeneralMonitoringDTO.java) (revision be07c35c372d904a65581d98660e73f3b13b69db) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McGeneralMonitoringDTO.java (.../McGeneralMonitoringDTO.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -25,8 +25,6 @@ import java.util.List; import java.util.Map; -import org.apache.commons.lang.builder.ToStringBuilder; - /** *

* DTO that holds monitoring flow properties @@ -35,23 +33,17 @@ * @author Ozgur Demirtas */ public class McGeneralMonitoringDTO implements Comparable { - protected String editResponse; protected Map mapQuestionContent; protected String defaultQuestionContent; protected String currentMonitoringTab; - protected String sbmtSuccess; - protected String defineLaterInEditMode; protected String requestLearningReport; protected String userExceptionNoToolSessions; protected String userExceptionContentInUse; protected String userExceptionContentDoesNotExist; protected String userExceptionNoStudentActivity; - protected String isMonitoredContentInUse; - protected String monitoredContentInUse; - protected String activeModule; protected String currentTab; protected String activityTitle; protected String activityInstructions; @@ -62,11 +54,9 @@ protected String groupName; protected String existsOpenMcs; protected String responseId; - protected String currentUid; protected String displayAnswers; protected String toolContentID; - protected Map mapOptionsContent; protected Map summaryToolSessions; protected List listMonitoredAnswersContainerDto; protected List listUserEntries; @@ -116,21 +106,6 @@ } /** - * @return Returns the activeModule. - */ - public String getActiveModule() { - return activeModule; - } - - /** - * @param activeModule - * The activeModule to set. - */ - public void setActiveModule(String activeModule) { - this.activeModule = activeModule; - } - - /** * @return Returns the currentTab. */ public String getCurrentTab() { @@ -221,21 +196,6 @@ } /** - * @return Returns the defineLaterInEditMode. - */ - public String getDefineLaterInEditMode() { - return defineLaterInEditMode; - } - - /** - * @param defineLaterInEditMode - * The defineLaterInEditMode to set. - */ - public void setDefineLaterInEditMode(String defineLaterInEditMode) { - this.defineLaterInEditMode = defineLaterInEditMode; - } - - /** * @return Returns the requestLearningReport. */ public String getRequestLearningReport() { @@ -251,21 +211,6 @@ } /** - * @return Returns the sbmtSuccess. - */ - public String getSbmtSuccess() { - return sbmtSuccess; - } - - /** - * @param sbmtSuccess - * The sbmtSuccess to set. - */ - public void setSbmtSuccess(String sbmtSuccess) { - this.sbmtSuccess = sbmtSuccess; - } - - /** * @return Returns the userExceptionNoToolSessions. */ public String getUserExceptionNoToolSessions() { @@ -281,36 +226,6 @@ } /** - * @return Returns the isMonitoredContentInUse. - */ - public String getIsMonitoredContentInUse() { - return isMonitoredContentInUse; - } - - /** - * @param isMonitoredContentInUse - * The isMonitoredContentInUse to set. - */ - public void setIsMonitoredContentInUse(String isMonitoredContentInUse) { - this.isMonitoredContentInUse = isMonitoredContentInUse; - } - - /** - * @return Returns the mapOptionsContent. - */ - public Map getMapOptionsContent() { - return mapOptionsContent; - } - - /** - * @param mapOptionsContent - * The mapOptionsContent to set. - */ - public void setMapOptionsContent(Map mapOptionsContent) { - this.mapOptionsContent = mapOptionsContent; - } - - /** * @return Returns the countAllUsers. */ public Integer getCountAllUsers() { @@ -506,21 +421,6 @@ } /** - * @return Returns the currentUid. - */ - public String getCurrentUid() { - return currentUid; - } - - /** - * @param currentUid - * The currentUid to set. - */ - public void setCurrentUid(String currentUid) { - this.currentUid = currentUid; - } - - /** * @return Returns the displayAnswers. */ public String getDisplayAnswers() { @@ -610,32 +510,6 @@ this.sessionUserCount = sessionUserCount; } - public String toString() { - return new ToStringBuilder(this).append("toolContentID: ", toolContentID) - .append("activeModule: ", activeModule).append("monitoredContentInUse: ", monitoredContentInUse) - .append("currentMonitoringTab: ", currentMonitoringTab).append("currentTab: ", currentTab) - .append("sbmtSuccess: ", sbmtSuccess).append("defineLaterInEditMode: ", defineLaterInEditMode) - .append("requestLearningReport: ", requestLearningReport) - .append("userExceptionNoToolSessions: ", userExceptionNoToolSessions) - .append("userExceptionContentDoesNotExist: ", userExceptionContentDoesNotExist) - .append("userExceptionNoStudentActivity: ", userExceptionNoStudentActivity) - .append("isMonitoredContentInUse: ", isMonitoredContentInUse).append("activityTitle: ", activityTitle) - .append("activityInstructions: ", activityInstructions) - .append("userExceptionContentInUse: ", userExceptionContentInUse) - .append("defaultOptionContent: ", defaultOptionContent).append("countAllUsers: ", countAllUsers) - .append("countSessionComplete: ", countSessionComplete) - .append("isPortfolioExport: ", isPortfolioExport).append("summaryToolSessions: ", summaryToolSessions) - .append("groupName: ", groupName) - .append("listMonitoredAnswersContainerDto: ", listMonitoredAnswersContainerDto) - .append("listUserEntries: ", listUserEntries).append("existsOpenMcs: ", existsOpenMcs) - .append("listMcAllSessionsDTO: ", listMcAllSessionsDTO) - .append("showOpenMcsSection: ", showOpenMcsSection).append("mapStudentsMcd: ", mapStudentsMcd) - .append("responseId: ", responseId).append("currentUid: ", currentUid) - .append("displayAnswers: ", displayAnswers).append("sessionUserCount: ", sessionUserCount) - .append("completedSessionUserCount: ", completedSessionUserCount) - .append("completedSessionUserPercent: ", completedSessionUserPercent).toString(); - } - public int compareTo(Object o) { McGeneralMonitoringDTO mcGeneralMonitoringDTO = (McGeneralMonitoringDTO) o; @@ -646,21 +520,6 @@ } /** - * @return Returns the monitoredContentInUse. - */ - public String getMonitoredContentInUse() { - return monitoredContentInUse; - } - - /** - * @param monitoredContentInUse - * The monitoredContentInUse to set. - */ - public void setMonitoredContentInUse(String monitoredContentInUse) { - this.monitoredContentInUse = monitoredContentInUse; - } - - /** * @return Returns the contentFolderID. */ public String getContentFolderID() { @@ -691,21 +550,6 @@ } /** - * @return Returns the editResponse. - */ - public String getEditResponse() { - return editResponse; - } - - /** - * @param editResponse - * The editResponse to set. - */ - public void setEditResponse(String editResponse) { - this.editResponse = editResponse; - } - - /** * @return Returns the mapQuestionContent. */ public Map getMapQuestionContent() { Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McOptionDTO.java =================================================================== diff -u --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McOptionDTO.java (revision 0) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McOptionDTO.java (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -0,0 +1,109 @@ +/*************************************************************************** + * 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 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$$ */ +package org.lamsfoundation.lams.tool.mc; + +import org.apache.commons.lang.builder.ToStringBuilder; +import org.lamsfoundation.lams.tool.mc.pojos.McOptsContent; + +/** + * DTO that holds candiate answers data for summary page + * + * @author Ozgur Demirtas + */ +public class McOptionDTO implements Comparable { + + private Long uid; + private String candidateAnswer; + private String correct; + + public McOptionDTO() { + + } + + public McOptionDTO(McOptsContent option) { + this.uid = option.getUid(); + this.candidateAnswer = option.getMcQueOptionText(); + //this.correct = new Boolean(option.isCorrectOption()).toString(); + + if (option.isCorrectOption()) { + this.correct = "Correct"; + } else { + this.correct = "Incorrect"; + } + } + + /** + * @return Returns the uid. + */ + public Long getUid() { + return uid; + } + + /** + * @param uid + * The uid to set. + */ + public void setUid(Long uid) { + this.uid = uid; + } + + /** + * @return Returns the candidateAnswer. + */ + public String getCandidateAnswer() { + return candidateAnswer; + } + + /** + * @param candidateAnswer + * The candidateAnswer to set. + */ + public void setCandidateAnswer(String candidateAnswer) { + this.candidateAnswer = candidateAnswer; + } + + /** + * @return Returns the correct. + */ + public String getCorrect() { + return correct; + } + + /** + * @param correct + * The correct to set. + */ + public void setCorrect(String correct) { + this.correct = correct; + } + + public int compareTo(Object o) { + McOptionDTO mcOptionDTO = (McOptionDTO) o; + + if (mcOptionDTO == null) + return 1; + else + return 0; + } + +} Fisheye: Tag 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f refers to a dead (removed) revision in file `lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McQuestionContentDTO.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McQuestionDTO.java =================================================================== diff -u --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McQuestionDTO.java (revision 0) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McQuestionDTO.java (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -0,0 +1,158 @@ +/**************************************************************** + * 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 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$$ */ +package org.lamsfoundation.lams.tool.mc; + +import java.util.List; + +import org.apache.commons.lang.builder.ToStringBuilder; + +/** + * DTO that holds users attempt history data for jsp purposes + * + * @author Ozgur Demirtas + */ +public class McQuestionDTO implements Comparable { + private Long uid; + private String question; + private String displayOrder; + private String feedback; + private String weight; + private String mark; + + private List listCandidateAnswersDTO; + + public int compareTo(Object o) { + McMonitoredUserDTO mcMonitoredUserDTO = (McMonitoredUserDTO) o; + + if (mcMonitoredUserDTO == null) + return 1; + else + return 0; + } + + /** + * @return Returns the uid. + */ + public Long getUid() { + return uid; + } + + /** + * @param uid + * The uid to set. + */ + public void setUid(Long uid) { + this.uid = uid; + } + + /** + * @return Returns the displayOrder. + */ + public String getDisplayOrder() { + return displayOrder; + } + + /** + * @param displayOrder + * The displayOrder to set. + */ + public void setDisplayOrder(String displayOrder) { + this.displayOrder = displayOrder; + } + + /** + * @return Returns the feedback. + */ + public String getFeedback() { + return feedback; + } + + /** + * @param feedback + * The feedback to set. + */ + public void setFeedback(String feedback) { + this.feedback = feedback; + } + + /** + * @return Returns the question. + */ + public String getQuestion() { + return question; + } + + /** + * @param question + * The question to set. + */ + public void setQuestion(String question) { + this.question = question; + } + + /** + * @return Returns the weight. + */ + public String getWeight() { + return weight; + } + + /** + * @param weight + * The weight to set. + */ + public void setWeight(String weight) { + this.weight = weight; + } + + /** + * @return Returns the mark. + */ + public String getMark() { + return mark; + } + + /** + * @param mark + * The mark to set. + */ + public void setMark(String mark) { + this.mark = mark; + } + + /** + * @return Returns the listCandidateAnswersDTO. + */ + public List getListCandidateAnswersDTO() { + return listCandidateAnswersDTO; + } + + /** + * @param listCandidateAnswersDTO + * The listCandidateAnswersDTO to set. + */ + public void setListCandidateAnswersDTO(List listCandidateAnswersDTO) { + this.listCandidateAnswersDTO = listCandidateAnswersDTO; + } +} Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McUserMarkDTO.java =================================================================== diff -u -rd66da54e1b79ff5493ac331ec290649184965a7e -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McUserMarkDTO.java (.../McUserMarkDTO.java) (revision d66da54e1b79ff5493ac331ec290649184965a7e) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McUserMarkDTO.java (.../McUserMarkDTO.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -25,7 +25,6 @@ import java.util.Date; import org.apache.commons.lang.builder.ToStringBuilder; -import org.lamsfoundation.lams.tool.mc.pojos.McQueUsr; /** *

Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McUtils.java =================================================================== diff -u -rbe07c35c372d904a65581d98660e73f3b13b69db -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McUtils.java (.../McUtils.java) (revision be07c35c372d904a65581d98660e73f3b13b69db) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McUtils.java (.../McUtils.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -22,191 +22,33 @@ /* $$Id$$ */ package org.lamsfoundation.lams.tool.mc; -import java.text.DateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Random; -import java.util.TreeMap; - import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpSession; import org.lamsfoundation.lams.tool.mc.pojos.McContent; -import org.lamsfoundation.lams.tool.mc.pojos.McOptsContent; import org.lamsfoundation.lams.tool.mc.service.IMcService; import org.lamsfoundation.lams.tool.mc.web.McAuthoringForm; -import org.lamsfoundation.lams.usermanagement.User; -import org.lamsfoundation.lams.usermanagement.dto.UserDTO; -import org.lamsfoundation.lams.web.session.SessionManager; -import org.lamsfoundation.lams.web.util.AttributeNames; import org.lamsfoundation.lams.web.util.SessionMap; /** - * @author Ozgur Demirtas Common MCQ utility functions live here. + * Common MCQ utility functions live here. + * + * @author Ozgur Demirtas */ public abstract class McUtils implements McAppConstants { - public static String replaceNewLines(String text) { - String newText = ""; - if (text != null) { - newText = text.replaceAll("\n", "
"); - } - - return newText; - - } - /** - * - * @param request - * @return - */ - /* fix this */ - public static Date getGMTDateTime() { - Date date = new Date(System.currentTimeMillis()); - return date; - } - - public static UserDTO getToolUser() { - /* obtain user object from the session */ - HttpSession ss = SessionManager.getSession(); - /* get back login user DTO */ - UserDTO toolUser = (UserDTO) ss.getAttribute(AttributeNames.USER); - return toolUser; - } - - public static Long getUserId() { - UserDTO toolUser = getToolUser(); - long userId = toolUser.getUserID().longValue(); - return new Long(userId); - } - - public static String getUserName() { - /* double check if username and login is the same */ - UserDTO toolUser = getToolUser(); - String userName = toolUser.getLogin(); - return userName; - } - - public static String getUserFullName() { - UserDTO toolUser = getToolUser(); - String fullName = toolUser.getFirstName() + " " + toolUser.getLastName(); - return fullName; - } - - public static String getFormattedDateString(Date date) { - return (DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(date)); - } - - /** - * generateOptionsMap(List listMcOptions) - * - * returns a Map of options - * - * @param listMcOptions - * @return Map - */ - public static Map generateOptionsMap(List listMcOptions) { - Map mapOptionsContent = new TreeMap(new McStringComparator()); - - Iterator listIterator = listMcOptions.iterator(); - Long mapIndex = new Long(1); - while (listIterator.hasNext()) { - McOptsContent mcOptionsContent = (McOptsContent) listIterator.next(); - mapOptionsContent.put(mapIndex.toString(), mcOptionsContent.getMcQueOptionText()); - mapIndex = new Long(mapIndex.longValue() + 1); - } - return mapOptionsContent; - } - - /** - * temporary function - * - * @return - */ - public static long generateId() { - Random generator = new Random(); - long longId = generator.nextLong(); - if (longId < 0) - longId = longId * (-1); - return longId; - } - - /** - * temporary function - * - * @return - */ - public static int generateIntegerId() { - Random generator = new Random(); - int intId = generator.nextInt(); - if (intId < 0) - intId = intId * (-1); - return intId; - } - - /** - * temporary function - * - * @return - */ - public static int getCurrentUserId(HttpServletRequest request) throws McApplicationException { - HttpSession ss = SessionManager.getSession(); - UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); - return user.getUserID().intValue(); - } - - /** - * temporary function - * - * @return - */ - public static User createSimpleUser(Integer userId) { - User user = new User(); - user.setUserId(userId); - return user; - } - - /** - * find out if the content is in use or not. If it is in use, the author can not modify it. The idea of content - * being in use is, once any one learner starts using a particular content that content should become unmodifiable. - * - * @param mcContent - * @return boolean - */ - public static boolean isContentInUse(McContent mcContent) { - return mcContent.isContentInUse(); - } - - /** - * find out if the content is being edited in monitoring interface or not. If it is, the author can not modify it. - * - * @param mcContent - * @return boolean - */ - public static boolean isDefineLater(McContent mcContent) { - return mcContent.isDefineLater(); - } - - /** * the only attributes kept are TOOL_SESSION and TOOL_CONTENT_ID and CURRENT_MONITORED_TOOL_SESSION - * cleanUpSessionAbsolute(HttpServletRequest request) * * @param request */ public static void cleanUpSessionAbsolute(HttpServletRequest request) { request.getSession().removeAttribute(MY_SIGNATURE); request.getSession().removeAttribute(DEFAULT_CONTENT_ID); request.getSession().removeAttribute(ERROR_MCAPPLICATION); - request.getSession().removeAttribute(LOAD); - request.getSession().removeAttribute(LOAD_QUESTIONS); - request.getSession().removeAttribute(LOAD_STARTER); - request.getSession().removeAttribute(AUTHORING_STARTER); + request.getSession().removeAttribute(LOAD_AUTHORING); + request.getSession().removeAttribute("starter"); request.getSession().removeAttribute(LEARNING_STARTER); - request.getSession().removeAttribute(MONITORING_STARTER); + request.getSession().removeAttribute("monitoringStarter"); request.getSession().removeAttribute(LOAD_LEARNER); request.getSession().removeAttribute(LOAD_MONITORING_CONTENT); request.getSession().removeAttribute(INDIVIDUAL_REPORT); @@ -216,12 +58,9 @@ request.getSession().removeAttribute(PREVIEW); request.getSession().removeAttribute(LEARNER_PROGRESS); request.getSession().removeAttribute(LEARNER_PROGRESS_USERID); - request.getSession().removeAttribute(AUTHORING); - request.getSession().removeAttribute(SOURCE_MC_STARTER); request.getSession().removeAttribute(AUTHORING_CANCELLED); request.getSession().removeAttribute(DEFINE_LATER_EDIT_ACTIVITY); request.getSession().removeAttribute(EDIT_OPTIONS_MODE); - request.getSession().removeAttribute(DEFINE_LATER_IN_EDIT_MODE); request.getSession().removeAttribute(IS_ADD_QUESTION); request.getSession().removeAttribute(IS_REMOVE_QUESTION); request.getSession().removeAttribute(SUBMIT_SUCCESS); @@ -262,7 +101,6 @@ request.getSession().removeAttribute(TITLE); request.getSession().removeAttribute(INSTRUCTIONS); request.getSession().removeAttribute(CREATION_DATE); - request.getSession().removeAttribute(DEFINE_LATER); request.getSession().removeAttribute(RICHTEXT_FEEDBACK_CORRECT); request.getSession().removeAttribute(RETRIES); request.getSession().removeAttribute(ON); @@ -281,7 +119,6 @@ request.getSession().removeAttribute(TOP_MARK); request.getSession().removeAttribute(LOWEST_MARK); request.getSession().removeAttribute(AVERAGE_MARK); - request.getSession().removeAttribute(ACTIVE_MODULE); request.getSession().removeAttribute(NOT_ATTEMPTED); request.getSession().removeAttribute(INCOMPLETE); request.getSession().removeAttribute(COMPLETED); @@ -344,28 +181,6 @@ /** * - * determines the struts level location to return - * - * @param sourceMcStarter - * @param requestedModule - * @return - */ - public static String getDestination(String sourceMcStarter, String requestedModule) { - - if (requestedModule.equals(DEFINE_LATER)) { - // request is from define Later url. return to LOAD_VIEW_ONLY - return LOAD_VIEW_ONLY; - } else if (requestedModule.equals(AUTHORING)) { - // request is from authoring url. return to LOAD_QUESTIONS - return LOAD_QUESTIONS; - } else { - // request is from an unknown source. return null - return null; - } - } - - /** - * * @param request * @param defaultMcContent * @param mcGeneralAuthoringDTO @@ -384,7 +199,7 @@ public static void setDefineLater(HttpServletRequest request, boolean value, String strToolContentID, IMcService mcService) { - McContent mcContent = mcService.retrieveMc(new Long(strToolContentID)); + McContent mcContent = mcService.getMcContent(new Long(strToolContentID)); if (mcContent != null) { mcContent.setDefineLater(value); mcService.updateMc(mcContent); @@ -393,33 +208,15 @@ /** * - * @param request - * @param mcService - * @param mcAuthoringForm - * @param mcGeneralAuthoringDTO - * @param strToolContentID - * @param defaultContentIdStr - * @param activeModule - * @param sessionMap - * @param httpSessionID */ - public static void setFormProperties(HttpServletRequest request, IMcService mcService, - McAuthoringForm mcAuthoringForm, McGeneralAuthoringDTO mcGeneralAuthoringDTO, String strToolContentID, - String defaultContentIdStr, String activeModule, SessionMap sessionMap, String httpSessionID) { + public static void setFormProperties(HttpServletRequest request, McAuthoringForm mcAuthoringForm, + McGeneralAuthoringDTO mcGeneralAuthoringDTO, String strToolContentID, String httpSessionID) { mcAuthoringForm.setHttpSessionID(httpSessionID); mcGeneralAuthoringDTO.setHttpSessionID(httpSessionID); mcAuthoringForm.setToolContentID(strToolContentID); - if ((defaultContentIdStr != null) && (defaultContentIdStr.length() > 0)) { - mcAuthoringForm.setDefaultContentIdStr(new Long(defaultContentIdStr).toString()); - mcGeneralAuthoringDTO.setDefaultContentIdStr(new Long(defaultContentIdStr).toString()); - } - - mcAuthoringForm.setActiveModule(activeModule); - mcGeneralAuthoringDTO.setActiveModule(activeModule); - String sln = request.getParameter("sln"); mcAuthoringForm.setSln(sln); mcGeneralAuthoringDTO.setSln(sln); Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcContentDAO.java =================================================================== diff -u -r567af22fafd6a56534cc071f3650eda4495d05ef -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcContentDAO.java (.../IMcContentDAO.java) (revision 567af22fafd6a56534cc071f3650eda4495d05ef) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcContentDAO.java (.../IMcContentDAO.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -61,17 +61,6 @@ /** *

- * Returns the persistent instance of McContent with the given tool session id mcSessionId, returns - * null if not found. - * - * @param mcSessionId - * The tool session id - * @return a persistent instance of McContent or null if not found. - */ - public McContent getMcContentBySession(Long mcSessionId); - - /** - *

* Persist the given persistent instance of McContent. *

* Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcOptionsContentDAO.java =================================================================== diff -u -r4de4cce84ca65dd587b4dd0765438daac1d99e57 -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcOptionsContentDAO.java (.../IMcOptionsContentDAO.java) (revision 4de4cce84ca65dd587b4dd0765438daac1d99e57) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcOptionsContentDAO.java (.../IMcOptionsContentDAO.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -24,15 +24,13 @@ import java.util.List; -import org.lamsfoundation.lams.tool.mc.McCandidateAnswersDTO; +import org.lamsfoundation.lams.tool.mc.McOptionDTO; import org.lamsfoundation.lams.tool.mc.pojos.McOptsContent; /** - * @author Ozgur Demirtas - *

- * Interface for the McOptionsContent DAO, defines methods needed to access/modify mc options content - *

+ * Interface for the McOptionsContent DAO, defines methods needed to access/modify mc options content * + * @author Ozgur Demirtas */ public interface IMcOptionsContentDAO { /** @@ -45,7 +43,7 @@ * @param uid * @return McOptsContent */ - public McOptsContent getMcOptionsContentByUID(Long uid); + McOptsContent getMcOptionsContentByUID(Long uid); /** *

@@ -56,7 +54,7 @@ * @param mcQueContentId * @return List */ - public List findMcOptionsContentByQueId(Long mcQueContentId); + List findMcOptionsContentByQueId(Long mcQueContentId); /** *

@@ -68,11 +66,11 @@ * @param mcQueContentUid * @return McOptsContent */ - public McOptsContent getOptionContentByOptionText(final String option, final Long mcQueContentUid); + McOptsContent getOptionContentByOptionText(final String option, final Long mcQueContentUid); - public List findMcOptionCorrectByQueId(Long mcQueContentId); + List findMcOptionCorrectByQueId(Long mcQueContentId); - public List populateCandidateAnswersDTO(Long mcQueContentId); + List getOptionDtos(Long mcQueContentId); /** *

@@ -81,7 +79,7 @@ * * @param mcOptionsContent */ - public void saveMcOptionsContent(McOptsContent mcOptionsContent); + void saveMcOptionsContent(McOptsContent mcOptionsContent); /** *

@@ -90,7 +88,7 @@ * * @param mcOptionsContent */ - public void updateMcOptionsContent(McOptsContent mcOptionsContent); + void updateMcOptionsContent(McOptsContent mcOptionsContent); /** *

@@ -99,7 +97,7 @@ * * @param mcOptionsContent */ - public void removeMcOptionsContentByUID(Long uid); + void removeMcOptionsContentByUID(Long uid); /** *

@@ -108,14 +106,5 @@ * * @param mcOptionsContent */ - public void removeMcOptionsContentByQueId(Long mcQueContentId); - - /** - *

- * removes McOptsContent - *

- * - * @param mcOptionsContent - */ - public void removeMcOptionsContent(McOptsContent mcOptsContent); + void removeMcOptionsContent(McOptsContent mcOptsContent); } Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcQueContentDAO.java =================================================================== diff -u -r9a2c06691bf5157039ae82f36ec2f84c32eda8cb -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcQueContentDAO.java (.../IMcQueContentDAO.java) (revision 9a2c06691bf5157039ae82f36ec2f84c32eda8cb) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcQueContentDAO.java (.../IMcQueContentDAO.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -27,16 +27,13 @@ import org.lamsfoundation.lams.tool.mc.pojos.McQueContent; /** + * Interface for the McQueContent DAO, defines methods needed to access/modify mc question content * * @author Ozgur Demirtas - *

- * Interface for the McQueContent DAO, defines methods needed to access/modify mc question content - *

- * */ public interface IMcQueContentDAO { + /** - * * *

* Return the persistent instance of a McQueContent with the given identifier uid, returns null if not * found. @@ -45,23 +42,10 @@ * @param uid * @return McQueContent */ - public McQueContent getMcQueContentByUID(Long uid); + McQueContent getMcQueContentByUID(Long uid); /** - * * *

- * Return the persistent instance of a McQueContent with the given identifier mcContentId, returns null - * if not found. - *

- * - * @param mcContentId - * @return McQueContent - */ - public McQueContent getToolDefaultQuestionContent(final long mcContentId); - - /** - * * - *

* Return the persistent instance of a McQueContent with the given identifier question and * mcContentUid, returns null if not found. *

@@ -70,10 +54,9 @@ * @param mcContentUid * @return McQueContent */ - public McQueContent getQuestionContentByQuestionText(final String question, final Long mcContentUid); + McQueContent getQuestionContentByQuestionText(final String question, final Long mcContentUid); /** - * * *

* Return the persistent instance of a McQueContent with the given identifier displayOrder and * mcContentUid, returns null if not found. @@ -83,10 +66,9 @@ * @param mcContentUid * @return McQueContent */ - public McQueContent getQuestionContentByDisplayOrder(final Long displayOrder, final Long mcContentUid); + McQueContent getQuestionContentByDisplayOrder(final Long displayOrder, final Long mcContentUid); /** - * * *

* Return a list of McQueContent with the given identifier question and mcContentUid, * returns null if not found. @@ -95,10 +77,9 @@ * @param mcContentUid * @return List */ - public List getAllQuestionEntries(final long mcContentId); + List getQuestionsByContentUid(final long mcContentId); /** - * * *

* Return a list of McQueContent with the given identifier question and mcContentUid, * returns null if not found. @@ -107,94 +88,86 @@ * @param mcContentUid * @return List */ - public List refreshQuestionContent(final Long mcContentId); + List refreshQuestionContent(final Long mcContentId); /** - * * *

* resets McQueContent with the given identifier mcContentUid *

* * @param mcContentUid */ - public void resetAllQuestions(final Long mcContentUid); + void resetAllQuestions(final Long mcContentUid); /** - * * *

* removes McQueContent with the given identifier mcContentUid *

* * @param mcContentUid */ - public void removeQuestionContentByMcUid(final Long mcContentUid); + void removeQuestionContentByMcUid(final Long mcContentUid); /** - * * *

* saves McQueContent with the given identifier mcQueContent *

* * @param mcQueContent */ - public void saveMcQueContent(McQueContent mcQueContent); + void saveMcQueContent(McQueContent mcQueContent); /** - * * *

* updates McQueContent with the given identifier mcQueContent *

* * @param mcQueContent */ - public void updateMcQueContent(McQueContent mcQueContent); + void updateMcQueContent(McQueContent mcQueContent); /** - * * *

* saves McQueContent with the given identifier mcQueContent *

* * @param mcQueContent */ - public void saveOrUpdateMcQueContent(McQueContent mcQueContent); + void saveOrUpdateMcQueContent(McQueContent mcQueContent); /** - * * *

* removes McQueContent with the given identifier uid *

* * @param uid */ - public void removeMcQueContentByUID(Long uid); + void removeMcQueContentByUID(Long uid); /** - * * *

* removes McQueContent with the given identifier mcQueContent *

* * @param mcQueContent * @return */ - public void removeMcQueContent(McQueContent mcQueContent); + void removeMcQueContent(McQueContent mcQueContent); /** - * * *

* used to get the next available display order with the given identifier mcContentId *

* * @param mcQueContent * @return */ - public List getNextAvailableDisplayOrder(final long mcContentId); + List getNextAvailableDisplayOrder(final long mcContentId); - public McQueContent findMcQuestionContentByUid(Long uid); + McQueContent findMcQuestionContentByUid(Long uid); - public List getAllQuestionEntriesSorted(final long qaContentId); + List getAllQuestionEntriesSorted(final long qaContentId); + + void releaseQuestionFromCache(McQueContent question); - public List getMcQueContentsByContentId(long mcContentId); - } Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcUserDAO.java =================================================================== diff -u -rc369c0326857e08851d03a29d39d4337091f5253 -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcUserDAO.java (.../IMcUserDAO.java) (revision c369c0326857e08851d03a29d39d4337091f5253) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcUserDAO.java (.../IMcUserDAO.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -44,18 +44,6 @@ */ public McQueUsr getMcUserByUID(Long uid); - /** - *

- * Return the persistent instance of a McQueUsr with the given user id userId, returns null if not - * found. - *

- * - * @param userId - * The id of a McQueUsr - * @return the persistent instance of a McQueUsr or null if not found. - */ - public McQueUsr findMcUserById(Long userId); - public McQueUsr getMcUserBySession(Long userId, Long sessionUid); public void saveMcUser(McQueUsr mcUser); Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcUsrAttemptDAO.java =================================================================== diff -u -r45dc9d53a03937ef25d6a8fa6c383c046f5df9f3 -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcUsrAttemptDAO.java (.../IMcUsrAttemptDAO.java) (revision 45dc9d53a03937ef25d6a8fa6c383c046f5df9f3) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcUsrAttemptDAO.java (.../IMcUsrAttemptDAO.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -68,6 +68,8 @@ * @return */ void removeAllUserAttempts(Long queUserUid); + + void removeAttempt(McUsrAttempt userAttempt); /** * Get the most recent attempts (for all questions) for one user in one tool session Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McContentDAO.java =================================================================== diff -u -r567af22fafd6a56534cc071f3650eda4495d05ef -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McContentDAO.java (.../McContentDAO.java) (revision 567af22fafd6a56534cc071f3650eda4495d05ef) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McContentDAO.java (.../McContentDAO.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -44,9 +44,6 @@ private static final String FIND_MC_CONTENT = "from " + McContent.class.getName() + " as mc where content_id=?"; - private static final String LOAD_MC_BY_SESSION = "select mc from McContent mc left join fetch " - + "mc.mcSessions session where session.mcSessionId=:sessionId"; - public McContent getMcContentByUID(Long uid) { return (McContent) this.getHibernateTemplate().get(McContent.class, uid); } @@ -64,16 +61,6 @@ return null; } - public McContent getMcContentBySession(final Long mcSessionId) { - return (McContent) getHibernateTemplate().execute(new HibernateCallback() { - - public Object doInHibernate(Session session) throws HibernateException { - return session.createQuery(LOAD_MC_BY_SESSION).setLong("sessionId", mcSessionId.longValue()) - .uniqueResult(); - } - }); - } - public void saveMcContent(McContent mcContent) { this.getSession().setFlushMode(FlushMode.AUTO); this.getHibernateTemplate().saveOrUpdate(mcContent); Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McOptionsContentDAO.java =================================================================== diff -u -r4de4cce84ca65dd587b4dd0765438daac1d99e57 -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McOptionsContentDAO.java (.../McOptionsContentDAO.java) (revision 4de4cce84ca65dd587b4dd0765438daac1d99e57) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McOptionsContentDAO.java (.../McOptionsContentDAO.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -28,64 +28,60 @@ import org.apache.log4j.Logger; import org.hibernate.FlushMode; -import org.lamsfoundation.lams.tool.mc.McCandidateAnswersDTO; +import org.lamsfoundation.lams.tool.mc.McOptionDTO; import org.lamsfoundation.lams.tool.mc.dao.IMcOptionsContentDAO; import org.lamsfoundation.lams.tool.mc.pojos.McOptsContent; import org.springframework.orm.hibernate3.HibernateTemplate; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; /** + * Hibernate implementation for database access to McOptionsContent for the mc tool. + * * @author Ozgur Demirtas - *

- * Hibernate implementation for database access to McOptionsContent for the mc tool. - *

*/ public class McOptionsContentDAO extends HibernateDaoSupport implements IMcOptionsContentDAO { - static Logger logger = Logger.getLogger(McOptionsContentDAO.class.getName()); + private static Logger logger = Logger.getLogger(McOptionsContentDAO.class.getName()); - private static final String FIND_MC_OPTIONS_CONTENT = "from mcOptsContent in class McOptsContent where mcOptsContent.mcQueContentId=:mcQueContentUid order by mcOptsContent.displayOrder"; - private static final String LOAD_OPTION_CONTENT_BY_OPTION_TEXT = "from mcOptsContent in class McOptsContent where mcOptsContent.mcQueOptionText=:option and mcOptsContent.mcQueContentId=:mcQueContentUid"; + private static final String FIND_OPTIONS_BY_QUESTION_UID = "from mcOptsContent in class McOptsContent where mcOptsContent.mcQueContentId=:mcQueContentUid order by mcOptsContent.displayOrder"; + private static final String FIND_OPTIONS_BY_OPTION_TEXT = "from mcOptsContent in class McOptsContent where mcOptsContent.mcQueOptionText=:option and mcOptsContent.mcQueContentId=:mcQueContentUid"; public McOptsContent getMcOptionsContentByUID(Long uid) { return (McOptsContent) this.getHibernateTemplate().get(McOptsContent.class, uid); } - public List findMcOptionsContentByQueId(Long mcQueContentId) { - HibernateTemplate templ = this.getHibernateTemplate(); - if (mcQueContentId != null) { - List list = getSession().createQuery(FIND_MC_OPTIONS_CONTENT) - .setLong("mcQueContentUid", mcQueContentId.longValue()).list(); + public List findMcOptionsContentByQueId(Long questionUid) { + if (questionUid != null) { + List list = getSession().createQuery(FIND_OPTIONS_BY_QUESTION_UID) + .setLong("mcQueContentUid", questionUid.longValue()).list(); return list; } return null; } - public List populateCandidateAnswersDTO(Long mcQueContentId) { - List listCandidateAnswersData = new LinkedList(); + public List getOptionDtos(Long questionUid) { + List optionDtos = new LinkedList(); - if (mcQueContentId != null) { - List options = getSession().createQuery(FIND_MC_OPTIONS_CONTENT) - .setLong("mcQueContentUid", mcQueContentId.longValue()).list(); + if (questionUid != null) { + List options = getSession().createQuery(FIND_OPTIONS_BY_QUESTION_UID) + .setLong("mcQueContentUid", questionUid.longValue()).list(); if (options != null && options.size() > 0) { for (McOptsContent option : options) { - McCandidateAnswersDTO mcCandidateAnswersDTO = new McCandidateAnswersDTO(); - mcCandidateAnswersDTO.setCandidateAnswer(option.getMcQueOptionText()); - mcCandidateAnswersDTO.setCorrect(new Boolean(option.isCorrectOption()).toString()); - listCandidateAnswersData.add(mcCandidateAnswersDTO); + McOptionDTO optionDto = new McOptionDTO(option); + optionDtos.add(optionDto); } } } - return listCandidateAnswersData; + return optionDtos; } - public List findMcOptionCorrectByQueId(Long mcQueContentId) { + public List findMcOptionCorrectByQueId(Long questionUid) { List listOptionCorrect = new LinkedList(); - if (mcQueContentId != null) { - List options = getSession().createQuery(FIND_MC_OPTIONS_CONTENT) - .setLong("mcQueContentUid", mcQueContentId.longValue()).list(); + if (questionUid != null) { + List options = getSession().createQuery(FIND_OPTIONS_BY_QUESTION_UID) + .setLong("mcQueContentUid", questionUid.longValue()).list(); if (options != null && options.size() > 0) { for (McOptsContent option : options) { @@ -96,9 +92,9 @@ return listOptionCorrect; } - public McOptsContent getOptionContentByOptionText(final String option, final Long mcQueContentUid) { - List list = getSession().createQuery(LOAD_OPTION_CONTENT_BY_OPTION_TEXT).setString("option", option) - .setLong("mcQueContentUid", mcQueContentUid.longValue()).list(); + public McOptsContent getOptionContentByOptionText(final String option, final Long questionUid) { + List list = getSession().createQuery(FIND_OPTIONS_BY_OPTION_TEXT).setString("option", option) + .setLong("mcQueContentUid", questionUid.longValue()).list(); if (list != null && list.size() > 0) { McOptsContent mcq = (McOptsContent) list.get(0); @@ -108,7 +104,7 @@ } public void saveMcOptionsContent(McOptsContent mcOptsContent) { - this.getHibernateTemplate().save(mcOptsContent); + this.getHibernateTemplate().saveOrUpdate(mcOptsContent); } public void updateMcOptionsContent(McOptsContent mcOptsContent) { @@ -120,21 +116,6 @@ this.getHibernateTemplate().delete(mco); } - public void removeMcOptionsContentByQueId(Long mcQueContentId) { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(FIND_MC_OPTIONS_CONTENT) - .setLong("mcQueContentUid", mcQueContentId.longValue()).list(); - - if (list != null && list.size() > 0) { - Iterator listIterator = list.iterator(); - while (listIterator.hasNext()) { - McOptsContent mcOptsContent = (McOptsContent) listIterator.next(); - this.getSession().setFlushMode(FlushMode.AUTO); - templ.delete(mcOptsContent); - } - } - } - public void removeMcOptionsContent(McOptsContent mcOptsContent) { this.getSession().setFlushMode(FlushMode.AUTO); this.getHibernateTemplate().delete(mcOptsContent); Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McQueContentDAO.java =================================================================== diff -u -r9a2c06691bf5157039ae82f36ec2f84c32eda8cb -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McQueContentDAO.java (.../McQueContentDAO.java) (revision 9a2c06691bf5157039ae82f36ec2f84c32eda8cb) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McQueContentDAO.java (.../McQueContentDAO.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -32,11 +32,9 @@ import org.springframework.orm.hibernate3.support.HibernateDaoSupport; /** - * @author Ozgur Demirtas + * Hibernate implementation for database access to McQueContent for the mc tool. * - *

- * Hibernate implementation for database access to McQueContent for the mc tool. - *

+ * @author Ozgur Demirtas */ public class McQueContentDAO extends HibernateDaoSupport implements IMcQueContentDAO { @@ -54,6 +52,7 @@ private static final String SORT_QUESTION_CONTENT_BY_DISPLAY_ORDER = "from mcQueContent in class McQueContent where mcQueContent.mcContentId=:mcContentId order by mcQueContent.displayOrder"; + @Override public McQueContent findMcQuestionContentByUid(Long uid) { HibernateTemplate templ = this.getHibernateTemplate(); if (uid != null) { @@ -67,30 +66,21 @@ return null; } + @Override public McQueContent getMcQueContentByUID(Long uid) { return (McQueContent) this.getHibernateTemplate().get(McQueContent.class, uid); } - public McQueContent getToolDefaultQuestionContent(final long mcContentId) { + @Override + public List getQuestionsByContentUid(final long contentUid) { HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_QUESTION_CONTENT_BY_CONTENT_ID).setLong("mcContentId", mcContentId) + List list = getSession().createQuery(LOAD_QUESTION_CONTENT_BY_CONTENT_ID).setLong("mcContentId", contentUid) .list(); - if (list != null && list.size() > 0) { - McQueContent mcq = (McQueContent) list.get(0); - return mcq; - } - return null; - } - - public List getAllQuestionEntries(final long mcContentId) { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_QUESTION_CONTENT_BY_CONTENT_ID).setLong("mcContentId", mcContentId) - .list(); - return list; } + @Override public List refreshQuestionContent(final Long mcContentId) { HibernateTemplate templ = this.getHibernateTemplate(); List list = getSession().createQuery(REFRESH_QUESTION_CONTENT).setLong("mcContentId", mcContentId.longValue()) @@ -99,6 +89,7 @@ return list; } + @Override public McQueContent getQuestionContentByQuestionText(final String question, final Long mcContentUid) { HibernateTemplate templ = this.getHibernateTemplate(); List list = getSession().createQuery(LOAD_QUESTION_CONTENT_BY_QUESTION_TEXT).setString("question", question) @@ -111,6 +102,7 @@ return null; } + @Override public McQueContent getQuestionContentByDisplayOrder(final Long displayOrder, final Long mcContentUid) { HibernateTemplate templ = this.getHibernateTemplate(); List list = getSession().createQuery(LOAD_QUESTION_CONTENT_BY_DISPLAY_ORDER) @@ -124,6 +116,7 @@ return null; } + @Override public void removeQuestionContentByMcUid(final Long mcContentUid) { HibernateTemplate templ = this.getHibernateTemplate(); List list = getSession().createQuery(LOAD_QUESTION_CONTENT_BY_CONTENT_ID) @@ -140,6 +133,7 @@ } } + @Override public void resetAllQuestions(final Long mcContentUid) { HibernateTemplate templ = this.getHibernateTemplate(); List list = getSession().createQuery(LOAD_QUESTION_CONTENT_BY_CONTENT_ID) @@ -155,6 +149,7 @@ } } + @Override public List getNextAvailableDisplayOrder(final long mcContentId) { HibernateTemplate templ = this.getHibernateTemplate(); List list = getSession().createQuery(GET_NEXT_AVAILABLE_DISPLAY_ORDER).setLong("mcContentId", mcContentId) @@ -163,25 +158,30 @@ return list; } + @Override public void saveMcQueContent(McQueContent mcQueContent) { this.getHibernateTemplate().save(mcQueContent); } + @Override public void saveOrUpdateMcQueContent(McQueContent mcQueContent) { this.getHibernateTemplate().saveOrUpdate(mcQueContent); } + @Override public void removeMcQueContentByUID(Long uid) { McQueContent mcq = (McQueContent) getHibernateTemplate().get(McQueContent.class, uid); this.getSession().setFlushMode(FlushMode.AUTO); this.getHibernateTemplate().delete(mcq); } + @Override public void updateMcQueContent(McQueContent mcQueContent) { this.getSession().setFlushMode(FlushMode.AUTO); - this.getHibernateTemplate().update(mcQueContent); + this.getHibernateTemplate().saveOrUpdate(mcQueContent); } + @Override public List getAllQuestionEntriesSorted(final long mcContentId) { HibernateTemplate templ = this.getHibernateTemplate(); List list = getSession().createQuery(SORT_QUESTION_CONTENT_BY_DISPLAY_ORDER) @@ -190,20 +190,17 @@ return list; } - public List getMcQueContentsByContentId(long mcContentId) { - return getHibernateTemplate().findByNamedParam(LOAD_QUESTION_CONTENT_BY_CONTENT_ID, "mcContentId", - new Long(mcContentId)); - } - + @Override public void removeMcQueContent(McQueContent mcQueContent) { if ((mcQueContent != null) && (mcQueContent.getUid() != null)) { this.getSession().setFlushMode(FlushMode.AUTO); this.getHibernateTemplate().delete(mcQueContent); } } - - public void flush() { - this.getHibernateTemplate().flush(); + + @Override + public void releaseQuestionFromCache(McQueContent question) { + getHibernateTemplate().evict(question); } } \ No newline at end of file Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McUserDAO.java =================================================================== diff -u -rc369c0326857e08851d03a29d39d4337091f5253 -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McUserDAO.java (.../McUserDAO.java) (revision c369c0326857e08851d03a29d39d4337091f5253) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McUserDAO.java (.../McUserDAO.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -42,22 +42,10 @@ private static final String GET_USER_BY_USER_ID_SESSION = "from mcQueUsr in class McQueUsr where mcQueUsr.queUsrId=:queUsrId and mcQueUsr.mcSessionId=:mcSessionUid"; - private static final String GET_USER_BY_USER_ID = "from McQueUsr user where user.queUsrId=?"; - public McQueUsr getMcUserByUID(Long uid) { return (McQueUsr) this.getHibernateTemplate().get(McQueUsr.class, uid); } - public McQueUsr findMcUserById(Long userId) { - List list = getSession().createQuery(GET_USER_BY_USER_ID).setLong(0, userId.longValue()).list(); - - if (list != null && list.size() > 0) { - McQueUsr mcu = (McQueUsr) list.get(0); - return mcu; - } - return null; - } - public McQueUsr getMcUserBySession(final Long queUsrId, final Long mcSessionUid) { List list = getSession().createQuery(GET_USER_BY_USER_ID_SESSION).setLong("queUsrId", queUsrId.longValue()) Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McUsrAttemptDAO.java =================================================================== diff -u -r3fec05d7118aa084eb47e46dddba34b472ff775d -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McUsrAttemptDAO.java (.../McUsrAttemptDAO.java) (revision 3fec05d7118aa084eb47e46dddba34b472ff775d) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McUsrAttemptDAO.java (.../McUsrAttemptDAO.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -118,6 +118,11 @@ } @Override + public void removeAttempt(McUsrAttempt userAttempt) { + this.getHibernateTemplate().delete(userAttempt); + } + + @Override public int getAttemptsCountPerOption(Long optionUid) { List list = getHibernateTemplate().find(FIND_ATTEMPTS_COUNT_BY_OPTION, new Object[] { optionUid }); if (list == null || list.size() == 0) Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dbupdates/patch20140512.sql =================================================================== diff -u --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dbupdates/patch20140512.sql (revision 0) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dbupdates/patch20140512.sql (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -0,0 +1,20 @@ +-- Turn off autocommit, so nothing is committed if there is an error +SET AUTOCOMMIT = 0; +SET FOREIGN_KEY_CHECKS=0; +----------------------Put all sql statements below here------------------------- + +-- LDEV-3228 Ability to change, add, remove MCQ questions even after student have reached it +ALTER TABLE tl_lamc11_content DROP COLUMN content_in_use; + +ALTER TABLE tl_lamc11_options_content DROP FOREIGN KEY FK_tl_lamc11_options_content_1; +ALTER TABLE tl_lamc11_options_content MODIFY COLUMN mc_que_content_id BIGINT(20), + ADD CONSTRAINT FK_tl_lamc11_options_content_1 FOREIGN KEY (mc_que_content_id) REFERENCES tl_lamc11_que_content(uid); + +UPDATE lams_tool SET tool_version='20140512' WHERE tool_signature='lamc11'; + +----------------------Put all sql statements above here------------------------- + +-- If there were no errors, commit and restore autocommit to on +COMMIT; +SET AUTOCOMMIT = 1; +SET FOREIGN_KEY_CHECKS=1; \ No newline at end of file Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/pojos/McContent.java =================================================================== diff -u -rbe07c35c372d904a65581d98660e73f3b13b69db -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/pojos/McContent.java (.../McContent.java) (revision be07c35c372d904a65581d98660e73f3b13b69db) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/pojos/McContent.java (.../McContent.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -77,9 +77,6 @@ private long createdBy; /** nullable persistent field */ - private boolean contentInUse; - - /** nullable persistent field */ private boolean retries; private boolean showReport; @@ -110,8 +107,8 @@ /** full constructor */ public McContent(Long mcContentId, String content, String title, String instructions, boolean defineLater, - Date creationDate, Date updateDate, boolean questionsSequenced, long createdBy, boolean contentInUse, - Integer passMark, boolean showReport, boolean randomize, boolean displayAnswers, boolean showMarks, + Date creationDate, Date updateDate, boolean questionsSequenced, long createdBy, Integer passMark, + boolean showReport, boolean randomize, boolean displayAnswers, boolean showMarks, boolean useSelectLeaderToolOuput, boolean prefixAnswersWithLetters, boolean retries, boolean reflect, String reflectionSubject, Set mcQueContents, Set mcSessions) { @@ -124,7 +121,6 @@ this.updateDate = updateDate; this.questionsSequenced = questionsSequenced; this.createdBy = createdBy; - this.contentInUse = contentInUse; this.retries = retries; this.reflectionSubject = reflectionSubject; this.reflect = reflect; @@ -162,14 +158,12 @@ * the new mc content id. * @return the new mc content object. */ - public static McContent newInstance(IToolContentHandler toolContentHandler, McContent mc, Long newContentId) - throws ItemNotFoundException, RepositoryCheckedException { + public static McContent newInstance(McContent mc, Long newContentId) { McContent newContent = new McContent(newContentId, mc.getContent(), mc.getTitle(), mc.getInstructions(), - mc.isDefineLater(), mc.getCreationDate(), mc.getUpdateDate(), - mc.isQuestionsSequenced(), mc.getCreatedBy(), mc.isContentInUse(), mc.getPassMark(), mc.isShowReport(), mc.isRandomize(), - mc.isDisplayAnswers(), mc.isShowMarks(), mc.isUseSelectLeaderToolOuput(), - mc.isPrefixAnswersWithLetters(), mc.isRetries(), mc.isReflect(), mc.getReflectionSubject(), - new TreeSet(), new TreeSet()); + mc.isDefineLater(), mc.getCreationDate(), mc.getUpdateDate(), mc.isQuestionsSequenced(), + mc.getCreatedBy(), mc.getPassMark(), mc.isShowReport(), mc.isRandomize(), mc.isDisplayAnswers(), + mc.isShowMarks(), mc.isUseSelectLeaderToolOuput(), mc.isPrefixAnswersWithLetters(), mc.isRetries(), + mc.isReflect(), mc.getReflectionSubject(), new TreeSet(), new TreeSet()); newContent.setMcQueContents(mc.deepCopyMcQueContent(newContent)); return newContent; @@ -258,14 +252,6 @@ this.createdBy = createdBy; } - public boolean isContentInUse() { - return this.contentInUse; - } - - public void setContentInUse(boolean contentInUse) { - this.contentInUse = contentInUse; - } - public Integer getPassMark() { return this.passMark; } Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/pojos/McOptsContent.java =================================================================== diff -u -r3f7d82f8f5d0c6881eb83f9ce8c36720e9756649 -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/pojos/McOptsContent.java (.../McOptsContent.java) (revision 3f7d82f8f5d0c6881eb83f9ce8c36720e9756649) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/pojos/McOptsContent.java (.../McOptsContent.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -27,10 +27,8 @@ import org.apache.commons.lang.builder.ToStringBuilder; /** - *

* Persistent object/bean that defines the content for the MCQ tool. Provides accessors and mutators to get/set * attributes It maps to database table: tl_lamc11_options_content - *

* * @author Ozgur Demirtas */ @@ -39,8 +37,6 @@ /** identifier field */ private Long uid; - private Long mcQueOptionId; - /** nullable persistent field */ private boolean correctOption; @@ -53,24 +49,21 @@ private Long mcQueContentId; /** persistent field */ - private org.lamsfoundation.lams.tool.mc.pojos.McQueContent mcQueContent; - - //DTO fields + private McQueContent mcQueContent; + + // DTO fields private boolean selected; - + private String escapedOptionText; - public McOptsContent(Integer displayOrder, boolean correctOption, String mcQueOptionText, - org.lamsfoundation.lams.tool.mc.pojos.McQueContent mcQueContent) { + public McOptsContent(Integer displayOrder, boolean correctOption, String mcQueOptionText, McQueContent mcQueContent) { this.displayOrder = displayOrder; this.correctOption = correctOption; this.mcQueOptionText = mcQueOptionText; this.mcQueContent = mcQueContent; } - public static McOptsContent newInstance(McOptsContent mcOptsContent, McQueContent newMcQueContent) - - { + public static McOptsContent newInstance(McOptsContent mcOptsContent, McQueContent newMcQueContent) { McOptsContent newMcOptsContent = new McOptsContent(mcOptsContent.getDisplayOrder(), mcOptsContent.isCorrectOption(), mcOptsContent.getMcQueOptionText(), newMcQueContent); return newMcOptsContent; @@ -104,11 +97,11 @@ this.mcQueOptionText = mcQueOptionText; } - public org.lamsfoundation.lams.tool.mc.pojos.McQueContent getMcQueContent() { + public McQueContent getMcQueContent() { return this.mcQueContent; } - public void setMcQueContent(org.lamsfoundation.lams.tool.mc.pojos.McQueContent mcQueContent) { + public void setMcQueContent(McQueContent mcQueContent) { this.mcQueContent = mcQueContent; } @@ -117,21 +110,6 @@ } /** - * @return Returns the mcQueOptionId. - */ - public Long getMcQueOptionId() { - return mcQueOptionId; - } - - /** - * @param mcQueOptionId - * The mcQueOptionId to set. - */ - public void setMcQueOptionId(Long mcQueOptionId) { - this.mcQueOptionId = mcQueOptionId; - } - - /** * @return Returns the mcQueContentId. */ public Long getMcQueContentId() { @@ -149,10 +127,10 @@ public int compareTo(Object o) { McOptsContent optContent = (McOptsContent) o; // if the object does not exist yet, then just return any one of 0, -1, 1. Should not make a difference. - if (mcQueOptionId == null) + if (uid == null) return 1; else - return (int) (mcQueOptionId.longValue() - optContent.mcQueOptionId.longValue()); + return (int) (uid.longValue() - optContent.uid.longValue()); } /** @@ -169,15 +147,15 @@ public void setDisplayOrder(Integer displayOrder) { this.displayOrder = displayOrder; } - + public boolean isSelected() { return this.selected; } public void setSelected(boolean selected) { this.selected = selected; } - + public String getEscapedOptionText() { return this.escapedOptionText; } Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/pojos/McQueContent.java =================================================================== diff -u -r3f7d82f8f5d0c6881eb83f9ce8c36720e9756649 -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/pojos/McQueContent.java (.../McQueContent.java) (revision 3f7d82f8f5d0c6881eb83f9ce8c36720e9756649) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/pojos/McQueContent.java (.../McQueContent.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -63,9 +63,6 @@ private org.lamsfoundation.lams.tool.mc.pojos.McContent mcContent; /** persistent field */ - private Set mcUsrAttempts; - - /** persistent field */ private Set mcOptionsContents; //DTO fields @@ -79,7 +76,6 @@ this.mark = mark; this.feedback = feedback; this.mcContent = mcContent; - this.mcUsrAttempts = mcUsrAttempts; this.mcOptionsContents = mcOptionsContents; } @@ -96,9 +92,7 @@ * the original qa question content * @return the new qa question content object */ - public static McQueContent newInstance(McQueContent queContent, McContent newMcContent) - - { + public static McQueContent newInstance(McQueContent queContent, McContent newMcContent) { McQueContent newQueContent = new McQueContent(queContent.getQuestion(), queContent.getDisplayOrder(), queContent.getMark(), queContent.getFeedback(), newMcContent, new TreeSet(), new TreeSet()); @@ -111,10 +105,7 @@ for (Iterator i = this.getMcOptionsContents().iterator(); i.hasNext();) { McOptsContent mcOptsContent = (McOptsContent) i.next(); McOptsContent mcNewOptsContent = McOptsContent.newInstance(mcOptsContent, newQueContent); - - if (mcNewOptsContent.getMcQueContent() != null) { - newMcOptionsContent.add(mcNewOptsContent); - } + newMcOptionsContent.add(mcNewOptsContent); } return newMcOptionsContent; } @@ -159,16 +150,6 @@ this.mcContent = mcContent; } - public Set getMcUsrAttempts() { - if (this.mcUsrAttempts == null) - setMcUsrAttempts(new HashSet()); - return this.mcUsrAttempts; - } - - public void setMcUsrAttempts(Set mcUsrAttempts) { - this.mcUsrAttempts = mcUsrAttempts; - } - public Set getMcOptionsContents() { if (this.mcOptionsContents == null) setMcOptionsContents(new HashSet()); Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/pojos/McUsrAttempt.java =================================================================== diff -u -r3f7d82f8f5d0c6881eb83f9ce8c36720e9756649 -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/pojos/McUsrAttempt.java (.../McUsrAttempt.java) (revision 3f7d82f8f5d0c6881eb83f9ce8c36720e9756649) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/pojos/McUsrAttempt.java (.../McUsrAttempt.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -80,7 +80,32 @@ /** default constructor */ public McUsrAttempt() { } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((uid == null) ? 0 : uid.hashCode()); + return result; + } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + McUsrAttempt other = (McUsrAttempt) obj; + if (uid == null) { + if (other.uid != null) + return false; + } else if (!uid.equals(other.uid)) + return false; + return true; + } + public Long getUid() { return this.uid; } Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/IMcService.java =================================================================== diff -u -rd66da54e1b79ff5493ac331ec290649184965a7e -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/IMcService.java (.../IMcService.java) (revision d66da54e1b79ff5493ac331ec290649184965a7e) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/IMcService.java (.../IMcService.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -23,21 +23,19 @@ package org.lamsfoundation.lams.tool.mc.service; import java.io.IOException; -import java.io.InputStream; import java.util.List; +import java.util.Set; -import org.lamsfoundation.lams.contentrepository.ITicket; -import org.lamsfoundation.lams.contentrepository.NodeKey; -import org.lamsfoundation.lams.contentrepository.RepositoryCheckedException; import org.lamsfoundation.lams.notebook.model.NotebookEntry; import org.lamsfoundation.lams.tool.IToolVO; import org.lamsfoundation.lams.tool.ToolSessionExportOutputData; import org.lamsfoundation.lams.tool.exception.DataMissingException; import org.lamsfoundation.lams.tool.exception.SessionDataExistsException; import org.lamsfoundation.lams.tool.exception.ToolException; import org.lamsfoundation.lams.tool.mc.McApplicationException; -import org.lamsfoundation.lams.tool.mc.McCandidateAnswersDTO; +import org.lamsfoundation.lams.tool.mc.McOptionDTO; import org.lamsfoundation.lams.tool.mc.McLearnerAnswersDTO; +import org.lamsfoundation.lams.tool.mc.McQuestionDTO; import org.lamsfoundation.lams.tool.mc.McSessionMarkDTO; import org.lamsfoundation.lams.tool.mc.ReflectionDTO; import org.lamsfoundation.lams.tool.mc.pojos.McContent; @@ -48,9 +46,9 @@ import org.lamsfoundation.lams.tool.mc.pojos.McUsrAttempt; /** - * @author Ozgur Demirtas + * Interface that defines the contract that all MCQ service provider must follow. * - * Interface that defines the contract that all MCQ service provider must follow. + * @author Ozgur Demirtas */ public interface IMcService { @@ -73,14 +71,12 @@ void createMc(McContent mcContent) throws McApplicationException; - McContent retrieveMc(Long toolContentId) throws McApplicationException; + McContent getMcContent(Long toolContentId) throws McApplicationException; - void createMcQue(McQueContent mcQueContent) throws McApplicationException; + void createQuestion(McQueContent mcQueContent) throws McApplicationException; - void updateMcQueContent(McQueContent mcQueContent) throws McApplicationException; + void updateQuestion(McQueContent mcQueContent) throws McApplicationException; - List retrieveMcQueContentsByToolContentId(long mcContentId) throws McApplicationException; - McQueContent getQuestionByDisplayOrder(final Long displayOrder, final Long mcContentUid) throws McApplicationException; @@ -90,19 +86,17 @@ McQueUsr getMcUserBySession(final Long queUsrId, final Long mcSessionUid) throws McApplicationException; - McQueUsr retrieveMcQueUsr(Long userId) throws McApplicationException; - void saveUserAttempt(McQueUsr user, List selectedQuestionAndCandidateAnswersDTO); void updateMcUsrAttempt(McUsrAttempt mcUsrAttempt) throws McApplicationException; - McQueContent retrieveMcQueContentByUID(Long uid) throws McApplicationException; - void removeMcQueContent(McQueContent mcQueContent) throws McApplicationException; McQueContent getMcQueContentByUID(Long uid) throws McApplicationException; void saveOrUpdateMcQueContent(McQueContent mcQueContent) throws McApplicationException; + + void releaseQuestionsFromCache(McContent content); void removeQuestionContentByMcUid(final Long mcContentUid) throws McApplicationException; @@ -114,31 +108,27 @@ List getAllQuestionEntriesSorted(final long mcContentId) throws McApplicationException; - McQueContent getQuestionByUid(Long uid) throws McApplicationException; + McQueContent getQuestionByUid(Long uid); - void removeMcOptionsContentByQueId(Long mcQueContentId) throws McApplicationException; - void removeMcOptionsContent(McOptsContent mcOptsContent); - McQueContent getQuestionContentByQuestionText(final String question, final Long mcContentUid); + McQueContent getQuestionByQuestionText(final String question, final Long mcContentUid); void removeMcQueContentByUID(Long uid) throws McApplicationException; McQueUsr getMcUserByUID(Long uid) throws McApplicationException; - List getAllQuestionEntries(final Long mcContentId) throws McApplicationException; + List getQuestionsByContentUid(final Long mcContentId) throws McApplicationException; McSession getMcSessionById(Long mcSessionId) throws McApplicationException; - McContent retrieveMcBySessionId(Long mcSessionId) throws McApplicationException; - void updateMc(McContent mc) throws McApplicationException; void updateMcSession(McSession mcSession) throws McApplicationException; void updateMcQueUsr(McQueUsr mcQueUsr) throws McApplicationException; - List populateCandidateAnswersDTO(Long mcQueContentId) throws McApplicationException; + List getOptionDtos(Long mcQueContentId) throws McApplicationException; McSession getMcSessionByUID(Long uid) throws McApplicationException; @@ -150,9 +140,9 @@ void deleteMcQueUsr(McQueUsr mcQueUsr) throws McApplicationException; - List findMcOptionsContentByQueId(Long mcQueContentId) throws McApplicationException; + List findOptionsByQuestionUid(Long mcQueContentId) throws McApplicationException; - void saveMcOptionsContent(McOptsContent mcOptsContent) throws McApplicationException; + void saveOption(McOptsContent mcOptsContent) throws McApplicationException; McOptsContent getOptionContentByOptionText(final String option, final Long mcQueContentUid); @@ -191,8 +181,6 @@ long getToolDefaultContentIdBySignature(String toolSignature) throws McApplicationException; - McQueContent getToolDefaultQuestionContent(long contentId) throws McApplicationException; - List getNextAvailableDisplayOrder(final long mcContentId) throws McApplicationException; List findMcOptionCorrectByQueId(Long mcQueContentId) throws McApplicationException; @@ -248,6 +236,9 @@ void changeUserAttemptMark(Long userAttemptUid, Integer newMark); + void recalculateUserAnswers(McContent content, Set oldQuestions, List questionDTOs, + List deletedQuestions); + /** * * returns reflection data for all sessions Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/McImportContentVersionFilter.java =================================================================== diff -u -rbe07c35c372d904a65581d98660e73f3b13b69db -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/McImportContentVersionFilter.java (.../McImportContentVersionFilter.java) (revision be07c35c372d904a65581d98660e73f3b13b69db) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/McImportContentVersionFilter.java (.../McImportContentVersionFilter.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -10,7 +10,6 @@ * Import filter class for different version of MC content. * * @author steven - * */ public class McImportContentVersionFilter extends ToolContentVersionFilter { @@ -26,15 +25,13 @@ public void up20061015To20061113() { // Change name to suit the version you give the tool. - this.addField(McContent.class, "showMarks", new Boolean(false)); this.addField(McContent.class, "randomize", new Boolean(false)); this.addField(McOptsContent.class, "displayOrder", new Integer(0)); } public void up20061113To20070820() { // Adds displayAnswers LDEV-1156 - this.addField(McContent.class, "displayAnswers", new Boolean(true)); } @@ -47,4 +44,11 @@ this.removeField(McContent.class, "offlineInstructions"); this.removeField(McContent.class, "mcAttachments"); } + + /** + * Import 20131212 version content to 20140512 version tool server. + */ + public void up20140102To20140505() { + this.removeField(McContent.class, "contentInUse"); + } } Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/McServicePOJO.java =================================================================== diff -u -r5b6e51b5d96619f619209830fdab0ed1ef572c05 -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/McServicePOJO.java (.../McServicePOJO.java) (revision 5b6e51b5d96619f619209830fdab0ed1ef572c05) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/McServicePOJO.java (.../McServicePOJO.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -24,7 +24,6 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -51,20 +50,9 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.IndexedColors; -import org.lamsfoundation.lams.contentrepository.AccessDeniedException; -import org.lamsfoundation.lams.contentrepository.FileException; -import org.lamsfoundation.lams.contentrepository.ICredentials; -import org.lamsfoundation.lams.contentrepository.ITicket; -import org.lamsfoundation.lams.contentrepository.IVersionedNode; -import org.lamsfoundation.lams.contentrepository.ItemExistsException; import org.lamsfoundation.lams.contentrepository.ItemNotFoundException; -import org.lamsfoundation.lams.contentrepository.LoginException; -import org.lamsfoundation.lams.contentrepository.NodeKey; import org.lamsfoundation.lams.contentrepository.RepositoryCheckedException; -import org.lamsfoundation.lams.contentrepository.WorkspaceNotFoundException; import org.lamsfoundation.lams.contentrepository.client.IToolContentHandler; -import org.lamsfoundation.lams.contentrepository.service.IRepositoryService; -import org.lamsfoundation.lams.contentrepository.service.SimpleCredentials; import org.lamsfoundation.lams.gradebook.service.IGradebookService; import org.lamsfoundation.lams.learning.service.ILearnerService; import org.lamsfoundation.lams.learningdesign.service.ExportToolContentException; @@ -85,20 +73,19 @@ import org.lamsfoundation.lams.tool.exception.ToolException; import org.lamsfoundation.lams.tool.mc.McAppConstants; import org.lamsfoundation.lams.tool.mc.McApplicationException; -import org.lamsfoundation.lams.tool.mc.McCandidateAnswersDTO; +import org.lamsfoundation.lams.tool.mc.McOptionDTO; import org.lamsfoundation.lams.tool.mc.McLearnerAnswersDTO; +import org.lamsfoundation.lams.tool.mc.McQuestionDTO; import org.lamsfoundation.lams.tool.mc.McSessionMarkDTO; import org.lamsfoundation.lams.tool.mc.McStringComparator; import org.lamsfoundation.lams.tool.mc.McUserMarkDTO; -import org.lamsfoundation.lams.tool.mc.McUtils; import org.lamsfoundation.lams.tool.mc.ReflectionDTO; import org.lamsfoundation.lams.tool.mc.dao.IMcContentDAO; import org.lamsfoundation.lams.tool.mc.dao.IMcOptionsContentDAO; import org.lamsfoundation.lams.tool.mc.dao.IMcQueContentDAO; import org.lamsfoundation.lams.tool.mc.dao.IMcSessionDAO; import org.lamsfoundation.lams.tool.mc.dao.IMcUserDAO; import org.lamsfoundation.lams.tool.mc.dao.IMcUsrAttemptDAO; -import org.lamsfoundation.lams.tool.mc.dao.hibernate.McUserDAO; import org.lamsfoundation.lams.tool.mc.pojos.McContent; import org.lamsfoundation.lams.tool.mc.pojos.McOptsContent; import org.lamsfoundation.lams.tool.mc.pojos.McQueContent; @@ -121,15 +108,14 @@ /** * - * @author Ozgur Demirtas + * The POJO implementation of Mc service. All business logics of MCQ tool are implemented in this class. It translate + * the request from presentation layer and perform appropriate database operation. * - * The POJO implementation of Mc service. All business logics of MCQ tool are implemented in this class. It - * translate the request from presentation layer and perform appropriate database operation. - * + * @author Ozgur Demirtas */ public class McServicePOJO implements IMcService, ToolContentManager, ToolSessionManager, ToolContentImport102Manager, McAppConstants { - static Logger logger = Logger.getLogger(McServicePOJO.class.getName()); + private static Logger logger = Logger.getLogger(McServicePOJO.class.getName()); private IMcContentDAO mcContentDAO; private IMcQueContentDAO mcQueContentDAO; @@ -231,7 +217,7 @@ } } - public McContent retrieveMc(Long toolContentId) throws McApplicationException { + public McContent getMcContent(Long toolContentId) throws McApplicationException { try { return mcContentDAO.findMcContentById(toolContentId); } catch (DataAccessException e) { @@ -247,7 +233,7 @@ } } - public void createMcQue(McQueContent mcQueContent) throws McApplicationException { + public void createQuestion(McQueContent mcQueContent) throws McApplicationException { try { mcQueContentDAO.saveMcQueContent(mcQueContent); } catch (DataAccessException e) { @@ -256,7 +242,7 @@ } } - public void updateMcQueContent(McQueContent mcQueContent) throws McApplicationException { + public void updateQuestion(McQueContent mcQueContent) throws McApplicationException { try { mcQueContentDAO.updateMcQueContent(mcQueContent); } catch (DataAccessException e) { @@ -266,14 +252,6 @@ } - public List retrieveMcQueContentsByToolContentId(long mcContentId) throws McApplicationException { - try { - return mcQueContentDAO.getMcQueContentsByContentId(mcContentId); - } catch (DataAccessException e) { - throw new McApplicationException("Exception occured when lams is loading mc que usr: " + e.getMessage(), e); - } - } - public McQueContent getQuestionByDisplayOrder(final Long displayOrder, final Long mcContentUid) throws McApplicationException { try { @@ -310,6 +288,13 @@ + e.getMessage(), e); } } + + @Override + public void releaseQuestionsFromCache(McContent content) { + for (McQueContent question : (Set)content.getMcQueContents()) { + mcQueContentDAO.releaseQuestionFromCache(question); + } + } public void removeQuestionContentByMcUid(final Long mcContentUid) throws McApplicationException { try { @@ -398,19 +383,10 @@ } } - public McQueUsr retrieveMcQueUsr(Long userId) throws McApplicationException { - try { - McQueUsr mcQueUsr = mcUserDAO.findMcUserById(userId); - return mcQueUsr; - } catch (DataAccessException e) { - throw new McApplicationException("Exception occured when lams is retrieving McQueUsr: " + e.getMessage(), e); - } - } - @Override public void saveUserAttempt(McQueUsr user, List selectedQuestionAndCandidateAnswersDTO) { - Date attemptTime = McUtils.getGMTDateTime(); + Date attemptTime = new Date(System.currentTimeMillis()); for (McLearnerAnswersDTO mcLearnerAnswersDTO : selectedQuestionAndCandidateAnswersDTO) { @@ -469,7 +445,7 @@ @Override public List buildLearnerAnswersDTOList(McContent mcContent, McQueUsr user) { List learnerAnswersDTOList = new LinkedList(); - List questions = this.getAllQuestionEntries(mcContent.getUid()); + List questions = this.getQuestionsByContentUid(mcContent.getUid()); for (McQueContent question : questions) { McLearnerAnswersDTO learnerAnswersDTO = new McLearnerAnswersDTO(); @@ -636,19 +612,10 @@ } } - public McQueContent retrieveMcQueContentByUID(Long uid) throws McApplicationException { + public List getQuestionsByContentUid(final Long contentUid) throws McApplicationException { try { - return mcQueContentDAO.getMcQueContentByUID(uid); + return mcQueContentDAO.getQuestionsByContentUid(contentUid.longValue()); } catch (DataAccessException e) { - throw new McApplicationException("Exception occured when lams is retrieving by uid mc question content: " - + e.getMessage(), e); - } - } - - public List getAllQuestionEntries(final Long uid) throws McApplicationException { - try { - return mcQueContentDAO.getAllQuestionEntries(uid.longValue()); - } catch (DataAccessException e) { throw new McApplicationException("Exception occured when lams is getting by uid mc question content: " + e.getMessage(), e); } @@ -691,16 +658,16 @@ } } - public List populateCandidateAnswersDTO(Long mcQueContentId) throws McApplicationException { + public List getOptionDtos(Long mcQueContentId) throws McApplicationException { try { - return mcOptionsContentDAO.populateCandidateAnswersDTO(mcQueContentId); + return mcOptionsContentDAO.getOptionDtos(mcQueContentId); } catch (DataAccessException e) { throw new McApplicationException("Exception occured when lams is populating candidate answers dto" + e.getMessage(), e); } } - public McQueContent getQuestionContentByQuestionText(final String question, final Long mcContentId) { + public McQueContent getQuestionByQuestionText(final String question, final Long mcContentId) { try { return mcQueContentDAO.getQuestionContentByQuestionText(question, mcContentId); } catch (DataAccessException e) { @@ -718,15 +685,6 @@ } } - public McContent retrieveMcBySessionId(Long mcSessionId) throws McApplicationException { - try { - return mcContentDAO.getMcContentBySession(mcSessionId); - } catch (DataAccessException e) { - throw new McApplicationException("Exception occured when lams is retrieving mc by session id: " - + e.getMessage(), e); - } - } - public void updateMc(McContent mc) throws McApplicationException { try { mcContentDAO.updateMcContent(mc); @@ -791,10 +749,9 @@ } } - public List findMcOptionsContentByQueId(Long mcQueContentId) throws McApplicationException { + public List findOptionsByQuestionUid(Long mcQueContentId) throws McApplicationException { try { - List list = mcOptionsContentDAO.findMcOptionsContentByQueId(mcQueContentId); - return list; + return mcOptionsContentDAO.findMcOptionsContentByQueId(mcQueContentId); } catch (DataAccessException e) { throw new McApplicationException("Exception occured when lams is finding by que id" + " the mc options: " + e.getMessage(), e); @@ -810,16 +767,15 @@ } } - public McQueContent getQuestionByUid(Long uid) throws McApplicationException { - try { - return mcQueContentDAO.findMcQuestionContentByUid(uid); - } catch (DataAccessException e) { - throw new McApplicationException("Exception occured when lams is getting que content by uid" - + e.getMessage(), e); + public McQueContent getQuestionByUid(Long uid) { + if (uid == null) { + return null; } + + return mcQueContentDAO.findMcQuestionContentByUid(uid); } - public void saveMcOptionsContent(McOptsContent mcOptsContent) throws McApplicationException { + public void saveOption(McOptsContent mcOptsContent) throws McApplicationException { try { mcOptionsContentDAO.saveMcOptionsContent(mcOptsContent); } catch (DataAccessException e) { @@ -865,15 +821,6 @@ } } - public void removeMcOptionsContentByQueId(Long mcQueContentId) throws McApplicationException { - try { - mcOptionsContentDAO.removeMcOptionsContentByQueId(mcQueContentId); - } catch (DataAccessException e) { - throw new McApplicationException("Exception occured when lams is removing by que id" - + " the mc options content: " + e.getMessage(), e); - } - } - public void deleteMcOptionsContentByUID(Long uid) throws McApplicationException { try { mcOptionsContentDAO.removeMcOptionsContentByUID(uid); @@ -891,18 +838,7 @@ * @throws McApplicationException */ public boolean studentActivityOccurredGlobal(McContent mcContent) throws McApplicationException { - Iterator questionIterator = mcContent.getMcQueContents().iterator(); - while (questionIterator.hasNext()) { - McQueContent mcQueContent = (McQueContent) questionIterator.next(); - Iterator attemptsIterator = mcQueContent.getMcUsrAttempts().iterator(); - while (attemptsIterator.hasNext()) { - /** - * proved the fact that there is at least one attempt for this content. - */ - return true; - } - } - return false; + return !mcContent.getMcSessions().isEmpty(); } @Override @@ -932,6 +868,138 @@ } @Override + public void recalculateUserAnswers(McContent content, Set oldQuestions, + List questionDTOs, List deletedQuestions) { + + //create list of modified questions + List modifiedQuestions = new ArrayList(); + //create list of modified question marks + List modifiedQuestionsMarksOnly= new ArrayList(); + for (McQueContent oldQuestion : oldQuestions) { + for (McQuestionDTO questionDTO : questionDTOs) { + if (oldQuestion.getUid().equals(questionDTO.getUid())) { + + boolean isQuestionModified = false; + boolean isQuestionMarkModified = false; + + //question is different + if (!oldQuestion.getQuestion().equals(questionDTO.getQuestion())) { + isQuestionModified = true; + } + + //mark is different + if (oldQuestion.getMark().intValue() != (new Integer(questionDTO.getMark())).intValue()) { + isQuestionMarkModified = true; + } + + //options are different + Set oldOptions = oldQuestion.getMcOptionsContents(); + List optionDTOs = questionDTO.getListCandidateAnswersDTO(); + for (McOptsContent oldOption : oldOptions) { + for (McOptionDTO optionDTO : optionDTOs) { + if (oldOption.getUid().equals(optionDTO.getUid())) { + + if (!StringUtils.equals(oldOption.getMcQueOptionText(), optionDTO.getCandidateAnswer()) + || (oldOption.isCorrectOption() != "Correct".equals(optionDTO.getCorrect()))) { + isQuestionModified = true; + } + } + } + } + + if (isQuestionModified) { + modifiedQuestions.add(questionDTO); + + } else if (isQuestionMarkModified) { + modifiedQuestionsMarksOnly.add(questionDTO); + } + } + } + } + + Set sessionList = content.getMcSessions(); + for (McSession session : sessionList) { + Long toolSessionId = session.getMcSessionId(); + Set sessionUsers = session.getMcQueUsers(); + + for (McQueUsr user : sessionUsers) { + + final int oldTotalMark = mcUsrAttemptDAO.getUserTotalMark(user.getUid()); + int newTotalMark = oldTotalMark; + + //get all finished user results + List userAttempts = getFinalizedUserAttempts(user); + Iterator iter = userAttempts.iterator(); + while (iter.hasNext()) { + McUsrAttempt userAttempt = iter.next(); + + McQueContent question = userAttempt.getMcQueContent(); + + boolean isRemoveQuestionResult = false; + + // [+] if the question mark is modified + for (McQuestionDTO modifiedQuestion : modifiedQuestionsMarksOnly) { + if (question.getUid().equals(modifiedQuestion.getUid())) { + Integer newQuestionMark = new Integer(modifiedQuestion.getMark()); + Integer oldQuestionMark = question.getMark(); + Integer newActualMark = userAttempt.getMark() * newQuestionMark / oldQuestionMark; + + newTotalMark += newActualMark - userAttempt.getMark(); + + // update question answer's mark + userAttempt.setMark(newActualMark); + mcUsrAttemptDAO.saveMcUsrAttempt(userAttempt); + + break; + } + + } + + // [+] if the question is modified + for (McQuestionDTO modifiedQuestion : modifiedQuestions) { + if (question.getUid().equals(modifiedQuestion.getUid())) { + isRemoveQuestionResult = true; + break; + } + } + + // [+] if the question was removed + for (McQuestionDTO deletedQuestion : deletedQuestions) { + if (question.getUid().equals(deletedQuestion.getUid())) { + isRemoveQuestionResult = true; + break; + } + } + + if (isRemoveQuestionResult) { + + Integer oldMark = userAttempt.getMark(); + if (oldMark != null) { + newTotalMark -= oldMark; + } + + iter.remove(); + mcUsrAttemptDAO.removeAttempt(userAttempt); + } + + // [+] doing nothing if the new question was added + + + } + + // propagade new total mark to Gradebook if it was changed + if (newTotalMark != oldTotalMark) { + gradebookService.updateActivityMark(new Double(newTotalMark), null, user.getQueUsrId().intValue(), + toolSessionId, false); + } + + } + } + + + } + + @Override public byte[] prepareSessionDataSpreadsheet(McContent mcContent) throws IOException { Set questions = mcContent.getMcQueContents(); @@ -1240,64 +1308,33 @@ * @throws ToolException * */ - public void copyToolContent(Long fromContentId, Long toContentId) throws ToolException { + public void copyToolContent(Long fromContentId, Long toContentId) { if (fromContentId == null) { McServicePOJO.logger.warn("fromContentId is null."); - long defaultContentId = 0; - try { - defaultContentId = getToolDefaultContentIdBySignature(McAppConstants.MY_SIGNATURE); - fromContentId = new Long(defaultContentId); - } catch (Exception e) { - McServicePOJO.logger.error("default content id has not been setup for signature: " - + McAppConstants.MY_SIGNATURE); - throw new ToolException("WARNING! default content has not been setup for signature" - + McAppConstants.MY_SIGNATURE + " Can't continue!"); - } + long defaultContentId = getToolDefaultContentIdBySignature(McAppConstants.MY_SIGNATURE); + fromContentId = new Long(defaultContentId); } if (toContentId == null) { McServicePOJO.logger.error("throwing ToolException: toContentId is null"); throw new ToolException("toContentId is missing"); } - try { - McContent fromContent = mcContentDAO.findMcContentById(fromContentId); + McContent fromContent = mcContentDAO.findMcContentById(fromContentId); - if (fromContent == null) { - McServicePOJO.logger.warn("fromContent is null."); - long defaultContentId = 0; - try { - defaultContentId = getToolDefaultContentIdBySignature(McAppConstants.MY_SIGNATURE); - fromContentId = new Long(defaultContentId); - } catch (Exception e) { - McServicePOJO.logger.error("default content id has not been setup for signature: " - + McAppConstants.MY_SIGNATURE); - throw new ToolException("WARNING! default content has not been setup for signature" - + McAppConstants.MY_SIGNATURE + " Can't continue!"); - } + if (fromContent == null) { + McServicePOJO.logger.warn("fromContent is null."); + long defaultContentId = getToolDefaultContentIdBySignature(McAppConstants.MY_SIGNATURE); + fromContent = mcContentDAO.findMcContentById(defaultContentId); + } - fromContent = mcContentDAO.findMcContentById(fromContentId); - } - - try { - McContent toContent = McContent.newInstance(mcToolContentHandler, fromContent, toContentId); - if (toContent == null) { - McServicePOJO.logger.error("throwing ToolException: WARNING!, retrieved toContent is null."); - throw new ToolException("WARNING! Fail to create toContent. Can't continue!"); - } else { - mcContentDAO.saveMcContent(toContent); - } - - } catch (ItemNotFoundException e) { - McServicePOJO.logger.error("exception occurred: " + e); - } catch (RepositoryCheckedException e) { - McServicePOJO.logger.error("exception occurred: " + e); - } - } catch (DataAccessException e) { - McServicePOJO.logger - .error("throwing ToolException: Exception occured when lams is copying content between content ids."); - throw new ToolException("Exception occured when lams is copying content between content ids."); + McContent toContent = McContent.newInstance(fromContent, toContentId); + if (toContent == null) { + McServicePOJO.logger.error("throwing ToolException: WARNING!, retrieved toContent is null."); + throw new ToolException("WARNING! Fail to create toContent. Can't continue!"); + } else { + mcContentDAO.saveMcContent(toContent); } } @@ -1392,15 +1429,11 @@ try { // set ToolContentHandler as null to avoid copy file node in repository again. - toolContentObj = McContent.newInstance(null, toolContentObj, toolContentId); + toolContentObj = McContent.newInstance(toolContentObj, toolContentId); toolContentObj.setMcSessions(null); exportContentService.exportToolContent(toolContentId, toolContentObj, mcToolContentHandler, rootPath); } catch (ExportToolContentException e) { throw new ToolException(e); - } catch (ItemNotFoundException e) { - throw new ToolException(e); - } catch (RepositoryCheckedException e) { - throw new ToolException(e); } } @@ -1443,10 +1476,10 @@ */ public SortedMap getToolOutputDefinitions(Long toolContentId, int definitionType) throws ToolException { - McContent content = retrieveMc(toolContentId); + McContent content = getMcContent(toolContentId); if (content == null) { long defaultToolContentId = getToolDefaultContentIdBySignature(McAppConstants.MY_SIGNATURE); - content = retrieveMc(defaultToolContentId); + content = getMcContent(defaultToolContentId); } return getMcOutputFactory().getToolOutputDefinitions(content, definitionType); } @@ -1492,40 +1525,9 @@ throw new ToolException("toolSessionId is missing"); } - long defaultContentId = 0; - if (toolContentId == null) { - - try { - defaultContentId = getToolDefaultContentIdBySignature(McAppConstants.MY_SIGNATURE); - toolContentId = new Long(defaultContentId); - } catch (Exception e) { - McServicePOJO.logger.error("default content id has not been setup for signature: " - + McAppConstants.MY_SIGNATURE); - throw new ToolException("WARNING! default content has not been setup for signature" - + McAppConstants.MY_SIGNATURE + " Can't continue!"); - } - } - McContent mcContent = mcContentDAO.findMcContentById(toolContentId); - if (mcContent == null) { - - try { - defaultContentId = getToolDefaultContentIdBySignature(McAppConstants.MY_SIGNATURE); - toolContentId = new Long(defaultContentId); - } catch (Exception e) { - McServicePOJO.logger.error("default content id has not been setup for signature: " - + McAppConstants.MY_SIGNATURE); - throw new ToolException("WARNING! default content has not been setup for signature" - + McAppConstants.MY_SIGNATURE + " Can't continue!"); - } - - mcContent = mcContentDAO.findMcContentById(toolContentId); - } - - /* - * create a new a new tool session if it does not already exist in the tool session table - */ + //create a new a new tool session if it does not already exist in the tool session table if (!existsSession(toolSessionId)) { try { McSession mcSession = new McSession(toolSessionId, new Date(System.currentTimeMillis()), @@ -1672,17 +1674,12 @@ return tool; } - public long getToolDefaultContentIdBySignature(String toolSignature) throws McApplicationException { + public long getToolDefaultContentIdBySignature(String toolSignature) { long contentId = 0; contentId = toolService.getToolDefaultContentIdBySignature(toolSignature); return contentId; } - public McQueContent getToolDefaultQuestionContent(long contentId) throws McApplicationException { - McQueContent mcQueContent = mcQueContentDAO.getToolDefaultQuestionContent(contentId); - return mcQueContent; - } - public boolean isGroupedActivity(long toolContentID) { return toolService.isGroupedActivity(toolContentID); } @@ -1857,7 +1854,6 @@ public void import102ToolContent(Long toolContentId, UserDTO user, Hashtable importValues) { Date now = new Date(); McContent toolContentObj = new McContent(); - toolContentObj.setContentInUse(false); toolContentObj.setCreatedBy(user.getUserID().longValue()); toolContentObj.setCreationDate(now); toolContentObj.setDefineLater(false); @@ -2018,7 +2014,7 @@ McContent toolContentObj = null; if (toolContentId != null) { - toolContentObj = retrieveMc(toolContentId); + toolContentObj = getMcContent(toolContentId); } if (toolContentObj == null) { throw new DataMissingException("Unable to set reflective data titled " + title Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/AuthoringUtil.java =================================================================== diff -u -rbe07c35c372d904a65581d98660e73f3b13b69db -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/AuthoringUtil.java (.../AuthoringUtil.java) (revision be07c35c372d904a65581d98660e73f3b13b69db) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/AuthoringUtil.java (.../AuthoringUtil.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -23,543 +23,192 @@ package org.lamsfoundation.lams.tool.mc.web; import java.util.Date; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; import java.util.TreeMap; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.apache.log4j.Logger; import org.lamsfoundation.lams.tool.mc.McAppConstants; -import org.lamsfoundation.lams.tool.mc.McCandidateAnswersDTO; import org.lamsfoundation.lams.tool.mc.McComparator; -import org.lamsfoundation.lams.tool.mc.McQuestionContentDTO; +import org.lamsfoundation.lams.tool.mc.McOptionDTO; +import org.lamsfoundation.lams.tool.mc.McQuestionDTO; import org.lamsfoundation.lams.tool.mc.pojos.McContent; import org.lamsfoundation.lams.tool.mc.pojos.McOptsContent; import org.lamsfoundation.lams.tool.mc.pojos.McQueContent; import org.lamsfoundation.lams.tool.mc.service.IMcService; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; +import org.lamsfoundation.lams.util.WebUtil; import org.lamsfoundation.lams.web.session.SessionManager; import org.lamsfoundation.lams.web.util.AttributeNames; /** - * * Keeps all operations needed for Authoring mode. * * @author Ozgur Demirtas - * */ public class AuthoringUtil implements McAppConstants { - static Logger logger = Logger.getLogger(AuthoringUtil.class.getName()); + private static Logger logger = Logger.getLogger(AuthoringUtil.class.getName()); - /** - * setRadioboxes(McContent mcContent, McAuthoringForm mcAuthoringForm) - * - * set values of radioboxes for an existing content - * - * @param mcContent - * @param mcAuthoringForm - */ - protected static void setRadioboxes(McContent mcContent, McAuthoringForm mcAuthoringForm) { - mcAuthoringForm.setQuestionsSequenced(mcContent.isQuestionsSequenced() ? "1" : "0"); - mcAuthoringForm.setRandomize(mcContent.isRandomize() ? "1" : "0"); - mcAuthoringForm.setDisplayAnswers(mcContent.isDisplayAnswers() ? "1" : "0"); - mcAuthoringForm.setShowMarks(mcContent.isShowMarks() ? "1" : "0"); - mcAuthoringForm.setUseSelectLeaderToolOuput(mcContent.isUseSelectLeaderToolOuput() ? "1" : "0"); - mcAuthoringForm.setPrefixAnswersWithLetters(mcContent.isPrefixAnswersWithLetters() ? "1" : "0"); - mcAuthoringForm.setRetries(mcContent.isRetries() ? "1" : "0"); - mcAuthoringForm.setSln(mcContent.isShowReport() ? "1" : "0"); - mcAuthoringForm.setReflect(mcContent.isReflect() ? "1" : "0"); - } + public static List removeBlankOptions(List optionDtos) { + List newList = new LinkedList(); - /** - * verifyMapNoEmptyString(Map map) - * - * makes sure there is data in the map - * - * @param map - * @return boolean - */ - public static boolean verifyMapNoEmptyString(Map map) { - Iterator itMap = map.entrySet().iterator(); - while (itMap.hasNext()) { - Map.Entry pairs = (Map.Entry) itMap.next(); + for (McOptionDTO optionDTO : optionDtos) { + String optionText = optionDTO.getCandidateAnswer(); - if ((pairs.getValue() != null) && (pairs.getValue().toString().length() == 0)) { - return false; + if ((optionText != null) && (optionText.length() > 0)) { + newList.add(optionDTO); } - } - return true; - } - /** - * removes only unused question entries from the db. It keeps the valid entries since they get updated. - * - * cleanupRedundantQuestions(HttpServletRequest request, List existingQuestions, Map mapQuestionsContent, McContent - * mcContent) - * - * @param request - * @param existingQuestions - * @param mapQuestionsContent - * @param mcContent - */ - public static void cleanupRedundantQuestions(HttpServletRequest request, List existingQuestions, - Map mapQuestionsContent, McContent mcContent, IMcService mcService) { - - /* remove ununsed question entries from the db */ - boolean questionFound = false; - Iterator itExistingQuestions = existingQuestions.iterator(); - while (itExistingQuestions.hasNext()) { - McQueContent mcQueContent = (McQueContent) itExistingQuestions.next(); - - Iterator itNewQuestionsMap = mapQuestionsContent.entrySet().iterator(); - questionFound = false; - while (itNewQuestionsMap.hasNext()) { - Map.Entry pairs = (Map.Entry) itNewQuestionsMap.next(); - - if (mcQueContent.getQuestion().equals(pairs.getValue().toString())) { - questionFound = true; - break; - } - } - - if (questionFound == false) { - String deletableQuestion = mcQueContent.getQuestion(); - // found is false, delete this question - mcQueContent = mcService.getQuestionContentByQuestionText(deletableQuestion, mcContent.getUid()); - - if (mcQueContent != null) { - // first removing from collection - mcContent.getMcQueContents().remove(mcQueContent); - - mcService.removeMcQueContent(mcQueContent); - // removed mcQueContent from the db - } - } - } - } - - /** - * - * rebuildStartupGeneralOptionsContentMapfromDB(HttpServletRequest request, Map mapQuestionsUidContent) - * - * builds a map to hold all the candidate answers for all the questions by accessing the db - * - * @param request - * @param mapQuestionsUidContent - * @return - */ - public static Map rebuildStartupGeneralOptionsContentMapfromDB(HttpServletRequest request, - Map mapQuestionsUidContent, IMcService mcService) { - Map mapStartupGeneralOptionsContent = new TreeMap(new McComparator()); - - Iterator itMap = mapQuestionsUidContent.entrySet().iterator(); - Long mapIndex = new Long(1); - while (itMap.hasNext()) { - Map.Entry pairs = (Map.Entry) itMap.next(); - String currentQuestionUid = pairs.getValue().toString(); - List listQuestionOptions = mcService.findMcOptionsContentByQueId(new Long(currentQuestionUid)); - Map mapQuestionOptions = AuthoringUtil.generateOptionsMap(listQuestionOptions); - mapStartupGeneralOptionsContent.put(mapIndex.toString(), mapQuestionOptions); - mapIndex = new Long(mapIndex.longValue() + 1); - } - return mapStartupGeneralOptionsContent; - } - - protected static List removeBlankEntries(List list) { - List newList = new LinkedList(); - - Iterator listIterator = list.iterator(); - while (listIterator.hasNext()) { - McCandidateAnswersDTO mcCandidateAnswersDTO = (McCandidateAnswersDTO) listIterator.next(); - - if (mcCandidateAnswersDTO != null) { - String ca = mcCandidateAnswersDTO.getCandidateAnswer(); - - if ((ca != null) && (ca.length() > 0)) { - newList.add(mcCandidateAnswersDTO); - } - } - } - return newList; } /** - * - * generateOptionsMap(List listQuestionOptions) - * - * builds a questions map from questions list - * - * @param listQuestionOptions - * @return Map + * swappes McQuestionDTO questions in the list */ - public static Map generateOptionsMap(List listQuestionOptions) { - Map mapOptsContent = new TreeMap(new McComparator()); + public static List swapQuestions(List questionDTOs, String questionIndex, + String direction) { - Iterator listIterator = listQuestionOptions.iterator(); - Long mapIndex = new Long(1); - while (listIterator.hasNext()) { - McOptsContent mcOptsContent = (McOptsContent) listIterator.next(); - mapOptsContent.put(mapIndex.toString(), mcOptsContent.getMcQueOptionText()); - mapIndex = new Long(mapIndex.longValue() + 1); - } - return mapOptsContent; - } - - /** - * builds a map to hold question texts rebuildQuestionMapfromDB(HttpServletRequest request, Long toolContentId) - * - * @param request - * @param toolContentId - * @return Map - */ - public static Map rebuildQuestionMapfromDB(HttpServletRequest request, Long toolContentId, IMcService mcService) { - Map mapQuestionsContent = new TreeMap(new McComparator()); - - McContent mcContent = mcService.retrieveMc(toolContentId); - - List list = mcService.refreshQuestionContent(mcContent.getUid()); - - Iterator listIterator = list.iterator(); - Long mapIndex = new Long(1); - while (listIterator.hasNext()) { - McQueContent mcQueContent = (McQueContent) listIterator.next(); - mapQuestionsContent.put(mapIndex.toString(), mcQueContent.getQuestion()); - mapIndex = new Long(mapIndex.longValue() + 1); - } - - return mapQuestionsContent; - } - - public static Map rebuildFeedbackMapfromDB(HttpServletRequest request, Long toolContentId, IMcService mcService) { - Map map = new TreeMap(new McComparator()); - - McContent mcContent = mcService.retrieveMc(toolContentId); - - List list = mcService.refreshQuestionContent(mcContent.getUid()); - - Iterator listIterator = list.iterator(); - Long mapIndex = new Long(1); - while (listIterator.hasNext()) { - McQueContent mcQueContent = (McQueContent) listIterator.next(); - - String feedback = mcQueContent.getFeedback(); - - map.put(mapIndex.toString(), feedback); - mapIndex = new Long(mapIndex.longValue() + 1); - } - - return map; - } - - /** - * builds a map to hold persisted uid values for questions rebuildQuestionUidMapfromDB(HttpServletRequest request, - * Long toolContentId) - * - * @param request - * @param toolContentId - * @return Map - */ - public static Map rebuildQuestionUidMapfromDB(HttpServletRequest request, Long toolContentId, IMcService mcService) { - Map mapQuestionsContent = new TreeMap(new McComparator()); - - McContent mcContent = mcService.retrieveMc(toolContentId); - - if (mcContent != null) { - List list = mcService.refreshQuestionContent(mcContent.getUid()); - - Iterator listIterator = list.iterator(); - Long mapIndex = new Long(1); - while (listIterator.hasNext()) { - McQueContent mcQueContent = (McQueContent) listIterator.next(); - mapQuestionsContent.put(mapIndex.toString(), mcQueContent.getUid()); - mapIndex = new Long(mapIndex.longValue() + 1); - } - } - - return mapQuestionsContent; - } - - /** - * finds whether a candidate answer is selected or not isOptionSelected(Map mapGeneralSelectedOptionsContent, String - * optionText, String questionIndex) - * - * @param mapGeneralSelectedOptionsContent - * @param optionText - * @param questionIndex - * @return boolean - */ - public static boolean isOptionSelected(Map mapGeneralSelectedOptionsContent, String optionText, String questionIndex) { - Iterator itGSOMap = mapGeneralSelectedOptionsContent.entrySet().iterator(); - while (itGSOMap.hasNext()) { - Map.Entry pairs = (Map.Entry) itGSOMap.next(); - if (pairs.getKey().toString().equals(questionIndex)) { - Map currentOptionsMap = (Map) pairs.getValue(); - boolean isOptionSelectedInMap = AuthoringUtil.isOptionSelectedInMap(optionText, currentOptionsMap); - return isOptionSelectedInMap; - } - } - return false; - } - - /** - * checks the existence of a candidate answer in the options map isOptionSelectedInMap(String optionText, Map - * currentOptionsMap) - * - * @param optionText - * @param currentOptionsMap - * @return - */ - public static boolean isOptionSelectedInMap(String optionText, Map currentOptionsMap) { - Iterator itCOMap = currentOptionsMap.entrySet().iterator(); - while (itCOMap.hasNext()) { - Map.Entry pairs = (Map.Entry) itCOMap.next(); - if (pairs.getValue().toString().equals(optionText)) { - return true; - } - } - return false; - } - - /** - * List swapNodes(List listQuestionContentDTO, String questionIndex, String direction) - * - * swappes McQuestionContentDTO nodes in the list - * - * @param listQuestionContentDTO - * @param questionIndex - * @param direction - * @return - */ - protected static List swapNodes(List listQuestionContentDTO, String questionIndex, String direction) { - int intQuestionIndex = new Integer(questionIndex).intValue(); int intOriginalQuestionIndex = intQuestionIndex; - int replacedNodeIndex = 0; + int replacedQuestionIndex = 0; if (direction.equals("down")) { - replacedNodeIndex = ++intQuestionIndex; + replacedQuestionIndex = ++intQuestionIndex; } else { - replacedNodeIndex = --intQuestionIndex; - + replacedQuestionIndex = --intQuestionIndex; } - McQuestionContentDTO mainNode = AuthoringUtil.extractNodeAtDisplayOrder(listQuestionContentDTO, - intOriginalQuestionIndex); + McQuestionDTO mainQuestion = AuthoringUtil.getQuestionAtDisplayOrder(questionDTOs, intOriginalQuestionIndex); - McQuestionContentDTO replacedNode = AuthoringUtil.extractNodeAtDisplayOrder(listQuestionContentDTO, - replacedNodeIndex); + McQuestionDTO replacedQuestion = AuthoringUtil.getQuestionAtDisplayOrder(questionDTOs, replacedQuestionIndex); - if ((mainNode == null) || (replacedNode == null)) { - return listQuestionContentDTO; + if ((mainQuestion == null) || (replacedQuestion == null)) { + return questionDTOs; } - List listFinalQuestionContentDTO = new LinkedList(); + List newQuestionDtos = new LinkedList(); - listFinalQuestionContentDTO = AuthoringUtil.reorderSwappedListQuestionContentDTO(listQuestionContentDTO, - intOriginalQuestionIndex, replacedNodeIndex, mainNode, replacedNode); - - return listFinalQuestionContentDTO; - } - - /** - * List reorderSwappedListQuestionContentDTO(List listQuestionContentDTO, int intOriginalQuestionIndex, int - * replacedNodeIndex, McQuestionContentDTO mainNode, McQuestionContentDTO replacedNode) - * - * @param listQuestionContentDTO - * @param intOriginalQuestionIndex - * @param replacedNodeIndex - * @param mainNode - * @param replacedNode - * @return - */ - protected static List reorderSwappedListQuestionContentDTO(List listQuestionContentDTO, - int intOriginalQuestionIndex, int replacedNodeIndex, McQuestionContentDTO mainNode, - McQuestionContentDTO replacedNode) { - - List listFinalQuestionContentDTO = new LinkedList(); - int queIndex = 0; - Iterator listIterator = listQuestionContentDTO.iterator(); - while (listIterator.hasNext()) { - McQuestionContentDTO mcQuestionContentDTO = (McQuestionContentDTO) listIterator.next(); + Iterator iter = questionDTOs.iterator(); + while (iter.hasNext()) { + McQuestionDTO questionDto = (McQuestionDTO) iter.next(); queIndex++; - McQuestionContentDTO tempNode = new McQuestionContentDTO(); + McQuestionDTO tempQuestion = new McQuestionDTO(); - if ((!mcQuestionContentDTO.getDisplayOrder().equals(new Integer(intOriginalQuestionIndex).toString())) - && !mcQuestionContentDTO.getDisplayOrder().equals(new Integer(replacedNodeIndex).toString())) { - // normal cop - tempNode.setQuestion(mcQuestionContentDTO.getQuestion()); - tempNode.setDisplayOrder(mcQuestionContentDTO.getDisplayOrder()); - tempNode.setFeedback(mcQuestionContentDTO.getFeedback()); - tempNode.setListCandidateAnswersDTO(mcQuestionContentDTO.getListCandidateAnswersDTO()); - tempNode.setCaCount(mcQuestionContentDTO.getCaCount()); - tempNode.setMark(mcQuestionContentDTO.getMark()); + if ((!questionDto.getDisplayOrder().equals(new Integer(intOriginalQuestionIndex).toString())) + && !questionDto.getDisplayOrder().equals(new Integer(replacedQuestionIndex).toString())) { + // normal copy + tempQuestion = questionDto; - } else if (mcQuestionContentDTO.getDisplayOrder().equals(new Integer(intOriginalQuestionIndex).toString())) { + } else if (questionDto.getDisplayOrder().equals(new Integer(intOriginalQuestionIndex).toString())) { // move type 1 - tempNode.setQuestion(replacedNode.getQuestion()); - tempNode.setDisplayOrder(replacedNode.getDisplayOrder()); - tempNode.setFeedback(replacedNode.getFeedback()); - tempNode.setListCandidateAnswersDTO(replacedNode.getListCandidateAnswersDTO()); - tempNode.setCaCount(replacedNode.getCaCount()); - tempNode.setMark(replacedNode.getMark()); - } else if (mcQuestionContentDTO.getDisplayOrder().equals(new Integer(replacedNodeIndex).toString())) { + tempQuestion = replacedQuestion; + + } else if (questionDto.getDisplayOrder().equals(new Integer(replacedQuestionIndex).toString())) { // move type 2 - tempNode.setQuestion(mainNode.getQuestion()); - tempNode.setDisplayOrder(mainNode.getDisplayOrder()); - tempNode.setFeedback(mainNode.getFeedback()); - tempNode.setListCandidateAnswersDTO(mainNode.getListCandidateAnswersDTO()); - tempNode.setCaCount(mainNode.getCaCount()); - tempNode.setMark(mainNode.getMark()); + tempQuestion = mainQuestion; } - listFinalQuestionContentDTO.add(tempNode); + newQuestionDtos.add(tempQuestion); } - return listFinalQuestionContentDTO; + return newQuestionDtos; } /** - * List swapCandidateNodes(List listCandidates, String candidateIndex, String direction) - * - * swaps McCandidateAnswersDTO in the list - * - * - * @param listCandidates - * @param candidateIndex - * @param direction - * @return + * swaps options in the list */ - protected static List swapCandidateNodes(List listCandidates, String candidateIndex, String direction) { + public static List swapOptions(List optionDtos, String optionIndex, String direction) { - int intCandidateIndex = new Integer(candidateIndex).intValue(); - int intOriginalCandidateIndex = intCandidateIndex; + int intOptionIndex = new Integer(optionIndex).intValue(); + int intOriginalOptionIndex = intOptionIndex; - int replacedNodeIndex = 0; + int replacedOptionIndex = 0; if (direction.equals("down")) { - replacedNodeIndex = ++intCandidateIndex; + replacedOptionIndex = ++intOptionIndex; } else { - replacedNodeIndex = --intCandidateIndex; - + replacedOptionIndex = --intOptionIndex; } - McCandidateAnswersDTO mainNode = AuthoringUtil.extractCandidateAtOrder(listCandidates, - intOriginalCandidateIndex); + McOptionDTO mainOption = AuthoringUtil.getOptionAtDisplayOrder(optionDtos, intOriginalOptionIndex); - McCandidateAnswersDTO replacedNode = AuthoringUtil.extractCandidateAtOrder(listCandidates, replacedNodeIndex); + McOptionDTO replacedOption = AuthoringUtil.getOptionAtDisplayOrder(optionDtos, replacedOptionIndex); - if ((mainNode == null) || (replacedNode == null)) { - return listCandidates; + if ((mainOption == null) || (replacedOption == null)) { + return optionDtos; } - List listFinalCandidateDTO = new LinkedList(); + List newOptionDtos = new LinkedList(); - listFinalCandidateDTO = AuthoringUtil.reorderSwappedListCandidateDTO(listCandidates, intOriginalCandidateIndex, - replacedNodeIndex, mainNode, replacedNode); + int queIndex = 1; + for (McOptionDTO option : optionDtos) { - return listFinalCandidateDTO; - } - - /** - * reorderSwappedListCandidateDTO(List listCandidates, int intOriginalCandidateIndex, int replacedNodeIndex, - * McCandidateAnswersDTO mainNode, McCandidateAnswersDTO replacedNode) - * - * - * @param listCandidates - * @param intOriginalCandidateIndex - * @param replacedNodeIndex - * @param mainNode - * @param replacedNode - * @return - */ - protected static List reorderSwappedListCandidateDTO(List listCandidates, int intOriginalCandidateIndex, - int replacedNodeIndex, McCandidateAnswersDTO mainNode, McCandidateAnswersDTO replacedNode) { - - List listFinalCandidatesDTO = new LinkedList(); - - int queIndex = 0; - Iterator listIterator = listCandidates.iterator(); - while (listIterator.hasNext()) { - McCandidateAnswersDTO mcCandidateAnswersDTO = (McCandidateAnswersDTO) listIterator.next(); - queIndex++; - - McCandidateAnswersDTO tempNode = new McCandidateAnswersDTO(); - - if ((!new Integer(queIndex).toString().equals(new Integer(intOriginalCandidateIndex).toString())) - && !new Integer(queIndex).toString().equals(new Integer(replacedNodeIndex).toString())) { + McOptionDTO tempOption = new McOptionDTO(); + if ((!new Integer(queIndex).toString().equals(new Integer(intOriginalOptionIndex).toString())) + && !new Integer(queIndex).toString().equals(new Integer(replacedOptionIndex).toString())) { // normal copy - tempNode.setCandidateAnswer(mcCandidateAnswersDTO.getCandidateAnswer()); - tempNode.setCorrect(mcCandidateAnswersDTO.getCorrect()); - } else if (new Integer(queIndex).toString().equals(new Integer(intOriginalCandidateIndex).toString())) { + tempOption = option; + } else if (new Integer(queIndex).toString().equals(new Integer(intOriginalOptionIndex).toString())) { // move type 1 - tempNode.setCandidateAnswer(replacedNode.getCandidateAnswer()); - tempNode.setCorrect(replacedNode.getCorrect()); - } else if (new Integer(queIndex).toString().equals(new Integer(replacedNodeIndex).toString())) { + tempOption = replacedOption; + } else if (new Integer(queIndex).toString().equals(new Integer(replacedOptionIndex).toString())) { // move type 2 - tempNode.setCandidateAnswer(mainNode.getCandidateAnswer()); - tempNode.setCorrect(mainNode.getCorrect()); + tempOption = mainOption; } - listFinalCandidatesDTO.add(tempNode); + newOptionDtos.add(tempOption); + queIndex++; } - return listFinalCandidatesDTO; + return newOptionDtos; } /** - * McQuestionContentDTO extractNodeAtDisplayOrder(List listQuestionContentDTO, int intOriginalQuestionIndex) - * - * returns McQuestionContentDTO in the specified order of the list - * - * @param listQuestionContentDTO - * @param intOriginalQuestionIndex - * @return + * returns McQuestionDTO in the specified order of the list */ - protected static McQuestionContentDTO extractNodeAtDisplayOrder(List listQuestionContentDTO, - int intOriginalQuestionIndex) { + public static McQuestionDTO getQuestionAtDisplayOrder(List questionDTOs, int intOriginalQuestionIndex) { - Iterator listIterator = listQuestionContentDTO.iterator(); - while (listIterator.hasNext()) { - McQuestionContentDTO mcQuestionContentDTO = (McQuestionContentDTO) listIterator.next(); + Iterator iter = questionDTOs.iterator(); + while (iter.hasNext()) { + McQuestionDTO questionDto = (McQuestionDTO) iter.next(); - if (new Integer(intOriginalQuestionIndex).toString().equals(mcQuestionContentDTO.getDisplayOrder())) { - return mcQuestionContentDTO; + if (new Integer(intOriginalQuestionIndex).toString().equals(questionDto.getDisplayOrder())) { + return questionDto; } } return null; } /** - * McCandidateAnswersDTO extractCandidateAtOrder(List listCandidates, int intOriginalCandidateIndex) - * - * @param listCandidates - * @param intOriginalCandidateIndex - * @return + * extractCandidateAtOrder */ - protected static McCandidateAnswersDTO extractCandidateAtOrder(List listCandidates, int intOriginalCandidateIndex) { + public static McOptionDTO getOptionAtDisplayOrder(List options, int intOriginalCandidateIndex) { int counter = 0; - Iterator listIterator = listCandidates.iterator(); - while (listIterator.hasNext()) { + Iterator iter = options.iterator(); + while (iter.hasNext()) { ++counter; - McCandidateAnswersDTO mcCandidateAnswerDTO = (McCandidateAnswersDTO) listIterator.next(); + McOptionDTO optionDto = (McOptionDTO) iter.next(); if (new Integer(intOriginalCandidateIndex).toString().equals(new Integer(counter).toString())) { - return mcCandidateAnswerDTO; + return optionDto; } } return null; } - protected static String getTotalMark(List listQuestionContentDTO) { + public static String getTotalMark(List questionDTOs) { - Map mapMarks = AuthoringUtil.extractMapMarks(listQuestionContentDTO); + Map mapMarks = AuthoringUtil.extractMapMarks(questionDTOs); int intTotalMark = 0; Iterator itMap = mapMarks.entrySet().iterator(); @@ -579,193 +228,95 @@ } /** - * extractMapQuestionContent(List listQuestionContentDTO) - * - * @param listQuestionContentDTO - * @return + * extractMapQuestionContent */ - protected static Map extractMapQuestionContent(List listQuestionContentDTO) { - Map mapQuestionContent = new TreeMap(new McComparator()); + public static Map extractMapQuestions(List questionDTOs) { + Map mapQuestionContent = new TreeMap(new McComparator()); - Iterator listIterator = listQuestionContentDTO.iterator(); + Iterator iter = questionDTOs.iterator(); int queIndex = 0; - while (listIterator.hasNext()) { - McQuestionContentDTO mcQuestionContentDTO = (McQuestionContentDTO) listIterator.next(); + while (iter.hasNext()) { + McQuestionDTO questionDto = (McQuestionDTO) iter.next(); queIndex++; - mapQuestionContent.put(new Integer(queIndex).toString(), mcQuestionContentDTO.getQuestion()); + mapQuestionContent.put(new Integer(queIndex).toString(), questionDto.getQuestion()); } return mapQuestionContent; } /** - * List reorderListCandidatesDTO(List candidates) - * - * @param candidates - * @return + * reorderSimpleListQuestionContentDTO */ - protected static List reorderListCandidatesDTO(List candidates) { + public static List reorderSimpleQuestionDtos(List questionDTOs) { + List listFinalQuestionContentDTO = new LinkedList(); - List listFinalCandidatesDTO = new LinkedList(); - int queIndex = 0; - Iterator listIterator = candidates.iterator(); - while (listIterator.hasNext()) { - McCandidateAnswersDTO mcCandidateAnswersDTO = (McCandidateAnswersDTO) listIterator.next(); + Iterator iter = questionDTOs.iterator(); + while (iter.hasNext()) { + McQuestionDTO questionDto = (McQuestionDTO) iter.next(); - String answer = mcCandidateAnswersDTO.getCandidateAnswer(); + String question = questionDto.getQuestion(); - String correct = mcCandidateAnswersDTO.getCorrect(); + String feedback = questionDto.getFeedback(); - if ((answer != null) && (!answer.equals(""))) { - mcCandidateAnswersDTO.setCandidateAnswer(answer); - mcCandidateAnswersDTO.setCorrect(correct); + List optionDtos = questionDto.getListCandidateAnswersDTO(); - listFinalCandidatesDTO.add(mcCandidateAnswersDTO); + String mark = questionDto.getMark(); - } - } - - return listFinalCandidatesDTO; - } - - /** - * reorderListQuestionContentDTO(List listQuestionContentDTO, String excludeQuestionIndex) - * - * @param listQuestionContentDTO - * @param excludeQuestionIndex - * @return - */ - protected static List reorderListQuestionContentDTO(List listQuestionContentDTO, String excludeQuestionIndex) { - - List listFinalQuestionContentDTO = new LinkedList(); - - int queIndex = 0; - Iterator listIterator = listQuestionContentDTO.iterator(); - while (listIterator.hasNext()) { - McQuestionContentDTO mcQuestionContentDTO = (McQuestionContentDTO) listIterator.next(); - - String question = mcQuestionContentDTO.getQuestion(); - - String displayOrder = mcQuestionContentDTO.getDisplayOrder(); - - String feedback = mcQuestionContentDTO.getFeedback(); - - String caCount = mcQuestionContentDTO.getCaCount(); - - List caList = mcQuestionContentDTO.getListCandidateAnswersDTO(); - if ((question != null) && (!question.equals(""))) { - if (!displayOrder.equals(excludeQuestionIndex)) { - ++queIndex; - - mcQuestionContentDTO.setQuestion(question); - mcQuestionContentDTO.setDisplayOrder(new Integer(queIndex).toString()); - mcQuestionContentDTO.setFeedback(feedback); - mcQuestionContentDTO.setListCandidateAnswersDTO(caList); - - mcQuestionContentDTO.setCaCount(new Integer(mcQuestionContentDTO.getListCandidateAnswersDTO() - .size()).toString()); - - listFinalQuestionContentDTO.add(mcQuestionContentDTO); - } - } - } - - return listFinalQuestionContentDTO; - } - - /** - * List reorderSimpleListQuestionContentDTO(List listQuestionContentDTO) - * - * @param listQuestionContentDTO - * @return - */ - protected static List reorderSimpleListQuestionContentDTO(List listQuestionContentDTO) { - List listFinalQuestionContentDTO = new LinkedList(); - - int queIndex = 0; - Iterator listIterator = listQuestionContentDTO.iterator(); - while (listIterator.hasNext()) { - McQuestionContentDTO mcQuestionContentDTO = (McQuestionContentDTO) listIterator.next(); - - String question = mcQuestionContentDTO.getQuestion(); - - String displayOrder = mcQuestionContentDTO.getDisplayOrder(); - - String feedback = mcQuestionContentDTO.getFeedback(); - - List caList = mcQuestionContentDTO.getListCandidateAnswersDTO(); - - String caCount = mcQuestionContentDTO.getCaCount(); - - String mark = mcQuestionContentDTO.getMark(); - - if ((question != null) && (!question.equals(""))) { ++queIndex; - mcQuestionContentDTO.setQuestion(question); - mcQuestionContentDTO.setDisplayOrder(new Integer(queIndex).toString()); - mcQuestionContentDTO.setFeedback(feedback); - mcQuestionContentDTO.setListCandidateAnswersDTO(caList); - mcQuestionContentDTO.setCaCount(caCount); - mcQuestionContentDTO.setMark(mark); - listFinalQuestionContentDTO.add(mcQuestionContentDTO); + questionDto.setQuestion(question); + questionDto.setDisplayOrder(new Integer(queIndex).toString()); + questionDto.setFeedback(feedback); + questionDto.setListCandidateAnswersDTO(optionDtos); + questionDto.setMark(mark); + listFinalQuestionContentDTO.add(questionDto); } } return listFinalQuestionContentDTO; } /** - * reorderUpdateListQuestionContentDTO(List listQuestionContentDTO, McQuestionContentDTO mcQuestionContentDTONew, - * String editableQuestionIndex) - * - * @param listQuestionContentDTO - * @param mcQuestionContentDTONew - * @param editableQuestionIndex - * @return + * reorderUpdateListQuestionContentDTO */ - protected static List reorderUpdateListQuestionContentDTO(List listQuestionContentDTO, - McQuestionContentDTO mcQuestionContentDTONew, String editableQuestionIndex) { + public static List reorderUpdateQuestionDtos(List questionDTOs, McQuestionDTO mcQuestionContentDTONew, + String editableQuestionIndex) { List listFinalQuestionContentDTO = new LinkedList(); int queIndex = 0; - Iterator listIterator = listQuestionContentDTO.iterator(); - while (listIterator.hasNext()) { - McQuestionContentDTO mcQuestionContentDTO = (McQuestionContentDTO) listIterator.next(); + Iterator iter = questionDTOs.iterator(); + while (iter.hasNext()) { + McQuestionDTO questionDto = (McQuestionDTO) iter.next(); ++queIndex; - String question = mcQuestionContentDTO.getQuestion(); + String question = questionDto.getQuestion(); - String displayOrder = mcQuestionContentDTO.getDisplayOrder(); + String displayOrder = questionDto.getDisplayOrder(); - String feedback = mcQuestionContentDTO.getFeedback(); + String feedback = questionDto.getFeedback(); - String mark = mcQuestionContentDTO.getMark(); + String mark = questionDto.getMark(); - List caList = mcQuestionContentDTO.getListCandidateAnswersDTO(); + List optionDtos = questionDto.getListCandidateAnswersDTO(); - String caCount = mcQuestionContentDTO.getCaCount(); - if (displayOrder.equals(editableQuestionIndex)) { - mcQuestionContentDTO.setQuestion(mcQuestionContentDTONew.getQuestion()); - mcQuestionContentDTO.setDisplayOrder(mcQuestionContentDTONew.getDisplayOrder()); - mcQuestionContentDTO.setFeedback(mcQuestionContentDTONew.getFeedback()); - mcQuestionContentDTO.setMark(mcQuestionContentDTONew.getMark()); - mcQuestionContentDTO.setCaCount(mcQuestionContentDTONew.getCaCount()); - mcQuestionContentDTO.setListCandidateAnswersDTO(mcQuestionContentDTONew.getListCandidateAnswersDTO()); + questionDto.setQuestion(mcQuestionContentDTONew.getQuestion()); + questionDto.setDisplayOrder(mcQuestionContentDTONew.getDisplayOrder()); + questionDto.setFeedback(mcQuestionContentDTONew.getFeedback()); + questionDto.setMark(mcQuestionContentDTONew.getMark()); + questionDto.setListCandidateAnswersDTO(mcQuestionContentDTONew.getListCandidateAnswersDTO()); - listFinalQuestionContentDTO.add(mcQuestionContentDTO); + listFinalQuestionContentDTO.add(questionDto); } else { - mcQuestionContentDTO.setQuestion(question); - mcQuestionContentDTO.setDisplayOrder(displayOrder); - mcQuestionContentDTO.setFeedback(feedback); - mcQuestionContentDTO.setMark(mark); - mcQuestionContentDTO.setCaCount(caCount); - mcQuestionContentDTO.setListCandidateAnswersDTO(caList); - listFinalQuestionContentDTO.add(mcQuestionContentDTO); + questionDto.setQuestion(question); + questionDto.setDisplayOrder(displayOrder); + questionDto.setFeedback(feedback); + questionDto.setMark(mark); + questionDto.setListCandidateAnswersDTO(optionDtos); + listFinalQuestionContentDTO.add(questionDto); } @@ -775,51 +326,15 @@ } /** - * sorts the questions by the display order - * - * reOrganizeDisplayOrder(Map mapQuestionContent, IMcService mcService, McAuthoringForm mcAuthoringForm, McContent - * mcContent) - * - * @param mapQuestionContent - * @param mcService - * @param mcAuthoringForm - * @param mcContent - */ - public void reOrganizeDisplayOrder(Map mapQuestionContent, IMcService mcService, McAuthoringForm mcAuthoringForm, - McContent mcContent) { - if (mcContent != null) { - List sortedQuestions = mcService.getAllQuestionEntriesSorted(mcContent.getUid().longValue()); - - Iterator listIterator = sortedQuestions.iterator(); - int displayOrder = 1; - while (listIterator.hasNext()) { - McQueContent queContent = (McQueContent) listIterator.next(); - - McQueContent existingMcQueContent = mcService.getQuestionContentByQuestionText( - queContent.getQuestion(), mcContent.getUid()); - existingMcQueContent.setDisplayOrder(new Integer(displayOrder)); - mcService.updateMcQueContent(existingMcQueContent); - displayOrder++; - } - } - } - - /** - * boolean checkDuplicateQuestions(List listQuestionContentDTO, String newQuestion) - * * verifies that there are no duplicate questions - * - * @param listQuestionContentDTO - * @param newQuestion - * @return */ - public static boolean checkDuplicateQuestions(List listQuestionContentDTO, String newQuestion) { + public static boolean checkDuplicateQuestions(List questionDTOs, String newQuestion) { - Map mapQuestionContent = AuthoringUtil.extractMapQuestionContent(listQuestionContentDTO); + Map mapQuestionContent = AuthoringUtil.extractMapQuestions(questionDTOs); - Iterator itMap = mapQuestionContent.entrySet().iterator(); + Iterator> itMap = mapQuestionContent.entrySet().iterator(); while (itMap.hasNext()) { - Map.Entry pairs = (Map.Entry) itMap.next(); + Entry pairs = itMap.next(); if ((pairs.getValue() != null) && (!pairs.getValue().equals(""))) { if (pairs.getValue().equals(newQuestion)) { @@ -831,174 +346,36 @@ } /** - * removes unused question entries from db removeRedundantQuestions (Map mapQuestionContent, IMcService mcService, - * McAuthoringForm mcAuthoringForm) - * - * @param mapQuestionContent - * @param mcService - * @param mcAuthoringForm + * extractMapMarks */ - public void removeRedundantQuestions(Map mapQuestionContent, IMcService mcService, McAuthoringForm mcAuthoringForm, - HttpServletRequest request, String toolContentID) { - - McContent mcContent = mcService.retrieveMc(new Long(toolContentID)); - - if (mcContent != null) { - List allQuestions = mcService.getAllQuestionEntries(mcContent.getUid()); - - Iterator listIterator = allQuestions.iterator(); - int mapIndex = 0; - boolean entryUsed = false; - while (listIterator.hasNext()) { - ++mapIndex; - - McQueContent queContent = (McQueContent) listIterator.next(); - - entryUsed = false; - Iterator itMap = mapQuestionContent.entrySet().iterator(); - int displayOrder = 0; - while (itMap.hasNext()) { - ++displayOrder; - entryUsed = false; - Map.Entry pairs = (Map.Entry) itMap.next(); - - if (pairs.getValue().toString().length() != 0) { - - if (mapIndex == displayOrder) { - entryUsed = true; - break; - } - - } - } - - if (entryUsed == false) { - // removing unused entry in db - - McQueContent removeableMcQueContent = mcService.getQuestionContentByQuestionText( - queContent.getQuestion(), mcContent.getUid()); - if (removeableMcQueContent != null) { - // mcContent.getMcQueContents().remove(removeableMcQueContent); - mcService.removeMcQueContent(removeableMcQueContent); - } - - } - } - } - - } - - /** - * Map extractMapFeedback(List listQuestionContentDTO) - * - * @param listQuestionContentDTO - * @return - */ - protected static Map extractMapFeedback(List listQuestionContentDTO) { - Map mapFeedbackContent = new TreeMap(new McComparator()); - - Iterator listIterator = listQuestionContentDTO.iterator(); - int queIndex = 0; - while (listIterator.hasNext()) { - McQuestionContentDTO mcQuestionContentDTO = (McQuestionContentDTO) listIterator.next(); - - queIndex++; - mapFeedbackContent.put(new Integer(queIndex).toString(), mcQuestionContentDTO.getFeedback()); - } - return mapFeedbackContent; - } - - /** - * Map extractMapWeights(List listQuestionContentDTO) - * - * @param listQuestionContentDTO - * @return - */ - protected static Map extractMapWeights(List listQuestionContentDTO) { - Map mapWeights = new TreeMap(new McComparator()); - - Iterator listIterator = listQuestionContentDTO.iterator(); - int queIndex = 0; - while (listIterator.hasNext()) { - McQuestionContentDTO mcQuestionContentDTO = (McQuestionContentDTO) listIterator.next(); - - queIndex++; - mapWeights.put(new Integer(queIndex).toString(), mcQuestionContentDTO.getWeight()); - } - return mapWeights; - } - - /** - * Map extractMapMarks(List listQuestionContentDTO) - * - * @param listQuestionContentDTO - * @return - */ - protected static Map extractMapMarks(List listQuestionContentDTO) { + public static Map extractMapMarks(List questionDTOs) { Map mapMarks = new TreeMap(new McComparator()); - Iterator listIterator = listQuestionContentDTO.iterator(); + Iterator iter = questionDTOs.iterator(); int queIndex = 0; - while (listIterator.hasNext()) { - McQuestionContentDTO mcQuestionContentDTO = (McQuestionContentDTO) listIterator.next(); + while (iter.hasNext()) { + McQuestionDTO questionDto = (McQuestionDTO) iter.next(); queIndex++; - mapMarks.put(new Integer(queIndex).toString(), mcQuestionContentDTO.getMark()); + mapMarks.put(new Integer(queIndex).toString(), questionDto.getMark()); } return mapMarks; } /** - * Map extractMapCandidatesList(List listQuestionContentDTO) - * - * @param listQuestionContentDTO - * @return + * persisting content */ - protected static Map extractMapCandidatesList(List listQuestionContentDTO) { - Map mapCandidatesList = new TreeMap(new McComparator()); - - Iterator listIterator = listQuestionContentDTO.iterator(); - int queIndex = 0; - while (listIterator.hasNext()) { - McQuestionContentDTO mcQuestionContentDTO = (McQuestionContentDTO) listIterator.next(); - - queIndex++; - mapCandidatesList.put(new Integer(queIndex).toString(), mcQuestionContentDTO.getListCandidateAnswersDTO()); - } - return mapCandidatesList; - } - - /** - * saveOrUpdateMcContent(Map mapQuestionContent, Map mapFeedback, Map mapWeights, Map mapMarks, Map - * mapCandidatesList, IMcService mcService, McAuthoringForm mcAuthoringForm, HttpServletRequest request, McContent - * mcContent, String strToolContentID) - * - * enables persisting content - * - * @param mapQuestionContent - * @param mapFeedback - * @param mapWeights - * @param mapMarks - * @param mapCandidatesList - * @param mcService - * @param mcAuthoringForm - * @param request - * @param mcContent - * @param strToolContentID - * @return - */ - public McContent saveOrUpdateMcContent(Map mapQuestionContent, Map mapFeedback, Map mapWeights, Map mapMarks, - Map mapCandidatesList, IMcService mcService, McAuthoringForm mcAuthoringForm, HttpServletRequest request, + public static McContent saveOrUpdateMcContent(IMcService mcService, HttpServletRequest request, McContent mcContent, String strToolContentID) { UserDTO toolUser = (UserDTO) SessionManager.getSession().getAttribute(AttributeNames.USER); String richTextTitle = request.getParameter(McAppConstants.TITLE); String richTextInstructions = request.getParameter(McAppConstants.INSTRUCTIONS); String sln = request.getParameter("sln"); - + String useSelectLeaderToolOuput = request.getParameter("useSelectLeaderToolOuput"); - + String prefixAnswersWithLetters = request.getParameter("prefixAnswersWithLetters"); String questionsSequenced = request.getParameter("questionsSequenced"); @@ -1015,14 +392,6 @@ String reflectionSubject = request.getParameter(McAppConstants.REFLECTION_SUBJECT); - String activeModule = request.getParameter(McAppConstants.ACTIVE_MODULE); - - boolean setCommonContent = true; - if ((sln == null) || (questionsSequenced == null) || (retries == null) || (reflect == null) - || (showMarks == null) || (randomize == null)) { - setCommonContent = false; - } - boolean questionsSequencedBoolean = false; boolean randomizeBoolean = false; boolean displayAnswersBoolean = false; @@ -1052,11 +421,11 @@ if ((sln != null) && (sln.equalsIgnoreCase("1"))) { slnBoolean = true; } - + if ((useSelectLeaderToolOuput != null) && (useSelectLeaderToolOuput.equalsIgnoreCase("1"))) { useSelectLeaderToolOuputBoolean = true; } - + if ((prefixAnswersWithLetters != null) && (prefixAnswersWithLetters.equalsIgnoreCase("1"))) { prefixAnswersWithLettersBoolean = true; } @@ -1109,123 +478,115 @@ passmark = "0"; } - AuthoringUtil.logger.debug("activeModule:" + activeModule); - if (activeModule.equals(McAppConstants.AUTHORING)) { - // setting other content values - mcContent.setQuestionsSequenced(questionsSequencedBoolean); - mcContent.setRandomize(randomizeBoolean); - mcContent.setDisplayAnswers(displayAnswersBoolean); - mcContent.setShowMarks(showMarksBoolean); - mcContent.setRetries(retriesBoolean); - mcContent.setShowReport(slnBoolean); - mcContent.setUseSelectLeaderToolOuput(useSelectLeaderToolOuputBoolean); - mcContent.setPrefixAnswersWithLetters(prefixAnswersWithLettersBoolean); - - mcContent.setReflect(reflectBoolean); - mcContent.setReflectionSubject(reflectionSubject); + mcContent.setQuestionsSequenced(questionsSequencedBoolean); + mcContent.setRandomize(randomizeBoolean); + mcContent.setDisplayAnswers(displayAnswersBoolean); + mcContent.setShowMarks(showMarksBoolean); + mcContent.setRetries(retriesBoolean); + mcContent.setShowReport(slnBoolean); + mcContent.setUseSelectLeaderToolOuput(useSelectLeaderToolOuputBoolean); + mcContent.setPrefixAnswersWithLetters(prefixAnswersWithLettersBoolean); - mcContent.setPassMark(new Integer(passmark)); - } + mcContent.setReflect(reflectBoolean); + mcContent.setReflectionSubject(reflectionSubject); + mcContent.setPassMark(new Integer(passmark)); + if (newContent) { mcService.createMc(mcContent); } else { mcService.updateMc(mcContent); } - mcContent = mcService.retrieveMc(new Long(strToolContentID)); + mcContent = mcService.getMcContent(new Long(strToolContentID)); - mcContent = createQuestionContent(mapQuestionContent, mapFeedback, mapWeights, mapMarks, mapCandidatesList, - mcService, mcContent); - return mcContent; } /** - * - * McContent createQuestionContent(Map mapQuestionContent, Map mapFeedback, Map mapWeights, Map mapMarks, Map - * mapCandidatesList, IMcService mcService, McContent mcContent) - * - * persists the questions in the Map the user has submitted - * - * @param mapQuestionContent - * @param mapFeedback - * @param mapWeights - * @param mapMarks - * @param mapCandidatesList - * @param mcService - * @param mcContent - * @return + * persists the questions */ - protected McContent createQuestionContent(Map mapQuestionContent, Map mapFeedback, Map mapWeights, Map mapMarks, - Map mapCandidatesList, IMcService mcService, McContent mcContent) { - List questions = mcService.retrieveMcQueContentsByToolContentId(mcContent.getUid().longValue()); + public static McContent createQuestions(List questionDTOs, IMcService mcService, McContent content) { - Iterator itMap = mapQuestionContent.entrySet().iterator(); int displayOrder = 0; - while (itMap.hasNext()) { - Map.Entry pairs = (Map.Entry) itMap.next(); + for (McQuestionDTO questionDTO : questionDTOs) { + String currentQuestionText = questionDTO.getQuestion(); - if (pairs.getValue().toString().length() != 0) { + // skip empty questions + if (currentQuestionText.isEmpty()) { + continue; + } - ++displayOrder; - String currentFeedback = (String) mapFeedback.get(new Integer(displayOrder).toString()); + ++displayOrder; + String currentFeedback = questionDTO.getFeedback(); + String currentMark = questionDTO.getMark(); + /* set the default mark in case it is not provided */ + if (currentMark == null) { + currentMark = "1"; + } - String currentMark = (String) mapMarks.get(new Integer(displayOrder).toString()); - /* set the default mark in case it is not provided */ - if (currentMark == null) { - currentMark = "1"; - } + McQueContent question = mcService.getQuestionByUid(questionDTO.getUid()); - List caList = (List) mapCandidatesList.get(new Integer(displayOrder).toString()); + // in case question doesn't exist + if (question == null) { + question = new McQueContent(currentQuestionText, new Integer(displayOrder), new Integer(currentMark), + currentFeedback, content, null, null); - McQueContent queContent = new McQueContent(pairs.getValue().toString(), new Integer(displayOrder), - new Integer(currentMark), currentFeedback, mcContent, null, null); + // adding a new question to content + content.getMcQueContents().add(question); + question.setMcContent(content); - /* checks if the question is already recorded */ - McQueContent existingMcQueContent = mcService.getQuestionByDisplayOrder(new Long(displayOrder), - mcContent.getUid()); + // in case question exists already + } else { - if (existingMcQueContent == null) { - /* make sure a question with the same question text is not already saved */ - McQueContent duplicateMcQueContent = mcService.getQuestionContentByQuestionText(pairs.getValue() - .toString(), mcContent.getUid()); - // adding a new question to content - mcContent.getMcQueContents().add(queContent); - queContent.setMcContent(mcContent); + question.setQuestion(currentQuestionText); + question.setFeedback(currentFeedback); + question.setDisplayOrder(new Integer(displayOrder)); + question.setMark(new Integer(currentMark)); + } - mcService.createMcQue(queContent); + // persist candidate answers + List optionDTOs = questionDTO.getListCandidateAnswersDTO(); + Set oldOptions = question.getMcOptionsContents(); + Set newOptions = new HashSet(); + int displayOrderOption = 1; + for (McOptionDTO optionDTO : optionDTOs) { - // start persisting candidate answers - persistCandidates(caList, queContent, mcService); - } else { + Long optionUid = optionDTO.getUid(); + String optionText = optionDTO.getCandidateAnswer(); + boolean isCorrectOption = "Correct".equals(optionDTO.getCorrect()); + + //find persisted option if it exists + McOptsContent option = new McOptsContent(); + for (McOptsContent oldOption: oldOptions) { + if (oldOption.getUid().equals(optionUid)) { + option = oldOption; + } + } + + option.setDisplayOrder(displayOrderOption); + option.setCorrectOption(isCorrectOption); + option.setMcQueOptionText(optionText); + option.setMcQueContent(question); - String existingQuestion = existingMcQueContent.getQuestion(); + newOptions.add(option); + displayOrderOption++; + } + + question.setMcOptionsContents(newOptions); - existingMcQueContent.setQuestion(pairs.getValue().toString()); - existingMcQueContent.setFeedback(currentFeedback); - existingMcQueContent.setDisplayOrder(new Integer(displayOrder)); - existingMcQueContent.setMark(new Integer(currentMark)); + // updating the existing question content + mcService.updateQuestion(question); - // updating the existing question content - mcService.updateMcQueContent(existingMcQueContent); - - // will be removing redundant candidates - mcService.removeMcOptionsContentByQueId(existingMcQueContent.getUid()); - // start persisting candidates - - persistCandidates(caList, existingMcQueContent, mcService); - } - } } - return mcContent; + return content; } - protected Map buildDynamicPassMarkMap(List listQuestionContentDTO, boolean initialScreen) { + public static Map buildDynamicPassMarkMap(List questionDTOs, boolean initialScreen) { Map map = new TreeMap(new McComparator()); - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTO); + String totalMark = AuthoringUtil.getTotalMark(questionDTOs); int intTotalMark = 0; if ((totalMark != null) && (totalMark.length() > 0)) { @@ -1236,7 +597,7 @@ return passMarksMap; } - protected Map buildPassMarkMap(int intTotalMark, boolean initialScreen) { + public static Map buildPassMarkMap(int intTotalMark, boolean initialScreen) { Map map = new TreeMap(new McComparator()); @@ -1255,7 +616,7 @@ * * @return */ - protected Map buildMarksMap() { + public static Map buildMarksMap() { Map map = new TreeMap(new McComparator()); for (int i = 1; i <= 10; i++) { @@ -1269,20 +630,16 @@ * * @return */ - protected Map buildCorrectMap() { + public static Map buildCorrectMap() { Map map = new TreeMap(new McComparator()); map.put(new Integer(2).toString(), "Correct"); return map; } /** - * List repopulateCandidateAnswersBox(HttpServletRequest request, boolean addBlankCa) - * - * @param request - * @param addBlankCa - * @return + * repopulateOptionsBox */ - protected List repopulateCandidateAnswersBox(HttpServletRequest request, boolean addBlankCa) { + public static List repopulateOptionDTOs(HttpServletRequest request, boolean isAddBlankOptions) { String correct = request.getParameter("correct"); @@ -1292,175 +649,75 @@ intCorrect = new Integer(correct).intValue(); } - List listFinalCandidatesDTO = new LinkedList(); + List optionDtos = new LinkedList(); for (int i = 0; i < McAppConstants.MAX_OPTION_COUNT; i++) { - String candidate = request.getParameter("ca" + i); + String optionText = request.getParameter("ca" + i); + Long optionUid = WebUtil.readLongParam(request, "caUid" + i, true); String isCorrect = "Incorrect"; if (i == intCorrect) { isCorrect = "Correct"; } - if (candidate != null) { - McCandidateAnswersDTO mcCandidateAnswersDTO = new McCandidateAnswersDTO(); - mcCandidateAnswersDTO.setCandidateAnswer(candidate); - mcCandidateAnswersDTO.setCorrect(isCorrect); - listFinalCandidatesDTO.add(mcCandidateAnswersDTO); + if (optionText != null) { + McOptionDTO optionDTO = new McOptionDTO(); + optionDTO.setUid(optionUid); + optionDTO.setCandidateAnswer(optionText); + optionDTO.setCorrect(isCorrect); + optionDtos.add(optionDTO); } } - if (addBlankCa == true) { - McCandidateAnswersDTO mcCandidateAnswersDTO = new McCandidateAnswersDTO(); - mcCandidateAnswersDTO.setCandidateAnswer(""); - mcCandidateAnswersDTO.setCorrect("Incorrect"); - listFinalCandidatesDTO.add(mcCandidateAnswersDTO); + if (isAddBlankOptions) { + McOptionDTO optionDTO = new McOptionDTO(); + optionDTO.setCandidateAnswer(""); + optionDTO.setCorrect("Incorrect"); + optionDtos.add(optionDTO); } - return listFinalCandidatesDTO; + return optionDtos; } - protected boolean validateCandidateAnswersNotBlank(HttpServletRequest request) { - - for (int i = 0; i < McAppConstants.MAX_OPTION_COUNT; i++) { - String candidate = request.getParameter("ca" + i); - - if ((candidate != null) && (candidate.length() == 0)) { - // there is at least 1 blank candidate - return false; - } - } - return true; - } - /** - * boolean validateSingleCorrectCandidate(List caList) - * - * verifies that there is at least one Correct entry selected - * - * @param caList - * @return - */ - protected boolean validateSingleCorrectCandidate(List caList) { - Iterator itCaList = caList.iterator(); - while (itCaList.hasNext()) { - McCandidateAnswersDTO mcCandidateAnswersDTO = (McCandidateAnswersDTO) itCaList.next(); - - String candidateAnswer = mcCandidateAnswersDTO.getCandidateAnswer(); - String correct = mcCandidateAnswersDTO.getCorrect(); - - if (correct.equals("Correct")) { - // there is at least one Correct candidate, it is good. - return true; - } - } - - return false; - } - - /** - * buildDefaultQuestionContent(McContent mcContent, IMcService mcService) - * * generates a list for holding default questions and their candidate answers - * - * @param mcContent - * @param mcService - * @return */ - protected List buildDefaultQuestionContent(McContent mcContent, IMcService mcService) { - List listQuestionContentDTO = new LinkedList(); + public static List buildDefaultQuestions(McContent mcContent, IMcService mcService) { + List questionDTOs = new LinkedList(); - /* - * get the existing question content - */ - Iterator queIterator = mcContent.getMcQueContents().iterator(); Long mapIndex = new Long(1); - while (queIterator.hasNext()) { - McQuestionContentDTO mcQuestionContentDTO = new McQuestionContentDTO(); + for (McQueContent question : (Set) mcContent.getMcQueContents()) { + McQuestionDTO questionDto = new McQuestionDTO(); - McQueContent mcQueContent = (McQueContent) queIterator.next(); - if (mcQueContent != null) { - - String feedback = ""; - if (mcQueContent.getFeedback() != null) { - feedback = mcQueContent.getFeedback(); - } - - String question = mcQueContent.getQuestion(); - - mcQuestionContentDTO.setQuestion(question); - mcQuestionContentDTO.setDisplayOrder(mcQueContent.getDisplayOrder().toString()); - mcQuestionContentDTO.setFeedback(feedback); - mcQuestionContentDTO.setMark(mcQueContent.getMark().toString()); - - /* get candidates, from here.. */ - List list = mcService.findMcOptionsContentByQueId(mcQueContent.getUid()); - - int caCount = list.size(); - mcQuestionContentDTO.setCaCount(new Integer(caCount).toString()); - - List listCandidates = new LinkedList(); - Iterator listIterator = list.iterator(); - while (listIterator.hasNext()) { - McOptsContent mcOptsContent = (McOptsContent) listIterator.next(); - McCandidateAnswersDTO mcCandidateAnswersDTO = new McCandidateAnswersDTO(); - - mcCandidateAnswersDTO.setCandidateAnswer(mcOptsContent.getMcQueOptionText()); - - if (mcOptsContent.isCorrectOption()) { - mcCandidateAnswersDTO.setCorrect("Correct"); - } else { - mcCandidateAnswersDTO.setCorrect("Incorrect"); - } - listCandidates.add(mcCandidateAnswersDTO); - } - /* get candidates, till here.. */ - - mcQuestionContentDTO.setListCandidateAnswersDTO(listCandidates); - - listQuestionContentDTO.add(mcQuestionContentDTO); - - mapIndex = new Long(mapIndex.longValue() + 1); + String feedback = ""; + if (question.getFeedback() != null) { + feedback = question.getFeedback(); } - } - return listQuestionContentDTO; - } + String questionText = question.getQuestion(); - /** - * persistCandidates(List caList, McQueContent mcQueContent, IMcService mcService) - * - * @param caList - * @param mcQueContent - * @param mcService - */ - protected void persistCandidates(List caList, McQueContent mcQueContent, IMcService mcService) { + questionDto.setUid(question.getUid()); + questionDto.setQuestion(questionText); + questionDto.setDisplayOrder(question.getDisplayOrder().toString()); + questionDto.setFeedback(feedback); + questionDto.setMark(question.getMark().toString()); - int displayOrder = 0; - Iterator itCaList = caList.iterator(); - while (itCaList.hasNext()) { - McCandidateAnswersDTO mcCandidateAnswersDTO = (McCandidateAnswersDTO) itCaList.next(); - - String candidateAnswer = mcCandidateAnswersDTO.getCandidateAnswer(); - String correct = mcCandidateAnswersDTO.getCorrect(); - - boolean correctOption = false; - if (correct.equals("Correct")) { - correctOption = true; - } else { - correctOption = false; + // build candidate dtos + List optionDtos = new LinkedList(); + for (McOptsContent option : (Set) question.getMcOptionsContents()) { + McOptionDTO optionDTO = new McOptionDTO(option); + optionDtos.add(optionDTO); } - ++displayOrder; + questionDto.setListCandidateAnswersDTO(optionDtos); - // McOptsContent mcOptsContent = new McOptsContent(correctOption, candidateAnswer, mcQueContent, new - // TreeSet()); - McOptsContent mcOptsContent = new McOptsContent(new Integer(displayOrder), correctOption, candidateAnswer, - mcQueContent); + questionDTOs.add(questionDto); - mcService.saveMcOptionsContent(mcOptsContent); + mapIndex = new Long(mapIndex.longValue() + 1); } + + return questionDTOs; } } Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/ClearSessionAction.java =================================================================== diff -u -rbe07c35c372d904a65581d98660e73f3b13b69db -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/ClearSessionAction.java (.../ClearSessionAction.java) (revision be07c35c372d904a65581d98660e73f3b13b69db) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/ClearSessionAction.java (.../ClearSessionAction.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -37,7 +37,6 @@ * * @struts:action path="/clearsession" validate="false" * - * @version $Revision$ */ public class ClearSessionAction extends LamsAuthoringFinishAction { @@ -64,24 +63,20 @@ session.removeAttribute(McAction.CREATION_DATE); session.removeAttribute(McAction.QUESTIONS_WITHNO_OPTIONS); session.removeAttribute(McAction.RICHTEXT_CORRECT_FEEDBACK); - // session.removeAttribute(McAction.RICHTEXT_END_LEARNING_MSG); session.removeAttribute(McAction.RICHTEXT_INSTRUCTIONS); session.removeAttribute(McAction.MAP_STARTUP_GENERAL_OPTIONS_CONTENT); session.removeAttribute(McAction.MAP_STARTUP_GENERAL_OPTIONS_QUEID); session.removeAttribute(McAction.MAP_STARTUP_GENERAL_SELECTED_OPTIONS_CONTENT); session.removeAttribute(McAction.SHOW_AUTHORING_TABS); session.removeAttribute(McAction.MAP_SELECTED_OPTIONS); session.removeAttribute(McAction.SELECTED_QUESTION); - session.removeAttribute(McAction.DEFINE_LATER_IN_EDIT_MODE); session.removeAttribute(McAction.RICHTEXT_TITLE); session.removeAttribute(McAction.RICHTEXT_REPORT_TITLE); session.removeAttribute(McAction.DEFAULT_CONTENT_ID); - session.removeAttribute(McAction.DEFINE_LATER); session.removeAttribute(McAction.MAP_DISABLED_QUESTIONS); session.removeAttribute(McAction.MAP_QUESTIONS_CONTENT); session.removeAttribute(McAction.IS_REVISITING_USER); session.removeAttribute(McAction.MAP_CHECKBOX_STATES); - session.removeAttribute(McAction.ACTIVE_MODULE); session.removeAttribute("queIndex"); session.removeAttribute(McAction.MAP_OPTIONS_CONTENT); session.removeAttribute(McAction.MAP_STARTUP_GENERAL_SELECTED_OPTIONS_CONTENT); Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/ExportServlet.java =================================================================== diff -u -rbe07c35c372d904a65581d98660e73f3b13b69db -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/ExportServlet.java (.../ExportServlet.java) (revision be07c35c372d904a65581d98660e73f3b13b69db) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/ExportServlet.java (.../ExportServlet.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -28,7 +28,12 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.util.Iterator; +import java.util.LinkedList; import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; @@ -40,14 +45,18 @@ import org.lamsfoundation.lams.tool.mc.McAppConstants; import org.lamsfoundation.lams.tool.mc.McApplicationException; import org.lamsfoundation.lams.tool.mc.McMonitoredAnswersDTO; +import org.lamsfoundation.lams.tool.mc.McMonitoredUserDTO; +import org.lamsfoundation.lams.tool.mc.McOptionDTO; import org.lamsfoundation.lams.tool.mc.McSessionMarkDTO; +import org.lamsfoundation.lams.tool.mc.McStringComparator; import org.lamsfoundation.lams.tool.mc.ReflectionDTO; import org.lamsfoundation.lams.tool.mc.pojos.McContent; +import org.lamsfoundation.lams.tool.mc.pojos.McQueContent; import org.lamsfoundation.lams.tool.mc.pojos.McQueUsr; import org.lamsfoundation.lams.tool.mc.pojos.McSession; +import org.lamsfoundation.lams.tool.mc.pojos.McUsrAttempt; import org.lamsfoundation.lams.tool.mc.service.IMcService; import org.lamsfoundation.lams.tool.mc.service.McServiceProxy; -import org.lamsfoundation.lams.util.MessageService; import org.lamsfoundation.lams.util.WebUtil; import org.lamsfoundation.lams.web.servlet.AbstractExportPortfolioServlet; @@ -66,8 +75,7 @@ public String doExport(HttpServletRequest request, HttpServletResponse response, String directoryName, Cookie[] cookies) { - String basePath = WebUtil.getBaseServerURL() - + request.getContextPath(); + String basePath = WebUtil.getBaseServerURL() + request.getContextPath(); if (StringUtils.equals(mode, ToolAccessMode.LEARNER.toString())) { learner(request, response, directoryName, cookies); @@ -118,14 +126,14 @@ request.getSession().setAttribute(PORTFOLIO_EXPORT_MODE, "learner"); if (learner != null) { - List listMonitoredAnswersContainerDTO = MonitoringUtil.buildGroupsQuestionDataForExportLearner(content, - mcService, mcSession, learner); + List listMonitoredAnswersContainerDTO = buildGroupsQuestionDataForExportLearner(content, mcService, + mcSession, learner); request.getSession().setAttribute(LIST_MONITORED_ANSWERS_CONTAINER_DTO, listMonitoredAnswersContainerDTO); request.getSession().setAttribute(LEARNER_MARK, learner.getLastAttemptTotalMark()); request.getSession().setAttribute(LEARNER_NAME, learner.getFullname()); request.getSession().setAttribute(PASSMARK, content.getPassMark().toString()); - + List reflectionsContainerDTO = mcService.getReflectionList(content, userID); request.getSession().setAttribute(REFLECTIONS_CONTAINER_DTO, reflectionsContainerDTO); } @@ -152,15 +160,15 @@ throw new McApplicationException(error); } - McContent content = mcService.retrieveMc(toolContentID); + McContent content = mcService.getMcContent(toolContentID); if (content == null) { String error = "Data is missing from the database. Unable to Continue"; logger.error(error); throw new McApplicationException(error); } - List listMonitoredAnswersContainerDTO = MonitoringUtil.buildGroupsQuestionData(content, mcService); + List listMonitoredAnswersContainerDTO = buildGroupsQuestionData(content, mcService); request.getSession().setAttribute(LIST_MONITORED_ANSWERS_CONTAINER_DTO, listMonitoredAnswersContainerDTO); List listMonitoredMarksContainerDTO = mcService.buildGroupsMarkData(content, true); @@ -209,4 +217,139 @@ } } + + /** + * + * ends up populating the attempt history for all the users of all the tool sessions for a content + * + * @param request + * @param mcContent + * @return List + */ + private static List buildGroupsQuestionData(McContent mcContent, IMcService mcService) { + // will be building groups question data for content + + List questions = mcService.getQuestionsByContentUid(mcContent.getUid()); + + List monitoredAnswersDTOs = new LinkedList(); + + for (McQueContent question : questions) { + + if (question != null) { + McMonitoredAnswersDTO monitoredAnswersDTO = new McMonitoredAnswersDTO(); + monitoredAnswersDTO.setQuestionUid(question.getUid().toString()); + monitoredAnswersDTO.setQuestion(question.getQuestion()); + monitoredAnswersDTO.setMark(question.getMark().toString()); + + List listCandidateAnswersDTO = mcService.getOptionDtos(question.getUid()); + monitoredAnswersDTO.setCandidateAnswersCorrect(listCandidateAnswersDTO); + + Map> questionAttemptData = new TreeMap>( + new McStringComparator()); + + for (McSession session : (Set) mcContent.getMcSessions()) { + Set users = session.getMcQueUsers(); + List monitoredUserDTOs = new LinkedList(); + for (McQueUsr user : users) { + McMonitoredUserDTO monitoredUserDTO = getUserAttempt(mcService, user, session, + question.getUid()); + monitoredUserDTOs.add(monitoredUserDTO); + } + + questionAttemptData.put(session.getSession_name(), monitoredUserDTOs); + } + + monitoredAnswersDTO.setQuestionAttempts(questionAttemptData); + monitoredAnswersDTOs.add(monitoredAnswersDTO); + + } + } + return monitoredAnswersDTOs; + } + + /** + * + * @param request + * @param mcContent + * @param mcService + * @param mcSession + * @param mcQueUsr + * @return + */ + private static List buildGroupsQuestionDataForExportLearner(McContent mcContent, IMcService mcService, + McSession mcSession, McQueUsr mcQueUsr) { + + List questions = mcService.getQuestionsByContentUid(mcContent.getUid()); + + List listMonitoredAnswersContainerDTO = new LinkedList(); + + Iterator itListQuestions = questions.iterator(); + while (itListQuestions.hasNext()) { + McQueContent question = itListQuestions.next(); + + if (question != null) { + McMonitoredAnswersDTO monitoredAnswersDTO = new McMonitoredAnswersDTO(); + monitoredAnswersDTO.setQuestionUid(question.getUid().toString()); + monitoredAnswersDTO.setQuestion(question.getQuestion()); + monitoredAnswersDTO.setMark(question.getMark().toString()); + + List listCandidateAnswersDTO = mcService.getOptionDtos(question.getUid()); + monitoredAnswersDTO.setCandidateAnswersCorrect(listCandidateAnswersDTO); + + // Get the attempts for this user. The maps must match the maps in buildGroupsAttemptData or the jsp + // won't work. + McMonitoredUserDTO mcMonitoredUserDTO = getUserAttempt(mcService, mcQueUsr, mcSession, + question.getUid()); + List listMonitoredUserContainerDTO = new LinkedList(); + listMonitoredUserContainerDTO.add(mcMonitoredUserDTO); + Map questionAttemptData = new TreeMap(new McStringComparator()); + questionAttemptData.put(mcSession.getSession_name(), listMonitoredUserContainerDTO); + + monitoredAnswersDTO.setQuestionAttempts(questionAttemptData); + listMonitoredAnswersContainerDTO.add(monitoredAnswersDTO); + } + } + return listMonitoredAnswersContainerDTO; + } + + /** + * + */ + private static McMonitoredUserDTO getUserAttempt(IMcService mcService, McQueUsr mcQueUsr, McSession mcSession, + Long questionUid) { + + McMonitoredUserDTO mcMonitoredUserDTO = new McMonitoredUserDTO(); + if (mcQueUsr != null) { + mcMonitoredUserDTO.setUserName(mcQueUsr.getFullname()); + mcMonitoredUserDTO.setSessionId(mcSession.getMcSessionId().toString()); + mcMonitoredUserDTO.setQuestionUid(questionUid.toString()); + mcMonitoredUserDTO.setQueUsrId(mcQueUsr.getUid().toString()); + + McUsrAttempt userAttempt = mcService.getUserAttemptByQuestion(mcQueUsr.getUid(), questionUid); + + if (!mcQueUsr.isResponseFinalised() || (userAttempt == null)) { + + mcMonitoredUserDTO.setMark(new Integer(0)); + + } else { + + // At present, we expect there to be only one answer to a question but there + // could be more in the future - if that happens then we need to change + // String to a list of Strings. + + // We get the mark for the attempt if the answer is correct and we don't allow + // retries, or if the answer is correct and the learner has met the passmark if + // we do allow retries. + + String userAnswer = userAttempt.getMcOptionsContent().getMcQueOptionText(); + boolean isRetries = mcSession.getMcContent().isRetries(); + mcMonitoredUserDTO.setMark(userAttempt.getMarkForShow(isRetries)); + mcMonitoredUserDTO.setIsCorrect(new Boolean(userAttempt.isAttemptCorrect()).toString()); + mcMonitoredUserDTO.setUserAnswer(userAnswer); + } + + } + + return mcMonitoredUserDTO; + } } Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McAction.java =================================================================== diff -u -rf26fb3937b73bfdefd25a6166863ea188d5f8cb9 -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McAction.java (.../McAction.java) (revision f26fb3937b73bfdefd25a6166863ea188d5f8cb9) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McAction.java (.../McAction.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -24,14 +24,15 @@ /* $$Id$$ */ package org.lamsfoundation.lams.tool.mc.web; -import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.TreeMap; +import java.util.TreeSet; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -45,82 +46,44 @@ import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionMessage; import org.apache.struts.action.ActionMessages; -import org.apache.struts.upload.FormFile; import org.lamsfoundation.lams.authoring.web.AuthoringConstants; -import org.lamsfoundation.lams.contentrepository.NodeKey; -import org.lamsfoundation.lams.contentrepository.RepositoryCheckedException; -import org.lamsfoundation.lams.contentrepository.client.IToolContentHandler; import org.lamsfoundation.lams.questions.Answer; import org.lamsfoundation.lams.questions.Question; import org.lamsfoundation.lams.questions.QuestionExporter; import org.lamsfoundation.lams.questions.QuestionParser; -import org.lamsfoundation.lams.tool.exception.ToolException; -import org.lamsfoundation.lams.tool.mc.EditActivityDTO; +import org.lamsfoundation.lams.tool.ToolAccessMode; import org.lamsfoundation.lams.tool.mc.McAppConstants; -import org.lamsfoundation.lams.tool.mc.McCandidateAnswersDTO; import org.lamsfoundation.lams.tool.mc.McComparator; +import org.lamsfoundation.lams.tool.mc.McOptionDTO; import org.lamsfoundation.lams.tool.mc.McGeneralAuthoringDTO; -import org.lamsfoundation.lams.tool.mc.McQuestionContentDTO; +import org.lamsfoundation.lams.tool.mc.McQuestionDTO; import org.lamsfoundation.lams.tool.mc.McUtils; import org.lamsfoundation.lams.tool.mc.pojos.McContent; +import org.lamsfoundation.lams.tool.mc.pojos.McOptsContent; +import org.lamsfoundation.lams.tool.mc.pojos.McQueContent; +import org.lamsfoundation.lams.tool.mc.pojos.McUsrAttempt; import org.lamsfoundation.lams.tool.mc.service.IMcService; import org.lamsfoundation.lams.tool.mc.service.McServiceProxy; -import org.lamsfoundation.lams.tool.mc.util.McToolContentHandler; -import org.lamsfoundation.lams.util.FileValidatorUtil; import org.lamsfoundation.lams.util.WebUtil; import org.lamsfoundation.lams.web.action.LamsDispatchAction; import org.lamsfoundation.lams.web.util.AttributeNames; import org.lamsfoundation.lams.web.util.SessionMap; -import org.springframework.web.context.WebApplicationContext; -import org.springframework.web.context.support.WebApplicationContextUtils; /** - *

* Action class that controls the logic of tool behavior. - *

* * @author Ozgur Demirtas - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * */ public class McAction extends LamsDispatchAction implements McAppConstants { - static Logger logger = Logger.getLogger(McAction.class.getName()); + private static Logger logger = Logger.getLogger(McAction.class.getName()); - private McToolContentHandler toolContentHandler; - public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { - return (mapping.findForward(McAppConstants.LOAD_QUESTIONS)); + return (mapping.findForward(McAppConstants.LOAD_AUTHORING)); } /** - * * submits content into the tool database - * - * @param mapping - * @param form - * @param request - * @param response - * @return - * @throws IOException - * @throws ServletException */ public ActionForward submitAllContent(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { @@ -131,39 +94,23 @@ String httpSessionID = mcAuthoringForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); mcAuthoringForm.setContentFolderID(contentFolderID); - String activeModule = request.getParameter(McAppConstants.ACTIVE_MODULE); - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(McAppConstants.MY_SIGNATURE)) - .toString(); + List questionDTOs = (List) sessionMap.get(McAppConstants.LIST_QUESTION_DTOS); - List listQuestionContentDTO = (List) sessionMap.get(McAppConstants.LIST_QUESTION_CONTENT_DTO_KEY); - - Map mapQuestionContent = AuthoringUtil.extractMapQuestionContent(listQuestionContentDTO); - - Map mapFeedback = AuthoringUtil.extractMapFeedback(listQuestionContentDTO); - - Map mapWeights = new TreeMap(new McComparator()); - - Map mapMarks = AuthoringUtil.extractMapMarks(listQuestionContentDTO); - - Map mapCandidatesList = AuthoringUtil.extractMapCandidatesList(listQuestionContentDTO); - ActionMessages errors = new ActionMessages(); - - if (mapQuestionContent.size() == 0) { + if (questionDTOs.isEmpty()) { ActionMessage error = new ActionMessage("questions.none.submitted"); errors.add(ActionMessages.GLOBAL_MESSAGE, error); + saveErrors(request, errors); + McAction.logger.debug("errors saved: " + errors); } - AuthoringUtil authoringUtil = new AuthoringUtil(); - McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); @@ -179,109 +126,112 @@ sessionMap.put(McAppConstants.ACTIVITY_TITLE_KEY, richTextTitle); sessionMap.put(McAppConstants.ACTIVITY_INSTRUCTIONS_KEY, richTextInstructions); - mcGeneralAuthoringDTO.setMapQuestionContent(mapQuestionContent); - request.setAttribute(McAppConstants.MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); // there are no issues with input, continue and submit data - McContent mcContentTest = mcService.retrieveMc(new Long(strToolContentID)); + McContent mcContentTest = mcService.getMcContent(new Long(strToolContentID)); - if (!errors.isEmpty()) { - saveErrors(request, errors); - McAction.logger.debug("errors saved: " + errors); - } - McContent mcContent = mcContentTest; if (errors.isEmpty()) { - authoringUtil.removeRedundantQuestions(mapQuestionContent, mcService, mcAuthoringForm, request, - strToolContentID); - // end of removing unused entries - mcContent = authoringUtil.saveOrUpdateMcContent(mapQuestionContent, mapFeedback, mapWeights, mapMarks, - mapCandidatesList, mcService, mcAuthoringForm, request, mcContentTest, strToolContentID); + ToolAccessMode mode = getAccessMode(request); + request.setAttribute(AttributeNames.ATTR_MODE, mode.toString()); - long defaultContentID = 0; - // attempt retrieving tool with signatute McAppConstants.MY_SIGNATURE - defaultContentID = mcService.getToolDefaultContentIdBySignature(McAppConstants.MY_SIGNATURE); + List deletedQuestionDTOs = (List) sessionMap.get(LIST_DELETED_QUESTION_DTOS); - if (mcContent != null) { - mcGeneralAuthoringDTO.setDefaultContentIdStr(new Long(defaultContentID).toString()); + // in case request is from monitoring module - prepare for recalculate User Answers + if (mode.isTeacher()) { + Set oldQuestions = mcContent.getMcQueContents(); + mcService.releaseQuestionsFromCache(mcContent); + McUtils.setDefineLater(request, false, strToolContentID, mcService); + + // recalculate User Answers + mcService.recalculateUserAnswers(mcContent, oldQuestions, questionDTOs, deletedQuestionDTOs); } + + // remove deleted questions + for (McQuestionDTO deletedQuestionDTO : deletedQuestionDTOs) { + McQueContent removeableQuestion = mcService.getQuestionByUid(deletedQuestionDTO.getUid()); + if (removeableQuestion != null) { +// Set attempts = removeableQuestion.getMcUsrAttempts(); +// Iterator iter = attempts.iterator(); +// while (iter.hasNext()) { +// McUsrAttempt attempt = iter.next(); +// iter.remove(); +// } +// mcService.updateQuestion(removeableQuestion); + mcContent.getMcQueContents().remove(removeableQuestion); + mcService.removeMcQueContent(removeableQuestion); + } + } - authoringUtil.reOrganizeDisplayOrder(mapQuestionContent, mcService, mcAuthoringForm, mcContent); + //store content + mcContent = AuthoringUtil.saveOrUpdateMcContent(mcService, request, mcContentTest, strToolContentID); + + //store questions + mcContent = AuthoringUtil.createQuestions(questionDTOs, mcService, mcContent); - McUtils.setDefineLater(request, false, strToolContentID, mcService); - // define later set to false + if (mcContent != null) { - McUtils.setFormProperties(request, mcService, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); - - if (activeModule.equals(McAppConstants.AUTHORING)) { - // standard authoring close - request.setAttribute(AuthoringConstants.LAMS_AUTHORING_SUCCESS_FLAG, Boolean.TRUE); - mcGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - } else { - // go back to view only screen - mcGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(false).toString()); + // sorts the questions by the display order + List sortedQuestions = mcService.getAllQuestionEntriesSorted(mcContent.getUid() + .longValue()); + Iterator iterSort = sortedQuestions.iterator(); + int displayOrder = 1; + while (iterSort.hasNext()) { + McQueContent question = (McQueContent) iterSort.next(); + McQueContent existingQuestion = mcService.getQuestionByUid(question.getUid()); + existingQuestion.setDisplayOrder(new Integer(displayOrder)); + mcService.updateQuestion(existingQuestion); + displayOrder++; + } } + McUtils.setFormProperties(request, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, httpSessionID); + + request.setAttribute(AuthoringConstants.LAMS_AUTHORING_SUCCESS_FLAG, Boolean.TRUE); + } else { // errors is not empty if (mcContent != null) { - long defaultContentID = 0; - defaultContentID = mcService.getToolDefaultContentIdBySignature(McAppConstants.MY_SIGNATURE); - - if (mcContent != null) { - mcGeneralAuthoringDTO.setDefaultContentIdStr(new Long(defaultContentID).toString()); - } - - McUtils.setFormProperties(request, mcService, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); - + McUtils.setFormProperties(request, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, httpSessionID); } } - mcGeneralAuthoringDTO.setSbmtSuccess(new Integer(1).toString()); - mcAuthoringForm.resetUserAction(); - mcGeneralAuthoringDTO.setMapQuestionContent(mapQuestionContent); - Map marksMap = authoringUtil.buildMarksMap(); + Map marksMap = AuthoringUtil.buildMarksMap(); mcGeneralAuthoringDTO.setMarksMap(marksMap); - Map correctMap = authoringUtil.buildCorrectMap(); + Map correctMap = AuthoringUtil.buildCorrectMap(); mcGeneralAuthoringDTO.setCorrectMap(correctMap); - request.setAttribute(McAppConstants.LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - sessionMap.put(McAppConstants.LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); + request.setAttribute(McAppConstants.LIST_QUESTION_DTOS, questionDTOs); + sessionMap.put(McAppConstants.LIST_QUESTION_DTOS, questionDTOs); request.getSession().setAttribute(httpSessionID, sessionMap); - request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); + request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(questionDTOs.size())); - // generating dyn pass map using listQuestionContentDTO - Map passMarksMap = authoringUtil.buildDynamicPassMarkMap(listQuestionContentDTO, false); + // generating dyn pass map using questionDTOs + Map passMarksMap = AuthoringUtil.buildDynamicPassMarkMap(questionDTOs, false); mcGeneralAuthoringDTO.setPassMarksMap(passMarksMap); - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTO); + String totalMark = AuthoringUtil.getTotalMark(questionDTOs); mcAuthoringForm.setTotalMarks(totalMark); mcGeneralAuthoringDTO.setTotalMarks(totalMark); request.setAttribute(McAppConstants.MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); mcGeneralAuthoringDTO.setToolContentID(strToolContentID); mcGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - mcGeneralAuthoringDTO.setActiveModule(activeModule); - mcGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); mcAuthoringForm.setToolContentID(strToolContentID); mcAuthoringForm.setHttpSessionID(httpSessionID); - mcAuthoringForm.setActiveModule(activeModule); - mcAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); mcAuthoringForm.setCurrentTab("1"); - return mapping.findForward(McAppConstants.LOAD_QUESTIONS); + return mapping.findForward(McAppConstants.LOAD_AUTHORING); } public ActionForward saveSingleQuestion(ActionMapping mapping, ActionForm form, HttpServletRequest request, @@ -292,41 +242,31 @@ IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); String httpSessionID = mcAuthoringForm.getHttpSessionID(); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); mcAuthoringForm.setContentFolderID(contentFolderID); - String activeModule = request.getParameter(McAppConstants.ACTIVE_MODULE); - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(McAppConstants.MY_SIGNATURE)) - .toString(); - String editQuestionBoxRequest = request.getParameter("editQuestionBoxRequest"); String mark = request.getParameter("mark"); String passmark = request.getParameter("passmark"); - AuthoringUtil authoringUtil = new AuthoringUtil(); + List options = AuthoringUtil.repopulateOptionDTOs(request, false); + options = AuthoringUtil.removeBlankOptions(options); - List caList = authoringUtil.repopulateCandidateAnswersBox(request, false); + List questionDTOs = (List) sessionMap + .get(McAppConstants.LIST_QUESTION_DTOS); - caList = AuthoringUtil.removeBlankEntries(caList); - - List listQuestionContentDTO = (List) sessionMap.get(McAppConstants.LIST_QUESTION_CONTENT_DTO_KEY); - McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); mcGeneralAuthoringDTO.setMarkValue(mark); mcGeneralAuthoringDTO.setPassMarkValue(passmark); mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); - mcGeneralAuthoringDTO.setSbmtSuccess(new Integer(0).toString()); - String newQuestion = request.getParameter("newQuestion"); String feedback = request.getParameter("feedback"); @@ -337,15 +277,15 @@ if ((newQuestion != null) && (newQuestion.length() > 0)) { if ((editQuestionBoxRequest != null) && (editQuestionBoxRequest.equals("false"))) { // request for add and save - boolean duplicates = AuthoringUtil.checkDuplicateQuestions(listQuestionContentDTO, newQuestion); + boolean duplicates = AuthoringUtil.checkDuplicateQuestions(questionDTOs, newQuestion); if (!duplicates) { - McQuestionContentDTO mcQuestionContentDTO = null; - Iterator listIterator = listQuestionContentDTO.iterator(); - while (listIterator.hasNext()) { - mcQuestionContentDTO = (McQuestionContentDTO) listIterator.next(); + McQuestionDTO questionDTO = null; + Iterator iter = questionDTOs.iterator(); + while (iter.hasNext()) { + questionDTO = iter.next(); - String displayOrder = mcQuestionContentDTO.getDisplayOrder(); + String displayOrder = questionDTO.getDisplayOrder(); if ((displayOrder != null) && (!displayOrder.equals(""))) { if (displayOrder.equals(editableQuestionIndex)) { @@ -355,29 +295,26 @@ } } - mcQuestionContentDTO.setQuestion(newQuestion); - mcQuestionContentDTO.setFeedback(feedback); - mcQuestionContentDTO.setDisplayOrder(editableQuestionIndex); - mcQuestionContentDTO.setListCandidateAnswersDTO(caList); - mcQuestionContentDTO.setMark(mark); + questionDTO.setQuestion(newQuestion); + questionDTO.setFeedback(feedback); + questionDTO.setDisplayOrder(editableQuestionIndex); + questionDTO.setListCandidateAnswersDTO(options); + questionDTO.setMark(mark); - mcQuestionContentDTO.setCaCount(new Integer(mcQuestionContentDTO.getListCandidateAnswersDTO() - .size()).toString()); - - listQuestionContentDTO = AuthoringUtil.reorderUpdateListQuestionContentDTO(listQuestionContentDTO, - mcQuestionContentDTO, editableQuestionIndex); - // post reorderUpdateListQuestionContentDTO listQuestionContentDTO + questionDTOs = AuthoringUtil.reorderUpdateQuestionDtos(questionDTOs, + questionDTO, editableQuestionIndex); + // post reorderUpdateListQuestionContentDTO questionDTOs } else { // duplicate question entry, not adding } } else { // request for edit and save - McQuestionContentDTO mcQuestionContentDTO = null; - Iterator listIterator = listQuestionContentDTO.iterator(); - while (listIterator.hasNext()) { - mcQuestionContentDTO = (McQuestionContentDTO) listIterator.next(); + McQuestionDTO questionDTO = null; + Iterator iter = questionDTOs.iterator(); + while (iter.hasNext()) { + questionDTO = iter.next(); - String displayOrder = mcQuestionContentDTO.getDisplayOrder(); + String displayOrder = questionDTO.getDisplayOrder(); if ((displayOrder != null) && (!displayOrder.equals(""))) { if (displayOrder.equals(editableQuestionIndex)) { @@ -387,31 +324,28 @@ } } - mcQuestionContentDTO.setQuestion(newQuestion); - mcQuestionContentDTO.setFeedback(feedback); - mcQuestionContentDTO.setDisplayOrder(editableQuestionIndex); - mcQuestionContentDTO.setListCandidateAnswersDTO(caList); - mcQuestionContentDTO.setMark(mark); + questionDTO.setQuestion(newQuestion); + questionDTO.setFeedback(feedback); + questionDTO.setDisplayOrder(editableQuestionIndex); + questionDTO.setListCandidateAnswersDTO(options); + questionDTO.setMark(mark); - mcQuestionContentDTO.setCaCount(new Integer(mcQuestionContentDTO.getListCandidateAnswersDTO().size()) - .toString()); - - listQuestionContentDTO = AuthoringUtil.reorderUpdateListQuestionContentDTO(listQuestionContentDTO, - mcQuestionContentDTO, editableQuestionIndex); + questionDTOs = AuthoringUtil.reorderUpdateQuestionDtos(questionDTOs, + questionDTO, editableQuestionIndex); } } else { // entry blank, not adding } mcGeneralAuthoringDTO.setMarkValue(mark); - request.setAttribute(McAppConstants.LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - sessionMap.put(McAppConstants.LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); + request.setAttribute(McAppConstants.LIST_QUESTION_DTOS, questionDTOs); + sessionMap.put(McAppConstants.LIST_QUESTION_DTOS, questionDTOs); - commonSaveCode(request, mcGeneralAuthoringDTO, mcAuthoringForm, sessionMap, activeModule, strToolContentID, - defaultContentIdStr, mcService, httpSessionID, listQuestionContentDTO); + commonSaveCode(request, mcGeneralAuthoringDTO, mcAuthoringForm, sessionMap, strToolContentID, + mcService, httpSessionID, questionDTOs); - request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); + request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(questionDTOs.size())); return (mapping.findForward("itemList")); @@ -428,21 +362,16 @@ IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); String httpSessionID = request.getParameter("httpSessionID"); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); mcAuthoringForm.setContentFolderID(contentFolderID); - String activeModule = request.getParameter(McAppConstants.ACTIVE_MODULE); String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(McAppConstants.MY_SIGNATURE)) - .toString(); McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); - McContent mcContent = mcService.retrieveMc(new Long(strToolContentID)); mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); - mcGeneralAuthoringDTO.setSbmtSuccess(new Integer(0).toString()); - List listQuestionContentDTO = (List) sessionMap - .get(McAppConstants.LIST_QUESTION_CONTENT_DTO_KEY); + List questionDTOs = (List) sessionMap + .get(McAppConstants.LIST_QUESTION_DTOS); // proper parsing Question[] questions = QuestionParser.parseQuestionChoiceForm(request); @@ -457,18 +386,18 @@ questionText = QuestionParser.processHTMLField(questionText, false, contentFolderID, question.getResourcesFolderPath()); - if (AuthoringUtil.checkDuplicateQuestions(listQuestionContentDTO, questionText)) { + if (AuthoringUtil.checkDuplicateQuestions(questionDTOs, questionText)) { LamsDispatchAction.log.warn("Skipping duplicate question: " + questionText); continue; } - List caList = new ArrayList(); + List optionDtos = new ArrayList(); String correctAnswer = null; Integer correctAnswerScore = 1; if (question.getAnswers() != null) { for (Answer answer : question.getAnswers()) { - McCandidateAnswersDTO mcCandidateAnswersDTO = new McCandidateAnswersDTO(); + McOptionDTO optionDto = new McOptionDTO(); String answerText = QuestionParser.processHTMLField(answer.getText(), false, contentFolderID, question.getResourcesFolderPath()); if (answerText == null) { @@ -482,26 +411,26 @@ continue; } - mcCandidateAnswersDTO.setCandidateAnswer(answerText); + optionDto.setCandidateAnswer(answerText); if ((answer.getScore() != null) && (answer.getScore() > 0)) { if (correctAnswer == null) { - mcCandidateAnswersDTO.setCorrect("Correct"); - correctAnswer = mcCandidateAnswersDTO.getCandidateAnswer(); + optionDto.setCorrect("Correct"); + correctAnswer = optionDto.getCandidateAnswer(); // marks are integer numbers correctAnswerScore = Math.min(new Double(Math.ceil(answer.getScore())).intValue(), 10); } else { // there can be only one correct answer in a MCQ question LamsDispatchAction.log .warn("Choosing only first correct answer, despite another one was found: " + answerText); - mcCandidateAnswersDTO.setCorrect("Incorrect"); + optionDto.setCorrect("Incorrect"); } } else { - mcCandidateAnswersDTO.setCorrect("Incorrect"); + optionDto.setCorrect("Incorrect"); } - caList.add(mcCandidateAnswersDTO); + optionDtos.add(optionDto); } } @@ -510,29 +439,28 @@ continue; } - McQuestionContentDTO mcQuestionContentDTO = new McQuestionContentDTO(); - mcQuestionContentDTO.setDisplayOrder(String.valueOf(listQuestionContentDTO.size() + 1)); - mcQuestionContentDTO.setQuestion(questionText); - mcQuestionContentDTO.setFeedback(QuestionParser.processHTMLField(question.getFeedback(), true, null, null)); - mcQuestionContentDTO.setListCandidateAnswersDTO(caList); - mcQuestionContentDTO.setMark(correctAnswerScore.toString()); - mcQuestionContentDTO.setCaCount(String.valueOf(caList.size())); + McQuestionDTO questionDto = new McQuestionDTO(); + questionDto.setDisplayOrder(String.valueOf(questionDTOs.size() + 1)); + questionDto.setQuestion(questionText); + questionDto.setFeedback(QuestionParser.processHTMLField(question.getFeedback(), true, null, null)); + questionDto.setListCandidateAnswersDTO(optionDtos); + questionDto.setMark(correctAnswerScore.toString()); - listQuestionContentDTO.add(mcQuestionContentDTO); + questionDTOs.add(questionDto); if (LamsDispatchAction.log.isDebugEnabled()) { LamsDispatchAction.log.debug("Added question: " + questionText); } } - request.setAttribute(McAppConstants.LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - sessionMap.put(McAppConstants.LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); + request.setAttribute(McAppConstants.LIST_QUESTION_DTOS, questionDTOs); + sessionMap.put(McAppConstants.LIST_QUESTION_DTOS, questionDTOs); - commonSaveCode(request, mcGeneralAuthoringDTO, mcAuthoringForm, sessionMap, activeModule, strToolContentID, - defaultContentIdStr, mcService, httpSessionID, listQuestionContentDTO); + commonSaveCode(request, mcGeneralAuthoringDTO, mcAuthoringForm, sessionMap, strToolContentID, + mcService, httpSessionID, questionDTOs); - request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); - return mapping.findForward(McAppConstants.LOAD); + request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(questionDTOs.size())); + return mapping.findForward(McAppConstants.LOAD_AUTHORING); } /** @@ -542,13 +470,13 @@ public ActionForward exportQTI(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException { String httpSessionID = request.getParameter("httpSessionID"); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - List listQuestionContentDTO = (List) sessionMap - .get(McAppConstants.LIST_QUESTION_CONTENT_DTO_KEY); + List questionDTOs = (List) sessionMap + .get(McAppConstants.LIST_QUESTION_DTOS); List questions = new LinkedList(); - for (McQuestionContentDTO mcQuestion : listQuestionContentDTO) { + for (McQuestionDTO mcQuestion : questionDTOs) { Question question = new Question(); question.setType(Question.QUESTION_TYPE_MULTIPLE_CHOICE); @@ -557,7 +485,7 @@ question.setFeedback(mcQuestion.getFeedback()); List answers = new ArrayList(); - for (McCandidateAnswersDTO mcAnswer : (List) mcQuestion.getListCandidateAnswersDTO()) { + for (McOptionDTO mcAnswer : (List) mcQuestion.getListCandidateAnswersDTO()) { Answer answer = new Answer(); answer.setText(mcAnswer.getCandidateAnswer()); answer.setScore("Correct".equalsIgnoreCase(mcAnswer.getCorrect()) ? Float.parseFloat(mcQuestion @@ -578,9 +506,9 @@ return null; } - protected void commonSaveCode(HttpServletRequest request, McGeneralAuthoringDTO mcGeneralAuthoringDTO, - McAuthoringForm mcAuthoringForm, SessionMap sessionMap, String activeModule, String strToolContentID, - String defaultContentIdStr, IMcService mcService, String httpSessionID, List listQuestionContentDTO) { + private void commonSaveCode(HttpServletRequest request, McGeneralAuthoringDTO mcGeneralAuthoringDTO, + McAuthoringForm mcAuthoringForm, SessionMap sessionMap, String strToolContentID, + IMcService mcService, String httpSessionID, List questionDTOs) { String richTextTitle = request.getParameter(McAppConstants.TITLE); String richTextInstructions = request.getParameter(McAppConstants.INSTRUCTIONS); @@ -592,39 +520,29 @@ sessionMap.put(McAppConstants.ACTIVITY_TITLE_KEY, richTextTitle); sessionMap.put(McAppConstants.ACTIVITY_INSTRUCTIONS_KEY, richTextInstructions); - mcGeneralAuthoringDTO.setEditActivityEditMode(new Boolean(true).toString()); - request.getSession().setAttribute(httpSessionID, sessionMap); - sessionMap.put(McAppConstants.LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); + sessionMap.put(McAppConstants.LIST_QUESTION_DTOS, questionDTOs); - McUtils.setFormProperties(request, mcService, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); + McUtils.setFormProperties(request, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, httpSessionID); mcGeneralAuthoringDTO.setToolContentID(strToolContentID); mcGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - mcGeneralAuthoringDTO.setActiveModule(activeModule); - mcGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); mcAuthoringForm.setToolContentID(strToolContentID); mcAuthoringForm.setHttpSessionID(httpSessionID); - mcAuthoringForm.setActiveModule(activeModule); - mcAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); mcAuthoringForm.setCurrentTab("1"); - mcGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - AuthoringUtil authoringUtil = new AuthoringUtil(); - Map marksMap = authoringUtil.buildMarksMap(); + Map marksMap = AuthoringUtil.buildMarksMap(); mcGeneralAuthoringDTO.setMarksMap(marksMap); - Map passMarksMap = authoringUtil.buildDynamicPassMarkMap(listQuestionContentDTO, false); + Map passMarksMap = AuthoringUtil.buildDynamicPassMarkMap(questionDTOs, false); mcGeneralAuthoringDTO.setPassMarksMap(passMarksMap); - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTO); + String totalMark = AuthoringUtil.getTotalMark(questionDTOs); mcAuthoringForm.setTotalMarks(totalMark); mcGeneralAuthoringDTO.setTotalMarks(totalMark); - Map correctMap = authoringUtil.buildCorrectMap(); + Map correctMap = AuthoringUtil.buildCorrectMap(); mcGeneralAuthoringDTO.setCorrectMap(correctMap); request.setAttribute(McAppConstants.MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); @@ -640,35 +558,25 @@ String httpSessionID = mcAuthoringForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); mcAuthoringForm.setContentFolderID(contentFolderID); - String activeModule = request.getParameter(McAppConstants.ACTIVE_MODULE); - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(McAppConstants.MY_SIGNATURE)) - .toString(); - McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); - mcGeneralAuthoringDTO.setSbmtSuccess(new Integer(0).toString()); + List questionDTOs = (List) sessionMap.get(McAppConstants.LIST_QUESTION_DTOS); - AuthoringUtil authoringUtil = new AuthoringUtil(); + McQuestionDTO newQuestionDTO = (McQuestionDTO) sessionMap.get(McAppConstants.NEW_QUESTION_DTO); + request.setAttribute(McAppConstants.NEW_QUESTION_DTO, newQuestionDTO); - List listQuestionContentDTO = (List) sessionMap.get(McAppConstants.LIST_QUESTION_CONTENT_DTO_KEY); + int listSize = questionDTOs.size(); - List listAddableQuestionContentDTO = (List) sessionMap.get(McAppConstants.NEW_ADDABLE_QUESTION_CONTENT_KEY); + String newQuestionParam = request.getParameter("newQuestion"); - int listSize = listQuestionContentDTO.size(); - - request.setAttribute(McAppConstants.NEW_ADDABLE_QUESTION_CONTENT_LIST, listAddableQuestionContentDTO); - - String newQuestion = request.getParameter("newQuestion"); - String feedback = request.getParameter("feedback"); String mark = request.getParameter("mark"); @@ -677,25 +585,22 @@ String passmark = request.getParameter("passmark"); mcGeneralAuthoringDTO.setPassMarkValue(passmark); - List caList = authoringUtil.repopulateCandidateAnswersBox(request, false); + List optionDtos = AuthoringUtil.repopulateOptionDTOs(request, false); + optionDtos = AuthoringUtil.removeBlankOptions(optionDtos); - caList = AuthoringUtil.removeBlankEntries(caList); + if ((newQuestionParam != null) && (newQuestionParam.length() > 0)) { + boolean duplicates = AuthoringUtil.checkDuplicateQuestions(questionDTOs, newQuestionParam); - if ((newQuestion != null) && (newQuestion.length() > 0)) { - boolean duplicates = AuthoringUtil.checkDuplicateQuestions(listQuestionContentDTO, newQuestion); - if (!duplicates) { - McQuestionContentDTO mcQuestionContentDTO = new McQuestionContentDTO(); - mcQuestionContentDTO.setDisplayOrder(new Long(listSize + 1).toString()); - mcQuestionContentDTO.setFeedback(feedback); - mcQuestionContentDTO.setQuestion(newQuestion); - mcQuestionContentDTO.setMark(mark); + McQuestionDTO questionDto = new McQuestionDTO(); + questionDto.setDisplayOrder(new Long(listSize + 1).toString()); + questionDto.setFeedback(feedback); + questionDto.setQuestion(newQuestionParam); + questionDto.setMark(mark); - mcQuestionContentDTO.setListCandidateAnswersDTO(caList); - mcQuestionContentDTO.setCaCount(new Integer(mcQuestionContentDTO.getListCandidateAnswersDTO().size()) - .toString()); + questionDto.setListCandidateAnswersDTO(optionDtos); - listQuestionContentDTO.add(mcQuestionContentDTO); + questionDTOs.add(questionDto); } else { // entry duplicate, not adding } @@ -705,35 +610,33 @@ mcGeneralAuthoringDTO.setMarkValue(mark); - Map passMarksMap = authoringUtil.buildDynamicPassMarkMap(listQuestionContentDTO, false); + Map passMarksMap = AuthoringUtil.buildDynamicPassMarkMap(questionDTOs, false); mcGeneralAuthoringDTO.setPassMarksMap(passMarksMap); - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTO); + String totalMark = AuthoringUtil.getTotalMark(questionDTOs); mcAuthoringForm.setTotalMarks(totalMark); mcGeneralAuthoringDTO.setTotalMarks(totalMark); - mcGeneralAuthoringDTO.setEditableQuestionText(newQuestion); + mcGeneralAuthoringDTO.setEditableQuestionText(newQuestionParam); mcAuthoringForm.setFeedback(feedback); mcGeneralAuthoringDTO.setMarkValue(mark); request.setAttribute(McAppConstants.MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - request.setAttribute(McAppConstants.LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - sessionMap.put(McAppConstants.LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); + request.setAttribute(McAppConstants.LIST_QUESTION_DTOS, questionDTOs); + sessionMap.put(McAppConstants.LIST_QUESTION_DTOS, questionDTOs); - commonSaveCode(request, mcGeneralAuthoringDTO, mcAuthoringForm, sessionMap, activeModule, strToolContentID, - defaultContentIdStr, mcService, httpSessionID, listQuestionContentDTO); + commonSaveCode(request, mcGeneralAuthoringDTO, mcAuthoringForm, sessionMap, strToolContentID, + mcService, httpSessionID, questionDTOs); - request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); + request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(questionDTOs.size())); return (mapping.findForward("itemList")); } /** * opens up an new screen within the current page for adding a new question * - * newQuestionBox - * * @param mapping * @param form * @param request @@ -749,20 +652,12 @@ IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); String httpSessionID = mcAuthoringForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); mcAuthoringForm.setContentFolderID(contentFolderID); - String activeModule = request.getParameter(McAppConstants.ACTIVE_MODULE); - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(McAppConstants.MY_SIGNATURE)) - .toString(); - - /* create default mcContent object */ - McContent mcContent = mcService.retrieveMc(new Long(defaultContentIdStr)); - McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); @@ -773,41 +668,37 @@ mcGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - McUtils.setFormProperties(request, mcService, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); + McUtils.setFormProperties(request, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, httpSessionID); - mcGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - AuthoringUtil authoringUtil = new AuthoringUtil(); - Map marksMap = authoringUtil.buildMarksMap(); + Map marksMap = AuthoringUtil.buildMarksMap(); mcGeneralAuthoringDTO.setMarksMap(marksMap); - List listQuestionContentDTO = (List) sessionMap.get(McAppConstants.LIST_QUESTION_CONTENT_DTO_KEY); + List questionDTOs = (List) sessionMap.get(McAppConstants.LIST_QUESTION_DTOS); - Map correctMap = authoringUtil.buildCorrectMap(); + Map correctMap = AuthoringUtil.buildCorrectMap(); mcGeneralAuthoringDTO.setCorrectMap(correctMap); request.setAttribute(McAppConstants.MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); + + //prepare question for adding new question page + McQuestionDTO newQuestionDTO = new McQuestionDTO(); + List newOptions = new ArrayList(); + McOptionDTO newOption1 = new McOptionDTO(); + newOption1.setCorrect("Correct"); + McOptionDTO newOption2 = new McOptionDTO(); + newOptions.add(newOption1); + newOptions.add(newOption2); + newQuestionDTO.setListCandidateAnswersDTO(newOptions); + sessionMap.put(NEW_QUESTION_DTO, newQuestionDTO); + request.setAttribute(McAppConstants.NEW_QUESTION_DTO, newQuestionDTO); - String requestType = request.getParameter("requestType"); + request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(questionDTOs.size())); - List listAddableQuestionContentDTO = (List) sessionMap.get(McAppConstants.NEW_ADDABLE_QUESTION_CONTENT_KEY); - - if ((requestType != null) && (requestType.equals("direct"))) { - // requestType is direct - listAddableQuestionContentDTO = authoringUtil.buildDefaultQuestionContent(mcContent, mcService); - } - - request.setAttribute(McAppConstants.NEW_ADDABLE_QUESTION_CONTENT_LIST, listAddableQuestionContentDTO); - sessionMap.put(McAppConstants.NEW_ADDABLE_QUESTION_CONTENT_KEY, listAddableQuestionContentDTO); - - request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); - - Map passMarksMap = authoringUtil.buildDynamicPassMarkMap(listQuestionContentDTO, false); + Map passMarksMap = AuthoringUtil.buildDynamicPassMarkMap(questionDTOs, false); mcGeneralAuthoringDTO.setPassMarksMap(passMarksMap); - String newQuestion = request.getParameter("newQuestion"); - mcGeneralAuthoringDTO.setEditableQuestionText(newQuestion); + String newQuestionParam = request.getParameter("newQuestion"); + mcGeneralAuthoringDTO.setEditableQuestionText(newQuestionParam); String feedback = request.getParameter("feedback"); mcAuthoringForm.setFeedback(feedback); @@ -817,21 +708,17 @@ request.setAttribute(McAppConstants.MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTO); + String totalMark = AuthoringUtil.getTotalMark(questionDTOs); mcAuthoringForm.setTotalMarks(totalMark); mcGeneralAuthoringDTO.setTotalMarks(totalMark); - request.setAttribute(McAppConstants.LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); + request.setAttribute(McAppConstants.LIST_QUESTION_DTOS, questionDTOs); mcGeneralAuthoringDTO.setToolContentID(strToolContentID); mcGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - mcGeneralAuthoringDTO.setActiveModule(activeModule); - mcGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); mcAuthoringForm.setToolContentID(strToolContentID); mcAuthoringForm.setHttpSessionID(httpSessionID); - mcAuthoringForm.setActiveModule(activeModule); - mcAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); return (mapping.findForward("newQuestionBox")); } @@ -855,7 +742,7 @@ String httpSessionID = mcAuthoringForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); String questionIndex = request.getParameter("questionIndex"); mcAuthoringForm.setQuestionIndex(questionIndex); @@ -864,23 +751,23 @@ mcAuthoringForm.setEditableQuestionIndex(questionIndex); - List listQuestionContentDTO = (List) sessionMap.get(McAppConstants.LIST_QUESTION_CONTENT_DTO_KEY); + List questionDTOs = (List) sessionMap.get(McAppConstants.LIST_QUESTION_DTOS); String editableQuestion = ""; String editableFeedback = ""; String editableMark = ""; - Iterator listIterator = listQuestionContentDTO.iterator(); - while (listIterator.hasNext()) { - McQuestionContentDTO mcQuestionContentDTO = (McQuestionContentDTO) listIterator.next(); - String displayOrder = mcQuestionContentDTO.getDisplayOrder(); + Iterator iter = questionDTOs.iterator(); + while (iter.hasNext()) { + McQuestionDTO questionDto = (McQuestionDTO) iter.next(); + String displayOrder = questionDto.getDisplayOrder(); if ((displayOrder != null) && (!displayOrder.equals(""))) { if (displayOrder.equals(questionIndex)) { - editableFeedback = mcQuestionContentDTO.getFeedback(); - editableQuestion = mcQuestionContentDTO.getQuestion(); - editableMark = mcQuestionContentDTO.getMark(); + editableFeedback = questionDto.getFeedback(); + editableQuestion = questionDto.getQuestion(); + editableMark = questionDto.getMark(); - List candidates = mcQuestionContentDTO.getListCandidateAnswersDTO(); + List candidates = questionDto.getListCandidateAnswersDTO(); break; } @@ -891,12 +778,9 @@ String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); mcAuthoringForm.setContentFolderID(contentFolderID); - String activeModule = request.getParameter(McAppConstants.ACTIVE_MODULE); String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(McAppConstants.MY_SIGNATURE)) - .toString(); - McContent mcContent = mcService.retrieveMc(new Long(strToolContentID)); + McContent mcContent = mcService.getMcContent(new Long(strToolContentID)); McGeneralAuthoringDTO mcGeneralAuthoringDTO = (McGeneralAuthoringDTO) request .getAttribute(McAppConstants.MC_GENERAL_AUTHORING_DTO); @@ -915,29 +799,25 @@ mcGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - McUtils.setFormProperties(request, mcService, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); + McUtils.setFormProperties(request, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, httpSessionID); mcGeneralAuthoringDTO.setEditableQuestionText(editableQuestion); mcGeneralAuthoringDTO.setEditableQuestionFeedback(editableFeedback); mcAuthoringForm.setFeedback(editableFeedback); - mcGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - AuthoringUtil authoringUtil = new AuthoringUtil(); - Map marksMap = authoringUtil.buildMarksMap(); + Map marksMap = AuthoringUtil.buildMarksMap(); mcGeneralAuthoringDTO.setMarksMap(marksMap); - Map correctMap = authoringUtil.buildCorrectMap(); + Map correctMap = AuthoringUtil.buildCorrectMap(); mcGeneralAuthoringDTO.setCorrectMap(correctMap); request.setAttribute(McAppConstants.MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); + request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(questionDTOs.size())); - Map passMarksMap = authoringUtil.buildDynamicPassMarkMap(listQuestionContentDTO, false); + Map passMarksMap = AuthoringUtil.buildDynamicPassMarkMap(questionDTOs, false); mcGeneralAuthoringDTO.setPassMarksMap(passMarksMap); - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTO); + String totalMark = AuthoringUtil.getTotalMark(questionDTOs); mcAuthoringForm.setTotalMarks(totalMark); mcGeneralAuthoringDTO.setTotalMarks(totalMark); @@ -958,30 +838,18 @@ } request.setAttribute(McAppConstants.MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - request.setAttribute(McAppConstants.LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); + request.setAttribute(McAppConstants.LIST_QUESTION_DTOS, questionDTOs); mcGeneralAuthoringDTO.setToolContentID(strToolContentID); mcGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - mcGeneralAuthoringDTO.setActiveModule(activeModule); - mcGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); mcAuthoringForm.setToolContentID(strToolContentID); mcAuthoringForm.setHttpSessionID(httpSessionID); - mcAuthoringForm.setActiveModule(activeModule); - mcAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); return (mapping.findForward("editQuestionBox")); } /** * removes a question from the questions map - * - * @param mapping - * @param form - * @param request - * @param response - * @return - * @throws IOException - * @throws ServletException */ public ActionForward removeQuestion(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { @@ -990,55 +858,46 @@ IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); String httpSessionID = mcAuthoringForm.getHttpSessionID(); + String questionIndexToDelete = request.getParameter("questionIndex"); + mcAuthoringForm.setQuestionIndex(questionIndexToDelete); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); + List questionDTOs = (List) sessionMap.get(McAppConstants.LIST_QUESTION_DTOS); - String questionIndex = request.getParameter("questionIndex"); - mcAuthoringForm.setQuestionIndex(questionIndex); - - List listQuestionContentDTO = (List) sessionMap.get(McAppConstants.LIST_QUESTION_CONTENT_DTO_KEY); - - McQuestionContentDTO mcQuestionContentDTO = null; - Iterator listIterator = listQuestionContentDTO.iterator(); - while (listIterator.hasNext()) { - mcQuestionContentDTO = (McQuestionContentDTO) listIterator.next(); - - String question = mcQuestionContentDTO.getQuestion(); - String displayOrder = mcQuestionContentDTO.getDisplayOrder(); - - if ((displayOrder != null) && (!displayOrder.equals(""))) { - if (displayOrder.equals(questionIndex)) { - break; - } - + //exclude Question with questionIndex From List + List listFinalQuestionContentDTO = new LinkedList(); + int queIndex = 0; + for (McQuestionDTO questionDTO : questionDTOs) { + + String questionText = questionDTO.getQuestion(); + String displayOrder = questionDTO.getDisplayOrder(); + if ((questionText != null) && (!questionText.isEmpty()) && !displayOrder.equals(questionIndexToDelete)) { + + ++queIndex; + questionDTO.setDisplayOrder(new Integer(queIndex).toString()); + listFinalQuestionContentDTO.add(questionDTO); } + if ((questionText != null) && (!questionText.isEmpty()) && displayOrder.equals(questionIndexToDelete)) { + List deletedQuestionDTOs = (List) sessionMap.get(LIST_DELETED_QUESTION_DTOS);; + deletedQuestionDTOs.add(questionDTO); + sessionMap.put(LIST_DELETED_QUESTION_DTOS, deletedQuestionDTOs); + } } + questionDTOs = listFinalQuestionContentDTO; + sessionMap.put(McAppConstants.LIST_QUESTION_DTOS, questionDTOs); - mcQuestionContentDTO.setQuestion(""); - - listQuestionContentDTO = AuthoringUtil.reorderListQuestionContentDTO(listQuestionContentDTO, questionIndex); - - sessionMap.put(McAppConstants.LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); mcAuthoringForm.setContentFolderID(contentFolderID); - String activeModule = request.getParameter(McAppConstants.ACTIVE_MODULE); String richTextTitle = request.getParameter(McAppConstants.TITLE); String richTextInstructions = request.getParameter(McAppConstants.INSTRUCTIONS); sessionMap.put(McAppConstants.ACTIVITY_TITLE_KEY, richTextTitle); sessionMap.put(McAppConstants.ACTIVITY_INSTRUCTIONS_KEY, richTextInstructions); String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(McAppConstants.MY_SIGNATURE)) - .toString(); - McContent mcContent = mcService.retrieveMc(new Long(strToolContentID)); + McContent mcContent = mcService.getMcContent(new Long(strToolContentID)); - if (mcContent == null) { - mcContent = mcService.retrieveMc(new Long(defaultContentIdStr)); - } - McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); @@ -1047,53 +906,40 @@ mcGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - AuthoringUtil authoringUtil = new AuthoringUtil(); - - mcGeneralAuthoringDTO.setEditActivityEditMode(new Boolean(true).toString()); - request.getSession().setAttribute(httpSessionID, sessionMap); - McUtils.setFormProperties(request, mcService, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); + McUtils.setFormProperties(request, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, httpSessionID); mcGeneralAuthoringDTO.setToolContentID(strToolContentID); mcGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - mcGeneralAuthoringDTO.setActiveModule(activeModule); - mcGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); mcAuthoringForm.setToolContentID(strToolContentID); mcAuthoringForm.setHttpSessionID(httpSessionID); - mcAuthoringForm.setActiveModule(activeModule); - mcAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); mcAuthoringForm.setCurrentTab("1"); - request.setAttribute(McAppConstants.LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); + request.setAttribute(McAppConstants.LIST_QUESTION_DTOS, questionDTOs); - mcGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - Map marksMap = authoringUtil.buildMarksMap(); + Map marksMap = AuthoringUtil.buildMarksMap(); mcGeneralAuthoringDTO.setMarksMap(marksMap); - Map passMarksMap = authoringUtil.buildDynamicPassMarkMap(listQuestionContentDTO, false); + Map passMarksMap = AuthoringUtil.buildDynamicPassMarkMap(questionDTOs, false); mcGeneralAuthoringDTO.setPassMarksMap(passMarksMap); - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTO); + String totalMark = AuthoringUtil.getTotalMark(questionDTOs); mcAuthoringForm.setTotalMarks(totalMark); mcGeneralAuthoringDTO.setTotalMarks(totalMark); - Map correctMap = authoringUtil.buildCorrectMap(); + Map correctMap = AuthoringUtil.buildCorrectMap(); mcGeneralAuthoringDTO.setCorrectMap(correctMap); request.setAttribute(McAppConstants.MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); + request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(questionDTOs.size())); return (mapping.findForward("itemList")); } /** * moves a question down in the list * - * moveQuestionDown - * * @param mapping * @param form * @param request @@ -1110,24 +956,22 @@ String httpSessionID = mcAuthoringForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); String questionIndex = request.getParameter("questionIndex"); mcAuthoringForm.setQuestionIndex(questionIndex); - List listQuestionContentDTO = (List) sessionMap.get(McAppConstants.LIST_QUESTION_CONTENT_DTO_KEY); + List questionDTOs = (List) sessionMap.get(McAppConstants.LIST_QUESTION_DTOS); - listQuestionContentDTO = AuthoringUtil.swapNodes(listQuestionContentDTO, questionIndex, "down"); + questionDTOs = AuthoringUtil.swapQuestions(questionDTOs, questionIndex, "down"); - listQuestionContentDTO = AuthoringUtil.reorderSimpleListQuestionContentDTO(listQuestionContentDTO); + questionDTOs = AuthoringUtil.reorderSimpleQuestionDtos(questionDTOs); - sessionMap.put(McAppConstants.LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); + sessionMap.put(McAppConstants.LIST_QUESTION_DTOS, questionDTOs); String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); mcAuthoringForm.setContentFolderID(contentFolderID); - String activeModule = request.getParameter(McAppConstants.ACTIVE_MODULE); - String richTextTitle = request.getParameter(McAppConstants.TITLE); String richTextInstructions = request.getParameter(McAppConstants.INSTRUCTIONS); @@ -1137,11 +981,8 @@ String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(McAppConstants.MY_SIGNATURE)) - .toString(); + McContent mcContent = mcService.getMcContent(new Long(strToolContentID)); - McContent mcContent = mcService.retrieveMc(new Long(strToolContentID)); - McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); @@ -1150,41 +991,31 @@ mcGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - AuthoringUtil authoringUtil = new AuthoringUtil(); - - mcGeneralAuthoringDTO.setEditActivityEditMode(new Boolean(true).toString()); - request.getSession().setAttribute(httpSessionID, sessionMap); - McUtils.setFormProperties(request, mcService, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); + McUtils.setFormProperties(request, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, httpSessionID); mcGeneralAuthoringDTO.setToolContentID(strToolContentID); mcGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - mcGeneralAuthoringDTO.setActiveModule(activeModule); - mcGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); mcAuthoringForm.setToolContentID(strToolContentID); mcAuthoringForm.setHttpSessionID(httpSessionID); - mcAuthoringForm.setActiveModule(activeModule); - mcAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); mcAuthoringForm.setCurrentTab("1"); - request.setAttribute(McAppConstants.LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - mcGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); + request.setAttribute(McAppConstants.LIST_QUESTION_DTOS, questionDTOs); - Map marksMap = authoringUtil.buildMarksMap(); + Map marksMap = AuthoringUtil.buildMarksMap(); mcGeneralAuthoringDTO.setMarksMap(marksMap); - Map passMarksMap = authoringUtil.buildDynamicPassMarkMap(listQuestionContentDTO, false); + Map passMarksMap = AuthoringUtil.buildDynamicPassMarkMap(questionDTOs, false); mcGeneralAuthoringDTO.setPassMarksMap(passMarksMap); - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTO); + String totalMark = AuthoringUtil.getTotalMark(questionDTOs); mcAuthoringForm.setTotalMarks(totalMark); mcGeneralAuthoringDTO.setTotalMarks(totalMark); - Map correctMap = authoringUtil.buildCorrectMap(); + Map correctMap = AuthoringUtil.buildCorrectMap(); mcGeneralAuthoringDTO.setCorrectMap(correctMap); request.setAttribute(McAppConstants.MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); + request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(questionDTOs.size())); return (mapping.findForward("itemList")); } @@ -1196,39 +1027,32 @@ String httpSessionID = mcAuthoringForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); String questionIndex = request.getParameter("questionIndex"); mcAuthoringForm.setQuestionIndex(questionIndex); - List listQuestionContentDTO = (List) sessionMap.get(McAppConstants.LIST_QUESTION_CONTENT_DTO_KEY); + List questionDTOs = (List) sessionMap.get(McAppConstants.LIST_QUESTION_DTOS); - listQuestionContentDTO = AuthoringUtil.swapNodes(listQuestionContentDTO, questionIndex, "up"); + questionDTOs = AuthoringUtil.swapQuestions(questionDTOs, questionIndex, "up"); - listQuestionContentDTO = AuthoringUtil.reorderSimpleListQuestionContentDTO(listQuestionContentDTO); + questionDTOs = AuthoringUtil.reorderSimpleQuestionDtos(questionDTOs); - sessionMap.put(McAppConstants.LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); + sessionMap.put(McAppConstants.LIST_QUESTION_DTOS, questionDTOs); String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); mcAuthoringForm.setContentFolderID(contentFolderID); - String activeModule = request.getParameter(McAppConstants.ACTIVE_MODULE); - String richTextTitle = request.getParameter(McAppConstants.TITLE); - String totalMarks = request.getParameter("totalMarks"); - String richTextInstructions = request.getParameter(McAppConstants.INSTRUCTIONS); sessionMap.put(McAppConstants.ACTIVITY_TITLE_KEY, richTextTitle); sessionMap.put(McAppConstants.ACTIVITY_INSTRUCTIONS_KEY, richTextInstructions); String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(McAppConstants.MY_SIGNATURE)) - .toString(); + McContent mcContent = mcService.getMcContent(new Long(strToolContentID)); - McContent mcContent = mcService.retrieveMc(new Long(strToolContentID)); - McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); @@ -1237,45 +1061,34 @@ mcGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - AuthoringUtil authoringUtil = new AuthoringUtil(); - - mcGeneralAuthoringDTO.setEditActivityEditMode(new Boolean(true).toString()); - request.getSession().setAttribute(httpSessionID, sessionMap); - McUtils.setFormProperties(request, mcService, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); + McUtils.setFormProperties(request, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, httpSessionID); mcGeneralAuthoringDTO.setToolContentID(strToolContentID); mcGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - mcGeneralAuthoringDTO.setActiveModule(activeModule); - mcGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); mcAuthoringForm.setToolContentID(strToolContentID); mcAuthoringForm.setHttpSessionID(httpSessionID); - mcAuthoringForm.setActiveModule(activeModule); - mcAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); mcAuthoringForm.setCurrentTab("1"); - request.setAttribute(McAppConstants.LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); + request.setAttribute(McAppConstants.LIST_QUESTION_DTOS, questionDTOs); - mcGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - Map marksMap = authoringUtil.buildMarksMap(); + Map marksMap = AuthoringUtil.buildMarksMap(); mcGeneralAuthoringDTO.setMarksMap(marksMap); - Map passMarksMap = authoringUtil.buildDynamicPassMarkMap(listQuestionContentDTO, false); + Map passMarksMap = AuthoringUtil.buildDynamicPassMarkMap(questionDTOs, false); mcGeneralAuthoringDTO.setPassMarksMap(passMarksMap); - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTO); + String totalMark = AuthoringUtil.getTotalMark(questionDTOs); mcAuthoringForm.setTotalMarks(totalMark); mcGeneralAuthoringDTO.setTotalMarks(totalMark); - Map correctMap = authoringUtil.buildCorrectMap(); + Map correctMap = AuthoringUtil.buildCorrectMap(); mcGeneralAuthoringDTO.setCorrectMap(correctMap); request.setAttribute(McAppConstants.MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); + request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(questionDTOs.size())); return (mapping.findForward("itemList")); } @@ -1293,131 +1106,7 @@ saveErrors(request, errors); } - private McToolContentHandler getToolContentHandler() { - if (toolContentHandler == null) { - WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet() - .getServletContext()); - toolContentHandler = (McToolContentHandler) wac.getBean("mcToolContentHandler"); - } - return toolContentHandler; - } - - public ActionForward editActivity(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException { - return null; - } - /** - * - * generates Edit Activity screen - * - * @param mapping - * @param form - * @param request - * @param response - * @return - * @throws IOException - * @throws ServletException - * @throws ToolException - */ - public ActionForward editActivityQuestions(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException, ToolException { - - McAuthoringForm mcAuthoringForm = (McAuthoringForm) form; - - IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); - - String httpSessionID = mcAuthoringForm.getHttpSessionID(); - - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - mcAuthoringForm.setContentFolderID(contentFolderID); - - String totalMarks = request.getParameter("totalMarks"); - - String activeModule = request.getParameter(McAppConstants.ACTIVE_MODULE); - - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - - String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(McAppConstants.MY_SIGNATURE)) - .toString(); - - McContent mcContent = mcService.retrieveMc(new Long(strToolContentID)); - - McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); - mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); - - mcGeneralAuthoringDTO.setActivityTitle(mcContent.getTitle()); - mcAuthoringForm.setTitle(mcContent.getTitle()); - - mcGeneralAuthoringDTO.setActivityInstructions(mcContent.getInstructions()); - - sessionMap.put(McAppConstants.ACTIVITY_TITLE_KEY, mcContent.getTitle()); - sessionMap.put(McAppConstants.ACTIVITY_INSTRUCTIONS_KEY, mcContent.getInstructions()); - - /* determine whether the request is from Monitoring url Edit Activity */ - String sourceMcStarter = (String) request.getAttribute(McAppConstants.SOURCE_MC_STARTER); - - mcAuthoringForm.setDefineLaterInEditMode(new Boolean(true).toString()); - mcGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - boolean isContentInUse = McUtils.isContentInUse(mcContent); - - mcGeneralAuthoringDTO.setMonitoredContentInUse(new Boolean(false).toString()); - if (isContentInUse == true) { - // monitoring url does not allow editActivity since the content is in use - persistError(request, "error.content.inUse"); - mcGeneralAuthoringDTO.setMonitoredContentInUse(new Boolean(true).toString()); - } - - EditActivityDTO editActivityDTO = new EditActivityDTO(); - if (isContentInUse == true) { - editActivityDTO.setMonitoredContentInUse(new Boolean(true).toString()); - } - request.setAttribute(McAppConstants.EDIT_ACTIVITY_DTO, editActivityDTO); - - McUtils.setDefineLater(request, true, strToolContentID, mcService); - - McUtils.setFormProperties(request, mcService, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); - - mcGeneralAuthoringDTO.setToolContentID(strToolContentID); - mcGeneralAuthoringDTO.setActiveModule(activeModule); - mcGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); - mcAuthoringForm.setToolContentID(strToolContentID); - mcAuthoringForm.setActiveModule(activeModule); - mcAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); - mcAuthoringForm.setCurrentTab("1"); - - AuthoringUtil authoringUtil = new AuthoringUtil(); - List listQuestionContentDTO = authoringUtil.buildDefaultQuestionContent(mcContent, mcService); - - request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); - request.setAttribute(McAppConstants.LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - sessionMap.put(McAppConstants.LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - - request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); - request.getSession().setAttribute(httpSessionID, sessionMap); - - Map marksMap = authoringUtil.buildMarksMap(); - mcGeneralAuthoringDTO.setMarksMap(marksMap); - - Map passMarksMap = authoringUtil.buildDynamicPassMarkMap(listQuestionContentDTO, false); - mcGeneralAuthoringDTO.setPassMarksMap(passMarksMap); - - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTO); - mcAuthoringForm.setTotalMarks(totalMark); - mcGeneralAuthoringDTO.setTotalMarks(totalMark); - - Map correctMap = authoringUtil.buildCorrectMap(); - mcGeneralAuthoringDTO.setCorrectMap(correctMap); - request.setAttribute(McAppConstants.MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - - return mapping.findForward(McAppConstants.LOAD_QUESTIONS); - } - - /** * moves a candidate dwn in the list * * @param mapping @@ -1436,7 +1125,7 @@ String httpSessionID = mcAuthoringForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); String questionIndex = request.getParameter("questionIndex"); request.setAttribute("questionIndex", questionIndex); @@ -1445,48 +1134,42 @@ String candidateIndex = request.getParameter("candidateIndex"); request.setAttribute("candidateIndex", candidateIndex); - String totalMarks = request.getParameter("totalMarks"); + List optionDtos = AuthoringUtil.repopulateOptionDTOs(request, false); - AuthoringUtil authoringUtil = new AuthoringUtil(); + List questionDTOs = (List) sessionMap.get(McAppConstants.LIST_QUESTION_DTOS); - List caList = authoringUtil.repopulateCandidateAnswersBox(request, false); - - List listQuestionContentDTO = (List) sessionMap.get(McAppConstants.LIST_QUESTION_CONTENT_DTO_KEY); - List candidates = new LinkedList(); List listCandidates = new LinkedList(); String editableQuestion = ""; - Iterator listIterator = listQuestionContentDTO.iterator(); - while (listIterator.hasNext()) { - McQuestionContentDTO mcQuestionContentDTO = (McQuestionContentDTO) listIterator.next(); + Iterator iter = questionDTOs.iterator(); + while (iter.hasNext()) { + McQuestionDTO questionDto = (McQuestionDTO) iter.next(); - String question = mcQuestionContentDTO.getQuestion(); - String displayOrder = mcQuestionContentDTO.getDisplayOrder(); + String question = questionDto.getQuestion(); + String displayOrder = questionDto.getDisplayOrder(); if ((displayOrder != null) && (!displayOrder.equals(""))) { if (displayOrder.equals(questionIndex)) { - editableQuestion = mcQuestionContentDTO.getQuestion(); + editableQuestion = questionDto.getQuestion(); - candidates = mcQuestionContentDTO.getListCandidateAnswersDTO(); + candidates = questionDto.getListCandidateAnswersDTO(); // candidates found - // but we are using the repopulated caList here + // but we are using the repopulated optionDtos here - listCandidates = AuthoringUtil.swapCandidateNodes(caList, candidateIndex, "down"); + listCandidates = AuthoringUtil.swapOptions(optionDtos, candidateIndex, "down"); - mcQuestionContentDTO.setListCandidateAnswersDTO(listCandidates); + questionDto.setListCandidateAnswersDTO(listCandidates); break; } } } - sessionMap.put(McAppConstants.LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); + sessionMap.put(McAppConstants.LIST_QUESTION_DTOS, questionDTOs); String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - String activeModule = request.getParameter(McAppConstants.ACTIVE_MODULE); - String richTextTitle = request.getParameter(McAppConstants.TITLE); String richTextInstructions = request.getParameter(McAppConstants.INSTRUCTIONS); @@ -1496,44 +1179,34 @@ String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(McAppConstants.MY_SIGNATURE)) - .toString(); + McContent mcContent = mcService.getMcContent(new Long(strToolContentID)); - McContent mcContent = mcService.retrieveMc(new Long(strToolContentID)); - McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); mcGeneralAuthoringDTO.setActivityTitle(richTextTitle); mcGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - mcGeneralAuthoringDTO.setEditActivityEditMode(new Boolean(true).toString()); - request.getSession().setAttribute(httpSessionID, sessionMap); - McUtils.setFormProperties(request, mcService, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); + McUtils.setFormProperties(request, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, httpSessionID); mcGeneralAuthoringDTO.setToolContentID(strToolContentID); mcGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - mcGeneralAuthoringDTO.setActiveModule(activeModule); - mcGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); - request.setAttribute(McAppConstants.LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); + request.setAttribute(McAppConstants.LIST_QUESTION_DTOS, questionDTOs); - mcGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - Map marksMap = authoringUtil.buildMarksMap(); + Map marksMap = AuthoringUtil.buildMarksMap(); mcGeneralAuthoringDTO.setMarksMap(marksMap); - Map passMarksMap = authoringUtil.buildDynamicPassMarkMap(listQuestionContentDTO, false); + Map passMarksMap = AuthoringUtil.buildDynamicPassMarkMap(questionDTOs, false); mcGeneralAuthoringDTO.setPassMarksMap(passMarksMap); - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTO); + String totalMark = AuthoringUtil.getTotalMark(questionDTOs); mcGeneralAuthoringDTO.setTotalMarks(totalMark); - Map correctMap = authoringUtil.buildCorrectMap(); + Map correctMap = AuthoringUtil.buildCorrectMap(); mcGeneralAuthoringDTO.setCorrectMap(correctMap); String newQuestion = request.getParameter("newQuestion"); @@ -1544,7 +1217,7 @@ request.setAttribute(McAppConstants.MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); + request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(questionDTOs.size())); String editQuestionBoxRequest = request.getParameter("editQuestionBoxRequest"); @@ -1571,7 +1244,7 @@ String httpSessionID = mcAuthoringForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); String questionIndex = request.getParameter("questionIndex"); request.setAttribute("questionIndex", questionIndex); @@ -1580,45 +1253,40 @@ String candidateIndex = request.getParameter("candidateIndex"); request.setAttribute("candidateIndex", candidateIndex); - AuthoringUtil authoringUtil = new AuthoringUtil(); + List optionDtos = AuthoringUtil.repopulateOptionDTOs(request, false); - List caList = authoringUtil.repopulateCandidateAnswersBox(request, false); + List questionDTOs = (List) sessionMap.get(McAppConstants.LIST_QUESTION_DTOS); - List listQuestionContentDTO = (List) sessionMap.get(McAppConstants.LIST_QUESTION_CONTENT_DTO_KEY); - List candidates = new LinkedList(); List listCandidates = new LinkedList(); String editableQuestion = ""; - Iterator listIterator = listQuestionContentDTO.iterator(); - while (listIterator.hasNext()) { - McQuestionContentDTO mcQuestionContentDTO = (McQuestionContentDTO) listIterator.next(); + Iterator iter = questionDTOs.iterator(); + while (iter.hasNext()) { + McQuestionDTO questionDto = (McQuestionDTO) iter.next(); - String question = mcQuestionContentDTO.getQuestion(); - String displayOrder = mcQuestionContentDTO.getDisplayOrder(); + String question = questionDto.getQuestion(); + String displayOrder = questionDto.getDisplayOrder(); if ((displayOrder != null) && (!displayOrder.equals(""))) { if (displayOrder.equals(questionIndex)) { - editableQuestion = mcQuestionContentDTO.getQuestion(); + editableQuestion = questionDto.getQuestion(); - candidates = mcQuestionContentDTO.getListCandidateAnswersDTO(); + candidates = questionDto.getListCandidateAnswersDTO(); - listCandidates = AuthoringUtil.swapCandidateNodes(caList, candidateIndex, "up"); + listCandidates = AuthoringUtil.swapOptions(optionDtos, candidateIndex, "up"); - mcQuestionContentDTO.setListCandidateAnswersDTO(listCandidates); - mcQuestionContentDTO.setCaCount(new Integer(listCandidates.size()).toString()); + questionDto.setListCandidateAnswersDTO(listCandidates); break; } } } - sessionMap.put(McAppConstants.LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); + sessionMap.put(McAppConstants.LIST_QUESTION_DTOS, questionDTOs); String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - String activeModule = request.getParameter(McAppConstants.ACTIVE_MODULE); - String richTextTitle = request.getParameter(McAppConstants.TITLE); String richTextInstructions = request.getParameter(McAppConstants.INSTRUCTIONS); @@ -1627,44 +1295,34 @@ sessionMap.put(McAppConstants.ACTIVITY_INSTRUCTIONS_KEY, richTextInstructions); String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); + McContent mcContent = mcService.getMcContent(new Long(strToolContentID)); - String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(McAppConstants.MY_SIGNATURE)) - .toString(); - McContent mcContent = mcService.retrieveMc(new Long(strToolContentID)); - McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); mcGeneralAuthoringDTO.setActivityTitle(richTextTitle); mcGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - mcGeneralAuthoringDTO.setEditActivityEditMode(new Boolean(true).toString()); - request.getSession().setAttribute(httpSessionID, sessionMap); - McUtils.setFormProperties(request, mcService, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); + McUtils.setFormProperties(request, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, httpSessionID); mcGeneralAuthoringDTO.setToolContentID(strToolContentID); mcGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - mcGeneralAuthoringDTO.setActiveModule(activeModule); - mcGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); - request.setAttribute(McAppConstants.LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); + request.setAttribute(McAppConstants.LIST_QUESTION_DTOS, questionDTOs); - mcGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - Map marksMap = authoringUtil.buildMarksMap(); + Map marksMap = AuthoringUtil.buildMarksMap(); mcGeneralAuthoringDTO.setMarksMap(marksMap); - Map passMarksMap = authoringUtil.buildDynamicPassMarkMap(listQuestionContentDTO, false); + Map passMarksMap = AuthoringUtil.buildDynamicPassMarkMap(questionDTOs, false); mcGeneralAuthoringDTO.setPassMarksMap(passMarksMap); - Map correctMap = authoringUtil.buildCorrectMap(); + Map correctMap = AuthoringUtil.buildCorrectMap(); mcGeneralAuthoringDTO.setCorrectMap(correctMap); - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTO); + String totalMark = AuthoringUtil.getTotalMark(questionDTOs); mcGeneralAuthoringDTO.setTotalMarks(totalMark); String newQuestion = request.getParameter("newQuestion"); @@ -1675,7 +1333,7 @@ request.setAttribute(McAppConstants.MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); + request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(questionDTOs.size())); String editQuestionBoxRequest = request.getParameter("editQuestionBoxRequest"); @@ -1702,67 +1360,49 @@ String httpSessionID = mcAuthoringForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); String questionIndex = request.getParameter("questionIndex"); request.setAttribute("questionIndex", questionIndex); request.setAttribute(McAppConstants.CURRENT_EDITABLE_QUESTION_INDEX, questionIndex); - String candidateIndex = request.getParameter("candidateIndex"); - request.setAttribute("candidateIndex", candidateIndex); + String optionIndexToRemove = request.getParameter("candidateIndex"); + request.setAttribute("candidateIndex", optionIndexToRemove); - String totalMarks = request.getParameter("totalMarks"); - - List listQuestionContentDTO = (List) sessionMap.get(McAppConstants.LIST_QUESTION_CONTENT_DTO_KEY); - - AuthoringUtil authoringUtil = new AuthoringUtil(); - List caList = authoringUtil.repopulateCandidateAnswersBox(request, false); - - McQuestionContentDTO mcQuestionContentDTO = null; - Iterator listIterator = listQuestionContentDTO.iterator(); - while (listIterator.hasNext()) { - mcQuestionContentDTO = (McQuestionContentDTO) listIterator.next(); - - String question = mcQuestionContentDTO.getQuestion(); - String displayOrder = mcQuestionContentDTO.getDisplayOrder(); - + //find question + List questionDTOs = (List) sessionMap.get(McAppConstants.LIST_QUESTION_DTOS); + McQuestionDTO questionDto = null; + Iterator iter = questionDTOs.iterator(); + while (iter.hasNext()) { + questionDto = (McQuestionDTO) iter.next(); + String displayOrder = questionDto.getDisplayOrder(); if ((displayOrder != null) && (!displayOrder.equals(""))) { if (displayOrder.equals(questionIndex)) { break; } - } } - mcQuestionContentDTO.setListCandidateAnswersDTO(caList); - - List candidateAnswers = mcQuestionContentDTO.getListCandidateAnswersDTO(); - - McCandidateAnswersDTO mcCandidateAnswersDTO = null; - Iterator listCaIterator = candidateAnswers.iterator(); + //update options + List optionDtos = AuthoringUtil.repopulateOptionDTOs(request, false); + List listFinalCandidatesDTO = new LinkedList(); + McOptionDTO mcOptionDTO = null; + Iterator listCaIterator = optionDtos.iterator(); int caIndex = 0; while (listCaIterator.hasNext()) { caIndex++; - mcCandidateAnswersDTO = (McCandidateAnswersDTO) listCaIterator.next(); - - if (caIndex == new Integer(candidateIndex).intValue()) { - mcCandidateAnswersDTO.setCandidateAnswer(""); - - break; + mcOptionDTO = (McOptionDTO) listCaIterator.next(); + if (caIndex != new Integer(optionIndexToRemove).intValue()) { + listFinalCandidatesDTO.add(mcOptionDTO); } } - candidateAnswers = AuthoringUtil.reorderListCandidatesDTO(candidateAnswers); + questionDto.setListCandidateAnswersDTO(listFinalCandidatesDTO); - mcQuestionContentDTO.setListCandidateAnswersDTO(candidateAnswers); - mcQuestionContentDTO.setCaCount(new Integer(candidateAnswers.size()).toString()); + sessionMap.put(McAppConstants.LIST_QUESTION_DTOS, questionDTOs); - sessionMap.put(McAppConstants.LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - String activeModule = request.getParameter(McAppConstants.ACTIVE_MODULE); - String richTextTitle = request.getParameter(McAppConstants.TITLE); String richTextInstructions = request.getParameter(McAppConstants.INSTRUCTIONS); @@ -1772,48 +1412,34 @@ String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(McAppConstants.MY_SIGNATURE)) - .toString(); + McContent mcContent = mcService.getMcContent(new Long(strToolContentID)); - McContent mcContent = mcService.retrieveMc(new Long(strToolContentID)); - - if (mcContent == null) { - mcContent = mcService.retrieveMc(new Long(defaultContentIdStr)); - } - McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); mcGeneralAuthoringDTO.setActivityTitle(richTextTitle); mcGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - mcGeneralAuthoringDTO.setEditActivityEditMode(new Boolean(true).toString()); - request.getSession().setAttribute(httpSessionID, sessionMap); - McUtils.setFormProperties(request, mcService, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); + McUtils.setFormProperties(request, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, httpSessionID); mcGeneralAuthoringDTO.setToolContentID(strToolContentID); mcGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - mcGeneralAuthoringDTO.setActiveModule(activeModule); - mcGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); - request.setAttribute(McAppConstants.LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); + request.setAttribute(McAppConstants.LIST_QUESTION_DTOS, questionDTOs); - mcGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - Map marksMap = authoringUtil.buildMarksMap(); + Map marksMap = AuthoringUtil.buildMarksMap(); mcGeneralAuthoringDTO.setMarksMap(marksMap); - Map passMarksMap = authoringUtil.buildDynamicPassMarkMap(listQuestionContentDTO, false); + Map passMarksMap = AuthoringUtil.buildDynamicPassMarkMap(questionDTOs, false); mcGeneralAuthoringDTO.setPassMarksMap(passMarksMap); - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTO); + String totalMark = AuthoringUtil.getTotalMark(questionDTOs); mcGeneralAuthoringDTO.setTotalMarks(totalMark); - Map correctMap = authoringUtil.buildCorrectMap(); + Map correctMap = AuthoringUtil.buildCorrectMap(); mcGeneralAuthoringDTO.setCorrectMap(correctMap); String newQuestion = request.getParameter("newQuestion"); @@ -1824,7 +1450,7 @@ request.setAttribute(McAppConstants.MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); + request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(questionDTOs.size())); String editQuestionBoxRequest = request.getParameter("editQuestionBoxRequest"); @@ -1851,7 +1477,7 @@ String httpSessionID = mcAuthoringForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); String questionIndex = request.getParameter("questionIndex"); request.setAttribute("questionIndex", questionIndex); @@ -1860,13 +1486,10 @@ String candidateIndex = request.getParameter("candidateIndex"); request.setAttribute("candidateIndex", candidateIndex); - List listQuestionContentDTO = (List) sessionMap.get(McAppConstants.LIST_QUESTION_CONTENT_DTO_KEY); + List questionDTOs = (List) sessionMap.get(McAppConstants.LIST_QUESTION_DTOS); - AuthoringUtil authoringUtil = new AuthoringUtil(); - List caList = authoringUtil.repopulateCandidateAnswersBox(request, true); + List optionDtos = AuthoringUtil.repopulateOptionDTOs(request, true); - int caCount = caList.size(); - String newQuestion = request.getParameter("newQuestion"); String mark = request.getParameter("mark"); @@ -1875,14 +1498,12 @@ String feedback = request.getParameter("feedback"); - int currentQuestionCount = listQuestionContentDTO.size(); - String editQuestionBoxRequest = request.getParameter("editQuestionBoxRequest"); - McQuestionContentDTO mcQuestionContentDTOLocal = null; - Iterator listIterator = listQuestionContentDTO.iterator(); - while (listIterator.hasNext()) { - mcQuestionContentDTOLocal = (McQuestionContentDTO) listIterator.next(); + McQuestionDTO mcQuestionContentDTOLocal = null; + Iterator iter = questionDTOs.iterator(); + while (iter.hasNext()) { + mcQuestionContentDTOLocal = (McQuestionDTO) iter.next(); String question = mcQuestionContentDTOLocal.getQuestion(); String displayOrder = mcQuestionContentDTOLocal.getDisplayOrder(); @@ -1896,16 +1517,13 @@ } if (mcQuestionContentDTOLocal != null) { - mcQuestionContentDTOLocal.setListCandidateAnswersDTO(caList); - mcQuestionContentDTOLocal.setCaCount(new Integer(caList.size()).toString()); + mcQuestionContentDTOLocal.setListCandidateAnswersDTO(optionDtos); } - sessionMap.put(McAppConstants.LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); + sessionMap.put(McAppConstants.LIST_QUESTION_DTOS, questionDTOs); String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - String activeModule = request.getParameter(McAppConstants.ACTIVE_MODULE); - String richTextTitle = request.getParameter(McAppConstants.TITLE); String richTextInstructions = request.getParameter(McAppConstants.INSTRUCTIONS); @@ -1914,8 +1532,6 @@ sessionMap.put(McAppConstants.ACTIVITY_INSTRUCTIONS_KEY, richTextInstructions); String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(McAppConstants.MY_SIGNATURE)) - .toString(); McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); @@ -1924,32 +1540,25 @@ mcGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - mcGeneralAuthoringDTO.setEditActivityEditMode(new Boolean(true).toString()); - request.getSession().setAttribute(httpSessionID, sessionMap); - McUtils.setFormProperties(request, mcService, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); + McUtils.setFormProperties(request, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, httpSessionID); mcGeneralAuthoringDTO.setToolContentID(strToolContentID); mcGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - mcGeneralAuthoringDTO.setActiveModule(activeModule); - mcGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); - request.setAttribute(McAppConstants.LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); + request.setAttribute(McAppConstants.LIST_QUESTION_DTOS, questionDTOs); - mcGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - Map marksMap = authoringUtil.buildMarksMap(); + Map marksMap = AuthoringUtil.buildMarksMap(); mcGeneralAuthoringDTO.setMarksMap(marksMap); - Map passMarksMap = authoringUtil.buildDynamicPassMarkMap(listQuestionContentDTO, false); + Map passMarksMap = AuthoringUtil.buildDynamicPassMarkMap(questionDTOs, false); mcGeneralAuthoringDTO.setPassMarksMap(passMarksMap); - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTO); + String totalMark = AuthoringUtil.getTotalMark(questionDTOs); mcGeneralAuthoringDTO.setTotalMarks(totalMark); - Map correctMap = authoringUtil.buildCorrectMap(); + Map correctMap = AuthoringUtil.buildCorrectMap(); mcGeneralAuthoringDTO.setCorrectMap(correctMap); mcGeneralAuthoringDTO.setEditableQuestionText(newQuestion); @@ -1958,7 +1567,7 @@ request.setAttribute(McAppConstants.MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); + request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(questionDTOs.size())); request.setAttribute("requestNewEditableQuestionBox", new Boolean(true).toString()); return (mapping.findForward("candidateAnswersList")); @@ -1968,26 +1577,25 @@ HttpServletResponse response) throws IOException, ServletException { McAuthoringForm mcAuthoringForm = (McAuthoringForm) form; + ToolAccessMode mode = getAccessMode(request); + request.setAttribute(AttributeNames.ATTR_MODE, mode.toString()); + IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); String httpSessionID = mcAuthoringForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); String questionIndex = request.getParameter("questionIndex"); mcAuthoringForm.setQuestionIndex(questionIndex); - String totalMarks = request.getParameter("totalMarks"); + List questionDTOs = (List) sessionMap.get(McAppConstants.LIST_QUESTION_DTOS); - List listQuestionContentDTO = (List) sessionMap.get(McAppConstants.LIST_QUESTION_CONTENT_DTO_KEY); + sessionMap.put(McAppConstants.LIST_QUESTION_DTOS, questionDTOs); - sessionMap.put(McAppConstants.LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); mcAuthoringForm.setContentFolderID(contentFolderID); - String activeModule = request.getParameter(McAppConstants.ACTIVE_MODULE); - String richTextTitle = request.getParameter(McAppConstants.TITLE); String richTextInstructions = request.getParameter(McAppConstants.INSTRUCTIONS); @@ -1996,12 +1604,8 @@ sessionMap.put(McAppConstants.ACTIVITY_INSTRUCTIONS_KEY, richTextInstructions); String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); + McContent mcContent = mcService.getMcContent(new Long(strToolContentID)); - String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(McAppConstants.MY_SIGNATURE)) - .toString(); - - McContent mcContent = mcService.retrieveMc(new Long(strToolContentID)); - McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); @@ -2010,47 +1614,36 @@ mcGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - AuthoringUtil authoringUtil = new AuthoringUtil(); - - mcGeneralAuthoringDTO.setEditActivityEditMode(new Boolean(true).toString()); - request.getSession().setAttribute(httpSessionID, sessionMap); - McUtils.setFormProperties(request, mcService, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); + McUtils.setFormProperties(request, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, httpSessionID); mcGeneralAuthoringDTO.setToolContentID(strToolContentID); mcGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - mcGeneralAuthoringDTO.setActiveModule(activeModule); - mcGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); mcAuthoringForm.setToolContentID(strToolContentID); mcAuthoringForm.setHttpSessionID(httpSessionID); - mcAuthoringForm.setActiveModule(activeModule); - mcAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); mcAuthoringForm.setCurrentTab("2"); - request.setAttribute(McAppConstants.LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); + request.setAttribute(McAppConstants.LIST_QUESTION_DTOS, questionDTOs); - mcGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - Map marksMap = authoringUtil.buildMarksMap(); + Map marksMap = AuthoringUtil.buildMarksMap(); mcGeneralAuthoringDTO.setMarksMap(marksMap); - Map passMarksMap = authoringUtil.buildDynamicPassMarkMap(listQuestionContentDTO, false); + Map passMarksMap = AuthoringUtil.buildDynamicPassMarkMap(questionDTOs, false); mcGeneralAuthoringDTO.setPassMarksMap(passMarksMap); - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTO); + String totalMark = AuthoringUtil.getTotalMark(questionDTOs); mcAuthoringForm.setTotalMarks(totalMark); mcGeneralAuthoringDTO.setTotalMarks(totalMark); - Map correctMap = authoringUtil.buildCorrectMap(); + Map correctMap = AuthoringUtil.buildCorrectMap(); mcGeneralAuthoringDTO.setCorrectMap(correctMap); request.setAttribute(McAppConstants.MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); + request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(questionDTOs.size())); - return (mapping.findForward(McAppConstants.LOAD_QUESTIONS)); + return (mapping.findForward(McAppConstants.LOAD_AUTHORING)); } public ActionForward moveAddedCandidateUp(ActionMapping mapping, ActionForm form, HttpServletRequest request, @@ -2061,42 +1654,28 @@ String httpSessionID = mcAuthoringForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - String totalMarks = request.getParameter("totalMarks"); String candidateIndex = request.getParameter("candidateIndex"); request.setAttribute("candidateIndex", candidateIndex); - AuthoringUtil authoringUtil = new AuthoringUtil(); + List optionDtos = AuthoringUtil.repopulateOptionDTOs(request, false); - List caList = authoringUtil.repopulateCandidateAnswersBox(request, false); + List questionDTOs = (List) sessionMap.get(McAppConstants.LIST_QUESTION_DTOS); - List listQuestionContentDTO = (List) sessionMap.get(McAppConstants.LIST_QUESTION_CONTENT_DTO_KEY); + sessionMap.put(McAppConstants.LIST_QUESTION_DTOS, questionDTOs); - sessionMap.put(McAppConstants.LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - - List listAddableQuestionContentDTO = (List) sessionMap.get(McAppConstants.NEW_ADDABLE_QUESTION_CONTENT_KEY); - + //moveAddedCandidateUp + McQuestionDTO newQuestionDTO = (McQuestionDTO) sessionMap.get(McAppConstants.NEW_QUESTION_DTO); List listCandidates = new LinkedList(); + listCandidates = AuthoringUtil.swapOptions(optionDtos, candidateIndex, "up"); + newQuestionDTO.setListCandidateAnswersDTO(listCandidates); + request.setAttribute(McAppConstants.NEW_QUESTION_DTO, newQuestionDTO); + sessionMap.put(McAppConstants.NEW_QUESTION_DTO, newQuestionDTO); - Iterator listIterator = listAddableQuestionContentDTO.iterator(); - /* there is only 1 question dto */ - while (listIterator.hasNext()) { - McQuestionContentDTO mcQuestionContentDTO = (McQuestionContentDTO) listIterator.next(); - - listCandidates = AuthoringUtil.swapCandidateNodes(caList, candidateIndex, "up"); - - mcQuestionContentDTO.setListCandidateAnswersDTO(listCandidates); - } - - request.setAttribute(McAppConstants.NEW_ADDABLE_QUESTION_CONTENT_LIST, listAddableQuestionContentDTO); - sessionMap.put(McAppConstants.NEW_ADDABLE_QUESTION_CONTENT_KEY, listAddableQuestionContentDTO); - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - String activeModule = request.getParameter(McAppConstants.ACTIVE_MODULE); - String richTextTitle = request.getParameter(McAppConstants.TITLE); String richTextInstructions = request.getParameter(McAppConstants.INSTRUCTIONS); @@ -2105,45 +1684,34 @@ sessionMap.put(McAppConstants.ACTIVITY_INSTRUCTIONS_KEY, richTextInstructions); String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); + McContent mcContent = mcService.getMcContent(new Long(strToolContentID)); - String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(McAppConstants.MY_SIGNATURE)) - .toString(); - - McContent mcContent = mcService.retrieveMc(new Long(strToolContentID)); - McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); mcGeneralAuthoringDTO.setActivityTitle(richTextTitle); mcGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - mcGeneralAuthoringDTO.setEditActivityEditMode(new Boolean(true).toString()); - request.getSession().setAttribute(httpSessionID, sessionMap); - McUtils.setFormProperties(request, mcService, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); + McUtils.setFormProperties(request, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, httpSessionID); mcGeneralAuthoringDTO.setToolContentID(strToolContentID); mcGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - mcGeneralAuthoringDTO.setActiveModule(activeModule); - mcGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); - request.setAttribute(McAppConstants.LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); + request.setAttribute(McAppConstants.LIST_QUESTION_DTOS, questionDTOs); - mcGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - Map marksMap = authoringUtil.buildMarksMap(); + Map marksMap = AuthoringUtil.buildMarksMap(); mcGeneralAuthoringDTO.setMarksMap(marksMap); - Map passMarksMap = authoringUtil.buildDynamicPassMarkMap(listQuestionContentDTO, false); + Map passMarksMap = AuthoringUtil.buildDynamicPassMarkMap(questionDTOs, false); mcGeneralAuthoringDTO.setPassMarksMap(passMarksMap); - Map correctMap = authoringUtil.buildCorrectMap(); + Map correctMap = AuthoringUtil.buildCorrectMap(); mcGeneralAuthoringDTO.setCorrectMap(correctMap); - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTO); + String totalMark = AuthoringUtil.getTotalMark(questionDTOs); mcGeneralAuthoringDTO.setTotalMarks(totalMark); String newQuestion = request.getParameter("newQuestion"); @@ -2156,7 +1724,7 @@ request.setAttribute(McAppConstants.MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); + request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(questionDTOs.size())); String editQuestionBoxRequest = request.getParameter("editQuestionBoxRequest"); @@ -2172,41 +1740,26 @@ String httpSessionID = mcAuthoringForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); String candidateIndex = request.getParameter("candidateIndex"); request.setAttribute("candidateIndex", candidateIndex); - String totalMarks = request.getParameter("totalMarks"); + List optionDtos = AuthoringUtil.repopulateOptionDTOs(request, false); - AuthoringUtil authoringUtil = new AuthoringUtil(); + List questionDTOs = (List) sessionMap.get(McAppConstants.LIST_QUESTION_DTOS); + sessionMap.put(McAppConstants.LIST_QUESTION_DTOS, questionDTOs); - List caList = authoringUtil.repopulateCandidateAnswersBox(request, false); - - List listQuestionContentDTO = (List) sessionMap.get(McAppConstants.LIST_QUESTION_CONTENT_DTO_KEY); - sessionMap.put(McAppConstants.LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - - List listAddableQuestionContentDTO = (List) sessionMap.get(McAppConstants.NEW_ADDABLE_QUESTION_CONTENT_KEY); - + //moveAddedCandidateDown + McQuestionDTO newQuestionDTO = (McQuestionDTO) sessionMap.get(McAppConstants.NEW_QUESTION_DTO); List listCandidates = new LinkedList(); + listCandidates = AuthoringUtil.swapOptions(optionDtos, candidateIndex, "down"); + newQuestionDTO.setListCandidateAnswersDTO(listCandidates); + request.setAttribute(McAppConstants.NEW_QUESTION_DTO, newQuestionDTO); + sessionMap.put(McAppConstants.NEW_QUESTION_DTO, newQuestionDTO); - Iterator listIterator = listAddableQuestionContentDTO.iterator(); - /* there is only 1 question dto */ - while (listIterator.hasNext()) { - McQuestionContentDTO mcQuestionContentDTO = (McQuestionContentDTO) listIterator.next(); - - listCandidates = AuthoringUtil.swapCandidateNodes(caList, candidateIndex, "down"); - - mcQuestionContentDTO.setListCandidateAnswersDTO(listCandidates); - } - - request.setAttribute(McAppConstants.NEW_ADDABLE_QUESTION_CONTENT_LIST, listAddableQuestionContentDTO); - sessionMap.put(McAppConstants.NEW_ADDABLE_QUESTION_CONTENT_KEY, listAddableQuestionContentDTO); - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - String activeModule = request.getParameter(McAppConstants.ACTIVE_MODULE); - String richTextTitle = request.getParameter(McAppConstants.TITLE); String richTextInstructions = request.getParameter(McAppConstants.INSTRUCTIONS); @@ -2216,42 +1769,32 @@ String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(McAppConstants.MY_SIGNATURE)) - .toString(); - McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); mcGeneralAuthoringDTO.setActivityTitle(richTextTitle); mcGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - mcGeneralAuthoringDTO.setEditActivityEditMode(new Boolean(true).toString()); - request.getSession().setAttribute(httpSessionID, sessionMap); - McUtils.setFormProperties(request, mcService, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); + McUtils.setFormProperties(request, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, httpSessionID); mcGeneralAuthoringDTO.setToolContentID(strToolContentID); mcGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - mcGeneralAuthoringDTO.setActiveModule(activeModule); - mcGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); - request.setAttribute(McAppConstants.LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); + request.setAttribute(McAppConstants.LIST_QUESTION_DTOS, questionDTOs); - mcGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - Map marksMap = authoringUtil.buildMarksMap(); + Map marksMap = AuthoringUtil.buildMarksMap(); mcGeneralAuthoringDTO.setMarksMap(marksMap); - Map passMarksMap = authoringUtil.buildDynamicPassMarkMap(listQuestionContentDTO, false); + Map passMarksMap = AuthoringUtil.buildDynamicPassMarkMap(questionDTOs, false); mcGeneralAuthoringDTO.setPassMarksMap(passMarksMap); - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTO); + String totalMark = AuthoringUtil.getTotalMark(questionDTOs); mcGeneralAuthoringDTO.setTotalMarks(totalMark); - Map correctMap = authoringUtil.buildCorrectMap(); + Map correctMap = AuthoringUtil.buildCorrectMap(); mcGeneralAuthoringDTO.setCorrectMap(correctMap); String newQuestion = request.getParameter("newQuestion"); @@ -2262,7 +1805,7 @@ request.setAttribute(McAppConstants.MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); + request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(questionDTOs.size())); return (mapping.findForward("candidateAnswersAddList")); } @@ -2275,61 +1818,34 @@ String httpSessionID = mcAuthoringForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - String candidateIndex = request.getParameter("candidateIndex"); - request.setAttribute("candidateIndex", candidateIndex); + String candidateIndexToRemove = request.getParameter("candidateIndex"); + request.setAttribute("candidateIndex", candidateIndexToRemove); - String totalMarks = request.getParameter("totalMarks"); + List questionDTOs = (List) sessionMap.get(McAppConstants.LIST_QUESTION_DTOS); + sessionMap.put(McAppConstants.LIST_QUESTION_DTOS, questionDTOs); - AuthoringUtil authoringUtil = new AuthoringUtil(); - List caList = authoringUtil.repopulateCandidateAnswersBox(request, false); + // removeAddedCandidate + McQuestionDTO newQuestionDTO = (McQuestionDTO) sessionMap.get(McAppConstants.NEW_QUESTION_DTO); + + List optionDtos = AuthoringUtil.repopulateOptionDTOs(request, false); + List listFinalCandidatesDTO = new LinkedList(); + int caIndex = 0; + for (McOptionDTO mcOptionDTO : optionDtos) { + caIndex++; - List listQuestionContentDTO = (List) sessionMap.get(McAppConstants.LIST_QUESTION_CONTENT_DTO_KEY); - sessionMap.put(McAppConstants.LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - - List listAddableQuestionContentDTO = (List) sessionMap.get(McAppConstants.NEW_ADDABLE_QUESTION_CONTENT_KEY); - - List candidates = new LinkedList(); - List listCandidates = new LinkedList(); - - Iterator listIterator = listAddableQuestionContentDTO.iterator(); - /* there is only 1 question dto */ - while (listIterator.hasNext()) { - McQuestionContentDTO mcQuestionContentDTO = (McQuestionContentDTO) listIterator.next(); - - candidates = mcQuestionContentDTO.getListCandidateAnswersDTO(); - mcQuestionContentDTO.setListCandidateAnswersDTO(caList); - - List candidateAnswers = mcQuestionContentDTO.getListCandidateAnswersDTO(); - - McCandidateAnswersDTO mcCandidateAnswersDTO = null; - Iterator listCaIterator = candidateAnswers.iterator(); - int caIndex = 0; - while (listCaIterator.hasNext()) { - caIndex++; - mcCandidateAnswersDTO = (McCandidateAnswersDTO) listCaIterator.next(); - - if (caIndex == new Integer(candidateIndex).intValue()) { - mcCandidateAnswersDTO.setCandidateAnswer(""); - - break; - } + if (caIndex != new Integer(candidateIndexToRemove).intValue()) { + listFinalCandidatesDTO.add(mcOptionDTO); } - - candidateAnswers = AuthoringUtil.reorderListCandidatesDTO(candidateAnswers); - - mcQuestionContentDTO.setListCandidateAnswersDTO(candidateAnswers); - mcQuestionContentDTO.setCaCount(new Integer(candidateAnswers.size()).toString()); } + + newQuestionDTO.setListCandidateAnswersDTO(listFinalCandidatesDTO); + request.setAttribute(McAppConstants.NEW_QUESTION_DTO, newQuestionDTO); + sessionMap.put(McAppConstants.NEW_QUESTION_DTO, newQuestionDTO); - request.setAttribute(McAppConstants.NEW_ADDABLE_QUESTION_CONTENT_LIST, listAddableQuestionContentDTO); - sessionMap.put(McAppConstants.NEW_ADDABLE_QUESTION_CONTENT_KEY, listAddableQuestionContentDTO); - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - String activeModule = request.getParameter(McAppConstants.ACTIVE_MODULE); - String richTextTitle = request.getParameter(McAppConstants.TITLE); String richTextInstructions = request.getParameter(McAppConstants.INSTRUCTIONS); @@ -2338,49 +1854,34 @@ sessionMap.put(McAppConstants.ACTIVITY_INSTRUCTIONS_KEY, richTextInstructions); String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); + McContent mcContent = mcService.getMcContent(new Long(strToolContentID)); - String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(McAppConstants.MY_SIGNATURE)) - .toString(); - - McContent mcContent = mcService.retrieveMc(new Long(strToolContentID)); - - if (mcContent == null) { - mcContent = mcService.retrieveMc(new Long(defaultContentIdStr)); - } - McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); mcGeneralAuthoringDTO.setActivityTitle(richTextTitle); mcGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - mcGeneralAuthoringDTO.setEditActivityEditMode(new Boolean(true).toString()); - request.getSession().setAttribute(httpSessionID, sessionMap); - McUtils.setFormProperties(request, mcService, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); + McUtils.setFormProperties(request, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, httpSessionID); mcGeneralAuthoringDTO.setToolContentID(strToolContentID); mcGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - mcGeneralAuthoringDTO.setActiveModule(activeModule); - mcGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); - request.setAttribute(McAppConstants.LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); + request.setAttribute(McAppConstants.LIST_QUESTION_DTOS, questionDTOs); - mcGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - Map marksMap = authoringUtil.buildMarksMap(); + Map marksMap = AuthoringUtil.buildMarksMap(); mcGeneralAuthoringDTO.setMarksMap(marksMap); - Map passMarksMap = authoringUtil.buildDynamicPassMarkMap(listQuestionContentDTO, false); + Map passMarksMap = AuthoringUtil.buildDynamicPassMarkMap(questionDTOs, false); mcGeneralAuthoringDTO.setPassMarksMap(passMarksMap); - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTO); + String totalMark = AuthoringUtil.getTotalMark(questionDTOs); mcGeneralAuthoringDTO.setTotalMarks(totalMark); - Map correctMap = authoringUtil.buildCorrectMap(); + Map correctMap = AuthoringUtil.buildCorrectMap(); mcGeneralAuthoringDTO.setCorrectMap(correctMap); String newQuestion = request.getParameter("newQuestion"); @@ -2393,7 +1894,7 @@ request.setAttribute(McAppConstants.MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); + request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(questionDTOs.size())); String editQuestionBoxRequest = request.getParameter("editQuestionBoxRequest"); @@ -2409,20 +1910,15 @@ String httpSessionID = mcAuthoringForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); String candidateIndex = request.getParameter("candidateIndex"); request.setAttribute("candidateIndex", candidateIndex); - String totalMarks = request.getParameter("totalMarks"); + List questionDTOs = (List) sessionMap.get(McAppConstants.LIST_QUESTION_DTOS); - List listQuestionContentDTO = (List) sessionMap.get(McAppConstants.LIST_QUESTION_CONTENT_DTO_KEY); + List optionDtos = AuthoringUtil.repopulateOptionDTOs(request, true); - AuthoringUtil authoringUtil = new AuthoringUtil(); - List caList = authoringUtil.repopulateCandidateAnswersBox(request, true); - - int caCount = caList.size(); - String newQuestion = request.getParameter("newQuestion"); String mark = request.getParameter("mark"); @@ -2431,33 +1927,18 @@ String feedback = request.getParameter("feedback"); - int currentQuestionCount = listQuestionContentDTO.size(); - String editQuestionBoxRequest = request.getParameter("editQuestionBoxRequest"); - List listAddableQuestionContentDTO = (List) sessionMap.get(McAppConstants.NEW_ADDABLE_QUESTION_CONTENT_KEY); + //newAddedCandidateBox + McQuestionDTO newQuestionDTO = (McQuestionDTO) sessionMap.get(McAppConstants.NEW_QUESTION_DTO); + newQuestionDTO.setListCandidateAnswersDTO(optionDtos); + request.setAttribute(McAppConstants.NEW_QUESTION_DTO, newQuestionDTO); + sessionMap.put(McAppConstants.NEW_QUESTION_DTO, newQuestionDTO); - List candidates = new LinkedList(); - List listCandidates = new LinkedList(); + sessionMap.put(McAppConstants.LIST_QUESTION_DTOS, questionDTOs); - Iterator listIterator = listAddableQuestionContentDTO.iterator(); - /* there is only 1 question dto */ - while (listIterator.hasNext()) { - McQuestionContentDTO mcQuestionContentDTO = (McQuestionContentDTO) listIterator.next(); - - mcQuestionContentDTO.setListCandidateAnswersDTO(caList); - mcQuestionContentDTO.setCaCount(new Integer(caList.size()).toString()); - } - - request.setAttribute(McAppConstants.NEW_ADDABLE_QUESTION_CONTENT_LIST, listAddableQuestionContentDTO); - sessionMap.put(McAppConstants.NEW_ADDABLE_QUESTION_CONTENT_KEY, listAddableQuestionContentDTO); - - sessionMap.put(McAppConstants.LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - String activeModule = request.getParameter(McAppConstants.ACTIVE_MODULE); - String richTextTitle = request.getParameter(McAppConstants.TITLE); String richTextInstructions = request.getParameter(McAppConstants.INSTRUCTIONS); @@ -2467,42 +1948,32 @@ String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(McAppConstants.MY_SIGNATURE)) - .toString(); - McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); mcGeneralAuthoringDTO.setActivityTitle(richTextTitle); mcGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - mcGeneralAuthoringDTO.setEditActivityEditMode(new Boolean(true).toString()); - request.getSession().setAttribute(httpSessionID, sessionMap); - McUtils.setFormProperties(request, mcService, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); + McUtils.setFormProperties(request, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, httpSessionID); mcGeneralAuthoringDTO.setToolContentID(strToolContentID); mcGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - mcGeneralAuthoringDTO.setActiveModule(activeModule); - mcGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); - request.setAttribute(McAppConstants.LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); + request.setAttribute(McAppConstants.LIST_QUESTION_DTOS, questionDTOs); - mcGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - Map marksMap = authoringUtil.buildMarksMap(); + Map marksMap = AuthoringUtil.buildMarksMap(); mcGeneralAuthoringDTO.setMarksMap(marksMap); - Map passMarksMap = authoringUtil.buildDynamicPassMarkMap(listQuestionContentDTO, false); + Map passMarksMap = AuthoringUtil.buildDynamicPassMarkMap(questionDTOs, false); mcGeneralAuthoringDTO.setPassMarksMap(passMarksMap); - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTO); + String totalMark = AuthoringUtil.getTotalMark(questionDTOs); mcGeneralAuthoringDTO.setTotalMarks(totalMark); - Map correctMap = authoringUtil.buildCorrectMap(); + Map correctMap = AuthoringUtil.buildCorrectMap(); mcGeneralAuthoringDTO.setCorrectMap(correctMap); mcGeneralAuthoringDTO.setEditableQuestionText(newQuestion); @@ -2511,19 +1982,36 @@ request.setAttribute(McAppConstants.MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); + request.setAttribute(McAppConstants.TOTAL_QUESTION_COUNT, new Integer(questionDTOs.size())); return (mapping.findForward("candidateAnswersAddList")); } protected boolean existsContent(long toolContentID, IMcService mcService) { - McContent mcContent = mcService.retrieveMc(new Long(toolContentID)); + McContent mcContent = mcService.getMcContent(new Long(toolContentID)); if (mcContent == null) { return false; } return true; } + + /** + * 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; + } } Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McAuthoringForm.java =================================================================== diff -u -rbe07c35c372d904a65581d98660e73f3b13b69db -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McAuthoringForm.java (.../McAuthoringForm.java) (revision be07c35c372d904a65581d98660e73f3b13b69db) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McAuthoringForm.java (.../McAuthoringForm.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -22,7 +22,6 @@ /* $$Id$$ */ package org.lamsfoundation.lams.tool.mc.web; -import org.apache.struts.upload.FormFile; import org.lamsfoundation.lams.tool.mc.McAppConstants; /** @@ -43,7 +42,6 @@ protected String editDefaultQuestion; protected String removeOptionContent; - protected String activeModule; protected String editOptionsMode; protected String showMarks; @@ -52,8 +50,6 @@ protected String randomize; protected String displayAnswers; - protected String defaultContentIdStr; - protected String addContent; protected String removeContent; protected String removeAllContent; @@ -107,7 +103,6 @@ protected String edit; private String contentFolderID; private String editableQuestionIndex; - private String defineLaterInEditMode; private String feedback; private String candidateIndex; private String totalMarks; @@ -776,21 +771,6 @@ } /** - * @return Returns the activeModule. - */ - public String getActiveModule() { - return activeModule; - } - - /** - * @param activeModule - * The activeModule to set. - */ - public void setActiveModule(String activeModule) { - this.activeModule = activeModule; - } - - /** * @return Returns the editOptionsMode. */ public String getEditOptionsMode() { @@ -851,21 +831,6 @@ } /** - * @return Returns the defaultContentIdStr. - */ - public String getDefaultContentIdStr() { - return defaultContentIdStr; - } - - /** - * @param defaultContentIdStr - * The defaultContentIdStr to set. - */ - public void setDefaultContentIdStr(String defaultContentIdStr) { - this.defaultContentIdStr = defaultContentIdStr; - } - - /** * @return Returns the editableQuestionIndex. */ public String getEditableQuestionIndex() { @@ -881,21 +846,6 @@ } /** - * @return Returns the defineLaterInEditMode. - */ - public String getDefineLaterInEditMode() { - return defineLaterInEditMode; - } - - /** - * @param defineLaterInEditMode - * The defineLaterInEditMode to set. - */ - public void setDefineLaterInEditMode(String defineLaterInEditMode) { - this.defineLaterInEditMode = defineLaterInEditMode; - } - - /** * @return Returns the feedback. */ public String getFeedback() { Fisheye: Tag 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f refers to a dead (removed) revision in file `lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McDLStarterAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McLearningAction.java =================================================================== diff -u -r007cc263f66ed201eb1f7585dcfc5d8f85f9329f -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McLearningAction.java (.../McLearningAction.java) (revision 007cc263f66ed201eb1f7585dcfc5d8f85f9329f) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McLearningAction.java (.../McLearningAction.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -120,11 +120,6 @@ String toolContentId = mcSession.getMcContent().getMcContentId().toString(); mcLearningForm.setToolContentID(toolContentId); - //setContentInUse - McContent mcContent = mcService.retrieveMc(new Long(toolContentId)); - mcContent.setContentInUse(true); - mcService.saveMcContent(mcContent); - LearningUtil.saveFormRequestData(request, mcLearningForm, false); if (mcLearningForm.getNextQuestionSelected() != null && !mcLearningForm.getNextQuestionSelected().equals("")) { @@ -303,7 +298,7 @@ McSession mcSession = mcService.getMcSessionById(new Long(toolSessionID)); String toolContentId = mcSession.getMcContent().getMcContentId().toString(); /* process the answers */ - McContent mcContent = mcService.retrieveMc(new Long(toolContentId)); + McContent mcContent = mcService.getMcContent(new Long(toolContentId)); McGeneralLearnerFlowDTO mcGeneralLearnerFlowDTO = LearningUtil.buildMcGeneralLearnerFlowDTO(mcContent); @@ -383,7 +378,7 @@ String toolSessionID = request.getParameter(AttributeNames.PARAM_TOOL_SESSION_ID); McSession mcSession = mcService.getMcSessionById(new Long(toolSessionID)); String toolContentId = mcSession.getMcContent().getMcContentId().toString(); - McContent mcContent = mcService.retrieveMc(new Long(toolContentId)); + McContent mcContent = mcService.getMcContent(new Long(toolContentId)); HttpSession ss = SessionManager.getSession(); UserDTO userDto = (UserDTO) ss.getAttribute(AttributeNames.USER); @@ -454,21 +449,72 @@ McSession mcSession = mcService.getMcSessionById(new Long(toolSessionID)); String toolContentId = mcSession.getMcContent().getMcContentId().toString(); - McContent mcContent = mcService.retrieveMc(new Long(toolContentId)); + McContent mcContent = mcService.getMcContent(new Long(toolContentId)); McGeneralLearnerFlowDTO mcGeneralLearnerFlowDTO = LearningUtil.buildMcGeneralLearnerFlowDTO(mcContent); + + Map mapQuestionsUidContent = new TreeMap(new McComparator()); + if (mcContent != null) { + List list = mcService.refreshQuestionContent(mcContent.getUid()); - Map mapQuestionsUidContent = AuthoringUtil.rebuildQuestionUidMapfromDB(request, new Long(toolContentId), - mcService); - - Map mapStartupGeneralOptionsContent = AuthoringUtil.rebuildStartupGeneralOptionsContentMapfromDB(request, - mapQuestionsUidContent, mcService); + Iterator listIterator = list.iterator(); + Long mapIndex = new Long(1); + while (listIterator.hasNext()) { + McQueContent mcQueContent = (McQueContent) listIterator.next(); + mapQuestionsUidContent.put(mapIndex.toString(), mcQueContent.getUid()); + mapIndex = new Long(mapIndex.longValue() + 1); + } + } + + //builds a map to hold all the candidate answers for all the questions by accessing the db + Map mapStartupGeneralOptionsContent = new TreeMap(new McComparator()); + Iterator itMap = mapQuestionsUidContent.entrySet().iterator(); + Long mapIndex = new Long(1); + while (itMap.hasNext()) { + Map.Entry pairs = (Map.Entry) itMap.next(); + String currentQuestionUid = pairs.getValue().toString(); + List listQuestionOptions = mcService.findOptionsByQuestionUid(new Long(currentQuestionUid)); + + //builds a questions map from questions list + Map mapOptsContent = new TreeMap(new McComparator()); + Iterator iter = listQuestionOptions.iterator(); + Long mapIndex2 = new Long(1); + while (iter.hasNext()) { + McOptsContent option = iter.next(); + mapOptsContent.put(mapIndex2.toString(), option.getMcQueOptionText()); + mapIndex2 = new Long(mapIndex2.longValue() + 1); + } + + mapStartupGeneralOptionsContent.put(mapIndex.toString(), mapOptsContent); + mapIndex = new Long(mapIndex.longValue() + 1); + } mcGeneralLearnerFlowDTO.setMapGeneralOptionsContent(mapStartupGeneralOptionsContent); - Map mapQuestionsContent = AuthoringUtil.rebuildQuestionMapfromDB(request, new Long(toolContentId), mcService); + //builds a map to hold question texts + Map mapQuestionsContent = new TreeMap(new McComparator()); + List list = mcService.refreshQuestionContent(mcContent.getUid()); + Iterator iter = list.iterator(); + Long mapIndex3 = new Long(1); + while (iter.hasNext()) { + McQueContent question = (McQueContent) iter.next(); + mapQuestionsContent.put(mapIndex3.toString(), question.getQuestion()); + mapIndex3 = new Long(mapIndex3.longValue() + 1); + } mcGeneralLearnerFlowDTO.setMapQuestionsContent(mapQuestionsContent); - Map mapFeedbackContent = AuthoringUtil.rebuildFeedbackMapfromDB(request, new Long(toolContentId), mcService); + //rebuildFeedbackMapfromDB + Map mapFeedbackContent = new TreeMap(new McComparator()); + List list2 = mcService.refreshQuestionContent(mcContent.getUid()); + Iterator iter2 = list2.iterator(); + Long mapIndex4 = new Long(1); + while (iter2.hasNext()) { + McQueContent question = (McQueContent) iter2.next(); + + String feedback = question.getFeedback(); + + mapFeedbackContent.put(mapIndex4.toString(), feedback); + mapIndex4 = new Long(mapIndex4.longValue() + 1); + } mcGeneralLearnerFlowDTO.setMapFeedbackContent(mapFeedbackContent); // Set up the user details. If this is the learner progress screen then we that id, @@ -562,7 +608,7 @@ String toolSessionID = request.getParameter(AttributeNames.PARAM_TOOL_SESSION_ID); McSession mcSession = mcService.getMcSessionById(new Long(toolSessionID)); String toolContentId = mcSession.getMcContent().getMcContentId().toString(); - McContent mcContent = mcService.retrieveMc(new Long(toolContentId)); + McContent mcContent = mcService.getMcContent(new Long(toolContentId)); McQueUsr mcQueUsr = getCurrentUser(toolSessionID); //clear sessionMap Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McLearningStarterAction.java =================================================================== diff -u -r007cc263f66ed201eb1f7585dcfc5d8f85f9329f -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McLearningStarterAction.java (.../McLearningStarterAction.java) (revision 007cc263f66ed201eb1f7585dcfc5d8f85f9329f) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McLearningStarterAction.java (.../McLearningStarterAction.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -207,9 +207,9 @@ mcGeneralLearnerFlowDTO.setShowMarks(showMarks.toString()); /* find out if the content is being modified at the moment. */ - boolean isDefineLater = McUtils.isDefineLater(mcContent); + boolean isDefineLater = mcContent.isDefineLater(); if (isDefineLater == true) { - return (mapping.findForward(McAppConstants.DEFINE_LATER)); + return (mapping.findForward("defineLater")); } McQueUsr groupLeader = null; Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McMonitoringAction.java =================================================================== diff -u -r007cc263f66ed201eb1f7585dcfc5d8f85f9329f -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McMonitoringAction.java (.../McMonitoringAction.java) (revision 007cc263f66ed201eb1f7585dcfc5d8f85f9329f) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McMonitoringAction.java (.../McMonitoringAction.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -24,10 +24,8 @@ import java.io.IOException; import java.io.OutputStream; -import java.util.ArrayList; import java.util.Date; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.TimeZone; @@ -40,29 +38,21 @@ import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; -import org.apache.struts.Globals; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; -import org.apache.struts.action.ActionMessage; -import org.apache.struts.action.ActionMessages; import org.lamsfoundation.lams.notebook.model.NotebookEntry; import org.lamsfoundation.lams.notebook.service.CoreNotebookConstants; import org.lamsfoundation.lams.tool.exception.ToolException; -import org.lamsfoundation.lams.tool.mc.EditActivityDTO; import org.lamsfoundation.lams.tool.mc.McAppConstants; -import org.lamsfoundation.lams.tool.mc.McCandidateAnswersDTO; import org.lamsfoundation.lams.tool.mc.McComparator; import org.lamsfoundation.lams.tool.mc.McGeneralAuthoringDTO; import org.lamsfoundation.lams.tool.mc.McGeneralLearnerFlowDTO; import org.lamsfoundation.lams.tool.mc.McGeneralMonitoringDTO; -import org.lamsfoundation.lams.tool.mc.McQuestionContentDTO; -import org.lamsfoundation.lams.tool.mc.McUtils; import org.lamsfoundation.lams.tool.mc.ReflectionDTO; import org.lamsfoundation.lams.tool.mc.pojos.McContent; import org.lamsfoundation.lams.tool.mc.pojos.McQueContent; import org.lamsfoundation.lams.tool.mc.pojos.McQueUsr; -import org.lamsfoundation.lams.tool.mc.pojos.McSession; import org.lamsfoundation.lams.tool.mc.pojos.McUsrAttempt; import org.lamsfoundation.lams.tool.mc.service.IMcService; import org.lamsfoundation.lams.tool.mc.service.McServiceProxy; @@ -72,7 +62,6 @@ import org.lamsfoundation.lams.web.action.LamsDispatchAction; import org.lamsfoundation.lams.web.session.SessionManager; import org.lamsfoundation.lams.web.util.AttributeNames; -import org.lamsfoundation.lams.web.util.SessionMap; /** * * @author Ozgur Demirtas @@ -90,25 +79,28 @@ } /** - * + * displayAnswers */ - protected ActionForward commonSubmitSessionCode(McMonitoringForm mcMonitoringForm, HttpServletRequest request, - ActionMapping mapping, IMcService mcService, McGeneralMonitoringDTO mcGeneralMonitoringDTO) - throws IOException, ServletException { + public ActionForward displayAnswers(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws IOException, ServletException { + IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); + String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); + McContent mcContent = mcService.getMcContent(new Long(strToolContentID)); + mcContent.setDisplayAnswers(new Boolean(true)); + + McMonitoringForm mcMonitoringForm = (McMonitoringForm) form; + McGeneralMonitoringDTO mcGeneralMonitoringDTO = new McGeneralMonitoringDTO(); repopulateRequestParameters(request, mcMonitoringForm, mcGeneralMonitoringDTO); String toolContentID = mcMonitoringForm.getToolContentID(); - McContent mcContent = mcService.retrieveMc(new Long(toolContentID)); - // generate DTO for All sessions MonitoringUtil.setupAllSessionsData(request, mcContent, mcService); - mcGeneralMonitoringDTO.setSbmtSuccess(new Boolean(false).toString()); mcGeneralMonitoringDTO.setRequestLearningReport(new Boolean(false).toString()); - mcGeneralMonitoringDTO.setSummaryToolSessions(populateToolSessions(mcContent)); + mcGeneralMonitoringDTO.setSummaryToolSessions(MonitoringUtil.populateToolSessions(mcContent)); mcGeneralMonitoringDTO.setDisplayAnswers(new Boolean(mcContent.isDisplayAnswers()).toString()); /* setting editable screen properties */ @@ -128,13 +120,6 @@ } } - boolean isContentInUse = McUtils.isContentInUse(mcContent); - mcGeneralMonitoringDTO.setIsMonitoredContentInUse(new Boolean(false).toString()); - if (isContentInUse == true) { - // monitoring url does not allow editActivity since the content is in use - mcGeneralMonitoringDTO.setIsMonitoredContentInUse(new Boolean(true).toString()); - } - request.setAttribute(MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); List reflectionsContainerDTO = mcService.getReflectionList(mcContent, null); @@ -150,12 +135,6 @@ request.setAttribute(MC_GENERAL_MONITORING_DTO, mcGeneralMonitoringDTO); - EditActivityDTO editActivityDTO = new EditActivityDTO(); - if (isContentInUse == true) { - editActivityDTO.setMonitoredContentInUse(new Boolean(true).toString()); - } - request.setAttribute(EDIT_ACTIVITY_DTO, editActivityDTO); - if (!reflectionsContainerDTO.isEmpty()) { request.setAttribute(NOTEBOOK_ENTRIES_EXIST, new Boolean(true).toString()); @@ -173,2292 +152,9 @@ MonitoringUtil.setSessionUserCount(mcContent, mcGeneralMonitoringDTO); return (mapping.findForward(LOAD_MONITORING_CONTENT)); - } /** - * Populates a sorted map of the tool session where the key is the mcSessionId and the value is name of the session. - * If no sessions exists, there will be a single entry "None", otherwise on the end of the list will be the entry - * "All" - */ - public static Map populateToolSessions(McContent mcContent) { - Map sessionsMap = new TreeMap(); - Iterator iter = mcContent.getMcSessions().iterator(); - while (iter.hasNext()) { - McSession elem = (McSession) iter.next(); - sessionsMap.put(elem.getMcSessionId().toString(), elem.getSession_name()); - } - - if (sessionsMap.isEmpty()) { - sessionsMap.put("None", "None"); - } else { - sessionsMap.put("All", "All"); - } - - return sessionsMap; - - } - - /** - * - * submitSession - */ - public ActionForward submitSession(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException { - IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - McContent mcContent = mcService.retrieveMc(new Long(strToolContentID)); - mcContent.setDisplayAnswers(new Boolean(true)); - return commonSubmitSessionCode((McMonitoringForm) form, request, mapping, mcService, - new McGeneralMonitoringDTO()); - } - - /** - * displayAnswers - */ - public ActionForward displayAnswers(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException { - IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - McContent mcContent = mcService.retrieveMc(new Long(strToolContentID)); - mcContent.setDisplayAnswers(new Boolean(true)); - return commonSubmitSessionCode((McMonitoringForm) form, request, mapping, mcService, - new McGeneralMonitoringDTO()); - } - - /** - * enables swiching to editable mode in the Edit Activity tab - */ - public ActionForward editActivityQuestions(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException, ToolException { - - McAuthoringForm mcAuthoringForm = (McMonitoringForm) form; - - IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); - - String httpSessionID = mcAuthoringForm.getHttpSessionID(); - - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - mcAuthoringForm.setContentFolderID(contentFolderID); - - String activeModule = request.getParameter(ACTIVE_MODULE); - - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(MY_SIGNATURE)).toString(); - // String defaultContentIdStr=request.getParameter(DEFAULT_CONTENT_ID_STR); - - McContent mcContent = mcService.retrieveMc(new Long(strToolContentID)); - - McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); - mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); - - mcGeneralAuthoringDTO.setActivityTitle(mcContent.getTitle()); - mcAuthoringForm.setTitle(mcContent.getTitle()); - - mcGeneralAuthoringDTO.setActivityInstructions(mcContent.getInstructions()); - - mcAuthoringForm.setDefineLaterInEditMode(new Boolean(true).toString()); - mcGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - boolean isContentInUse = McUtils.isContentInUse(mcContent); - - mcGeneralAuthoringDTO.setMonitoredContentInUse(new Boolean(false).toString()); - if (isContentInUse == true) { - // monitoring url does not allow editActivity since the content is in use - ActionMessages errors = new ActionMessages(); - errors.add(Globals.ERROR_KEY, new ActionMessage("error.content.inUse")); - saveErrors(request, errors); - mcGeneralAuthoringDTO.setMonitoredContentInUse(new Boolean(true).toString()); - } - - EditActivityDTO editActivityDTO = new EditActivityDTO(); - if (isContentInUse == true) { - editActivityDTO.setMonitoredContentInUse(new Boolean(true).toString()); - } - request.setAttribute(EDIT_ACTIVITY_DTO, editActivityDTO); - - McUtils.setDefineLater(request, true, strToolContentID, mcService); - - McUtils.setFormProperties(request, mcService, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); - - mcGeneralAuthoringDTO.setToolContentID(strToolContentID); - mcGeneralAuthoringDTO.setActiveModule(activeModule); - mcGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); - mcAuthoringForm.setToolContentID(strToolContentID); - mcAuthoringForm.setActiveModule(activeModule); - mcAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); - mcAuthoringForm.setCurrentTab("3"); - - AuthoringUtil authoringUtil = new AuthoringUtil(); - List listQuestionContentDTO = authoringUtil.buildDefaultQuestionContent(mcContent, mcService); - - request.setAttribute(TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); - request.setAttribute(LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - sessionMap.put(LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - - request.setAttribute(TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); - request.getSession().setAttribute(httpSessionID, sessionMap); - - Map marksMap = authoringUtil.buildMarksMap(); - mcGeneralAuthoringDTO.setMarksMap(marksMap); - - Map correctMap = authoringUtil.buildCorrectMap(); - mcGeneralAuthoringDTO.setCorrectMap(correctMap); - - request.setAttribute(MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - - /* setting up USER_EXCEPTION_NO_TOOL_SESSIONS, from here */ - McGeneralMonitoringDTO mcGeneralMonitoringDTO = new McGeneralMonitoringDTO(); - mcGeneralMonitoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - if (mcService.studentActivityOccurredGlobal(mcContent)) { - mcGeneralMonitoringDTO.setUserExceptionNoToolSessions(new Boolean(false).toString()); - } else { - mcGeneralMonitoringDTO.setUserExceptionNoToolSessions(new Boolean(true).toString()); - } - - request.setAttribute(MC_GENERAL_MONITORING_DTO, mcGeneralMonitoringDTO); - /* .. till here */ - - /* find out if there are any reflection entries, from here */ - boolean notebookEntriesExist = MonitoringUtil.notebookEntriesExist(mcService, mcContent); - - if (notebookEntriesExist) { - request.setAttribute(NOTEBOOK_ENTRIES_EXIST, new Boolean(true).toString()); - - String userExceptionNoToolSessions = (String) mcGeneralMonitoringDTO.getUserExceptionNoToolSessions(); - - if (userExceptionNoToolSessions.equals("true")) { - // there are no online student activity but there are reflections - request.setAttribute(NO_SESSIONS_NOTEBOOK_ENTRIES_EXIST, new Boolean(true).toString()); - } - } else { - request.setAttribute(NOTEBOOK_ENTRIES_EXIST, new Boolean(false).toString()); - } - /* ... till here */ - MonitoringUtil.setSessionUserCount(mcContent, mcGeneralMonitoringDTO); - - List listAllGroupsDTO = MonitoringUtil.buildGroupBasedSessionData(mcContent, mcService); - request.setAttribute(LIST_ALL_GROUPS_DTO, listAllGroupsDTO); - - MonitoringUtil.setupAllSessionsData(request, mcContent, mcService); - - return mapping.findForward(LOAD_MONITORING_CONTENT); - } - - /** - * - submits content into the tool database - */ - public ActionForward submitAllContent(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException { - - McAuthoringForm mcAuthoringForm = (McMonitoringForm) form; - - IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); - - String httpSessionID = mcAuthoringForm.getHttpSessionID(); - - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - mcAuthoringForm.setContentFolderID(contentFolderID); - - String activeModule = request.getParameter(ACTIVE_MODULE); - - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - - String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(MY_SIGNATURE)).toString(); - - List listQuestionContentDTO = (List) sessionMap.get(LIST_QUESTION_CONTENT_DTO_KEY); - - Map mapQuestionContent = AuthoringUtil.extractMapQuestionContent(listQuestionContentDTO); - - Map mapFeedback = AuthoringUtil.extractMapFeedback(listQuestionContentDTO); - - Map mapWeights = new TreeMap(new McComparator()); - - Map mapMarks = AuthoringUtil.extractMapMarks(listQuestionContentDTO); - - Map mapCandidatesList = AuthoringUtil.extractMapCandidatesList(listQuestionContentDTO); - - ActionMessages errors = new ActionMessages(); - - if (mapQuestionContent.size() == 0) { - ActionMessage error = new ActionMessage("questions.none.submitted"); - errors.add(ActionMessages.GLOBAL_MESSAGE, error); - } - - AuthoringUtil authoringUtil = new AuthoringUtil(); - - McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); - - mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); - - String richTextTitle = request.getParameter(TITLE); - String richTextInstructions = request.getParameter(INSTRUCTIONS); - - mcGeneralAuthoringDTO.setActivityTitle(richTextTitle); - mcAuthoringForm.setTitle(richTextTitle); - - mcGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - - sessionMap.put(ACTIVITY_TITLE_KEY, richTextTitle); - sessionMap.put(ACTIVITY_INSTRUCTIONS_KEY, richTextInstructions); - - mcGeneralAuthoringDTO.setMapQuestionContent(mapQuestionContent); - request.setAttribute(MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - - McContent mcContentTest = mcService.retrieveMc(new Long(strToolContentID)); - if (!errors.isEmpty()) { - saveErrors(request, errors); - logger.debug("errors saved: " + errors); - } - - McGeneralMonitoringDTO mcGeneralMonitoringDTO = new McGeneralMonitoringDTO(); - - McContent mcContent = mcContentTest; - if (errors.isEmpty()) { - authoringUtil.removeRedundantQuestions(mapQuestionContent, mcService, mcAuthoringForm, request, - strToolContentID); - - mcContent = authoringUtil.saveOrUpdateMcContent(mapQuestionContent, mapFeedback, mapWeights, mapMarks, - mapCandidatesList, mcService, mcAuthoringForm, request, mcContentTest, strToolContentID); - - long defaultContentID = 0; - defaultContentID = mcService.getToolDefaultContentIdBySignature(MY_SIGNATURE); - - if (mcContent != null) { - mcGeneralAuthoringDTO.setDefaultContentIdStr(new Long(defaultContentID).toString()); - } - - authoringUtil.reOrganizeDisplayOrder(mapQuestionContent, mcService, mcAuthoringForm, mcContent); - - McUtils.setDefineLater(request, false, strToolContentID, mcService); - // define later set to false - - McUtils.setFormProperties(request, mcService, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); - - // go back to view only screen - mcGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(false).toString()); - mcGeneralMonitoringDTO.setDefineLaterInEditMode(new Boolean(false).toString()); - } else { - // errors is not empty - - if (mcContent != null) { - long defaultContentID = 0; - defaultContentID = mcService.getToolDefaultContentIdBySignature(MY_SIGNATURE); - - if (mcContent != null) { - mcGeneralAuthoringDTO.setDefaultContentIdStr(new Long(defaultContentID).toString()); - } - - McUtils.setFormProperties(request, mcService, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); - - mcGeneralMonitoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - } - } - request.setAttribute(MC_GENERAL_MONITORING_DTO, mcGeneralMonitoringDTO); - - mcGeneralAuthoringDTO.setSbmtSuccess(new Integer(1).toString()); - - mcAuthoringForm.resetUserAction(); - mcGeneralAuthoringDTO.setMapQuestionContent(mapQuestionContent); - - Map marksMap = authoringUtil.buildMarksMap(); - mcGeneralAuthoringDTO.setMarksMap(marksMap); - - Map correctMap = authoringUtil.buildCorrectMap(); - mcGeneralAuthoringDTO.setCorrectMap(correctMap); - - request.setAttribute(LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - sessionMap.put(LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - request.getSession().setAttribute(httpSessionID, sessionMap); - - request.setAttribute(TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); - - Map passMarksMap = authoringUtil.buildDynamicPassMarkMap(listQuestionContentDTO, false); - mcGeneralAuthoringDTO.setPassMarksMap(passMarksMap); - - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTO); - mcAuthoringForm.setTotalMarks(totalMark); - mcGeneralAuthoringDTO.setTotalMarks(totalMark); - - request.setAttribute(MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - - mcGeneralAuthoringDTO.setToolContentID(strToolContentID); - mcGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - mcGeneralAuthoringDTO.setActiveModule(activeModule); - mcGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); - - mcAuthoringForm.setToolContentID(strToolContentID); - mcAuthoringForm.setHttpSessionID(httpSessionID); - mcAuthoringForm.setActiveModule(activeModule); - mcAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); - mcAuthoringForm.setCurrentTab("3"); - - /* common screen data */ - if (mcService.studentActivityOccurredGlobal(mcContent)) { - mcGeneralMonitoringDTO.setUserExceptionNoToolSessions(new Boolean(false).toString()); - } else { - mcGeneralMonitoringDTO.setUserExceptionNoToolSessions(new Boolean(true).toString()); - } - - /* find out if there are any reflection entries, from here */ - boolean notebookEntriesExist = MonitoringUtil.notebookEntriesExist(mcService, mcContent); - - if (notebookEntriesExist) { - request.setAttribute(NOTEBOOK_ENTRIES_EXIST, new Boolean(true).toString()); - - String userExceptionNoToolSessions = (String) mcGeneralMonitoringDTO.getUserExceptionNoToolSessions(); - - if (userExceptionNoToolSessions.equals("true")) { - // there are no online student activity but there are reflections - request.setAttribute(NO_SESSIONS_NOTEBOOK_ENTRIES_EXIST, new Boolean(true).toString()); - } - } else { - request.setAttribute(NOTEBOOK_ENTRIES_EXIST, new Boolean(false).toString()); - } - /* ... till here */ - MonitoringUtil.setSessionUserCount(mcContent, mcGeneralMonitoringDTO); - List listAllGroupsDTO = MonitoringUtil.buildGroupBasedSessionData(mcContent, mcService); - request.setAttribute(LIST_ALL_GROUPS_DTO, listAllGroupsDTO); - - MonitoringUtil.setupAllSessionsData(request, mcContent, mcService); - - return mapping.findForward(LOAD_MONITORING); - } - - /** - * - */ - public ActionForward saveSingleQuestion(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException { - - McAuthoringForm mcAuthoringForm = (McMonitoringForm) form; - - IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); - String httpSessionID = mcAuthoringForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - mcAuthoringForm.setContentFolderID(contentFolderID); - - String activeModule = request.getParameter(ACTIVE_MODULE); - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(MY_SIGNATURE)).toString(); - ; - String editQuestionBoxRequest = request.getParameter("editQuestionBoxRequest"); - String totalMarks = request.getParameter("totalMarks"); - String mark = request.getParameter("mark"); - String passmark = request.getParameter("passmark"); - - AuthoringUtil authoringUtil = new AuthoringUtil(); - List caList = authoringUtil.repopulateCandidateAnswersBox(request, false); - - caList = AuthoringUtil.removeBlankEntries(caList); - - boolean validateSingleCorrectCandidate = authoringUtil.validateSingleCorrectCandidate(caList); - - ActionMessages errors = new ActionMessages(); - - if (!validateSingleCorrectCandidate) { - ActionMessage error = new ActionMessage("candidates.none.correct"); - errors.add(ActionMessages.GLOBAL_MESSAGE, error); - } - - if (!errors.isEmpty()) { - saveErrors(request, errors); - logger.debug("errors saved: " + errors); - } - - List listQuestionContentDTO = (List) sessionMap.get(LIST_QUESTION_CONTENT_DTO_KEY); - - McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); - - mcGeneralAuthoringDTO.setMarkValue(mark); - mcGeneralAuthoringDTO.setPassMarkValue(passmark); - - McContent mcContent = mcService.retrieveMc(new Long(strToolContentID)); - - if (errors.isEmpty()) { - // errors is empty - mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); - - mcGeneralAuthoringDTO.setSbmtSuccess(new Integer(0).toString()); - - String newQuestion = request.getParameter("newQuestion"); - String feedback = request.getParameter("feedback"); - - String editableQuestionIndex = request.getParameter("editableQuestionIndex"); - mcAuthoringForm.setQuestionIndex(editableQuestionIndex); - - if ((newQuestion != null) && (newQuestion.length() > 0)) { - if ((editQuestionBoxRequest != null) && (editQuestionBoxRequest.equals("false"))) { - boolean duplicates = AuthoringUtil.checkDuplicateQuestions(listQuestionContentDTO, newQuestion); - if (!duplicates) { - McQuestionContentDTO mcQuestionContentDTO = null; - Iterator listIterator = listQuestionContentDTO.iterator(); - while (listIterator.hasNext()) { - mcQuestionContentDTO = (McQuestionContentDTO) listIterator.next(); - - String question = mcQuestionContentDTO.getQuestion(); - String displayOrder = mcQuestionContentDTO.getDisplayOrder(); - - if ((displayOrder != null) && (!displayOrder.equals(""))) { - if (displayOrder.equals(editableQuestionIndex)) { - break; - } - - } - } - - mcQuestionContentDTO.setQuestion(newQuestion); - mcQuestionContentDTO.setFeedback(feedback); - mcQuestionContentDTO.setDisplayOrder(editableQuestionIndex); - mcQuestionContentDTO.setListCandidateAnswersDTO(caList); - mcQuestionContentDTO.setMark(mark); - - mcQuestionContentDTO.setCaCount(new Integer(mcQuestionContentDTO.getListCandidateAnswersDTO() - .size()).toString()); - - listQuestionContentDTO = AuthoringUtil.reorderUpdateListQuestionContentDTO( - listQuestionContentDTO, mcQuestionContentDTO, editableQuestionIndex); - } else { - // duplicate question entry, not adding - } - } else { - // request for edit and save - McQuestionContentDTO mcQuestionContentDTO = null; - Iterator listIterator = listQuestionContentDTO.iterator(); - while (listIterator.hasNext()) { - mcQuestionContentDTO = (McQuestionContentDTO) listIterator.next(); - - String question = mcQuestionContentDTO.getQuestion(); - String displayOrder = mcQuestionContentDTO.getDisplayOrder(); - - if ((displayOrder != null) && (!displayOrder.equals(""))) { - if (displayOrder.equals(editableQuestionIndex)) { - break; - } - - } - } - - mcQuestionContentDTO.setQuestion(newQuestion); - mcQuestionContentDTO.setFeedback(feedback); - mcQuestionContentDTO.setDisplayOrder(editableQuestionIndex); - mcQuestionContentDTO.setListCandidateAnswersDTO(caList); - mcQuestionContentDTO.setMark(mark); - - mcQuestionContentDTO.setCaCount(new Integer(mcQuestionContentDTO.getListCandidateAnswersDTO() - .size()).toString()); - - listQuestionContentDTO = AuthoringUtil.reorderUpdateListQuestionContentDTO(listQuestionContentDTO, - mcQuestionContentDTO, editableQuestionIndex); - } - } else { - // entry blank, not adding - } - - mcGeneralAuthoringDTO.setMarkValue(mark); - - request.setAttribute(LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - sessionMap.put(LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - - commonSaveCode(request, mcGeneralAuthoringDTO, mcAuthoringForm, sessionMap, activeModule, strToolContentID, - defaultContentIdStr, mcService, httpSessionID, listQuestionContentDTO); - - request.setAttribute(TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); - - setupCommonScreenData(mcContent, mcService, request); - MonitoringUtil.setupAllSessionsData(request, mcContent, mcService); - - return (mapping.findForward(LOAD_MONITORING)); - } else { - // errors is not empty - commonSaveCode(request, mcGeneralAuthoringDTO, mcAuthoringForm, sessionMap, activeModule, strToolContentID, - defaultContentIdStr, mcService, httpSessionID, listQuestionContentDTO); - - Map passMarksMap = authoringUtil.buildDynamicPassMarkMap(listQuestionContentDTO, false); - mcGeneralAuthoringDTO.setPassMarksMap(passMarksMap); - - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTO); - mcAuthoringForm.setTotalMarks(totalMark); - mcGeneralAuthoringDTO.setTotalMarks(totalMark); - - request.setAttribute(MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - - request.setAttribute(LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - sessionMap.put(LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - - setupCommonScreenData(mcContent, mcService, request); - MonitoringUtil.setupAllSessionsData(request, mcContent, mcService); - - request.setAttribute("requestNewEditableQuestionBox", new Boolean(true).toString()); - - return newEditableQuestionBox(mapping, form, request, response); - } - - } - - /** - * - */ - protected void commonSaveCode(HttpServletRequest request, McGeneralAuthoringDTO mcGeneralAuthoringDTO, - McAuthoringForm mcAuthoringForm, SessionMap sessionMap, String activeModule, String strToolContentID, - String defaultContentIdStr, IMcService mcService, String httpSessionID, List listQuestionContentDTO) { - String richTextTitle = request.getParameter(TITLE); - String richTextInstructions = request.getParameter(INSTRUCTIONS); - - mcGeneralAuthoringDTO.setActivityTitle(richTextTitle); - mcAuthoringForm.setTitle(richTextTitle); - - mcGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - - sessionMap.put(ACTIVITY_TITLE_KEY, richTextTitle); - sessionMap.put(ACTIVITY_INSTRUCTIONS_KEY, richTextInstructions); - - mcGeneralAuthoringDTO.setEditActivityEditMode(new Boolean(true).toString()); - - request.getSession().setAttribute(httpSessionID, sessionMap); - sessionMap.put(LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - - McUtils.setFormProperties(request, mcService, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); - - mcGeneralAuthoringDTO.setToolContentID(strToolContentID); - mcGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - mcGeneralAuthoringDTO.setActiveModule(activeModule); - mcGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); - - mcAuthoringForm.setToolContentID(strToolContentID); - mcAuthoringForm.setHttpSessionID(httpSessionID); - mcAuthoringForm.setActiveModule(activeModule); - mcAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); - mcAuthoringForm.setCurrentTab("3"); - - mcGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - AuthoringUtil authoringUtil = new AuthoringUtil(); - Map marksMap = authoringUtil.buildMarksMap(); - mcGeneralAuthoringDTO.setMarksMap(marksMap); - - Map passMarksMap = authoringUtil.buildDynamicPassMarkMap(listQuestionContentDTO, false); - mcGeneralAuthoringDTO.setPassMarksMap(passMarksMap); - - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTO); - mcAuthoringForm.setTotalMarks(totalMark); - mcGeneralAuthoringDTO.setTotalMarks(totalMark); - - Map correctMap = authoringUtil.buildCorrectMap(); - mcGeneralAuthoringDTO.setCorrectMap(correctMap); - - request.setAttribute(MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - - request.getSession().setAttribute(httpSessionID, sessionMap); - } - - /** - * - */ - public ActionForward addSingleQuestion(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException { - - McAuthoringForm mcAuthoringForm = (McMonitoringForm) form; - - IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); - String httpSessionID = mcAuthoringForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - mcAuthoringForm.setContentFolderID(contentFolderID); - - String activeModule = request.getParameter(ACTIVE_MODULE); - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(MY_SIGNATURE)).toString(); - McContent mcContent = mcService.retrieveMc(new Long(strToolContentID)); - McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); - mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); - - mcGeneralAuthoringDTO.setSbmtSuccess(new Integer(0).toString()); - - AuthoringUtil authoringUtil = new AuthoringUtil(); - - List listQuestionContentDTO = (List) sessionMap.get(LIST_QUESTION_CONTENT_DTO_KEY); - List listAddableQuestionContentDTO = (List) sessionMap.get(NEW_ADDABLE_QUESTION_CONTENT_KEY); - - int listSize = listQuestionContentDTO.size(); - request.setAttribute(NEW_ADDABLE_QUESTION_CONTENT_LIST, listAddableQuestionContentDTO); - - String newQuestion = request.getParameter("newQuestion"); - String feedback = request.getParameter("feedback"); - String mark = request.getParameter("mark"); - mcGeneralAuthoringDTO.setMarkValue(mark); - - String passmark = request.getParameter("passmark"); - mcGeneralAuthoringDTO.setPassMarkValue(passmark); - - List caList = authoringUtil.repopulateCandidateAnswersBox(request, false); - caList = AuthoringUtil.removeBlankEntries(caList); - - boolean validateSingleCorrectCandidate = authoringUtil.validateSingleCorrectCandidate(caList); - - ActionMessages errors = new ActionMessages(); - - if (!validateSingleCorrectCandidate) { - ActionMessage error = new ActionMessage("candidates.none.correct"); - errors.add(ActionMessages.GLOBAL_MESSAGE, error); - } - - if (!errors.isEmpty()) { - saveErrors(request, errors); - logger.debug("errors saved: " + errors); - } - - if (errors.isEmpty()) { - if ((newQuestion != null) && (newQuestion.length() > 0)) { - boolean duplicates = AuthoringUtil.checkDuplicateQuestions(listQuestionContentDTO, newQuestion); - - if (!duplicates) { - McQuestionContentDTO mcQuestionContentDTO = new McQuestionContentDTO(); - mcQuestionContentDTO.setDisplayOrder(new Long(listSize + 1).toString()); - mcQuestionContentDTO.setFeedback(feedback); - mcQuestionContentDTO.setQuestion(newQuestion); - mcQuestionContentDTO.setMark(mark); - - mcQuestionContentDTO.setListCandidateAnswersDTO(caList); - mcQuestionContentDTO.setCaCount(new Integer(mcQuestionContentDTO.getListCandidateAnswersDTO() - .size()).toString()); - - listQuestionContentDTO.add(mcQuestionContentDTO); - } else { - // entry duplicate, not adding - } - } else { - // entry blank, not adding - } - } else { - // errors, not adding - - commonSaveCode(request, mcGeneralAuthoringDTO, mcAuthoringForm, sessionMap, activeModule, strToolContentID, - defaultContentIdStr, mcService, httpSessionID, listQuestionContentDTO); - - Map passMarksMap = authoringUtil.buildDynamicPassMarkMap(listQuestionContentDTO, false); - mcGeneralAuthoringDTO.setPassMarksMap(passMarksMap); - - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTO); - mcAuthoringForm.setTotalMarks(totalMark); - mcGeneralAuthoringDTO.setTotalMarks(totalMark); - - request.setAttribute(MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - - request.setAttribute(LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - sessionMap.put(LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - return newQuestionBox(mapping, form, request, response); - } - mcGeneralAuthoringDTO.setMarkValue(mark); - - Map passMarksMap = authoringUtil.buildDynamicPassMarkMap(listQuestionContentDTO, false); - mcGeneralAuthoringDTO.setPassMarksMap(passMarksMap); - - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTO); - mcAuthoringForm.setTotalMarks(totalMark); - mcGeneralAuthoringDTO.setTotalMarks(totalMark); - mcGeneralAuthoringDTO.setEditableQuestionText(newQuestion); - mcAuthoringForm.setFeedback(feedback); - - mcGeneralAuthoringDTO.setMarkValue(mark); - - request.setAttribute(MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - - request.setAttribute(LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - sessionMap.put(LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - - commonSaveCode(request, mcGeneralAuthoringDTO, mcAuthoringForm, sessionMap, activeModule, strToolContentID, - defaultContentIdStr, mcService, httpSessionID, listQuestionContentDTO); - - request.setAttribute(TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); - - setupCommonScreenData(mcContent, mcService, request); - - MonitoringUtil.setupAllSessionsData(request, mcContent, mcService); - - return (mapping.findForward(LOAD_MONITORING)); - } - - /** - * opens up an new screen within the current page for adding a new question - */ - public ActionForward newQuestionBox(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException { - McAuthoringForm mcAuthoringForm = (McMonitoringForm) form; - - IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); - - String httpSessionID = mcAuthoringForm.getHttpSessionID(); - - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - mcAuthoringForm.setContentFolderID(contentFolderID); - - String activeModule = request.getParameter(ACTIVE_MODULE); - - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - - String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(MY_SIGNATURE)).toString(); - - /* create default mcContent object */ - McContent mcContent = mcService.retrieveMc(new Long(defaultContentIdStr)); - - McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); - mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); - - String richTextTitle = request.getParameter(TITLE); - String richTextInstructions = request.getParameter(INSTRUCTIONS); - - mcGeneralAuthoringDTO.setActivityTitle(richTextTitle); - mcAuthoringForm.setTitle(richTextTitle); - - mcGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - - McUtils.setFormProperties(request, mcService, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); - - mcGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - AuthoringUtil authoringUtil = new AuthoringUtil(); - Map marksMap = authoringUtil.buildMarksMap(); - mcGeneralAuthoringDTO.setMarksMap(marksMap); - - List listQuestionContentDTO = (List) sessionMap.get(LIST_QUESTION_CONTENT_DTO_KEY); - - Map correctMap = authoringUtil.buildCorrectMap(); - mcGeneralAuthoringDTO.setCorrectMap(correctMap); - - request.setAttribute(MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - - String requestType = request.getParameter("requestType"); - - List listAddableQuestionContentDTO = (List) sessionMap.get(NEW_ADDABLE_QUESTION_CONTENT_KEY); - if ((requestType != null) && (requestType.equals("direct"))) { - // requestType is direct - listAddableQuestionContentDTO = authoringUtil.buildDefaultQuestionContent(mcContent, mcService); - } - - request.setAttribute(NEW_ADDABLE_QUESTION_CONTENT_LIST, listAddableQuestionContentDTO); - sessionMap.put(NEW_ADDABLE_QUESTION_CONTENT_KEY, listAddableQuestionContentDTO); - - request.setAttribute(TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); - Map passMarksMap = authoringUtil.buildDynamicPassMarkMap(listQuestionContentDTO, false); - mcGeneralAuthoringDTO.setPassMarksMap(passMarksMap); - String newQuestion = request.getParameter("newQuestion"); - mcGeneralAuthoringDTO.setEditableQuestionText(newQuestion); - - String feedback = request.getParameter("feedback"); - mcAuthoringForm.setFeedback(feedback); - - String mark = request.getParameter("mark"); - mcGeneralAuthoringDTO.setMarkValue(mark); - - request.setAttribute(MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTO); - mcAuthoringForm.setTotalMarks(totalMark); - mcGeneralAuthoringDTO.setTotalMarks(totalMark); - - request.setAttribute(LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - - mcGeneralAuthoringDTO.setToolContentID(strToolContentID); - mcGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - mcGeneralAuthoringDTO.setActiveModule(activeModule); - mcGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); - - mcAuthoringForm.setToolContentID(strToolContentID); - mcAuthoringForm.setHttpSessionID(httpSessionID); - mcAuthoringForm.setActiveModule(activeModule); - mcAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); - - setupCommonScreenData(mcContent, mcService, request); - - MonitoringUtil.setupAllSessionsData(request, mcContent, mcService); - return (mapping.findForward("newQuestionBox")); - } - - /** - * opens up an new screen within the current page for editing a question - */ - public ActionForward newEditableQuestionBox(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException { - McAuthoringForm mcAuthoringForm = (McMonitoringForm) form; - - IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); - - String httpSessionID = mcAuthoringForm.getHttpSessionID(); - - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - - String questionIndex = request.getParameter("questionIndex"); - mcAuthoringForm.setQuestionIndex(questionIndex); - - request.setAttribute(CURRENT_EDITABLE_QUESTION_INDEX, questionIndex); - - mcAuthoringForm.setEditableQuestionIndex(questionIndex); - - List listQuestionContentDTO = (List) sessionMap.get(LIST_QUESTION_CONTENT_DTO_KEY); - - String editableQuestion = ""; - String editableFeedback = ""; - String editableMark = ""; - Iterator listIterator = listQuestionContentDTO.iterator(); - while (listIterator.hasNext()) { - McQuestionContentDTO mcQuestionContentDTO = (McQuestionContentDTO) listIterator.next(); - String question = mcQuestionContentDTO.getQuestion(); - String displayOrder = mcQuestionContentDTO.getDisplayOrder(); - - if ((displayOrder != null) && (!displayOrder.equals(""))) { - if (displayOrder.equals(questionIndex)) { - editableFeedback = mcQuestionContentDTO.getFeedback(); - editableQuestion = mcQuestionContentDTO.getQuestion(); - editableMark = mcQuestionContentDTO.getMark(); - - List candidates = mcQuestionContentDTO.getListCandidateAnswersDTO(); - - break; - } - - } - } - - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - mcAuthoringForm.setContentFolderID(contentFolderID); - - String activeModule = request.getParameter(ACTIVE_MODULE); - - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - - String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(MY_SIGNATURE)).toString(); - ; - - McContent mcContent = mcService.retrieveMc(new Long(strToolContentID)); - - McGeneralAuthoringDTO mcGeneralAuthoringDTO = (McGeneralAuthoringDTO) request - .getAttribute(MC_GENERAL_AUTHORING_DTO); - - if (mcGeneralAuthoringDTO == null) - mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); - - mcGeneralAuthoringDTO.setMarkValue(editableMark); - - mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); - - String richTextTitle = request.getParameter(TITLE); - String richTextInstructions = request.getParameter(INSTRUCTIONS); - - mcGeneralAuthoringDTO.setActivityTitle(richTextTitle); - mcAuthoringForm.setTitle(richTextTitle); - - mcGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - - McUtils.setFormProperties(request, mcService, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); - - mcGeneralAuthoringDTO.setEditableQuestionText(editableQuestion); - mcGeneralAuthoringDTO.setEditableQuestionFeedback(editableFeedback); - mcAuthoringForm.setFeedback(editableFeedback); - - mcGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - AuthoringUtil authoringUtil = new AuthoringUtil(); - Map marksMap = authoringUtil.buildMarksMap(); - mcGeneralAuthoringDTO.setMarksMap(marksMap); - - Map correctMap = authoringUtil.buildCorrectMap(); - mcGeneralAuthoringDTO.setCorrectMap(correctMap); - - request.setAttribute(MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - - request.setAttribute(TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); - - Map passMarksMap = authoringUtil.buildDynamicPassMarkMap(listQuestionContentDTO, false); - mcGeneralAuthoringDTO.setPassMarksMap(passMarksMap); - - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTO); - mcAuthoringForm.setTotalMarks(totalMark); - mcGeneralAuthoringDTO.setTotalMarks(totalMark); - - String requestNewEditableQuestionBox = (String) request.getAttribute("requestNewEditableQuestionBox"); - - String newQuestion = request.getParameter("newQuestion"); - - if ((requestNewEditableQuestionBox != null) && requestNewEditableQuestionBox.equals("true")) { - mcGeneralAuthoringDTO.setEditableQuestionText(newQuestion); - - String feedback = request.getParameter("feedback"); - mcAuthoringForm.setFeedback(feedback); - } - - request.setAttribute(MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - request.setAttribute(LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - - mcGeneralAuthoringDTO.setToolContentID(strToolContentID); - mcGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - mcGeneralAuthoringDTO.setActiveModule(activeModule); - mcGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); - - mcAuthoringForm.setToolContentID(strToolContentID); - mcAuthoringForm.setHttpSessionID(httpSessionID); - mcAuthoringForm.setActiveModule(activeModule); - mcAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); - - setupCommonScreenData(mcContent, mcService, request); - - MonitoringUtil.setupAllSessionsData(request, mcContent, mcService); - return (mapping.findForward("editQuestionBox")); - } - - /** - * removes a question from the questions map - */ - public ActionForward removeQuestion(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException { - McAuthoringForm mcAuthoringForm = (McMonitoringForm) form; - - IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); - - String httpSessionID = mcAuthoringForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - String questionIndex = request.getParameter("questionIndex"); - mcAuthoringForm.setQuestionIndex(questionIndex); - - List listQuestionContentDTO = (List) sessionMap.get(LIST_QUESTION_CONTENT_DTO_KEY); - - McQuestionContentDTO mcQuestionContentDTO = null; - Iterator listIterator = listQuestionContentDTO.iterator(); - while (listIterator.hasNext()) { - mcQuestionContentDTO = (McQuestionContentDTO) listIterator.next(); - - String question = mcQuestionContentDTO.getQuestion(); - String displayOrder = mcQuestionContentDTO.getDisplayOrder(); - - if ((displayOrder != null) && (!displayOrder.equals(""))) { - if (displayOrder.equals(questionIndex)) { - break; - } - - } - } - - mcQuestionContentDTO.setQuestion(""); - - listQuestionContentDTO = AuthoringUtil.reorderListQuestionContentDTO(listQuestionContentDTO, questionIndex); - - sessionMap.put(LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - mcAuthoringForm.setContentFolderID(contentFolderID); - String activeModule = request.getParameter(ACTIVE_MODULE); - - String richTextTitle = request.getParameter(TITLE); - - String richTextInstructions = request.getParameter(INSTRUCTIONS); - - sessionMap.put(ACTIVITY_TITLE_KEY, richTextTitle); - sessionMap.put(ACTIVITY_INSTRUCTIONS_KEY, richTextInstructions); - - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - - String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(MY_SIGNATURE)).toString(); - ; - - McContent mcContent = mcService.retrieveMc(new Long(strToolContentID)); - - if (mcContent == null) { - mcContent = mcService.retrieveMc(new Long(defaultContentIdStr)); - } - - McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); - mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); - - mcGeneralAuthoringDTO.setActivityTitle(richTextTitle); - mcAuthoringForm.setTitle(richTextTitle); - - mcGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - - AuthoringUtil authoringUtil = new AuthoringUtil(); - - mcGeneralAuthoringDTO.setEditActivityEditMode(new Boolean(true).toString()); - - request.getSession().setAttribute(httpSessionID, sessionMap); - - McUtils.setFormProperties(request, mcService, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); - - mcGeneralAuthoringDTO.setToolContentID(strToolContentID); - mcGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - mcGeneralAuthoringDTO.setActiveModule(activeModule); - mcGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); - mcAuthoringForm.setToolContentID(strToolContentID); - mcAuthoringForm.setHttpSessionID(httpSessionID); - mcAuthoringForm.setActiveModule(activeModule); - mcAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); - mcAuthoringForm.setCurrentTab("3"); - - request.setAttribute(LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - mcGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - Map marksMap = authoringUtil.buildMarksMap(); - mcGeneralAuthoringDTO.setMarksMap(marksMap); - - Map passMarksMap = authoringUtil.buildDynamicPassMarkMap(listQuestionContentDTO, false); - mcGeneralAuthoringDTO.setPassMarksMap(passMarksMap); - - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTO); - mcAuthoringForm.setTotalMarks(totalMark); - mcGeneralAuthoringDTO.setTotalMarks(totalMark); - - Map correctMap = authoringUtil.buildCorrectMap(); - mcGeneralAuthoringDTO.setCorrectMap(correctMap); - request.setAttribute(MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - - request.setAttribute(TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); - - setupCommonScreenData(mcContent, mcService, request); - - MonitoringUtil.setupAllSessionsData(request, mcContent, mcService); - return (mapping.findForward(LOAD_MONITORING)); - } - - /** - * moves a question down in the list - */ - public ActionForward moveQuestionDown(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException { - McAuthoringForm mcAuthoringForm = (McMonitoringForm) form; - - IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); - String httpSessionID = mcAuthoringForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - String questionIndex = request.getParameter("questionIndex"); - mcAuthoringForm.setQuestionIndex(questionIndex); - - List listQuestionContentDTO = (List) sessionMap.get(LIST_QUESTION_CONTENT_DTO_KEY); - - listQuestionContentDTO = AuthoringUtil.swapNodes(listQuestionContentDTO, questionIndex, "down"); - - listQuestionContentDTO = AuthoringUtil.reorderSimpleListQuestionContentDTO(listQuestionContentDTO); - sessionMap.put(LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - mcAuthoringForm.setContentFolderID(contentFolderID); - - String activeModule = request.getParameter(ACTIVE_MODULE); - String richTextTitle = request.getParameter(TITLE); - String richTextInstructions = request.getParameter(INSTRUCTIONS); - sessionMap.put(ACTIVITY_TITLE_KEY, richTextTitle); - sessionMap.put(ACTIVITY_INSTRUCTIONS_KEY, richTextInstructions); - - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(MY_SIGNATURE)).toString(); - ; - McContent mcContent = mcService.retrieveMc(new Long(strToolContentID)); - McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); - mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); - - mcGeneralAuthoringDTO.setActivityTitle(richTextTitle); - mcAuthoringForm.setTitle(richTextTitle); - - mcGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - - AuthoringUtil authoringUtil = new AuthoringUtil(); - - mcGeneralAuthoringDTO.setEditActivityEditMode(new Boolean(true).toString()); - - request.getSession().setAttribute(httpSessionID, sessionMap); - - McUtils.setFormProperties(request, mcService, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); - - mcGeneralAuthoringDTO.setToolContentID(strToolContentID); - mcGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - mcGeneralAuthoringDTO.setActiveModule(activeModule); - mcGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); - mcAuthoringForm.setToolContentID(strToolContentID); - mcAuthoringForm.setHttpSessionID(httpSessionID); - mcAuthoringForm.setActiveModule(activeModule); - mcAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); - mcAuthoringForm.setCurrentTab("3"); - - request.setAttribute(LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - mcGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - Map marksMap = authoringUtil.buildMarksMap(); - mcGeneralAuthoringDTO.setMarksMap(marksMap); - - Map passMarksMap = authoringUtil.buildDynamicPassMarkMap(listQuestionContentDTO, false); - mcGeneralAuthoringDTO.setPassMarksMap(passMarksMap); - - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTO); - mcAuthoringForm.setTotalMarks(totalMark); - mcGeneralAuthoringDTO.setTotalMarks(totalMark); - - Map correctMap = authoringUtil.buildCorrectMap(); - mcGeneralAuthoringDTO.setCorrectMap(correctMap); - - request.setAttribute(MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - - request.setAttribute(TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); - - setupCommonScreenData(mcContent, mcService, request); - - MonitoringUtil.setupAllSessionsData(request, mcContent, mcService); - return (mapping.findForward(LOAD_MONITORING)); - } - - /** - * - */ - public ActionForward moveQuestionUp(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException { - McAuthoringForm mcAuthoringForm = (McMonitoringForm) form; - - IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); - - String httpSessionID = mcAuthoringForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - String questionIndex = request.getParameter("questionIndex"); - mcAuthoringForm.setQuestionIndex(questionIndex); - - List listQuestionContentDTO = (List) sessionMap.get(LIST_QUESTION_CONTENT_DTO_KEY); - listQuestionContentDTO = AuthoringUtil.swapNodes(listQuestionContentDTO, questionIndex, "up"); - listQuestionContentDTO = AuthoringUtil.reorderSimpleListQuestionContentDTO(listQuestionContentDTO); - sessionMap.put(LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - mcAuthoringForm.setContentFolderID(contentFolderID); - - String activeModule = request.getParameter(ACTIVE_MODULE); - String richTextTitle = request.getParameter(TITLE); - String richTextInstructions = request.getParameter(INSTRUCTIONS); - sessionMap.put(ACTIVITY_TITLE_KEY, richTextTitle); - sessionMap.put(ACTIVITY_INSTRUCTIONS_KEY, richTextInstructions); - - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(MY_SIGNATURE)).toString(); - McContent mcContent = mcService.retrieveMc(new Long(strToolContentID)); - McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); - mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); - - mcGeneralAuthoringDTO.setActivityTitle(richTextTitle); - mcAuthoringForm.setTitle(richTextTitle); - - mcGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - - AuthoringUtil authoringUtil = new AuthoringUtil(); - - mcGeneralAuthoringDTO.setEditActivityEditMode(new Boolean(true).toString()); - - request.getSession().setAttribute(httpSessionID, sessionMap); - - McUtils.setFormProperties(request, mcService, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); - - mcGeneralAuthoringDTO.setToolContentID(strToolContentID); - mcGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - mcGeneralAuthoringDTO.setActiveModule(activeModule); - mcGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); - mcAuthoringForm.setToolContentID(strToolContentID); - mcAuthoringForm.setHttpSessionID(httpSessionID); - mcAuthoringForm.setActiveModule(activeModule); - mcAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); - mcAuthoringForm.setCurrentTab("3"); - - request.setAttribute(LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - mcGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - Map marksMap = authoringUtil.buildMarksMap(); - mcGeneralAuthoringDTO.setMarksMap(marksMap); - - Map passMarksMap = authoringUtil.buildDynamicPassMarkMap(listQuestionContentDTO, false); - mcGeneralAuthoringDTO.setPassMarksMap(passMarksMap); - - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTO); - mcAuthoringForm.setTotalMarks(totalMark); - mcGeneralAuthoringDTO.setTotalMarks(totalMark); - - Map correctMap = authoringUtil.buildCorrectMap(); - mcGeneralAuthoringDTO.setCorrectMap(correctMap); - request.setAttribute(MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - - request.setAttribute(TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); - - setupCommonScreenData(mcContent, mcService, request); - - MonitoringUtil.setupAllSessionsData(request, mcContent, mcService); - - return (mapping.findForward(LOAD_MONITORING)); - } - - /** - * moves a candidate dwn in the list - */ - public ActionForward moveCandidateDown(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException { - McAuthoringForm mcAuthoringForm = (McMonitoringForm) form; - - IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); - - String httpSessionID = mcAuthoringForm.getHttpSessionID(); - - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - String questionIndex = request.getParameter("questionIndex"); - mcAuthoringForm.setQuestionIndex(questionIndex); - - String candidateIndex = request.getParameter("candidateIndex"); - mcAuthoringForm.setCandidateIndex(candidateIndex); - - AuthoringUtil authoringUtil = new AuthoringUtil(); - boolean validateCandidateAnswersNotBlank = authoringUtil.validateCandidateAnswersNotBlank(request); - ActionMessages errors = new ActionMessages(); - - if (!validateCandidateAnswersNotBlank) { - ActionMessage error = new ActionMessage("candidates.blank"); - errors.add(ActionMessages.GLOBAL_MESSAGE, error); - } - - if (!errors.isEmpty()) { - saveErrors(request, errors); - logger.debug("errors saved: " + errors); - } - - List caList = authoringUtil.repopulateCandidateAnswersBox(request, false); - - List listQuestionContentDTO = (List) sessionMap.get(LIST_QUESTION_CONTENT_DTO_KEY); - - if (errors.isEmpty()) { - List candidates = new LinkedList(); - List listCandidates = new LinkedList(); - String editableQuestion = ""; - Iterator listIterator = listQuestionContentDTO.iterator(); - while (listIterator.hasNext()) { - McQuestionContentDTO mcQuestionContentDTO = (McQuestionContentDTO) listIterator.next(); - - String question = mcQuestionContentDTO.getQuestion(); - String displayOrder = mcQuestionContentDTO.getDisplayOrder(); - - if ((displayOrder != null) && (!displayOrder.equals(""))) { - if (displayOrder.equals(questionIndex)) { - editableQuestion = mcQuestionContentDTO.getQuestion(); - - candidates = mcQuestionContentDTO.getListCandidateAnswersDTO(); - - listCandidates = AuthoringUtil.swapCandidateNodes(caList, candidateIndex, "down"); - - mcQuestionContentDTO.setListCandidateAnswersDTO(listCandidates); - - break; - } - - } - } - } - - sessionMap.put(LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - mcAuthoringForm.setContentFolderID(contentFolderID); - - String activeModule = request.getParameter(ACTIVE_MODULE); - - String richTextTitle = request.getParameter(TITLE); - - String richTextInstructions = request.getParameter(INSTRUCTIONS); - - sessionMap.put(ACTIVITY_TITLE_KEY, richTextTitle); - sessionMap.put(ACTIVITY_INSTRUCTIONS_KEY, richTextInstructions); - - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(MY_SIGNATURE)).toString(); - ; - McContent mcContent = mcService.retrieveMc(new Long(strToolContentID)); - McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); - mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); - - mcGeneralAuthoringDTO.setActivityTitle(richTextTitle); - mcAuthoringForm.setTitle(richTextTitle); - - mcGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - - mcGeneralAuthoringDTO.setEditActivityEditMode(new Boolean(true).toString()); - - request.getSession().setAttribute(httpSessionID, sessionMap); - - McUtils.setFormProperties(request, mcService, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); - - mcGeneralAuthoringDTO.setToolContentID(strToolContentID); - mcGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - mcGeneralAuthoringDTO.setActiveModule(activeModule); - mcGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); - mcAuthoringForm.setToolContentID(strToolContentID); - mcAuthoringForm.setHttpSessionID(httpSessionID); - mcAuthoringForm.setActiveModule(activeModule); - mcAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); - mcAuthoringForm.setCurrentTab("3"); - - request.setAttribute(LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - - mcGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - Map marksMap = authoringUtil.buildMarksMap(); - mcGeneralAuthoringDTO.setMarksMap(marksMap); - - Map passMarksMap = authoringUtil.buildDynamicPassMarkMap(listQuestionContentDTO, false); - mcGeneralAuthoringDTO.setPassMarksMap(passMarksMap); - - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTO); - mcAuthoringForm.setTotalMarks(totalMark); - mcGeneralAuthoringDTO.setTotalMarks(totalMark); - - Map correctMap = authoringUtil.buildCorrectMap(); - mcGeneralAuthoringDTO.setCorrectMap(correctMap); - - String newQuestion = request.getParameter("newQuestion"); - mcGeneralAuthoringDTO.setEditableQuestionText(newQuestion); - - String feedback = request.getParameter("feedback"); - mcAuthoringForm.setFeedback(feedback); - - String mark = request.getParameter("mark"); - mcGeneralAuthoringDTO.setMarkValue(mark); - - request.setAttribute(MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - - request.setAttribute(TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); - - String editQuestionBoxRequest = request.getParameter("editQuestionBoxRequest"); - - setupCommonScreenData(mcContent, mcService, request); - - MonitoringUtil.setupAllSessionsData(request, mcContent, mcService); - request.setAttribute("requestNewEditableQuestionBox", new Boolean(true).toString()); - - return newEditableQuestionBox(mapping, form, request, response); - } - - /** - * - * moves a candidate up in the list - */ - public ActionForward moveCandidateUp(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException { - McAuthoringForm mcAuthoringForm = (McAuthoringForm) form; - - IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); - String httpSessionID = mcAuthoringForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - String questionIndex = request.getParameter("questionIndex"); - mcAuthoringForm.setQuestionIndex(questionIndex); - - String totalMarks = request.getParameter("totalMarks"); - String candidateIndex = request.getParameter("candidateIndex"); - mcAuthoringForm.setCandidateIndex(candidateIndex); - - AuthoringUtil authoringUtil = new AuthoringUtil(); - - boolean validateCandidateAnswersNotBlank = authoringUtil.validateCandidateAnswersNotBlank(request); - - ActionMessages errors = new ActionMessages(); - - if (!validateCandidateAnswersNotBlank) { - ActionMessage error = new ActionMessage("candidates.blank"); - errors.add(ActionMessages.GLOBAL_MESSAGE, error); - } - - if (!errors.isEmpty()) { - saveErrors(request, errors); - logger.debug("errors saved: " + errors); - } - - List caList = authoringUtil.repopulateCandidateAnswersBox(request, false); - List listQuestionContentDTO = (List) sessionMap.get(LIST_QUESTION_CONTENT_DTO_KEY); - - if (errors.isEmpty()) { - List candidates = new LinkedList(); - List listCandidates = new LinkedList(); - String editableQuestion = ""; - Iterator listIterator = listQuestionContentDTO.iterator(); - while (listIterator.hasNext()) { - McQuestionContentDTO mcQuestionContentDTO = (McQuestionContentDTO) listIterator.next(); - String question = mcQuestionContentDTO.getQuestion(); - String displayOrder = mcQuestionContentDTO.getDisplayOrder(); - - if ((displayOrder != null) && (!displayOrder.equals(""))) { - if (displayOrder.equals(questionIndex)) { - editableQuestion = mcQuestionContentDTO.getQuestion(); - - candidates = mcQuestionContentDTO.getListCandidateAnswersDTO(); - listCandidates = AuthoringUtil.swapCandidateNodes(caList, candidateIndex, "up"); - mcQuestionContentDTO.setListCandidateAnswersDTO(listCandidates); - mcQuestionContentDTO.setCaCount(new Integer(listCandidates.size()).toString()); - - break; - } - - } - } - } - - sessionMap.put(LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - mcAuthoringForm.setContentFolderID(contentFolderID); - - String activeModule = request.getParameter(ACTIVE_MODULE); - String richTextTitle = request.getParameter(TITLE); - String richTextInstructions = request.getParameter(INSTRUCTIONS); - sessionMap.put(ACTIVITY_TITLE_KEY, richTextTitle); - sessionMap.put(ACTIVITY_INSTRUCTIONS_KEY, richTextInstructions); - - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(MY_SIGNATURE)).toString(); - ; - McContent mcContent = mcService.retrieveMc(new Long(strToolContentID)); - McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); - mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); - - mcGeneralAuthoringDTO.setActivityTitle(richTextTitle); - mcAuthoringForm.setTitle(richTextTitle); - - mcGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - - mcGeneralAuthoringDTO.setEditActivityEditMode(new Boolean(true).toString()); - - request.getSession().setAttribute(httpSessionID, sessionMap); - - McUtils.setFormProperties(request, mcService, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); - - mcGeneralAuthoringDTO.setToolContentID(strToolContentID); - mcGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - mcGeneralAuthoringDTO.setActiveModule(activeModule); - mcGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); - mcAuthoringForm.setToolContentID(strToolContentID); - mcAuthoringForm.setHttpSessionID(httpSessionID); - mcAuthoringForm.setActiveModule(activeModule); - mcAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); - mcAuthoringForm.setCurrentTab("3"); - - request.setAttribute(LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - mcGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - Map marksMap = authoringUtil.buildMarksMap(); - mcGeneralAuthoringDTO.setMarksMap(marksMap); - - Map passMarksMap = authoringUtil.buildDynamicPassMarkMap(listQuestionContentDTO, false); - mcGeneralAuthoringDTO.setPassMarksMap(passMarksMap); - - Map correctMap = authoringUtil.buildCorrectMap(); - mcGeneralAuthoringDTO.setCorrectMap(correctMap); - - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTO); - mcAuthoringForm.setTotalMarks(totalMark); - mcGeneralAuthoringDTO.setTotalMarks(totalMark); - - String newQuestion = request.getParameter("newQuestion"); - mcGeneralAuthoringDTO.setEditableQuestionText(newQuestion); - - String feedback = request.getParameter("feedback"); - mcAuthoringForm.setFeedback(feedback); - - String mark = request.getParameter("mark"); - mcGeneralAuthoringDTO.setMarkValue(mark); - - request.setAttribute(MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - - request.setAttribute(TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); - - String editQuestionBoxRequest = request.getParameter("editQuestionBoxRequest"); - - setupCommonScreenData(mcContent, mcService, request); - - MonitoringUtil.setupAllSessionsData(request, mcContent, mcService); - request.setAttribute("requestNewEditableQuestionBox", new Boolean(true).toString()); - - return newEditableQuestionBox(mapping, form, request, response); - } - - /** - * removes a candidate from the list - */ - public ActionForward removeCandidate(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException { - McAuthoringForm mcAuthoringForm = (McMonitoringForm) form; - - IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); - String httpSessionID = mcAuthoringForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - String questionIndex = request.getParameter("questionIndex"); - mcAuthoringForm.setQuestionIndex(questionIndex); - - String candidateIndex = request.getParameter("candidateIndex"); - mcAuthoringForm.setCandidateIndex(candidateIndex); - - String totalMarks = request.getParameter("totalMarks"); - List listQuestionContentDTO = (List) sessionMap.get(LIST_QUESTION_CONTENT_DTO_KEY); - AuthoringUtil authoringUtil = new AuthoringUtil(); - List caList = authoringUtil.repopulateCandidateAnswersBox(request, false); - - McQuestionContentDTO mcQuestionContentDTO = null; - Iterator listIterator = listQuestionContentDTO.iterator(); - while (listIterator.hasNext()) { - mcQuestionContentDTO = (McQuestionContentDTO) listIterator.next(); - - String question = mcQuestionContentDTO.getQuestion(); - String displayOrder = mcQuestionContentDTO.getDisplayOrder(); - - if ((displayOrder != null) && (!displayOrder.equals(""))) { - if (displayOrder.equals(questionIndex)) { - break; - } - - } - } - - mcQuestionContentDTO.setListCandidateAnswersDTO(caList); - - List candidateAnswers = mcQuestionContentDTO.getListCandidateAnswersDTO(); - - McCandidateAnswersDTO mcCandidateAnswersDTO = null; - Iterator listCaIterator = candidateAnswers.iterator(); - int caIndex = 0; - while (listCaIterator.hasNext()) { - caIndex++; - mcCandidateAnswersDTO = (McCandidateAnswersDTO) listCaIterator.next(); - - if (caIndex == new Integer(candidateIndex).intValue()) { - mcCandidateAnswersDTO.setCandidateAnswer(""); - - break; - } - } - - candidateAnswers = AuthoringUtil.reorderListCandidatesDTO(candidateAnswers); - mcQuestionContentDTO.setListCandidateAnswersDTO(candidateAnswers); - mcQuestionContentDTO.setCaCount(new Integer(candidateAnswers.size()).toString()); - sessionMap.put(LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - mcAuthoringForm.setContentFolderID(contentFolderID); - - String activeModule = request.getParameter(ACTIVE_MODULE); - String richTextTitle = request.getParameter(TITLE); - String richTextInstructions = request.getParameter(INSTRUCTIONS); - sessionMap.put(ACTIVITY_TITLE_KEY, richTextTitle); - sessionMap.put(ACTIVITY_INSTRUCTIONS_KEY, richTextInstructions); - - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(MY_SIGNATURE)).toString(); - ; - McContent mcContent = mcService.retrieveMc(new Long(strToolContentID)); - if (mcContent == null) { - mcContent = mcService.retrieveMc(new Long(defaultContentIdStr)); - } - McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); - mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); - - mcGeneralAuthoringDTO.setActivityTitle(richTextTitle); - mcAuthoringForm.setTitle(richTextTitle); - - mcGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - - mcGeneralAuthoringDTO.setEditActivityEditMode(new Boolean(true).toString()); - - request.getSession().setAttribute(httpSessionID, sessionMap); - - McUtils.setFormProperties(request, mcService, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); - - mcGeneralAuthoringDTO.setToolContentID(strToolContentID); - mcGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - mcGeneralAuthoringDTO.setActiveModule(activeModule); - mcGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); - mcAuthoringForm.setToolContentID(strToolContentID); - mcAuthoringForm.setHttpSessionID(httpSessionID); - mcAuthoringForm.setActiveModule(activeModule); - mcAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); - mcAuthoringForm.setCurrentTab("3"); - - request.setAttribute(LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - mcGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - Map marksMap = authoringUtil.buildMarksMap(); - mcGeneralAuthoringDTO.setMarksMap(marksMap); - Map passMarksMap = authoringUtil.buildDynamicPassMarkMap(listQuestionContentDTO, false); - mcGeneralAuthoringDTO.setPassMarksMap(passMarksMap); - - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTO); - mcAuthoringForm.setTotalMarks(totalMark); - mcGeneralAuthoringDTO.setTotalMarks(totalMark); - - Map correctMap = authoringUtil.buildCorrectMap(); - mcGeneralAuthoringDTO.setCorrectMap(correctMap); - - String newQuestion = request.getParameter("newQuestion"); - mcGeneralAuthoringDTO.setEditableQuestionText(newQuestion); - - String feedback = request.getParameter("feedback"); - mcAuthoringForm.setFeedback(feedback); - - String mark = request.getParameter("mark"); - mcGeneralAuthoringDTO.setMarkValue(mark); - request.setAttribute(MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - request.setAttribute(TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); - - String editQuestionBoxRequest = request.getParameter("editQuestionBoxRequest"); - - setupCommonScreenData(mcContent, mcService, request); - - MonitoringUtil.setupAllSessionsData(request, mcContent, mcService); - request.setAttribute("requestNewEditableQuestionBox", new Boolean(true).toString()); - - return newEditableQuestionBox(mapping, form, request, response); - - } - - /** - * - * enables adding a new candidate answer - */ - public ActionForward newCandidateBox(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException { - McAuthoringForm mcAuthoringForm = (McMonitoringForm) form; - - IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); - - String httpSessionID = mcAuthoringForm.getHttpSessionID(); - - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - - String questionIndex = request.getParameter("questionIndex"); - mcAuthoringForm.setQuestionIndex(questionIndex); - - String candidateIndex = request.getParameter("candidateIndex"); - mcAuthoringForm.setCandidateIndex(candidateIndex); - - String totalMarks = request.getParameter("totalMarks"); - - List listQuestionContentDTO = (List) sessionMap.get(LIST_QUESTION_CONTENT_DTO_KEY); - - AuthoringUtil authoringUtil = new AuthoringUtil(); - List caList = authoringUtil.repopulateCandidateAnswersBox(request, true); - - int caCount = caList.size(); - String newQuestion = request.getParameter("newQuestion"); - String mark = request.getParameter("mark"); - String passmark = request.getParameter("passmark"); - String feedback = request.getParameter("feedback"); - int currentQuestionCount = listQuestionContentDTO.size(); - String editQuestionBoxRequest = request.getParameter("editQuestionBoxRequest"); - McQuestionContentDTO mcQuestionContentDTOLocal = null; - Iterator listIterator = listQuestionContentDTO.iterator(); - while (listIterator.hasNext()) { - mcQuestionContentDTOLocal = (McQuestionContentDTO) listIterator.next(); - - String question = mcQuestionContentDTOLocal.getQuestion(); - String displayOrder = mcQuestionContentDTOLocal.getDisplayOrder(); - if ((displayOrder != null) && (!displayOrder.equals(""))) { - if (displayOrder.equals(questionIndex)) { - break; - } - - } - } - - if (mcQuestionContentDTOLocal != null) { - mcQuestionContentDTOLocal.setListCandidateAnswersDTO(caList); - mcQuestionContentDTOLocal.setCaCount(new Integer(caList.size()).toString()); - } - - sessionMap.put(LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - mcAuthoringForm.setContentFolderID(contentFolderID); - - String activeModule = request.getParameter(ACTIVE_MODULE); - String richTextTitle = request.getParameter(TITLE); - String richTextInstructions = request.getParameter(INSTRUCTIONS); - sessionMap.put(ACTIVITY_TITLE_KEY, richTextTitle); - sessionMap.put(ACTIVITY_INSTRUCTIONS_KEY, richTextInstructions); - - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(MY_SIGNATURE)).toString(); - ; - McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); - mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); - - mcGeneralAuthoringDTO.setActivityTitle(richTextTitle); - mcAuthoringForm.setTitle(richTextTitle); - - mcGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - - mcGeneralAuthoringDTO.setEditActivityEditMode(new Boolean(true).toString()); - - request.getSession().setAttribute(httpSessionID, sessionMap); - - McUtils.setFormProperties(request, mcService, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); - - mcGeneralAuthoringDTO.setToolContentID(strToolContentID); - mcGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - mcGeneralAuthoringDTO.setActiveModule(activeModule); - mcGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); - mcAuthoringForm.setToolContentID(strToolContentID); - mcAuthoringForm.setHttpSessionID(httpSessionID); - mcAuthoringForm.setActiveModule(activeModule); - mcAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); - mcAuthoringForm.setCurrentTab("3"); - - request.setAttribute(LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - mcGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - Map marksMap = authoringUtil.buildMarksMap(); - mcGeneralAuthoringDTO.setMarksMap(marksMap); - - Map passMarksMap = authoringUtil.buildDynamicPassMarkMap(listQuestionContentDTO, false); - mcGeneralAuthoringDTO.setPassMarksMap(passMarksMap); - - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTO); - mcAuthoringForm.setTotalMarks(totalMark); - mcGeneralAuthoringDTO.setTotalMarks(totalMark); - - Map correctMap = authoringUtil.buildCorrectMap(); - mcGeneralAuthoringDTO.setCorrectMap(correctMap); - - mcGeneralAuthoringDTO.setEditableQuestionText(newQuestion); - - mcAuthoringForm.setFeedback(feedback); - - mcGeneralAuthoringDTO.setMarkValue(mark); - - request.setAttribute(MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - - request.setAttribute(TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); - - McContent mcContent = mcService.retrieveMc(new Long(strToolContentID)); - - setupCommonScreenData(mcContent, mcService, request); - - MonitoringUtil.setupAllSessionsData(request, mcContent, mcService); - request.setAttribute("requestNewEditableQuestionBox", new Boolean(true).toString()); - - return newEditableQuestionBox(mapping, form, request, response); - } - - public ActionForward moveAddedCandidateUp(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException { - McAuthoringForm mcAuthoringForm = (McMonitoringForm) form; - - IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); - - String httpSessionID = mcAuthoringForm.getHttpSessionID(); - - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - - String totalMarks = request.getParameter("totalMarks"); - - String candidateIndex = request.getParameter("candidateIndex"); - mcAuthoringForm.setCandidateIndex(candidateIndex); - - AuthoringUtil authoringUtil = new AuthoringUtil(); - - boolean validateCandidateAnswersNotBlank = authoringUtil.validateCandidateAnswersNotBlank(request); - ActionMessages errors = new ActionMessages(); - - if (!validateCandidateAnswersNotBlank) { - ActionMessage error = new ActionMessage("candidates.blank"); - errors.add(ActionMessages.GLOBAL_MESSAGE, error); - } - - if (!errors.isEmpty()) { - saveErrors(request, errors); - logger.debug("errors saved: " + errors); - } - - List caList = authoringUtil.repopulateCandidateAnswersBox(request, false); - List listQuestionContentDTO = (List) sessionMap.get(LIST_QUESTION_CONTENT_DTO_KEY); - sessionMap.put(LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - - List listAddableQuestionContentDTO = (List) sessionMap.get(NEW_ADDABLE_QUESTION_CONTENT_KEY); - if (errors.isEmpty()) { - List candidates = new LinkedList(); - List listCandidates = new LinkedList(); - - Iterator listIterator = listAddableQuestionContentDTO.iterator(); - /* there is only 1 question dto */ - while (listIterator.hasNext()) { - McQuestionContentDTO mcQuestionContentDTO = (McQuestionContentDTO) listIterator.next(); - - candidates = mcQuestionContentDTO.getListCandidateAnswersDTO(); - listCandidates = AuthoringUtil.swapCandidateNodes(caList, candidateIndex, "up"); - - mcQuestionContentDTO.setListCandidateAnswersDTO(listCandidates); - } - } - - request.setAttribute(NEW_ADDABLE_QUESTION_CONTENT_LIST, listAddableQuestionContentDTO); - sessionMap.put(NEW_ADDABLE_QUESTION_CONTENT_KEY, listAddableQuestionContentDTO); - - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - mcAuthoringForm.setContentFolderID(contentFolderID); - - String activeModule = request.getParameter(ACTIVE_MODULE); - - String richTextTitle = request.getParameter(TITLE); - String richTextInstructions = request.getParameter(INSTRUCTIONS); - sessionMap.put(ACTIVITY_TITLE_KEY, richTextTitle); - sessionMap.put(ACTIVITY_INSTRUCTIONS_KEY, richTextInstructions); - - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(MY_SIGNATURE)).toString(); - ; - McContent mcContent = mcService.retrieveMc(new Long(strToolContentID)); - McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); - mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); - - mcGeneralAuthoringDTO.setActivityTitle(richTextTitle); - mcAuthoringForm.setTitle(richTextTitle); - - mcGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - - mcGeneralAuthoringDTO.setEditActivityEditMode(new Boolean(true).toString()); - - request.getSession().setAttribute(httpSessionID, sessionMap); - - McUtils.setFormProperties(request, mcService, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); - - mcGeneralAuthoringDTO.setToolContentID(strToolContentID); - mcGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - mcGeneralAuthoringDTO.setActiveModule(activeModule); - mcGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); - mcAuthoringForm.setToolContentID(strToolContentID); - mcAuthoringForm.setHttpSessionID(httpSessionID); - mcAuthoringForm.setActiveModule(activeModule); - mcAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); - mcAuthoringForm.setCurrentTab("3"); - - request.setAttribute(LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - mcGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - Map marksMap = authoringUtil.buildMarksMap(); - mcGeneralAuthoringDTO.setMarksMap(marksMap); - - Map passMarksMap = authoringUtil.buildDynamicPassMarkMap(listQuestionContentDTO, false); - mcGeneralAuthoringDTO.setPassMarksMap(passMarksMap); - - Map correctMap = authoringUtil.buildCorrectMap(); - mcGeneralAuthoringDTO.setCorrectMap(correctMap); - - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTO); - mcAuthoringForm.setTotalMarks(totalMark); - mcGeneralAuthoringDTO.setTotalMarks(totalMark); - - String newQuestion = request.getParameter("newQuestion"); - mcGeneralAuthoringDTO.setEditableQuestionText(newQuestion); - - String feedback = request.getParameter("feedback"); - mcAuthoringForm.setFeedback(feedback); - - String mark = request.getParameter("mark"); - mcGeneralAuthoringDTO.setMarkValue(mark); - - request.setAttribute(MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - - request.setAttribute(TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); - - String editQuestionBoxRequest = request.getParameter("editQuestionBoxRequest"); - - setupCommonScreenData(mcContent, mcService, request); - - MonitoringUtil.setupAllSessionsData(request, mcContent, mcService); - - return newQuestionBox(mapping, form, request, response); - - } - - public ActionForward moveAddedCandidateDown(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException { - McAuthoringForm mcAuthoringForm = (McMonitoringForm) form; - - IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); - - String httpSessionID = mcAuthoringForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - String candidateIndex = request.getParameter("candidateIndex"); - mcAuthoringForm.setCandidateIndex(candidateIndex); - - String totalMarks = request.getParameter("totalMarks"); - AuthoringUtil authoringUtil = new AuthoringUtil(); - boolean validateCandidateAnswersNotBlank = authoringUtil.validateCandidateAnswersNotBlank(request); - ActionMessages errors = new ActionMessages(); - - if (!validateCandidateAnswersNotBlank) { - ActionMessage error = new ActionMessage("candidates.blank"); - errors.add(ActionMessages.GLOBAL_MESSAGE, error); - } - - if (!errors.isEmpty()) { - saveErrors(request, errors); - logger.debug("errors saved: " + errors); - } - - List caList = authoringUtil.repopulateCandidateAnswersBox(request, false); - - List listQuestionContentDTO = (List) sessionMap.get(LIST_QUESTION_CONTENT_DTO_KEY); - sessionMap.put(LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - - List listAddableQuestionContentDTO = (List) sessionMap.get(NEW_ADDABLE_QUESTION_CONTENT_KEY); - - if (errors.isEmpty()) { - List candidates = new LinkedList(); - List listCandidates = new LinkedList(); - - Iterator listIterator = listAddableQuestionContentDTO.iterator(); - /* there is only 1 question dto */ - while (listIterator.hasNext()) { - McQuestionContentDTO mcQuestionContentDTO = (McQuestionContentDTO) listIterator.next(); - - candidates = mcQuestionContentDTO.getListCandidateAnswersDTO(); - listCandidates = AuthoringUtil.swapCandidateNodes(caList, candidateIndex, "down"); - mcQuestionContentDTO.setListCandidateAnswersDTO(listCandidates); - } - } - - request.setAttribute(NEW_ADDABLE_QUESTION_CONTENT_LIST, listAddableQuestionContentDTO); - sessionMap.put(NEW_ADDABLE_QUESTION_CONTENT_KEY, listAddableQuestionContentDTO); - - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - mcAuthoringForm.setContentFolderID(contentFolderID); - - String activeModule = request.getParameter(ACTIVE_MODULE); - String richTextTitle = request.getParameter(TITLE); - String richTextInstructions = request.getParameter(INSTRUCTIONS); - sessionMap.put(ACTIVITY_TITLE_KEY, richTextTitle); - sessionMap.put(ACTIVITY_INSTRUCTIONS_KEY, richTextInstructions); - - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(MY_SIGNATURE)).toString(); - ; - McContent mcContent = mcService.retrieveMc(new Long(strToolContentID)); - McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); - mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); - - mcGeneralAuthoringDTO.setActivityTitle(richTextTitle); - mcAuthoringForm.setTitle(richTextTitle); - - mcGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - - mcGeneralAuthoringDTO.setEditActivityEditMode(new Boolean(true).toString()); - - request.getSession().setAttribute(httpSessionID, sessionMap); - - McUtils.setFormProperties(request, mcService, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); - - mcGeneralAuthoringDTO.setToolContentID(strToolContentID); - mcGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - mcGeneralAuthoringDTO.setActiveModule(activeModule); - mcGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); - mcAuthoringForm.setToolContentID(strToolContentID); - mcAuthoringForm.setHttpSessionID(httpSessionID); - mcAuthoringForm.setActiveModule(activeModule); - mcAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); - mcAuthoringForm.setCurrentTab("3"); - - request.setAttribute(LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - mcGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - Map marksMap = authoringUtil.buildMarksMap(); - mcGeneralAuthoringDTO.setMarksMap(marksMap); - - Map passMarksMap = authoringUtil.buildDynamicPassMarkMap(listQuestionContentDTO, false); - mcGeneralAuthoringDTO.setPassMarksMap(passMarksMap); - - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTO); - mcAuthoringForm.setTotalMarks(totalMark); - mcGeneralAuthoringDTO.setTotalMarks(totalMark); - - Map correctMap = authoringUtil.buildCorrectMap(); - mcGeneralAuthoringDTO.setCorrectMap(correctMap); - - String newQuestion = request.getParameter("newQuestion"); - mcGeneralAuthoringDTO.setEditableQuestionText(newQuestion); - - String feedback = request.getParameter("feedback"); - mcAuthoringForm.setFeedback(feedback); - - String mark = request.getParameter("mark"); - mcGeneralAuthoringDTO.setMarkValue(mark); - - request.setAttribute(MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - - request.setAttribute(TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); - - String editQuestionBoxRequest = request.getParameter("editQuestionBoxRequest"); - setupCommonScreenData(mcContent, mcService, request); - - MonitoringUtil.setupAllSessionsData(request, mcContent, mcService); - - return newQuestionBox(mapping, form, request, response); - } - - public ActionForward removeAddedCandidate(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException { - McAuthoringForm mcAuthoringForm = (McMonitoringForm) form; - - IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); - - String httpSessionID = mcAuthoringForm.getHttpSessionID(); - - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - - String candidateIndex = request.getParameter("candidateIndex"); - mcAuthoringForm.setCandidateIndex(candidateIndex); - - String totalMarks = request.getParameter("totalMarks"); - - AuthoringUtil authoringUtil = new AuthoringUtil(); - List caList = authoringUtil.repopulateCandidateAnswersBox(request, false); - - List listQuestionContentDTO = (List) sessionMap.get(LIST_QUESTION_CONTENT_DTO_KEY); - sessionMap.put(LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - - List listAddableQuestionContentDTO = (List) sessionMap.get(NEW_ADDABLE_QUESTION_CONTENT_KEY); - - List candidates = new LinkedList(); - List listCandidates = new LinkedList(); - - Iterator listIterator = listAddableQuestionContentDTO.iterator(); - /* there is only 1 question dto */ - while (listIterator.hasNext()) { - McQuestionContentDTO mcQuestionContentDTO = (McQuestionContentDTO) listIterator.next(); - - candidates = mcQuestionContentDTO.getListCandidateAnswersDTO(); - mcQuestionContentDTO.setListCandidateAnswersDTO(caList); - - List candidateAnswers = mcQuestionContentDTO.getListCandidateAnswersDTO(); - McCandidateAnswersDTO mcCandidateAnswersDTO = null; - Iterator listCaIterator = candidateAnswers.iterator(); - int caIndex = 0; - while (listCaIterator.hasNext()) { - caIndex++; - mcCandidateAnswersDTO = (McCandidateAnswersDTO) listCaIterator.next(); - if (caIndex == new Integer(candidateIndex).intValue()) { - mcCandidateAnswersDTO.setCandidateAnswer(""); - break; - } - } - - candidateAnswers = AuthoringUtil.reorderListCandidatesDTO(candidateAnswers); - mcQuestionContentDTO.setListCandidateAnswersDTO(candidateAnswers); - mcQuestionContentDTO.setCaCount(new Integer(candidateAnswers.size()).toString()); - } - - request.setAttribute(NEW_ADDABLE_QUESTION_CONTENT_LIST, listAddableQuestionContentDTO); - sessionMap.put(NEW_ADDABLE_QUESTION_CONTENT_KEY, listAddableQuestionContentDTO); - - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - mcAuthoringForm.setContentFolderID(contentFolderID); - - String activeModule = request.getParameter(ACTIVE_MODULE); - String richTextTitle = request.getParameter(TITLE); - String richTextInstructions = request.getParameter(INSTRUCTIONS); - sessionMap.put(ACTIVITY_TITLE_KEY, richTextTitle); - sessionMap.put(ACTIVITY_INSTRUCTIONS_KEY, richTextInstructions); - - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(MY_SIGNATURE)).toString(); - ; - McContent mcContent = mcService.retrieveMc(new Long(strToolContentID)); - if (mcContent == null) { - mcContent = mcService.retrieveMc(new Long(defaultContentIdStr)); - } - - McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); - mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); - - mcGeneralAuthoringDTO.setActivityTitle(richTextTitle); - mcAuthoringForm.setTitle(richTextTitle); - - mcGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - - mcGeneralAuthoringDTO.setEditActivityEditMode(new Boolean(true).toString()); - - request.getSession().setAttribute(httpSessionID, sessionMap); - - McUtils.setFormProperties(request, mcService, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); - - mcGeneralAuthoringDTO.setToolContentID(strToolContentID); - mcGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - mcGeneralAuthoringDTO.setActiveModule(activeModule); - mcGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); - mcAuthoringForm.setToolContentID(strToolContentID); - mcAuthoringForm.setHttpSessionID(httpSessionID); - mcAuthoringForm.setActiveModule(activeModule); - mcAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); - mcAuthoringForm.setCurrentTab("3"); - - request.setAttribute(LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - - mcGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - Map marksMap = authoringUtil.buildMarksMap(); - mcGeneralAuthoringDTO.setMarksMap(marksMap); - - Map passMarksMap = authoringUtil.buildDynamicPassMarkMap(listQuestionContentDTO, false); - mcGeneralAuthoringDTO.setPassMarksMap(passMarksMap); - - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTO); - mcAuthoringForm.setTotalMarks(totalMark); - mcGeneralAuthoringDTO.setTotalMarks(totalMark); - - Map correctMap = authoringUtil.buildCorrectMap(); - mcGeneralAuthoringDTO.setCorrectMap(correctMap); - - String newQuestion = request.getParameter("newQuestion"); - mcGeneralAuthoringDTO.setEditableQuestionText(newQuestion); - - String feedback = request.getParameter("feedback"); - mcAuthoringForm.setFeedback(feedback); - - String mark = request.getParameter("mark"); - mcGeneralAuthoringDTO.setMarkValue(mark); - - request.setAttribute(MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - - request.setAttribute(TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); - - String editQuestionBoxRequest = request.getParameter("editQuestionBoxRequest"); - - setupCommonScreenData(mcContent, mcService, request); - - MonitoringUtil.setupAllSessionsData(request, mcContent, mcService); - return newQuestionBox(mapping, form, request, response); - - } - - public ActionForward newAddedCandidateBox(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException { - McAuthoringForm mcAuthoringForm = (McMonitoringForm) form; - - IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); - String httpSessionID = mcAuthoringForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - String candidateIndex = request.getParameter("candidateIndex"); - mcAuthoringForm.setCandidateIndex(candidateIndex); - String totalMarks = request.getParameter("totalMarks"); - List listQuestionContentDTO = (List) sessionMap.get(LIST_QUESTION_CONTENT_DTO_KEY); - AuthoringUtil authoringUtil = new AuthoringUtil(); - List caList = authoringUtil.repopulateCandidateAnswersBox(request, true); - int caCount = caList.size(); - String newQuestion = request.getParameter("newQuestion"); - String mark = request.getParameter("mark"); - String passmark = request.getParameter("passmark"); - - String feedback = request.getParameter("feedback"); - int currentQuestionCount = listQuestionContentDTO.size(); - String editQuestionBoxRequest = request.getParameter("editQuestionBoxRequest"); - List listAddableQuestionContentDTO = (List) sessionMap.get(NEW_ADDABLE_QUESTION_CONTENT_KEY); - List candidates = new LinkedList(); - List listCandidates = new LinkedList(); - - Iterator listIterator = listAddableQuestionContentDTO.iterator(); - /* there is only 1 question dto */ - while (listIterator.hasNext()) { - McQuestionContentDTO mcQuestionContentDTO = (McQuestionContentDTO) listIterator.next(); - mcQuestionContentDTO.setListCandidateAnswersDTO(caList); - mcQuestionContentDTO.setCaCount(new Integer(caList.size()).toString()); - } - - request.setAttribute(NEW_ADDABLE_QUESTION_CONTENT_LIST, listAddableQuestionContentDTO); - sessionMap.put(NEW_ADDABLE_QUESTION_CONTENT_KEY, listAddableQuestionContentDTO); - - sessionMap.put(LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - mcAuthoringForm.setContentFolderID(contentFolderID); - - String activeModule = request.getParameter(ACTIVE_MODULE); - String richTextTitle = request.getParameter(TITLE); - String richTextInstructions = request.getParameter(INSTRUCTIONS); - sessionMap.put(ACTIVITY_TITLE_KEY, richTextTitle); - sessionMap.put(ACTIVITY_INSTRUCTIONS_KEY, richTextInstructions); - - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(MY_SIGNATURE)).toString(); - ; - McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); - mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); - - mcGeneralAuthoringDTO.setActivityTitle(richTextTitle); - mcAuthoringForm.setTitle(richTextTitle); - - mcGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - - mcGeneralAuthoringDTO.setEditActivityEditMode(new Boolean(true).toString()); - - request.getSession().setAttribute(httpSessionID, sessionMap); - - McUtils.setFormProperties(request, mcService, mcAuthoringForm, mcGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); - - mcGeneralAuthoringDTO.setToolContentID(strToolContentID); - mcGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - mcGeneralAuthoringDTO.setActiveModule(activeModule); - mcGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); - mcAuthoringForm.setToolContentID(strToolContentID); - mcAuthoringForm.setHttpSessionID(httpSessionID); - mcAuthoringForm.setActiveModule(activeModule); - mcAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); - mcAuthoringForm.setCurrentTab("3"); - - request.setAttribute(LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - - mcGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - Map marksMap = authoringUtil.buildMarksMap(); - mcGeneralAuthoringDTO.setMarksMap(marksMap); - - Map passMarksMap = authoringUtil.buildDynamicPassMarkMap(listQuestionContentDTO, false); - mcGeneralAuthoringDTO.setPassMarksMap(passMarksMap); - - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTO); - mcAuthoringForm.setTotalMarks(totalMark); - mcGeneralAuthoringDTO.setTotalMarks(totalMark); - - Map correctMap = authoringUtil.buildCorrectMap(); - mcGeneralAuthoringDTO.setCorrectMap(correctMap); - - mcGeneralAuthoringDTO.setEditableQuestionText(newQuestion); - mcAuthoringForm.setFeedback(feedback); - mcGeneralAuthoringDTO.setMarkValue(mark); - - request.setAttribute(MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - request.setAttribute(TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); - McContent mcContent = mcService.retrieveMc(new Long(strToolContentID)); - setupCommonScreenData(mcContent, mcService, request); - - MonitoringUtil.setupAllSessionsData(request, mcContent, mcService); - return newQuestionBox(mapping, form, request, response); - } - - /** * allows viewing users reflection data */ public ActionForward openNotebook(ActionMapping mapping, ActionForm form, HttpServletRequest request, @@ -2484,82 +180,6 @@ } /** - */ - public void prepareEditActivityScreenData(HttpServletRequest request, McContent mcContent) { - McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); - - mcGeneralAuthoringDTO.setActivityTitle(mcContent.getTitle()); - mcGeneralAuthoringDTO.setActivityInstructions(mcContent.getInstructions()); - request.setAttribute(MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - } - - /** - */ - protected void repopulateRequestParameters(HttpServletRequest request, McMonitoringForm mcMonitoringForm, - McGeneralMonitoringDTO mcGeneralMonitoringDTO) { - - String toolContentID = request.getParameter(TOOL_CONTENT_ID); - mcMonitoringForm.setToolContentID(toolContentID); - mcGeneralMonitoringDTO.setToolContentID(toolContentID); - - String activeModule = request.getParameter(ACTIVE_MODULE); - mcMonitoringForm.setActiveModule(activeModule); - mcGeneralMonitoringDTO.setActiveModule(activeModule); - - String defineLaterInEditMode = request.getParameter(DEFINE_LATER_IN_EDIT_MODE); - mcMonitoringForm.setDefineLaterInEditMode(defineLaterInEditMode); - mcGeneralMonitoringDTO.setDefineLaterInEditMode(defineLaterInEditMode); - - String responseId = request.getParameter(RESPONSE_ID); - mcMonitoringForm.setResponseId(responseId); - mcGeneralMonitoringDTO.setResponseId(responseId); - - String currentUid = request.getParameter(CURRENT_UID); - mcMonitoringForm.setCurrentUid(currentUid); - mcGeneralMonitoringDTO.setCurrentUid(currentUid); - } - - /** - * - */ - protected void setupCommonScreenData(McContent mcContent, IMcService mcService, HttpServletRequest request) { - /* setting up USER_EXCEPTION_NO_TOOL_SESSIONS, from here */ - McGeneralMonitoringDTO mcGeneralMonitoringDTO = new McGeneralMonitoringDTO(); - mcGeneralMonitoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - if (mcService.studentActivityOccurredGlobal(mcContent)) { - mcGeneralMonitoringDTO.setUserExceptionNoToolSessions(new Boolean(false).toString()); - } else { - mcGeneralMonitoringDTO.setUserExceptionNoToolSessions(new Boolean(true).toString()); - } - - request.setAttribute(MC_GENERAL_MONITORING_DTO, mcGeneralMonitoringDTO); - /* .. till here */ - - /* find out if there are any reflection entries, from here */ - boolean notebookEntriesExist = MonitoringUtil.notebookEntriesExist(mcService, mcContent); - - if (notebookEntriesExist) { - request.setAttribute(NOTEBOOK_ENTRIES_EXIST, new Boolean(true).toString()); - - String userExceptionNoToolSessions = (String) mcGeneralMonitoringDTO.getUserExceptionNoToolSessions(); - - if (userExceptionNoToolSessions.equals("true")) { - // there are no online student activity but there are reflections - request.setAttribute(NO_SESSIONS_NOTEBOOK_ENTRIES_EXIST, new Boolean(true).toString()); - } - } else { - request.setAttribute(NOTEBOOK_ENTRIES_EXIST, new Boolean(false).toString()); - } - /* ... till here */ - - MonitoringUtil.setSessionUserCount(mcContent, mcGeneralMonitoringDTO); - List listAllGroupsDTO = MonitoringUtil.buildGroupBasedSessionData(mcContent, mcService); - request.setAttribute(LIST_ALL_GROUPS_DTO, listAllGroupsDTO); - MonitoringUtil.setupAllSessionsData(request, mcContent, mcService); - } - - /** * downloadMarks */ public ActionForward downloadMarks(ActionMapping mapping, ActionForm form, HttpServletRequest request, @@ -2571,7 +191,7 @@ IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); String toolContentID = mcMonitoringForm.getToolContentID(); - McContent mcContent = mcService.retrieveMc(new Long(toolContentID)); + McContent mcContent = mcService.getMcContent(new Long(toolContentID)); byte[] spreadsheet = null; @@ -2616,7 +236,7 @@ IMcService service = McServiceProxy.getMcService(getServlet().getServletContext()); Long contentID = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID); - McContent mcContent = service.retrieveMc(contentID); + McContent mcContent = service.getMcContent(contentID); Long dateParameter = WebUtil.readLongParam(request, McAppConstants.ATTR_SUBMISSION_DEADLINE, true); Date tzSubmissionDeadline = null; @@ -2676,6 +296,20 @@ // ************************************************************************************* /** + */ + protected void repopulateRequestParameters(HttpServletRequest request, McMonitoringForm mcMonitoringForm, + McGeneralMonitoringDTO mcGeneralMonitoringDTO) { + + String toolContentID = request.getParameter(TOOL_CONTENT_ID); + mcMonitoringForm.setToolContentID(toolContentID); + mcGeneralMonitoringDTO.setToolContentID(toolContentID); + + String responseId = request.getParameter(RESPONSE_ID); + mcMonitoringForm.setResponseId(responseId); + mcGeneralMonitoringDTO.setResponseId(responseId); + } + + /** * Return ResourceService bean. */ private MessageService getMessageService() { Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McMonitoringForm.java =================================================================== diff -u -r3f7d82f8f5d0c6881eb83f9ce8c36720e9756649 -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McMonitoringForm.java (.../McMonitoringForm.java) (revision 3f7d82f8f5d0c6881eb83f9ce8c36720e9756649) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McMonitoringForm.java (.../McMonitoringForm.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -22,20 +22,15 @@ /* $$Id$$ */ package org.lamsfoundation.lams.tool.mc.web; -import org.lamsfoundation.lams.tool.mc.McAppConstants; /** - * @author Ozgur Demirtas + * ActionForm for the Monitoring environment * - * ActionForm for the Monitoring environment + * @author Ozgur Demirtas */ -public class McMonitoringForm extends McAuthoringForm implements McAppConstants { +public class McMonitoringForm extends McAuthoringForm { protected String method; - private String currentUid; - - private String editResponse; - /** * @return Returns the method. */ @@ -50,34 +45,4 @@ public void setMethod(String method) { this.method = method; } - - /** - * @return Returns the currentUid. - */ - public String getCurrentUid() { - return currentUid; - } - - /** - * @param currentUid - * The currentUid to set. - */ - public void setCurrentUid(String currentUid) { - this.currentUid = currentUid; - } - - /** - * @return Returns the editResponse. - */ - public String getEditResponse() { - return editResponse; - } - - /** - * @param editResponse - * The editResponse to set. - */ - public void setEditResponse(String editResponse) { - this.editResponse = editResponse; - } } Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McMonitoringStarterAction.java =================================================================== diff -u -rbe07c35c372d904a65581d98660e73f3b13b69db -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McMonitoringStarterAction.java (.../McMonitoringStarterAction.java) (revision be07c35c372d904a65581d98660e73f3b13b69db) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McMonitoringStarterAction.java (.../McMonitoringStarterAction.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -23,7 +23,6 @@ package org.lamsfoundation.lams.tool.mc.web; import java.io.IOException; -import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -39,13 +38,12 @@ import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; -import org.lamsfoundation.lams.tool.mc.EditActivityDTO; import org.lamsfoundation.lams.tool.mc.McAppConstants; import org.lamsfoundation.lams.tool.mc.McApplicationException; import org.lamsfoundation.lams.tool.mc.McComparator; import org.lamsfoundation.lams.tool.mc.McGeneralAuthoringDTO; import org.lamsfoundation.lams.tool.mc.McGeneralMonitoringDTO; -import org.lamsfoundation.lams.tool.mc.McQuestionContentDTO; +import org.lamsfoundation.lams.tool.mc.McQuestionDTO; import org.lamsfoundation.lams.tool.mc.McUtils; import org.lamsfoundation.lams.tool.mc.ReflectionDTO; import org.lamsfoundation.lams.tool.mc.pojos.McContent; @@ -57,9 +55,7 @@ import org.lamsfoundation.lams.web.util.SessionMap; /** - *

* Starts up the monitoring module - *

* * @author Ozgur Demirtas */ @@ -88,27 +84,23 @@ throw (e); } - McContent mcContent = service.retrieveMc(new Long(toolContentID)); + McContent mcContent = service.getMcContent(new Long(toolContentID)); mcGeneralMonitoringDTO.setToolContentID(toolContentID.toString()); mcGeneralMonitoringDTO.setActivityTitle(mcContent.getTitle()); mcGeneralMonitoringDTO.setActivityInstructions(mcContent.getInstructions()); mcGeneralMonitoringDTO.setCurrentMonitoringTab("summary"); - mcGeneralMonitoringDTO.setSbmtSuccess(new Boolean(false).toString()); - mcGeneralMonitoringDTO.setDefineLaterInEditMode(new Boolean(false).toString()); mcGeneralMonitoringDTO.setRequestLearningReport(new Boolean(false).toString()); mcGeneralMonitoringDTO.setUserExceptionNoToolSessions(new Boolean(true).toString()); /* * get the questions section is needed for the Edit tab's View Only mode */ - List listQuestionContentDTO = new LinkedList(); - Map mapOptionsContent = new TreeMap(new McComparator()); + List listQuestionContentDTO = new LinkedList(); Long mapIndex = new Long(1); for (McQueContent question : (Set)mcContent.getMcQueContents()) { - McQuestionContentDTO mcContentDTO = new McQuestionContentDTO(); + McQuestionDTO mcContentDTO = new McQuestionDTO(); if (question != null) { - mapOptionsContent.put(mapIndex.toString(), question.getQuestion()); mcContentDTO.setQuestion(question.getQuestion()); mcContentDTO.setDisplayOrder(question.getDisplayOrder().toString()); @@ -117,9 +109,8 @@ mapIndex = new Long(mapIndex.longValue() + 1); } } - mcGeneralMonitoringDTO.setMapOptionsContent(mapOptionsContent); - request.setAttribute(LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); + request.setAttribute(LIST_QUESTION_DTOS, listQuestionContentDTO); request.setAttribute(TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); mcGeneralMonitoringDTO.setExistsOpenMcs(new Boolean(false).toString()); @@ -137,33 +128,21 @@ mcMonitoringForm.setCurrentTab("1"); mcGeneralMonitoringDTO.setCurrentTab("1"); - mcMonitoringForm.setActiveModule(MONITORING); - mcGeneralMonitoringDTO.setActiveModule(MONITORING); mcGeneralMonitoringDTO.setIsPortfolioExport(new Boolean(false).toString()); /* this section is needed for Edit Activity screen, from here... */ mcGeneralAuthoringDTO.setActivityTitle(mcGeneralMonitoringDTO.getActivityTitle()); mcGeneralAuthoringDTO.setActivityInstructions(mcGeneralMonitoringDTO.getActivityInstructions()); - mcGeneralAuthoringDTO.setActiveModule(MONITORING); request.setAttribute(MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - - McMonitoringAction monitoringAction = new McMonitoringAction(); monitoringAction.repopulateRequestParameters(request, mcMonitoringForm, mcGeneralMonitoringDTO); mcGeneralMonitoringDTO.setRequestLearningReport(new Boolean(false).toString()); - mcGeneralMonitoringDTO.setSummaryToolSessions(monitoringAction.populateToolSessions(mcContent)); + mcGeneralMonitoringDTO.setSummaryToolSessions(MonitoringUtil.populateToolSessions(mcContent)); mcGeneralMonitoringDTO.setDisplayAnswers(new Boolean(mcContent.isDisplayAnswers()).toString()); - boolean isContentInUse = McUtils.isContentInUse(mcContent); - mcGeneralMonitoringDTO.setIsMonitoredContentInUse(new Boolean(false).toString()); - if (isContentInUse == true) { - // monitoring url does not allow editActivity since the content is in use - mcGeneralMonitoringDTO.setIsMonitoredContentInUse(new Boolean(true).toString()); - } - List reflectionsContainerDTO = service.getReflectionList(mcContent, null); request.setAttribute(REFLECTIONS_CONTAINER_DTO, reflectionsContainerDTO); @@ -177,12 +156,6 @@ request.setAttribute(MC_GENERAL_MONITORING_DTO, mcGeneralMonitoringDTO); - EditActivityDTO editActivityDTO = new EditActivityDTO(); - if (isContentInUse == true) { - editActivityDTO.setMonitoredContentInUse(new Boolean(true).toString()); - } - request.setAttribute(EDIT_ACTIVITY_DTO, editActivityDTO); - // find out if there are any reflection entries if (!reflectionsContainerDTO.isEmpty()) { request.setAttribute(NOTEBOOK_ENTRIES_EXIST, new Boolean(true).toString()); Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McPedagogicalPlannerAction.java =================================================================== diff -u -rc369c0326857e08851d03a29d39d4337091f5253 -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McPedagogicalPlannerAction.java (.../McPedagogicalPlannerAction.java) (revision c369c0326857e08851d03a29d39d4337091f5253) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McPedagogicalPlannerAction.java (.../McPedagogicalPlannerAction.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -41,7 +41,7 @@ import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionMessages; import org.lamsfoundation.lams.tool.mc.McAppConstants; -import org.lamsfoundation.lams.tool.mc.McCandidateAnswersDTO; +import org.lamsfoundation.lams.tool.mc.McOptionDTO; import org.lamsfoundation.lams.tool.mc.pojos.McContent; import org.lamsfoundation.lams.tool.mc.pojos.McOptsContent; import org.lamsfoundation.lams.tool.mc.pojos.McQueContent; @@ -65,7 +65,7 @@ HttpServletResponse response) { McPedagogicalPlannerForm plannerForm = (McPedagogicalPlannerForm) form; Long toolContentID = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID); - McContent mcContent = getMcService().retrieveMc(toolContentID); + McContent mcContent = getMcService().getMcContent(toolContentID); plannerForm.fillForm(mcContent, getMcService()); String contentFolderId = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); plannerForm.setContentFolderID(contentFolderId); @@ -80,18 +80,18 @@ ActionMessages errors = plannerForm.validate(request); if (errors.isEmpty()) { - McContent mcContent = getMcService().retrieveMc(plannerForm.getToolContentID()); + McContent mcContent = getMcService().getMcContent(plannerForm.getToolContentID()); int questionIndex = 1; String question = null; do { question = plannerForm.getQuestion(questionIndex - 1); - List candidateAnswerDTOList = plannerForm.extractCandidateAnswers(request, + List candidateAnswerDTOList = plannerForm.extractCandidateAnswers(request, questionIndex); boolean removeQuestion = true; if (!StringUtils.isEmpty(question)) { if (candidateAnswerDTOList != null) { - for (McCandidateAnswersDTO answer : candidateAnswerDTOList) { + for (McOptionDTO answer : candidateAnswerDTOList) { if (answer != null && !StringUtils.isEmpty(answer.getCandidateAnswer())) { removeQuestion = false; break; @@ -114,7 +114,7 @@ if (candidateAnswerDTOIndex >= candidateAnswerDTOList.size()) { candidateAnswerIter.remove(); } else { - McCandidateAnswersDTO answerDTO = candidateAnswerDTOList.get(candidateAnswerDTOIndex); + McOptionDTO answerDTO = candidateAnswerDTOList.get(candidateAnswerDTOIndex); candidateAnswer.setCorrectOption(McAppConstants.CORRECT.equals(answerDTO.getCorrect())); candidateAnswer.setMcQueOptionText(answerDTO.getCandidateAnswer()); getMcService().updateMcOptionsContent(candidateAnswer); @@ -131,7 +131,7 @@ mcQueContent.setMark(McAppConstants.QUESTION_DEFAULT_MARK); Set candidateAnswers = mcQueContent.getMcOptionsContents(); for (int candidateAnswerDTOIndex = 0; candidateAnswerDTOIndex < candidateAnswerDTOList.size(); candidateAnswerDTOIndex++) { - McCandidateAnswersDTO answerDTO = candidateAnswerDTOList.get(candidateAnswerDTOIndex); + McOptionDTO answerDTO = candidateAnswerDTOList.get(candidateAnswerDTOIndex); McOptsContent candidateAnswer = new McOptsContent(candidateAnswerDTOIndex + 1, McAppConstants.CORRECT.equals(answerDTO.getCorrect()), answerDTO.getCandidateAnswer(), mcQueContent); Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McPedagogicalPlannerForm.java =================================================================== diff -u -r8ddb4345fdfc8904e5a7ff156cc63053e63741ca -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McPedagogicalPlannerForm.java (.../McPedagogicalPlannerForm.java) (revision 8ddb4345fdfc8904e5a7ff156cc63053e63741ca) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McPedagogicalPlannerForm.java (.../McPedagogicalPlannerForm.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -36,8 +36,8 @@ import org.apache.struts.action.ActionMessage; import org.apache.struts.action.ActionMessages; import org.lamsfoundation.lams.tool.mc.McAppConstants; -import org.lamsfoundation.lams.tool.mc.McCandidateAnswersDTO; -import org.lamsfoundation.lams.tool.mc.McQuestionContentDTO; +import org.lamsfoundation.lams.tool.mc.McOptionDTO; +import org.lamsfoundation.lams.tool.mc.McQuestionDTO; import org.lamsfoundation.lams.tool.mc.pojos.McContent; import org.lamsfoundation.lams.tool.mc.service.IMcService; import org.lamsfoundation.lams.web.planner.PedagogicalPlannerActivityForm; @@ -68,12 +68,12 @@ for (String item : question) { if (item != null || !StringUtils.isEmpty(item)) { try { - List candidateAnswerList = extractCandidateAnswers(request, + List candidateAnswerList = extractCandidateAnswers(request, questionIndex); if (candidateAnswerList != null) { boolean answersEmpty = true; ActionMessage correctAnswerBlankError = null; - for (McCandidateAnswersDTO answer : candidateAnswerList) { + for (McOptionDTO answer : candidateAnswerList) { if (answer != null && !StringUtils.isEmpty(answer.getCandidateAnswer())) { allEmpty = false; answersEmpty = false; @@ -114,7 +114,7 @@ setCandidateAnswersString(candidateAnswersBuilder.toString()); for (int questionIndex = 1; questionIndex <= getQuestionCount(); questionIndex++) { Object param = paramMap.get(McAppConstants.CANDIDATE_ANSWER_COUNT + questionIndex); - int count = NumberUtils.stringToInt(((String[]) param)[0]); + int count = NumberUtils.toInt(((String[]) param)[0]); getCandidateAnswerCount().add(count); } } @@ -127,21 +127,20 @@ if (mcContent != null) { setToolContentID(mcContent.getMcContentId()); - AuthoringUtil authoringUtil = new AuthoringUtil(); - List questions = authoringUtil.buildDefaultQuestionContent(mcContent, mcService); + List questionDtos = AuthoringUtil.buildDefaultQuestions(mcContent, mcService); StringBuilder candidateAnswersBuilder = new StringBuilder(); - setCandidateAnswerCount(new ArrayList(questions.size())); - for (int questionIndex = 1; questionIndex <= questions.size(); questionIndex++) { - McQuestionContentDTO item = questions.get(questionIndex - 1); + setCandidateAnswerCount(new ArrayList(questionDtos.size())); + for (int questionIndex = 1; questionIndex <= questionDtos.size(); questionIndex++) { + McQuestionDTO item = questionDtos.get(questionIndex - 1); int questionDisplayOrder = Integer.parseInt(item.getDisplayOrder()); String questionText = item.getQuestion(); setQuestion(questionDisplayOrder - 1, questionText); - List candidateAnswers = item.getListCandidateAnswersDTO(); + List candidateAnswers = item.getListCandidateAnswersDTO(); for (int candidateAnswerIndex = 1; candidateAnswerIndex <= candidateAnswers.size(); candidateAnswerIndex++) { - McCandidateAnswersDTO candidateAnswer = candidateAnswers.get(candidateAnswerIndex - 1); + McOptionDTO candidateAnswer = candidateAnswers.get(candidateAnswerIndex - 1); candidateAnswersBuilder.append(McAppConstants.CANDIDATE_ANSWER_PREFIX).append(questionDisplayOrder) .append('-').append(candidateAnswerIndex).append('=') @@ -193,19 +192,19 @@ candidateAnswersString = candidateAnswers; } - public List extractCandidateAnswers(HttpServletRequest request, int questionIndex) + public List extractCandidateAnswers(HttpServletRequest request, int questionIndex) throws UnsupportedEncodingException { Map paramMap = request.getParameterMap(); Object param = paramMap.get(McAppConstants.CANDIDATE_ANSWER_COUNT + questionIndex); - int count = NumberUtils.stringToInt(((String[]) param)[0]); + int count = NumberUtils.toInt(((String[]) param)[0]); int correct = Integer.parseInt(getCorrect(questionIndex - 1)); - List candidateAnswerList = new ArrayList(); + List candidateAnswerList = new ArrayList(); for (int index = 1; index <= count; index++) { param = paramMap.get(McAppConstants.CANDIDATE_ANSWER_PREFIX + questionIndex + "-" + index); String answer = ((String[]) param)[0]; if (answer != null) { - McCandidateAnswersDTO candidateAnswer = new McCandidateAnswersDTO(); + McOptionDTO candidateAnswer = new McOptionDTO(); candidateAnswer.setCandidateAnswer(answer); if (index == correct) { candidateAnswer.setCorrect(McAppConstants.CORRECT); Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McStarterAction.java =================================================================== diff -u -rbe07c35c372d904a65581d98660e73f3b13b69db -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McStarterAction.java (.../McStarterAction.java) (revision be07c35c372d904a65581d98660e73f3b13b69db) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McStarterAction.java (.../McStarterAction.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -21,116 +21,21 @@ * **************************************************************** */ -/** - * @author Ozgur Demirtas - * - * Created on 8/03/2005 - * - */ - -/** - * Tool path The URL path for the tool should be /tool/$TOOL_SIG. - * - * McStarterAction loads the default content and initializes the presentation Map - * Requests can come either from authoring envuironment or from the monitoring environment for Edit Activity screen - * - * Check McUtils.createAuthoringUser again User Management Service is ready - * - * */ - -/** - * - * Tool Content: - * - * While tool's manage their own content, the LAMS core and the tools work together to create and use the content. - * The tool content id (toolContentID) is the key by which the tool and the LAMS core discuss data - - * it is generated by the LAMS core and supplied to the tool whenever content needs to be stored. - * The LAMS core will refer to the tool content id whenever the content needs to be used. - * Tool content will be covered in more detail in following sections. - * - * Each tool will have one piece of content that is the default content. - * The tool content id for this content is created as part of the installation process. - * Whenever a tool is asked for some tool content that does not exist, it should supply the default tool content. - * This will allow the system to render the normal screen, albeit with useless information, rather than crashing. - */ - -/** - * - * Authoring URL: - * - * The tool must supply an authoring module, which will be called to create new content or edit existing content. It will be called by an authoring URL using the following format: ????? - * The initial data displayed on the authoring screen for a new tool content id may be the default tool content. - * - * Authoring UI data consists of general Activity data fields and the Tool specific data fields. - * The authoring interface will have three tabs. The mandatory (and suggested) fields are given. Each tool will have its own fields which it will add on any of the three tabs, as appropriate to the tabs' function. - * - * Basic: Displays the basic set of fields that are needed for the tool, and it could be expected that a new LAMS user would use. Mandatory fields: Title, Instructions. - * Advanced: Displays the extra fields that would be used by experienced LAMS users. Optional fields: Lock On Finish, Make Responses Anonymous - * Instructions: Displays the "instructions" fields for teachers. Mandatory fields: Online instructions, Offline instructions, Document upload. - * The "Define Later" and "Run Offline" options are set on the Flash authoring part, and not on the tool's authoring screens. - * - * Preview The tool must be able to show the specified content as if it was running in a lesson. It will be the learner url with tool access mode set to ToolAccessMode.AUTHOR. - * Export The tool must be able to export its tool content for part of the overall learning design export. - * - * The format of the serialization for export is XML. Tool will define extra namespace inside the element to add a new data element (type). Inside the data element, it can further define more structures and types as it seems fit. - * The data elements must be "version" aware. The data elements must be "type" aware if they are to be shared between Tools. - * - * - - - - - - - - - - - - - - - - * - */ - /* $$Id$$ */ package org.lamsfoundation.lams.tool.mc.web; import java.io.IOException; import java.util.ArrayList; -import java.util.LinkedList; +import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.TreeMap; +import java.util.TreeSet; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import org.apache.struts.Globals; import org.apache.struts.action.Action; @@ -139,26 +44,28 @@ import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionMessage; import org.apache.struts.action.ActionMessages; +import org.lamsfoundation.lams.tool.ToolAccessMode; import org.lamsfoundation.lams.tool.mc.McAppConstants; import org.lamsfoundation.lams.tool.mc.McApplicationException; -import org.lamsfoundation.lams.tool.mc.McComparator; import org.lamsfoundation.lams.tool.mc.McGeneralAuthoringDTO; +import org.lamsfoundation.lams.tool.mc.McQuestionDTO; import org.lamsfoundation.lams.tool.mc.McUtils; import org.lamsfoundation.lams.tool.mc.pojos.McContent; +import org.lamsfoundation.lams.tool.mc.pojos.McOptsContent; +import org.lamsfoundation.lams.tool.mc.pojos.McQueContent; import org.lamsfoundation.lams.tool.mc.service.IMcService; import org.lamsfoundation.lams.tool.mc.service.McServiceProxy; import org.lamsfoundation.lams.util.WebUtil; import org.lamsfoundation.lams.web.util.AttributeNames; import org.lamsfoundation.lams.web.util.SessionMap; /** + * A Map data structure is used to present the UI. * * @author Ozgur Demirtas - * - * A Map data structure is used to present the UI. */ public class McStarterAction extends Action implements McAppConstants { - static Logger logger = Logger.getLogger(McStarterAction.class.getName()); + private static Logger logger = Logger.getLogger(McStarterAction.class.getName()); public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException, McApplicationException { @@ -172,8 +79,6 @@ McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); - Map mapQuestionContent = new TreeMap(new McComparator()); - mcAuthoringForm.resetRadioBoxes(); IMcService mcService = null; @@ -185,129 +90,64 @@ mcGeneralAuthoringDTO.setCurrentTab("1"); - mcGeneralAuthoringDTO.setMonitoringOriginatedDefineLater(new Boolean(false).toString()); - String servletPath = request.getServletPath(); - String requestedModule = null; - if (servletPath.indexOf("authoringStarter") > 0) { - // request is for authoring module - mcGeneralAuthoringDTO.setActiveModule(AUTHORING); - mcGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - mcGeneralAuthoringDTO.setShowAuthoringTabs(new Boolean(true).toString()); - mcAuthoringForm.setActiveModule(AUTHORING); - requestedModule = AUTHORING; - } else { - // request is for define later module either direcly from define later url or monitoring url - mcGeneralAuthoringDTO.setActiveModule(DEFINE_LATER); - mcGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - mcGeneralAuthoringDTO.setShowAuthoringTabs(new Boolean(false).toString()); - mcAuthoringForm.setActiveModule(DEFINE_LATER); - requestedModule = DEFINE_LATER; - - if (servletPath.indexOf("monitoring") > 0) { - // request is from monitoring url - mcGeneralAuthoringDTO.setMonitoringOriginatedDefineLater(new Boolean(true).toString()); - } - } - mcGeneralAuthoringDTO.setRequestedModule(requestedModule); - - String sourceMcStarter = (String) request.getAttribute(SOURCE_MC_STARTER); - - boolean validateSignature = readSignature(request, mapping, mcService, mcGeneralAuthoringDTO, mcAuthoringForm); + boolean validateSignature = validateDefaultContent(request, mapping, mcService, mcGeneralAuthoringDTO, mcAuthoringForm); if (validateSignature == false) { logger.debug("error during validation"); } - /* mark the http session as an authoring activity */ - mcGeneralAuthoringDTO.setTargetMode(TARGET_MODE_AUTHORING); - - /* - * find out whether the request is coming from monitoring module for EditActivity tab or from authoring - * environment url - */ - String strToolContentID = ""; /* the authoring url must be passed a tool content id */ - strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); + String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); mcGeneralAuthoringDTO.setToolContentID(strToolContentID); - SessionMap sessionMap = new SessionMap(); - List sequentialCheckedCa = new LinkedList(); + ToolAccessMode mode = getAccessMode(request); + // request is from monitoring module + if (mode.isTeacher()) { + McUtils.setDefineLater(request, true, strToolContentID, mcService); + } + request.setAttribute(AttributeNames.ATTR_MODE, mode.toString()); + + SessionMap sessionMap = new SessionMap(); sessionMap.put(ACTIVITY_TITLE_KEY, ""); sessionMap.put(ACTIVITY_INSTRUCTIONS_KEY, ""); mcAuthoringForm.setHttpSessionID(sessionMap.getSessionID()); mcGeneralAuthoringDTO.setHttpSessionID(sessionMap.getSessionID()); + request.getSession().setAttribute(sessionMap.getSessionID(), sessionMap); - String defaultContentId = null; - if (strToolContentID == null) { - /* - * it is possible that the original request for authoring module is coming from monitoring url which keeps - * the TOOL_CONTENT_ID in the session - */ - - Long toolContentID = (Long) request.getSession().getAttribute(TOOL_CONTENT_ID); - if (toolContentID != null) { - strToolContentID = toolContentID.toString(); - // cached strToolContentID from the session - } else { - // we should IDEALLY not arrive here. The TOOL_CONTENT_ID is NOT available from the url or the session. - /* use default content instead of giving a warning */ - defaultContentId = mcAuthoringForm.getDefaultContentIdStr(); - strToolContentID = defaultContentId; - } - } - if ((strToolContentID == null) || (strToolContentID.equals(""))) { McUtils.cleanUpSessionAbsolute(request); - // return (mapping.findForward(ERROR_LIST)); + return (mapping.findForward(ERROR_LIST)); } mcAuthoringForm.setToolContentID(strToolContentID); - - /* - * find out if the passed tool content id exists in the db present user either a first timer screen with default - * content data or fetch the existing content. - * - * if the toolcontentid does not exist in the db, create the default Map, there is no need to check if the - * content is locked in this case. It is always unlocked since it is the default content. - */ - - String defaultContentIdStr = null; - McContent mcContent = null; - if (!existsContent(new Long(strToolContentID).longValue(), mcService)) { - /* fetch default content */ - defaultContentIdStr = mcAuthoringForm.getDefaultContentIdStr(); - mcContent = retrieveContent(request, mapping, mcAuthoringForm, mapQuestionContent, new Long( - defaultContentIdStr).longValue(), true, mcService, mcGeneralAuthoringDTO, sessionMap); - - } else { - /* it is possible that the content is in use by learners. */ - mcContent = mcService.retrieveMc(new Long(strToolContentID)); - - if (mcService.studentActivityOccurredGlobal(mcContent)) { - McUtils.cleanUpSessionAbsolute(request); - } - mcContent = retrieveContent(request, mapping, mcAuthoringForm, mapQuestionContent, new Long( - strToolContentID).longValue(), false, mcService, mcGeneralAuthoringDTO, sessionMap); + + McContent mcContent = mcService.getMcContent(new Long(strToolContentID)); + + // if mcContent does not exist, try to use default content instead. + if (mcContent == null) { + long defaultContentID = mcService.getToolDefaultContentIdBySignature(MY_SIGNATURE); + mcContent = mcService.getMcContent(new Long(defaultContentID)); + mcContent = McContent.newInstance(mcContent, new Long(strToolContentID)); } + + prepareDTOandForm(request, mapping, mcAuthoringForm, new Long(strToolContentID).longValue(), + mcContent, mcGeneralAuthoringDTO, sessionMap); - String destination = McUtils.getDestination(sourceMcStarter, requestedModule); - Map mapQuestionContentLocal = mcGeneralAuthoringDTO.getMapQuestionContent(); - sessionMap.put(MAP_QUESTION_CONTENT_KEY, mapQuestionContent); + List questionDtos = AuthoringUtil.buildDefaultQuestions(mcContent, mcService); + request.setAttribute(TOTAL_QUESTION_COUNT, new Integer(questionDtos.size())); + request.setAttribute(LIST_QUESTION_DTOS, questionDtos); + sessionMap.put(LIST_QUESTION_DTOS, questionDtos); + + List listDeletedQuestionDTOs = new ArrayList(); + sessionMap.put(LIST_DELETED_QUESTION_DTOS, listDeletedQuestionDTOs); - AuthoringUtil authoringUtil = new AuthoringUtil(); - List listAddableQuestionContentDTO = authoringUtil.buildDefaultQuestionContent(mcContent, mcService); - sessionMap.put(NEW_ADDABLE_QUESTION_CONTENT_KEY, listAddableQuestionContentDTO); - - request.getSession().setAttribute(sessionMap.getSessionID(), sessionMap); - - Map marksMap = authoringUtil.buildMarksMap(); + Map marksMap = AuthoringUtil.buildMarksMap(); mcGeneralAuthoringDTO.setMarksMap(marksMap); mcGeneralAuthoringDTO.setMarkValue("1"); - List listQuestionContentDTOLocal = authoringUtil.buildDefaultQuestionContent(mcContent, mcService); - Map passMarksMap = authoringUtil.buildDynamicPassMarkMap(listQuestionContentDTOLocal, true); + Map passMarksMap = AuthoringUtil.buildDynamicPassMarkMap(questionDtos, true); mcGeneralAuthoringDTO.setPassMarksMap(passMarksMap); - String totalMark = AuthoringUtil.getTotalMark(listQuestionContentDTOLocal); + String totalMark = AuthoringUtil.getTotalMark(questionDtos); mcAuthoringForm.setTotalMarks(totalMark); mcGeneralAuthoringDTO.setTotalMarks(totalMark); @@ -318,16 +158,16 @@ mcGeneralAuthoringDTO.setPassMarkValue(passMark); - Map correctMap = authoringUtil.buildCorrectMap(); + Map correctMap = AuthoringUtil.buildCorrectMap(); mcGeneralAuthoringDTO.setCorrectMap(correctMap); request.setAttribute(MC_GENERAL_AUTHORING_DTO, mcGeneralAuthoringDTO); - return (mapping.findForward(destination)); + return (mapping.findForward(LOAD_AUTHORING)); } /** - * retrives the existing content information from the db and prepares the data for presentation purposes. + * prepares the data for presentation purposes. * * @param request * @param mapping @@ -336,10 +176,9 @@ * @param toolContentID * @return ActionForward */ - protected McContent retrieveContent(HttpServletRequest request, ActionMapping mapping, - McAuthoringForm mcAuthoringForm, Map mapQuestionContent, long toolContentID, boolean isDefaultContent, - IMcService mcService, McGeneralAuthoringDTO mcGeneralAuthoringDTO, SessionMap sessionMap) { - McContent mcContent = mcService.retrieveMc(new Long(toolContentID)); + protected McContent prepareDTOandForm(HttpServletRequest request, ActionMapping mapping, + McAuthoringForm mcAuthoringForm, long toolContentID, McContent mcContent, + McGeneralAuthoringDTO mcGeneralAuthoringDTO, SessionMap sessionMap) { McUtils.populateAuthoringDTO(request, mcContent, mcGeneralAuthoringDTO); @@ -363,8 +202,6 @@ mcGeneralAuthoringDTO.setReflect(mcContent.isReflect() ? "1" : "0"); mcGeneralAuthoringDTO.setReflectionSubject(mcContent.getReflectionSubject()); - mcGeneralAuthoringDTO.setIsDefineLater(new Boolean(mcContent.isDefineLater()).toString()); - mcGeneralAuthoringDTO.setActivityTitle(mcContent.getTitle()); mcAuthoringForm.setTitle(mcContent.getTitle()); @@ -374,21 +211,6 @@ sessionMap.put(ACTIVITY_TITLE_KEY, mcGeneralAuthoringDTO.getActivityTitle()); sessionMap.put(ACTIVITY_INSTRUCTIONS_KEY, mcGeneralAuthoringDTO.getActivityInstructions()); - AuthoringUtil authoringUtil = new AuthoringUtil(); - List listQuestionContentDTO = authoringUtil.buildDefaultQuestionContent(mcContent, mcService); - - request.setAttribute(TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); - request.setAttribute(LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - sessionMap.put(LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - - if (isDefaultContent) { - // overwriting default question - mcGeneralAuthoringDTO.setDefaultQuestionContent("Sample Question 1?"); - - } - - mcGeneralAuthoringDTO.setMapQuestionContent(mapQuestionContent); - mcAuthoringForm.resetUserAction(); return mcContent; } @@ -402,7 +224,7 @@ * @param mapping * @return ActionForward */ - public boolean readSignature(HttpServletRequest request, ActionMapping mapping, IMcService mcService, + private boolean validateDefaultContent(HttpServletRequest request, ActionMapping mapping, IMcService mcService, McGeneralAuthoringDTO mcGeneralAuthoringDTO, McAuthoringForm mcAuthoringForm) { /* * retrieve the default content id based on tool signature @@ -420,61 +242,23 @@ return false; } - /* retrieve uid of the content based on default content id determined above */ - long contentUID = 0; try { - McContent mcContent = mcService.retrieveMc(new Long(defaultContentID)); + McContent mcContent = mcService.getMcContent(new Long(defaultContentID)); if (mcContent == null) { logger.debug("Exception occured: No default content"); persistError(request, "error.defaultContent.notSetup"); return false; } - contentUID = mcContent.getUid().longValue(); } catch (Exception e) { logger.debug("Exception occured: No default question content"); persistError(request, "error.defaultContent.notSetup"); return false; } - mcGeneralAuthoringDTO.setDefaultContentIdStr(new Long(defaultContentID).toString()); - mcAuthoringForm.setDefaultContentIdStr(new Long(defaultContentID).toString()); - return true; } /** - * @param long toolContentID - * @return boolean determine whether a specific toolContentID exists in the db - */ - protected boolean existsContent(long toolContentID, IMcService mcService) { - McContent mcContent = mcService.retrieveMc(new Long(toolContentID)); - if (mcContent == null) - return false; - - return true; - } - - /** - * bridges define later url request to authoring functionality - * - * - * @param mapping - * @param form - * @param request - * @param response - * @param mcService - * @return - * @throws IOException - * @throws ServletException - * @throws McApplicationException - */ - public ActionForward executeDefineLater(ActionMapping mapping, McAuthoringForm mcAuthoringForm, - HttpServletRequest request, HttpServletResponse response, IMcService mcService) throws IOException, - ServletException, McApplicationException { - return execute(mapping, mcAuthoringForm, request, response); - } - - /** * persists error messages to request scope * * @param request @@ -485,4 +269,21 @@ errors.add(Globals.ERROR_KEY, new ActionMessage(message)); saveErrors(request, 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; + } } Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/MonitoringUtil.java =================================================================== diff -u -r6c5d0c6b8ff17d661580df2c265f2dcabfe7d76c -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/MonitoringUtil.java (.../MonitoringUtil.java) (revision 6c5d0c6b8ff17d661580df2c265f2dcabfe7d76c) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/MonitoringUtil.java (.../MonitoringUtil.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -35,17 +35,13 @@ import javax.servlet.http.HttpSession; import org.apache.commons.lang.StringEscapeUtils; -import org.lamsfoundation.lams.notebook.model.NotebookEntry; -import org.lamsfoundation.lams.notebook.service.CoreNotebookConstants; -import org.lamsfoundation.lams.tool.mc.McAllGroupsDTO; import org.lamsfoundation.lams.tool.mc.McAppConstants; -import org.lamsfoundation.lams.tool.mc.McCandidateAnswersDTO; +import org.lamsfoundation.lams.tool.mc.McOptionDTO; import org.lamsfoundation.lams.tool.mc.McGeneralMonitoringDTO; import org.lamsfoundation.lams.tool.mc.McMonitoredAnswersDTO; import org.lamsfoundation.lams.tool.mc.McMonitoredUserDTO; import org.lamsfoundation.lams.tool.mc.McSessionMarkDTO; import org.lamsfoundation.lams.tool.mc.McStringComparator; -import org.lamsfoundation.lams.tool.mc.McUserMarkDTO; import org.lamsfoundation.lams.tool.mc.pojos.McContent; import org.lamsfoundation.lams.tool.mc.pojos.McOptsContent; import org.lamsfoundation.lams.tool.mc.pojos.McQueContent; @@ -90,144 +86,8 @@ } /** - * - * ends up populating the attempt history for all the users of all the tool sessions for a content - * * @param request - * @param mcContent - * @return List - */ - public static List buildGroupsQuestionData(McContent mcContent, IMcService mcService) { - // will be building groups question data for content - - List questions = mcService.getAllQuestionEntries(mcContent.getUid()); - - List monitoredAnswersDTOs = new LinkedList(); - - for (McQueContent question : questions) { - - if (question != null) { - McMonitoredAnswersDTO monitoredAnswersDTO = new McMonitoredAnswersDTO(); - monitoredAnswersDTO.setQuestionUid(question.getUid().toString()); - monitoredAnswersDTO.setQuestion(question.getQuestion()); - monitoredAnswersDTO.setMark(question.getMark().toString()); - - List listCandidateAnswersDTO = mcService.populateCandidateAnswersDTO(question - .getUid()); - monitoredAnswersDTO.setCandidateAnswersCorrect(listCandidateAnswersDTO); - - Map> questionAttemptData = new TreeMap>( - new McStringComparator()); - - for (McSession session : (Set) mcContent.getMcSessions()) { - Set users = session.getMcQueUsers(); - List monitoredUserDTOs = new LinkedList(); - for (McQueUsr user : users) { - McMonitoredUserDTO monitoredUserDTO = getUserAttempt(mcService, user, session, - question.getUid()); - monitoredUserDTOs.add(monitoredUserDTO); - } - - questionAttemptData.put(session.getSession_name(), monitoredUserDTOs); - } - - monitoredAnswersDTO.setQuestionAttempts(questionAttemptData); - monitoredAnswersDTOs.add(monitoredAnswersDTO); - - } - } - return monitoredAnswersDTOs; - } - - /** - * - * @param request - * @param mcContent * @param mcService - * @param mcSession - * @param mcQueUsr - * @return - */ - public static List buildGroupsQuestionDataForExportLearner(McContent mcContent, IMcService mcService, - McSession mcSession, McQueUsr mcQueUsr) { - - List questions = mcService.getAllQuestionEntries(mcContent.getUid()); - - List listMonitoredAnswersContainerDTO = new LinkedList(); - - Iterator itListQuestions = questions.iterator(); - while (itListQuestions.hasNext()) { - McQueContent question = itListQuestions.next(); - - if (question != null) { - McMonitoredAnswersDTO monitoredAnswersDTO = new McMonitoredAnswersDTO(); - monitoredAnswersDTO.setQuestionUid(question.getUid().toString()); - monitoredAnswersDTO.setQuestion(question.getQuestion()); - monitoredAnswersDTO.setMark(question.getMark().toString()); - - List listCandidateAnswersDTO = mcService.populateCandidateAnswersDTO(question.getUid()); - monitoredAnswersDTO.setCandidateAnswersCorrect(listCandidateAnswersDTO); - - // Get the attempts for this user. The maps must match the maps in buildGroupsAttemptData or the jsp - // won't work. - McMonitoredUserDTO mcMonitoredUserDTO = getUserAttempt(mcService, mcQueUsr, mcSession, - question.getUid()); - List listMonitoredUserContainerDTO = new LinkedList(); - listMonitoredUserContainerDTO.add(mcMonitoredUserDTO); - Map questionAttemptData = new TreeMap(new McStringComparator()); - questionAttemptData.put(mcSession.getSession_name(), listMonitoredUserContainerDTO); - - monitoredAnswersDTO.setQuestionAttempts(questionAttemptData); - listMonitoredAnswersContainerDTO.add(monitoredAnswersDTO); - } - } - return listMonitoredAnswersContainerDTO; - } - - /** - * - */ - public static McMonitoredUserDTO getUserAttempt(IMcService mcService, McQueUsr mcQueUsr, - McSession mcSession, Long questionUid) { - - McMonitoredUserDTO mcMonitoredUserDTO = new McMonitoredUserDTO(); - if (mcQueUsr != null) { - mcMonitoredUserDTO.setUserName(mcQueUsr.getFullname()); - mcMonitoredUserDTO.setSessionId(mcSession.getMcSessionId().toString()); - mcMonitoredUserDTO.setQuestionUid(questionUid.toString()); - mcMonitoredUserDTO.setQueUsrId(mcQueUsr.getUid().toString()); - - McUsrAttempt userAttempt = mcService.getUserAttemptByQuestion(mcQueUsr.getUid(), questionUid); - - if (!mcQueUsr.isResponseFinalised() || (userAttempt == null)) { - - mcMonitoredUserDTO.setMark(new Integer(0)); - - } else { - - // At present, we expect there to be only one answer to a question but there - // could be more in the future - if that happens then we need to change - // String to a list of Strings. - - // We get the mark for the attempt if the answer is correct and we don't allow - // retries, or if the answer is correct and the learner has met the passmark if - // we do allow retries. - - String userAnswer = userAttempt.getMcOptionsContent().getMcQueOptionText(); - boolean isRetries = mcSession.getMcContent().isRetries(); - mcMonitoredUserDTO.setMark(userAttempt.getMarkForShow(isRetries)); - mcMonitoredUserDTO.setIsCorrect(new Boolean(userAttempt.isAttemptCorrect()).toString()); - mcMonitoredUserDTO.setUserAnswer(userAnswer); - } - - } - - return mcMonitoredUserDTO; - } - - /** - * @param request - * @param mcService * @param mcContent */ public static void setSessionUserCount(McContent mcContent, McGeneralMonitoringDTO mcGeneralMonitoringDTO) { @@ -254,89 +114,6 @@ } /** - * - * @param mcService - * @param mcContent - * @return - */ - public static boolean notebookEntriesExist(IMcService mcService, McContent mcContent) { - Iterator iteratorSession = mcContent.getMcSessions().iterator(); - while (iteratorSession.hasNext()) { - McSession mcSession = (McSession) iteratorSession.next(); - - if (mcSession != null) { - - Iterator iteratorUser = mcSession.getMcQueUsers().iterator(); - while (iteratorUser.hasNext()) { - McQueUsr mcQueUsr = (McQueUsr) iteratorUser.next(); - - if (mcQueUsr != null) { - NotebookEntry notebookEntry = mcService.getEntry(mcSession.getMcSessionId(), - CoreNotebookConstants.NOTEBOOK_TOOL, MY_SIGNATURE, new Integer(mcQueUsr.getQueUsrId() - .intValue())); - if (notebookEntry != null) { - return true; - } - - } - } - } - } - return false; - } - - /** - * @param request - * @param mcContent - * @param mcService - * @return - */ - public static List buildGroupBasedSessionData(McContent mcContent, IMcService mcService) { - List listQuestions = mcService.getAllQuestionEntries(mcContent.getUid()); - - List listAllGroupsContainerDTO = new LinkedList(); - - Iterator iteratorSession = mcContent.getMcSessions().iterator(); - while (iteratorSession.hasNext()) { - McSession mcSession = (McSession) iteratorSession.next(); - String currentSessionId = mcSession.getMcSessionId().toString(); - - String currentSessionName = mcSession.getSession_name(); - - McAllGroupsDTO mcAllGroupsDTO = new McAllGroupsDTO(); - List listMonitoredAnswersContainerDTO = new LinkedList(); - - if (mcSession != null) { - Iterator itListQuestions = listQuestions.iterator(); - while (itListQuestions.hasNext()) { - McQueContent mcQueContent = (McQueContent) itListQuestions.next(); - - if (mcQueContent != null) { - McMonitoredAnswersDTO mcMonitoredAnswersDTO = new McMonitoredAnswersDTO(); - mcMonitoredAnswersDTO.setQuestionUid(mcQueContent.getUid().toString()); - mcMonitoredAnswersDTO.setQuestion(mcQueContent.getQuestion()); - mcMonitoredAnswersDTO.setSessionId(currentSessionId); - mcMonitoredAnswersDTO.setSessionName(currentSessionName); - - Map questionAttemptData = new TreeMap(); - - mcMonitoredAnswersDTO.setQuestionAttempts(questionAttemptData); - - listMonitoredAnswersContainerDTO.add(mcMonitoredAnswersDTO); - } - } - } - mcAllGroupsDTO.setGroupData(listMonitoredAnswersContainerDTO); - mcAllGroupsDTO.setSessionName(currentSessionName); - mcAllGroupsDTO.setSessionId(currentSessionId); - - listAllGroupsContainerDTO.add(mcAllGroupsDTO); - - } - return listAllGroupsContainerDTO; - } - - /** * Sets up auxiliary parameters. Used by all monitoring action methods. * * @param request @@ -389,4 +166,27 @@ boolean isGroupedActivity = mcService.isGroupedActivity(new Long(content.getMcContentId())); request.setAttribute("isGroupedActivity", isGroupedActivity); } + + /** + * Populates a sorted map of the tool session where the key is the mcSessionId and the value is name of the session. + * If no sessions exists, there will be a single entry "None", otherwise on the end of the list will be the entry + * "All" + */ + public static Map populateToolSessions(McContent mcContent) { + Map sessionsMap = new TreeMap(); + Iterator iter = mcContent.getMcSessions().iterator(); + while (iter.hasNext()) { + McSession elem = (McSession) iter.next(); + sessionsMap.put(elem.getMcSessionId().toString(), elem.getSession_name()); + } + + if (sessionsMap.isEmpty()) { + sessionsMap.put("None", "None"); + } else { + sessionsMap.put("All", "All"); + } + + return sessionsMap; + + } } Fisheye: Tag 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f refers to a dead (removed) revision in file `lams_tool_lamc/web/AuthoringMaincontent.jsp'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f refers to a dead (removed) revision in file `lams_tool_lamc/web/BaseContent.jsp'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f refers to a dead (removed) revision in file `lams_tool_lamc/web/Footer.jsp'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f refers to a dead (removed) revision in file `lams_tool_lamc/web/Header.jsp'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f refers to a dead (removed) revision in file `lams_tool_lamc/web/SystemErrorContent.jsp'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_tool_lamc/web/WEB-INF/struts-config.xml =================================================================== diff -u -rbe07c35c372d904a65581d98660e73f3b13b69db -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/web/WEB-INF/struts-config.xml (.../struts-config.xml) (revision be07c35c372d904a65581d98660e73f3b13b69db) +++ lams_tool_lamc/web/WEB-INF/struts-config.xml (.../struts-config.xml) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -39,16 +39,10 @@ > - - @@ -92,12 +86,6 @@ path="/monitoring/MonitoringMaincontent.jsp" redirect="false" /> - - - - - - - - - - - - - - - - - + /> - - + /> - - - - - - - - + - Index: lams_tool_lamc/web/authoring/AuthoringTabsHolder.jsp =================================================================== diff -u -rbe07c35c372d904a65581d98660e73f3b13b69db -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f --- lams_tool_lamc/web/authoring/AuthoringTabsHolder.jsp (.../AuthoringTabsHolder.jsp) (revision be07c35c372d904a65581d98660e73f3b13b69db) +++ lams_tool_lamc/web/authoring/AuthoringTabsHolder.jsp (.../AuthoringTabsHolder.jsp) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) @@ -12,10 +12,6 @@ tabs.add("label.basic"); tabs.add("label.advanced"); pageContext.setAttribute("tabs", tabs); - - Set tabsBasic = new LinkedHashSet(); - tabsBasic.add("label.basic"); - pageContext.setAttribute("tabsBasic", tabsBasic); %> @@ -65,24 +61,13 @@ var themeName="aqua"; function init() { - - if (document.McAuthoringForm.activeModule.value != 'defineLater') - { - updatePass(document.McAuthoringForm.retries); + updatePass(document.McAuthoringForm.retries); - var tag = document.getElementById("currentTab"); - if(tag.value != "") - selectTab(tag.value); - else - selectTab(1); //select the default tab; - - } else { - var tag = document.getElementById("currentTab"); - if(tag.value != "") - selectTab(tag.value); - else - selectTab(1); //select the default tab; - } + var tag = document.getElementById("currentTab"); + if(tag.value != "") + selectTab(tag.value); + else + selectTab(1); //select the default tab; } function doSelectTab(tabId) { @@ -106,63 +91,34 @@

-
- + - - - Fisheye: Tag 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f refers to a dead (removed) revision in file `lams_tool_lamc/web/monitoring/candidateAnswersAddList.jsp'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f refers to a dead (removed) revision in file `lams_tool_lamc/web/monitoring/candidateAnswersList.jsp'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f refers to a dead (removed) revision in file `lams_tool_lamc/web/monitoring/editQuestionBox.jsp'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f refers to a dead (removed) revision in file `lams_tool_lamc/web/monitoring/itemlist.jsp'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f refers to a dead (removed) revision in file `lams_tool_lamc/web/monitoring/newQuestionBox.jsp'. Fisheye: No comparison available. Pass `N' to diff?