use of org.olat.core.util.vfs.filters.SystemItemFilter 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.filters.SystemItemFilter in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class CourseResourceFolderWebService method getFiles.
public Response getFiles(Long courseId, List<PathSegment> path, FolderType type, UriInfo uriInfo, HttpServletRequest httpRequest, Request request) {
if (!isAuthor(httpRequest)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
ICourse course = CoursesWebService.loadCourse(courseId);
if (course == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
VFSContainer container = null;
RepositoryEntry re = null;
switch(type) {
case COURSE_FOLDER:
container = course.getCourseFolderContainer();
break;
case SHARED_FOLDER:
{
container = null;
String sfSoftkey = course.getCourseConfig().getSharedFolderSoftkey();
OLATResource sharedResource = CoreSpringFactory.getImpl(RepositoryService.class).loadRepositoryEntryResourceBySoftKey(sfSoftkey);
if (sharedResource != null) {
re = CoreSpringFactory.getImpl(RepositoryService.class).loadByResourceKey(sharedResource.getKey());
container = SharedFolderManager.getInstance().getNamedSharedFolder(re, true);
CourseConfig courseConfig = course.getCourseConfig();
if (courseConfig.isSharedFolderReadOnlyMount()) {
container.setLocalSecurityCallback(new ReadOnlyCallback());
}
}
break;
}
}
if (container == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
VFSLeaf leaf = null;
for (PathSegment seg : path) {
VFSItem item = container.resolve(seg.getPath());
if (item instanceof VFSLeaf) {
leaf = (VFSLeaf) item;
break;
} else if (item instanceof VFSContainer) {
container = (VFSContainer) item;
}
}
if (leaf != null) {
Date lastModified = new Date(leaf.getLastModified());
Response.ResponseBuilder response = request.evaluatePreconditions(lastModified);
if (response == null) {
String mimeType = WebappHelper.getMimeType(leaf.getName());
if (mimeType == null)
mimeType = MediaType.APPLICATION_OCTET_STREAM;
response = Response.ok(leaf.getInputStream(), mimeType).lastModified(lastModified).cacheControl(cc);
}
return response.build();
}
List<VFSItem> items = container.getItems(new SystemItemFilter());
int count = 0;
LinkVO[] links = new LinkVO[items.size()];
for (VFSItem item : items) {
UriBuilder baseUriBuilder = uriInfo.getBaseUriBuilder();
UriBuilder repoUri = baseUriBuilder.path(CourseResourceFolderWebService.class).path("files");
if (type.equals(FolderType.SHARED_FOLDER) && re != null) {
repoUri = baseUriBuilder.replacePath("restapi").path(SharedFolderWebService.class).path(re.getKey().toString()).path("files");
}
for (PathSegment pathSegment : path) {
repoUri.path(pathSegment.getPath());
}
String uri = repoUri.path(item.getName()).build(courseId).toString();
links[count++] = new LinkVO("self", uri, item.getName());
}
return Response.ok(links).build();
}
use of org.olat.core.util.vfs.filters.SystemItemFilter in project OpenOLAT by OpenOLAT.
the class ForumMediaHandler method createMedia.
@Override
public Media createMedia(AbstractArtefact artefact) {
VFSContainer artefactFolder = oldPortfolioManager.getArtefactContainer(artefact);
String businessPath = artefact.getBusinessPath();
if (businessPath == null) {
businessPath = "[PortfolioV2:0][MediaCenter:0]";
}
Media media = mediaDao.createMedia(artefact.getTitle(), artefact.getDescription(), null, FORUM_HANDLER, businessPath, artefact.getKey().toString(), artefact.getSignature(), artefact.getAuthor());
ThreadLocalUserActivityLogger.log(PortfolioLoggingAction.PORTFOLIO_MEDIA_ADDED, getClass(), LoggingResourceable.wrap(media));
List<VFSItem> items = artefactFolder.getItems(new SystemItemFilter());
if (items.size() > 0) {
File mediaDir = fileStorage.generateMediaSubDirectory(media);
String storagePath = fileStorage.getRelativePath(mediaDir);
mediaDao.updateStoragePath(media, storagePath, null);
VFSContainer mediaContainer = fileStorage.getMediaContainer(media);
VFSManager.copyContent(artefactFolder, mediaContainer);
}
return media;
}
use of org.olat.core.util.vfs.filters.SystemItemFilter in project OpenOLAT by OpenOLAT.
the class BCCourseNode method createPeekViewRunController.
/**
* @see org.olat.course.nodes.GenericCourseNode#createPeekViewRunController(org.olat.core.gui.UserRequest,
* org.olat.core.gui.control.WindowControl,
* org.olat.course.run.userview.UserCourseEnvironment,
* org.olat.course.run.userview.NodeEvaluation)
*/
@Override
public Controller createPeekViewRunController(UserRequest ureq, WindowControl wControl, UserCourseEnvironment userCourseEnv, NodeEvaluation ne) {
if (ne.isAtLeastOneAccessible()) {
updateModuleConfigDefaults(false);
// Create a folder peekview controller that shows the latest two entries
VFSContainer rootFolder = null;
if (getModuleConfiguration().getBooleanSafe(BCCourseNodeEditController.CONFIG_AUTO_FOLDER)) {
rootFolder = getNodeFolderContainer(this, userCourseEnv.getCourseEnvironment());
} else {
String subPath = getModuleConfiguration().getStringValue(BCCourseNodeEditController.CONFIG_SUBPATH, "");
VFSItem item = userCourseEnv.getCourseEnvironment().getCourseFolderContainer().resolve(subPath);
if (item instanceof VFSContainer) {
rootFolder = (VFSContainer) item;
}
}
if (rootFolder == null) {
return super.createPeekViewRunController(ureq, wControl, userCourseEnv, ne);
}
rootFolder.setDefaultItemFilter(new SystemItemFilter());
return new BCPeekviewController(ureq, wControl, rootFolder, getIdent(), 4);
} else {
// use standard peekview
return super.createPeekViewRunController(ureq, wControl, userCourseEnv, ne);
}
}
Aggregations