Search in sources :

Example 6 with FileArtefact

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;
}
Also used : VFSContainer(org.olat.core.util.vfs.VFSContainer) UploadMedia(org.olat.modules.portfolio.ui.media.UploadMedia) Media(org.olat.modules.portfolio.Media) FileArtefact(org.olat.portfolio.model.artefacts.FileArtefact) File(java.io.File)

Aggregations

FileArtefact (org.olat.portfolio.model.artefacts.FileArtefact)6 File (java.io.File)2 Date (java.util.Date)2 Test (org.junit.Test)2 VFSContainer (org.olat.core.util.vfs.VFSContainer)2 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)2 Media (org.olat.modules.portfolio.Media)2 UploadMedia (org.olat.modules.portfolio.ui.media.UploadMedia)2 AbstractArtefact (org.olat.portfolio.model.artefacts.AbstractArtefact)2