Index: lams_tool_survey/conf/language/ApplicationResources.properties =================================================================== RCS file: /usr/local/cvsroot/lams_tool_survey/conf/language/Attic/ApplicationResources.properties,v diff -u -r1.19 -r1.20 --- lams_tool_survey/conf/language/ApplicationResources.properties 17 Nov 2006 02:06:44 -0000 1.19 +++ lams_tool_survey/conf/language/ApplicationResources.properties 12 Dec 2006 00:25:42 -0000 1.20 @@ -151,4 +151,6 @@ #======= End labels: Exported 141 labels for en AU ===== -message.no.reflection.available = No notebook available \ No newline at end of file +message.no.reflection.available = No notebook available +label.monitoring..button.export.excel=Export Survey Data +error.monitoring.export.excel=Export Survey data failed becuase of this reason: {0} \ No newline at end of file Index: lams_tool_survey/conf/xdoclet/struts-actions.xml =================================================================== RCS file: /usr/local/cvsroot/lams_tool_survey/conf/xdoclet/struts-actions.xml,v diff -u -r1.9 -r1.10 --- lams_tool_survey/conf/xdoclet/struts-actions.xml 17 Nov 2006 02:06:44 -0000 1.9 +++ lams_tool_survey/conf/xdoclet/struts-actions.xml 12 Dec 2006 00:25:44 -0000 1.10 @@ -237,6 +237,11 @@ parameter="viewReflection"> + + + Index: lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/service/ISurveyService.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/service/ISurveyService.java,v diff -u -r1.10 -r1.11 --- lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/service/ISurveyService.java 24 Nov 2006 00:28:46 -0000 1.10 +++ lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/service/ISurveyService.java 12 Dec 2006 00:25:44 -0000 1.11 @@ -217,6 +217,9 @@ //****************************************************************************************** SortedMap>> exportByLeaner(SurveyUser learner); SortedMap>> exportByContentId(Long toolContentID); + + //This export for exporting Excel format file in Survey monitoring summary page: + SortedMap>> exportBySessionId(Long toolSessionID); //****************************************************************************************** // NOTEBOOK Functions Index: lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/service/SurveyServiceImpl.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/service/SurveyServiceImpl.java,v diff -u -r1.14 -r1.15 --- lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/service/SurveyServiceImpl.java 24 Nov 2006 00:28:46 -0000 1.14 +++ lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/service/SurveyServiceImpl.java 12 Dec 2006 00:25:44 -0000 1.15 @@ -479,6 +479,28 @@ return summary; } + public SortedMap>> exportBySessionId(Long toolSessionID) { + + SortedMap>> summary = + new TreeMap>>(new SurveySessionComparator()); + + //get tool sessions + SurveySession session = surveySessionDao.getSessionBySessionId(toolSessionID); + List users = surveyUserDao.getBySessionID(session.getSessionId()); + + //container for this user's answers + List> learnerAnswers = new ArrayList>(); + if(users != null){ + //for every user, get answers of all questions. + for (SurveyUser user : users) { + List answers = getQuestionAnswers(user.getSession().getSessionId(), user.getUid()); + learnerAnswers.add(answers); + } + } + toQuestionMap(summary, session, learnerAnswers); + + return summary; + } Index: lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/web/action/MonitoringAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/web/action/MonitoringAction.java,v diff -u -r1.9 -r1.10 --- lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/web/action/MonitoringAction.java 28 Sep 2006 05:44:04 -0000 1.9 +++ lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/web/action/MonitoringAction.java 12 Dec 2006 00:25:44 -0000 1.10 @@ -24,32 +24,43 @@ /* $Id$ */ package org.lamsfoundation.lams.tool.survey.web.action; -import static org.lamsfoundation.lams.tool.survey.SurveyConstants.CHART_TYPE; -import static org.lamsfoundation.lams.tool.survey.SurveyConstants.ATTR_QUESTION; import static org.lamsfoundation.lams.tool.survey.SurveyConstants.ATTR_ANSWER_LIST; +import static org.lamsfoundation.lams.tool.survey.SurveyConstants.ATTR_QUESTION; +import static org.lamsfoundation.lams.tool.survey.SurveyConstants.CHART_TYPE; +import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.io.PrintWriter; import java.util.List; import java.util.Map; import java.util.Set; import java.util.SortedMap; import java.util.TreeMap; +import java.util.Map.Entry; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; +import org.apache.poi.hssf.usermodel.HSSFCell; +import org.apache.poi.hssf.usermodel.HSSFRow; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.struts.action.Action; 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.util.MessageResources; import org.lamsfoundation.lams.notebook.model.NotebookEntry; import org.lamsfoundation.lams.notebook.service.CoreNotebookConstants; import org.lamsfoundation.lams.tool.survey.SurveyConstants; import org.lamsfoundation.lams.tool.survey.dto.AnswerDTO; import org.lamsfoundation.lams.tool.survey.dto.ReflectDTO; import org.lamsfoundation.lams.tool.survey.model.Survey; +import org.lamsfoundation.lams.tool.survey.model.SurveyOption; import org.lamsfoundation.lams.tool.survey.model.SurveyQuestion; import org.lamsfoundation.lams.tool.survey.model.SurveySession; import org.lamsfoundation.lams.tool.survey.model.SurveyUser; @@ -63,6 +74,12 @@ import org.springframework.web.context.support.WebApplicationContextUtils; public class MonitoringAction extends Action { + private static final String MSG_LABEL_QUESTION = "label.question"; + private static final String MSG_LABEL_OPEN_RESPONSE = "label.open.response"; + private static final String MSG_LABEL_SESSION_NAME = "label.session.name"; + private static final String MSG_LABEL_POSSIBLE_ANSWERS = "message.possible.answers"; + private static final String MSG_LABEL_LEARNER = "label.learner"; + public static Logger log = Logger.getLogger(MonitoringAction.class); @@ -85,6 +102,10 @@ if (param.equals("viewReflection")) { return viewReflection(mapping, form, request, response); } + + if (param.equals("exportSurvey")) { + return exportSurvey(mapping, form, request, response); + } return mapping.findForward(SurveyConstants.ERROR); } @@ -214,6 +235,189 @@ return mapping.findForward("success"); } + /** + * Export Excel format survey data. + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward exportSurvey(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { + Long toolSessionID =new Long(WebUtil.readLongParam(request,AttributeNames.PARAM_TOOL_SESSION_ID)); + + ISurveyService service = getSurveyService(); + + SortedMap>> groupList = service.exportBySessionId(toolSessionID); + String errors = null; + MessageResources resource = this.getResources(request); + try { + //create an empty excel file + HSSFWorkbook wb = new HSSFWorkbook(); + HSSFSheet sheet = wb.createSheet("Survey"); + sheet.setColumnWidth((short)0,(short)5000); + HSSFRow row; + HSSFCell cell; + int idx = 0; + Set>>> entries = groupList.entrySet(); + for (Entry>> entry : entries) { + SurveySession session = entry.getKey(); + SortedMap> map = entry.getValue(); + //display survey title, instruction and questions + Survey survey = session.getSurvey(); + //survey title + row = sheet.createRow(idx++); + cell = row.createCell((short) 0); + cell.setCellValue(survey.getTitle()); + + //survey instruction + row = sheet.createRow(idx++); + cell = row.createCell((short) 0); + cell.setCellValue(survey.getInstructions()); + + //display 2 empty row + row = sheet.createRow(idx++); + cell = row.createCell((short) 0); + cell.setCellValue(""); + row = sheet.createRow(idx++); + cell = row.createCell((short) 0); + cell.setCellValue(""); + + //display session name + row = sheet.createRow(idx++); + cell = row.createCell((short) 0); + cell.setCellValue(resource.getMessage(MSG_LABEL_SESSION_NAME)); + cell = row.createCell((short) 1); + cell.setCellValue(session.getSessionName()); + + //begin to display question and its answers + Set>> questionEntries = map.entrySet(); + int questionIdx = 0; + for (Entry> questionEntry : questionEntries ) { + //display 1 empty row + row = sheet.createRow(idx++); + cell = row.createCell((short) 0); + cell.setCellValue(""); + + questionIdx++; + SurveyQuestion question = questionEntry.getKey(); + List answers = questionEntry.getValue(); + + //display question content + row = sheet.createRow(idx++); + cell = row.createCell((short) 0); + cell.setCellValue(resource.getMessage(MSG_LABEL_QUESTION) + " " + questionIdx); + cell = row.createCell((short) 1); + cell.setCellValue(question.getDescription()); + + + //display options content + Set options = question.getOptions(); + + row = sheet.createRow(idx++); + cell = row.createCell((short) 0); + cell.setCellValue(resource.getMessage(MSG_LABEL_POSSIBLE_ANSWERS)); + + int optionIdx = 0; + for (SurveyOption option : options) { + optionIdx++; + row = sheet.createRow(idx++); + cell = row.createCell((short) 0); + cell.setCellValue(SurveyConstants.OPTION_SHORT_HEADER + optionIdx); + cell = row.createCell((short) 1); + cell.setCellValue(option.getDescription()); + } + if(question.isAppendText() || question.getType() == SurveyConstants.QUESTION_TYPE_TEXT_ENTRY){ + optionIdx++; + row = sheet.createRow(idx++); + cell = row.createCell((short) 0); + cell.setCellValue(SurveyConstants.OPTION_SHORT_HEADER + optionIdx); + cell = row.createCell((short) 1); + cell.setCellValue(resource.getMessage(MSG_LABEL_OPEN_RESPONSE)); + } + + //display 1 empty row + row = sheet.createRow(idx++); + cell = row.createCell((short) 0); + cell.setCellValue(""); + + //////////////////////////// + //display answer list + //////////////////////////// + // first display option title : a1 , a2, a3 etc + + int cellIdx = 0; + row = sheet.createRow(idx++); + cell = row.createCell((short) cellIdx); + cell.setCellValue(resource.getMessage(MSG_LABEL_LEARNER)); + //increase one more option number if there are open entry option + int optionsNum = options.size(); + if(question.isAppendText() || question.getType() == SurveyConstants.QUESTION_TYPE_TEXT_ENTRY){ + optionsNum++; + } + for(cellIdx = 1; cellIdx<=optionsNum;cellIdx++){ + cell = row.createCell((short) cellIdx); + cell.setCellValue(SurveyConstants.OPTION_SHORT_HEADER + cellIdx); + } + + //display all users' answers for this question in multiple rows + for (AnswerDTO answer: answers) { + row = sheet.createRow(idx++); + cellIdx = 0; + cell = row.createCell((short) cellIdx); + cell.setCellValue(answer.getReplier().getLoginName()); + //for answer's options + for (SurveyOption option : options) { + cellIdx++; + cell = row.createCell((short) cellIdx); + if(answer.getAnswer() == null) + break; + String[] choices = answer.getAnswer().getChoices(); + for (String choice : choices) { + if(StringUtils.equals(choice, option.getUid().toString())){ + cell.setCellValue("X"); + } + } + } + //for textEntry option + if(question.isAppendText() || question.getType() == SurveyConstants.QUESTION_TYPE_TEXT_ENTRY){ + cell = row.createCell((short) ++cellIdx); + if(answer.getAnswer() != null){ + cell.setCellValue(answer.getAnswer().getAnswerText()); + } + } + + } + } + } + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + wb.write(bos); + //construct download file response header + String fileName = "lams_survey_" + toolSessionID+".xls"; + String mineType = "application/vnd.ms-excel"; + String header = "attachment; filename=\"" + fileName + "\";"; + response.setContentType(mineType); + response.setHeader("Content-Disposition",header); + + byte[] data = bos.toByteArray(); + response.getOutputStream().write(data,0,data.length); + response.getOutputStream().flush(); + } catch (Exception e) { + log.error(e); + errors =new ActionMessage("error.monitoring.export.excel",e.toString()).toString(); + } + + if(errors != null){ + try { + PrintWriter out = response.getWriter(); + out.write(errors); + out.flush(); + } catch (IOException e) { + } + } + return null; + } + // ************************************************************************************* // Private method // ************************************************************************************* Index: lams_tool_survey/web/pages/monitoring/summary.jsp =================================================================== RCS file: /usr/local/cvsroot/lams_tool_survey/web/pages/monitoring/summary.jsp,v diff -u -r1.5 -r1.6 --- lams_tool_survey/web/pages/monitoring/summary.jsp 27 Sep 2006 07:44:19 -0000 1.5 +++ lams_tool_survey/web/pages/monitoring/summary.jsp 12 Dec 2006 00:25:44 -0000 1.6 @@ -3,6 +3,15 @@ +
@@ -14,15 +23,15 @@ - - - - -
-
- -
-
+ + + + +
+
+ +
+
<%-- display group name on first row--%> @@ -151,7 +160,15 @@ - + - + + + + +
+ + + +