Search in sources :

Example 1 with FileResource

use of org.olat.fileresource.types.FileResource in project OpenOLAT by OpenOLAT.

the class FileResourceManager method getAsDownloadeableMediaResource.

/**
 * @param res
 * @return File resource as downloadeable media resource.
 */
public MediaResource getAsDownloadeableMediaResource(OLATResourceable res) {
    FileResource fr = getAsGenericFileResource(res);
    File f = getFile(fr);
    if (// folder not existing or no file in it
    f == null)
        throw new OLATRuntimeException(FileResourceManager.class, "could not get File for OLATResourceable " + res.getResourceableId() + ":" + res.getResourceableTypeName(), null);
    return new DownloadeableMediaResource(f);
}
Also used : OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) FileResource(org.olat.fileresource.types.FileResource) File(java.io.File)

Example 2 with FileResource

use of org.olat.fileresource.types.FileResource in project OpenOLAT by OpenOLAT.

the class FileResourceManager method getFileResource.

/**
 * @param res
 * @return Get resourceable as file.
 */
private File getFileResource(OLATResourceable res, String resourceFolderName) {
    FileResource fr = getAsGenericFileResource(res);
    File f = getFile(fr, resourceFolderName);
    if (f == null) {
        // folder not existing or no file in it
        throw new OLATRuntimeException(FileResourceManager.class, "could not getFileResource for OLATResourceable " + res.getResourceableId() + ":" + res.getResourceableTypeName(), null);
    }
    return f;
}
Also used : OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) FileResource(org.olat.fileresource.types.FileResource) File(java.io.File)

Example 3 with FileResource

use of org.olat.fileresource.types.FileResource in project OpenOLAT by OpenOLAT.

the class FileResourceManager method getAsGenericFileResource.

private FileResource getAsGenericFileResource(OLATResourceable res) {
    FileResource fr = new FileResource();
    fr.overrideResourceableId(res.getResourceableId());
    return fr;
}
Also used : FileResource(org.olat.fileresource.types.FileResource)

Example 4 with FileResource

use of org.olat.fileresource.types.FileResource in project OpenOLAT by OpenOLAT.

the class VideoHandler method importResource.

@Override
public RepositoryEntry importResource(Identity initialAuthor, String initialAuthorAlt, String displayname, String description, boolean withReferences, Locale locale, File file, String fileName) {
    // 1) Create resource and repository entry
    FileResource ores = new VideoFileResource();
    OLATResource resource = OLATResourceManager.getInstance().createAndPersistOLATResourceInstance(ores);
    RepositoryEntry repoEntry = CoreSpringFactory.getImpl(RepositoryService.class).create(initialAuthor, null, "", displayname, description, resource, RepositoryEntry.ACC_OWNERS);
    if (fileName == null) {
        fileName = file.getName();
    }
    fileName = fileName.toLowerCase();
    VFSLeaf importFile = new LocalFileImpl(file);
    long filesize = importFile.getSize();
    VideoManager videoManager = CoreSpringFactory.getImpl(VideoManager.class);
    if (fileName.endsWith(".mp4") || fileName.endsWith(".mov") || fileName.endsWith(".m4v")) {
        // 2a) import video from raw mp4 master video file
        videoManager.importFromMasterFile(repoEntry, importFile);
    } else if (fileName.endsWith(".zip")) {
        // 2b) import video from archive from another OpenOLAT instance
        DBFactory.getInstance().commit();
        videoManager.importFromExportArchive(repoEntry, importFile);
    }
    // 3) Persist Meta data
    videoManager.createVideoMetadata(repoEntry, filesize, fileName);
    DBFactory.getInstance().commit();
    // 4) start transcoding process if enabled
    videoManager.startTranscodingProcessIfEnabled(resource);
    return repoEntry;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VideoFileResource(org.olat.fileresource.types.VideoFileResource) FileResource(org.olat.fileresource.types.FileResource) VideoFileResource(org.olat.fileresource.types.VideoFileResource) OLATResource(org.olat.resource.OLATResource) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) RepositoryEntry(org.olat.repository.RepositoryEntry) VideoManager(org.olat.modules.video.VideoManager) RepositoryService(org.olat.repository.RepositoryService)

Example 5 with FileResource

use of org.olat.fileresource.types.FileResource in project OpenOLAT by OpenOLAT.

the class WebDocumentHandler method importResource.

