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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations