use of org.olat.repository.RepositoryEntryImportExport.RepositoryEntryImport in project OpenOLAT by OpenOLAT.
the class CourseHandler method importResource.
@Override
public RepositoryEntry importResource(Identity initialAuthor, String initialAuthorAlt, String displayname, String description, boolean withReferences, Locale locale, File file, String filename) {
OLATResource newCourseResource = OLATResourceManager.getInstance().createOLATResourceInstance(CourseModule.class);
ICourse course = CourseFactory.importCourseFromZip(newCourseResource, file);
// cfc.release();
if (course == null) {
return null;
}
RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
RepositoryEntry re = repositoryService.create(initialAuthor, null, "", displayname, description, newCourseResource, RepositoryEntry.ACC_OWNERS);
DBFactory.getInstance().commit();
// create empty run structure
course = CourseFactory.openCourseEditSession(course.getResourceableId());
Structure runStructure = course.getRunStructure();
runStructure.getRootNode().removeAllChildren();
CourseFactory.saveCourse(course.getResourceableId());
// import references
CourseEditorTreeNode rootNode = (CourseEditorTreeNode) course.getEditorTreeModel().getRootNode();
importReferences(rootNode, course, initialAuthor, locale, withReferences);
if (withReferences && course.getCourseConfig().hasCustomSharedFolder()) {
importSharedFolder(course, initialAuthor);
}
if (withReferences && course.getCourseConfig().hasGlossary()) {
importGlossary(course, initialAuthor);
}
// create group management / import groups
CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager();
File fImportBaseDirectory = course.getCourseExportDataDir().getBasefile();
CourseEnvironmentMapper envMapper = cgm.importCourseBusinessGroups(fImportBaseDirectory);
envMapper.setAuthor(initialAuthor);
// upgrade course
course = CourseFactory.loadCourse(cgm.getCourseResource());
course.postImport(fImportBaseDirectory, envMapper);
// rename root nodes, but only when user modified the course title
boolean doUpdateTitle = true;
File repoConfigXml = new File(fImportBaseDirectory, "repo.xml");
if (repoConfigXml.exists()) {
RepositoryEntryImport importConfig;
try {
importConfig = RepositoryEntryImportExport.getConfiguration(new FileInputStream(repoConfigXml));
if (importConfig != null) {
if (displayname.equals(importConfig.getDisplayname())) {
// do not update if title was not modified during import
// user does not expect to have an updated title and there is a chance
// the root node title is not the same as the course title
doUpdateTitle = false;
}
}
} catch (FileNotFoundException e) {
// ignore
}
}
if (doUpdateTitle) {
// do not use truncate!
course.getRunStructure().getRootNode().setShortTitle(Formatter.truncateOnly(displayname, 25));
course.getRunStructure().getRootNode().setLongTitle(displayname);
}
// course.saveRunStructure();
CourseEditorTreeNode editorRootNode = ((CourseEditorTreeNode) course.getEditorTreeModel().getRootNode());
// do not use truncate!
editorRootNode.getCourseNode().setShortTitle(Formatter.truncateOnly(displayname, 25));
editorRootNode.getCourseNode().setLongTitle(displayname);
// mark entire structure as dirty/new so the user can re-publish
markDirtyNewRecursively(editorRootNode);
// root has already been created during export. Unmark it.
editorRootNode.setNewnode(false);
// save and close edit session
CourseFactory.saveCourse(course.getResourceableId());
CourseFactory.closeCourseEditSession(course.getResourceableId(), true);
RepositoryEntryImportExport imp = new RepositoryEntryImportExport(fImportBaseDirectory);
if (imp.anyExportedPropertiesAvailable()) {
re = imp.importContent(re, getMediaContainer(re));
}
// import reminders
importReminders(re, fImportBaseDirectory, envMapper, initialAuthor);
// clean up export folder
cleanExportAfterImport(fImportBaseDirectory);
return re;
}
use of org.olat.repository.RepositoryEntryImportExport.RepositoryEntryImport in project openolat by klemens.
the class CourseHandler method importResource.
@Override
public RepositoryEntry importResource(Identity initialAuthor, String initialAuthorAlt, String displayname, String description, boolean withReferences, Locale locale, File file, String filename) {
OLATResource newCourseResource = OLATResourceManager.getInstance().createOLATResourceInstance(CourseModule.class);
ICourse course = CourseFactory.importCourseFromZip(newCourseResource, file);
// cfc.release();
if (course == null) {
return null;
}
RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
RepositoryEntry re = repositoryService.create(initialAuthor, null, "", displayname, description, newCourseResource, RepositoryEntry.ACC_OWNERS);
DBFactory.getInstance().commit();
// create empty run structure
course = CourseFactory.openCourseEditSession(course.getResourceableId());
Structure runStructure = course.getRunStructure();
runStructure.getRootNode().removeAllChildren();
CourseFactory.saveCourse(course.getResourceableId());
// import references
CourseEditorTreeNode rootNode = (CourseEditorTreeNode) course.getEditorTreeModel().getRootNode();
importReferences(rootNode, course, initialAuthor, locale, withReferences);
if (withReferences && course.getCourseConfig().hasCustomSharedFolder()) {
importSharedFolder(course, initialAuthor);
}
if (withReferences && course.getCourseConfig().hasGlossary()) {
importGlossary(course, initialAuthor);
}
// create group management / import groups
CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager();
File fImportBaseDirectory = course.getCourseExportDataDir().getBasefile();
CourseEnvironmentMapper envMapper = cgm.importCourseBusinessGroups(fImportBaseDirectory);
envMapper.setAuthor(initialAuthor);
// upgrade course
course = CourseFactory.loadCourse(cgm.getCourseResource());
course.postImport(fImportBaseDirectory, envMapper);
// rename root nodes, but only when user modified the course title
boolean doUpdateTitle = true;
File repoConfigXml = new File(fImportBaseDirectory, "repo.xml");
if (repoConfigXml.exists()) {
RepositoryEntryImport importConfig;
try {
importConfig = RepositoryEntryImportExport.getConfiguration(new FileInputStream(repoConfigXml));
if (importConfig != null) {
if (displayname.equals(importConfig.getDisplayname())) {
// do not update if title was not modified during import
// user does not expect to have an updated title and there is a chance
// the root node title is not the same as the course title
doUpdateTitle = false;
}
}
} catch (FileNotFoundException e) {
// ignore
}
}
if (doUpdateTitle) {
// do not use truncate!
course.getRunStructure().getRootNode().setShortTitle(Formatter.truncateOnly(displayname, 25));
course.getRunStructure().getRootNode().setLongTitle(displayname);
}
// course.saveRunStructure();
CourseEditorTreeNode editorRootNode = ((CourseEditorTreeNode) course.getEditorTreeModel().getRootNode());
// do not use truncate!
editorRootNode.getCourseNode().setShortTitle(Formatter.truncateOnly(displayname, 25));
editorRootNode.getCourseNode().setLongTitle(displayname);
// mark entire structure as dirty/new so the user can re-publish
markDirtyNewRecursively(editorRootNode);
// root has already been created during export. Unmark it.
editorRootNode.setNewnode(false);
// save and close edit session
CourseFactory.saveCourse(course.getResourceableId());
CourseFactory.closeCourseEditSession(course.getResourceableId(), true);
RepositoryEntryImportExport imp = new RepositoryEntryImportExport(fImportBaseDirectory);
if (imp.anyExportedPropertiesAvailable()) {
re = imp.importContent(re, getMediaContainer(re));
}
// import reminders
importReminders(re, fImportBaseDirectory, envMapper, initialAuthor);
// clean up export folder
cleanExportAfterImport(fImportBaseDirectory);
return re;
}
use of org.olat.repository.RepositoryEntryImportExport.RepositoryEntryImport in project openolat by klemens.
the class CourseHandler method acceptImport.
@Override
public ResourceEvaluation acceptImport(File file, String filename) {
ResourceEvaluation eval = new ResourceEvaluation();
try {
IndexFileFilter visitor = new IndexFileFilter();
Path fPath = PathUtils.visit(file, filename, visitor);
if (visitor.isValid()) {
Path repoXml = fPath.resolve("export/repo.xml");
if (repoXml != null) {
eval.setValid(true);
RepositoryEntryImport re = RepositoryEntryImportExport.getConfiguration(repoXml);
if (re != null) {
eval.setDisplayname(re.getDisplayname());
eval.setDescription(re.getDescription());
}
eval.setReferences(hasReferences(fPath));
}
}
eval.setValid(visitor.isValid());
PathUtils.closeSubsequentFS(fPath);
} catch (IOException | IllegalArgumentException e) {
log.error("", e);
}
return eval;
}
Aggregations