use of org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl in project OpenOLAT by OpenOLAT.
the class ConvertToGTACourseNode method convertDropbox.
private void convertDropbox(TaskList taskList, TACourseNode sourceNode, GTACourseNode gtaNode, CourseEnvironment courseEnv) {
String dropbox = DropboxController.getDropboxPathRelToFolderRoot(courseEnv, sourceNode);
OlatRootFolderImpl dropboxContainer = new OlatRootFolderImpl(dropbox, null);
for (VFSItem userDropbox : dropboxContainer.getItems()) {
if (userDropbox instanceof VFSContainer) {
VFSContainer userDropContainer = (VFSContainer) userDropbox;
String username = userDropContainer.getName();
Identity assessedIdentity = securityManager.findIdentityByName(username);
if (assessedIdentity != null) {
VFSContainer sumbitContainer = gtaManager.getSubmitContainer(courseEnv, gtaNode, assessedIdentity);
boolean dropped = false;
for (VFSItem dropppedItem : userDropContainer.getItems()) {
if (dropppedItem instanceof VFSLeaf) {
VFSLeaf submittedDocument = sumbitContainer.createChildLeaf(dropppedItem.getName());
VFSManager.copyContent((VFSLeaf) dropppedItem, submittedDocument);
convertMetada(userDropContainer, sumbitContainer, dropppedItem.getName(), null, null);
dropped = true;
}
}
if (dropped) {
setTaskStatus(taskList, assessedIdentity, TaskProcess.submit, gtaNode);
}
}
}
}
}
use of org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl in project OpenOLAT by OpenOLAT.
the class BinderTemplateHandler method importResource.
@Override
public RepositoryEntry importResource(Identity initialAuthor, String initialAuthorAlt, String displayname, String description, boolean withReferences, Locale locale, File file, String filename) {
RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
PortfolioService portfolioService = CoreSpringFactory.getImpl(PortfolioService.class);
try {
// create resource
OLATResource resource = portfolioService.createBinderTemplateResource();
OlatRootFolderImpl fResourceRootContainer = FileResourceManager.getInstance().getFileResourceRootImpl(resource);
File fResourceFileroot = fResourceRootContainer.getBasefile();
File zipRoot = new File(fResourceFileroot, FileResourceManager.ZIPDIR);
FileResource.copyResource(file, filename, zipRoot);
// create repository entry
RepositoryEntry re = repositoryService.create(initialAuthor, initialAuthorAlt, "", displayname, description, resource, RepositoryEntry.ACC_OWNERS);
// import binder
File binderFile = new File(zipRoot, BinderTemplateResource.BINDER_XML);
Binder transientBinder = BinderXStream.fromPath(binderFile.toPath());
File posterImage = null;
if (StringHelper.containsNonWhitespace(transientBinder.getImagePath())) {
posterImage = new File(zipRoot, transientBinder.getImagePath());
}
portfolioService.importBinder(transientBinder, re, posterImage);
RepositoryEntryImportExport rei = new RepositoryEntryImportExport(re, zipRoot);
if (rei.anyExportedPropertiesAvailable()) {
re = rei.importContent(re, fResourceRootContainer.createChildContainer("media"));
}
// delete the imported files
FileUtils.deleteDirsAndFiles(zipRoot, true, true);
return re;
} catch (IOException e) {
log.error("", e);
return null;
}
}
use of org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl 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());
}
use of org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl in project OpenOLAT by OpenOLAT.
the class VersionManagerTest method testAuthorsAndCreators.
@Test
public void testAuthorsAndCreators() throws IOException {
// create a file
OlatRootFolderImpl rootTest = new OlatRootFolderImpl("/test2", 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);
assertTrue(file instanceof MetaTagged);
// set the author
MetaTagged metaTagged = (MetaTagged) file;
MetaInfo metaInfo = metaTagged.getMetaInfo();
metaInfo.setAuthor(id1);
metaInfo.setCreator(id1.getName());
metaInfo.write();
// save a first version -> id2
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 -> id1
Versionable versionedFile2 = (Versionable) file;
InputStream in2 = new ByteArrayInputStream("Hello version 2".getBytes());
versionedFile2.getVersions().addVersion(id1, "Version 2", in2);
IOUtils.closeQuietly(in2);
// save a third version -> id2
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 = versionManager.createVersionsFor((VFSLeaf) retrievedFile);
List<VFSRevision> revisions = versions.getRevisions();
assertNotNull(revisions);
assertEquals(3, revisions.size());
assertTrue(retrievedFile instanceof MetaTagged);
VFSRevision revision0 = revisions.get(0);
// we don't set an author for the original file
assertEquals(id1.getName(), revision0.getAuthor());
VFSRevision revision1 = revisions.get(1);
assertEquals(id2.getName(), revision1.getAuthor());
VFSRevision revision2 = revisions.get(2);
assertEquals(id1.getName(), revision2.getAuthor());
// current
assertEquals(id2.getName(), versions.getAuthor());
}
use of org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl in project OpenOLAT by OpenOLAT.
the class VersionManagerTest method testCircleMove.
/**
* Create a file with 2 revision, move it to another name, move it to the primitive name:
* File A, change file A, change file A, move to file B, move to file A
* @throws IOException
*/
@Test
public void testCircleMove() throws IOException {
// create a file A
OlatRootFolderImpl rootTest = new OlatRootFolderImpl("/test2", 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);
assertTrue(file instanceof MetaTagged);
// set the author
MetaTagged metaTagged = (MetaTagged) file;
MetaInfo metaInfo = metaTagged.getMetaInfo();
metaInfo.setAuthor(id1);
metaInfo.setCreator(id1.getName());
metaInfo.write();
// save a first version of file A -> id2
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 of file A -> id1
Versionable versionedFile2 = (Versionable) file;
InputStream in2 = new ByteArrayInputStream("Hello version 2".getBytes());
versionedFile2.getVersions().addVersion(id1, "Version 2", in2);
IOUtils.closeQuietly(in2);
// move the file A -> file B
VFSLeaf retrievedLeaf = (VFSLeaf) rootTest.resolve(filename);
String copyFilename = getRandomName();
VFSLeaf copyFile = rootTest.createChildLeaf(copyFilename);
OutputStream copyOutput = copyFile.getOutputStream(false);
InputStream copyInput = retrievedLeaf.getInputStream();
IOUtils.copy(copyInput, copyOutput);
IOUtils.closeQuietly(copyOutput);
IOUtils.closeQuietly(copyInput);
// move the revisions
VersionsManager.getInstance().move(retrievedLeaf, copyFile, id2);
// move the file B -> file A
VFSLeaf retrievedCopyLeaf = (VFSLeaf) rootTest.resolve(copyFilename);
VFSLeaf originalFile = (VFSLeaf) rootTest.resolve(filename);
OutputStream originalOutput = originalFile.getOutputStream(false);
InputStream retrievedCopyInput = retrievedCopyLeaf.getInputStream();
IOUtils.copy(retrievedCopyInput, originalOutput);
IOUtils.closeQuietly(originalOutput);
IOUtils.closeQuietly(retrievedCopyInput);
// move the revisions
VersionsManager.getInstance().move(retrievedCopyLeaf, originalFile, id2);
// check if the revisions are moved
VFSLeaf retirevedOriginalFile = (VFSLeaf) rootTest.resolve(filename);
assertTrue(retirevedOriginalFile instanceof Versionable);
Versions versions = VersionsFileManager.getInstance().createVersionsFor(retirevedOriginalFile);
List<VFSRevision> revisions = versions.getRevisions();
assertNotNull(revisions);
assertEquals(2, revisions.size());
VFSRevision revision0 = revisions.get(0);
// we don't set an author for the original file
assertEquals(id1.getName(), revision0.getAuthor());
VFSRevision revision1 = revisions.get(1);
assertEquals(id2.getName(), revision1.getAuthor());
// current
assertEquals(id1.getName(), versions.getCreator());
assertEquals(id2.getName(), versions.getAuthor());
}
Aggregations