From c7e1da69a1042f8fffe27743132cc2780d83bfeb Mon Sep 17 00:00:00 2001 From: fkiefer <none@none> Date: Mon, 13 Feb 2017 11:56:20 +0100 Subject: [PATCH] OO-2456 qti12 resolve empty .zip download in archive tool, format file name --- .../org/olat/course/archiver/ArchiveResource.java | 6 ++---- .../java/org/olat/course/nodes/IQSELFCourseNode.java | 2 +- .../java/org/olat/course/nodes/IQSURVCourseNode.java | 2 +- .../java/org/olat/course/nodes/IQTESTCourseNode.java | 2 +- .../org/olat/ims/qti/export/QTIExportManager.java | 12 +++++++++++- .../ims/qti/export/_i18n/LocalStrings_de.properties | 1 + .../ims/qti/export/_i18n/LocalStrings_en.properties | 1 + .../qti21/manager/archive/QTI21ArchiveFormat.java | 2 +- 8 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/olat/course/archiver/ArchiveResource.java b/src/main/java/org/olat/course/archiver/ArchiveResource.java index dbb323b8c3b..266157f6f17 100644 --- a/src/main/java/org/olat/course/archiver/ArchiveResource.java +++ b/src/main/java/org/olat/course/archiver/ArchiveResource.java @@ -94,10 +94,8 @@ public class ArchiveResource implements MediaResource { log.error("", e); } - String label = //courseNode.getType() + "_" + - StringHelper.transformDisplayNameToFileSystemName(courseNode.getShortName()) - + "_" + Formatter.formatDatetimeSave(new Date(System.currentTimeMillis())) - + ".zip"; + String label = StringHelper.transformDisplayNameToFileSystemName(courseNode.getShortName()) + + "_" + Formatter.formatDatetimeSave(new Date()) + ".zip"; String urlEncodedLabel = StringHelper.urlEncodeUTF8(label); hres.setHeader("Content-Disposition","attachment; filename*=UTF-8''" + urlEncodedLabel); hres.setHeader("Content-Description", urlEncodedLabel); diff --git a/src/main/java/org/olat/course/nodes/IQSELFCourseNode.java b/src/main/java/org/olat/course/nodes/IQSELFCourseNode.java index 0b8c19d7f7b..f85216f47ff 100644 --- a/src/main/java/org/olat/course/nodes/IQSELFCourseNode.java +++ b/src/main/java/org/olat/course/nodes/IQSELFCourseNode.java @@ -250,7 +250,7 @@ public class IQSELFCourseNode extends AbstractAccessableCourseNode implements Se try { QTIExportFormatter qef = new QTIExportFormatterCSVType2(locale, null, "\t", "\"", "\r\n", false); - return qem.selectAndExportResults(qef, course.getResourceableId(), getShortTitle(), getIdent(), re, exportStream, ".xls"); + return qem.selectAndExportResults(qef, course.getResourceableId(), getShortTitle(), getIdent(), re, exportStream, locale, ".xls"); } catch (IOException e) { log.error("", e); return false; diff --git a/src/main/java/org/olat/course/nodes/IQSURVCourseNode.java b/src/main/java/org/olat/course/nodes/IQSURVCourseNode.java index e37147e0819..e78d3fd3747 100644 --- a/src/main/java/org/olat/course/nodes/IQSURVCourseNode.java +++ b/src/main/java/org/olat/course/nodes/IQSURVCourseNode.java @@ -328,7 +328,7 @@ public class IQSURVCourseNode extends AbstractAccessableCourseNode implements QT QTIExportFormatter qef = new QTIExportFormatterCSVType3(locale, null,"\t", "\"", "\r\n", false); try { - return qem.selectAndExportResults(qef, course.getResourceableId(), getShortTitle(), getIdent(), re, exportStream, ".xls"); + return qem.selectAndExportResults(qef, course.getResourceableId(), getShortTitle(), getIdent(), re, exportStream, locale, ".xls"); } catch (IOException e) { log.error("", e); return false; diff --git a/src/main/java/org/olat/course/nodes/IQTESTCourseNode.java b/src/main/java/org/olat/course/nodes/IQTESTCourseNode.java index 038d16454b8..220633aebe0 100644 --- a/src/main/java/org/olat/course/nodes/IQTESTCourseNode.java +++ b/src/main/java/org/olat/course/nodes/IQTESTCourseNode.java @@ -669,7 +669,7 @@ public class IQTESTCourseNode extends AbstractAccessableCourseNode implements Pe String shortTitle = getShortTitle(); QTIExportManager qem = QTIExportManager.getInstance(); QTIExportFormatter qef = new QTIExportFormatterCSVType1(locale, "\t", "\"", "\r\n", false); - return qem.selectAndExportResults(qef, courseResourceableId, shortTitle, getIdent(), re, exportStream, ".xls"); + return qem.selectAndExportResults(qef, courseResourceableId, shortTitle, getIdent(), re, exportStream, locale, ".xls"); } } catch (IOException e) { log.error("", e); diff --git a/src/main/java/org/olat/ims/qti/export/QTIExportManager.java b/src/main/java/org/olat/ims/qti/export/QTIExportManager.java index f4206c314a0..ccea4f331ef 100644 --- a/src/main/java/org/olat/ims/qti/export/QTIExportManager.java +++ b/src/main/java/org/olat/ims/qti/export/QTIExportManager.java @@ -33,14 +33,17 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; import org.apache.commons.io.IOUtils; +import org.olat.core.gui.translator.Translator; import org.olat.core.manager.BasicManager; import org.olat.core.util.ExportUtil; import org.olat.core.util.Formatter; +import org.olat.core.util.Util; import org.olat.ims.qti.QTIResult; import org.olat.ims.qti.QTIResultManager; import org.olat.ims.qti.export.helper.QTIItemObject; @@ -106,7 +109,7 @@ public class QTIExportManager extends BasicManager{ } public boolean selectAndExportResults(QTIExportFormatter qef, Long courseResId, String shortTitle, - String olatResourceDetail, RepositoryEntry testRe, ZipOutputStream exportStream, + String olatResourceDetail, RepositoryEntry testRe, ZipOutputStream exportStream, Locale locale, String fileNameSuffix) throws IOException { boolean resultsFoundAndExported = false; QTIResultManager qrm = QTIResultManager.getInstance(); @@ -123,6 +126,13 @@ public class QTIExportManager extends BasicManager{ exportStream.closeEntry(); resultsFoundAndExported = true; } + } else { + String targetFileName = getFilename(shortTitle, fileNameSuffix); + exportStream.putNextEntry(new ZipEntry(targetFileName)); + Translator translator = Util.createPackageTranslator(QTIExportFormatter.class, locale); + IOUtils.write(translator.translate("archive.noresults.short"), exportStream); + exportStream.closeEntry(); + resultsFoundAndExported = true; } return resultsFoundAndExported; } diff --git a/src/main/java/org/olat/ims/qti/export/_i18n/LocalStrings_de.properties b/src/main/java/org/olat/ims/qti/export/_i18n/LocalStrings_de.properties index b6b26ba070e..7ca48c162fc 100644 --- a/src/main/java/org/olat/ims/qti/export/_i18n/LocalStrings_de.properties +++ b/src/main/java/org/olat/ims/qti/export/_i18n/LocalStrings_de.properties @@ -3,6 +3,7 @@ action.choose=Archivieren archive.all.users=Benutzer (Alle Benutzergruppen, z.B. Autoren, Teilnehmer etc) archive.anonymous.users=Anonyme Benutzer (G\u00E4ste) archive.noresults=F\u00FCr diesen Kursbaustein wurden noch keine Resultate gespeichert. +archive.noresults.short=Keine Resultate in diesem Kursbaustein archive.participants=Teilnehmer (Kurs und eingebundene Gruppen) archive.results.successfully=<b>Die Resultate wurden in Ihrem pers\u00F6nlichen Ordner gespeichert.</b> archive.wizard.title=Archivierung von Test und Fragebogen diff --git a/src/main/java/org/olat/ims/qti/export/_i18n/LocalStrings_en.properties b/src/main/java/org/olat/ims/qti/export/_i18n/LocalStrings_en.properties index 88d61842a2c..83f425024fe 100644 --- a/src/main/java/org/olat/ims/qti/export/_i18n/LocalStrings_en.properties +++ b/src/main/java/org/olat/ims/qti/export/_i18n/LocalStrings_en.properties @@ -3,6 +3,7 @@ action.choose=Archive archive.all.users=User (All user groups, e.g. authors, participants etc) archive.anonymous.users=Anonymous users (Guests) archive.noresults=No results saved for this course element. +archive.noresults.short=No results for this course element archive.participants=Participants (Course and embedded groups) archive.results.successfully=<b>The results are archived in your personal folder.</b> archive.wizard.title=Archive of test and survey diff --git a/src/main/java/org/olat/ims/qti21/manager/archive/QTI21ArchiveFormat.java b/src/main/java/org/olat/ims/qti21/manager/archive/QTI21ArchiveFormat.java index c9651d798ab..33b668a1ee3 100644 --- a/src/main/java/org/olat/ims/qti21/manager/archive/QTI21ArchiveFormat.java +++ b/src/main/java/org/olat/ims/qti21/manager/archive/QTI21ArchiveFormat.java @@ -199,7 +199,7 @@ public class QTI21ArchiveFormat { ICourse course = CourseFactory.loadCourse(courseEntry); CourseNode courseNode = course.getRunStructure().getNode(subIdent); String label = StringHelper.transformDisplayNameToFileSystemName(courseNode.getShortName()) - + "_" + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis())) + + "_" + Formatter.formatDatetimeSave(new Date()) + ".xlsx"; if("iqself".equals(courseNode.getType())) { -- GitLab