use of org.olat.course.config.CourseConfig in project openolat by klemens.
the class ModifyCourseEvent method copyCourse.
/**
* Copies a course. More specifically, the run and editor structures and the
* course folder will be copied to create a new course.
*
* @param sourceRes
* @param ureq
* @return copy of the course.
*/
public static OLATResourceable copyCourse(OLATResourceable sourceRes, OLATResource targetRes) {
PersistingCourseImpl sourceCourse = (PersistingCourseImpl) loadCourse(sourceRes);
PersistingCourseImpl targetCourse = new PersistingCourseImpl(targetRes);
File fTargetCourseBasePath = targetCourse.getCourseBaseContainer().getBasefile();
// close connection before file copy
DBFactory.getInstance().commitAndCloseSession();
synchronized (sourceCourse) {
// o_clusterNOK - cannot be solved with doInSync since could take too long (leads to error: "Lock wait timeout exceeded")
// copy configuration
CourseConfig courseConf = CourseConfigManagerImpl.getInstance().copyConfigOf(sourceCourse);
targetCourse.setCourseConfig(courseConf);
// save structures
targetCourse.setRunStructure((Structure) XStreamHelper.xstreamClone(sourceCourse.getRunStructure()));
targetCourse.saveRunStructure();
targetCourse.setEditorTreeModel((CourseEditorTreeModel) XStreamHelper.xstreamClone(sourceCourse.getEditorTreeModel()));
targetCourse.saveEditorTreeModel();
// copy course folder
File fSourceCourseFolder = sourceCourse.getIsolatedCourseBaseFolder();
if (fSourceCourseFolder.exists())
FileUtils.copyDirToDir(fSourceCourseFolder, fTargetCourseBasePath, false, "copy course folder");
// copy folder nodes directories
File fSourceFoldernodesFolder = new File(FolderConfig.getCanonicalRoot() + BCCourseNode.getFoldernodesPathRelToFolderBase(sourceCourse.getCourseEnvironment()));
if (fSourceFoldernodesFolder.exists())
FileUtils.copyDirToDir(fSourceFoldernodesFolder, fTargetCourseBasePath, false, "copy folder nodes directories");
// copy task folder directories
File fSourceTaskfoldernodesFolder = new File(FolderConfig.getCanonicalRoot() + TACourseNode.getTaskFoldersPathRelToFolderRoot(sourceCourse.getCourseEnvironment()));
if (fSourceTaskfoldernodesFolder.exists())
FileUtils.copyDirToDir(fSourceTaskfoldernodesFolder, fTargetCourseBasePath, false, "copy task folder directories");
// update references
List<Reference> refs = referenceManager.getReferences(sourceCourse);
int count = 0;
for (Reference ref : refs) {
referenceManager.addReference(targetCourse, ref.getTarget(), ref.getUserdata());
if (count % 20 == 0) {
DBFactory.getInstance().intermediateCommit();
}
}
// set quotas
Quota sourceQuota = VFSManager.isTopLevelQuotaContainer(sourceCourse.getCourseFolderContainer());
Quota targetQuota = VFSManager.isTopLevelQuotaContainer(targetCourse.getCourseFolderContainer());
if (sourceQuota != null && targetQuota != null) {
QuotaManager qm = QuotaManager.getInstance();
if (sourceQuota.getQuotaKB() != qm.getDefaultQuota(QuotaConstants.IDENTIFIER_DEFAULT_COURSE).getQuotaKB()) {
targetQuota = qm.createQuota(targetQuota.getPath(), sourceQuota.getQuotaKB(), sourceQuota.getUlLimitKB());
qm.setCustomQuotaKB(targetQuota);
}
}
}
return targetRes;
}
use of org.olat.course.config.CourseConfig in project openolat by klemens.
the class ModifyCourseEvent method getCustomCourseCss.
/**
* Create a custom css object for the course layout. This can then be set on a
* MainLayoutController to activate the course layout
*
* @param usess The user session
* @param courseEnvironment the course environment
* @return The custom course css or NULL if no course css is available
*/
public static CustomCSS getCustomCourseCss(UserSession usess, CourseEnvironment courseEnvironment) {
CustomCSS customCSS = null;
CourseConfig courseConfig = courseEnvironment.getCourseConfig();
if (courseConfig.hasCustomCourseCSS()) {
// Notify the current tab that it should load a custom CSS
return CourseLayoutHelper.getCustomCSS(usess, courseEnvironment);
}
return customCSS;
}
use of org.olat.course.config.CourseConfig in project openolat by klemens.
the class ModifyCourseEvent method importCourseFromZip.
/**
* Import a course from a ZIP file.
*
* @param ores
* @param zipFile
* @return New Course.
*/
public static ICourse importCourseFromZip(OLATResource ores, File zipFile) {
// Generate course with filesystem
PersistingCourseImpl newCourse = new PersistingCourseImpl(ores);
CourseConfigManagerImpl.getInstance().deleteConfigOf(newCourse);
// Unzip course strucure in new course
File fCanonicalCourseBasePath = newCourse.getCourseBaseContainer().getBasefile();
if (ZipUtil.unzip(zipFile, fCanonicalCourseBasePath)) {
// Load course strucure now
try {
newCourse.load();
CourseConfig cc = CourseConfigManagerImpl.getInstance().loadConfigFor(newCourse);
// newCourse is not in cache yet, so we cannot call setCourseConfig()
newCourse.setCourseConfig(cc);
loadedCourses.put(newCourse.getResourceableId(), newCourse);
return newCourse;
} catch (AssertException ae) {
// ok failed, cleanup below
// better logging to search error
log.error("rollback importCourseFromZip", ae);
}
}
// cleanup if not successfull
FileUtils.deleteDirsAndFiles(fCanonicalCourseBasePath, true, true);
return null;
}
use of org.olat.course.config.CourseConfig in project openolat by klemens.
the class CertificatesManagerImpl method getDateNextRecertification.
@Override
public Date getDateNextRecertification(Certificate certificate, RepositoryEntry entry) {
ICourse course = CourseFactory.loadCourse(entry);
CourseConfig config = course.getCourseEnvironment().getCourseConfig();
return getDateNextRecertification(certificate, config);
}
use of org.olat.course.config.CourseConfig in project openolat by klemens.
the class CourseRuntimeController method launchGlossary.
private void launchGlossary(UserRequest ureq) {
// start glossary in window
ICourse course = CourseFactory.loadCourse(getRepositoryEntry());
// do not cache cc, not save
final CourseConfig cc = course.getCourseConfig();
final boolean allowGlossaryEditing = reSecurity.isEntryAdmin() || hasCourseRight(CourseRights.RIGHT_GLOSSARY);
// if glossary had been opened from LR as Tab before, warn user:
DTabs dts = Windows.getWindows(ureq).getWindow(ureq).getDTabs();
RepositoryEntry repoEntry = RepositoryManager.getInstance().lookupRepositoryEntryBySoftkey(cc.getGlossarySoftKey(), false);
DTab dt = dts.getDTab(repoEntry.getOlatResource());
if (dt != null) {
List<ContextEntry> entries = BusinessControlFactory.getInstance().createCEListFromResourceType(allowGlossaryEditing ? "true" : "false");
dts.activate(ureq, dt, entries);
} else {
ControllerCreator ctrlCreator = new ControllerCreator() {
public Controller createController(UserRequest lureq, WindowControl lwControl) {
GlossaryMainController glossaryController = CourseGlossaryFactory.createCourseGlossaryMainRunController(lwControl, lureq, cc, allowGlossaryEditing);
listenTo(glossaryController);
if (glossaryController == null) {
// happens in the unlikely event of a user who is in a course and
// now
// tries to access the glossary
String text = translate("error.noglossary");
return MessageUIFactory.createInfoMessage(lureq, lwControl, null, text);
} else {
// use a one-column main layout
LayoutMain3ColsController layoutCtr = new LayoutMain3ColsController(lureq, lwControl, glossaryController);
// dispose glossary on layout dispose
layoutCtr.addDisposableChildController(glossaryController);
return layoutCtr;
}
}
};
ControllerCreator layoutCtrlr = BaseFullWebappPopupLayoutFactory.createAuthMinimalPopupLayout(ureq, ctrlCreator);
// open in new browser window
openInNewBrowserWindow(ureq, layoutCtrlr);
// immediate return after opening new browser window!
return;
}
}
Aggregations