Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
OLAT CI-CD Testing Project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lars Oliver Dam
OLAT CI-CD Testing Project
Commits
64a81fcc
Commit
64a81fcc
authored
4 years ago
by
srosse
Browse files
Options
Downloads
Patches
Plain Diff
OO-5238: give a name ot the downloaded ZIP of participants folders
parent
0c47adcd
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/org/olat/course/nodes/pf/manager/FileSystemExport.java
+25
-5
25 additions, 5 deletions
...va/org/olat/course/nodes/pf/manager/FileSystemExport.java
with
25 additions
and
5 deletions
src/main/java/org/olat/course/nodes/pf/manager/FileSystemExport.java
+
25
−
5
View file @
64a81fcc
...
@@ -22,12 +22,14 @@ package org.olat.course.nodes.pf.manager;
...
@@ -22,12 +22,14 @@ package org.olat.course.nodes.pf.manager;
import
java.io.File
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.nio.file.FileVisitResult
;
import
java.nio.file.FileVisitResult
;
import
java.nio.file.Files
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.nio.file.Paths
;
import
java.nio.file.SimpleFileVisitor
;
import
java.nio.file.SimpleFileVisitor
;
import
java.nio.file.attribute.BasicFileAttributes
;
import
java.nio.file.attribute.BasicFileAttributes
;
import
java.util.Date
;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.Locale
;
...
@@ -44,12 +46,15 @@ import org.olat.core.gui.media.ServletUtil;
...
@@ -44,12 +46,15 @@ import org.olat.core.gui.media.ServletUtil;
import
org.olat.core.gui.translator.Translator
;
import
org.olat.core.gui.translator.Translator
;
import
org.olat.core.id.Identity
;
import
org.olat.core.id.Identity
;
import
org.olat.core.logging.Tracing
;
import
org.olat.core.logging.Tracing
;
import
org.olat.core.util.Formatter
;
import
org.olat.core.util.StringHelper
;
import
org.olat.core.util.StringHelper
;
import
org.olat.core.util.Util
;
import
org.olat.core.util.Util
;
import
org.olat.core.util.io.ShieldOutputStream
;
import
org.olat.core.util.io.SystemFileFilter
;
import
org.olat.core.util.io.SystemFileFilter
;
import
org.olat.course.nodes.PFCourseNode
;
import
org.olat.course.nodes.PFCourseNode
;
import
org.olat.course.nodes.pf.ui.PFParticipantController
;
import
org.olat.course.nodes.pf.ui.PFParticipantController
;
import
org.olat.course.run.environment.CourseEnvironment
;
import
org.olat.course.run.environment.CourseEnvironment
;
import
org.olat.repository.RepositoryEntry
;
import
org.olat.user.UserManager
;
import
org.olat.user.UserManager
;
/**
/**
*
*
...
@@ -107,6 +112,14 @@ public class FileSystemExport implements MediaResource {
...
@@ -107,6 +112,14 @@ public class FileSystemExport implements MediaResource {
@Override
@Override
public
void
prepare
(
HttpServletResponse
hres
)
{
public
void
prepare
(
HttpServletResponse
hres
)
{
RepositoryEntry
entry
=
courseEnv
.
getCourseGroupManager
().
getCourseEntry
();
String
label
=
StringHelper
.
transformDisplayNameToFileSystemName
(
pfNode
.
getShortName
()
+
"_"
+
entry
.
getDisplayname
())
+
"_"
+
Formatter
.
formatDatetimeWithMinutes
(
new
Date
())
+
".zip"
;
String
urlEncodedLabel
=
StringHelper
.
urlEncodeUTF8
(
label
);
hres
.
setHeader
(
"Content-Disposition"
,
"attachment; filename*=UTF-8''"
+
urlEncodedLabel
);
hres
.
setHeader
(
"Content-Description"
,
urlEncodedLabel
);
try
(
ZipOutputStream
zout
=
new
ZipOutputStream
(
hres
.
getOutputStream
()))
{
try
(
ZipOutputStream
zout
=
new
ZipOutputStream
(
hres
.
getOutputStream
()))
{
zout
.
setLevel
(
9
);
zout
.
setLevel
(
9
);
Path
relPath
=
Paths
.
get
(
courseEnv
.
getCourseBaseContainer
().
getBasefile
().
getAbsolutePath
(),
Path
relPath
=
Paths
.
get
(
courseEnv
.
getCourseBaseContainer
().
getBasefile
().
getAbsolutePath
(),
...
@@ -132,8 +145,8 @@ public class FileSystemExport implements MediaResource {
...
@@ -132,8 +145,8 @@ public class FileSystemExport implements MediaResource {
* @param translator
* @param translator
* @throws IOException Signals that an I/O exception has occurred.
* @throws IOException Signals that an I/O exception has occurred.
*/
*/
public
static
boolean
fsToZip
(
ZipOutputStream
zout
,
String
zipPath
,
final
Path
sourceFolder
,
PFCourseNode
pfNode
,
public
static
boolean
fsToZip
(
final
ZipOutputStream
zout
,
String
zipPath
,
final
Path
sourceFolder
,
PFCourseNode
pfNode
,
List
<
Identity
>
identities
,
Translator
translator
)
{
List
<
Identity
>
identities
,
final
Translator
translator
)
{
if
(
StringHelper
.
containsNonWhitespace
(
zipPath
))
{
if
(
StringHelper
.
containsNonWhitespace
(
zipPath
))
{
if
(!
zipPath
.
endsWith
(
"/"
))
{
if
(!
zipPath
.
endsWith
(
"/"
))
{
...
@@ -143,7 +156,7 @@ public class FileSystemExport implements MediaResource {
...
@@ -143,7 +156,7 @@ public class FileSystemExport implements MediaResource {
zipPath
=
""
;
zipPath
=
""
;
}
}
final
String
targetPath
=
zipPath
+
translator
.
translate
(
"participant.folder"
)
+
"/"
;
final
String
targetPath
=
zipPath
;
final
UserManager
userManager
=
CoreSpringFactory
.
getImpl
(
UserManager
.
class
);
final
UserManager
userManager
=
CoreSpringFactory
.
getImpl
(
UserManager
.
class
);
Set
<
String
>
idKeys
=
new
HashSet
<>();
Set
<
String
>
idKeys
=
new
HashSet
<>();
if
(
identities
!=
null
)
{
if
(
identities
!=
null
)
{
...
@@ -188,7 +201,7 @@ public class FileSystemExport implements MediaResource {
...
@@ -188,7 +201,7 @@ public class FileSystemExport implements MediaResource {
String
relPath
=
sourceFolder
.
relativize
(
file
).
toString
();
String
relPath
=
sourceFolder
.
relativize
(
file
).
toString
();
if
((
relPath
=
containsID
(
relPath
))
!=
null
&&
(
relPath
=
boxesEnabled
(
relPath
))
!=
null
)
{
if
((
relPath
=
containsID
(
relPath
))
!=
null
&&
(
relPath
=
boxesEnabled
(
relPath
))
!=
null
)
{
zout
.
putNextEntry
(
new
ZipEntry
(
targetPath
+
relPath
));
zout
.
putNextEntry
(
new
ZipEntry
(
targetPath
+
relPath
));
Files
.
copy
(
file
,
zout
);
copy
File
(
file
,
zout
);
zout
.
closeEntry
();
zout
.
closeEntry
();
}
}
return
FileVisitResult
.
CONTINUE
;
return
FileVisitResult
.
CONTINUE
;
...
@@ -204,7 +217,6 @@ public class FileSystemExport implements MediaResource {
...
@@ -204,7 +217,6 @@ public class FileSystemExport implements MediaResource {
return
FileVisitResult
.
CONTINUE
;
return
FileVisitResult
.
CONTINUE
;
}
}
});
});
zout
.
close
();
return
true
;
return
true
;
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
log
.
error
(
"Unable to export zip"
,
e
);
log
.
error
(
"Unable to export zip"
,
e
);
...
@@ -212,4 +224,12 @@ public class FileSystemExport implements MediaResource {
...
@@ -212,4 +224,12 @@ public class FileSystemExport implements MediaResource {
}
}
}
}
private
static
void
copyFile
(
Path
file
,
ZipOutputStream
zout
)
{
try
(
OutputStream
out
=
new
ShieldOutputStream
(
zout
))
{
Files
.
copy
(
file
,
zout
);
}
catch
(
Exception
e
)
{
log
.
error
(
"Cannot zip {}"
,
file
,
e
);
}
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment