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());
}
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());
}
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());
}
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);
}
}
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;
}
Aggregations