@Override
public RepositoryEntry importResource(Identity initialAuthor, String initialAuthorAlt, String displayname, String description, boolean withReferences, Locale locale, File file, String filename) {
    FileResource ores;
    if (DocFileResource.TYPE_NAME.equals(supportedType) && DocFileResource.validate(filename)) {
        ores = new DocFileResource();
    } else if (XlsFileResource.TYPE_NAME.equals(supportedType) && XlsFileResource.validate(filename)) {
        ores = new XlsFileResource();
    } else if (PowerpointFileResource.TYPE_NAME.equals(supportedType) && PowerpointFileResource.validate(filename)) {
        ores = new PowerpointFileResource();
    } else if (PdfFileResource.TYPE_NAME.equals(supportedType) && PdfFileResource.validate(filename)) {
        ores = new PdfFileResource();
    } else if (ImageFileResource.TYPE_NAME.equals(supportedType) && ImageFileResource.validate(filename)) {
        ores = new ImageFileResource();
    } else if (MovieFileResource.TYPE_NAME.equals(supportedType) && MovieFileResource.validate(filename)) {
        ores = new MovieFileResource();
    } else if (SoundFileResource.TYPE_NAME.equals(supportedType) && SoundFileResource.validate(filename)) {
        ores = new SoundFileResource();
    } else if (AnimationFileResource.TYPE_NAME.equals(supportedType) && AnimationFileResource.validate(filename)) {
        ores = new AnimationFileResource();
    } else {
        return null;
    }
    OLATResource resource = OLATResourceManager.getInstance().createAndPersistOLATResourceInstance(ores);
    File fResourceFileroot = FileResourceManager.getInstance().getFileResourceRootImpl(resource).getBasefile();
    File target = new File(fResourceFileroot, filename);
    try {
        Files.move(file.toPath(), target.toPath(), StandardCopyOption.REPLACE_EXISTING);
    } catch (IOException e) {
        log.error("", e);
    }
    RepositoryEntry re = CoreSpringFactory.getImpl(RepositoryService.class).create(initialAuthor, null, "", displayname, description, resource, RepositoryEntry.ACC_OWNERS);
    DBFactory.getInstance().commit();
    return re;
}
Also used : DocFileResource(org.olat.fileresource.types.DocFileResource) AnimationFileResource(org.olat.fileresource.types.AnimationFileResource) FileResource(org.olat.fileresource.types.FileResource) PdfFileResource(org.olat.fileresource.types.PdfFileResource) XlsFileResource(org.olat.fileresource.types.XlsFileResource) ImageFileResource(org.olat.fileresource.types.ImageFileResource) DocFileResource(org.olat.fileresource.types.DocFileResource) AnimationFileResource(org.olat.fileresource.types.AnimationFileResource) SoundFileResource(org.olat.fileresource.types.SoundFileResource) MovieFileResource(org.olat.fileresource.types.MovieFileResource) PowerpointFileResource(org.olat.fileresource.types.PowerpointFileResource) OLATResource(org.olat.resource.OLATResource) IOException(java.io.IOException) RepositoryEntry(org.olat.repository.RepositoryEntry) SoundFileResource(org.olat.fileresource.types.SoundFileResource) XlsFileResource(org.olat.fileresource.types.XlsFileResource) PowerpointFileResource(org.olat.fileresource.types.PowerpointFileResource) PdfFileResource(org.olat.fileresource.types.PdfFileResource) ImageFileResource(org.olat.fileresource.types.ImageFileResource) File(java.io.File) MovieFileResource(org.olat.fileresource.types.MovieFileResource) RepositoryService(org.olat.repository.RepositoryService)

Aggregations

FileResource (org.olat.fileresource.types.FileResource)10 File (java.io.File)6 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)4 RepositoryEntry (org.olat.repository.RepositoryEntry)4 RepositoryService (org.olat.repository.RepositoryService)4 OLATResource (org.olat.resource.OLATResource)4 IOException (java.io.IOException)2 LocalFileImpl (org.olat.core.util.vfs.LocalFileImpl)2 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)2 AnimationFileResource (org.olat.fileresource.types.AnimationFileResource)2 DocFileResource (org.olat.fileresource.types.DocFileResource)2 ImageFileResource (org.olat.fileresource.types.ImageFileResource)2 MovieFileResource (org.olat.fileresource.types.MovieFileResource)2 PdfFileResource (org.olat.fileresource.types.PdfFileResource)2 PowerpointFileResource (org.olat.fileresource.types.PowerpointFileResource)2 SoundFileResource (org.olat.fileresource.types.SoundFileResource)2 VideoFileResource (org.olat.fileresource.types.VideoFileResource)2 XlsFileResource (org.olat.fileresource.types.XlsFileResource)2 VideoManager (org.olat.modules.video.VideoManager)2