Search in sources :

Example 56 with VFSLeaf

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

the class VersionManagerTest method testVersionChecksum.

@Test
public void testVersionChecksum() 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);
    // 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());
    // 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(3, revisions.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)

Example 57 with VFSLeaf

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

the class VersionManagerTest method testVersionManager.

@Test
public void testVersionManager() throws IOException {
    // create a file
    OlatRootFolderImpl rootTest = new OlatRootFolderImpl("/test", 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 versionedFile1 = (Versionable) file;
    InputStream in1 = new ByteArrayInputStream("Hello version 1".getBytes());
    versionedFile1.getVersions().addVersion(id2, "Version 1", in1);
    IOUtils.closeQuietly(in1);
    // save a second version
    Versionable versionedFile2 = (Versionable) file;
    InputStream in2 = new ByteArrayInputStream("Hello version 2".getBytes());
    versionedFile2.getVersions().addVersion(id2, "Version 2", in2);
    IOUtils.closeQuietly(in2);
    // save a third version
    Versionable versionedFile3 = (Versionable) file;
    InputStream in3 = new ByteArrayInputStream("Hello version 3".getBytes());
    versionedFile3.getVersions().addVersion(id2, "Version 3", in3);
    IOUtils.closeQuietly(in3);
    // make the checks
    VFSItem retrievedFile = rootTest.resolve(filename);
    assertTrue(retrievedFile instanceof Versionable);
    Versions versions = VersionsFileManager.getInstance().createVersionsFor((VFSLeaf) retrievedFile);
    List<VFSRevision> revisions = versions.getRevisions();
    assertNotNull(revisions);
    assertEquals(3, revisions.size());
    VFSRevision revision0 = revisions.get(0);
    // we don't set an author for the original file
    assertEquals("-", revision0.getAuthor());
    VFSRevision revision1 = revisions.get(1);
    assertEquals(id2.getName(), revision1.getAuthor());
    VFSRevision revision2 = revisions.get(2);
    assertEquals(id2.getName(), revision2.getAuthor());
    // check the comments
    assertNull(revision0.getComment());
    assertEquals("Version 1", revision1.getComment());
    assertEquals("Version 2", revision2.getComment());
    assertEquals("Version 3", versions.getComment());
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) VFSItem(org.olat.core.util.vfs.VFSItem) Test(org.junit.Test)

Example 58 with VFSLeaf

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

the class CertificatesManagerTest method createCertificate.

@Test
public void createCertificate() throws URISyntaxException {
    Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("cer-1");
    RepositoryEntry entry = JunitTestHelper.deployBasicCourse(identity);
    dbInstance.commitAndCloseSession();
    CertificateInfos certificateInfos = new CertificateInfos(identity, null, null);
    Certificate certificate = certificatesManager.generateCertificate(certificateInfos, entry, null, false);
    Assert.assertNotNull(certificate);
    Assert.assertNotNull(certificate.getKey());
    Assert.assertNotNull(certificate.getUuid());
    Assert.assertEquals(entry.getOlatResource().getKey(), certificate.getArchivedResourceKey());
    // check if the pdf exists / flush cache, reload the entry with the updated path
    dbInstance.commitAndCloseSession();
    waitCertificate(certificate.getKey());
    Certificate reloadCertificate = certificatesManager.getCertificateById(certificate.getKey());
    VFSLeaf certificateFile = certificatesManager.getCertificateLeaf(reloadCertificate);
    Assert.assertNotNull(certificateFile);
    Assert.assertTrue(certificateFile.exists());
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) CertificateInfos(org.olat.course.certificate.model.CertificateInfos) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) Certificate(org.olat.course.certificate.Certificate) Test(org.junit.Test)

Example 59 with VFSLeaf

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

the class DialogElementController method doDownload.

private void doDownload(UserRequest ureq) {
    VFSLeaf file = dialogElmsMgr.getDialogLeaf(element);
    if (file != null) {
        ureq.getDispatchResult().setResultingMediaResource(new VFSMediaResource(file));
        ThreadLocalUserActivityLogger.log(CourseLoggingAction.DIALOG_ELEMENT_FILE_DOWNLOADED, getClass(), LoggingResourceable.wrapBCFile(element.getFilename()));
    } else {
        ureq.getDispatchResult().setResultingMediaResource(new NotFoundMediaResource());
        logError("No file to discuss: " + element, null);
    }
}
Also used : NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Example 60 with VFSLeaf

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

the class CPManagerImpl method load.

/**
 * @see org.olat.ims.cp.CPManager#load(org.olat.core.util.vfs.VFSContainer)
 */
public ContentPackage load(VFSContainer directory, OLATResourceable ores) {
    XMLParser parser = new XMLParser();
    ContentPackage cp;
    VFSLeaf file = (VFSLeaf) directory.resolve("imsmanifest.xml");
    if (file != null) {
        try {
            DefaultDocument doc = (DefaultDocument) parser.parse(file.getInputStream(), false);
            cp = new ContentPackage(doc, directory, ores);
            // identifier.
            if (cp.getLastError() == null) {
                if (cp.isOLATContentPackage() && CPCore.OLAT_ORGANIZATION_IDENTIFIER.equals(cp.getFirstOrganizationInManifest().getIdentifier())) {
                    setUniqueOrgaIdentifier(cp);
                }
            }
        } catch (OLATRuntimeException e) {
            cp = new ContentPackage(null, directory, ores);
            logError("Reading imsmanifest failed. Dir: " + directory.getName() + ". Ores: " + ores.getResourceableId(), e);
            cp.setLastError("Exception reading XML for IMS CP: invalid xml-file ( " + directory.getName() + ")");
        }
    } else {
        cp = new ContentPackage(null, directory, ores);
        cp.setLastError("Exception reading XML for IMS CP: IMS-Manifest not found in " + directory.getName());
        logError("IMS manifiest xml couldn't be found in dir " + directory.getName() + ". Ores: " + ores.getResourceableId(), null);
        throw new OLATRuntimeException(CPManagerImpl.class, "The imsmanifest.xml file was not found.", new IOException());
    }
    return cp;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) DefaultDocument(org.dom4j.tree.DefaultDocument) IOException(java.io.IOException) XMLParser(org.olat.core.util.xml.XMLParser)

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