use of org.olat.core.util.io.ShieldOutputStream in project openolat by klemens.
the class BinderTemplateMediaResource method prepare.
@Override
public void prepare(HttpServletResponse hres) {
try {
hres.setCharacterEncoding("UTF-8");
} catch (Exception e) {
log.error("", e);
}
try (ZipOutputStream zout = new ZipOutputStream(hres.getOutputStream())) {
PortfolioService portfolioService = CoreSpringFactory.getImpl(PortfolioService.class);
Binder loadedTemplate = portfolioService.getBinderByKey(template.getKey());
String label = loadedTemplate.getTitle();
String secureLabel = StringHelper.transformDisplayNameToFileSystemName(label);
String file = secureLabel + ".zip";
hres.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + StringHelper.urlEncodeUTF8(file));
hres.setHeader("Content-Description", StringHelper.urlEncodeUTF8(label));
zout.setLevel(9);
zout.putNextEntry(new ZipEntry("binder.xml"));
BinderXStream.toStream(loadedTemplate, zout);
zout.closeEntry();
if (StringHelper.containsNonWhitespace(loadedTemplate.getImagePath())) {
File posterImage = portfolioService.getPosterImageFile(loadedTemplate);
if (posterImage.exists()) {
zout.putNextEntry(new ZipEntry(loadedTemplate.getImagePath()));
FileUtils.copyFile(posterImage, new ShieldOutputStream(zout));
zout.closeEntry();
}
}
OLATResource resource = templateEntry.getOlatResource();
File baseContainer = FileResourceManager.getInstance().getFileResource(resource);
RepositoryEntryImportExport importExport = new RepositoryEntryImportExport(templateEntry, baseContainer);
importExport.exportDoExportProperties(zout);
} catch (Exception e) {
log.error("", e);
}
}
use of org.olat.core.util.io.ShieldOutputStream in project openolat by klemens.
the class GTACourseNode method archiveNodeData.
@Override
public boolean archiveNodeData(Locale locale, ICourse course, ArchiveOptions options, ZipOutputStream exportStream, String charset) {
final GTAManager gtaManager = CoreSpringFactory.getImpl(GTAManager.class);
final ModuleConfiguration config = getModuleConfiguration();
String prefix;
if (GTAType.group.name().equals(config.getStringValue(GTACourseNode.GTASK_TYPE))) {
prefix = "grouptask_";
} else {
prefix = "ita_";
}
String dirName = prefix + StringHelper.transformDisplayNameToFileSystemName(getShortName()) + "_" + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis()));
TaskList taskList = gtaManager.getTaskList(course.getCourseEnvironment().getCourseGroupManager().getCourseEntry(), this);
// save assessment datas
List<Identity> users = null;
if (config.getBooleanSafe(GTASK_GRADING)) {
users = ScoreAccountingHelper.loadUsers(course.getCourseEnvironment(), options);
String courseTitle = course.getCourseTitle();
String fileName = ExportUtil.createFileNameWithTimeStamp(courseTitle, "xlsx");
List<AssessableCourseNode> nodes = Collections.<AssessableCourseNode>singletonList(this);
try (OutputStream out = new ShieldOutputStream(exportStream)) {
exportStream.putNextEntry(new ZipEntry(dirName + "/" + fileName));
ScoreAccountingHelper.createCourseResultsOverviewXMLTable(users, nodes, course, locale, out);
exportStream.closeEntry();
} catch (Exception e) {
log.error("", e);
}
}
// copy tasks
if (taskList != null) {
if (GTAType.group.name().equals(config.getStringValue(GTACourseNode.GTASK_TYPE))) {
List<BusinessGroup> selectedGroups;
if (options != null && options.getGroup() != null) {
selectedGroups = Collections.singletonList(options.getGroup());
} else {
selectedGroups = gtaManager.getBusinessGroups(this);
}
for (BusinessGroup businessGroup : selectedGroups) {
archiveNodeData(course, businessGroup, taskList, dirName, exportStream);
}
} else {
if (users == null) {
users = ScoreAccountingHelper.loadUsers(course.getCourseEnvironment(), options);
}
Set<Identity> uniqueUsers = new HashSet<>(users);
for (Identity user : uniqueUsers) {
archiveNodeData(course, user, taskList, dirName, exportStream);
}
}
}
// copy solutions
if (config.getBooleanSafe(GTACourseNode.GTASK_SAMPLE_SOLUTION)) {
VFSContainer solutions = gtaManager.getSolutionsContainer(course.getCourseEnvironment(), this);
if (solutions.exists()) {
String solutionDirName = dirName + "/solutions";
for (VFSItem solution : solutions.getItems(new SystemItemFilter())) {
ZipUtil.addToZip(solution, solutionDirName, exportStream);
}
}
}
return true;
}
use of org.olat.core.util.io.ShieldOutputStream in project openolat by klemens.
the class ScoreAccountingHelper method createCourseResultsOverview.
public static void createCourseResultsOverview(List<Identity> identities, List<AssessableCourseNode> nodes, ICourse course, Locale locale, ZipOutputStream zout) {
try (OutputStream out = new ShieldOutputStream(zout)) {
zout.putNextEntry(new ZipEntry("Course_results.xlsx"));
createCourseResultsOverviewXMLTable(identities, nodes, course, locale, out);
zout.closeEntry();
} catch (IOException e) {
log.error("", e);
}
for (AssessableCourseNode node : nodes) {
String dir = "Assessment_documents/" + StringHelper.transformDisplayNameToFileSystemName(node.getShortName());
if (node instanceof IQTESTCourseNode || node.getModuleConfiguration().getBooleanSafe(MSCourseNode.CONFIG_KEY_HAS_INDIVIDUAL_ASSESSMENT_DOCS, false)) {
for (Identity assessedIdentity : identities) {
List<File> assessmentDocuments = course.getCourseEnvironment().getAssessmentManager().getIndividualAssessmentDocuments(node, assessedIdentity);
if (assessmentDocuments != null && !assessmentDocuments.isEmpty()) {
String name = assessedIdentity.getUser().getLastName() + "_" + assessedIdentity.getUser().getFirstName() + "_" + assessedIdentity.getName();
String userDirName = dir + "/" + StringHelper.transformDisplayNameToFileSystemName(name);
for (File document : assessmentDocuments) {
String path = userDirName + "/" + document.getName();
ZipUtil.addFileToZip(path, document, zout);
}
}
}
}
}
}
use of org.olat.core.util.io.ShieldOutputStream in project openolat by klemens.
the class TACourseNode method archiveNodeData.
@Override
public boolean archiveNodeData(Locale locale, ICourse course, ArchiveOptions options, ZipOutputStream exportStream, String charset) {
boolean dataFound = false;
String dropboxPath = DropboxController.getDropboxPathRelToFolderRoot(course.getCourseEnvironment(), this);
OlatRootFolderImpl dropboxDir = new OlatRootFolderImpl(dropboxPath, null);
String solutionsPath = TACourseNode.getFoldernodesPathRelToFolderBase(course.getCourseEnvironment()) + "/" + this.getIdent();
OlatRootFolderImpl solutionDir = new OlatRootFolderImpl(solutionsPath, null);
String returnboxPath = ReturnboxController.getReturnboxPathRelToFolderRoot(course.getCourseEnvironment(), this);
OlatRootFolderImpl returnboxDir = new OlatRootFolderImpl(returnboxPath, null);
Boolean hasTask = (Boolean) getModuleConfiguration().get(TACourseNode.CONF_TASK_ENABLED);
String dirName = "task_" + StringHelper.transformDisplayNameToFileSystemName(getShortName()) + "_" + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis()));
if (dropboxDir.exists() || solutionDir.exists() || returnboxDir.exists() || hasTask.booleanValue()) {
// prepare writing course results overview table
List<Identity> users = ScoreAccountingHelper.loadUsers(course.getCourseEnvironment(), options);
Set<String> dropboxNames = null;
if (options != null && (options.getGroup() != null || options.getIdentities() != null)) {
dropboxNames = new HashSet<String>();
for (Identity user : users) {
dropboxNames.add(user.getName());
}
}
String courseTitle = course.getCourseTitle();
String fileName = ExportUtil.createFileNameWithTimeStamp(courseTitle, "xlsx");
List<AssessableCourseNode> nodes = Collections.<AssessableCourseNode>singletonList(this);
// write course results overview table to filesystem
try (OutputStream out = new ShieldOutputStream(exportStream)) {
exportStream.putNextEntry(new ZipEntry(dirName + "/" + fileName));
ScoreAccountingHelper.createCourseResultsOverviewXMLTable(users, nodes, course, locale, out);
exportStream.closeEntry();
} catch (IOException e) {
log.error("", e);
}
// copy solutions to tmp dir
if (solutionDir.exists()) {
for (VFSItem child : solutionDir.getItems()) {
dataFound = true;
ZipUtil.addToZip(child, dirName + "/solutions", exportStream);
}
}
// copy dropboxes to tmp dir
if (dropboxDir.exists()) {
// OLAT-6362 archive only dropboxes of users that handed in at least one file -> prevent empty folders in archive
List<VFSItem> dropBoxContent = dropboxDir.getItems();
for (VFSItem file : dropBoxContent) {
if ((dropboxNames == null || dropboxNames.contains(file.getName())) && VFSManager.isDirectoryAndNotEmpty(file)) {
dataFound = true;
ZipUtil.addToZip(file, dirName + "/dropboxes", exportStream);
}
}
}
// copy only the choosen task to user taskfolder, loop over all users
String taskfolderPath = TACourseNode.getTaskFolderPathRelToFolderRoot(course.getCourseEnvironment(), this);
OlatRootFolderImpl taskfolderDir = new OlatRootFolderImpl(taskfolderPath, null);
for (Identity identity : users) {
// check if user already chose a task
String assignedTask = TaskController.getAssignedTask(identity, course.getCourseEnvironment(), this);
if (assignedTask != null) {
VFSItem item = taskfolderDir.resolve(assignedTask);
if (item != null) {
// copy choosen task to user folder
ZipUtil.addToZip(item, dirName + "/taskfolders/" + identity.getName(), exportStream);
dataFound = true;
}
}
}
// copy returnboxes
if (returnboxDir.exists()) {
// OLAT-6362 archive only existing returnboxes -> prevent empty folders in archive
List<VFSItem> returnBoxContent = returnboxDir.getItems();
for (VFSItem file : returnBoxContent) {
if ((dropboxNames == null || dropboxNames.contains(file.getName())) && VFSManager.isDirectoryAndNotEmpty(file)) {
dataFound = true;
ZipUtil.addToZip(file, dirName + "/returnboxes", exportStream);
}
}
}
// assessment documents
if (getModuleConfiguration().getBooleanSafe(MSCourseNode.CONFIG_KEY_HAS_INDIVIDUAL_ASSESSMENT_DOCS, false)) {
for (Identity assessedIdentity : users) {
List<File> assessmentDocuments = course.getCourseEnvironment().getAssessmentManager().getIndividualAssessmentDocuments(this, assessedIdentity);
if (assessmentDocuments != null && !assessmentDocuments.isEmpty()) {
for (File document : assessmentDocuments) {
String path = dirName + "/assessment_documents/" + assessedIdentity.getName() + "/" + document.getName();
ZipUtil.addFileToZip(path, document, exportStream);
}
}
}
}
}
return dataFound;
}
use of org.olat.core.util.io.ShieldOutputStream in project openolat by klemens.
the class QTI21ArchiveFormat method export.
public void export(String filename, ZipOutputStream exportStream) {
try (OutputStream out = new ShieldOutputStream(exportStream)) {
exportStream.putNextEntry(new ZipEntry(filename));
exportWorkbook(out);
exportStream.closeEntry();
} catch (IOException e) {
log.error("", e);
}
}
Aggregations