Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/service/IVoteService.java
===================================================================
diff -u -r2abc3485dc2d24ea02044a64271f3ee0d3b8c11b -r571d64337ed3fb6a9733a5214180fd4a5c6d6292
--- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/service/IVoteService.java (.../IVoteService.java) (revision 2abc3485dc2d24ea02044a64271f3ee0d3b8c11b)
+++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/service/IVoteService.java (.../IVoteService.java) (revision 571d64337ed3fb6a9733a5214180fd4a5c6d6292)
@@ -51,6 +51,7 @@
import org.lamsfoundation.lams.tool.vote.pojos.VoteQueUsr;
import org.lamsfoundation.lams.tool.vote.pojos.VoteSession;
import org.lamsfoundation.lams.tool.vote.pojos.VoteUsrAttempt;
+import org.lamsfoundation.lams.tool.vote.util.VoteApplicationException;
import org.lamsfoundation.lams.util.MessageService;
/**
Fisheye: Tag 571d64337ed3fb6a9733a5214180fd4a5c6d6292 refers to a dead (removed) revision in file `lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/service/VoteApplicationException.java'.
Fisheye: No comparison available. Pass `N' to diff?
Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/service/VoteServicePOJO.java
===================================================================
diff -u -r2abc3485dc2d24ea02044a64271f3ee0d3b8c11b -r571d64337ed3fb6a9733a5214180fd4a5c6d6292
--- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/service/VoteServicePOJO.java (.../VoteServicePOJO.java) (revision 2abc3485dc2d24ea02044a64271f3ee0d3b8c11b)
+++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/service/VoteServicePOJO.java (.../VoteServicePOJO.java) (revision 571d64337ed3fb6a9733a5214180fd4a5c6d6292)
@@ -90,9 +90,10 @@
import org.lamsfoundation.lams.tool.vote.pojos.VoteQueUsr;
import org.lamsfoundation.lams.tool.vote.pojos.VoteSession;
import org.lamsfoundation.lams.tool.vote.pojos.VoteUsrAttempt;
+import org.lamsfoundation.lams.tool.vote.util.VoteApplicationException;
import org.lamsfoundation.lams.tool.vote.util.VoteComparator;
import org.lamsfoundation.lams.tool.vote.util.VoteUtils;
-import org.lamsfoundation.lams.tool.vote.web.MonitoringAction;
+import org.lamsfoundation.lams.tool.vote.web.action.MonitoringAction;
import org.lamsfoundation.lams.usermanagement.User;
import org.lamsfoundation.lams.usermanagement.dto.UserDTO;
import org.lamsfoundation.lams.usermanagement.service.IUserManagementService;
Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/util/VoteApplicationException.java
===================================================================
diff -u
--- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/util/VoteApplicationException.java (revision 0)
+++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/util/VoteApplicationException.java (revision 571d64337ed3fb6a9733a5214180fd4a5c6d6292)
@@ -0,0 +1,78 @@
+/***************************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ***********************************************************************/
+
+package org.lamsfoundation.lams.tool.vote.util;
+
+/**
+ *
+ * This exception wraps all basic exception occured in the voting tool. It is
+ * not suppose to be try and catched in any level. The struts should be taking
+ * care of handling this exception.
+ *
+ *
+ * @author Ozgur Demirtas
+ *
+ */
+public class VoteApplicationException extends RuntimeException {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 6708356432970104502L;
+
+ /**
+ * Default Constructor
+ */
+ public VoteApplicationException() {
+ super();
+ }
+
+ /**
+ * Constructor for customized error message
+ *
+ * @param message
+ */
+ public VoteApplicationException(String message) {
+ super(message);
+ }
+
+ /**
+ * Constructor for wrapping the throwable object
+ *
+ * @param cause
+ */
+ public VoteApplicationException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Constructor for wrapping both the customized error message and
+ * throwable exception object.
+ *
+ * @param message
+ * @param cause
+ */
+ public VoteApplicationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
Fisheye: Tag 571d64337ed3fb6a9733a5214180fd4a5c6d6292 refers to a dead (removed) revision in file `lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/AuthoringAction.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 571d64337ed3fb6a9733a5214180fd4a5c6d6292 refers to a dead (removed) revision in file `lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/ClearSessionAction.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 571d64337ed3fb6a9733a5214180fd4a5c6d6292 refers to a dead (removed) revision in file `lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/LearningAction.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 571d64337ed3fb6a9733a5214180fd4a5c6d6292 refers to a dead (removed) revision in file `lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/MonitoringAction.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 571d64337ed3fb6a9733a5214180fd4a5c6d6292 refers to a dead (removed) revision in file `lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/VoteChartGeneratorAction.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 571d64337ed3fb6a9733a5214180fd4a5c6d6292 refers to a dead (removed) revision in file `lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/VotePedagogicalPlannerAction.java'.
Fisheye: No comparison available. Pass `N' to diff?
Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/action/AuthoringAction.java
===================================================================
diff -u
--- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/action/AuthoringAction.java (revision 0)
+++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/action/AuthoringAction.java (revision 571d64337ed3fb6a9733a5214180fd4a5c6d6292)
@@ -0,0 +1,1338 @@
+/***************************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ***********************************************************************/
+
+package org.lamsfoundation.lams.tool.vote.web.action;
+
+import java.io.IOException;
+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.Set;
+import java.util.TreeMap;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+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.authoring.web.AuthoringConstants;
+import org.lamsfoundation.lams.learningdesign.DataFlowObject;
+import org.lamsfoundation.lams.tool.ToolAccessMode;
+import org.lamsfoundation.lams.tool.vote.VoteAppConstants;
+import org.lamsfoundation.lams.tool.vote.dto.VoteGeneralAuthoringDTO;
+import org.lamsfoundation.lams.tool.vote.dto.VoteQuestionDTO;
+import org.lamsfoundation.lams.tool.vote.pojos.VoteContent;
+import org.lamsfoundation.lams.tool.vote.pojos.VoteQueContent;
+import org.lamsfoundation.lams.tool.vote.service.IVoteService;
+import org.lamsfoundation.lams.tool.vote.service.VoteServiceProxy;
+import org.lamsfoundation.lams.tool.vote.util.VoteApplicationException;
+import org.lamsfoundation.lams.tool.vote.util.VoteComparator;
+import org.lamsfoundation.lams.tool.vote.util.VoteUtils;
+import org.lamsfoundation.lams.tool.vote.web.form.VoteAuthoringForm;
+import org.lamsfoundation.lams.usermanagement.dto.UserDTO;
+import org.lamsfoundation.lams.util.WebUtil;
+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
+ */
+public class AuthoringAction extends LamsDispatchAction implements VoteAppConstants {
+ private static Logger logger = Logger.getLogger(AuthoringAction.class.getName());
+
+ /**
+ *
+ * main content/question content management and workflow logic
+ *
+ * if the passed toolContentID exists in the db, we need to get the relevant data into the Map if not, create the
+ * default Map
+ */
+ @Override
+ public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws IOException, ServletException {
+ VoteUtils.cleanUpUserExceptions(request);
+ VoteAuthoringForm voteAuthoringForm = (VoteAuthoringForm) form;
+ VoteGeneralAuthoringDTO voteGeneralAuthoringDTO = new VoteGeneralAuthoringDTO();
+ repopulateRequestParameters(request, voteAuthoringForm, voteGeneralAuthoringDTO);
+
+ String richTextTitle = request.getParameter(TITLE);
+ String richTextInstructions = request.getParameter(INSTRUCTIONS);
+
+ if (richTextTitle != null) {
+ voteGeneralAuthoringDTO.setActivityTitle(richTextTitle);
+ }
+
+ if (richTextInstructions != null) {
+ voteGeneralAuthoringDTO.setActivityInstructions(richTextInstructions);
+ }
+
+ voteAuthoringForm.resetUserAction();
+ return null;
+ }
+
+ /**
+ * repopulateRequestParameters reads and saves request parameters
+ *
+ * @param request
+ * @param voteAuthoringForm
+ * @param voteGeneralAuthoringDTO
+ */
+ protected void repopulateRequestParameters(HttpServletRequest request, VoteAuthoringForm voteAuthoringForm,
+ VoteGeneralAuthoringDTO voteGeneralAuthoringDTO) {
+
+ String toolContentID = request.getParameter(VoteAppConstants.TOOL_CONTENT_ID);
+ voteAuthoringForm.setToolContentID(toolContentID);
+ voteGeneralAuthoringDTO.setToolContentID(toolContentID);
+
+ String httpSessionID = request.getParameter(VoteAppConstants.HTTP_SESSION_ID);
+ voteAuthoringForm.setHttpSessionID(httpSessionID);
+ voteGeneralAuthoringDTO.setHttpSessionID(httpSessionID);
+
+ String lockOnFinish = request.getParameter(VoteAppConstants.LOCK_ON_FINISH);
+ voteAuthoringForm.setLockOnFinish(lockOnFinish);
+ voteGeneralAuthoringDTO.setLockOnFinish(lockOnFinish);
+
+ String useSelectLeaderToolOuput = request.getParameter(VoteAppConstants.USE_SELECT_LEADER_TOOL_OUTPUT);
+ voteAuthoringForm.setUseSelectLeaderToolOuput(useSelectLeaderToolOuput);
+ voteGeneralAuthoringDTO.setUseSelectLeaderToolOuput(useSelectLeaderToolOuput);
+
+ String allowText = request.getParameter(VoteAppConstants.ALLOW_TEXT);
+ voteAuthoringForm.setAllowText(allowText);
+ voteGeneralAuthoringDTO.setAllowText(allowText);
+
+ String showResults = request.getParameter(VoteAppConstants.SHOW_RESULTS);
+ voteAuthoringForm.setShowResults(showResults);
+ voteGeneralAuthoringDTO.setShowResults(showResults);
+
+ String maxNominationCount = request.getParameter(VoteAppConstants.MAX_NOMINATION_COUNT);
+ voteAuthoringForm.setMaxNominationCount(maxNominationCount);
+ voteGeneralAuthoringDTO.setMaxNominationCount(maxNominationCount);
+
+ String minNominationCount = request.getParameter(MIN_NOMINATION_COUNT);
+ voteAuthoringForm.setMinNominationCount(minNominationCount);
+ voteGeneralAuthoringDTO.setMinNominationCount(minNominationCount);
+
+ String reflect = request.getParameter("reflect");
+ voteAuthoringForm.setReflect(reflect);
+ voteGeneralAuthoringDTO.setReflect(reflect);
+
+ String reflectionSubject = request.getParameter("reflectionSubject");
+ voteAuthoringForm.setReflectionSubject(reflectionSubject);
+ voteGeneralAuthoringDTO.setReflectionSubject(reflectionSubject);
+
+ String maxInputs = request.getParameter(VoteAppConstants.MAX_INPUTS);
+ if (maxInputs == null) {
+ logger.info("Since minNomcount is equal to null hence setting it to '0'");
+ maxInputs = "0";
+ }
+ voteAuthoringForm.setMaxInputs(new Short(maxInputs));
+
+ ToolAccessMode mode = WebUtil.readToolAccessModeAuthorDefaulted(request);
+ request.setAttribute(AttributeNames.ATTR_MODE, mode.toString());
+ }
+
+ /**
+ * moves a nomination down in the authoring list
+ */
+ @SuppressWarnings("unchecked")
+ public ActionForward moveNominationDown(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws IOException, ServletException {
+ VoteAuthoringForm voteAuthoringForm = (VoteAuthoringForm) form;
+
+ String httpSessionID = voteAuthoringForm.getHttpSessionID();
+ SessionMap sessionMap = (SessionMap) request.getSession()
+ .getAttribute(httpSessionID);
+
+ String questionIndex = request.getParameter("questionIndex");
+
+ List questionDTOs = (List) sessionMap.get(VoteAppConstants.LIST_QUESTION_DTO);
+
+ questionDTOs = AuthoringAction.swapQuestions(questionDTOs, questionIndex, "down");
+
+ questionDTOs = AuthoringAction.reorderQuestionDTOs(questionDTOs);
+ sessionMap.put(VoteAppConstants.LIST_QUESTION_DTO, questionDTOs);
+
+ String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID);
+ voteAuthoringForm.setContentFolderID(contentFolderID);
+
+ String richTextTitle = request.getParameter(VoteAppConstants.TITLE);
+
+ String richTextInstructions = request.getParameter(VoteAppConstants.INSTRUCTIONS);
+
+ sessionMap.put(VoteAppConstants.ACTIVITY_TITLE_KEY, richTextTitle);
+ sessionMap.put(VoteAppConstants.ACTIVITY_INSTRUCTIONS_KEY, richTextInstructions);
+
+ String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID);
+
+ VoteGeneralAuthoringDTO voteGeneralAuthoringDTO = new VoteGeneralAuthoringDTO();
+ voteGeneralAuthoringDTO.setContentFolderID(contentFolderID);
+
+ repopulateRequestParameters(request, voteAuthoringForm, voteGeneralAuthoringDTO);
+
+ voteGeneralAuthoringDTO.setActivityTitle(richTextTitle);
+ voteAuthoringForm.setTitle(richTextTitle);
+
+ voteGeneralAuthoringDTO.setActivityInstructions(richTextInstructions);
+
+ request.getSession().setAttribute(httpSessionID, sessionMap);
+
+ voteGeneralAuthoringDTO.setToolContentID(strToolContentID);
+ voteGeneralAuthoringDTO.setHttpSessionID(httpSessionID);
+ voteAuthoringForm.setToolContentID(strToolContentID);
+ voteAuthoringForm.setHttpSessionID(httpSessionID);
+ voteAuthoringForm.setCurrentTab("1");
+
+ request.setAttribute(VoteAppConstants.LIST_QUESTION_DTO, questionDTOs);
+
+ request.setAttribute(VoteAppConstants.VOTE_GENERAL_AUTHORING_DTO, voteGeneralAuthoringDTO);
+
+ return mapping.findForward(VoteAppConstants.LOAD_QUESTIONS);
+ }
+
+ /**
+ * moves a nomination up in the authoring list
+ */
+ @SuppressWarnings("unchecked")
+ public ActionForward moveNominationUp(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws IOException, ServletException {
+ VoteAuthoringForm voteAuthoringForm = (VoteAuthoringForm) form;
+
+ String httpSessionID = voteAuthoringForm.getHttpSessionID();
+ SessionMap sessionMap = (SessionMap) request.getSession()
+ .getAttribute(httpSessionID);
+
+ String questionIndex = request.getParameter("questionIndex");
+
+ List questionDTOs = (List) sessionMap.get(VoteAppConstants.LIST_QUESTION_DTO);
+
+ questionDTOs = AuthoringAction.swapQuestions(questionDTOs, questionIndex, "up");
+
+ questionDTOs = AuthoringAction.reorderQuestionDTOs(questionDTOs);
+
+ sessionMap.put(VoteAppConstants.LIST_QUESTION_DTO, questionDTOs);
+
+ String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID);
+ voteAuthoringForm.setContentFolderID(contentFolderID);
+
+ String richTextTitle = request.getParameter(VoteAppConstants.TITLE);
+
+ String richTextInstructions = request.getParameter(VoteAppConstants.INSTRUCTIONS);
+
+ sessionMap.put(VoteAppConstants.ACTIVITY_TITLE_KEY, richTextTitle);
+ sessionMap.put(VoteAppConstants.ACTIVITY_INSTRUCTIONS_KEY, richTextInstructions);
+
+ String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID);
+
+ VoteGeneralAuthoringDTO voteGeneralAuthoringDTO = new VoteGeneralAuthoringDTO();
+ voteGeneralAuthoringDTO.setContentFolderID(contentFolderID);
+
+ repopulateRequestParameters(request, voteAuthoringForm, voteGeneralAuthoringDTO);
+
+ voteGeneralAuthoringDTO.setActivityTitle(richTextTitle);
+ voteAuthoringForm.setTitle(richTextTitle);
+
+ voteGeneralAuthoringDTO.setActivityInstructions(richTextInstructions);
+
+ request.getSession().setAttribute(httpSessionID, sessionMap);
+
+ voteGeneralAuthoringDTO.setToolContentID(strToolContentID);
+ voteGeneralAuthoringDTO.setHttpSessionID(httpSessionID);
+ voteAuthoringForm.setToolContentID(strToolContentID);
+ voteAuthoringForm.setHttpSessionID(httpSessionID);
+ voteAuthoringForm.setCurrentTab("1");
+
+ request.setAttribute(VoteAppConstants.LIST_QUESTION_DTO, questionDTOs);
+
+ request.setAttribute(VoteAppConstants.VOTE_GENERAL_AUTHORING_DTO, voteGeneralAuthoringDTO);
+ return mapping.findForward(VoteAppConstants.LOAD_QUESTIONS);
+ }
+
+ /**
+ * removes a nomination from the authoring list
+ */
+ @SuppressWarnings("unchecked")
+ public ActionForward removeNomination(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws IOException, ServletException {
+ VoteAuthoringForm voteAuthoringForm = (VoteAuthoringForm) form;
+
+ String httpSessionID = voteAuthoringForm.getHttpSessionID();
+ SessionMap sessionMap = (SessionMap) request.getSession()
+ .getAttribute(httpSessionID);
+
+ String questionIndexToDelete = request.getParameter("questionIndex");
+ logger.info("Question Index to delete" + questionIndexToDelete);
+ List questionDTOs = (List) sessionMap.get(VoteAppConstants.LIST_QUESTION_DTO);
+
+ List listFinalQuestionDTO = new LinkedList<>();
+ int queIndex = 0;
+ for (VoteQuestionDTO questionDTO : questionDTOs) {
+
+ String questionText = questionDTO.getNomination();
+ String displayOrder = questionDTO.getDisplayOrder();
+
+ if (questionText != null && !questionText.equals("") && (!displayOrder.equals(questionIndexToDelete))) {
+
+ ++queIndex;
+ questionDTO.setDisplayOrder(new Integer(queIndex).toString());
+ listFinalQuestionDTO.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);
+ }
+ }
+
+ sessionMap.put(VoteAppConstants.LIST_QUESTION_DTO, listFinalQuestionDTO);
+ request.setAttribute(VoteAppConstants.LIST_QUESTION_DTO, listFinalQuestionDTO);
+
+ String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID);
+ voteAuthoringForm.setContentFolderID(contentFolderID);
+
+ String richTextTitle = request.getParameter(VoteAppConstants.TITLE);
+ String richTextInstructions = request.getParameter(VoteAppConstants.INSTRUCTIONS);
+
+ sessionMap.put(VoteAppConstants.ACTIVITY_TITLE_KEY, richTextTitle);
+ sessionMap.put(VoteAppConstants.ACTIVITY_INSTRUCTIONS_KEY, richTextInstructions);
+
+ String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID);
+
+ VoteGeneralAuthoringDTO voteGeneralAuthoringDTO = new VoteGeneralAuthoringDTO();
+ voteGeneralAuthoringDTO.setContentFolderID(contentFolderID);
+
+ repopulateRequestParameters(request, voteAuthoringForm, voteGeneralAuthoringDTO);
+
+ voteGeneralAuthoringDTO.setActivityTitle(richTextTitle);
+ voteAuthoringForm.setTitle(richTextTitle);
+
+ voteGeneralAuthoringDTO.setActivityInstructions(richTextInstructions);
+
+ request.getSession().setAttribute(httpSessionID, sessionMap);
+
+ voteGeneralAuthoringDTO.setToolContentID(strToolContentID);
+ voteGeneralAuthoringDTO.setHttpSessionID(httpSessionID);
+ voteAuthoringForm.setToolContentID(strToolContentID);
+ voteAuthoringForm.setHttpSessionID(httpSessionID);
+ voteAuthoringForm.setCurrentTab("1");
+
+ request.setAttribute(VoteAppConstants.VOTE_GENERAL_AUTHORING_DTO, voteGeneralAuthoringDTO);
+
+ return mapping.findForward(VoteAppConstants.LOAD_QUESTIONS);
+ }
+
+ /**
+ * enables editing a nomination
+ */
+ @SuppressWarnings("unchecked")
+ public ActionForward newEditableNominationBox(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws IOException, ServletException {
+ VoteAuthoringForm voteAuthoringForm = (VoteAuthoringForm) form;
+
+ String httpSessionID = voteAuthoringForm.getHttpSessionID();
+
+ SessionMap sessionMap = (SessionMap) request.getSession()
+ .getAttribute(httpSessionID);
+
+ String questionIndex = request.getParameter("questionIndex");
+ logger.info("Question Index" + questionIndex);
+ voteAuthoringForm.setEditableNominationIndex(questionIndex);
+
+ List questionDTOs = (List) sessionMap.get(VoteAppConstants.LIST_QUESTION_DTO);
+
+ String editableNomination = "";
+ Iterator iter = questionDTOs.iterator();
+ while (iter.hasNext()) {
+ VoteQuestionDTO voteQuestionDTO = (VoteQuestionDTO) iter.next();
+ // String question = voteQuestionDTO.getNomination();
+ String displayOrder = voteQuestionDTO.getDisplayOrder();
+
+ if (displayOrder != null && !displayOrder.equals("")) {
+ if (displayOrder.equals(questionIndex)) {
+ editableNomination = voteQuestionDTO.getNomination();
+ break;
+ }
+
+ }
+ }
+ String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID);
+ voteAuthoringForm.setContentFolderID(contentFolderID);
+
+ VoteGeneralAuthoringDTO voteGeneralAuthoringDTO = new VoteGeneralAuthoringDTO();
+ voteGeneralAuthoringDTO.setContentFolderID(contentFolderID);
+
+ repopulateRequestParameters(request, voteAuthoringForm, voteGeneralAuthoringDTO);
+
+ String richTextTitle = request.getParameter(VoteAppConstants.TITLE);
+ String richTextInstructions = request.getParameter(VoteAppConstants.INSTRUCTIONS);
+
+ voteGeneralAuthoringDTO.setActivityTitle(richTextTitle);
+ voteAuthoringForm.setTitle(richTextTitle);
+ voteGeneralAuthoringDTO.setActivityInstructions(richTextInstructions);
+
+ voteGeneralAuthoringDTO.setEditableNominationText(editableNomination);
+
+ request.setAttribute(VoteAppConstants.VOTE_GENERAL_AUTHORING_DTO, voteGeneralAuthoringDTO);
+
+ return mapping.findForward("editNominationBox");
+ }
+
+ /**
+ * enables adding a new nomination
+ */
+ public ActionForward newNominationBox(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws IOException, ServletException {
+ VoteAuthoringForm voteAuthoringForm = (VoteAuthoringForm) form;
+
+// String httpSessionID = voteAuthoringForm.getHttpSessionID();
+//
+// SessionMap sessionMap = (SessionMap) request.getSession()
+// .getAttribute(httpSessionID);
+
+ String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID);
+ voteAuthoringForm.setContentFolderID(contentFolderID);
+
+ VoteGeneralAuthoringDTO voteGeneralAuthoringDTO = new VoteGeneralAuthoringDTO();
+ voteGeneralAuthoringDTO.setContentFolderID(contentFolderID);
+
+ repopulateRequestParameters(request, voteAuthoringForm, voteGeneralAuthoringDTO);
+
+ String richTextTitle = request.getParameter(VoteAppConstants.TITLE);
+ String richTextInstructions = request.getParameter(VoteAppConstants.INSTRUCTIONS);
+
+ voteGeneralAuthoringDTO.setActivityTitle(richTextTitle);
+ voteAuthoringForm.setTitle(richTextTitle);
+
+ voteGeneralAuthoringDTO.setActivityInstructions(richTextInstructions);
+
+ request.setAttribute(VoteAppConstants.VOTE_GENERAL_AUTHORING_DTO, voteGeneralAuthoringDTO);
+
+ return mapping.findForward("newNominationBox");
+ }
+
+ /**
+ * enables adding a new nomination to the authoring nominations list
+ */
+ @SuppressWarnings("unchecked")
+ public ActionForward addSingleNomination(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws IOException, ServletException {
+ VoteAuthoringForm voteAuthoringForm = (VoteAuthoringForm) form;
+
+ //IVoteService voteService = VoteServiceProxy.getVoteService(getServlet().getServletContext());
+
+ String httpSessionID = voteAuthoringForm.getHttpSessionID();
+
+ SessionMap sessionMap = (SessionMap) request.getSession()
+ .getAttribute(httpSessionID);
+ String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID);
+ voteAuthoringForm.setContentFolderID(contentFolderID);
+
+ String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID);
+
+ VoteGeneralAuthoringDTO voteGeneralAuthoringDTO = new VoteGeneralAuthoringDTO();
+ voteGeneralAuthoringDTO.setContentFolderID(contentFolderID);
+
+ repopulateRequestParameters(request, voteAuthoringForm, voteGeneralAuthoringDTO);
+
+ List questionDTOs = (List) sessionMap.get(VoteAppConstants.LIST_QUESTION_DTO);
+
+ String newNomination = request.getParameter("newNomination");
+
+ int listSize = questionDTOs.size();
+
+ if (newNomination != null && newNomination.length() > 0) {
+ boolean duplicates = AuthoringAction.checkDuplicateNominations(questionDTOs, newNomination);
+
+ if (!duplicates) {
+ VoteQuestionDTO voteQuestionDTO = new VoteQuestionDTO();
+ voteQuestionDTO.setDisplayOrder(new Long(listSize + 1).toString());
+ voteQuestionDTO.setNomination(newNomination);
+
+ questionDTOs.add(voteQuestionDTO);
+ }
+ }
+
+ request.setAttribute(VoteAppConstants.LIST_QUESTION_DTO, questionDTOs);
+ sessionMap.put(VoteAppConstants.LIST_QUESTION_DTO, questionDTOs);
+
+ String richTextTitle = (String) sessionMap.get(VoteAppConstants.ACTIVITY_TITLE_KEY);
+ String richTextInstructions = (String) sessionMap.get(VoteAppConstants.ACTIVITY_INSTRUCTIONS_KEY);
+
+ voteGeneralAuthoringDTO.setActivityTitle(richTextTitle);
+ voteAuthoringForm.setTitle(richTextTitle);
+ voteGeneralAuthoringDTO.setActivityInstructions(richTextInstructions);
+
+ request.getSession().setAttribute(httpSessionID, sessionMap);
+
+ voteGeneralAuthoringDTO.setToolContentID(strToolContentID);
+ voteGeneralAuthoringDTO.setHttpSessionID(httpSessionID);
+
+ voteAuthoringForm.setToolContentID(strToolContentID);
+ voteAuthoringForm.setHttpSessionID(httpSessionID);
+ voteAuthoringForm.setCurrentTab("1");
+
+ request.setAttribute(VoteAppConstants.VOTE_GENERAL_AUTHORING_DTO, voteGeneralAuthoringDTO);
+
+ request.getSession().setAttribute(httpSessionID, sessionMap);
+
+ return mapping.findForward(VoteAppConstants.LOAD_NOMINATIONS);
+ }
+
+ /**
+ * saves a new or updated nomination in the authoring nominations list
+ */
+ @SuppressWarnings("unchecked")
+ public ActionForward saveSingleNomination(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws IOException, ServletException {
+
+ VoteAuthoringForm voteAuthoringForm = (VoteAuthoringForm) form;
+
+ String httpSessionID = voteAuthoringForm.getHttpSessionID();
+
+ SessionMap sessionMap = (SessionMap) request.getSession()
+ .getAttribute(httpSessionID);
+
+ String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID);
+ voteAuthoringForm.setContentFolderID(contentFolderID);
+
+ String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID);
+
+ String editNominationBoxRequest = request.getParameter("editNominationBoxRequest");
+
+ logger.info("Edit nomination box request" + editNominationBoxRequest);
+
+ VoteGeneralAuthoringDTO voteGeneralAuthoringDTO = new VoteGeneralAuthoringDTO();
+
+ voteGeneralAuthoringDTO.setContentFolderID(contentFolderID);
+
+ repopulateRequestParameters(request, voteAuthoringForm, voteGeneralAuthoringDTO);
+
+ List questionDTOs = (List) sessionMap.get(VoteAppConstants.LIST_QUESTION_DTO);
+
+ String newNomination = request.getParameter("newNomination");
+
+ String editableNominationIndex = request.getParameter("editableNominationIndex");
+
+ if (newNomination != null && newNomination.length() > 0) {
+ if (editNominationBoxRequest != null && editNominationBoxRequest.equals("false")) {
+ boolean duplicates = AuthoringAction.checkDuplicateNominations(questionDTOs, newNomination);
+
+ if (!duplicates) {
+ VoteQuestionDTO voteQuestionDTO = null;
+ Iterator iter = questionDTOs.iterator();
+ while (iter.hasNext()) {
+ voteQuestionDTO = (VoteQuestionDTO) iter.next();
+
+ //String question = voteQuestionDTO.getNomination();
+ String displayOrder = voteQuestionDTO.getDisplayOrder();
+
+ if (displayOrder != null && !displayOrder.equals("")) {
+ if (displayOrder.equals(editableNominationIndex)) {
+ break;
+ }
+
+ }
+ }
+
+ voteQuestionDTO.setQuestion(newNomination);
+ voteQuestionDTO.setDisplayOrder(editableNominationIndex);
+
+ questionDTOs = AuthoringAction.reorderUpdateListQuestionDTO(questionDTOs, voteQuestionDTO,
+ editableNominationIndex);
+ } else {
+ logger.info("Duplicate question entry therefore not adding");
+ //duplicate question entry, not adding
+ }
+ } else {
+ logger.info("In Request for Save and Edit");
+ //request for edit and save
+ VoteQuestionDTO voteQuestionDTO = null;
+ Iterator iter = questionDTOs.iterator();
+ while (iter.hasNext()) {
+ voteQuestionDTO = (VoteQuestionDTO) iter.next();
+
+ // String question = voteQuestionDTO.getNomination();
+ String displayOrder = voteQuestionDTO.getDisplayOrder();
+
+ if (displayOrder != null && !displayOrder.equals("")) {
+ if (displayOrder.equals(editableNominationIndex)) {
+ break;
+ }
+
+ }
+ }
+
+ voteQuestionDTO.setNomination(newNomination);
+ voteQuestionDTO.setDisplayOrder(editableNominationIndex);
+
+ questionDTOs = AuthoringAction.reorderUpdateListQuestionDTO(questionDTOs, voteQuestionDTO,
+ editableNominationIndex);
+ }
+ } else {
+ logger.info("newNomination entry is blank,therefore not adding");
+ //entry blank, not adding
+ }
+
+ request.setAttribute(VoteAppConstants.LIST_QUESTION_DTO, questionDTOs);
+ sessionMap.put(VoteAppConstants.LIST_QUESTION_DTO, questionDTOs);
+
+ String richTextTitle = (String) sessionMap.get(VoteAppConstants.ACTIVITY_TITLE_KEY);
+ String richTextInstructions = (String) sessionMap.get(VoteAppConstants.ACTIVITY_INSTRUCTIONS_KEY);
+
+ voteGeneralAuthoringDTO.setActivityTitle(richTextTitle);
+ voteAuthoringForm.setTitle(richTextTitle);
+ voteGeneralAuthoringDTO.setActivityInstructions(richTextInstructions);
+
+ request.getSession().setAttribute(httpSessionID, sessionMap);
+
+ voteGeneralAuthoringDTO.setToolContentID(strToolContentID);
+ voteGeneralAuthoringDTO.setHttpSessionID(httpSessionID);
+
+ voteAuthoringForm.setToolContentID(strToolContentID);
+ voteAuthoringForm.setHttpSessionID(httpSessionID);
+ voteAuthoringForm.setCurrentTab("1");
+
+ request.setAttribute(VoteAppConstants.VOTE_GENERAL_AUTHORING_DTO, voteGeneralAuthoringDTO);
+
+ request.getSession().setAttribute(httpSessionID, sessionMap);
+
+ return mapping.findForward(VoteAppConstants.LOAD_NOMINATIONS);
+ }
+
+ /**
+ * persists the nominations list and other user selections in the db.
+ */
+ @SuppressWarnings("unchecked")
+ public ActionForward submitAllContent(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws IOException, ServletException {
+
+ VoteAuthoringForm voteAuthoringForm = (VoteAuthoringForm) form;
+
+ IVoteService voteService = VoteServiceProxy.getVoteService(getServlet().getServletContext());
+
+ String httpSessionID = voteAuthoringForm.getHttpSessionID();
+
+ SessionMap sessionMap = (SessionMap) request.getSession()
+ .getAttribute(httpSessionID);
+
+ String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID);
+ voteAuthoringForm.setContentFolderID(contentFolderID);
+
+ String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID);
+
+ List questionDTOs = (List) sessionMap.get(VoteAppConstants.LIST_QUESTION_DTO);
+
+ ActionMessages errors = new ActionMessages();
+ if (questionDTOs.isEmpty() && (voteAuthoringForm.getAssignedDataFlowObject() == null
+ || voteAuthoringForm.getAssignedDataFlowObject() == 0)) {
+ ActionMessage error = new ActionMessage("nominations.none.submitted");
+ errors.add(ActionMessages.GLOBAL_MESSAGE, error);
+ logger.error("Nominations not submitted");
+ }
+
+ String maxNomCount = voteAuthoringForm.getMaxNominationCount();
+ if (maxNomCount != null) {
+ if (maxNomCount.equals("0") || maxNomCount.contains("-")) {
+ ActionMessage error = new ActionMessage("maxNomination.invalid");
+ errors.add(ActionMessages.GLOBAL_MESSAGE, error);
+ logger.error("Maximum votes in Advance tab is invalid");
+ }
+
+ try {
+ //int intMaxNomCount = new Integer(maxNomCount).intValue();
+ } catch (NumberFormatException e) {
+ ActionMessage error = new ActionMessage("maxNomination.invalid");
+ errors.add(ActionMessages.GLOBAL_MESSAGE, error);
+ logger.error("Maximum votes in Advance tab is invalid");
+ }
+ }
+
+ //verifyDuplicateNominations
+ Map mapQuestion = AuthoringAction.extractMapQuestion(questionDTOs);
+ int optionCount = 0;
+ boolean isNominationsDuplicate = false;
+ for (long i = 1; i <= VoteAppConstants.MAX_OPTION_COUNT; i++) {
+ String currentOption = (String) mapQuestion.get(new Long(i).toString());
+
+ optionCount = 0;
+ for (long j = 1; j <= VoteAppConstants.MAX_OPTION_COUNT; j++) {
+ String backedOption = (String) mapQuestion.get(new Long(j).toString());
+
+ if (currentOption != null && backedOption != null) {
+ if (currentOption.equals(backedOption)) {
+ optionCount++;
+ }
+
+ if (optionCount > 1) {
+ isNominationsDuplicate = true;
+ }
+ }
+ }
+ }
+
+ if (isNominationsDuplicate == true) {
+ ActionMessage error = new ActionMessage("nominations.duplicate");
+ errors.add(ActionMessages.GLOBAL_MESSAGE, error);
+ logger.error("There are duplicate nomination entries.");
+ }
+
+ VoteGeneralAuthoringDTO voteGeneralAuthoringDTO = new VoteGeneralAuthoringDTO();
+ repopulateRequestParameters(request, voteAuthoringForm, voteGeneralAuthoringDTO);
+
+ DataFlowObject assignedDataFlowObject = null;
+
+ List dataFlowObjects = voteService.getDataFlowObjects(new Long(strToolContentID));
+ List dataFlowObjectNames = null;
+ if (dataFlowObjects != null) {
+ dataFlowObjectNames = new ArrayList<>(dataFlowObjects.size());
+ int objectIndex = 1;
+ for (DataFlowObject dataFlowObject : dataFlowObjects) {
+ dataFlowObjectNames.add(dataFlowObject.getDisplayName());
+ if (VoteAppConstants.DATA_FLOW_OBJECT_ASSIGMENT_ID.equals(dataFlowObject.getToolAssigmentId())) {
+ voteAuthoringForm.setAssignedDataFlowObject(objectIndex);
+ }
+ objectIndex++;
+
+ }
+ }
+ voteGeneralAuthoringDTO.setDataFlowObjectNames(dataFlowObjectNames);
+
+ if (voteAuthoringForm.getAssignedDataFlowObject() != null
+ && voteAuthoringForm.getAssignedDataFlowObject() != 0) {
+ assignedDataFlowObject = dataFlowObjects.get(voteAuthoringForm.getAssignedDataFlowObject() - 1);
+ }
+
+ voteGeneralAuthoringDTO.setContentFolderID(contentFolderID);
+
+ String richTextTitle = request.getParameter(VoteAppConstants.TITLE);
+ String richTextInstructions = request.getParameter(VoteAppConstants.INSTRUCTIONS);
+
+ voteGeneralAuthoringDTO.setActivityTitle(richTextTitle);
+ voteAuthoringForm.setTitle(richTextTitle);
+
+ voteGeneralAuthoringDTO.setActivityInstructions(richTextInstructions);
+
+ sessionMap.put(VoteAppConstants.ACTIVITY_TITLE_KEY, richTextTitle);
+ sessionMap.put(VoteAppConstants.ACTIVITY_INSTRUCTIONS_KEY, richTextInstructions);
+
+ request.setAttribute(VoteAppConstants.VOTE_GENERAL_AUTHORING_DTO, voteGeneralAuthoringDTO);
+
+ VoteContent voteContentTest = voteService.getVoteContent(new Long(strToolContentID));
+ if (!errors.isEmpty()) {
+ saveErrors(request, errors);
+ logger.error("errors saved: " + errors);
+ }
+
+ if (errors.isEmpty()) {
+ ToolAccessMode mode = WebUtil.readToolAccessModeAuthorDefaulted(request);
+ request.setAttribute(AttributeNames.ATTR_MODE, mode.toString());
+
+ List deletedQuestionDTOs = (List) sessionMap
+ .get(LIST_DELETED_QUESTION_DTOS);
+
+ // in case request is from monitoring module - recalculate User Answers
+ if (mode.isTeacher()) {
+ Set oldQuestions = voteContentTest.getVoteQueContents();
+ voteService.removeQuestionsFromCache(voteContentTest);
+ VoteUtils.setDefineLater(request, false, strToolContentID, voteService);
+
+ // audit log the teacher has started editing activity in monitor
+ voteService.auditLogStartEditingActivityInMonitor(new Long(strToolContentID));
+
+ // recalculate User Answers
+ voteService.recalculateUserAnswers(voteContentTest, oldQuestions, questionDTOs, deletedQuestionDTOs);
+ }
+
+ // remove deleted questions
+ for (VoteQuestionDTO deletedQuestionDTO : deletedQuestionDTOs) {
+ VoteQueContent removeableQuestion = voteService.getVoteQueContentByUID(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);
+ voteContentTest.getVoteQueContents().remove(removeableQuestion);
+ voteService.removeVoteQueContent(removeableQuestion);
+ }
+ }
+
+ // store content
+ VoteContent voteContent = AuthoringAction.saveOrUpdateVoteContent(voteService, voteAuthoringForm, request,
+ voteContentTest, strToolContentID);
+
+ //store questions
+ voteContent = voteService.createQuestions(questionDTOs, voteContent);
+
+ //store DataFlowObjectAssigment
+ voteService.saveDataFlowObjectAssigment(assignedDataFlowObject);
+
+ //reOrganizeDisplayOrder
+ List sortedQuestions = voteService.getAllQuestionsSorted(voteContent.getUid().longValue());
+ Iterator iter = sortedQuestions.iterator();
+ while (iter.hasNext()) {
+ VoteQueContent question = (VoteQueContent) iter.next();
+
+ VoteQueContent existingQuestion = voteService.getQuestionByUid(question.getUid());
+ voteService.saveOrUpdateVoteQueContent(existingQuestion);
+ }
+
+ // standard authoring close
+ request.setAttribute(AuthoringConstants.LAMS_AUTHORING_SUCCESS_FLAG, Boolean.TRUE);
+
+ }
+
+ voteAuthoringForm.resetUserAction();
+
+ request.setAttribute(VoteAppConstants.VOTE_GENERAL_AUTHORING_DTO, voteGeneralAuthoringDTO);
+
+ request.setAttribute(VoteAppConstants.LIST_QUESTION_DTO, questionDTOs);
+ sessionMap.put(VoteAppConstants.LIST_QUESTION_DTO, questionDTOs);
+ request.getSession().setAttribute(httpSessionID, sessionMap);
+
+ voteGeneralAuthoringDTO.setToolContentID(strToolContentID);
+ voteGeneralAuthoringDTO.setHttpSessionID(httpSessionID);
+
+ voteAuthoringForm.setToolContentID(strToolContentID);
+ voteAuthoringForm.setHttpSessionID(httpSessionID);
+ voteAuthoringForm.setCurrentTab("1");
+
+ return mapping.findForward(VoteAppConstants.LOAD_QUESTIONS);
+ }
+
+ public ActionForward start(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws IOException, ServletException, VoteApplicationException {
+
+ VoteUtils.cleanUpUserExceptions(request);
+
+ VoteAuthoringForm voteAuthoringForm = (VoteAuthoringForm) form;
+ VoteGeneralAuthoringDTO voteGeneralAuthoringDTO = new VoteGeneralAuthoringDTO();
+ request.setAttribute(VoteAppConstants.VOTE_GENERAL_AUTHORING_DTO, voteGeneralAuthoringDTO);
+
+ String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID);
+ voteAuthoringForm.setContentFolderID(contentFolderID);
+
+ AuthoringAction voteAction = new AuthoringAction();
+ voteAction.repopulateRequestParameters(request, voteAuthoringForm, voteGeneralAuthoringDTO);
+
+ IVoteService voteService = null;
+ if (getServlet() != null) {
+ voteService = VoteServiceProxy.getVoteService(getServlet().getServletContext());
+ } else {
+ voteService = voteAuthoringForm.getVoteService();
+ }
+
+ voteGeneralAuthoringDTO.setContentFolderID(contentFolderID);
+
+ SessionMap sessionMap = new SessionMap<>();
+ voteAuthoringForm.setHttpSessionID(sessionMap.getSessionID());
+ voteGeneralAuthoringDTO.setHttpSessionID(sessionMap.getSessionID());
+ request.getSession().setAttribute(sessionMap.getSessionID(), sessionMap);
+
+ voteAuthoringForm.resetRadioBoxes();
+ voteAuthoringForm.setExceptionMaxNominationInvalid(new Boolean(false).toString());
+ voteGeneralAuthoringDTO.setExceptionMaxNominationInvalid(new Boolean(false).toString());
+
+ ActionForward validateSignature = validateDefaultContent(request, mapping, voteService, voteAuthoringForm);
+ if (validateSignature != null) {
+ return validateSignature;
+ }
+
+ //no problems getting the default content, will render authoring screen
+
+ /* the authoring url must be passed a tool content id */
+ String strToolContentId = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID);
+ voteAuthoringForm.setToolContentID(new Long(strToolContentId).toString());
+ voteGeneralAuthoringDTO.setToolContentID(new Long(strToolContentId).toString());
+
+ if (strToolContentId == null || strToolContentId.equals("")) {
+ VoteUtils.cleanUpUserExceptions(request);
+ // saveInRequestError(request,"error.contentId.required");
+ VoteUtils.cleanUpUserExceptions(request);
+ return mapping.findForward(VoteAppConstants.ERROR_LIST);
+ }
+
+ ToolAccessMode mode = WebUtil.readToolAccessModeAuthorDefaulted(request);
+ // request is from monitoring module
+ if (mode.isTeacher()) {
+ VoteUtils.setDefineLater(request, true, strToolContentId, voteService);
+ }
+ request.setAttribute(AttributeNames.ATTR_MODE, mode.toString());
+
+ VoteContent voteContent = voteService.getVoteContent(new Long(strToolContentId));
+
+ // if mcContent does not exist, try to use default content instead.
+ if (voteContent == null) {
+ long defaultContentID = voteService.getToolDefaultContentIdBySignature(VoteAppConstants.MY_SIGNATURE);
+ voteContent = voteService.getVoteContent(defaultContentID);
+ voteContent = VoteContent.newInstance(voteContent, new Long(strToolContentId));
+ }
+
+ AuthoringAction.prepareDTOandForm(request, voteContent, voteAuthoringForm, voteGeneralAuthoringDTO);
+ if (voteContent.getTitle() == null) {
+ voteGeneralAuthoringDTO.setActivityTitle(VoteAppConstants.DEFAULT_VOTING_TITLE);
+ voteAuthoringForm.setTitle(VoteAppConstants.DEFAULT_VOTING_TITLE);
+ } else {
+ voteGeneralAuthoringDTO.setActivityTitle(voteContent.getTitle());
+ voteAuthoringForm.setTitle(voteContent.getTitle());
+ }
+
+ if (voteContent.getInstructions() == null) {
+ voteGeneralAuthoringDTO.setActivityInstructions(VoteAppConstants.DEFAULT_VOTING_INSTRUCTIONS);
+ voteAuthoringForm.setInstructions(VoteAppConstants.DEFAULT_VOTING_INSTRUCTIONS);
+ } else {
+ voteGeneralAuthoringDTO.setActivityInstructions(voteContent.getInstructions());
+ voteAuthoringForm.setInstructions(voteContent.getInstructions());
+ }
+
+ sessionMap.put(VoteAppConstants.ACTIVITY_TITLE_KEY, voteGeneralAuthoringDTO.getActivityTitle());
+ sessionMap.put(VoteAppConstants.ACTIVITY_INSTRUCTIONS_KEY, voteGeneralAuthoringDTO.getActivityInstructions());
+
+ voteAuthoringForm.setReflectionSubject(voteContent.getReflectionSubject());
+ voteGeneralAuthoringDTO.setReflectionSubject(voteContent.getReflectionSubject());
+
+ List dataFlowObjects = voteService.getDataFlowObjects(new Long(strToolContentId));
+ if (dataFlowObjects != null) {
+ List dataFlowObjectNames = new ArrayList<>(dataFlowObjects.size());
+ int objectIndex = 1;
+ for (DataFlowObject dataFlowObject : dataFlowObjects) {
+ dataFlowObjectNames.add(dataFlowObject.getDisplayName());
+ if (VoteAppConstants.DATA_FLOW_OBJECT_ASSIGMENT_ID.equals(dataFlowObject.getToolAssigmentId())) {
+ voteAuthoringForm.setAssignedDataFlowObject(objectIndex);
+ }
+ objectIndex++;
+
+ }
+ voteGeneralAuthoringDTO.setDataFlowObjectNames(dataFlowObjectNames);
+ }
+
+ List questionDTOs = new LinkedList<>();
+
+ for (VoteQueContent question : (Set) voteContent.getVoteQueContents()) {
+ VoteQuestionDTO questionDTO = new VoteQuestionDTO();
+
+ questionDTO.setUid(question.getUid());
+ questionDTO.setQuestion(question.getQuestion());
+ questionDTO.setDisplayOrder(new Integer(question.getDisplayOrder()).toString());
+ questionDTOs.add(questionDTO);
+ }
+
+ request.setAttribute(VoteAppConstants.LIST_QUESTION_DTO, questionDTOs);
+ sessionMap.put(VoteAppConstants.LIST_QUESTION_DTO, questionDTOs);
+
+ Short maxInputs = voteContent.getMaxExternalInputs();
+ if (maxInputs == null) {
+ maxInputs = 0;
+ }
+ voteAuthoringForm.setMaxInputs(maxInputs);
+ voteAuthoringForm.resetUserAction();
+
+ List listDeletedQuestionDTOs = new ArrayList<>();
+ sessionMap.put(VoteAppConstants.LIST_DELETED_QUESTION_DTOS, listDeletedQuestionDTOs);
+
+ voteAuthoringForm.resetUserAction();
+ voteAuthoringForm.setCurrentTab("1");
+
+ return mapping.findForward(LOAD_QUESTIONS);
+ }
+
+ /**
+ * each tool has a signature. Voting tool's signature is stored in MY_SIGNATURE. The default tool content id and
+ * other depending content ids are obtained in this method. if all the default content has been setup properly the
+ * method saves DEFAULT_CONTENT_ID in the session.
+ *
+ * @param request
+ * @param mapping
+ * @return ActionForward
+ */
+ private ActionForward validateDefaultContent(HttpServletRequest request, ActionMapping mapping,
+ IVoteService voteService, VoteAuthoringForm voteAuthoringForm) {
+ /*
+ * retrieve the default content id based on tool signature
+ */
+ long defaultContentID = 0;
+ try {
+ defaultContentID = voteService.getToolDefaultContentIdBySignature(VoteAppConstants.MY_SIGNATURE);
+ if (defaultContentID == 0) {
+ VoteUtils.cleanUpUserExceptions(request);
+ logger.error("Exception occured: No default content");
+ saveInRequestError(request, "error.defaultContent.notSetup");
+ return mapping.findForward(VoteAppConstants.ERROR_LIST);
+ }
+ } catch (Exception e) {
+ VoteUtils.cleanUpUserExceptions(request);
+ logger.error("error getting the default content id: " + e.getMessage());
+ saveInRequestError(request, "error.defaultContent.notSetup");
+ return mapping.findForward(VoteAppConstants.ERROR_LIST);
+ }
+
+ try {
+ //retrieve uid of the content based on default content id determined above defaultContentID
+ VoteContent voteContent = voteService.getVoteContent(new Long(defaultContentID));
+ if (voteContent == null) {
+ VoteUtils.cleanUpUserExceptions(request);
+ logger.error("Exception occured: No default content");
+ saveInRequestError(request, "error.defaultContent.notSetup");
+ return mapping.findForward(VoteAppConstants.ERROR_LIST);
+ }
+ } catch (Exception e) {
+ logger.error("other problems: " + e);
+ VoteUtils.cleanUpUserExceptions(request);
+ logger.error("Exception occured: No default question content");
+ saveInRequestError(request, "error.defaultContent.notSetup");
+ return mapping.findForward(VoteAppConstants.ERROR_LIST);
+ }
+
+ return null;
+ }
+
+ private static void prepareDTOandForm(HttpServletRequest request, VoteContent voteContent,
+ VoteAuthoringForm voteAuthoringForm, VoteGeneralAuthoringDTO voteGeneralAuthoringDTO) {
+
+ voteGeneralAuthoringDTO.setActivityTitle(voteContent.getTitle());
+ voteGeneralAuthoringDTO.setActivityInstructions(voteContent.getInstructions());
+
+ voteAuthoringForm.setUseSelectLeaderToolOuput(voteContent.isUseSelectLeaderToolOuput() ? "1" : "0");
+ voteAuthoringForm.setAllowText(voteContent.isAllowText() ? "1" : "0");
+ voteAuthoringForm.setAllowTextEntry(voteContent.isAllowText() ? "1" : "0");
+
+ voteAuthoringForm.setShowResults(voteContent.isShowResults() ? "1" : "0");
+
+ voteAuthoringForm.setLockOnFinish(voteContent.isLockOnFinish() ? "1" : "0");
+ voteAuthoringForm.setReflect(voteContent.isReflect() ? "1" : "0");
+
+ voteGeneralAuthoringDTO.setUseSelectLeaderToolOuput(voteContent.isUseSelectLeaderToolOuput() ? "1" : "0");
+ voteGeneralAuthoringDTO.setAllowText(voteContent.isAllowText() ? "1" : "0");
+ voteGeneralAuthoringDTO.setLockOnFinish(voteContent.isLockOnFinish() ? "1" : "0");
+ voteAuthoringForm.setReflect(voteContent.isReflect() ? "1" : "0");
+
+ String maxNomcount = voteContent.getMaxNominationCount();
+ if (maxNomcount.equals("")) {
+ logger.info("Since minNomcount is equal to null hence setting it to '0'");
+ maxNomcount = "0";
+ }
+ voteAuthoringForm.setMaxNominationCount(maxNomcount);
+ voteGeneralAuthoringDTO.setMaxNominationCount(maxNomcount);
+
+ String minNomcount = voteContent.getMinNominationCount();
+ if ((minNomcount == null) || minNomcount.equals("")) {
+ logger.info("Since minNomcount is equal to null hence setting it to '0'");
+ minNomcount = "0";
+ }
+ voteAuthoringForm.setMinNominationCount(minNomcount);
+ voteGeneralAuthoringDTO.setMinNominationCount(minNomcount);
+ }
+
+ /**
+ * saves error messages to request scope
+ *
+ * @param request
+ * @param message
+ */
+ private void saveInRequestError(HttpServletRequest request, String message) {
+ ActionMessages errors = new ActionMessages();
+ errors.add(Globals.ERROR_KEY, new ActionMessage(message));
+ logger.error("add " + message + " to ActionMessages:");
+ saveErrors(request, errors);
+ }
+
+ protected static List swapQuestions(List questionDTOs, String questionIndex,
+ String direction) {
+
+ int intQuestionIndex = new Integer(questionIndex).intValue();
+ int intOriginalQuestionIndex = intQuestionIndex;
+
+ int replacedQuestionIndex = 0;
+ if (direction.equals("down")) {
+ replacedQuestionIndex = ++intQuestionIndex;
+ } else {
+ replacedQuestionIndex = --intQuestionIndex;
+ }
+
+ VoteQuestionDTO mainQuestion = AuthoringAction.getQuestionAtDisplayOrder(questionDTOs,
+ intOriginalQuestionIndex);
+
+ VoteQuestionDTO replacedQuestion = AuthoringAction.getQuestionAtDisplayOrder(questionDTOs,
+ replacedQuestionIndex);
+
+ List newQuestionDtos = new LinkedList();
+
+ Iterator iter = questionDTOs.iterator();
+ while (iter.hasNext()) {
+ VoteQuestionDTO questionDTO = iter.next();
+ VoteQuestionDTO tempQuestion = new VoteQuestionDTO();
+
+ if (!questionDTO.getDisplayOrder().equals(new Integer(intOriginalQuestionIndex).toString())
+ && !questionDTO.getDisplayOrder().equals(new Integer(replacedQuestionIndex).toString())) {
+ logger.info("Normal Copy");
+ // normal copy
+ tempQuestion = questionDTO;
+
+ } else if (questionDTO.getDisplayOrder().equals(new Integer(intOriginalQuestionIndex).toString())) {
+ // move type 1
+ logger.info("Move type 1");
+ tempQuestion = replacedQuestion;
+
+ } else if (questionDTO.getDisplayOrder().equals(new Integer(replacedQuestionIndex).toString())) {
+ // move type 1
+ logger.info("Move type 1");
+ tempQuestion = mainQuestion;
+ }
+
+ newQuestionDtos.add(tempQuestion);
+ }
+
+ return newQuestionDtos;
+ }
+
+ protected static VoteQuestionDTO getQuestionAtDisplayOrder(List questionDTOs,
+ int intOriginalQuestionIndex) {
+
+ Iterator iter = questionDTOs.iterator();
+ while (iter.hasNext()) {
+ VoteQuestionDTO voteQuestionDTO = iter.next();
+
+ if (new Integer(intOriginalQuestionIndex).toString().equals(voteQuestionDTO.getDisplayOrder())) {
+ return voteQuestionDTO;
+ }
+ }
+ return null;
+ }
+
+ protected static List reorderQuestionDTOs(List listQuestionDTO) {
+ List listFinalQuestionDTO = new LinkedList();
+
+ int queIndex = 0;
+ Iterator iter = listQuestionDTO.iterator();
+ while (iter.hasNext()) {
+ VoteQuestionDTO voteQuestionDTO = iter.next();
+
+ String question = voteQuestionDTO.getNomination();
+
+ // String displayOrder = voteQuestionDTO.getDisplayOrder();
+
+ if (question != null && !question.equals("")) {
+ ++queIndex;
+
+ voteQuestionDTO.setNomination(question);
+ voteQuestionDTO.setDisplayOrder(new Integer(queIndex).toString());
+
+ listFinalQuestionDTO.add(voteQuestionDTO);
+ }
+ }
+
+ return listFinalQuestionDTO;
+ }
+
+ @SuppressWarnings("rawtypes")
+ public static boolean checkDuplicateNominations(List listQuestionDTO, String newQuestion) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("New Question" + newQuestion);
+ }
+
+ Map mapQuestion = AuthoringAction.extractMapQuestion(listQuestionDTO);
+
+ Iterator itMap = mapQuestion.entrySet().iterator();
+ while (itMap.hasNext()) {
+ Map.Entry pairs = (Map.Entry) itMap.next();
+ if (pairs.getValue() != null && !pairs.getValue().equals("")) {
+
+ if (pairs.getValue().equals(newQuestion)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ protected static Map extractMapQuestion(List listQuestionDTO) {
+ Map mapQuestion = new TreeMap(new VoteComparator());
+
+ Iterator iter = listQuestionDTO.iterator();
+ int queIndex = 0;
+ while (iter.hasNext()) {
+ VoteQuestionDTO voteQuestionDTO = (VoteQuestionDTO) iter.next();
+
+ queIndex++;
+ mapQuestion.put(new Integer(queIndex).toString(), voteQuestionDTO.getNomination());
+ }
+ return mapQuestion;
+ }
+
+ protected static List reorderUpdateListQuestionDTO(List listQuestionDTO,
+ VoteQuestionDTO voteQuestionDTONew, String editableQuestionIndex) {
+
+ List listFinalQuestionDTO = new LinkedList();
+
+ int queIndex = 0;
+ Iterator iter = listQuestionDTO.iterator();
+ while (iter.hasNext()) {
+ VoteQuestionDTO voteQuestionDTO = (VoteQuestionDTO) iter.next();
+
+ ++queIndex;
+ String question = voteQuestionDTO.getNomination();
+
+ String displayOrder = voteQuestionDTO.getDisplayOrder();
+
+ if (displayOrder.equals(editableQuestionIndex)) {
+ voteQuestionDTO.setNomination(voteQuestionDTONew.getNomination());
+ voteQuestionDTO.setDisplayOrder(voteQuestionDTONew.getDisplayOrder());
+
+ listFinalQuestionDTO.add(voteQuestionDTO);
+ } else {
+ voteQuestionDTO.setNomination(question);
+ voteQuestionDTO.setDisplayOrder(displayOrder);
+
+ listFinalQuestionDTO.add(voteQuestionDTO);
+ }
+ }
+
+ return listFinalQuestionDTO;
+ }
+
+ protected static VoteContent saveOrUpdateVoteContent(IVoteService voteService, VoteAuthoringForm voteAuthoringForm,
+ HttpServletRequest request, VoteContent voteContent, String strToolContentID) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("ToolContentID" + strToolContentID);
+ }
+ UserDTO toolUser = (UserDTO) SessionManager.getSession().getAttribute(AttributeNames.USER);
+
+ String richTextTitle = request.getParameter(VoteAppConstants.TITLE);
+ String richTextInstructions = request.getParameter(VoteAppConstants.INSTRUCTIONS);
+
+ String lockOnFinish = request.getParameter("lockOnFinish");
+
+ String allowTextEntry = request.getParameter("allowText");
+
+ String showResults = request.getParameter("showResults");
+
+ String maxInputs = request.getParameter("maxInputs");
+
+ String useSelectLeaderToolOuput = request.getParameter("useSelectLeaderToolOuput");
+
+ String reflect = request.getParameter(VoteAppConstants.REFLECT);
+
+ String reflectionSubject = voteAuthoringForm.getReflectionSubject();
+
+ String maxNomcount = voteAuthoringForm.getMaxNominationCount();
+
+ String minNomcount = voteAuthoringForm.getMinNominationCount();
+
+ boolean lockOnFinishBoolean = false;
+ boolean allowTextEntryBoolean = false;
+ boolean useSelectLeaderToolOuputBoolean = false;
+ boolean reflectBoolean = false;
+ boolean showResultsBoolean = false;
+ short maxInputsShort = 0;
+
+ if (lockOnFinish != null && lockOnFinish.equalsIgnoreCase("1")) {
+ lockOnFinishBoolean = true;
+ }
+
+ if (allowTextEntry != null && allowTextEntry.equalsIgnoreCase("1")) {
+ allowTextEntryBoolean = true;
+ }
+
+ if (useSelectLeaderToolOuput != null && useSelectLeaderToolOuput.equalsIgnoreCase("1")) {
+ useSelectLeaderToolOuputBoolean = true;
+ }
+
+ if (reflect != null && reflect.equalsIgnoreCase("1")) {
+ reflectBoolean = true;
+ }
+
+ if (showResults != null && showResults.equalsIgnoreCase("1")) {
+ showResultsBoolean = true;
+ }
+
+ if (maxInputs != null && !"0".equals(maxInputs)) {
+ maxInputsShort = Short.parseShort(maxInputs);
+ }
+
+ long userId = 0;
+ if (toolUser != null) {
+ userId = toolUser.getUserID().longValue();
+ } else {
+ HttpSession ss = SessionManager.getSession();
+ UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER);
+ if (user != null) {
+ userId = user.getUserID().longValue();
+ } else {
+ userId = 0;
+ }
+ }
+
+ boolean newContent = false;
+ if (voteContent == null) {
+ voteContent = new VoteContent();
+ newContent = true;
+ }
+
+ voteContent.setVoteContentId(new Long(strToolContentID));
+ voteContent.setTitle(richTextTitle);
+ voteContent.setInstructions(richTextInstructions);
+ voteContent.setUpdateDate(new Date(System.currentTimeMillis()));
+ /** keep updating this one */
+ voteContent.setCreatedBy(userId);
+ /** make sure we are setting the userId from the User object above */
+
+ voteContent.setLockOnFinish(lockOnFinishBoolean);
+ voteContent.setAllowText(allowTextEntryBoolean);
+ voteContent.setShowResults(showResultsBoolean);
+ voteContent.setUseSelectLeaderToolOuput(useSelectLeaderToolOuputBoolean);
+ voteContent.setReflect(reflectBoolean);
+ voteContent.setMaxNominationCount(maxNomcount);
+ voteContent.setMinNominationCount(minNomcount);
+
+ voteContent.setReflectionSubject(reflectionSubject);
+
+ voteContent.setMaxExternalInputs(maxInputsShort);
+
+ if (newContent) {
+ logger.info("In New Content");
+ voteService.saveVoteContent(voteContent);
+ } else {
+ voteService.updateVote(voteContent);
+ }
+
+ voteContent = voteService.getVoteContent(new Long(strToolContentID));
+
+ return voteContent;
+ }
+
+}
Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/action/ClearSessionAction.java
===================================================================
diff -u
--- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/action/ClearSessionAction.java (revision 0)
+++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/action/ClearSessionAction.java (revision 571d64337ed3fb6a9733a5214180fd4a5c6d6292)
@@ -0,0 +1,51 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+package org.lamsfoundation.lams.tool.vote.web.action;
+
+import javax.servlet.http.HttpSession;
+
+import org.apache.log4j.Logger;
+import org.lamsfoundation.lams.authoring.web.AuthoringConstants;
+import org.lamsfoundation.lams.authoring.web.LamsAuthoringFinishAction;
+import org.lamsfoundation.lams.tool.ToolAccessMode;
+import org.lamsfoundation.lams.tool.vote.VoteAppConstants;
+
+/**
+ * This class give a chance to clear HttpSession when user save/close authoring page.
+ *
+ * @author Steve.Ni, Ozgur Demirtas
+ */
+public class ClearSessionAction extends LamsAuthoringFinishAction implements VoteAppConstants {
+ private static Logger logger = Logger.getLogger(ClearSessionAction.class.getName());
+
+ @Override
+ public void clearSession(String customiseSessionID, HttpSession session, ToolAccessMode mode) {
+ session.removeAttribute(AuthoringConstants.LAMS_AUTHORING_SUCCESS_FLAG);
+ if (mode.isAuthor()) {
+ ClearSessionAction.logger.debug("In Author mode");
+ session.removeAttribute(customiseSessionID);
+ }
+ }
+
+}
Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/action/LearningAction.java
===================================================================
diff -u
--- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/action/LearningAction.java (revision 0)
+++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/action/LearningAction.java (revision 571d64337ed3fb6a9733a5214180fd4a5c6d6292)
@@ -0,0 +1,1084 @@
+/***************************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ***********************************************************************/
+
+package org.lamsfoundation.lams.tool.vote.web.action;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TimeZone;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+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.apache.tomcat.util.json.JSONException;
+import org.apache.tomcat.util.json.JSONObject;
+import org.lamsfoundation.lams.learning.web.util.LearningWebUtil;
+import org.lamsfoundation.lams.notebook.model.NotebookEntry;
+import org.lamsfoundation.lams.notebook.service.CoreNotebookConstants;
+import org.lamsfoundation.lams.tool.ToolAccessMode;
+import org.lamsfoundation.lams.tool.exception.DataMissingException;
+import org.lamsfoundation.lams.tool.exception.ToolException;
+import org.lamsfoundation.lams.tool.vote.VoteAppConstants;
+import org.lamsfoundation.lams.tool.vote.dto.VoteGeneralLearnerFlowDTO;
+import org.lamsfoundation.lams.tool.vote.pojos.VoteContent;
+import org.lamsfoundation.lams.tool.vote.pojos.VoteQueContent;
+import org.lamsfoundation.lams.tool.vote.pojos.VoteQueUsr;
+import org.lamsfoundation.lams.tool.vote.pojos.VoteSession;
+import org.lamsfoundation.lams.tool.vote.pojos.VoteUsrAttempt;
+import org.lamsfoundation.lams.tool.vote.service.IVoteService;
+import org.lamsfoundation.lams.tool.vote.service.VoteServiceProxy;
+import org.lamsfoundation.lams.tool.vote.util.VoteApplicationException;
+import org.lamsfoundation.lams.tool.vote.util.VoteComparator;
+import org.lamsfoundation.lams.tool.vote.util.VoteUtils;
+import org.lamsfoundation.lams.tool.vote.web.form.VoteLearningForm;
+import org.lamsfoundation.lams.usermanagement.dto.UserDTO;
+import org.lamsfoundation.lams.util.DateUtil;
+import org.lamsfoundation.lams.util.WebUtil;
+import org.lamsfoundation.lams.web.action.LamsDispatchAction;
+import org.lamsfoundation.lams.web.session.SessionManager;
+import org.lamsfoundation.lams.web.util.AttributeNames;
+
+/**
+ * @author Ozgur Demirtas
+ */
+public class LearningAction extends LamsDispatchAction implements VoteAppConstants {
+ private static Logger logger = Logger.getLogger(LearningAction.class.getName());
+
+ private static IVoteService voteService;
+
+ /**
+ *
+ * main content/question content management and workflow logic
+ *
+ * if the passed toolContentID exists in the db, we need to get the relevant
+ * data into the Map if not, create the default Map
+ */
+ @Override
+ public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws IOException, ServletException {
+ VoteLearningForm voteLearningForm = (VoteLearningForm) form;
+ voteLearningForm.setNominationsSubmited(new Boolean(false).toString());
+
+ repopulateRequestParameters(request, voteLearningForm);
+
+ VoteUtils.cleanUpUserExceptions(request);
+ voteLearningForm.setMaxNominationCountReached(new Boolean(false).toString());
+ voteLearningForm.setMinNominationCountReached(new Boolean(false).toString());
+ return null;
+ }
+
+ public ActionForward viewAllResults(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws IOException, ServletException {
+ VoteUtils.cleanUpUserExceptions(request);
+ VoteLearningForm voteLearningForm = (VoteLearningForm) form;
+ VoteGeneralLearnerFlowDTO voteGeneralLearnerFlowDTO = new VoteGeneralLearnerFlowDTO();
+
+ voteLearningForm.setNominationsSubmited(new Boolean(false).toString());
+ voteLearningForm.setMaxNominationCountReached(new Boolean(false).toString());
+ voteLearningForm.setMinNominationCountReached(new Boolean(false).toString());
+
+ voteGeneralLearnerFlowDTO.setNominationsSubmited(new Boolean(false).toString());
+ voteGeneralLearnerFlowDTO.setMaxNominationCountReached(new Boolean(false).toString());
+ voteGeneralLearnerFlowDTO.setMinNominationCountReached(new Boolean(false).toString());
+
+ IVoteService voteService = VoteServiceProxy.getVoteService(getServlet().getServletContext());
+ repopulateRequestParameters(request, voteLearningForm);
+
+ String toolSessionID = request.getParameter(TOOL_SESSION_ID);
+ logger.info("Tool session ID" + toolSessionID);
+ voteLearningForm.setToolSessionID(toolSessionID);
+
+ String userID = request.getParameter(USER_ID);
+ voteLearningForm.setUserID(userID);
+
+ VoteSession voteSession = voteService.getSessionBySessionId(new Long(toolSessionID));
+ VoteContent voteContent = voteSession.getVoteContent();
+
+ voteGeneralLearnerFlowDTO.setActivityTitle(voteContent.getTitle());
+ voteGeneralLearnerFlowDTO.setActivityInstructions(voteContent.getInstructions());
+
+ Long toolContentID = voteContent.getVoteContentId();
+
+ Long toolSessionUid = voteSession.getUid();
+
+ VoteQueUsr existingVoteQueUsr = voteService.getVoteUserBySession(new Long(userID), voteSession.getUid());
+
+ existingVoteQueUsr.setFinalScreenRequested(true);
+ voteService.updateVoteUser(existingVoteQueUsr);
+
+ Set userAttempts = voteService.getAttemptsForUserAndSession(existingVoteQueUsr.getUid(),
+ toolSessionUid);
+ request.setAttribute(LIST_GENERAL_CHECKED_OPTIONS_CONTENT, userAttempts);
+
+ voteService.prepareChartData(request, toolContentID, toolSessionUid, voteGeneralLearnerFlowDTO);
+
+ voteGeneralLearnerFlowDTO.setReflection(new Boolean(voteContent.isReflect()).toString());
+ //String reflectionSubject = VoteUtils.replaceNewLines(voteContent.getReflectionSubject());
+ voteGeneralLearnerFlowDTO.setReflectionSubject(voteContent.getReflectionSubject());
+
+ voteLearningForm.resetCommands();
+
+ request.setAttribute(VOTE_GENERAL_LEARNER_FLOW_DTO, voteGeneralLearnerFlowDTO);
+
+ LearningWebUtil.putActivityPositionInRequestByToolSessionId(new Long(toolSessionID), request,
+ getServlet().getServletContext());
+
+ return (mapping.findForward(ALL_NOMINATIONS));
+ }
+
+ public ActionForward viewAnswers(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws IOException, ServletException {
+ VoteUtils.cleanUpUserExceptions(request);
+
+ VoteLearningForm voteLearningForm = (VoteLearningForm) form;
+ VoteGeneralLearnerFlowDTO voteGeneralLearnerFlowDTO = new VoteGeneralLearnerFlowDTO();
+
+ voteLearningForm.setNominationsSubmited(new Boolean(false).toString());
+ voteLearningForm.setMaxNominationCountReached(new Boolean(false).toString());
+ voteLearningForm.setMinNominationCountReached(new Boolean(false).toString());
+
+ voteGeneralLearnerFlowDTO.setNominationsSubmited(new Boolean(false).toString());
+ voteGeneralLearnerFlowDTO.setMaxNominationCountReached(new Boolean(false).toString());
+ voteGeneralLearnerFlowDTO.setMinNominationCountReached(new Boolean(false).toString());
+
+ IVoteService voteService = VoteServiceProxy.getVoteService(getServlet().getServletContext());
+
+ repopulateRequestParameters(request, voteLearningForm);
+
+ String toolSessionID = request.getParameter(TOOL_SESSION_ID);
+ logger.info("Tool session id :" + toolSessionID);
+ voteLearningForm.setToolSessionID(toolSessionID);
+
+ String userID = request.getParameter(USER_ID);
+ logger.info("User id :" + userID);
+ voteLearningForm.setUserID(userID);
+
+ String revisitingUser = request.getParameter(REVISITING_USER);
+ voteLearningForm.setRevisitingUser(revisitingUser);
+
+ VoteSession voteSession = voteService.getSessionBySessionId(new Long(toolSessionID));
+ VoteContent voteContent = voteSession.getVoteContent();
+
+ voteGeneralLearnerFlowDTO.setActivityTitle(voteContent.getTitle());
+ voteGeneralLearnerFlowDTO.setActivityInstructions(voteContent.getInstructions());
+
+ if (revisitingUser.equals("true")) {
+ /* get back login user DTO */
+ HttpSession ss = SessionManager.getSession();
+ UserDTO toolUser = (UserDTO) ss.getAttribute(AttributeNames.USER);
+ long userId = toolUser.getUserID().longValue();
+ VoteQueUsr voteQueUsr = voteService.getUserByUserId(userId);
+
+ List attempts = voteService.getAttemptsForUser(voteQueUsr.getUid());
+
+ Map mapQuestionsContent = new TreeMap(new VoteComparator());
+ Iterator listIterator = attempts.iterator();
+ int order = 0;
+ while (listIterator.hasNext()) {
+ VoteUsrAttempt attempt = (VoteUsrAttempt) listIterator.next();
+ VoteQueContent voteQueContent = attempt.getVoteQueContent();
+ order++;
+ if (voteQueContent != null) {
+ mapQuestionsContent.put(new Integer(order).toString(), voteQueContent.getQuestion());
+ }
+ }
+ request.setAttribute(MAP_GENERAL_CHECKED_OPTIONS_CONTENT, mapQuestionsContent);
+ } else {
+ //this is not a revisiting user
+ logger.info("If not a revisiting user");
+ }
+
+ voteLearningForm.resetCommands();
+
+ request.setAttribute(VOTE_GENERAL_LEARNER_FLOW_DTO, voteGeneralLearnerFlowDTO);
+ LearningWebUtil.putActivityPositionInRequestByToolSessionId(new Long(toolSessionID), request,
+ getServlet().getServletContext());
+ return (mapping.findForward(VIEW_ANSWERS));
+ }
+
+ public ActionForward redoQuestionsOk(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws IOException, ServletException {
+ VoteUtils.cleanUpUserExceptions(request);
+
+ IVoteService voteService = VoteServiceProxy.getVoteService(getServlet().getServletContext());
+
+ VoteLearningForm voteLearningForm = (VoteLearningForm) form;
+ VoteGeneralLearnerFlowDTO voteGeneralLearnerFlowDTO = new VoteGeneralLearnerFlowDTO();
+
+ repopulateRequestParameters(request, voteLearningForm);
+
+ String toolSessionID = request.getParameter(TOOL_SESSION_ID);
+ logger.info("Tool session id:" + toolSessionID);
+ voteLearningForm.setToolSessionID(toolSessionID);
+
+ String userID = request.getParameter(USER_ID);
+ logger.info("User id:" + userID);
+ voteLearningForm.setUserID(userID);
+
+ String revisitingUser = request.getParameter(REVISITING_USER);
+ voteLearningForm.setRevisitingUser(revisitingUser);
+
+ voteLearningForm.setNominationsSubmited(new Boolean(false).toString());
+ voteLearningForm.setMaxNominationCountReached(new Boolean(false).toString());
+ voteLearningForm.setMinNominationCountReached(new Boolean(false).toString());
+
+ voteGeneralLearnerFlowDTO.setNominationsSubmited(new Boolean(false).toString());
+ voteGeneralLearnerFlowDTO.setMaxNominationCountReached(new Boolean(false).toString());
+ voteGeneralLearnerFlowDTO.setMinNominationCountReached(new Boolean(false).toString());
+
+ VoteSession voteSession = voteService.getSessionBySessionId(new Long(toolSessionID));
+ VoteContent voteContent = voteSession.getVoteContent();
+ voteGeneralLearnerFlowDTO.setActivityTitle(voteContent.getTitle());
+ voteGeneralLearnerFlowDTO.setActivityInstructions(voteContent.getInstructions());
+
+ voteGeneralLearnerFlowDTO.setReflection(new Boolean(voteContent.isReflect()).toString());
+ //String reflectionSubject = VoteUtils.replaceNewLines(voteContent.getReflectionSubject());
+ voteGeneralLearnerFlowDTO.setReflectionSubject(voteContent.getReflectionSubject());
+
+ voteLearningForm.resetCommands();
+
+ request.setAttribute(VOTE_GENERAL_LEARNER_FLOW_DTO, voteGeneralLearnerFlowDTO);
+ return redoQuestions(mapping, form, request, response);
+ }
+
+ public ActionForward learnerFinished(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws IOException, ServletException {
+ VoteGeneralLearnerFlowDTO voteGeneralLearnerFlowDTO = new VoteGeneralLearnerFlowDTO();
+ VoteLearningForm voteLearningForm = (VoteLearningForm) form;
+
+ voteLearningForm.setNominationsSubmited(new Boolean(false).toString());
+ voteLearningForm.setMaxNominationCountReached(new Boolean(false).toString());
+ voteLearningForm.setMinNominationCountReached(new Boolean(false).toString());
+
+ voteGeneralLearnerFlowDTO.setNominationsSubmited(new Boolean(false).toString());
+ voteGeneralLearnerFlowDTO.setMaxNominationCountReached(new Boolean(false).toString());
+ voteGeneralLearnerFlowDTO.setMinNominationCountReached(new Boolean(false).toString());
+
+ IVoteService voteService = VoteServiceProxy.getVoteService(getServlet().getServletContext());
+
+ repopulateRequestParameters(request, voteLearningForm);
+
+ String toolSessionID = request.getParameter(TOOL_SESSION_ID);
+ logger.info("Tool Session id :" + toolSessionID);
+ voteLearningForm.setToolSessionID(toolSessionID);
+
+ VoteSession voteSession = voteService.getSessionBySessionId(new Long(toolSessionID));
+ String userID = request.getParameter(USER_ID);
+ logger.info("User id:" + userID);
+ voteLearningForm.setUserID(userID);
+
+ VoteQueUsr voteQueUsr = voteService.getVoteUserBySession(new Long(userID), voteSession.getUid());
+
+ voteQueUsr.setResponseFinalised(true);
+ if (!voteSession.getVoteContent().isShowResults()) {
+ // if not isShowResults then we will have skipped the final screen.
+ voteQueUsr.setFinalScreenRequested(true);
+ }
+ voteService.updateVoteUser(voteQueUsr);
+
+ String revisitingUser = request.getParameter(REVISITING_USER);
+ voteLearningForm.setRevisitingUser(revisitingUser);
+
+ VoteContent voteContent = voteSession.getVoteContent();
+
+ voteGeneralLearnerFlowDTO.setActivityTitle(voteContent.getTitle());
+ voteGeneralLearnerFlowDTO.setActivityInstructions(voteContent.getInstructions());
+
+ voteGeneralLearnerFlowDTO.setReflection(new Boolean(voteContent.isReflect()).toString());
+ //String reflectionSubject = VoteUtils.replaceNewLines(voteContent.getReflectionSubject());
+ voteGeneralLearnerFlowDTO.setReflectionSubject(voteContent.getReflectionSubject());
+
+ request.setAttribute(VOTE_GENERAL_LEARNER_FLOW_DTO, voteGeneralLearnerFlowDTO);
+
+ VoteUtils.cleanUpUserExceptions(request);
+
+ String nextUrl = null;
+ try {
+ nextUrl = voteService.leaveToolSession(new Long(toolSessionID), new Long(userID));
+ } catch (DataMissingException e) {
+ logger.error("failure getting nextUrl: " + e);
+ voteLearningForm.resetCommands();
+ //throw new ServletException(e);
+ return (mapping.findForward(LEARNING_STARTER));
+ } catch (ToolException e) {
+ logger.error("failure getting nextUrl: " + e);
+ voteLearningForm.resetCommands();
+ //throw new ServletException(e);
+ return (mapping.findForward(LEARNING_STARTER));
+ } catch (Exception e) {
+ logger.error("unknown exception getting nextUrl: " + e);
+ voteLearningForm.resetCommands();
+ //throw new ServletException(e);
+ return (mapping.findForward(LEARNING_STARTER));
+ }
+
+ voteLearningForm.resetCommands();
+
+ /* pay attention here */
+ response.sendRedirect(nextUrl);
+
+ return null;
+
+ }
+
+ public ActionForward continueOptionsCombined(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws IOException, ServletException {
+ VoteUtils.cleanUpUserExceptions(request);
+ VoteGeneralLearnerFlowDTO voteGeneralLearnerFlowDTO = new VoteGeneralLearnerFlowDTO();
+ VoteLearningForm voteLearningForm = (VoteLearningForm) form;
+
+ IVoteService voteService = VoteServiceProxy.getVoteService(getServlet().getServletContext());
+ repopulateRequestParameters(request, voteLearningForm);
+
+ String toolSessionID = request.getParameter(TOOL_SESSION_ID);
+ logger.info("Tool session id:" + toolSessionID);
+ voteLearningForm.setToolSessionID(toolSessionID);
+
+ String userID = request.getParameter(USER_ID);
+ logger.info("User id:" + userID);
+ voteLearningForm.setUserID(userID);
+
+ String maxNominationCount = request.getParameter(MAX_NOMINATION_COUNT);
+ voteLearningForm.setMaxNominationCount(maxNominationCount);
+
+ String minNominationCount = request.getParameter(MIN_NOMINATION_COUNT);
+ voteLearningForm.setMinNominationCount(minNominationCount);
+
+ String userEntry = request.getParameter(USER_ENTRY);
+ voteLearningForm.setUserEntry(userEntry);
+
+ VoteSession session = voteService.getSessionBySessionId(new Long(toolSessionID));
+ voteLearningForm.setNominationsSubmited(new Boolean(false).toString());
+ voteLearningForm.setMaxNominationCountReached(new Boolean(false).toString());
+ voteLearningForm.setMinNominationCountReached(new Boolean(false).toString());
+
+ voteGeneralLearnerFlowDTO.setNominationsSubmited(new Boolean(false).toString());
+ voteGeneralLearnerFlowDTO.setMaxNominationCountReached(new Boolean(false).toString());
+ voteGeneralLearnerFlowDTO.setMinNominationCountReached(new Boolean(false).toString());
+
+ Collection voteDisplayOrderIds = voteLearningForm.votesAsCollection();
+
+ // check number of votes
+ int castVoteCount = voteDisplayOrderIds != null ? voteDisplayOrderIds.size() : 0;
+ if ((userEntry != null) && (userEntry.length() > 0)) {
+ ++castVoteCount;
+ }
+
+ int intMaxNominationCount = 0;
+ if (maxNominationCount != null) {
+ intMaxNominationCount = new Integer(maxNominationCount).intValue();
+ }
+
+ if (castVoteCount > intMaxNominationCount) {
+ voteLearningForm.setMaxNominationCountReached(new Boolean(true).toString());
+ voteGeneralLearnerFlowDTO.setMaxNominationCountReached(new Boolean(true).toString());
+ persistInRequestError(request, "error.maxNominationCount.reached");
+ logger.error("You have selected too many nominations.");
+ return (mapping.findForward(LOAD_LEARNER));
+ }
+
+ VoteContent voteContent = session.getVoteContent();
+
+ voteGeneralLearnerFlowDTO.setActivityTitle(voteContent.getTitle());
+ voteGeneralLearnerFlowDTO.setActivityInstructions(voteContent.getInstructions());
+
+ Long toolContentID = voteContent.getVoteContentId();
+ Long voteContentUid = voteContent.getUid();
+
+ boolean userEntryAvailable = false;
+ if ((userEntry != null) && (userEntry.length() > 0)) {
+ userEntryAvailable = true;
+ }
+
+ Long toolSessionUid = session.getUid();
+
+ VoteQueUsr user = voteService.getVoteUserBySession(new Long(userID), session.getUid());
+ if (user == null) {
+ throw new VoteApplicationException(
+ "User with userId= " + userID + " and sessionUid= " + session.getUid() + " doesn't exist.");
+ }
+
+ voteService.removeAttemptsForUserandSession(user.getUid(), session.getUid());
+
+ /*
+ * to minimize changes to working code, convert the String[] array to the mapGeneralCheckedOptionsContent
+ * structure
+ */
+ Map mapGeneralCheckedOptionsContent = voteService.buildQuestionMap(voteContent,
+ voteDisplayOrderIds);
+
+ if (mapGeneralCheckedOptionsContent.size() > 0) {
+ voteService.createAttempt(user, mapGeneralCheckedOptionsContent, "", session, voteContentUid);
+ }
+
+ if ((mapGeneralCheckedOptionsContent.size() == 0 && (userEntryAvailable == true))) {
+ Map mapLeanerCheckedOptionsContent = new TreeMap(new VoteComparator());
+
+ if (userEntry.length() > 0) {
+ voteService.createAttempt(user, mapLeanerCheckedOptionsContent, userEntry, session, voteContentUid);
+ }
+ }
+
+ if ((mapGeneralCheckedOptionsContent.size() > 0) && (userEntryAvailable == true)) {
+ Map mapLeanerCheckedOptionsContent = new TreeMap(new VoteComparator());
+
+ if (userEntry.length() > 0) {
+ voteService.createAttempt(user, mapLeanerCheckedOptionsContent, userEntry, session, voteContentUid);
+ }
+ }
+
+ /* put the map in the request ready for the next screen */
+ request.setAttribute(MAP_GENERAL_CHECKED_OPTIONS_CONTENT, mapGeneralCheckedOptionsContent);
+ voteLearningForm.setMapGeneralCheckedOptionsContent(mapGeneralCheckedOptionsContent);
+ voteGeneralLearnerFlowDTO.setMapGeneralCheckedOptionsContent(mapGeneralCheckedOptionsContent);
+
+ voteLearningForm.setNominationsSubmited(new Boolean(true).toString());
+ voteGeneralLearnerFlowDTO.setNominationsSubmited(new Boolean(true).toString());
+
+ voteService.prepareChartData(request, toolContentID, toolSessionUid, voteGeneralLearnerFlowDTO);
+
+ voteGeneralLearnerFlowDTO.setReflection(new Boolean(voteContent.isReflect()).toString());
+ voteGeneralLearnerFlowDTO.setReflectionSubject(voteContent.getReflectionSubject());
+
+ voteLearningForm.resetCommands();
+ request.setAttribute(VOTE_GENERAL_LEARNER_FLOW_DTO, voteGeneralLearnerFlowDTO);
+
+ return (mapping.findForward(INDIVIDUAL_REPORT));
+ }
+
+ public ActionForward redoQuestions(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws IOException, ServletException {
+ VoteUtils.cleanUpUserExceptions(request);
+
+ VoteGeneralLearnerFlowDTO voteGeneralLearnerFlowDTO = new VoteGeneralLearnerFlowDTO();
+ VoteLearningForm voteLearningForm = (VoteLearningForm) form;
+
+ IVoteService voteService = VoteServiceProxy.getVoteService(getServlet().getServletContext());
+
+ repopulateRequestParameters(request, voteLearningForm);
+
+ String toolSessionID = request.getParameter(TOOL_SESSION_ID);
+ voteLearningForm.setToolSessionID(toolSessionID);
+
+ String userID = request.getParameter(USER_ID);
+ voteLearningForm.setUserID(userID);
+
+ String revisitingUser = request.getParameter(REVISITING_USER);
+ voteLearningForm.setRevisitingUser(revisitingUser);
+
+ VoteSession voteSession = voteService.getSessionBySessionId(new Long(toolSessionID));
+
+ VoteContent voteContent = voteSession.getVoteContent();
+
+ voteGeneralLearnerFlowDTO.setActivityTitle(voteContent.getTitle());
+ voteGeneralLearnerFlowDTO.setActivityInstructions(voteContent.getInstructions());
+
+ voteLearningForm.setNominationsSubmited(new Boolean(false).toString());
+ voteLearningForm.setMaxNominationCountReached(new Boolean(false).toString());
+
+ voteGeneralLearnerFlowDTO.setNominationsSubmited(new Boolean(false).toString());
+ voteGeneralLearnerFlowDTO.setMaxNominationCountReached(new Boolean(false).toString());
+
+ Map mapQuestionsContent = voteService.buildQuestionMap(voteContent, null);
+ request.setAttribute(MAP_QUESTION_CONTENT_LEARNER, mapQuestionsContent);
+
+ Map mapGeneralCheckedOptionsContent = new TreeMap(new VoteComparator());
+ request.setAttribute(MAP_GENERAL_CHECKED_OPTIONS_CONTENT, mapGeneralCheckedOptionsContent);
+
+ voteLearningForm.setUserEntry("");
+
+ voteGeneralLearnerFlowDTO.setReflection(new Boolean(voteContent.isReflect()).toString());
+ voteGeneralLearnerFlowDTO.setReflectionSubject(voteContent.getReflectionSubject());
+ voteLearningForm.resetCommands();
+ request.setAttribute(VOTE_GENERAL_LEARNER_FLOW_DTO, voteGeneralLearnerFlowDTO);
+
+ return (mapping.findForward(LOAD_LEARNER));
+ }
+
+ /**
+ * checks Leader Progress
+ */
+ public ActionForward checkLeaderProgress(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws JSONException, IOException {
+
+ IVoteService voteService = VoteServiceProxy.getVoteService(getServlet().getServletContext());
+ Long toolSessionId = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_SESSION_ID);
+
+ VoteSession session = voteService.getSessionBySessionId(toolSessionId);
+ VoteQueUsr leader = session.getGroupLeader();
+ logger.info("Leader :" + leader);
+
+ boolean isLeaderResponseFinalized = leader.isResponseFinalised();
+
+ JSONObject JSONObject = new JSONObject();
+ JSONObject.put("isLeaderResponseFinalized", isLeaderResponseFinalized);
+ response.setContentType("application/x-json;charset=utf-8");
+ response.getWriter().print(JSONObject);
+ return null;
+ }
+
+ public ActionForward submitReflection(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws IOException, ServletException, ToolException {
+ VoteLearningForm voteLearningForm = (VoteLearningForm) form;
+
+ repopulateRequestParameters(request, voteLearningForm);
+
+ IVoteService voteService = VoteServiceProxy.getVoteService(getServlet().getServletContext());
+ String toolSessionID = request.getParameter(AttributeNames.PARAM_TOOL_SESSION_ID);
+ logger.info("Tool Session Id" + toolSessionID);
+ voteLearningForm.setToolSessionID(toolSessionID);
+
+ String userID = request.getParameter("userID");
+ logger.info("User Id:" + userID);
+ voteLearningForm.setUserID(userID);
+
+ String reflectionEntry = request.getParameter(ENTRY_TEXT);
+ logger.info("reflection entry: " + reflectionEntry);
+
+ voteService.createNotebookEntry(new Long(toolSessionID), CoreNotebookConstants.NOTEBOOK_TOOL, MY_SIGNATURE,
+ new Integer(userID), reflectionEntry);
+
+ voteLearningForm.resetUserActions(); /* resets all except submitAnswersContent */
+ return learnerFinished(mapping, form, request, response);
+ }
+
+ public ActionForward forwardtoReflection(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws IOException, ServletException, ToolException {
+ VoteLearningForm voteLearningForm = (VoteLearningForm) form;
+ IVoteService voteService = VoteServiceProxy.getVoteService(getServlet().getServletContext());
+
+ String toolSessionID = request.getParameter(AttributeNames.PARAM_TOOL_SESSION_ID);
+ logger.info("toolSessionID:" + toolSessionID);
+ VoteSession voteSession = voteService.getSessionBySessionId(new Long(toolSessionID));
+
+ VoteContent voteContent = voteSession.getVoteContent();
+ VoteGeneralLearnerFlowDTO voteGeneralLearnerFlowDTO = new VoteGeneralLearnerFlowDTO();
+ voteGeneralLearnerFlowDTO.setActivityTitle(voteContent.getTitle());
+
+ //String reflectionSubject = voteContent.getReflectionSubject();
+ //reflectionSubject = VoteUtils.replaceNewLines(reflectionSubject);
+
+ voteGeneralLearnerFlowDTO.setReflectionSubject(voteContent.getReflectionSubject());
+
+ String userID = request.getParameter("userID");
+ logger.info("User Id :" + userID);
+ voteLearningForm.setUserID(userID);
+
+ NotebookEntry notebookEntry = voteService.getEntry(new Long(toolSessionID), CoreNotebookConstants.NOTEBOOK_TOOL,
+ MY_SIGNATURE, new Integer(userID));
+
+ if (notebookEntry != null) {
+ String notebookEntryPresentable = notebookEntry.getEntry();
+ voteGeneralLearnerFlowDTO.setNotebookEntry(notebookEntryPresentable);
+ voteLearningForm.setEntryText(notebookEntryPresentable);
+ }
+
+ request.setAttribute(VOTE_GENERAL_LEARNER_FLOW_DTO, voteGeneralLearnerFlowDTO);
+
+ voteLearningForm.resetCommands();
+
+ LearningWebUtil.putActivityPositionInRequestByToolSessionId(new Long(toolSessionID), request,
+ getServlet().getServletContext());
+
+ return (mapping.findForward(NOTEBOOK));
+ }
+
+ protected void repopulateRequestParameters(HttpServletRequest request, VoteLearningForm voteLearningForm) {
+ String toolSessionID = request.getParameter(TOOL_SESSION_ID);
+ voteLearningForm.setToolSessionID(toolSessionID);
+
+ String userID = request.getParameter(USER_ID);
+ voteLearningForm.setUserID(userID);
+
+ String revisitingUser = request.getParameter(REVISITING_USER);
+ voteLearningForm.setRevisitingUser(revisitingUser);
+
+ String previewOnly = request.getParameter(PREVIEW_ONLY);
+ voteLearningForm.setPreviewOnly(previewOnly);
+
+ String maxNominationCount = request.getParameter(MAX_NOMINATION_COUNT);
+ voteLearningForm.setMaxNominationCount(maxNominationCount);
+
+ String minNominationCount = request.getParameter(MIN_NOMINATION_COUNT);
+ voteLearningForm.setMinNominationCount(minNominationCount);
+
+ String useSelectLeaderToolOuput = request.getParameter(USE_SELECT_LEADER_TOOL_OUTPUT);
+ voteLearningForm.setUseSelectLeaderToolOuput(useSelectLeaderToolOuput);
+
+ String allowTextEntry = request.getParameter(ALLOW_TEXT_ENTRY);
+ voteLearningForm.setAllowTextEntry(allowTextEntry);
+
+ String showResults = request.getParameter(SHOW_RESULTS);
+ voteLearningForm.setShowResults(showResults);
+
+ String lockOnFinish = request.getParameter(LOCK_ON_FINISH);
+ voteLearningForm.setLockOnFinish(lockOnFinish);
+
+ String reportViewOnly = request.getParameter(REPORT_VIEW_ONLY);
+ voteLearningForm.setReportViewOnly(reportViewOnly);
+
+ String userEntry = request.getParameter(USER_ENTRY);
+ voteLearningForm.setUserEntry(userEntry);
+
+ String groupLeaderName = request.getParameter(ATTR_GROUP_LEADER_NAME);
+ voteLearningForm.setGroupLeaderName(groupLeaderName);
+
+ String groupLeaderUserId = request.getParameter(ATTR_GROUP_LEADER_USER_ID);
+ voteLearningForm.setGroupLeaderUserId(groupLeaderUserId);
+
+ boolean isUserLeader = WebUtil.readBooleanParam(request, "userLeader");
+ voteLearningForm.setIsUserLeader(isUserLeader);
+ }
+
+ /*
+ * By now, the passed tool session id MUST exist in the db through the calling of: public void
+ * createToolSession(Long toolSessionID, Long toolContentId) by the container.
+ *
+ *
+ * make sure this session exists in tool's session table by now.
+ */
+ public ActionForward start(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws IOException, ServletException, VoteApplicationException {
+
+ VoteUtils.cleanUpUserExceptions(request);
+
+ if (voteService == null) {
+ voteService = VoteServiceProxy.getVoteService(getServlet().getServletContext());
+ }
+
+ VoteGeneralLearnerFlowDTO voteGeneralLearnerFlowDTO = new VoteGeneralLearnerFlowDTO();
+ VoteLearningForm voteLearningForm = (VoteLearningForm) form;
+
+ voteLearningForm.setRevisitingUser(new Boolean(false).toString());
+ voteLearningForm.setUserEntry("");
+ voteLearningForm.setCastVoteCount(0);
+ voteLearningForm.setMaxNominationCountReached(new Boolean(false).toString());
+
+ voteGeneralLearnerFlowDTO.setRevisitingUser(new Boolean(false).toString());
+ voteGeneralLearnerFlowDTO.setUserEntry("");
+ voteGeneralLearnerFlowDTO.setCastVoteCount("0");
+ voteGeneralLearnerFlowDTO.setMaxNominationCountReached(new Boolean(false).toString());
+
+ ActionForward validateParameters = validateParameters(request, mapping, voteLearningForm);
+ if (validateParameters != null) {
+ return validateParameters;
+ }
+
+ String toolSessionID = voteLearningForm.getToolSessionID();
+
+ /*
+ * by now, we made sure that the passed tool session id exists in the db as a new record Make sure we can
+ * retrieve it and the relavent content
+ */
+
+ VoteSession voteSession = voteService.getSessionBySessionId(new Long(toolSessionID));
+
+ if (voteSession == null) {
+ VoteUtils.cleanUpUserExceptions(request);
+ logger.error("error: The tool expects voteSession.");
+ return mapping.findForward(VoteAppConstants.ERROR_LIST);
+ }
+
+ /*
+ * find out what content this tool session is referring to get the content for this tool session Each passed
+ * tool session id points to a particular content. Many to one mapping.
+ */
+ VoteContent voteContent = voteSession.getVoteContent();
+ if (voteContent == null) {
+ VoteUtils.cleanUpUserExceptions(request);
+ logger.error("error: The tool expects voteContent.");
+ persistInRequestError(request, "error.content.doesNotExist");
+ return mapping.findForward(VoteAppConstants.ERROR_LIST);
+ }
+
+ /*
+ * The content we retrieved above must have been created before in Authoring time. And the passed tool session
+ * id already refers to it.
+ */
+ setupAttributes(request, voteContent, voteLearningForm, voteGeneralLearnerFlowDTO);
+
+ voteLearningForm.setToolContentID(voteContent.getVoteContentId().toString());
+ voteGeneralLearnerFlowDTO.setToolContentID(voteContent.getVoteContentId().toString());
+
+ voteLearningForm.setToolContentUID(voteContent.getUid().toString());
+ voteGeneralLearnerFlowDTO.setToolContentUID(voteContent.getUid().toString());
+
+ voteGeneralLearnerFlowDTO.setReflection(new Boolean(voteContent.isReflect()).toString());
+ //String reflectionSubject = VoteUtils.replaceNewLines(voteContent.getReflectionSubject());
+ voteGeneralLearnerFlowDTO.setReflectionSubject(voteContent.getReflectionSubject());
+
+ String mode = voteLearningForm.getLearningMode();
+ voteGeneralLearnerFlowDTO.setLearningMode(mode);
+
+ String userId = voteLearningForm.getUserID();
+ NotebookEntry notebookEntry = voteService.getEntry(new Long(toolSessionID), CoreNotebookConstants.NOTEBOOK_TOOL,
+ VoteAppConstants.MY_SIGNATURE, new Integer(userId));
+ if (notebookEntry != null) {
+ //String notebookEntryPresentable = VoteUtils.replaceNewLines(notebookEntry.getEntry());
+ voteGeneralLearnerFlowDTO.setNotebookEntry(notebookEntry.getEntry());
+ }
+
+ Map mapQuestions = voteService.buildQuestionMap(voteContent, null);
+ request.setAttribute(VoteAppConstants.MAP_QUESTION_CONTENT_LEARNER, mapQuestions);
+
+ request.setAttribute(VoteAppConstants.VOTE_GENERAL_LEARNER_FLOW_DTO, voteGeneralLearnerFlowDTO);
+
+ VoteQueUsr user = null;
+ if ((mode != null) && mode.equals(ToolAccessMode.TEACHER.toString())) {
+ // monitoring mode - user is specified in URL
+ // user may be null if the user was force completed.
+ user = getSpecifiedUser(toolSessionID, WebUtil.readIntParam(request, AttributeNames.PARAM_USER_ID, false));
+ } else {
+ user = getCurrentUser(toolSessionID);
+ }
+
+ // check if there is submission deadline
+ Date submissionDeadline = voteContent.getSubmissionDeadline();
+
+ if (submissionDeadline != null) {
+
+ request.setAttribute(VoteAppConstants.ATTR_SUBMISSION_DEADLINE, submissionDeadline);
+ HttpSession ss = SessionManager.getSession();
+ UserDTO learnerDto = (UserDTO) ss.getAttribute(AttributeNames.USER);
+ TimeZone learnerTimeZone = learnerDto.getTimeZone();
+ Date tzSubmissionDeadline = DateUtil.convertToTimeZoneFromDefault(learnerTimeZone, submissionDeadline);
+ Date currentLearnerDate = DateUtil.convertToTimeZoneFromDefault(learnerTimeZone, new Date());
+ voteGeneralLearnerFlowDTO.setSubmissionDeadline(tzSubmissionDeadline);
+
+ // calculate whether deadline has passed, and if so forward to "submissionDeadline"
+ if (currentLearnerDate.after(tzSubmissionDeadline)) {
+ return mapping.findForward("submissionDeadline");
+ }
+ }
+
+ LearningWebUtil.putActivityPositionInRequestByToolSessionId(new Long(toolSessionID), request,
+ getServlet().getServletContext());
+
+ /* find out if the content is being modified at the moment. */
+ if (voteContent.isDefineLater()) {
+ VoteUtils.cleanUpUserExceptions(request);
+ return mapping.findForward(VoteAppConstants.DEFINE_LATER);
+ }
+
+ //process group leader
+ VoteQueUsr groupLeader = null;
+ if (voteContent.isUseSelectLeaderToolOuput()) {
+ groupLeader = voteService.checkLeaderSelectToolForSessionLeader(user, new Long(toolSessionID));
+
+ // forwards to the leaderSelection page
+ if (groupLeader == null && !mode.equals(ToolAccessMode.TEACHER.toString())) {
+
+ Set groupUsers = voteSession.getVoteQueUsers();
+ request.setAttribute(ATTR_GROUP_USERS, groupUsers);
+ request.setAttribute(TOOL_SESSION_ID, toolSessionID);
+ request.setAttribute(ATTR_CONTENT, voteContent);
+
+ return mapping.findForward(WAIT_FOR_LEADER);
+ }
+
+ // check if leader has submitted all answers
+ if (groupLeader.isResponseFinalised() && !mode.equals(ToolAccessMode.TEACHER.toString())) {
+
+ // in case user joins the lesson after leader has answers some answers already - we need to make sure
+ // he has the same scratches as leader
+ voteService.copyAnswersFromLeader(user, groupLeader);
+
+ user.setFinalScreenRequested(true);
+ user.setResponseFinalised(true);
+ voteService.updateVoteUser(user);
+ }
+
+ // store group leader information
+ voteLearningForm.setGroupLeaderName(groupLeader.getFullname());
+ voteLearningForm.setGroupLeaderUserId(groupLeader.getQueUsrId() != null ? groupLeader.getQueUsrId().toString() : "");
+ boolean isUserLeader = voteService.isUserGroupLeader(user, new Long(toolSessionID));
+ voteLearningForm.setIsUserLeader(isUserLeader);
+ }
+
+ if (mode.equals("teacher")) {
+
+ Long sessionUid = user.getVoteSessionId();
+ putMapQuestionsContentIntoRequest(request, voteService, user);
+ Set userAttempts = voteService.getAttemptsForUserAndSessionUseOpenAnswer(user.getUid(), sessionUid);
+ request.setAttribute(VoteAppConstants.LIST_GENERAL_CHECKED_OPTIONS_CONTENT, userAttempts);
+
+ // since this is progress view, present a screen which can not be edited
+ voteLearningForm.setReportViewOnly(new Boolean(true).toString());
+ voteGeneralLearnerFlowDTO.setReportViewOnly(new Boolean(true).toString());
+
+ voteService.prepareChartData(request, voteContent.getVoteContentId(), voteSession.getUid(),
+ voteGeneralLearnerFlowDTO);
+
+ boolean isGroupedActivity = voteService.isGroupedActivity(new Long(voteLearningForm.getToolContentID()));
+ request.setAttribute("isGroupedActivity", isGroupedActivity);
+
+ return mapping.findForward(VoteAppConstants.EXIT_PAGE);
+ }
+
+ /*
+ * the user's session id AND user id exists in the tool tables goto this screen if the OverAll Results scren has
+ * been already called up by this user
+ */
+ if (user.isFinalScreenRequested()) {
+ Long sessionUid = user.getVoteSessionId();
+ VoteSession voteUserSession = voteService.getVoteSessionByUID(sessionUid);
+ String userSessionId = voteUserSession.getVoteSessionId().toString();
+
+ if (toolSessionID.toString().equals(userSessionId)) {
+ // the learner has already responsed to this content, just generate a read-only report. Use redo
+ // questions for this
+ putMapQuestionsContentIntoRequest(request, voteService, user);
+
+ boolean isResponseFinalised = user.isResponseFinalised();
+ if (isResponseFinalised) {
+ // since the response is finalised present a screen which can not be edited
+ voteLearningForm.setReportViewOnly(new Boolean(true).toString());
+ voteGeneralLearnerFlowDTO.setReportViewOnly(new Boolean(true).toString());
+ }
+
+ Set userAttempts = voteService.getAttemptsForUserAndSessionUseOpenAnswer(user.getUid(),
+ sessionUid);
+ request.setAttribute(VoteAppConstants.LIST_GENERAL_CHECKED_OPTIONS_CONTENT, userAttempts);
+
+ voteService.prepareChartData(request, voteContent.getVoteContentId(), voteSession.getUid(),
+ voteGeneralLearnerFlowDTO);
+
+ String isContentLockOnFinish = voteLearningForm.getLockOnFinish();
+ if (isContentLockOnFinish.equals(new Boolean(true).toString()) && isResponseFinalised == true) {
+ // user with session id: userSessionId should not redo votes. session is locked
+ return mapping.findForward(VoteAppConstants.EXIT_PAGE);
+ }
+
+ voteLearningForm.setRevisitingUser(new Boolean(true).toString());
+ voteGeneralLearnerFlowDTO.setRevisitingUser(new Boolean(true).toString());
+ request.setAttribute(VoteAppConstants.VOTE_GENERAL_LEARNER_FLOW_DTO, voteGeneralLearnerFlowDTO);
+
+ if (isContentLockOnFinish.equals(new Boolean(false).toString()) && isResponseFinalised == true) {
+ // isContentLockOnFinish is false, enable redo of votes
+ return mapping.findForward(VoteAppConstants.REVISITED_ALL_NOMINATIONS);
+ }
+
+ return mapping.findForward(VoteAppConstants.ALL_NOMINATIONS);
+ }
+ }
+ // presenting standard learner screen..
+ return mapping.findForward(VoteAppConstants.LOAD_LEARNER);
+ }
+
+ /**
+ * Build the attempts map and put it in the request, based on the supplied user. If the user is null then the map
+ * will be set but it will be empty TODO This shouldn't go in the request, it should go in our special session map.
+ */
+ private void putMapQuestionsContentIntoRequest(HttpServletRequest request, IVoteService voteService,
+ VoteQueUsr user) {
+ List attempts = null;
+ if (user != null) {
+ attempts = voteService.getAttemptsForUser(user.getUid());
+ }
+ Map localMapQuestionsContent = new TreeMap(new VoteComparator());
+
+ if (attempts != null) {
+
+ Iterator listIterator = attempts.iterator();
+ int order = 0;
+ while (listIterator.hasNext()) {
+ VoteUsrAttempt attempt = (VoteUsrAttempt) listIterator.next();
+ VoteQueContent voteQueContent = attempt.getVoteQueContent();
+ order++;
+ if (voteQueContent != null) {
+ String entry = voteQueContent.getQuestion();
+
+ String questionUid = attempt.getVoteQueContent().getUid().toString();
+ if (entry != null) {
+ if (entry.equals("sample nomination") && questionUid.equals("1")) {
+ localMapQuestionsContent.put(new Integer(order).toString(), attempt.getUserEntry());
+ } else {
+ localMapQuestionsContent.put(new Integer(order).toString(), voteQueContent.getQuestion());
+ }
+ }
+ }
+ }
+ }
+
+ request.setAttribute(VoteAppConstants.MAP_GENERAL_CHECKED_OPTIONS_CONTENT, localMapQuestionsContent);
+ }
+
+ /**
+ * sets up session scope attributes based on content linked to the passed tool session id
+ * setupAttributes(HttpServletRequest request, VoteContent voteContent)
+ *
+ * @param request
+ * @param voteContent
+ */
+ protected void setupAttributes(HttpServletRequest request, VoteContent voteContent,
+ VoteLearningForm voteLearningForm, VoteGeneralLearnerFlowDTO voteGeneralLearnerFlowDTO) {
+
+ Map mapGeneralCheckedOptionsContent = new TreeMap(new VoteComparator());
+ request.setAttribute(VoteAppConstants.MAP_GENERAL_CHECKED_OPTIONS_CONTENT, mapGeneralCheckedOptionsContent);
+
+ voteLearningForm.setActivityTitle(voteContent.getTitle());
+ voteLearningForm.setActivityInstructions(voteContent.getInstructions());
+ voteLearningForm.setMaxNominationCount(voteContent.getMaxNominationCount());
+ voteLearningForm.setMinNominationCount(voteContent.getMinNominationCount());
+ voteLearningForm.setUseSelectLeaderToolOuput(new Boolean(voteContent.isUseSelectLeaderToolOuput()).toString());
+ voteLearningForm.setAllowTextEntry(new Boolean(voteContent.isAllowText()).toString());
+ voteLearningForm.setShowResults(new Boolean(voteContent.isShowResults()).toString());
+ voteLearningForm.setLockOnFinish(new Boolean(voteContent.isLockOnFinish()).toString());
+
+ voteGeneralLearnerFlowDTO.setActivityTitle(voteContent.getTitle());
+ voteGeneralLearnerFlowDTO.setActivityInstructions(voteContent.getInstructions());
+ voteGeneralLearnerFlowDTO.setMaxNominationCount(voteContent.getMaxNominationCount());
+ voteGeneralLearnerFlowDTO.setMinNominationCount(voteContent.getMinNominationCount());
+ voteGeneralLearnerFlowDTO
+ .setUseSelectLeaderToolOuput(new Boolean(voteContent.isUseSelectLeaderToolOuput()).toString());
+ voteGeneralLearnerFlowDTO.setAllowTextEntry(new Boolean(voteContent.isAllowText()).toString());
+ voteGeneralLearnerFlowDTO.setLockOnFinish(new Boolean(voteContent.isLockOnFinish()).toString());
+ voteGeneralLearnerFlowDTO.setActivityTitle(voteContent.getTitle());
+ voteGeneralLearnerFlowDTO.setActivityInstructions(voteContent.getInstructions());
+ }
+
+ protected ActionForward validateParameters(HttpServletRequest request, ActionMapping mapping,
+ VoteLearningForm voteLearningForm) {
+ /*
+ * obtain and setup the current user's data
+ */
+
+ String userID = "";
+ HttpSession ss = SessionManager.getSession();
+
+ if (ss != null) {
+ UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER);
+ if (user != null && user.getUserID() != null) {
+ userID = user.getUserID().toString();
+ logger.info("User Id : " + userID);
+ voteLearningForm.setUserID(userID);
+ }
+ }
+
+ /*
+ * process incoming tool session id and later derive toolContentId from it.
+ */
+ String strToolSessionId = request.getParameter(AttributeNames.PARAM_TOOL_SESSION_ID);
+ long toolSessionID = 0;
+ if (strToolSessionId == null || strToolSessionId.length() == 0) {
+ VoteUtils.cleanUpUserExceptions(request);
+ // persistInRequestError(request, "error.toolSessionId.required");
+ logger.error("error.toolSessionId.required");
+ return mapping.findForward(VoteAppConstants.ERROR_LIST);
+ } else {
+ try {
+ toolSessionID = new Long(strToolSessionId).longValue();
+ voteLearningForm.setToolSessionID(new Long(toolSessionID).toString());
+ } catch (NumberFormatException e) {
+ VoteUtils.cleanUpUserExceptions(request);
+ // persistInRequestError(request, "error.sessionId.numberFormatException");
+ logger.error("add error.sessionId.numberFormatException to ActionMessages.");
+ return mapping.findForward(VoteAppConstants.ERROR_LIST);
+ }
+ }
+
+ /* mode can be learner, teacher or author */
+ String mode = request.getParameter(VoteAppConstants.MODE);
+
+ if (mode == null || mode.length() == 0) {
+ VoteUtils.cleanUpUserExceptions(request);
+ logger.error("mode missing: ");
+ return mapping.findForward(VoteAppConstants.ERROR_LIST);
+ }
+
+ if (!mode.equals("learner") && !mode.equals("teacher") && !mode.equals("author")) {
+ VoteUtils.cleanUpUserExceptions(request);
+ logger.error("mode invalid: ");
+ return mapping.findForward(VoteAppConstants.ERROR_LIST);
+ }
+ voteLearningForm.setLearningMode(mode);
+
+ return null;
+ }
+
+ boolean isSessionCompleted(String userSessionId, IVoteService voteService) {
+ VoteSession voteSession = voteService.getSessionBySessionId(new Long(userSessionId));
+ if (voteSession.getSessionStatus() != null
+ && voteSession.getSessionStatus().equals(VoteAppConstants.COMPLETED)) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * persists error messages to request scope
+ *
+ * @param request
+ * @param message
+ */
+ public void persistInRequestError(HttpServletRequest request, String message) {
+ ActionMessages errors = new ActionMessages();
+ errors.add(Globals.ERROR_KEY, new ActionMessage(message));
+ saveErrors(request, errors);
+ }
+
+ private VoteQueUsr getCurrentUser(String toolSessionId) {
+
+ // get back login user DTO
+ HttpSession ss = SessionManager.getSession();
+ UserDTO toolUser = (UserDTO) ss.getAttribute(AttributeNames.USER);
+ Long userId = new Long(toolUser.getUserID().longValue());
+
+ VoteSession session = voteService.getSessionBySessionId(new Long(toolSessionId));
+ VoteQueUsr user = voteService.getVoteUserBySession(userId, session.getUid());
+ if (user == null) {
+ String userName = toolUser.getLogin();
+ String fullName = toolUser.getFirstName() + " " + toolUser.getLastName();
+
+ user = new VoteQueUsr(userId, userName, fullName, session, new TreeSet());
+ voteService.createVoteQueUsr(user);
+ }
+
+ return user;
+ }
+
+ private VoteQueUsr getSpecifiedUser(String toolSessionId, Integer userId) {
+ VoteSession session = voteService.getSessionBySessionId(new Long(toolSessionId));
+ VoteQueUsr user = voteService.getVoteUserBySession(new Long(userId.intValue()), session.getUid());
+ if (user == null) {
+ logger.error("Unable to find specified user for Vote activity. Screens are likely to fail. SessionId="
+ + new Long(toolSessionId) + " UserId=" + userId);
+ }
+ return user;
+ }
+}
\ No newline at end of file
Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/action/MonitoringAction.java
===================================================================
diff -u
--- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/action/MonitoringAction.java (revision 0)
+++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/action/MonitoringAction.java (revision 571d64337ed3fb6a9733a5214180fd4a5c6d6292)
@@ -0,0 +1,554 @@
+/***************************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ***********************************************************************/
+
+package org.lamsfoundation.lams.tool.vote.web.action;
+
+import java.io.IOException;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.SortedSet;
+import java.util.TimeZone;
+import java.util.TreeMap;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.log4j.Logger;
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionForward;
+import org.apache.struts.action.ActionMapping;
+import org.apache.tomcat.util.json.JSONArray;
+import org.apache.tomcat.util.json.JSONException;
+import org.apache.tomcat.util.json.JSONObject;
+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.vote.VoteAppConstants;
+import org.lamsfoundation.lams.tool.vote.dto.OpenTextAnswerDTO;
+import org.lamsfoundation.lams.tool.vote.dto.SummarySessionDTO;
+import org.lamsfoundation.lams.tool.vote.dto.VoteGeneralAuthoringDTO;
+import org.lamsfoundation.lams.tool.vote.dto.VoteGeneralLearnerFlowDTO;
+import org.lamsfoundation.lams.tool.vote.dto.VoteGeneralMonitoringDTO;
+import org.lamsfoundation.lams.tool.vote.dto.VoteMonitoredUserDTO;
+import org.lamsfoundation.lams.tool.vote.dto.VoteQuestionDTO;
+import org.lamsfoundation.lams.tool.vote.pojos.VoteContent;
+import org.lamsfoundation.lams.tool.vote.pojos.VoteQueContent;
+import org.lamsfoundation.lams.tool.vote.pojos.VoteUsrAttempt;
+import org.lamsfoundation.lams.tool.vote.service.IVoteService;
+import org.lamsfoundation.lams.tool.vote.service.VoteServiceProxy;
+import org.lamsfoundation.lams.tool.vote.util.VoteApplicationException;
+import org.lamsfoundation.lams.tool.vote.util.VoteComparator;
+import org.lamsfoundation.lams.tool.vote.util.VoteUtils;
+import org.lamsfoundation.lams.tool.vote.web.form.VoteMonitoringForm;
+import org.lamsfoundation.lams.usermanagement.dto.UserDTO;
+import org.lamsfoundation.lams.util.DateUtil;
+import org.lamsfoundation.lams.util.WebUtil;
+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
+ */
+public class MonitoringAction extends LamsDispatchAction implements VoteAppConstants {
+ private static Logger logger = Logger.getLogger(MonitoringAction.class.getName());
+
+ /**
+ * main content/question content management and workflow logic
+ */
+ @Override
+ public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws IOException, ServletException {
+ VoteUtils.cleanUpUserExceptions(request);
+ return null;
+ }
+
+ public ActionForward hideOpenVote(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws IOException, ServletException, ToolException, JSONException {
+ return toggleHideShow(request, response, false);
+ }
+
+ public ActionForward showOpenVote(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws IOException, ServletException, ToolException, JSONException {
+ return toggleHideShow(request, response, true);
+ }
+
+ private ActionForward toggleHideShow(HttpServletRequest request, HttpServletResponse response, boolean show)
+ throws IOException, ServletException, ToolException, JSONException {
+
+ IVoteService voteService = VoteServiceProxy.getVoteService(getServlet().getServletContext());
+
+ Long currentUid = WebUtil.readLongParam(request, "currentUid");
+ logger.info("Current Uid" + currentUid);
+
+ VoteUsrAttempt voteUsrAttempt = voteService.getAttemptByUID(currentUid);
+
+ voteUsrAttempt.setVisible(show);
+ voteService.updateVoteUsrAttempt(voteUsrAttempt);
+ String nextActionMethod;
+ if (show) {
+ nextActionMethod = "hideOptionVote";
+ voteService.showOpenVote(voteUsrAttempt);
+ } else {
+ nextActionMethod = "showOpenVote";
+ voteService.hideOpenVote(voteUsrAttempt);
+ }
+
+ JSONObject responsedata = new JSONObject();
+ responsedata.put("currentUid", currentUid);
+ responsedata.put("nextActionMethod", nextActionMethod);
+ response.setContentType("application/json;charset=utf-8");
+ response.getWriter().print(new String(responsedata.toString()));
+ return null;
+ }
+
+ public ActionForward getVoteNomination(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws IOException, ServletException, ToolException {
+
+ IVoteService voteService = VoteServiceProxy.getVoteService(getServlet().getServletContext());
+
+ VoteMonitoringForm voteMonitoringForm = (VoteMonitoringForm) form;
+ voteMonitoringForm.setVoteService(voteService);
+
+ VoteGeneralMonitoringDTO voteGeneralMonitoringDTO = new VoteGeneralMonitoringDTO();
+ MonitoringAction.repopulateRequestParameters(request, voteMonitoringForm, voteGeneralMonitoringDTO);
+
+ Long questionUid = WebUtil.readLongParam(request, VoteAppConstants.ATTR_QUESTION_UID, false);
+ Long sessionUid = WebUtil.readLongParam(request, VoteAppConstants.ATTR_SESSION_UID, true);
+
+ VoteQueContent nomination = voteService.getQuestionByUid(questionUid);
+ request.setAttribute("nominationText", nomination.getQuestion());
+
+ request.setAttribute(VoteAppConstants.VOTE_GENERAL_MONITORING_DTO, voteGeneralMonitoringDTO);
+ request.setAttribute(VoteAppConstants.ATTR_QUESTION_UID, questionUid);
+ if (sessionUid != null) {
+ request.setAttribute(VoteAppConstants.ATTR_SESSION_UID, sessionUid);
+ }
+ return mapping.findForward(VoteAppConstants.VOTE_NOMINATION_VIEWER);
+ }
+
+ public ActionForward getVoteNominationsJSON(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws IOException, ServletException, ToolException, JSONException {
+
+ Long sessionUid = WebUtil.readLongParam(request, VoteAppConstants.ATTR_SESSION_UID, true);
+ if (sessionUid == 0L) {
+ sessionUid = null;
+ logger.info("Setting sessionUid to null");
+ }
+
+ Long questionUid = WebUtil.readLongParam(request, VoteAppConstants.ATTR_QUESTION_UID, false);
+
+ // paging parameters of tablesorter
+ int size = WebUtil.readIntParam(request, "size");
+ int page = WebUtil.readIntParam(request, "page");
+ Integer sortByName = WebUtil.readIntParam(request, "column[0]", true);
+ Integer sortByDate = WebUtil.readIntParam(request, "column[1]", true);
+ String searchString = request.getParameter("fcol[0]");
+
+ int sorting = VoteAppConstants.SORT_BY_DEFAULT;
+ if (sortByName != null) {
+ sorting = sortByName.equals(0) ? VoteAppConstants.SORT_BY_NAME_ASC : VoteAppConstants.SORT_BY_NAME_DESC;
+ } else if (sortByDate != null) {
+ sorting = sortByDate.equals(0) ? VoteAppConstants.SORT_BY_DATE_ASC : VoteAppConstants.SORT_BY_DATE_DESC;
+ }
+
+ //return user list according to the given sessionID
+ IVoteService voteService = VoteServiceProxy.getVoteService(getServlet().getServletContext());
+ List