Search in sources :

Example 46 with RepositoryEntryImportExport

use of org.olat.repository.RepositoryEntryImportExport in project OpenOLAT by OpenOLAT.

the class IQSURVCourseNode method importNode.

@Override
public void importNode(File importDirectory, ICourse course, Identity owner, Locale locale, boolean withReferences) {
    RepositoryEntryImportExport rie = new RepositoryEntryImportExport(importDirectory, getIdent());
    if (withReferences && rie.anyExportedPropertiesAvailable()) {
        RepositoryHandler handler = RepositoryHandlerFactory.getInstance().getRepositoryHandler(SurveyFileResource.TYPE_NAME);
        RepositoryEntry re = handler.importResource(owner, rie.getInitialAuthor(), rie.getDisplayName(), rie.getDescription(), false, locale, rie.importGetExportedFile(), null);
        IQEditController.setIQReference(re, getModuleConfiguration());
    } else {
        IQEditController.removeIQReference(getModuleConfiguration());
    }
}
Also used : RepositoryEntryImportExport(org.olat.repository.RepositoryEntryImportExport) RepositoryHandler(org.olat.repository.handlers.RepositoryHandler) RepositoryEntry(org.olat.repository.RepositoryEntry)

Example 47 with RepositoryEntryImportExport

use of org.olat.repository.RepositoryEntryImportExport in project OpenOLAT by OpenOLAT.

the class CPCourseNode method exportNode.

@Override
public void exportNode(File exportDirectory, ICourse course) {
    RepositoryEntry re = CPEditController.getCPReference(getModuleConfiguration(), false);
    if (re == null)
        return;
    File fExportDirectory = new File(exportDirectory, getIdent());
    fExportDirectory.mkdirs();
    RepositoryEntryImportExport reie = new RepositoryEntryImportExport(re, fExportDirectory);
    reie.exportDoExport();
}
Also used : RepositoryEntryImportExport(org.olat.repository.RepositoryEntryImportExport) RepositoryEntry(org.olat.repository.RepositoryEntry) File(java.io.File)

Example 48 with RepositoryEntryImportExport

use of org.olat.repository.RepositoryEntryImportExport in project openolat by klemens.

the class VideoManagerImpl method importFromExportArchive.

@Override
public boolean importFromExportArchive(RepositoryEntry repoEntry, VFSLeaf exportArchive) {
    OLATResource videoResource = repoEntry.getOlatResource();
    // 1) unzip archive
    VFSContainer baseContainer = FileResourceManager.getInstance().getFileResourceRootImpl(videoResource);
    ZipUtil.unzip(exportArchive, baseContainer);
    exportArchive.delete();
    // 2) update metadata from the repo entry export
    LocalFolderImpl repoentryContainer = (LocalFolderImpl) baseContainer.resolve(DIRNAME_REPOENTRY);
    if (repoentryContainer != null) {
        RepositoryEntryImportExport importExport = new RepositoryEntryImportExport(repoentryContainer.getBasefile());
        importExport.setRepoEntryPropertiesFromImport(repoEntry);
        // now delete the import folder, not used anymore
        repoentryContainer.delete();
    }
    // 3) Set poster image for repo entry
    VFSContainer masterContainer = getMasterContainer(videoResource);
    VFSLeaf posterImage = (VFSLeaf) masterContainer.resolve(FILENAME_POSTER_JPG);
    if (posterImage != null) {
        repositoryManager.setImage(posterImage, repoEntry);
    }
    return true;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) RepositoryEntryImportExport(org.olat.repository.RepositoryEntryImportExport) VFSContainer(org.olat.core.util.vfs.VFSContainer) OLATResource(org.olat.resource.OLATResource) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 49 with RepositoryEntryImportExport

use of org.olat.repository.RepositoryEntryImportExport 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;
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) PersistingCourseGroupManager(org.olat.course.groupsandrights.PersistingCourseGroupManager) RepositoryEntryImportExport(org.olat.repository.RepositoryEntryImportExport) CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode) FileNotFoundException(java.io.FileNotFoundException) OLATResource(org.olat.resource.OLATResource) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) RepositoryEntryImport(org.olat.repository.RepositoryEntryImportExport.RepositoryEntryImport) FileInputStream(java.io.FileInputStream) Structure(org.olat.course.Structure) File(java.io.File) CourseEnvironmentMapper(org.olat.course.export.CourseEnvironmentMapper) RepositoryService(org.olat.repository.RepositoryService)

Example 50 with RepositoryEntryImportExport

use of org.olat.repository.RepositoryEntryImportExport in project openolat by klemens.

the class CourseHandler method importGlossary.

private void importGlossary(ICourse course, Identity owner) {
    GlossaryManager gm = GlossaryManager.getInstance();
    RepositoryEntryImportExport importExport = gm.getRepositoryImportExport(course.getCourseExportDataDir().getBasefile());
    GlossaryResource resource = gm.createGlossary();
    if (resource == null) {
        log.error("Error adding glossary directry during repository reference import: " + importExport.getDisplayName());
        return;
    }
    // unzip contents
    VFSContainer glossaryContainer = gm.getGlossaryRootFolder(resource);
    File fExportedFile = importExport.importGetExportedFile();
    if (fExportedFile.exists()) {
        ZipUtil.unzip(new LocalFileImpl(fExportedFile), glossaryContainer);
    } else {
        log.warn("The actual contents of the glossary 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 glossary reference
    CourseConfig courseConfig = course.getCourseEnvironment().getCourseConfig();
    courseConfig.setGlossarySoftKey(importedRepositoryEntry.getSoftkey());
    CoreSpringFactory.getImpl(ReferenceManager.class).addReference(course, importedRepositoryEntry.getOlatResource(), GlossaryManager.GLOSSARY_REPO_REF_IDENTIFYER);
    CourseFactory.setCourseConfig(course.getResourceableId(), courseConfig);
}
Also used : 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) GlossaryManager(org.olat.modules.glossary.GlossaryManager) File(java.io.File) GlossaryResource(org.olat.fileresource.types.GlossaryResource) RepositoryService(org.olat.repository.RepositoryService) CourseConfig(org.olat.course.config.CourseConfig) ReferenceManager(org.olat.resource.references.ReferenceManager)

Aggregations

RepositoryEntryImportExport (org.olat.repository.RepositoryEntryImportExport)60 RepositoryEntry (org.olat.repository.RepositoryEntry)54 File (java.io.File)40 RepositoryHandler (org.olat.repository.handlers.RepositoryHandler)18 OLATResource (org.olat.resource.OLATResource)16 RepositoryService (org.olat.repository.RepositoryService)8 VFSContainer (org.olat.core.util.vfs.VFSContainer)6 CourseConfig (org.olat.course.config.CourseConfig)6 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)4 LocalFileImpl (org.olat.core.util.vfs.LocalFileImpl)4 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)4 ICourse (org.olat.course.ICourse)4 CourseEnvironmentMapper (org.olat.course.export.CourseEnvironmentMapper)4 CourseGroupManager (org.olat.course.groupsandrights.CourseGroupManager)4 Binder (org.olat.modules.portfolio.Binder)4 PortfolioService (org.olat.modules.portfolio.PortfolioService)4 ReferenceManager (org.olat.resource.references.ReferenceManager)4 XStream (com.thoughtworks.xstream.XStream)2 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2