Index: lams_learning/src/java/org/lamsfoundation/lams/learning/export/service/ExportPortfolioService.java
===================================================================
RCS file: /usr/local/cvsroot/lams_learning/src/java/org/lamsfoundation/lams/learning/export/service/ExportPortfolioService.java,v
diff -u -r1.6 -r1.7
--- lams_learning/src/java/org/lamsfoundation/lams/learning/export/service/ExportPortfolioService.java 14 Oct 2005 07:04:59 -0000 1.6
+++ lams_learning/src/java/org/lamsfoundation/lams/learning/export/service/ExportPortfolioService.java 20 Oct 2005 05:38:00 -0000 1.7
@@ -59,6 +59,7 @@
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.util.HttpUrlConnectionUtil;
import org.lamsfoundation.lams.util.FileUtil;
import org.lamsfoundation.lams.util.FileUtilException;
@@ -80,10 +81,24 @@
private ILamsCoreToolService lamsCoreToolService;
private ITransitionDAO transitionDAO;
private IActivityDAO activityDAO;
+ private IUserDAO userDAO;
private ILearnerService learnerService;
private ILessonDAO lessonDAO;
+ private String exportTmpDir; //value assigned then the doExport method is executed
+ /**
+ * @return Returns the exportTmpDir.
+ */
+ public String getExportTmpDir() {
+ return exportTmpDir;
+ }
+ /**
+ * @param exportTmpDir The exportTmpDir to set.
+ */
+ public void setExportTmpDir(String exportTmpDir) {
+ this.exportTmpDir = exportTmpDir;
+ }
/**
* @param learnerService The learnerService to set.
*/
@@ -119,6 +134,12 @@
this.lamsCoreToolService = lamsCoreToolService;
}
+ /**
+ * @param userDAO The userDAO to set.
+ */
+ public void setUserDAO(IUserDAO userDAO) {
+ this.userDAO = userDAO;
+ }
/** @see org.lamsfoundation.lams.learning.export.service.IExportPortfolioService#getOrderedActivityList(org.lamsfoundation.lams.learningdesign.LearningDesign) */
public Vector getOrderedActivityList(LearningDesign learningDesign)
@@ -157,35 +178,7 @@
}
}
-
-
/** @see org.lamsfoundation.lams.learning.export.service.IExportPortfolioService#exportPortfolioForTeacher(org.lamsfoundation.lams.lesson.Lesson) */
- public Portfolio[] exportPortfolioForTeacher(Lesson lesson, Cookie[] cookies)
- {
- Vector 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="lesson cannot be null";
- throw new ExportPortfolioException(error);
- }
- Vector activities = getOrderedActivityList(lesson.getLearningDesign());
-
- try
- {
- portfolios = setupPortfolios(activities, ToolAccessMode.TEACHER, null);
-
- exports = doExport(portfolios, ExportPortfolioConstants.EXPORT_TMP_DIR, cookies);
-
- }
- catch (LamsToolServiceException e)
- {
- //throw new ExportPortfolioException(e);
- }
- return exports;
- }
-
public Portfolio[] exportPortfolioForTeacher(Long lessonId, Cookie[] cookies)
{
Lesson lesson = lessonDAO.getLesson(lessonId);
@@ -204,7 +197,7 @@
{
portfolios = setupPortfolios(activities, ToolAccessMode.TEACHER, null);
- exports = doExport(portfolios, ExportPortfolioConstants.EXPORT_TMP_DIR, cookies);
+ exports = doExport(portfolios, cookies);
}
catch (LamsToolServiceException e)
@@ -218,35 +211,39 @@
/** @see org.lamsfoundation.lams.learning.export.service.IExportPortfolioService#exportPortfolioForStudent(java.lang.Long, org.lamsfoundation.lams.usermanagement.User,boolean) */
- public Portfolio[] exportPortfolioForStudent(Long learnerProgressId, User user, boolean anonymity, Cookie[] cookies)
+ public Portfolio[] exportPortfolioForStudent(Integer userId, Long lessonID, boolean anonymity, Cookie[] cookies)
{
-
Vector portfolios = null;
Portfolio[] exports = null;
- if (learnerProgressId == null || user == null)
+ User learner = userDAO.getUserById(userId);
+ Lesson lesson = lessonDAO.getLesson(lessonID);
+
+ if (learner == null || lesson == null)
{
- String error="learnerProgress or user is null";
+ String error="The learner or lesson cannot be found. Cannot Continue";
throw new ExportPortfolioException(error);
}
+
+ LearnerProgress learnerProgress = learnerService.getProgress(learner, lesson);
+
+ Vector activities = getOrderedActivityList(learnerProgress.getLearnerProgressId());
- Vector activities = getOrderedActivityList(learnerProgressId);
-
-
- try
- {
- portfolios = setupPortfolios(activities, ToolAccessMode.LEARNER, user);
-
- exports = doExport(portfolios, ExportPortfolioConstants.EXPORT_TMP_DIR, cookies);
- }
- catch (LamsToolServiceException e)
- {
- throw new ExportPortfolioException("An exception has occurred while generating portfolios. The error is: " + e);
- }
-
- return exports;
+
+ try
+ {
+ portfolios = setupPortfolios(activities, ToolAccessMode.LEARNER, learner);
+
+ exports = doExport(portfolios, cookies);
+ }
+ catch (LamsToolServiceException e)
+ {
+ throw new ExportPortfolioException("An exception has occurred while generating portfolios. The error is: " + e);
+ }
+
+ return exports;
+
}
-
/** @see org.lamsfoundation.lams.learning.export.service.IExportPortfolioService#setupPortfolios(java.util.Vector, org.lamsfoundation.lams.tool.ToolAccessMode, org.lamsfoundation.lams.usermanagement.User) */
public Vector setupPortfolios(Vector sortedActivityList, ToolAccessMode accessMode, User user) throws LamsToolServiceException
@@ -402,11 +399,18 @@
/** @see org.lamsfoundation.lams.learning.export.service.IExportPortfolioService#zipPortfolio(String, String) */
public String zipPortfolio(String filename, String directoryToZip)
{
- String zipfileName = null;
+ String zipfileName, dirToPutZip;
+ //create tmp dir to put zip file
+
try
{
- zipfileName = ZipFileUtil.createZipFile(filename, directoryToZip);
+ dirToPutZip = FileUtil.createTempDirectory(ExportPortfolioConstants.DIR_SUFFIX_ZIP);
+ zipfileName = ZipFileUtil.createZipFile(filename, directoryToZip, dirToPutZip);
}
+ catch(FileUtilException e)
+ {
+ throw new ExportPortfolioException("Cannot create tmp dir in which export is to be made.");
+ }
catch(ZipFileUtilException e)
{
throw new ExportPortfolioException("An error has occurred while zipping up the directory " + e);
@@ -415,21 +419,18 @@
}
- /** @see org.lamsfoundation.lams.learning.export.service.IExportPortfolioService#doExport(java.util.Vector, String) */
- public Portfolio[] doExport(Vector portfolios, String tempDirectoryName, Cookie[] cookies)
+ public Portfolio[] doExport(Vector portfolios, Cookie[] cookies)
{
Iterator i = portfolios.iterator();
String activitySubDirectory;
String exportURL;
String toolLink;
String mainFileName = null;
+ String tempDirectoryName;
//create the root directory for the export
- if(!createDirectory(ExportPortfolioConstants.EXPORT_TMP_DIR))
- {
- throw new ExportPortfolioException("The export directory cannot be created. Cannot continue");
- }
-
+ tempDirectoryName = createDirectory(ExportPortfolioConstants.DIR_SUFFIX_EXPORT);
+ setExportTmpDir(tempDirectoryName);
//iterate through the list of portfolios, create subdirectory,
while(i.hasNext())
{
@@ -460,7 +461,7 @@
mainFileName = connectToToolViaExportURL(absoluteExportURL, cookies);
//toolLink is used in main page, so that it can link with the tools export pages.
- toolLink = subDirectoryName + File.separator + mainFileName;
+ toolLink = subDirectoryName + "/" + mainFileName;
portfolio.setToolLink(toolLink);
@@ -503,42 +504,18 @@
* @param subDir The name of the child directory to create.
* @return true is the subdirectory was created, false otherwise
*/
- private boolean createDirectory(String directory)
+ private String createDirectory(String name)
{
- boolean created=false;
- if (FileUtil.directoryExist(directory))
- {
- //delete directory and create a new one
- try
- {
- if (FileUtil.deleteDirectory(directory))
- {
- created = FileUtil.createDirectory(directory);
- }
- else
- {
- throw new ExportPortfolioException("Could not delete the temporary directory " + directory + ", please manually delete this directory in order to proceed.");
- }
-
- }
- catch(FileUtilException e)
- {
- throw new ExportPortfolioException("An error has occurred while trying to create the temporary directory for the export. Reason: ", e);
- }
- }
- else
- {
- try
- {
- created = FileUtil.createDirectory(directory);
- }
- catch(FileUtilException e)
- {
- throw new ExportPortfolioException("An error has occurred while trying to create the temporary directory for the export. Reason: ", e);
- }
-
- }
- return created;
+ String tmpDir=null;
+ try
+ {
+ tmpDir = FileUtil.createTempDirectory(name);
+ }
+ catch(FileUtilException e)
+ {
+ throw new ExportPortfolioException("Unable to create temporary directory for export", e);
+ }
+ return tmpDir;
}
@@ -650,7 +627,10 @@
} */
+ public String getExportDir()
+ {
+ return getExportTmpDir();
+ }
-
}
Index: lams_learning/src/java/org/lamsfoundation/lams/learning/export/service/IExportPortfolioService.java
===================================================================
RCS file: /usr/local/cvsroot/lams_learning/src/java/org/lamsfoundation/lams/learning/export/service/IExportPortfolioService.java,v
diff -u -r1.6 -r1.7
--- lams_learning/src/java/org/lamsfoundation/lams/learning/export/service/IExportPortfolioService.java 14 Oct 2005 07:04:59 -0000 1.6
+++ lams_learning/src/java/org/lamsfoundation/lams/learning/export/service/IExportPortfolioService.java 20 Oct 2005 05:38:00 -0000 1.7
@@ -69,22 +69,22 @@
* Portfolio objects, in which the web layer can iterate through the array
* of portfolios to display the links to each activity.
* @param lesson The specific instance of the LearningDesign and Class.
+ * @param cookies. Are passed along to doExport, in order for access the export for other tools
* @return Portfolio[] The array of portfolio objects.
*/
- public Portfolio[] exportPortfolioForTeacher(Lesson lesson, Cookie[] cookies);
-
public Portfolio[] exportPortfolioForTeacher(Long lessonId, Cookie[] cookies);
+
/**
* The main method that performs the export for the student.
* It will get the list of activities that the user has completed
* and will setup the portfolios for each activity.
- * @param learnerProgressId The learner progress id, which is used to determine the learner progress and the
- * list of activities completed by the learner.
- * @param user The learner.
+ * @param userId The learner id.
+ * @param lessonID The lesson id of the lesson, the learner is doing the export for
* @param anonymity The anonymity flag, is true, then anonymity is on, otherwise username would be visible.
+ * @param cookies Are passed along to doExport, in order for access the export for other tools
* @return Portfolio[] The array of portfolio objects.
*/
- public Portfolio[] exportPortfolioForStudent(Long learnerProgressId, User user, boolean anonymity, Cookie[] cookies);
+ public Portfolio[] exportPortfolioForStudent(Integer userId, Long lessonID, boolean anonymity, Cookie[] cookies);
/**
* A helper method that sets up the export url for the activity. Will go through all key-value pairs
@@ -98,7 +98,7 @@
/**
* 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.
+ * (retrieved from Tool object), title, exportPortfolioUrl respestively.
*
* @param activity The Tool Activity
* @return a Portfolio object
@@ -148,15 +148,6 @@
public Vector getOrderedActivityList(Long learnerProgressId);
/**
- * Creates a directory with the name directoryName
.
- *
- * @param directoryName The name and location of the directory.
- * @return true if the directory has been created, false otherwise
- */
- // public boolean createTempDirectory(String directoryName);
-
-
- /**
* Zips up the directory specified by directoryToZip
and
* saves it in the filename given by filename
.
*
@@ -167,16 +158,17 @@
public String zipPortfolio(String filename, String directoryToZip);
/**
- * Iterates through the list of portfolios, creates a subdirectory for each of the tools
+ * 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
+ * @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, String tempDirectoryName, Cookie[] cookies);
+ 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
@@ -185,9 +177,10 @@
* @param tool The portfolio object, which contains the exportUrl in which to connect to.
* @return The main file name of the tool's page.
*/
- //commented out to use common code from HttpUrlConnectionUtil
public String connectToToolViaExportURL(String exportURL, Cookie[] cookies);
+ public String getExportDir();
+
/* public Portfolio[] exportPortfolioForStudent(LearnerProgress learnerProgress, User user, boolean anonymity);
public Portfolio[] exportPortfolioForStudent(Lesson lesson, User user, boolean anonymity);