Search in sources :

Example 26 with Media

use of org.olat.modules.portfolio.Media in project openolat by klemens.

the class CitationHandler method createMedia.

@Override
public Media createMedia(String title, String description, Object mediaObject, String businessPath, Identity author) {
    Media media = mediaDao.createMedia(title, description, (String) mediaObject, CITATION_MEDIA, businessPath, null, 60, author);
    ThreadLocalUserActivityLogger.log(PortfolioLoggingAction.PORTFOLIO_MEDIA_ADDED, getClass(), LoggingResourceable.wrap(media));
    return media;
}
Also used : Media(org.olat.modules.portfolio.Media)

Example 27 with Media

use of org.olat.modules.portfolio.Media in project openolat by klemens.

the class FileHandler method createMedia.

public Media createMedia(String title, String description, File file, String filename, String businessPath, Identity author) {
    Media media = mediaDao.createMedia(title, description, filename, FILE_TYPE, businessPath, null, 60, author);
    ThreadLocalUserActivityLogger.log(PortfolioLoggingAction.PORTFOLIO_MEDIA_ADDED, getClass(), LoggingResourceable.wrap(media));
    File mediaDir = fileStorage.generateMediaSubDirectory(media);
    File mediaFile = new File(mediaDir, filename);
    FileUtils.copyFileToFile(file, mediaFile, false);
    String storagePath = fileStorage.getRelativePath(mediaDir);
    mediaDao.updateStoragePath(media, storagePath, filename);
    return media;
}
Also used : UploadMedia(org.olat.modules.portfolio.ui.media.UploadMedia) Media(org.olat.modules.portfolio.Media) File(java.io.File)

Example 28 with Media

use of org.olat.modules.portfolio.Media in project openolat by klemens.

the class ForumMediaHandler method createMedia.

@Override
public Media createMedia(String title, String description, Object mediaObject, String businessPath, Identity author) {
    Message message = null;
    if (mediaObject instanceof Message) {
        // reload the message
        message = (Message) mediaObject;
        message = forumManager.loadMessage(message.getKey());
    } else if (mediaObject instanceof MessageLight) {
        MessageLight messageLight = (MessageLight) mediaObject;
        message = forumManager.loadMessage(messageLight.getKey());
    }
    String content = message.getBody();
    Media media = mediaDao.createMedia(title, description, content, FORUM_HANDLER, businessPath, null, 70, author);
    ThreadLocalUserActivityLogger.log(PortfolioLoggingAction.PORTFOLIO_MEDIA_ADDED, getClass(), LoggingResourceable.wrap(media));
    File messageDir = forumManager.getMessageDirectory(message.getForum().getKey(), message.getKey(), false);
    if (messageDir != null && messageDir.exists()) {
        File[] attachments = messageDir.listFiles();
        if (attachments.length > 0) {
            File mediaDir = fileStorage.generateMediaSubDirectory(media);
            for (File attachment : attachments) {
                FileUtils.copyFileToDir(attachment, mediaDir, "Forum media");
            }
            String storagePath = fileStorage.getRelativePath(mediaDir);
            media = mediaDao.updateStoragePath(media, storagePath, null);
        }
    }
    return media;
}
Also used : Message(org.olat.modules.fo.Message) Media(org.olat.modules.portfolio.Media) MessageLight(org.olat.modules.fo.MessageLight) File(java.io.File)

Example 29 with Media

use of org.olat.modules.portfolio.Media in project OpenOLAT by OpenOLAT.

the class CategoryDAOTest method getMediaCategoriesStatistics.

@Test
public void getMediaCategoriesStatistics() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("pf-media-1");
    Media media = mediaDao.createMedia("Media to categorize", "Media category", "Media content", "text", "[Media:0]", null, 10, id);
    dbInstance.commit();
    Category category = categoryDao.createAndPersistCategory("Cool");
    OLATResourceable ores = OresHelper.createOLATResourceableInstance(Media.class, media.getKey());
    categoryDao.appendRelation(ores, category);
    dbInstance.commitAndCloseSession();
    // load medias
    List<CategoryStatistics> catStatistics = categoryDao.getMediaCategoriesStatistics(id);
    Assert.assertNotNull(catStatistics);
    Assert.assertEquals(1, catStatistics.size());
    Assert.assertEquals(category.getName(), catStatistics.get(0).getName());
    Assert.assertTrue(1 <= catStatistics.get(0).getCount());
}
Also used : CategoryStatistics(org.olat.modules.portfolio.model.CategoryStatistics) Category(org.olat.modules.portfolio.Category) OLATResourceable(org.olat.core.id.OLATResourceable) Media(org.olat.modules.portfolio.Media) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 30 with Media

use of org.olat.modules.portfolio.Media in project OpenOLAT by OpenOLAT.

the class CategoryDAOTest method getMediaCategories.

@Test
public void getMediaCategories() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("pf-media-1");
    Media media = mediaDao.createMedia("Media to categorize", "Media category", "Media content", "text", "[Media:0]", null, 10, id);
    dbInstance.commit();
    Category category = categoryDao.createAndPersistCategory("Cool");
    OLATResourceable ores = OresHelper.createOLATResourceableInstance(Media.class, media.getKey());
    categoryDao.appendRelation(ores, category);
    dbInstance.commitAndCloseSession();
    // load medias
    List<CategoryLight> categories = categoryDao.getMediaCategories(id);
    Assert.assertNotNull(categories);
    Assert.assertEquals(1, categories.size());
    Assert.assertEquals(category.getName(), categories.get(0).getCategory());
}
Also used : Category(org.olat.modules.portfolio.Category) OLATResourceable(org.olat.core.id.OLATResourceable) Media(org.olat.modules.portfolio.Media) CategoryLight(org.olat.modules.portfolio.model.CategoryLight) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Aggregations

Media (org.olat.modules.portfolio.Media)60 File (java.io.File)18 Test (org.junit.Test)10 WindowControl (org.olat.core.gui.control.WindowControl)10 Identity (org.olat.core.id.Identity)10 VFSContainer (org.olat.core.util.vfs.VFSContainer)10 MediaHandler (org.olat.modules.portfolio.MediaHandler)10 List (java.util.List)8 Collectors (java.util.stream.Collectors)8 UserRequest (org.olat.core.gui.UserRequest)8 Component (org.olat.core.gui.components.Component)8 OLATResourceable (org.olat.core.id.OLATResourceable)8 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 Map (java.util.Map)6 Set (java.util.Set)6 FormItem (org.olat.core.gui.components.form.flexible.FormItem)6 FormItemContainer (org.olat.core.gui.components.form.flexible.FormItemContainer)6 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)6 FormBasicController (org.olat.core.gui.components.form.flexible.impl.FormBasicController)6