Index: lams_learning/build.xml =================================================================== diff -u -r058624bba137d9124eed6784321dbecc72a12550 -r6f11dd80335ff2b8a2d06d21f1a49b307ed233c1 --- lams_learning/build.xml (.../build.xml) (revision 058624bba137d9124eed6784321dbecc72a12550) +++ lams_learning/build.xml (.../build.xml) (revision 6f11dd80335ff2b8a2d06d21f1a49b307ed233c1) @@ -240,6 +240,7 @@ + Index: lams_learning/conf/language/ApplicationResources.properties =================================================================== diff -u -ra0722fe03d763f9da5efc82987034d929e6a23a1 -r6f11dd80335ff2b8a2d06d21f1a49b307ed233c1 --- lams_learning/conf/language/ApplicationResources.properties (.../ApplicationResources.properties) (revision a0722fe03d763f9da5efc82987034d929e6a23a1) +++ lams_learning/conf/language/ApplicationResources.properties (.../ApplicationResources.properties) (revision 6f11dd80335ff2b8a2d06d21f1a49b307ed233c1) @@ -1,6 +1,12 @@ # CVS ID: $Id$ # Language strings for the Progress Engine related classes and screens. Mostly error messages. -learner.title=Learner :: LAMS +# Window title +learner.title=LAMS Learner +# General system error for the learner module +error.system.learner=An internal error has occured and this function cannot be completed. If reporting this error, please report:
{0} +# General error displayed if a page cannot be found. +error.message.404=The page you have requested can not be found. + # Message which appears when the learner window is opened or between activities. message.activity.loading=The next task is loading. Please wait.... # Message which appears when the learner finishes a lesson (part 1) @@ -52,20 +58,6 @@ label.preview.definelater.title=Activity is set to Define Later label.preview.definelater.message=The next activity ({0}) is set to define later. Normally a staff member would set the content for the activity before the learner's can access the activity. For the purposes of preview, the default content for the activity will be displayed. -# Export Portfolio internal system error -error.system.exportPortfolio=An internal error has occurred with the Export Portfolio Functionality. If reporting this error, please report:
{0} -# Export Portfolio system error in the learner module -error.system.learner=An internal error has occurred with the Learner Environment. If reporting this error, please report:
{0} -# Export Portfolio internal system error -error.system.export=A system exception has occured and the portfolio could not be generated. Please contact Lams International technical support. -# Export Portfolio Page is missing -error.message.404=The page you have requested can not be found. -# HTML used to create main export page. The lesson name is inserted at {0} and the list of activities are inserted at {1} -export.html.mainPage=Export Portfolio

Export Portfolio

Lesson: {0}

Activities

{1} -# HTML used to create main export page when an portfolio is not available due to system constraints. -export.html.exportFailed=Export Portfolio

Export Portfolio Failed

This sequence does not support portfolio exports -# HTML used to create the export portfolio activity page when an activity does not support export portfolio (stops it being just a blank page) -export.html.exportNotSupported=Export Portfolio Unsupported

Export Portfolio for this activity is unsupported

