Index: lams_learning/src/java/org/lamsfoundation/lams/learning/export/web/action/MainExportServlet.java =================================================================== RCS file: /usr/local/cvsroot/lams_learning/src/java/org/lamsfoundation/lams/learning/export/web/action/MainExportServlet.java,v diff -u -r1.6 -r1.7 --- lams_learning/src/java/org/lamsfoundation/lams/learning/export/web/action/MainExportServlet.java 31 Oct 2005 05:24:55 -0000 1.6 +++ lams_learning/src/java/org/lamsfoundation/lams/learning/export/web/action/MainExportServlet.java 7 Dec 2005 00:39:32 -0000 1.7 @@ -60,6 +60,7 @@ import org.lamsfoundation.lams.learning.export.ExportPortfolioException; import org.lamsfoundation.lams.learning.export.ExportPortfolioConstants; import org.lamsfoundation.lams.learning.export.Portfolio; +import org.lamsfoundation.lams.learning.export.ToolPortfolio; import org.lamsfoundation.lams.learning.export.service.IExportPortfolioService; import org.lamsfoundation.lams.learning.export.service.ExportPortfolioService; import org.lamsfoundation.lams.learning.export.service.ExportPortfolioServiceProxy; @@ -89,11 +90,9 @@ private static Logger log = Logger.getLogger(MainExportServlet.class); private String exportTmpDir; - /* TODO: should probably be better getting this value from WebUtil. Change this once the variable names have been settled */ - private static final String PARAM_LESSON_ID = "lessonID"; - + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); @@ -102,76 +101,97 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, ExportPortfolioException{ + String htmlOutput=null; + Portfolio portfolios = null; + /** Get the cookies that were sent along with this request, then pass it onto export service */ Cookie[] cookies = request.getCookies(); IExportPortfolioService exportService = ExportPortfolioServiceProxy.getExportPortfolioService(this.getServletContext()); - String htmlOutput=null; - - Portfolio[] portfolios = null; + String mode = WebUtil.readStrParam(request, AttributeNames.PARAM_MODE); - if (mode.equals(ToolAccessMode.LEARNER.toString())) - { - HttpSession session = SessionManager.getSession(); - UserDTO userDto = (UserDTO)session.getAttribute(AttributeNames.USER); - Integer userId = userDto.getUserID(); - - Long lessonID = new Long(WebUtil.readLongParam(request, "lessonID")); - portfolios = exportService.exportPortfolioForStudent(userId, lessonID, true, cookies); - } - else if(mode.equals(ToolAccessMode.TEACHER.toString())) - { - //done in the monitoring environment - Long lessonID = new Long(WebUtil.readLongParam(request,"lessonID")); + if (mode.equals(ToolAccessMode.LEARNER.toString())) + { + HttpSession session = SessionManager.getSession(); + UserDTO userDto = (UserDTO)session.getAttribute(AttributeNames.USER); + Integer userId = userDto.getUserID(); + + Long lessonID = new Long(WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID)); + portfolios = exportService.exportPortfolioForStudent(userId, lessonID, true, cookies); + } + else if(mode.equals(ToolAccessMode.TEACHER.toString())) + { + //done in the monitoring environment + Long lessonID = new Long(WebUtil.readLongParam(request,AttributeNames.PARAM_LESSON_ID)); + + portfolios = exportService.exportPortfolioForTeacher(lessonID, cookies); + } + + if (portfolios!= null) + { + + exportTmpDir = portfolios.getExportTmpDir(); - portfolios = exportService.exportPortfolioForTeacher(lessonID, cookies); - } + String mainFileName = exportTmpDir+ File.separator + ExportPortfolioConstants.MAIN_EXPORT_FILENAME; + + htmlOutput = generateMainPage(portfolios); - exportTmpDir = exportService.getExportDir(); + //writing the file to the temp export folder. + BufferedWriter fileout = new BufferedWriter(new FileWriter(mainFileName)); + fileout.write(htmlOutput); + fileout.close(); - String mainFileName = exportTmpDir+ File.separator + ExportPortfolioConstants.MAIN_EXPORT_FILENAME; - + //zip up the contents of the temp export folder + String zipFilename = exportService.zipPortfolio(ExportPortfolioConstants.ZIP_FILENAME, exportTmpDir); - htmlOutput = generateMainPage(portfolios); + //return the relative filelocation of the zip file so that it can be picked up in exportWaitingPage.jsp + PrintWriter out = response.getWriter(); + out.println(returnRelativeExportTmpDir(zipFilename)); + } + else + { + //redirect the request to another page. + } - //writing the file to the temp export folder. - BufferedWriter fileout = new BufferedWriter(new FileWriter(mainFileName)); - fileout.write(htmlOutput); - fileout.close(); - - //zip up the contents of the temp export folder - String zipFilename = exportService.zipPortfolio(ExportPortfolioConstants.ZIP_FILENAME, exportTmpDir); - - //return the relative filelocation of the zip file so that it can be picked up in exportWaitingPage.jsp - PrintWriter out = response.getWriter(); - out.println(returnRelativeExportTmpDir(zipFilename)); - } /** * Used StringBuffer for concatenation as it is more efficient than using String * @param portfolios * @return */ - private String generateMainPage(Portfolio[] portfolios) + private String generateMainPage(Portfolio portfolio) { + ToolPortfolio[] portfolios = portfolio.getToolPortfolios(); StringBuffer htmlPage = new StringBuffer(); - htmlPage.append("Export Portfolio"); - htmlPage.append("

Portfolio

Activities

"); - htmlPage.append("
    "); - for (int i=0; i"); - htmlPage.append(portfolios[i].getActivityName()) - .append(" ") - .append(portfolios[i].getActivityDescription()).append(""); - htmlPage.append(""); + + htmlPage.append("Export Portfolio"); + htmlPage.append("

    Portfolio

    Activities

    "); + htmlPage.append("
      "); + for (int i=0; i"); + htmlPage.append(portfolios[i].getActivityName()) + .append(" ") + .append(portfolios[i].getActivityDescription()).append(""); + htmlPage.append(""); + } + htmlPage.append("
    "); + htmlPage.append(""); + } - htmlPage.append("
"); - htmlPage.append(""); - + else + { + htmlPage.append("Export Portfolio"); + htmlPage.append("

Export Portfolio Failed

"); + htmlPage.append("This sequence does not support portfolio exports"); + htmlPage.append(""); + } return htmlPage.toString(); + }