use of org.olat.core.util.vfs.filters.SystemItemFilter in project openolat by klemens.
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());
}
use of org.olat.core.util.vfs.filters.SystemItemFilter in project openolat by klemens.
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.util.vfs.filters.SystemItemFilter in project openolat by klemens.
the class LinkFileCombiCalloutController method doOpenFileChanger.
public void doOpenFileChanger(UserRequest ureq, String tool) {
// close callout and open appropriate file changer controller
calloutCtr.deactivate();
Controller toolCtr = null;
if (tool.equals("chooseLink")) {
VFSItemFilter filter = new SystemItemFilter();
FileChooserController fileChooserCtr = FileChooserUIFactory.createFileChooserController(ureq, getWindowControl(), baseContainer, filter, true);
fileChooserCtr.setShowTitle(true);
fileChooserCtr.selectPath(relFilePath);
toolCtr = fileChooserCtr;
}
if (tool.equals("createLink")) {
String folderPath = null;
if (StringHelper.containsNonWhitespace(relFilePath)) {
// remove file name from relFilePath to represent directory path
folderPath = relFilePath.substring(0, relFilePath.lastIndexOf("/"));
}
toolCtr = new FileCreatorController(ureq, getWindowControl(), baseContainer, folderPath);
}
if (tool.equals("uploadLink")) {
long quotaLeftKB = VFSManager.getQuotaLeftKB(baseContainer);
String folderPath = null;
if (StringHelper.containsNonWhitespace(relFilePath)) {
// remove file name from relFilePath to represent directory path
folderPath = relFilePath.substring(0, relFilePath.lastIndexOf("/"));
}
toolCtr = new FileUploadController(getWindowControl(), baseContainer, ureq, quotaLeftKB, quotaLeftKB, null, false, true, false, false, true, true, folderPath);
}
displayModal(toolCtr);
}
use of org.olat.core.util.vfs.filters.SystemItemFilter in project openolat by klemens.
the class GTACourseNode method archiveNodeData.
@Override
public boolean archiveNodeData(Locale locale, ICourse course, ArchiveOptions options, ZipOutputStream exportStream, String charset) {
final GTAManager gtaManager = CoreSpringFactory.getImpl(GTAManager.class);
final ModuleConfiguration config = getModuleConfiguration();
String prefix;
if (GTAType.group.name().equals(config.getStringValue(GTACourseNode.GTASK_TYPE))) {
prefix = "grouptask_";
} else {
prefix = "ita_";
}
String dirName = prefix + StringHelper.transformDisplayNameToFileSystemName(getShortName()) + "_" + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis()));
TaskList taskList = gtaManager.getTaskList(course.getCourseEnvironment().getCourseGroupManager().getCourseEntry(), this);
// save assessment datas
List<Identity> users = null;
if (config.getBooleanSafe(GTASK_GRADING)) {
users = ScoreAccountingHelper.loadUsers(course.getCourseEnvironment(), options);
String courseTitle = course.getCourseTitle();
String fileName = ExportUtil.createFileNameWithTimeStamp(courseTitle, "xlsx");
List<AssessableCourseNode> nodes = Collections.<AssessableCourseNode>singletonList(this);
try (OutputStream out = new ShieldOutputStream(exportStream)) {
exportStream.putNextEntry(new ZipEntry(dirName + "/" + fileName));
ScoreAccountingHelper.createCourseResultsOverviewXMLTable(users, nodes, course, locale, out);
exportStream.closeEntry();
} catch (Exception e) {
log.error("", e);
}
}
// copy tasks
if (taskList != null) {
if (GTAType.group.name().equals(config.getStringValue(GTACourseNode.GTASK_TYPE))) {
List<BusinessGroup> selectedGroups;
if (options != null && options.getGroup() != null) {
selectedGroups = Collections.singletonList(options.getGroup());
} else {
selectedGroups = gtaManager.getBusinessGroups(this);
}
for (BusinessGroup businessGroup : selectedGroups) {
archiveNodeData(course, businessGroup, taskList, dirName, exportStream);
}
} else {
if (users == null) {
users = ScoreAccountingHelper.loadUsers(course.getCourseEnvironment(), options);
}
Set<Identity> uniqueUsers = new HashSet<>(users);
for (Identity user : uniqueUsers) {
archiveNodeData(course, user, taskList, dirName, exportStream);
}
}
}
// copy solutions
if (config.getBooleanSafe(GTACourseNode.GTASK_SAMPLE_SOLUTION)) {
VFSContainer solutions = gtaManager.getSolutionsContainer(course.getCourseEnvironment(), this);
if (solutions.exists()) {
String solutionDirName = dirName + "/solutions";
for (VFSItem solution : solutions.getItems(new SystemItemFilter())) {
ZipUtil.addToZip(solution, solutionDirName, exportStream);
}
}
}
return true;
}
use of org.olat.core.util.vfs.filters.SystemItemFilter in project openolat by klemens.
the class VersionsFileManager method countDirectories.
private int countDirectories(VFSContainer container) {
// itself
int count = 1;
List<VFSItem> children = container.getItems(new SystemItemFilter());
for (VFSItem child : children) {
if (child instanceof VFSContainer) {
count += countDirectories((VFSContainer) child);
}
}
return count;
}
Aggregations