-# General system error message. -error.system.error=An error has occurred. Please start again. Reason for error: {0} +# Export portfolio: error message put in the activity's page if the activity doesn't support export portfolio. The name of the activity goes in {0} +error.export.portfolio.not.supported=The activity {0} does not support portfolio export. Index: lams_learning/src/java/org/lamsfoundation/lams/learning/export/ActivityPortfolio.java =================================================================== diff -u --- lams_learning/src/java/org/lamsfoundation/lams/learning/export/ActivityPortfolio.java (revision 0) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/export/ActivityPortfolio.java (revision 6f11dd80335ff2b8a2d06d21f1a49b307ed233c1) @@ -0,0 +1,129 @@ +/**************************************************************** + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +/* $$Id$$ */ +package org.lamsfoundation.lams.learning.export; + +import java.util.List; + +/** + * Models the portfolio for any type of activity, including tools, groupings, gates, optional and parallel activities + * @author mtruong, fmalikoff + * + */ +public class ActivityPortfolio { + + private Long activityId; + private String activityDescription; + private String activityName; + private String exportUrl; + private List childPortfolios; + /* The link to the tool page from the main export page */ + private String toolLink; + + /** + * @return Returns the toolLink. + */ + public String getToolLink() { + return toolLink; + } + /** + * @param toolLink The toolLink to set. + */ + public void setToolLink(String toolLink) { + this.toolLink = toolLink; + } + + public ActivityPortfolio() + { + this.activityId = null; + this.activityDescription = null; + this.activityName = null; + this.exportUrl = null; + this.toolLink = null; + this.childPortfolios = null; + } + + + + /** + * @return Returns the activityName. + */ + public String getActivityName() { + return activityName; + } + /** + * @param activityName The activityName to set. + */ + public void setActivityName(String activityName) { + this.activityName = activityName; + } + + /** + * @return Returns the exportUrl. + */ + public String getExportUrl() { + return exportUrl; + } + /** + * @param exportUrl The exportUrl to set. + */ + public void setExportUrl(String exportUrl) { + this.exportUrl = exportUrl; + } + + /** + * @return Returns the activityId. + */ + public Long getActivityId() { + return activityId; + } + /** + * @param activityId The activityId to set. + */ + public void setActivityId(Long activityId) { + this.activityId = activityId; + } + + /** + * @return Returns the activityDescription. + */ + public String getActivityDescription() { + return activityDescription; + } + /** + * @param activityDescription The activityDescription to set. + */ + public void setActivityDescription(String activityDescription) { + this.activityDescription = activityDescription; + } + /** Get the portfolios for any sub activities. Will return null for tool portfolios */ + public List getChildPortfolios() { + return childPortfolios; + } + public void setChildPortfolios(List childPortfolios) { + this.childPortfolios = childPortfolios; + } + + +} Index: lams_learning/src/java/org/lamsfoundation/lams/learning/export/ExportPortfolioConstants.java =================================================================== diff -u -r9f57e7f6691fb7d5a61b0f33bde8d9f1fee24376 -r6f11dd80335ff2b8a2d06d21f1a49b307ed233c1 --- lams_learning/src/java/org/lamsfoundation/lams/learning/export/ExportPortfolioConstants.java (.../ExportPortfolioConstants.java) (revision 9f57e7f6691fb7d5a61b0f33bde8d9f1fee24376) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/export/ExportPortfolioConstants.java (.../ExportPortfolioConstants.java) (revision 6f11dd80335ff2b8a2d06d21f1a49b307ed233c1) @@ -44,19 +44,10 @@ public static final String HOST = getServerURL(); public static final String SUBDIRECTORY_BASENAME = "Activity"; //subdirectory for each activity is ActivityXX where XX is the activity Id public static final String PARAM_FILE_LOCATION = "fileLocation"; - public static final String TEMP_DIRECTORY = FileUtil.TEMP_DIR; - public static final String URL_FOR_UNSUPPORTED_EXPORT = "learning/exportNotSupported"; + public static final String URL_FOR_UNSUPPORTED_EXPORT = "learning/exportPortfolio/notSupported.jsp"; public static final String EXPORT_ERROR_FILENAME = "export_error.html"; - - public static final String EXPORT_CSS_STYLESHEET = "default.css"; - public static final String LAMS_CSS_STYLESHEET = "/lams/css/default.css"; - - //Struts Message Resource - public static final String MESSAGE_RESOURCE_CONFIG_PARAM = "org.lamsfoundation.lams.learning.ApplicationResources"; - public static final String EXPORT_FAILED_KEY="export.html.exportFailed"; - public static final String EXPORT_MAINPAGE_KEY = "export.html.mainPage"; - public static final String EXPORT_NOT_SUPPORTED_KEY = "export.html.exportNotSupported"; - + public static final String EXPORT_ACTIVITY_ERROR_KEY = "error.export.portfolio.not.supported"; + private static String getServerURL() { return Configuration.get(ConfigurationKeys.SERVER_URL); Index: lams_learning/src/java/org/lamsfoundation/lams/learning/export/Portfolio.java =================================================================== diff -u -rcdb910b6cd3de106725e2c22ded380c5c0fab650 -r6f11dd80335ff2b8a2d06d21f1a49b307ed233c1 --- lams_learning/src/java/org/lamsfoundation/lams/learning/export/Portfolio.java (.../Portfolio.java) (revision cdb910b6cd3de106725e2c22ded380c5c0fab650) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/export/Portfolio.java (.../Portfolio.java) (revision 6f11dd80335ff2b8a2d06d21f1a49b307ed233c1) @@ -27,19 +27,20 @@ /** * @author mtruong - * - * TODO To change the template for this generated type comment go to - * Window - Preferences - Java - Code Style - Code Templates - */ + */ public class Portfolio { + private String exportID; private String exportTmpDir; - private ToolPortfolio[] toolPortfolios; + private String lessonName; + private String lessonDescription; + private ActivityPortfolio[] activityPortfolios; - public Portfolio() + public Portfolio(String exportID) { this.exportTmpDir = null; - this.toolPortfolios = null; + this.activityPortfolios = null; + this.exportID = exportID; } /** @@ -57,13 +58,38 @@ /** * @return Returns the toolPortfolios. */ - public ToolPortfolio[] getToolPortfolios() { - return toolPortfolios; + public ActivityPortfolio[] getActivityPortfolios() { + return activityPortfolios; } /** * @param toolPortfolios The toolPortfolios to set. */ - public void setToolPortfolios(ToolPortfolio[] toolPortfolios) { - this.toolPortfolios = toolPortfolios; + public void setActivityPortfolios(ActivityPortfolio[] activityPortfolios) { + this.activityPortfolios = activityPortfolios; } + + public String getLessonName() { + return lessonName; + } + + public void setLessonName(String lessonName) { + this.lessonName = lessonName; + } + + public String getLessonDescription() { + return lessonDescription; + } + + public void setLessonDescription(String lessonDescription) { + this.lessonDescription = lessonDescription; + } + + /** Get the internal id generated to keep this unique. Used in the directory name */ + public String getExportID() { + return exportID; + } + + public void setExportID(String exportID) { + this.exportID = exportID; + } } Fisheye: Tag 6f11dd80335ff2b8a2d06d21f1a49b307ed233c1 refers to a dead (removed) revision in file `lams_learning/src/java/org/lamsfoundation/lams/learning/export/ToolPortfolio.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_learning/src/java/org/lamsfoundation/lams/learning/export/service/ExportPortfolioService.java =================================================================== diff -u -r6c93a29e621c20da5662066e4be018eab3f5d17d -r6f11dd80335ff2b8a2d06d21f1a49b307ed233c1 --- lams_learning/src/java/org/lamsfoundation/lams/learning/export/service/ExportPortfolioService.java (.../ExportPortfolioService.java) (revision 6c93a29e621c20da5662066e4be018eab3f5d17d) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/export/service/ExportPortfolioService.java (.../ExportPortfolioService.java) (revision 6f11dd80335ff2b8a2d06d21f1a49b307ed233c1) @@ -30,65 +30,63 @@ import java.io.FileWriter; import java.io.IOException; import java.net.MalformedURLException; -import java.util.HashMap; +import java.util.ArrayList; import java.util.Iterator; -import java.util.Set; -import java.util.TreeSet; import java.util.Vector; import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; import org.apache.log4j.Logger; +import org.lamsfoundation.lams.learning.export.ActivityPortfolio; import org.lamsfoundation.lams.learning.export.ExportPortfolioConstants; import org.lamsfoundation.lams.learning.export.ExportPortfolioException; import org.lamsfoundation.lams.learning.export.Portfolio; -import org.lamsfoundation.lams.learning.export.ToolPortfolio; import org.lamsfoundation.lams.learning.service.ILearnerService; -import org.lamsfoundation.lams.learningdesign.Activity; -import org.lamsfoundation.lams.learningdesign.ActivityOrderComparator; -import org.lamsfoundation.lams.learningdesign.LearningDesign; -import org.lamsfoundation.lams.learningdesign.ToolActivity; import org.lamsfoundation.lams.learningdesign.dao.IActivityDAO; -import org.lamsfoundation.lams.learningdesign.dao.ITransitionDAO; import org.lamsfoundation.lams.lesson.LearnerProgress; import org.lamsfoundation.lams.lesson.Lesson; import org.lamsfoundation.lams.lesson.dao.ILessonDAO; -import org.lamsfoundation.lams.tool.Tool; import org.lamsfoundation.lams.tool.ToolAccessMode; -import org.lamsfoundation.lams.tool.ToolSession; import org.lamsfoundation.lams.tool.exception.LamsToolServiceException; import org.lamsfoundation.lams.tool.service.ILamsCoreToolService; import org.lamsfoundation.lams.usermanagement.User; import org.lamsfoundation.lams.usermanagement.dao.IUserDAO; +import org.lamsfoundation.lams.usermanagement.dto.UserDTO; import org.lamsfoundation.lams.util.FileUtil; import org.lamsfoundation.lams.util.FileUtilException; import org.lamsfoundation.lams.util.HttpUrlConnectionUtil; +import org.lamsfoundation.lams.util.MessageService; import org.lamsfoundation.lams.util.WebUtil; import org.lamsfoundation.lams.util.zipfile.ZipFileUtil; import org.lamsfoundation.lams.util.zipfile.ZipFileUtilException; +import org.lamsfoundation.lams.web.session.SessionManager; import org.lamsfoundation.lams.web.util.AttributeNames; /** - * @author mtruong + * Generates the learner and teacher portfolios. These are designed to be offline versions of a sequence, + * so that learners and teachers can refer to them after the lesson has finished. + * + * In general, anything that the learner sees should be in their portfolio. The teacher version + * should have the details for all students in the lesson. + * + * @author mtruong,fmalikoff * */ public class ExportPortfolioService implements IExportPortfolioService { private static Logger log = Logger.getLogger(ExportPortfolioService.class); - private static final String EXPORT_ERROR_MSG = "This activity does not support portfolio export"; - private ILamsCoreToolService lamsCoreToolService; - private ITransitionDAO transitionDAO; private IActivityDAO activityDAO; private IUserDAO userDAO; private ILearnerService learnerService; private ILessonDAO lessonDAO; - //private Portfolio portfolio = null; - // private String exportTmpDir; + protected MessageService messageService; /** @@ -99,13 +97,6 @@ } /** - * @param transitionDAO The transitionDAO to set. - */ - public void setTransitionDAO(ITransitionDAO transitionDAO) { - this.transitionDAO = transitionDAO; - } - - /** * @param activityDAO The activityDAO to set. */ public void setActivityDAO(IActivityDAO activityDAO) { @@ -133,39 +124,34 @@ this.userDAO = userDAO; } + public void setMessageService(MessageService messageService) { + this.messageService = messageService; + } + /** @see org.lamsfoundation.lams.learning.export.service.IExportPortfolioService#exportPortfolioForTeacher(org.lamsfoundation.lams.lesson.Lesson) */ public Portfolio exportPortfolioForTeacher(Long lessonId, Cookie[] cookies) { Lesson lesson = lessonDAO.getLesson(lessonId); - Vector portfolios = null; //each portfolio contains information about its activity, ordered in the same sequence as the ordered activity list. - //ToolPortfolio[] exports = null; + ArrayList portfolios = null; //each portfolio contains information about its activity, ordered in the same sequence as the ordered activity list. Portfolio exports = null; - /* if (lesson==null) - { - String error="The Lesson with lessonID " + lessonId + "is null."; - log.error(error); - throw new ExportPortfolioException(error); - } */ if (lesson != null) { - Vector activities = getOrderedActivityList(lesson.getLearningDesign()); - if (activities != null) - { - try - { - portfolios = setupPortfolios(activities, ToolAccessMode.TEACHER, null); - - exports = doExport(portfolios, cookies); - - } - catch (LamsToolServiceException e) - { - /** TODO avoid throwing exceptions if possible */ - throw new ExportPortfolioException("An exception has occurred while generating portfolios. The error is: " + e); - } + try + { + PortfolioBuilder builder = new PortfolioBuilder(lesson.getLearningDesign(), activityDAO, lamsCoreToolService, ToolAccessMode.TEACHER, null, null); + builder.parseLearningDesign(); + portfolios = builder.getPortfolioList(); + + exports = doExport(portfolios, cookies,lesson); + } + catch (LamsToolServiceException e) + { + /** TODO avoid throwing exceptions if possible */ + throw new ExportPortfolioException("An exception has occurred while generating portfolios. The error is: " + e); + } } else { @@ -177,7 +163,7 @@ * createDirectory() method, so that the main file can be generated in * that directory. */ - exports = createPortfolioIndicatingErrorHasOccurred(); + exports = createPortfolioIndicatingErrorHasOccurred(lesson); } return exports; @@ -189,10 +175,8 @@ /** @see org.lamsfoundation.lams.learning.export.service.IExportPortfolioService#exportPortfolioForStudent(java.lang.Long, org.lamsfoundation.lams.usermanagement.User,boolean) */ public Portfolio exportPortfolioForStudent(Integer userId, Long lessonID, boolean anonymity, Cookie[] cookies) { - Vector portfolios = null; - //ToolPortfolio[] exports = null; + ArrayList portfolios = null; Portfolio exports = null; - String error; User learner = userDAO.getUserById(userId); Lesson lesson = lessonDAO.getLesson(lessonID); @@ -203,229 +187,58 @@ if (learnerProgress != null) { - // Vector activities = getOrderedActivityList(learnerProgress.getLearnerProgressId()); - Vector activities = getOrderedActivityList(learnerProgress); - if (activities != null) - { - try - { - portfolios = setupPortfolios(activities, ToolAccessMode.LEARNER, learner); - exports = doExport(portfolios, cookies); - } - catch (LamsToolServiceException e) - { - - error = "An exception has occurred while generating portfolios. The error is: " + e; - log.error(error); - exports = createPortfolioIndicatingErrorHasOccurred(); - //throw new ExportPortfolioException("An exception has occurred while generating portfolios. The error is: " + e); - } + + try + { + PortfolioBuilder builder = new PortfolioBuilder(lesson.getLearningDesign(), activityDAO, lamsCoreToolService, ToolAccessMode.LEARNER, learnerProgress, learner); + builder.parseLearningDesign(); + portfolios = builder.getPortfolioList(); + + if ( portfolios.size() >= 0 ) { + exports = doExport(portfolios, cookies,lesson); + + } else { + log.error("The learner has not completed or attempted any activities"); + } + + } + catch (LamsToolServiceException e) + { + log.error("An exception has occurred while generating portfolios.",e); } - else - { - error = "The learner has not completed any activities"; - log.error(error); - exports = createPortfolioIndicatingErrorHasOccurred();//create dummy portfolio, which just contains the exportTmpDir and one dummy tool portfolio - } } else { - error = "The LearnerProgress cannot be found for userId " + userId + " participating in lessonId " + lessonID; - log.error(error); - exports = createPortfolioIndicatingErrorHasOccurred();//create dummy portfolio, which just contains the exportTmpDir and one dummy tool portfolio + log.error("The LearnerProgress cannot be found for userId " + userId + " participating in lessonId " + lessonID); } } else { - error="The User object with userId" + userId + "or Lesson object with lessonId" + lessonID + " is null. Cannot Continue"; - log.error(error); - exports = createPortfolioIndicatingErrorHasOccurred(); + log.error("The User object with userId" + userId + "or Lesson object with lessonId" + lessonID + " is null. Cannot Continue"); } + + if ( exports == null ) { + exports = createPortfolioIndicatingErrorHasOccurred(lesson); + } + return exports; } - - - /** @see org.lamsfoundation.lams.learning.export.service.IExportPortfolioService#getOrderedActivityList(org.lamsfoundation.lams.learningdesign.LearningDesign) */ - public Vector getOrderedActivityList(LearningDesign learningDesign) - { - if (learningDesign == null) - { - String error="the learningdesign is null. Cannot continue"; - log.error(error); - /** TODO avoid throwing exceptions if possible */ - throw new ExportPortfolioException(error); - } - HashMap activityTree = learningDesign.getActivityTree(); - Vector v = new Vector(); - Activity nextActivity = learningDesign.getFirstActivity(); - - while(nextActivity!=null){ - addActivityToVector(activityTree, v, nextActivity); - nextActivity = transitionDAO.getNextActivity(nextActivity.getActivityId()); - } - return v; - } - - - /** - * Used by getOrderedActivityList(LearningDesign) - * - * @param activityTree - * @param v - * @param nextActivity - */ - private void addActivityToVector(HashMap activityTree, Vector v, Activity activity) { - Set childActivities = (Set) activityTree.get(activity.getActivityId()); - if(childActivities.size()!=0){ - // must have been a complex activity - v.addAll(childActivities); - }else{ - // must be a simple activity - v.add(activity); - } - } - - /** - * This method will iterate through the list of ordered activities and create a Portfolio - * object for each activity. It will set up most of the properies of the Portfolio object. - * This method is used regardless of whether the export is being done by the teacher or - * the student. However, if the export is being done be the teacher, the User object should - * be null. - * - * If the list of ordered activities is null, then a Portfolio object will be created - * with the attribute exportTmpDir set and the array of ToolPortfolios being null. - * - * @param orderedActivityList The ordered activity list to iterate through - * @param accessMode The tool access mode, either Teacher or Learner. - * @param user The learner, or null if export is being done by the teacher. - * @return the array of Portfolio objects - * @throws LamsToolServiceException - */ - protected Vector setupPortfolios(Vector sortedActivityList, ToolAccessMode accessMode, User user) throws LamsToolServiceException - { - /* these checks are not really needed, the calling code ensures that the right parameters are supplied */ - /* if (sortedActivityList == null) - { - String error="The ordered activity list is null. Cannot continue"; - log.error(error); - - throw new ExportPortfolioException(error); - } - if (accessMode != ToolAccessMode.TEACHER && user == null ) - { - String error="Invalid User. User object is null. Cannot continue"; - log.error(error); - throw new ExportPortfolioException(error); - } - */ - - Iterator i = sortedActivityList.iterator(); - Vector portfolioList = new Vector(); - - while(i.hasNext()) - { - Activity activity = (Activity)i.next(); - - if (activity.isToolActivity()) - { - ToolActivity toolActivity = (ToolActivity)activityDAO.getActivityByActivityId(activity.getActivityId()); - ToolPortfolio portfolio = createToolPortfolio(toolActivity,accessMode); - String url = portfolio.getExportUrl(); - - /* - * Append parameters to the export url. - * If the export is done by teacher: mode, toolContentId is appended - * If the export is done by learner: mode, userId, toolSessionId is appended - */ - if (accessMode == ToolAccessMode.LEARNER) - { - url = WebUtil.appendParameterToURL(url, AttributeNames.PARAM_USER_ID, user.getUserId().toString()); - ToolSession toolSession = lamsCoreToolService.getToolSessionByActivity(user, toolActivity); - if (toolSession != null) { - url = WebUtil.appendParameterToURL(url, AttributeNames.PARAM_TOOL_SESSION_ID, toolSession.getToolSessionId().toString()); - } - } - else if (accessMode == ToolAccessMode.TEACHER) - { - url = WebUtil.appendParameterToURL(url, AttributeNames.PARAM_TOOL_CONTENT_ID, toolActivity.getToolContentId().toString()); - } + private Portfolio createPortfolioIndicatingErrorHasOccurred(Lesson lesson) + { + String tempDir = createDirectory(ExportPortfolioConstants.DIR_SUFFIX_EXPORT); + File dir = new File(tempDir); + String exportID = dir.getName(); - portfolio.setExportUrl(url); - portfolioList.add(portfolio); //add the portfolio at the end of the list. - } - } - - return portfolioList; - } - - /** - * Obtains the Tool from the ToolActivity and creates a portfolio object with properties activityId, activityName, - * activityDescription, exportURL set to the value of the ToolActivity's properties activityId, toolDisplayName - * (retrieved from Tool object), title, exportPortfolioUrl respestively. - * - * @param activity The Tool Activity - * @return a Portfolio object - */ - protected ToolPortfolio createToolPortfolio(ToolActivity activity, ToolAccessMode accessMode) - { - if (activity == null) - { - String error="Cannot create portfolio for this tool activity. Tool Activity is null"; - log.error(error); - throw new ExportPortfolioException(error); - } - ToolPortfolio p = new ToolPortfolio(); - Tool tool = activity.getTool(); - p.setActivityId(activity.getActivityId()); - p.setActivityName(activity.getTitle()); - p.setActivityDescription(activity.getDescription()); - - /* if the tool does not have an export url, use the url that points to the servlet that generates a page saying that the export is not supported */ - String exportUrlForTool = null; - if (accessMode == ToolAccessMode.LEARNER) - exportUrlForTool = tool.getExportPortfolioLearnerUrl(); - else - exportUrlForTool = tool.getExportPortfolioClassUrl(); - - if (exportUrlForTool == null || exportUrlForTool.equals("")) - p.setExportUrl(ExportPortfolioConstants.URL_FOR_UNSUPPORTED_EXPORT); - else - p.setExportUrl(exportUrlForTool); - - return p; - } - - /** @see org.lamsfoundation.lams.learning.export.service.IExportPortfolioService#getOrderedActivityList(org.lamsfoundation.lams.lesson.LearnerProgress) */ - public Vector getOrderedActivityList(LearnerProgress learnerProgress) - { - Set activitySet = learnerProgress.getCompletedActivities(); - - Vector activityList = null; - if (activitySet.size() != 0) - { - TreeSet sortedActivities = new TreeSet(new ActivityOrderComparator()); - sortedActivities.addAll(activitySet); - - activityList = new Vector(); - - Iterator i = sortedActivities.iterator(); - - while (i.hasNext()) - { - Activity activity = (Activity)i.next(); - if (!activity.isComplexActivity()) - { - activityList.add(activity); - } - } - } - return activityList; - } - - + Portfolio dummyPortfolio = new Portfolio(exportID); + dummyPortfolio.setExportTmpDir(tempDir); + dummyPortfolio.setLessonDescription(lesson.getLessonDescription()); + dummyPortfolio.setLessonName(lesson.getLessonName()); + return dummyPortfolio; + } + /** @see org.lamsfoundation.lams.learning.export.service.IExportPortfolioService#zipPortfolio(String, String) */ public String zipPortfolio(String filename, String directoryToZip) { @@ -449,28 +262,32 @@ } /** @see org.lamsfoundation.lams.learning.export.service.IExportPortfolioService#doExport(Vector, Cookie[]) */ - public Portfolio doExport(Vector portfolios, Cookie[] cookies) + public Portfolio doExport(ArrayList portfolios, Cookie[] cookies, Lesson lesson) { String activitySubDirectory; String exportURL; String toolLink; String mainFileName = null; String tempDirectoryName; - Portfolio portfolio = new Portfolio(); - Iterator i = portfolios.iterator(); //create the root directory for the export tempDirectoryName = createDirectory(ExportPortfolioConstants.DIR_SUFFIX_EXPORT); + File dir = new File(tempDirectoryName); + String exportID = dir.getName(); - //setExportTmpDir(tempDirectoryName); + Portfolio portfolio = new Portfolio(exportID); portfolio.setExportTmpDir(tempDirectoryName); + portfolio.setLessonName(lesson.getLessonName()); + portfolio.setLessonDescription(lesson.getLessonDescription()); + + Iterator i = portfolios.iterator(); //iterate through the list of portfolios, create subdirectory, while(i.hasNext()) { - ToolPortfolio toolPortfolio = (ToolPortfolio)i.next(); + ActivityPortfolio activityPortfolio = (ActivityPortfolio)i.next(); //create a subdirectory with the name ActivityXX where XX is the activityId - String subDirectoryName = ExportPortfolioConstants.SUBDIRECTORY_BASENAME + toolPortfolio.getActivityId().toString(); + String subDirectoryName = ExportPortfolioConstants.SUBDIRECTORY_BASENAME + activityPortfolio.getActivityId().toString(); if(!createSubDirectory(tempDirectoryName, subDirectoryName)) { throw new ExportPortfolioException("The subdirectory " + subDirectoryName + " could not be created."); @@ -480,30 +297,24 @@ activitySubDirectory = tempDirectoryName + File.separator + subDirectoryName; //for security reasons, append the relative directory name to the end of the export url instead of the whole path - String relativePath = activitySubDirectory.substring(ExportPortfolioConstants.TEMP_DIRECTORY.length()+1, activitySubDirectory.length()); - exportURL = WebUtil.appendParameterToURL(toolPortfolio.getExportUrl(), AttributeNames.PARAM_DIRECTORY_NAME, relativePath); + String relativePath = activitySubDirectory.substring(FileUtil.TEMP_DIR.length()+1, activitySubDirectory.length()); + exportURL = WebUtil.appendParameterToURL(activityPortfolio.getExportUrl(), AttributeNames.PARAM_DIRECTORY_NAME, relativePath); String absoluteExportURL = ExportPortfolioConstants.HOST + exportURL; - toolPortfolio.setExportUrl(absoluteExportURL); + activityPortfolio.setExportUrl(absoluteExportURL); //get tool to export its files, mainFileName is the name of the main HTML page that the tool exported. mainFileName = connectToToolViaExportURL(absoluteExportURL, cookies, activitySubDirectory); - - /* if (mainFileName == null) - { - log.error("The main export file returned by the tool activity was null. Tool activity id " + toolPortfolio.getActivityId()); - throw new ExportPortfolioException("The main file name the tool returned is null.Cannot continue with export."); - } */ - + //toolLink is used in main page, so that it can link with the tools export pages. toolLink = subDirectoryName + "/" + mainFileName; - toolPortfolio.setToolLink(toolLink); + activityPortfolio.setToolLink(toolLink); } - portfolio.setToolPortfolios((ToolPortfolio[])portfolios.toArray(new ToolPortfolio[portfolios.size()])); + portfolio.setActivityPortfolios((ActivityPortfolio[])portfolios.toArray(new ActivityPortfolio[portfolios.size()])); return portfolio; @@ -561,188 +372,82 @@ public String connectToToolViaExportURL(String exportURL, Cookie[] cookies, String directoryToStoreErrorFile) { String filename = null; - String errorMsg; try { filename = HttpUrlConnectionUtil.connectToToolExportURL(exportURL, cookies); if (filename == null) { filename = ExportPortfolioConstants.EXPORT_ERROR_FILENAME; - errorMsg = "A problem has occurred while connecting to the tool's export url. The export url may be invalid or may not exist"; - writeErrorMessageToFile(EXPORT_ERROR_MSG, directoryToStoreErrorFile, ExportPortfolioConstants.EXPORT_ERROR_FILENAME); + log.error("A problem has occurred while connecting to the tool's export url. The export url may be invalid or may not exist"); + writeErrorMessageToFile(directoryToStoreErrorFile); } } catch(MalformedURLException e) { - //throw new ExportPortfolioException("The URL given is invalid. ",e); - // filename = ExportPortfolioConstants.EXPORT_ERROR_FILENAME; - log.error("The URL given is invalid. Exception Message was: " +e); - writeErrorMessageToFile(EXPORT_ERROR_MSG, directoryToStoreErrorFile, filename); + log.error("The URL "+exportURL+" given is invalid.",e); + writeErrorMessageToFile(directoryToStoreErrorFile); } catch(FileNotFoundException e) { - //throw new ExportPortfolioException("The directory or file may not exist. ",e); - // filename = ExportPortfolioConstants.EXPORT_ERROR_FILENAME; - log.error("The directory or file may not exist. Exception Message was: " +e); - writeErrorMessageToFile(EXPORT_ERROR_MSG, directoryToStoreErrorFile, filename); + log.error("The directory "+directoryToStoreErrorFile+" may not exist.",e); + writeErrorMessageToFile(directoryToStoreErrorFile); } catch(IOException e) { - //throw new ExportPortfolioException("A problem has occurred while writing the contents of " + exportURL + " to file. ", e); - // filename = ExportPortfolioConstants.EXPORT_ERROR_FILENAME; - log.error("A problem has occurred while writing the contents of " + exportURL + " to file. Exception Message was: " +e); - writeErrorMessageToFile(EXPORT_ERROR_MSG, directoryToStoreErrorFile, filename); + log.error("A problem has occurred while writing the contents of " + exportURL + " to file.", e); + writeErrorMessageToFile(directoryToStoreErrorFile); } return filename; } - private void writeErrorMessageToFile(String errorMessage, String directoryToStoreFile, String filename) + /** Generate the main page, given this portfolio */ + public void generateMainPage(HttpServletRequest request, Portfolio portfolio, Cookie[] cookies) { + + String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath(); + String url = basePath + "/exportPortfolio/main.jsp"; + + String filename = ExportPortfolioConstants.MAIN_EXPORT_FILENAME; + try + { + request.getSession().setAttribute("portfolio", portfolio); + HttpUrlConnectionUtil.writeResponseToFile(url, portfolio.getExportTmpDir(), filename, cookies); + request.getSession().removeAttribute("portfolio"); + } + catch(MalformedURLException e) + { + log.error("The URL given is invalid. Exception Message was: " +e); + writeErrorMessageToFile(portfolio.getExportTmpDir()); + } + catch(FileNotFoundException e) + { + log.error("The directory or file may not exist. Exception Message was: " +e); + writeErrorMessageToFile(portfolio.getExportTmpDir()); + } + catch(IOException e) + { + log.error("A problem has occurred while writing the contents of " + url + " to file. Exception Message was: " +e); + writeErrorMessageToFile(portfolio.getExportTmpDir()); + + } + } + + private void writeErrorMessageToFile(String directoryToStoreFile) { try - { - String filepath = directoryToStoreFile + File.separator + filename; + { + String errorMessage = messageService.getMessage(ExportPortfolioConstants.EXPORT_ACTIVITY_ERROR_KEY); + String filepath = directoryToStoreFile + File.separator + ExportPortfolioConstants.EXPORT_ERROR_FILENAME; BufferedWriter fileout = new BufferedWriter(new FileWriter(filepath)); fileout.write(errorMessage); fileout.close(); } catch(IOException e) { - /** TODO avoid throwing exceptions if possible */ - // throw new ExportPortfolioServletException("Could not write error message to a file"); + log.error("Exception occured trying to write out error message to file.",e); } } - private Portfolio createPortfolioIndicatingErrorHasOccurred() - { - String tempDir = createDirectory(ExportPortfolioConstants.DIR_SUFFIX_EXPORT); - Portfolio dummyPortfolio = new Portfolio(); - dummyPortfolio.setExportTmpDir(tempDir); - return dummyPortfolio; - } - - //Methods that are not used - - /* public Vector getOrderedActivityList(LearnerProgress learnerProgress) - { - if (learnerProgress == null) - { - String error="the learnerProgress is null"; - throw new ExportPortfolioException(error); - } - Set activitySet = learnerProgress.getCompletedActivities(); - // if (activitySet.size() == 0) - //{ - //String error="Cannot export your portfolio. You have not completed any activities yet."; - //throw new ExportPortfolioException(error); - // } - TreeSet sortedActivities = new TreeSet(new ActivityOrderComparator()); - sortedActivities.addAll(activitySet); - - Vector v = new Vector(); - //sort the activities according to order_id or if not activityId - - - Iterator i = sortedActivities.iterator(); - - while (i.hasNext()) - { - Activity activity = (Activity)i.next(); - if (!activity.isComplexActivity()) - { - v.add(activity); - } - } - - return v; - } - */ - - /* - public Portfolio[] exportPortfolioForStudent(LearnerProgress learnerProgress, User user, boolean anonymity) - { - if (learnerProgress == null || user == null) - { - String error="learnerProgress or user is null"; - throw new ExportPortfolioException(error); - } - //LearnerProgress progress = learnerService.getProgress(learner, lesson); - Portfolio[] portfolios = null; - Vector activities = getOrderedActivityList(learnerProgress); - - try - { - portfolios = setupPortfolios(activities, ToolAccessMode.LEARNER, user); - - } - catch (LamsToolServiceException e) - { - //throw new ExportPortfolioException(e); - } - return portfolios; - - } - - public Portfolio[] exportPortfolioForStudent(Lesson lesson, User user, boolean anonymity) - { - if (lesson == null || user == null) - { - String error="learnerProgress or user is null"; - throw new ExportPortfolioException(error); - } - LearnerProgress learnerProgress = learnerService.getProgress(user, lesson); - - Portfolio[] portfolios = null; - Vector activities = getOrderedActivityList(learnerProgress); - - try - { - portfolios = setupPortfolios(activities, ToolAccessMode.LEARNER, user); - } - catch (LamsToolServiceException e) - { - //throw new ExportPortfolioException(e); - } - return portfolios; - - - } */ - - /*public String getExportDir() - { - return getExportTmpDir(); - } */ - - - /*public Vector getOrderedActivityList(Long learnerProgressId) - { - - Vector activityList = null; - LearnerProgress learnerProgress = learnerService.getProgressById(learnerProgressId); - Set activitySet = learnerProgress.getCompletedActivities(); - if (activitySet.size() != 0) - { - TreeSet sortedActivities = new TreeSet(new ActivityOrderComparator()); - sortedActivities.addAll(activitySet); - - activityList = new Vector(); - - Iterator i = sortedActivities.iterator(); - - while (i.hasNext()) - { - Activity activity = (Activity)i.next(); - if (!activity.isComplexActivity()) - { - activityList.add(activity); - } - } - } - return activityList; - - - } */ - } Index: lams_learning/src/java/org/lamsfoundation/lams/learning/export/service/IExportPortfolioService.java =================================================================== diff -u -rcdb910b6cd3de106725e2c22ded380c5c0fab650 -r6f11dd80335ff2b8a2d06d21f1a49b307ed233c1 --- lams_learning/src/java/org/lamsfoundation/lams/learning/export/service/IExportPortfolioService.java (.../IExportPortfolioService.java) (revision cdb910b6cd3de106725e2c22ded380c5c0fab650) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/export/service/IExportPortfolioService.java (.../IExportPortfolioService.java) (revision 6f11dd80335ff2b8a2d06d21f1a49b307ed233c1) @@ -24,19 +24,10 @@ /* $$Id$$ */ package org.lamsfoundation.lams.learning.export.service; -import java.util.Map; -import java.util.Vector; import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; -import org.lamsfoundation.lams.learning.export.ToolPortfolio; import org.lamsfoundation.lams.learning.export.Portfolio; -import org.lamsfoundation.lams.learningdesign.LearningDesign; -import org.lamsfoundation.lams.learningdesign.ToolActivity; -import org.lamsfoundation.lams.lesson.Lesson; -import org.lamsfoundation.lams.lesson.LearnerProgress; -import org.lamsfoundation.lams.tool.ToolAccessMode; -import org.lamsfoundation.lams.tool.exception.LamsToolServiceException; -import org.lamsfoundation.lams.usermanagement.User; /** * @author mtruong * @@ -101,30 +92,6 @@ public Portfolio exportPortfolioForStudent(Integer userId, Long lessonID, boolean anonymity, Cookie[] cookies); /** - * Returns the ordered activity list (ordered by the ActivityOrderComparator) - * containing all activities present in the learning design. The list will - * only contain Tool Activities. If it comes across a Complex Activity, it - * will only add its child activities in the ordered list. - * @param learningDesign The learning design in which the export is being done. - * @return Vector the ordered list of activities. - */ - public Vector getOrderedActivityList(LearningDesign learningDesign); - - - /** - * Returns the ordered activity list (ordered by the ActivityOrderComparator) - * containing the list of activities completed by the learner. The list will - * only contain Tool Activities. If it comes across a Complex Activity, it - * will only add its child activities in the ordered list. - * - * If the learner has not yet completed any activities, then it will return null. - * - * @param learnerProgressId - * @return - */ - public Vector getOrderedActivityList(LearnerProgress learnerProgress); - - /** * Zips up the directory specified by directoryToZip and * saves it in the filename given by filename. * @@ -134,34 +101,8 @@ */ public String zipPortfolio(String filename, String directoryToZip); - /** - * Creates the temporary root directory for the export and then - * iterates through the list of portfolios, creates a subdirectory for each of the tools - * and appends the temporary export directory to the export url. It will then call each - * tool to write its files in the subdirectory. - * The tool returns the name of the main html file written, the portfolio property - * mainFileName is set to this value. - * @param portfolios The portfolios to iterate through. - * @param cookies The cookies that are to be passed along - * @return An array of portfolios that can be used to generate the main export page. - */ - public Portfolio doExport(Vector portfolios, Cookie[] cookies); - /** - * This method is responsible for the call to the tool to export their portfolio via the export url. - * It uses a HttpURLConnection to connect to the export url of each tool and returns the filename - * of the main export page of the tool. - * - * @param tool The portfolio object, which contains the exportUrl in which to connect to. - * @return The main file name of the tool's page. - */ - public String connectToToolViaExportURL(String exportURL, Cookie[] cookies, String directoryToStoreErrorFile); + /** Generate the main page, given this portfolio */ + public void generateMainPage(HttpServletRequest request, Portfolio portfolio, Cookie[] cookies); + -// public String getExportDir(); - - /* public Portfolio[] exportPortfolioForStudent(LearnerProgress learnerProgress, User user, boolean anonymity); - - public Portfolio[] exportPortfolioForStudent(Lesson lesson, User user, boolean anonymity); - - public Vector getOrderedActivityList(Long learnerProgressId); */ - } Index: lams_learning/src/java/org/lamsfoundation/lams/learning/export/service/PortfolioBuilder.java =================================================================== diff -u --- lams_learning/src/java/org/lamsfoundation/lams/learning/export/service/PortfolioBuilder.java (revision 0) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/export/service/PortfolioBuilder.java (revision 6f11dd80335ff2b8a2d06d21f1a49b307ed233c1) @@ -0,0 +1,206 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ +/* $Id$ */ + +package org.lamsfoundation.lams.learning.export.service; + +import java.util.ArrayList; + +import org.apache.commons.collections.ArrayStack; +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.learning.export.ActivityPortfolio; +import org.lamsfoundation.lams.learning.export.ExportPortfolioConstants; +import org.lamsfoundation.lams.learning.export.ExportPortfolioException; +import org.lamsfoundation.lams.learningdesign.Activity; +import org.lamsfoundation.lams.learningdesign.ComplexActivity; +import org.lamsfoundation.lams.learningdesign.LearningDesign; +import org.lamsfoundation.lams.learningdesign.LearningDesignProcessor; +import org.lamsfoundation.lams.learningdesign.SimpleActivity; +import org.lamsfoundation.lams.learningdesign.ToolActivity; +import org.lamsfoundation.lams.learningdesign.dao.IActivityDAO; +import org.lamsfoundation.lams.learningdesign.exception.LearningDesignProcessorException; +import org.lamsfoundation.lams.lesson.LearnerProgress; +import org.lamsfoundation.lams.tool.Tool; +import org.lamsfoundation.lams.tool.ToolAccessMode; +import org.lamsfoundation.lams.tool.ToolSession; +import org.lamsfoundation.lams.tool.service.ILamsCoreToolService; +import org.lamsfoundation.lams.usermanagement.User; +import org.lamsfoundation.lams.util.WebUtil; +import org.lamsfoundation.lams.web.util.AttributeNames; + +public class PortfolioBuilder extends LearningDesignProcessor { + + private static Logger log = Logger.getLogger(PortfolioBuilder.class); + + ArrayList mainPortfolioList; + ArrayStack activityListStack; + ArrayList currentPortfolioList; + ToolAccessMode accessMode; + ILamsCoreToolService lamsCoreToolService; + User user; + LearnerProgress progress; + + /** Create the builder. Supply all the data that will be needed to parse the design and build the portfolio entries. + * + * If accessMode == LEARNER then progress and user must not be null. This will create a list of portfolio objects for + * all activities that the LEARNER has completed or attempted. + * + * If accessMode == TEACHER then progress and user will be ignored and all activities will be included. + * + * @param design + * @param activityDAO + * @param lamsCoreToolService + * @param accessMode + * @param progress + * @param user + */ + public PortfolioBuilder(LearningDesign design, IActivityDAO activityDAO, + ILamsCoreToolService lamsCoreToolService, ToolAccessMode accessMode, + LearnerProgress progress, User user) { + super(design, activityDAO); + this.mainPortfolioList = new ArrayList(); + this.currentPortfolioList = mainPortfolioList; + this.activityListStack = new ArrayStack(5); + this.accessMode = accessMode; + this.lamsCoreToolService = lamsCoreToolService; + this.user = user; + + this.progress = progress; + } + + /** Prepares to process children */ + public void startComplexActivity(ComplexActivity activity) throws LearningDesignProcessorException { + // Create a new current activity list, putting the old current one on the stack. + activityListStack.push(currentPortfolioList); + currentPortfolioList = new ArrayList(); + + } + + /** Creates an ActivityPortfolio and sets up the list of its children. Doesn't create an entry if there are no children. */ + public void endComplexActivity(ComplexActivity activity) throws LearningDesignProcessorException { + ActivityPortfolio complexPortfolio = null; + + if ( currentPortfolioList.size()>0 ) { + complexPortfolio = createActivityPortfolio(activity); + complexPortfolio.setChildPortfolios(currentPortfolioList); + } + + currentPortfolioList = (ArrayList) activityListStack.pop(); + if ( complexPortfolio != null ) + currentPortfolioList.add(complexPortfolio); + } + + public void startSimpleActivity(SimpleActivity activity) throws LearningDesignProcessorException { + // everything done by endSimpleActivity + } + + /** Creates an ActivityPortfolio. */ + public void endSimpleActivity(SimpleActivity activity) throws LearningDesignProcessorException { + + // if learner only include the attempted and completed activities + // if learner don't include gates + if (accessMode == ToolAccessMode.LEARNER) { + if ( activity.isGateActivity() || + ! ( progress.getCompletedActivities().contains(activity) || progress.getAttemptedActivities().contains(activity)) ) { + return; + } + } + + ActivityPortfolio p = createActivityPortfolio(activity); + String exportUrlForTool = null; + + if ( activity.isToolActivity() ) { + + /* if the tool does not have an export url, use the url that points to the servlet that generates a page saying that the export is not supported */ + ToolActivity toolActivity = (ToolActivity) activity; + Tool tool = toolActivity.getTool(); + if (accessMode == ToolAccessMode.LEARNER) + exportUrlForTool = tool.getExportPortfolioLearnerUrl(); + else + exportUrlForTool = tool.getExportPortfolioClassUrl(); + + /* + * Append parameters to the export url. + * If the export is done by teacher: mode, toolContentId is appended + * If the export is done by learner: mode, userId, toolSessionId is appended + */ + if (accessMode == ToolAccessMode.LEARNER) + { + exportUrlForTool = WebUtil.appendParameterToURL(exportUrlForTool, AttributeNames.PARAM_USER_ID, user.getUserId().toString()); + ToolSession toolSession = lamsCoreToolService.getToolSessionByActivity(user, toolActivity); + if (toolSession != null) { + exportUrlForTool = WebUtil.appendParameterToURL(exportUrlForTool, AttributeNames.PARAM_TOOL_SESSION_ID, toolSession.getToolSessionId().toString()); + } + } + else if (accessMode == ToolAccessMode.TEACHER) + { + exportUrlForTool = WebUtil.appendParameterToURL(exportUrlForTool, AttributeNames.PARAM_TOOL_CONTENT_ID, toolActivity.getToolContentId().toString()); + } + + } else if ( activity.isGateActivity() ) { + // only include the gates in the teacher version + + } else if ( activity.isGroupingActivity() ) { + + } + + if ( exportUrlForTool == null ) { + exportUrlForTool = ExportPortfolioConstants.URL_FOR_UNSUPPORTED_EXPORT; + exportUrlForTool = WebUtil.appendParameterToURL(exportUrlForTool, "activityTitle", activity.getTitle()); + exportUrlForTool = WebUtil.appendParameterToURL(exportUrlForTool, "lessonName", progress.getLesson().getLessonName()); + } + p.setExportUrl(exportUrlForTool); + + currentPortfolioList.add(p); + + } + + /** + * Obtains the Tool from the ToolActivity and creates a portfolio object with properties activityId, activityName, + * activityDescription, exportURL set to the value of the ToolActivity's properties activityId, toolDisplayName + * (retrieved from Tool object), title, exportPortfolioUrl respestively. + * + * @param activity The Tool Activity + * @return a Portfolio object + */ + protected ActivityPortfolio createActivityPortfolio(Activity activity) + { + if (activity == null) + { + String error="Cannot create portfolio for this activity as the activity is null."; + log.error(error); + throw new ExportPortfolioException(error); + } + ActivityPortfolio p = new ActivityPortfolio(); + p.setActivityId(activity.getActivityId()); + p.setActivityName(activity.getTitle()); + p.setActivityDescription(activity.getDescription()); + return p; + } + + /** Get the list of all the activity portfolios, which in turn may contain other activity portfolios */ + public ArrayList getPortfolioList() { + return mainPortfolioList; + } + +} Index: lams_learning/src/java/org/lamsfoundation/lams/learning/export/web/action/ExportDownloadServlet.java =================================================================== diff -u -rcdb910b6cd3de106725e2c22ded380c5c0fab650 -r6f11dd80335ff2b8a2d06d21f1a49b307ed233c1 --- lams_learning/src/java/org/lamsfoundation/lams/learning/export/web/action/ExportDownloadServlet.java (.../ExportDownloadServlet.java) (revision cdb910b6cd3de106725e2c22ded380c5c0fab650) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/export/web/action/ExportDownloadServlet.java (.../ExportDownloadServlet.java) (revision 6f11dd80335ff2b8a2d06d21f1a49b307ed233c1) @@ -39,6 +39,7 @@ import org.apache.log4j.Logger; import org.lamsfoundation.lams.learning.export.ExportPortfolioConstants; +import org.lamsfoundation.lams.util.FileUtil; import org.lamsfoundation.lams.util.WebUtil; /** @@ -97,7 +98,7 @@ private String constructAbsolutePath(String relativePath) { - return ExportPortfolioConstants.TEMP_DIRECTORY + File.separator + relativePath; + return FileUtil.TEMP_DIR + File.separator + relativePath; } } Fisheye: Tag 6f11dd80335ff2b8a2d06d21f1a49b307ed233c1 refers to a dead (removed) revision in file `lams_learning/src/java/org/lamsfoundation/lams/learning/export/web/action/ExportNotSupportedServlet.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_learning/src/java/org/lamsfoundation/lams/learning/export/web/action/MainExportServlet.java =================================================================== diff -u -rcdb910b6cd3de106725e2c22ded380c5c0fab650 -r6f11dd80335ff2b8a2d06d21f1a49b307ed233c1 --- lams_learning/src/java/org/lamsfoundation/lams/learning/export/web/action/MainExportServlet.java (.../MainExportServlet.java) (revision cdb910b6cd3de106725e2c22ded380c5c0fab650) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/export/web/action/MainExportServlet.java (.../MainExportServlet.java) (revision 6f11dd80335ff2b8a2d06d21f1a49b307ed233c1) @@ -24,63 +24,35 @@ /* $$Id$$ */ package org.lamsfoundation.lams.learning.export.web.action; -import org.apache.log4j.Logger; - -import java.io.BufferedInputStream; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileWriter; -import java.io.FileOutputStream; -import java.io.FileNotFoundException; import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; import java.io.PrintWriter; -import java.lang.StringBuffer; -import java.net.MalformedURLException; import java.util.Iterator; import java.util.List; - import javax.servlet.ServletException; import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpSession; +import org.lamsfoundation.lams.learning.export.ExportPortfolioConstants; +import org.lamsfoundation.lams.learning.export.ExportPortfolioException; +import org.lamsfoundation.lams.learning.export.Portfolio; +import org.lamsfoundation.lams.learning.export.service.ExportPortfolioServiceProxy; +import org.lamsfoundation.lams.learning.export.service.IExportPortfolioService; import org.lamsfoundation.lams.tool.ToolAccessMode; -import org.lamsfoundation.lams.usermanagement.User; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; import org.lamsfoundation.lams.util.CSSThemeUtil; -import org.lamsfoundation.lams.util.HttpUrlConnectionUtil; import org.lamsfoundation.lams.util.FileUtil; -import org.lamsfoundation.lams.util.FileUtilException; +import org.lamsfoundation.lams.util.HttpUrlConnectionUtil; import org.lamsfoundation.lams.util.WebUtil; -import org.lamsfoundation.lams.util.zipfile.ZipFileUtil; -import org.lamsfoundation.lams.util.zipfile.ZipFileUtilException; -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; -import org.lamsfoundation.lams.learning.service.ILearnerService; -import org.lamsfoundation.lams.learning.service.LearnerServiceProxy; -import org.lamsfoundation.lams.learning.web.util.LearningWebUtil; -import org.lamsfoundation.lams.lesson.LearnerProgress; -import org.lamsfoundation.lams.lesson.Lesson; -import org.lamsfoundation.lams.themes.CSSThemeVisualElement; import org.lamsfoundation.lams.web.session.SessionManager; import org.lamsfoundation.lams.web.util.AttributeNames; -import org.apache.struts.util.MessageResources; - /** * @author mtruong * @@ -96,12 +68,9 @@ */ public class MainExportServlet extends HttpServlet { - private static Logger log = Logger.getLogger(MainExportServlet.class); + private static final long serialVersionUID = 7788509831929373666L; private String exportTmpDir; - private MessageResources resources = MessageResources.getMessageResources(ExportPortfolioConstants.MESSAGE_RESOURCE_CONFIG_PARAM); - - protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); @@ -110,16 +79,14 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, ExportPortfolioException{ - String htmlOutput=null; Portfolio portfolios = null; Long lessonID = null; - String lessonDescription = 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()); - ILearnerService learnerService = LearnerServiceProxy.getLearnerService(this.getServletContext()); + // ILearnerService learnerService = LearnerServiceProxy.getLearnerService(this.getServletContext()); String mode = WebUtil.readStrParam(request, AttributeNames.PARAM_MODE); @@ -138,24 +105,13 @@ portfolios = exportService.exportPortfolioForTeacher(lessonID, cookies); } - Lesson lesson = learnerService.getLesson(lessonID); - if (lesson != null) - lessonDescription = lesson.getLessonDescription(); - if (portfolios!= null) { exportTmpDir = portfolios.getExportTmpDir(); - String mainFileName = exportTmpDir+ File.separator + ExportPortfolioConstants.MAIN_EXPORT_FILENAME; - - htmlOutput = generateMainPage(portfolios, lessonDescription); + exportService.generateMainPage(request, portfolios, cookies); - //writing the file to the temp export folder. - BufferedWriter fileout = new BufferedWriter(new FileWriter(mainFileName)); - fileout.write(htmlOutput); - fileout.close(); - //bundle the stylesheet with the package bundleStylesheetWithExportPackage(exportTmpDir, request, cookies); @@ -173,47 +129,10 @@ } - /** - * Used StringBuffer for concatenation as it is more efficient than using String - * @param portfolios - * @return - */ - private String generateMainPage(Portfolio portfolio, String lessonDescriptionToDisplay) - { - ToolPortfolio[] portfolios = portfolio.getToolPortfolios(); - String htmlPage; - if (portfolios != null) - { - StringBuffer htmlContent = new StringBuffer(300); - htmlContent.append("
    "); - for (int i=0; i"); - - htmlContent.append(" "); - htmlContent.append(portfolios[i].getActivityName()); - htmlContent.append(": "); - htmlContent.append(portfolios[i].getActivityDescription()); - - htmlContent.append(""); - } - htmlContent.append("
"); - htmlPage = resources.getMessage(ExportPortfolioConstants.EXPORT_MAINPAGE_KEY, lessonDescriptionToDisplay, htmlContent.toString()); - - - } - else - htmlPage = resources.getMessage(ExportPortfolioConstants.EXPORT_FAILED_KEY); - - return htmlPage; - - } - - private String returnRelativeExportTmpDir(String absolutePath) { - String tempSysDirName = ExportPortfolioConstants.TEMP_DIRECTORY; + String tempSysDirName = FileUtil.TEMP_DIR; return absolutePath.substring(tempSysDirName.length()+1, absolutePath.length()); } @@ -231,75 +150,6 @@ String url = basePath + "/lams/css/" + theme + ".css"; HttpUrlConnectionUtil.writeResponseToFile(url, directory, theme + ".css", cookies); //cookies aren't really needed here. } - - - - - - } - - - - /* - * The method below is commented out, because it uses HttpUrlConnection to connect to export service. - * It might be reverted back to this method, if we need to use jsp engine for the look and feel of things. - * - * MainExportServlet is responsible for calling the main export url - * which is in charge of calling all tools to output its portfolio. - * It is responsible for creating the temporary directory where - * all file output should be placed. It will connect to the main - * export url via HttpUrlConnection. - * At this moment, it is unsure where this page will forward to once - * the files are generated. (Most likely, the online version of the - * export page, or forward to the download page, which zips up all - * the exports and allows the user to download the zip file. - */ -/* String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath(); - String url = basePath + "/exportPortfolio.do"; - String urlWithParameters = null; - String mode = WebUtil.readStrParam(request, WebUtil.PARAM_MODE); - - - - - //create the directory - if (createTemporaryDirectory(ExportPortfolioConstants.EXPORT_TMP_DIR)) - { - - if (mode.equals(ToolAccessMode.LEARNER.toString())) - { - urlWithParameters = WebUtil.appendParameterToURL(url, WebUtil.PARAM_MODE, ToolAccessMode.LEARNER.toString()); - } - else if (mode.equals(ToolAccessMode.TEACHER.toString())) - { - urlWithParameters = WebUtil.appendParameterToURL(url, WebUtil.PARAM_MODE, ToolAccessMode.TEACHER.toString()); - urlWithParameters = WebUtil.appendParameterToURL(urlWithParameters, "lessonID", WebUtil.readStrParam(request, "lessonID")); - } - - try - { - HttpUrlConnectionUtil.writeResponseToFile(urlWithParameters, ExportPortfolioConstants.EXPORT_TMP_DIR, ExportPortfolioConstants.MAIN_EXPORT_FILENAME, cookies); - } - catch(MalformedURLException e) - { - throw new ExportPortfolioException("The URL given is invalid. ",e); - } - catch(FileNotFoundException e) - { - throw new ExportPortfolioException("The directory or file may not exist. ",e); - } - catch(IOException e) - { - throw new ExportPortfolioException("A problem has occurred while writing file. ", e); - } - - - //writeResponseToFile(urlWithParameters, ExportPortfolioConstants.EXPORT_TMP_DIR, ExportPortfolioConstants.MAIN_EXPORT_FILENAME, cookies); - } - //forward somewhere - - */ - } Index: lams_learning/src/java/org/lamsfoundation/lams/learning/learningApplicationContext.xml =================================================================== diff -u -r2b6827b06455b7269c88062bd218427529ee0a4c -r6f11dd80335ff2b8a2d06d21f1a49b307ed233c1 --- lams_learning/src/java/org/lamsfoundation/lams/learning/learningApplicationContext.xml (.../learningApplicationContext.xml) (revision 2b6827b06455b7269c88062bd218427529ee0a4c) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/learningApplicationContext.xml (.../learningApplicationContext.xml) (revision 6f11dd80335ff2b8a2d06d21f1a49b307ed233c1) @@ -59,16 +59,17 @@ - + PROPAGATION_REQUIRED - PROPAGATION_REQUIRED + PROPAGATION_REQUIRED + PROPAGATION_REQUIRED Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/LearnerAction.java =================================================================== diff -u -ra0722fe03d763f9da5efc82987034d929e6a23a1 -r6f11dd80335ff2b8a2d06d21f1a49b307ed233c1 --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/LearnerAction.java (.../LearnerAction.java) (revision a0722fe03d763f9da5efc82987034d929e6a23a1) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/LearnerAction.java (.../LearnerAction.java) (revision 6f11dd80335ff2b8a2d06d21f1a49b307ed233c1) @@ -111,7 +111,7 @@ String[] msg = new String[1]; msg[0] = e.getMessage(); return new FlashMessage(methodKey, - learnerService.getMessageService().getMessage("error.system.error", msg), + learnerService.getMessageService().getMessage("error.system.learner", msg), FlashMessage.CRITICAL_ERROR); } Index: lams_learning/test/java/org/lamsfoundation/lams/learning/export/service/TestExportPortfolioService.java =================================================================== diff -u -r6c93a29e621c20da5662066e4be018eab3f5d17d -r6f11dd80335ff2b8a2d06d21f1a49b307ed233c1 --- lams_learning/test/java/org/lamsfoundation/lams/learning/export/service/TestExportPortfolioService.java (.../TestExportPortfolioService.java) (revision 6c93a29e621c20da5662066e4be018eab3f5d17d) +++ lams_learning/test/java/org/lamsfoundation/lams/learning/export/service/TestExportPortfolioService.java (.../TestExportPortfolioService.java) (revision 6f11dd80335ff2b8a2d06d21f1a49b307ed233c1) @@ -71,16 +71,6 @@ private final Integer TEST_USER_ID = new Integer(1250); private final Long TEST_LESSON_ID = new Long(900); - private final Long TEST_ACTIVITY_ID1_NB = new Long(600); - private final Long TEST_ACTIVITY_ID2_NB = new Long(601); - private final Long TEST_ACTIVITY_ID3_SURVEY = new Long(602); - private final Long TEST_ACTIVITY_ID4_NB = new Long(603); - private final Long TEST_ACTIVITY_ID5_NB = new Long(604); - private final Long TEST_ACTIVITY_ID6_OPTIONAL = new Long(605); - private final Long TEST_ACTIVITY_ID7_OPT_NB = new Long(606); - private final Long TEST_ACTIVITY_ID8_OPT_SURVEY = new Long(607); - private final Long TEST_ACTIVITY_ID9_NB = new Long(608); - //original test data from lams_common private final Integer TEST_USER_ID_fromCommon = new Integer(1); private final Long TEST_LESSON_ID_fromCommon = new Long(1); @@ -144,188 +134,5 @@ } - /** - * Tests the export service method getOrderedActivityList(LearningDesign), used - * when the student is conducting the export. The ordered list of activities - * returned by this method, is compared with the correct ordered list that - * should be returned. - */ - public void testGetOrderedListByLearningDesign() - { - Long id = testLesson.getLearningDesign().getFirstActivity().getActivityId(); - Vector sortedActivityList = exportService.getOrderedActivityList(testLesson.getLearningDesign()); - Vector correctOrderedList = getTestOrderedActivityIdList(); - Iterator i = sortedActivityList.iterator(); - Iterator j = correctOrderedList.iterator(); - - while(i.hasNext() && j.hasNext()) - { - Activity a = (Activity)i.next(); - Long testId = (Long)j.next(); - // ensure that the activityId from the test ordered list and the ordered list returned from the method is the same - assertEquals(testId, a.getActivityId()); - } - - } - - /** - * Tests the export service method getOrderedActivityList(learnerProgressId), used when - * a student is conducting the export. The ordered list of completed activities returned - * by this method is compared with the correct ordered list that should be returned. - * @return - */ - public void testGetOrderedListByLearnerProgressId() - { - testProgress=learnerProgressDao.getLearnerProgressByLearner(testUser.getUserId(),testLesson.getLessonId()); - - Vector sortedActivityList = exportService.getOrderedActivityList(testProgress); - Vector testActivityIdList = getTestOrderedCompletedActivityIdList(); - Iterator i = sortedActivityList.iterator(); - Iterator j = testActivityIdList.iterator(); - while(i.hasNext() && j.hasNext()) - { - Activity a = (Activity)i.next(); - Long testId = (Long)j.next(); - assertEquals(testId, a.getActivityId()); - - } - } - - /** - * Helper method which creates the ordered activity list, based on the test data - * inserted by export_test_data.sql script. This list is used as a comparison - * between the ordered list obtained by calling getOrderedActivityList(LearningDesign) - * See export_test_data.sql for the list of activities. - * - * @return the ordered list of activities in the learning design - */ - private Vector getTestOrderedActivityIdList() - { - Vector orderedIdList = new Vector(); - orderedIdList.add(TEST_ACTIVITY_ID1_NB); - orderedIdList.add(TEST_ACTIVITY_ID2_NB); - orderedIdList.add(TEST_ACTIVITY_ID3_SURVEY); - orderedIdList.add(TEST_ACTIVITY_ID4_NB); - orderedIdList.add(TEST_ACTIVITY_ID5_NB); - //orderedIdList.add(TEST_ACTIVITY_ID6_OPTIONAL); //not added because its not a toolactivity, only child activities are added - orderedIdList.add(TEST_ACTIVITY_ID7_OPT_NB); - orderedIdList.add(TEST_ACTIVITY_ID8_OPT_SURVEY); - orderedIdList.add(TEST_ACTIVITY_ID9_NB); - return orderedIdList; - } - - /** - * Helper method which creates the ordered list of completed activities by the learner, - * based on the test data inserted by export_test_data.sql script. This list is used as a comparison - * between the ordered list obtained by calling getOrderedActivityList(learnerProgressId) - * See export_test_data.sql for the list of completed activities. - * - * @return the ordered list of completed activities by the test learner - */ - private Vector getTestOrderedCompletedActivityIdList() - { - Vector orderedIdList = new Vector(); - orderedIdList.add(TEST_ACTIVITY_ID1_NB); - orderedIdList.add(TEST_ACTIVITY_ID2_NB); - orderedIdList.add(TEST_ACTIVITY_ID3_SURVEY); - orderedIdList.add(TEST_ACTIVITY_ID4_NB); - orderedIdList.add(TEST_ACTIVITY_ID5_NB); - //orderedIdList.add(TEST_ACTIVITY_ID6_OPTIONAL); //not added because its not a toolactivity, only child activities are added - orderedIdList.add(TEST_ACTIVITY_ID7_OPT_NB); - - return orderedIdList; - } - - /* - //method is not used as it doesnt work. get the lazy initialisation error - public void testGetOrderedListByLearnerProgress2() - { - log.info("==================Inside testGetOrderedList(LearnerProgress)=================="); - testProgress=learnerProgressDao.getLearnerProgressByLearner(testUser,testLesson); - - Vector sortedActivityList = exportService.getOrderedActivityList(testProgress); - Vector testActivityIdList = getTestOrderedCompletedActivityIdList(); - Iterator i = sortedActivityList.iterator(); - Iterator j = testActivityIdList.iterator(); - while(i.hasNext() && j.hasNext()) - { - Activity a = (Activity)i.next(); - Long testId = (Long)j.next(); - assertEquals(testId, a.getActivityId()); - log.info("Activity Id: " + a.getActivityId()); - } - - - } */ - - /* - public void testSetupPortfoliosFromCommonByTeacher() throws LamsToolServiceException - { - log.info("==================Inside testSetupPortfolios by teacher=================="); - Long id = testLesson_fromCommon.getLearningDesign().getFirstActivity().getActivityId(); - Vector sortedActivityList = exportService.getOrderedActivityList(testLesson_fromCommon.getLearningDesign()); - Portfolio[] portfolioArray = exportService.setupPortfolios(sortedActivityList, ToolAccessMode.TEACHER, null); - Portfolio individualPortfolio = null; - assertNotNull(portfolioArray); - - int arraySize = portfolioArray.length; - assertTrue(arraySize!= 0); - for (int i=0; i + +<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8" %> + +<%@ taglib uri="tags-html" prefix="html"%> +<%@ taglib uri="tags-core" prefix="c" %> +<%@ taglib uri="tags-fmt" prefix="fmt" %> +<%@ taglib uri="tags-lams" prefix="lams" %> + + + + + + + + <c:out value="${portfolio.lessonName}"/> + + + + + +

+ +

+ + + +
    + + +
  1. + "/>: + +
  2. + +
+
+
+ + +
\ No newline at end of file Index: lams_learning/web/exportPortfolio/notSupported.jsp =================================================================== diff -u --- lams_learning/web/exportPortfolio/notSupported.jsp (revision 0) +++ lams_learning/web/exportPortfolio/notSupported.jsp (revision 6f11dd80335ff2b8a2d06d21f1a49b307ed233c1) @@ -0,0 +1,53 @@ +<%-- +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 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA + + http://www.gnu.org/licenses/gpl.txt +--%> +<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8" %> +<%@ taglib uri="tags-html" prefix="html"%> +<%@ taglib uri="tags-core" prefix="c" %> +<%@ taglib uri="tags-fmt" prefix="fmt" %> +<%@ taglib uri="tags-lams" prefix="lams" %> + + + + + + + + + + + + + <c:out value="${pageTitle}"/> + + + + + +

+ +

+ + +

+ + + +
\ No newline at end of file Index: lams_learning/web/exportWaitingPage.jsp =================================================================== diff -u -r66f147e9d94ea10fa2c2cea70a78d6479096ddc7 -r6f11dd80335ff2b8a2d06d21f1a49b307ed233c1 --- lams_learning/web/exportWaitingPage.jsp (.../exportWaitingPage.jsp) (revision 66f147e9d94ea10fa2c2cea70a78d6479096ddc7) +++ lams_learning/web/exportWaitingPage.jsp (.../exportWaitingPage.jsp) (revision 6f11dd80335ff2b8a2d06d21f1a49b307ed233c1) @@ -95,7 +95,7 @@ alert(msg); break; case 500: //status 500 Internal Server Error - msg = ""; + msg = "Status 500"; document.getElementById("message").innerHTML = msg; break; }