use of org.olat.portfolio.model.artefacts.FileArtefact in project openolat by klemens.
the class FileHandler method createMedia.
@Override
public Media createMedia(AbstractArtefact artefact) {
Media media = null;
if (artefact instanceof FileArtefact) {
VFSContainer artefactFolder = oldPortfolioManager.getArtefactContainer(artefact);
String filename = ((FileArtefact) artefact).getFilename();
String extension = FileUtils.getFileSuffix(filename);
String type = FILE_TYPE;
if ("jpg".equalsIgnoreCase(extension) || "jpeg".equalsIgnoreCase(extension) || "png".equalsIgnoreCase(extension) || "gif".equalsIgnoreCase(extension)) {
type = ImageHandler.IMAGE_TYPE;
}
String businessPath = artefact.getBusinessPath();
if (businessPath == null) {
businessPath = "[PortfolioV2:0][MediaCenter:0]";
}
media = mediaDao.createMedia(artefact.getTitle(), artefact.getDescription(), filename, type, businessPath, artefact.getKey().toString(), artefact.getSignature(), artefact.getAuthor());
ThreadLocalUserActivityLogger.log(PortfolioLoggingAction.PORTFOLIO_MEDIA_ADDED, getClass(), LoggingResourceable.wrap(media));
File mediaDir = fileStorage.generateMediaSubDirectory(media);
String storagePath = fileStorage.getRelativePath(mediaDir);
mediaDao.updateStoragePath(media, storagePath, filename);
VFSContainer mediaContainer = fileStorage.getMediaContainer(media);
VFSManager.copyContent(artefactFolder, mediaContainer);
}
return media;
}
Aggregations