use of org.olat.repository.RepositoryEntryImportExport in project OpenOLAT by OpenOLAT.
the class GlossaryManagerImpl method exportGlossary.
/**
* Exports the glossary resource to the given export directory
*
* @param glossarySoftkey
* @param exportedDataDir
* @return
*/
@Override
public boolean exportGlossary(String glossarySoftkey, File exportedDataDir) {
RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntryBySoftkey(glossarySoftkey, false);
if (re == null)
return false;
File fExportBaseDirectory = new File(exportedDataDir, EXPORT_FOLDER_NAME);
if (!fExportBaseDirectory.mkdir())
return false;
// export properties
RepositoryEntryImportExport reImportExport = new RepositoryEntryImportExport(re, fExportBaseDirectory);
return reImportExport.exportDoExport();
}
use of org.olat.repository.RepositoryEntryImportExport in project OpenOLAT by OpenOLAT.
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.repository.RepositoryEntryImportExport in project OpenOLAT by OpenOLAT.
the class ModifyCourseEvent method deployCourseFromZIP.
/**
* Deploys a course from an exported course ZIP file. This process is unatended and
* therefore relies on some default assumptions on how to setup the entry and add
* any referenced resources to the repository.
*
* @param exportedCourseZIPFile
*/
public static RepositoryEntry deployCourseFromZIP(File exportedCourseZIPFile, String softKey, int access) {
RepositoryEntryImportExport importExport = new RepositoryEntryImportExport(exportedCourseZIPFile);
if (!StringHelper.containsNonWhitespace(softKey)) {
softKey = importExport.getSoftkey();
}
RepositoryEntry existingEntry = repositoryManager.lookupRepositoryEntryBySoftkey(softKey, false);
if (existingEntry != null) {
log.info("RepositoryEntry with softkey " + softKey + " already exists. Course will not be deployed.");
return existingEntry;
}
RepositoryHandler courseHandler = RepositoryHandlerFactory.getInstance().getRepositoryHandler(CourseModule.getCourseTypeName());
RepositoryEntry re = courseHandler.importResource(null, importExport.getInitialAuthor(), importExport.getDisplayName(), importExport.getDescription(), true, Locale.ENGLISH, exportedCourseZIPFile, exportedCourseZIPFile.getName());
re.setSoftkey(softKey);
repositoryService.update(re);
ICourse course = loadCourse(re);
publishCourse(course, access, false, null, Locale.ENGLISH);
return re;
}
use of org.olat.repository.RepositoryEntryImportExport in project OpenOLAT by OpenOLAT.
the class NodeExportVisitor method exportToFilesystem.
/**
* @see org.olat.course.ICourse#exportToFilesystem(java.io.File)
* <p>
* See OLAT-5368: Course Export can take longer than say 2min.
* <p>
*/
@Override
public void exportToFilesystem(OLATResource originalCourseResource, File exportDirectory, boolean runtimeDatas, boolean backwardsCompatible) {
long s = System.currentTimeMillis();
log.info("exportToFilesystem: exporting course " + this + " to " + exportDirectory + "...");
File fCourseBase = getCourseBaseContainer().getBasefile();
// make the folder structure
File fExportedDataDir = new File(exportDirectory, EXPORTED_DATA_FOLDERNAME);
fExportedDataDir.mkdirs();
// export course config
FileUtils.copyFileToDir(new File(fCourseBase, CourseConfigManager.COURSECONFIG_XML), exportDirectory, "course export courseconfig");
// export business groups
CourseEnvironmentMapper envMapper = getCourseEnvironment().getCourseGroupManager().getBusinessGroupEnvironment();
if (backwardsCompatible) {
// prevents duplicate names
envMapper.avoidDuplicateNames();
}
getCourseEnvironment().getCourseGroupManager().exportCourseBusinessGroups(fExportedDataDir, envMapper, runtimeDatas, backwardsCompatible);
if (backwardsCompatible) {
XStream xstream = CourseXStreamAliases.getReadCourseXStream();
Structure exportedStructure = (Structure) XStreamHelper.readObject(xstream, new File(fCourseBase, RUNSTRUCTURE_XML));
visit(new NodePostExportVisitor(envMapper, backwardsCompatible), exportedStructure.getRootNode());
XStreamHelper.writeObject(xstream, new File(exportDirectory, RUNSTRUCTURE_XML), exportedStructure);
CourseEditorTreeModel exportedEditorModel = (CourseEditorTreeModel) XStreamHelper.readObject(xstream, new File(fCourseBase, EDITORTREEMODEL_XML));
visit(new NodePostExportVisitor(envMapper, backwardsCompatible), exportedEditorModel.getRootNode());
XStreamHelper.writeObject(xstream, new File(exportDirectory, EDITORTREEMODEL_XML), exportedEditorModel);
} else {
// export editor structure
FileUtils.copyFileToDir(new File(fCourseBase, EDITORTREEMODEL_XML), exportDirectory, "course export exitortreemodel");
// export run structure
FileUtils.copyFileToDir(new File(fCourseBase, RUNSTRUCTURE_XML), exportDirectory, "course export runstructure");
}
// export layout and media folder
FileUtils.copyDirToDir(new File(fCourseBase, "layout"), exportDirectory, "course export layout folder");
FileUtils.copyDirToDir(new File(fCourseBase, "media"), exportDirectory, "course export media folder");
// export course folder
FileUtils.copyDirToDir(getIsolatedCourseBaseFolder(), exportDirectory, "course export folder");
// export any node data
log.info("exportToFilesystem: exporting course " + this + ": exporting all nodes...");
Visitor visitor = new NodeExportVisitor(fExportedDataDir, this);
TreeVisitor tv = new TreeVisitor(visitor, getEditorTreeModel().getRootNode(), true);
tv.visitAll();
log.info("exportToFilesystem: exporting course " + this + ": exporting all nodes...done.");
// OLAT-5368: do intermediate commit to avoid transaction timeout
// discussion intermediatecommit vs increased transaction timeout:
// pro intermediatecommit: not much
// pro increased transaction timeout: would fix OLAT-5368 but only move the problem
// @TODO OLAT-2597: real solution is a long-running background-task concept...
DBFactory.getInstance().intermediateCommit();
// export shared folder
CourseConfig config = getCourseConfig();
if (config.hasCustomSharedFolder()) {
log.info("exportToFilesystem: exporting course " + this + ": shared folder...");
if (!SharedFolderManager.getInstance().exportSharedFolder(config.getSharedFolderSoftkey(), fExportedDataDir)) {
// export failed, delete reference to shared folder in the course config
log.info("exportToFilesystem: exporting course " + this + ": export of shared folder failed.");
config.setSharedFolderSoftkey(CourseConfig.VALUE_EMPTY_SHAREDFOLDER_SOFTKEY);
CourseConfigManagerImpl.getInstance().saveConfigTo(this, config);
}
log.info("exportToFilesystem: exporting course " + this + ": shared folder...done.");
}
// OLAT-5368: do intermediate commit to avoid transaction timeout
// discussion intermediatecommit vs increased transaction timeout:
// pro intermediatecommit: not much
// pro increased transaction timeout: would fix OLAT-5368 but only move the problem
// @TODO OLAT-2597: real solution is a long-running background-task concept...
DBFactory.getInstance().intermediateCommit();
// export glossary
if (config.hasGlossary()) {
log.info("exportToFilesystem: exporting course " + this + ": glossary...");
if (!GlossaryManager.getInstance().exportGlossary(config.getGlossarySoftKey(), fExportedDataDir)) {
// export failed, delete reference to glossary in the course config
log.info("exportToFilesystem: exporting course " + this + ": export of glossary failed.");
config.setGlossarySoftKey(null);
CourseConfigManagerImpl.getInstance().saveConfigTo(this, config);
}
log.info("exportToFilesystem: exporting course " + this + ": glossary...done.");
}
// OLAT-5368: do intermediate commit to avoid transaction timeout
// discussion intermediatecommit vs increased transaction timeout:
// pro intermediatecommit: not much
// pro increased transaction timeout: would fix OLAT-5368 but only move the problem
// @TODO OLAT-2597: real solution is a long-running background-task concept...
DBFactory.getInstance().intermediateCommit();
log.info("exportToFilesystem: exporting course " + this + ": configuration and repo data...");
// export configuration file
FileUtils.copyFileToDir(new File(fCourseBase, CourseConfigManager.COURSECONFIG_XML), exportDirectory, "course export configuration and repo info");
// export repo metadata
RepositoryManager rm = RepositoryManager.getInstance();
RepositoryEntry myRE = rm.lookupRepositoryEntry(this, true);
RepositoryEntryImportExport importExport = new RepositoryEntryImportExport(myRE, fExportedDataDir);
importExport.exportDoExportProperties();
// OLAT-5368: do intermediate commit to avoid transaction timeout
// discussion intermediatecommit vs increased transaction timeout:
// pro intermediatecommit: not much
// pro increased transaction timeout: would fix OLAT-5368 but only move the problem
// @TODO OLAT-2597: real solution is a long-running background-task concept...
DBFactory.getInstance().intermediateCommit();
// export reminders
CoreSpringFactory.getImpl(ReminderService.class).exportReminders(myRE, fExportedDataDir);
log.info("exportToFilesystem: exporting course " + this + " to " + exportDirectory + " done.");
log.info("finished export course '" + getCourseTitle() + "' in t=" + Long.toString(System.currentTimeMillis() - s));
}
use of org.olat.repository.RepositoryEntryImportExport in project OpenOLAT by OpenOLAT.
the class IQTESTCourseNode method exportNode.
@Override
public void exportNode(File exportDirectory, ICourse course) {
String repositorySoftKey = (String) getModuleConfiguration().get(IQEditController.CONFIG_KEY_REPOSITORY_SOFTKEY);
// nothing to export
if (repositorySoftKey == null)
return;
// self healing
RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntryBySoftkey(repositorySoftKey, false);
if (re == null) {
// nothing to export, but correct the module configuration
IQEditController.removeIQReference(getModuleConfiguration());
return;
}
File fExportDirectory = new File(exportDirectory, getIdent());
fExportDirectory.mkdirs();
RepositoryEntryImportExport reie = new RepositoryEntryImportExport(re, fExportDirectory);
reie.exportDoExport();
}
Aggregations