Search in sources :

Example 11 with Media

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

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 12 with Media

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

the class ForumMediaHandler method createMedia.

@Override
public Media createMedia(AbstractArtefact artefact) {
    VFSContainer artefactFolder = oldPortfolioManager.getArtefactContainer(artefact);
    String businessPath = artefact.getBusinessPath();
    if (businessPath == null) {
        businessPath = "[PortfolioV2:0][MediaCenter:0]";
    }
    Media media = mediaDao.createMedia(artefact.getTitle(), artefact.getDescription(), null, FORUM_HANDLER, businessPath, artefact.getKey().toString(), artefact.getSignature(), artefact.getAuthor());
    ThreadLocalUserActivityLogger.log(PortfolioLoggingAction.PORTFOLIO_MEDIA_ADDED, getClass(), LoggingResourceable.wrap(media));
    List<VFSItem> items = artefactFolder.getItems(new SystemItemFilter());
    if (items.size() > 0) {
        File mediaDir = fileStorage.generateMediaSubDirectory(media);
        String storagePath = fileStorage.getRelativePath(mediaDir);
        mediaDao.updateStoragePath(media, storagePath, null);
        VFSContainer mediaContainer = fileStorage.getMediaContainer(media);
        VFSManager.copyContent(artefactFolder, mediaContainer);
    }
    return media;
}
Also used : VFSContainer(org.olat.core.util.vfs.VFSContainer) Media(org.olat.modules.portfolio.Media) VFSItem(org.olat.core.util.vfs.VFSItem) SystemItemFilter(org.olat.core.util.vfs.filters.SystemItemFilter) File(java.io.File)

Example 13 with Media

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

the class ImageMediaEditorController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    Media media = mediaPart.getMedia();
    File mediaDir = new File(FolderConfig.getCanonicalRoot(), media.getStoragePath());
    File mediaFile = new File(mediaDir, media.getRootFilename());
    ImageFormItem imageEl = new ImageFormItem(ureq.getUserSession(), "image");
    imageEl.setMedia(mediaFile);
    formLayout.add("image", imageEl);
    alignmentEl = uifactory.addDropdownSingleselect("alignment", null, formLayout, alignmentKeys, alignmentKeys, null);
    alignmentEl.addActionListener(FormEvent.ONCHANGE);
    if (StringHelper.containsNonWhitespace(mediaPart.getLayoutOptions())) {
        for (String alignmentKey : alignmentKeys) {
            if (mediaPart.getLayoutOptions().contains(alignmentKey)) {
                alignmentEl.select(alignmentKey, true);
            }
        }
    }
}
Also used : ImageFormItem(org.olat.core.gui.components.image.ImageFormItem) Media(org.olat.modules.portfolio.Media) File(java.io.File)

Example 14 with Media

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

the class MediaDAOTest method usedInBinders.

@Test
public void usedInBinders() {
    Identity author = JunitTestHelper.createAndPersistIdentityAsRndUser("pf-media-2");
    Binder binder = portfolioService.createNewBinder("Binder p2", "A binder with 2 page", null, author);
    Section section = binderDao.createSection("Section", "First section", null, null, binder);
    dbInstance.commitAndCloseSession();
    Section reloadedSection = binderDao.loadSectionByKey(section.getKey());
    Page page = pageDao.createAndPersist("Page 1", "A page with content.", null, null, true, reloadedSection, null);
    Media media = mediaDao.createMedia("Media", "Binder", "Une citation sur les classeurs", TextHandler.TEXT_MEDIA, "[Media:0]", null, 10, author);
    dbInstance.commitAndCloseSession();
    MediaPart mediaPart = new MediaPart();
    mediaPart.setMedia(media);
    PageBody reloadedBody = pageDao.loadPageBodyByKey(page.getBody().getKey());
    pageDao.persistPart(reloadedBody, mediaPart);
    dbInstance.commitAndCloseSession();
    // reload
    List<BinderPageUsage> binders = mediaDao.usedInBinders(media);
    Assert.assertNotNull(binders);
    Assert.assertEquals(1, binders.size());
    Assert.assertTrue(binders.get(0).getBinderKey().equals(binder.getKey()));
}
Also used : Binder(org.olat.modules.portfolio.Binder) MediaPart(org.olat.modules.portfolio.model.MediaPart) BinderPageUsage(org.olat.modules.portfolio.model.BinderPageUsage) Media(org.olat.modules.portfolio.Media) Page(org.olat.modules.portfolio.Page) Identity(org.olat.core.id.Identity) Section(org.olat.modules.portfolio.Section) PageBody(org.olat.modules.portfolio.PageBody) Test(org.junit.Test)

Example 15 with Media

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

the class MediaDAO method deleteMedia.

public void deleteMedia(Media media) {
    if (StringHelper.containsNonWhitespace(media.getRootFilename())) {
        VFSContainer container = fileStorage.getMediaContainer(media);
        VFSItem item = container.resolve(media.getRootFilename());
        if (item instanceof VFSLeaf) {
            ((VFSLeaf) item).delete();
        }
    }
    Media reloadedMedia = dbInstance.getCurrentEntityManager().getReference(MediaImpl.class, media.getKey());
    dbInstance.getCurrentEntityManager().remove(reloadedMedia);
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) Media(org.olat.modules.portfolio.Media) VFSItem(org.olat.core.util.vfs.VFSItem)

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