Search in sources :

Example 1 with SharedFolderManager

use of org.olat.modules.sharedfolder.SharedFolderManager in project openolat by klemens.

the class CourseHandler method importSharedFolder.

private void importSharedFolder(ICourse course, Identity owner) {
    SharedFolderManager sfm = SharedFolderManager.getInstance();
    RepositoryEntryImportExport importExport = sfm.getRepositoryImportExport(course.getCourseExportDataDir().getBasefile());
    SharedFolderFileResource resource = sfm.createSharedFolder();
    if (resource == null) {
        log.error("Error adding file resource during repository reference import: " + importExport.getDisplayName());
    }
    // unzip contents
    VFSContainer sfContainer = sfm.getSharedFolder(resource);
    File fExportedFile = importExport.importGetExportedFile();
    if (fExportedFile.exists()) {
        ZipUtil.unzip(new LocalFileImpl(fExportedFile), sfContainer);
    } else {
        log.warn("The actual contents of the shared folder were not found in the export.");
    }
    // create repository entry
    RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
    OLATResource ores = OLATResourceManager.getInstance().findOrPersistResourceable(resource);
    RepositoryEntry importedRepositoryEntry = repositoryService.create(owner, null, importExport.getResourceName(), importExport.getDisplayName(), importExport.getDescription(), ores, 0);
    // set the new shared folder reference
    CourseConfig courseConfig = course.getCourseEnvironment().getCourseConfig();
    courseConfig.setSharedFolderSoftkey(importedRepositoryEntry.getSoftkey());
    CoreSpringFactory.getImpl(ReferenceManager.class).addReference(importedRepositoryEntry.getOlatResource(), course, SharedFolderManager.SHAREDFOLDERREF);
    CourseFactory.setCourseConfig(course.getResourceableId(), courseConfig);
}
Also used : SharedFolderFileResource(org.olat.fileresource.types.SharedFolderFileResource) RepositoryEntryImportExport(org.olat.repository.RepositoryEntryImportExport) VFSContainer(org.olat.core.util.vfs.VFSContainer) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) File(java.io.File) SharedFolderManager(org.olat.modules.sharedfolder.SharedFolderManager) RepositoryService(org.olat.repository.RepositoryService) CourseConfig(org.olat.course.config.CourseConfig) ReferenceManager(org.olat.resource.references.ReferenceManager)

Example 2 with SharedFolderManager

use of org.olat.modules.sharedfolder.SharedFolderManager in project OpenOLAT by OpenOLAT.

the class CourseHandler method importSharedFolder.

private void importSharedFolder(ICourse course, Identity owner) {
    SharedFolderManager sfm = SharedFolderManager.getInstance();
    RepositoryEntryImportExport importExport = sfm.getRepositoryImportExport(course.getCourseExportDataDir().getBasefile());
    SharedFolderFileResource resource = sfm.createSharedFolder();
    if (resource == null) {
        log.error("Error adding file resource during repository reference import: " + importExport.getDisplayName());
    }
    // unzip contents
    VFSContainer sfContainer = sfm.getSharedFolder(resource);
    File fExportedFile = importExport.importGetExportedFile();
    if (fExportedFile.exists()) {
        ZipUtil.unzip(new LocalFileImpl(fExportedFile), sfContainer);
    } else {
        log.warn("The actual contents of the shared folder were not found in the export.");
    }
    // create repository entry
    RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
    OLATResource ores = OLATResourceManager.getInstance().findOrPersistResourceable(resource);
    RepositoryEntry importedRepositoryEntry = repositoryService.create(owner, null, importExport.getResourceName(), importExport.getDisplayName(), importExport.getDescription(), ores, 0);
    // set the new shared folder reference
    CourseConfig courseConfig = course.getCourseEnvironment().getCourseConfig();
    courseConfig.setSharedFolderSoftkey(importedRepositoryEntry.getSoftkey());
    CoreSpringFactory.getImpl(ReferenceManager.class).addReference(importedRepositoryEntry.getOlatResource(), course, SharedFolderManager.SHAREDFOLDERREF);
    CourseFactory.setCourseConfig(course.getResourceableId(), courseConfig);
}
Also used : SharedFolderFileResource(org.olat.fileresource.types.SharedFolderFileResource) RepositoryEntryImportExport(org.olat.repository.RepositoryEntryImportExport) VFSContainer(org.olat.core.util.vfs.VFSContainer) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) File(java.io.File) SharedFolderManager(org.olat.modules.sharedfolder.SharedFolderManager) RepositoryService(org.olat.repository.RepositoryService) CourseConfig(org.olat.course.config.CourseConfig) ReferenceManager(org.olat.resource.references.ReferenceManager)

Aggregations

File (java.io.File)2 LocalFileImpl (org.olat.core.util.vfs.LocalFileImpl)2 VFSContainer (org.olat.core.util.vfs.VFSContainer)2 CourseConfig (org.olat.course.config.CourseConfig)2 SharedFolderFileResource (org.olat.fileresource.types.SharedFolderFileResource)2 SharedFolderManager (org.olat.modules.sharedfolder.SharedFolderManager)2 RepositoryEntry (org.olat.repository.RepositoryEntry)2 RepositoryEntryImportExport (org.olat.repository.RepositoryEntryImportExport)2 RepositoryService (org.olat.repository.RepositoryService)2 OLATResource (org.olat.resource.OLATResource)2 ReferenceManager (org.olat.resource.references.ReferenceManager)2