Search in sources :

Example 46 with VFSLeaf

use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.

the class BinderListController method doOpenBinder.

protected BinderController doOpenBinder(UserRequest ureq, BinderRef row) {
    SynchedBinder binder = portfolioService.loadAndSyncBinder(row);
    if (binder.isChanged()) {
        showInfo("warning.binder.synched");
    }
    BinderController selectedBinderCtrl = doOpenBinder(ureq, binder.getBinder());
    if (row instanceof BinderRow) {
        VFSLeaf image = portfolioService.getPosterImageLeaf(binder.getBinder());
        ((BinderRow) row).setBackgroundImage(image);
    }
    return selectedBinderCtrl;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) BinderRow(org.olat.modules.portfolio.ui.model.BinderRow) SynchedBinder(org.olat.modules.portfolio.model.SynchedBinder)

Example 47 with VFSLeaf

use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.

the class BinderListController method forgePortfolioRow.

protected BinderRow forgePortfolioRow(BinderStatistics binderRow) {
    String openLinkId = "open_" + (++counter);
    FormLink openLink = uifactory.addFormLink(openLinkId, "open", "open", null, flc, Link.LINK);
    openLink.setIconRightCSS("o_icon o_icon_start");
    VFSLeaf image = portfolioService.getPosterImageLeaf(binderRow);
    BinderRow row = new BinderRow(binderRow, image, openLink);
    openLink.setUserObject(row);
    return row;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) BinderRow(org.olat.modules.portfolio.ui.model.BinderRow) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink)

Example 48 with VFSLeaf

use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.

the class FileHandler method getThumbnail.

@Override
public VFSLeaf getThumbnail(MediaLight media, Size size) {
    String storagePath = media.getStoragePath();
    VFSLeaf thumbnail = null;
    if (StringHelper.containsNonWhitespace(storagePath)) {
        VFSContainer storageContainer = fileStorage.getMediaContainer(media);
        VFSItem item = storageContainer.resolve(media.getRootFilename());
        if (item instanceof VFSLeaf) {
            VFSLeaf leaf = (VFSLeaf) item;
            if (leaf instanceof MetaTagged) {
                MetaInfo metaInfo = ((MetaTagged) leaf).getMetaInfo();
                thumbnail = metaInfo.getThumbnail(size.getHeight(), size.getWidth(), true);
            }
        }
    }
    return thumbnail;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) VFSItem(org.olat.core.util.vfs.VFSItem)

Example 49 with VFSLeaf

use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.

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)

Example 50 with VFSLeaf

use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.

the class VersionManagerTest method testDeleteRevisions_withSameFile.

/**
 * The test create an original file and 3 revisions with exactly
 * the same content. We delete the original and the first version.
 * We check that version 2 and 3 survives and that the file exists.
 *
 * @throws IOException
 */
@Test
public void testDeleteRevisions_withSameFile() throws IOException {
    OlatRootFolderImpl rootTest = new OlatRootFolderImpl("/ver-" + UUID.randomUUID(), null);
    String filename = getRandomName();
    VFSLeaf file = rootTest.createChildLeaf(filename);
    OutputStream out = file.getOutputStream(false);
    InputStream in = VersionManagerTest.class.getResourceAsStream("test.txt");
    int byteCopied = IOUtils.copy(in, out);
    IOUtils.closeQuietly(in);
    assertFalse(byteCopied == 0);
    assertTrue(file instanceof Versionable);
    // save a first version
    Versionable versionedFile = (Versionable) file;
    InputStream in1 = VersionManagerTest.class.getResourceAsStream("test.txt");
    versionedFile.getVersions().addVersion(id2, "Version 1", in1);
    IOUtils.closeQuietly(in1);
    // save a second version
    InputStream in2 = VersionManagerTest.class.getResourceAsStream("test.txt");
    versionedFile.getVersions().addVersion(id2, "Version 2", in2);
    IOUtils.closeQuietly(in2);
    // save a third version
    InputStream in3 = VersionManagerTest.class.getResourceAsStream("test.txt");
    versionedFile.getVersions().addVersion(id2, "Version 3", in2);
    IOUtils.closeQuietly(in3);
    // delete revisions
    versionManager.deleteRevisions(versionedFile, versionedFile.getVersions().getRevisions().subList(0, 2));
    // check number of versions
    VFSItem reloadFile = rootTest.resolve(filename);
    assertTrue(reloadFile instanceof Versionable);
    Versionable reloadedVersionedFile = (Versionable) reloadFile;
    List<VFSRevision> revisions = reloadedVersionedFile.getVersions().getRevisions();
    Assert.assertNotNull(revisions);
    Assert.assertEquals(1, revisions.size());
    // check surviving versions
    Assert.assertEquals("Version 2", revisions.get(0).getComment());
    Assert.assertEquals("Version 3", reloadedVersionedFile.getVersions().getComment());
    // check that the last backup file exists
    RevisionFileImpl revision2 = (RevisionFileImpl) revisions.get(0);
    VFSLeaf revision2File = revision2.getFile();
    Assert.assertNotNull(revision2File);
    Assert.assertTrue(revision2File.exists());
    // check if there is only one backup file
    VFSContainer versionContainer = versionManager.getCanonicalVersionFolder(file.getParentContainer(), false);
    Assert.assertNotNull(versionContainer);
    List<VFSItem> items = versionContainer.getItems(new SystemItemFilter());
    Assert.assertNotNull(items);
    Assert.assertEquals(2, items.size());
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) SystemItemFilter(org.olat.core.util.vfs.filters.SystemItemFilter) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) Test(org.junit.Test)

Aggregations

VFSLeaf (org.olat.core.util.vfs.VFSLeaf)642 VFSContainer (org.olat.core.util.vfs.VFSContainer)338 VFSItem (org.olat.core.util.vfs.VFSItem)280 File (java.io.File)114 InputStream (java.io.InputStream)96 IOException (java.io.IOException)92 Test (org.junit.Test)86 ArrayList (java.util.ArrayList)72 OutputStream (java.io.OutputStream)60 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)58 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)58 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)58 Identity (org.olat.core.id.Identity)54 LocalFileImpl (org.olat.core.util.vfs.LocalFileImpl)52 VFSMediaResource (org.olat.core.util.vfs.VFSMediaResource)46 URL (java.net.URL)40 Date (java.util.Date)40 RepositoryEntry (org.olat.repository.RepositoryEntry)36 URI (java.net.URI)34 MediaResource (org.olat.core.gui.media.MediaResource)34