Search in sources :

Example 51 with RepositoryEntryImportExport

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

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();
}
Also used : RepositoryEntryImportExport(org.olat.repository.RepositoryEntryImportExport) RepositoryEntry(org.olat.repository.RepositoryEntry) File(java.io.File)

Example 52 with RepositoryEntryImportExport

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

the class BinderTemplateHandler method importResource.

@Override
public RepositoryEntry importResource(Identity initialAuthor, String initialAuthorAlt, String displayname, String description, boolean withReferences, Locale locale, File file, String filename) {
    RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
    PortfolioService portfolioService = CoreSpringFactory.getImpl(PortfolioService.class);
    try {
        // create resource
        OLATResource resource = portfolioService.createBinderTemplateResource();
        OlatRootFolderImpl fResourceRootContainer = FileResourceManager.getInstance().getFileResourceRootImpl(resource);
        File fResourceFileroot = fResourceRootContainer.getBasefile();
        File zipRoot = new File(fResourceFileroot, FileResourceManager.ZIPDIR);
        FileResource.copyResource(file, filename, zipRoot);
        // create repository entry
        RepositoryEntry re = repositoryService.create(initialAuthor, initialAuthorAlt, "", displayname, description, resource, RepositoryEntry.ACC_OWNERS);
        // import binder
        File binderFile = new File(zipRoot, BinderTemplateResource.BINDER_XML);
        Binder transientBinder = BinderXStream.fromPath(binderFile.toPath());
        File posterImage = null;
        if (StringHelper.containsNonWhitespace(transientBinder.getImagePath())) {
            posterImage = new File(zipRoot, transientBinder.getImagePath());
        }
        portfolioService.importBinder(transientBinder, re, posterImage);
        RepositoryEntryImportExport rei = new RepositoryEntryImportExport(re, zipRoot);
        if (rei.anyExportedPropertiesAvailable()) {
            re = rei.importContent(re, fResourceRootContainer.createChildContainer("media"));
        }
        // delete the imported files
        FileUtils.deleteDirsAndFiles(zipRoot, true, true);
        return re;
    } catch (IOException e) {
        log.error("", e);
        return null;
    }
}
Also used : Binder(org.olat.modules.portfolio.Binder) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) PortfolioService(org.olat.modules.portfolio.PortfolioService) RepositoryEntryImportExport(org.olat.repository.RepositoryEntryImportExport) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) IOException(java.io.IOException) File(java.io.File) RepositoryService(org.olat.repository.RepositoryService)

Example 53 with RepositoryEntryImportExport

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

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);
    }
}
Also used : Binder(org.olat.modules.portfolio.Binder) ShieldOutputStream(org.olat.core.util.io.ShieldOutputStream) PortfolioService(org.olat.modules.portfolio.PortfolioService) RepositoryEntryImportExport(org.olat.repository.RepositoryEntryImportExport) ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) OLATResource(org.olat.resource.OLATResource) File(java.io.File)

Example 54 with RepositoryEntryImportExport

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

the class AbstractFeedCourseNode method exportNode.

@Override
public void exportNode(File exportDirectory, ICourse course) {
    RepositoryEntry re = getReferencedRepositoryEntry();
    if (re == null)
        return;
    // build current export ZIP for feed learning resource
    FeedManager.getInstance().getFeedArchive(re.getOlatResource());
    // trigger resource file export
    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 55 with RepositoryEntryImportExport

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

the class IQTESTCourseNode 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()) {
        File file = rie.importGetExportedFile();
        RepositoryHandler handlerQTI21 = RepositoryHandlerFactory.getInstance().getRepositoryHandler(ImsQTI21Resource.TYPE_NAME);
        RepositoryEntry re;
        if (handlerQTI21.acceptImport(file, "repo.zip").isValid()) {
            re = handlerQTI21.importResource(owner, rie.getInitialAuthor(), rie.getDisplayName(), rie.getDescription(), false, locale, rie.importGetExportedFile(), null);
            getModuleConfiguration().set(IQEditController.CONFIG_KEY_TYPE_QTI, IQEditController.CONFIG_VALUE_QTI21);
        } else {
            RepositoryHandler handlerQTI = RepositoryHandlerFactory.getInstance().getRepositoryHandler(TestFileResource.TYPE_NAME);
            re = handlerQTI.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) File(java.io.File)

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