Search in sources :

Example 71 with VFSContainer

use of org.olat.core.util.vfs.VFSContainer 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)

Example 72 with VFSContainer

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

the class VersionManagerTest method testDeleteRevisions_withMissingRevisionFile.

/**
 * The test create an original file and 5 versions. It manually
 * delete the physical back up file. We delete the versions
 * of the orginal, 1 and 2. At the end, there is only version 4
 * and 5.
 *
 * @throws IOException
 */
@Test
public void testDeleteRevisions_withMissingRevisionFile() 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 = new ByteArrayInputStream("Hello original".getBytes());
    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 = new ByteArrayInputStream("Hello version 1".getBytes());
    versionedFile.getVersions().addVersion(id2, "Version 1", in1);
    IOUtils.closeQuietly(in1);
    // save a second version
    InputStream in2 = new ByteArrayInputStream("Hello version 2".getBytes());
    versionedFile.getVersions().addVersion(id2, "Version 2", in2);
    IOUtils.closeQuietly(in2);
    // save a third version
    InputStream in3 = new ByteArrayInputStream("Hello version 3".getBytes());
    versionedFile.getVersions().addVersion(id2, "Version 3", in3);
    IOUtils.closeQuietly(in3);
    // save a fourth version
    InputStream in4 = new ByteArrayInputStream("Hello version 4".getBytes());
    versionedFile.getVersions().addVersion(id2, "Version 4", in4);
    IOUtils.closeQuietly(in4);
    // save a fourth version
    InputStream in5 = new ByteArrayInputStream("Hello version 5".getBytes());
    versionedFile.getVersions().addVersion(id2, "Version 5", in5);
    IOUtils.closeQuietly(in5);
    // delete a specific
    VFSRevision rev3 = versionedFile.getVersions().getRevisions().get(3);
    RevisionFileImpl toDeleteVersionImpl = (RevisionFileImpl) rev3;
    VFSContainer versionContainerAlt = versionManager.getCanonicalVersionFolder(rootTest, false);
    VFSItem itemToDelete = versionContainerAlt.resolve(toDeleteVersionImpl.getFilename());
    itemToDelete.deleteSilently();
    // delete revisions
    List<VFSRevision> toDelete = new ArrayList<>(versionedFile.getVersions().getRevisions().subList(0, 3));
    versionManager.deleteRevisions(versionedFile, toDelete);
    // 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());
    VFSRevision revision = revisions.get(0);
    Assert.assertEquals("Version 4", revision.getComment());
    Assert.assertEquals("Version 5", reloadedVersionedFile.getVersions().getComment());
    // 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) ArrayList(java.util.ArrayList) VFSItem(org.olat.core.util.vfs.VFSItem) SystemItemFilter(org.olat.core.util.vfs.filters.SystemItemFilter) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Example 73 with VFSContainer

use of org.olat.core.util.vfs.VFSContainer 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 74 with VFSContainer

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

the class PFManagerTest method provideParticipantContainer.

@Test
public void provideParticipantContainer() {
    // prepare
    Identity initialAuthor = JunitTestHelper.createAndPersistIdentityAsRndUser("check-15");
    IdentityEnvironment ienv = new IdentityEnvironment();
    ienv.setIdentity(initialAuthor);
    PFCourseNode pfNode = new PFCourseNode();
    pfNode.getModuleConfiguration().setBooleanEntry(PFCourseNode.CONFIG_KEY_COACHBOX, true);
    pfNode.getModuleConfiguration().setBooleanEntry(PFCourseNode.CONFIG_KEY_PARTICIPANTBOX, true);
    // import "Demo course" into the bcroot_junittest
    RepositoryEntry entry = JunitTestHelper.deployDemoCourse(initialAuthor);
    Long resourceableId = entry.getOlatResource().getResourceableId();
    ICourse course = CourseFactory.loadCourse(resourceableId);
    UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
    Identity check3 = JunitTestHelper.createAndPersistIdentityAsRndUser("check-3");
    repositoryEntryRelationDao.addRole(check3, entry, GroupRoles.participant.name());
    VFSContainer vfsContainer = pfManager.provideCoachOrParticipantContainer(pfNode, userCourseEnv, check3, false);
    Assert.assertNotNull(vfsContainer);
    Assert.assertTrue(vfsContainer.exists());
}
Also used : PFCourseNode(org.olat.course.nodes.PFCourseNode) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) VFSContainer(org.olat.core.util.vfs.VFSContainer) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) Test(org.junit.Test)

Example 75 with VFSContainer

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

the class PFManagerTest method provideCoachContainer.

@Test
public void provideCoachContainer() {
    // prepare
    Identity initialAuthor = JunitTestHelper.createAndPersistIdentityAsRndUser("check-16");
    IdentityEnvironment ienv = new IdentityEnvironment();
    ienv.setIdentity(initialAuthor);
    PFCourseNode pfNode = new PFCourseNode();
    pfNode.getModuleConfiguration().setBooleanEntry(PFCourseNode.CONFIG_KEY_COACHBOX, true);
    pfNode.getModuleConfiguration().setBooleanEntry(PFCourseNode.CONFIG_KEY_PARTICIPANTBOX, true);
    // import "Demo course" into the bcroot_junittest
    RepositoryEntry entry = JunitTestHelper.deployDemoCourse(initialAuthor);
    Long resourceableId = entry.getOlatResource().getResourceableId();
    ICourse course = CourseFactory.loadCourse(resourceableId);
    UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
    Identity check4 = JunitTestHelper.createAndPersistIdentityAsRndUser("check-4");
    repositoryEntryRelationDao.addRole(check4, entry, GroupRoles.coach.name());
    VFSContainer vfsContainer = pfManager.provideCoachOrParticipantContainer(pfNode, userCourseEnv, check4, false);
    Assert.assertNotNull(vfsContainer);
}
Also used : PFCourseNode(org.olat.course.nodes.PFCourseNode) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) VFSContainer(org.olat.core.util.vfs.VFSContainer) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) Test(org.junit.Test)

Aggregations

VFSContainer (org.olat.core.util.vfs.VFSContainer)962 VFSItem (org.olat.core.util.vfs.VFSItem)364 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)338 File (java.io.File)170 Test (org.junit.Test)136 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)86 Identity (org.olat.core.id.Identity)86 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)76 RepositoryEntry (org.olat.repository.RepositoryEntry)76 IOException (java.io.IOException)74 InputStream (java.io.InputStream)64 ArrayList (java.util.ArrayList)64 Date (java.util.Date)60 URI (java.net.URI)56 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)42 OutputStream (java.io.OutputStream)40 HttpResponse (org.apache.http.HttpResponse)38 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)34 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)34 BlogFileResource (org.olat.fileresource.types.BlogFileResource)34