Skip to content
Snippets Groups Projects
Commit c911623a authored by srosse's avatar srosse
Browse files

OO-969: replace properly the list of folders after a timed refresh

parent a096a8a0
No related branches found
No related tags found
No related merge requests found
......@@ -470,7 +470,7 @@ public class WebDAVDispatcherImpl
throws ServletException, IOException {
String path = getRelativePath(req);
if (path.endsWith("/"))
if (path.length() > 1 && path.endsWith("/"))
path = path.substring(0, path.length() - 1);
// Properties which are to be displayed.
......
......@@ -69,6 +69,10 @@ public class MergeSource extends AbstractVirtualContainer {
mergedContainersChildren = new ArrayList<VFSContainer>(2);
}
}
protected void setMergedContainers(List<VFSContainer> mergedContainers) {
this.mergedContainers = mergedContainers;
}
@Override
public boolean exists() {
......@@ -81,8 +85,12 @@ public class MergeSource extends AbstractVirtualContainer {
* @param container
*/
public void addContainer(VFSContainer container) {
addContainerToList(container, mergedContainers);
}
public void addContainerToList(VFSContainer container, List<VFSContainer> containers) {
VFSContainer newContainer = container;
if (isContainerNameTaken(newContainer.getName())) {
if (isContainerNameTaken(newContainer.getName(), containers)) {
String newName = newContainer.getName() + "_" + CodeHelper.getRAMUniqueID();
newContainer = new NamedContainerImpl(newName, container);
}
......@@ -92,7 +100,7 @@ public class MergeSource extends AbstractVirtualContainer {
newContainer.setDefaultItemFilter(defaultFilter);
}
newContainer.setParentContainer(this);
mergedContainers.add(newContainer);
containers.add(newContainer);
}
/**
......@@ -295,14 +303,13 @@ public class MergeSource extends AbstractVirtualContainer {
return rootWriteContainer;
}
private boolean isContainerNameTaken(String containerName) {
for (Iterator<VFSContainer> iter = mergedContainers.iterator(); iter.hasNext();) {
VFSContainer mergedContainer = iter.next();
if (mergedContainer.getName().equals(containerName)) return true;
private boolean isContainerNameTaken(String containerName, List<VFSContainer> containers) {
for (Iterator<VFSContainer> iter = containers.iterator(); iter.hasNext();) {
VFSContainer container = iter.next();
if (container.getName().equals(containerName)) {
return true;
}
}
return false;
}
}
......@@ -19,6 +19,7 @@
*/
package org.olat.course;
import java.util.ArrayList;
import java.util.List;
import org.olat.core.id.Identity;
......@@ -26,6 +27,7 @@ import org.olat.core.util.Formatter;
import org.olat.core.util.vfs.MergeSource;
import org.olat.core.util.vfs.NamedContainerImpl;
import org.olat.core.util.vfs.VFSConstants;
import org.olat.core.util.vfs.VFSContainer;
import org.olat.core.util.vfs.VFSItem;
import org.olat.core.util.vfs.VFSManager;
import org.olat.core.util.vfs.VFSStatus;
......@@ -128,12 +130,14 @@ class CoursefolderWebDAVMergeSource extends MergeSource {
super.init();
RepositoryManager rm = RepositoryManager.getInstance();
List<RepositoryEntry> courseEntries = rm.queryByEditor(identity, CourseModule.getCourseTypeName());
List<VFSContainer> containers = new ArrayList<>();
// Add all found repo entries to merge source
for (RepositoryEntry re:courseEntries) {
String courseTitle = Formatter.makeStringFilesystemSave(re.getDisplayname());
NamedContainerImpl cfContainer = new CoursefolderWebDAVNamedContainer(courseTitle, re.getOlatResource());
addContainer(cfContainer);
addContainerToList(cfContainer, containers);
}
setMergedContainers(containers);
loadTime = System.currentTimeMillis();
init = true;
}
......
......@@ -19,6 +19,7 @@
*/
package org.olat.group;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
......@@ -143,29 +144,34 @@ class GroupfoldersWebDAVMergeSource extends MergeSource {
@Override
protected void init() {
super.init();
// collect buddy groups
// collect buddy groups
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
Set<Long> addedGroupKeys = new HashSet<Long>();
Set<String> addedGroupNames = new HashSet<String>();
List<VFSContainer> containers = new ArrayList<>();
SearchBusinessGroupParams params = new SearchBusinessGroupParams(identity, true, false);
params.addTools(CollaborationTools.TOOL_FOLDER);
List<BusinessGroup> tutorGroups = bgs.findBusinessGroups(params, null, 0, -1);
for (BusinessGroup group : tutorGroups) {
addContainer(group, addedGroupKeys, addedGroupNames, true);
addContainer(group, addedGroupKeys, addedGroupNames, containers, true);
}
SearchBusinessGroupParams paramsParticipants = new SearchBusinessGroupParams(identity, false, true);
paramsParticipants.addTools(CollaborationTools.TOOL_FOLDER);
List<BusinessGroup> participantsGroups = bgs.findBusinessGroups(paramsParticipants, null, 0, -1);
for (BusinessGroup group : participantsGroups) {
addContainer(group, addedGroupKeys, addedGroupNames, false);
addContainer(group, addedGroupKeys, addedGroupNames, containers, false);
}
setMergedContainers(containers);
loadTime = System.currentTimeMillis();
init = true;
}
private void addContainer(BusinessGroup group, Set<Long> addedGroupKeys, Set<String> addedGroupNames, boolean isOwner) {
private void addContainer(BusinessGroup group, Set<Long> addedGroupKeys, Set<String> addedGroupNames,
List<VFSContainer> containers, boolean isOwner) {
if(addedGroupKeys.contains(group.getKey())) {
return;
}
......@@ -176,7 +182,7 @@ class GroupfoldersWebDAVMergeSource extends MergeSource {
VFSContainer grpContainer = getGroupContainer(name, group, isOwner);
// add container
addContainer(grpContainer);
addContainerToList(grpContainer, containers);
addedGroupKeys.add(group.getKey());
}
......@@ -231,7 +237,7 @@ class GroupfoldersWebDAVMergeSource extends MergeSource {
return grpContainer;
}
private class FullAccessWithLazyQuotaCallback extends FullAccessWithQuotaCallback {
private static class FullAccessWithLazyQuotaCallback extends FullAccessWithQuotaCallback {
private final String folderPath;
......
......@@ -23,9 +23,10 @@ import static org.olat.modules.sharedfolder.SharedFolderWebDAVProvider.readOnlyC
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.olat.core.commons.persistence.PersistenceHelper;
import org.olat.core.id.Identity;
import org.olat.core.id.Roles;
import org.olat.core.logging.OLog;
......@@ -147,41 +148,25 @@ public class SharedFolderWebDAVMergeSource extends MergeSource {
return shared;
}
/**
* Outsourced helper method for adding an entry to the root container.
*
* @param rootContainer
* @param sfm
* @param ownerEntries
* @param entry
*/
private void addReadonlyFolder(MergeSource rootContainer, RepositoryEntry entry, SharedFolderManager sfm,
List<RepositoryEntry> addedEntries) {
//
if (addedEntries == null || !PersistenceHelper.listContainsObjectByKey(addedEntries, entry)) {
// add the entry (readonly)
VFSContainer folder = sfm.getNamedSharedFolder(entry, true);
folder.setLocalSecurityCallback(readOnlyCallback);
rootContainer.addContainer(folder);
addedEntries.add(entry);
}
}
@Override
protected void init() {
super.init();
SharedFolderManager sfm = SharedFolderManager.getInstance();
RepositoryManager repoManager = RepositoryManager.getInstance();
List<VFSContainer> containers = new ArrayList<>();
Set<Long> addedEntries = new HashSet<>();
List<RepositoryEntry> ownerEntries = (List<RepositoryEntry>) repoManager.queryByOwner(identity, SharedFolderFileResource.TYPE_NAME);
for (RepositoryEntry repoEntry : ownerEntries) {
addContainer(sfm.getNamedSharedFolder(repoEntry, true));
for (RepositoryEntry entry : ownerEntries) {
VFSContainer container = sfm.getNamedSharedFolder(entry, true);
addContainerToList(container, containers);
addedEntries.add(entry.getKey());
}
// see /olat3/webapp/WEB-INF/olat_extensions.xml
if (publiclyReadableFolders != null && publiclyReadableFolders.size() > 0) {
// Temporarily save added entries. This is needed to make sure not to add an entry twice.
List<RepositoryEntry> addedEntries = new ArrayList<RepositoryEntry>(ownerEntries);
String firstItem = publiclyReadableFolders.get(0);
// If the first value in the list is '*', list all resource folders.
if (firstItem != null && firstItem.equals("*")) {
......@@ -190,7 +175,7 @@ public class SharedFolderWebDAVMergeSource extends MergeSource {
List<String> types = Collections.singletonList(SharedFolderFileResource.TYPE_NAME);
List<RepositoryEntry> allEntries = repoManager.queryByTypeLimitAccess(identity, types, registeredUserRole);
for (RepositoryEntry entry : allEntries) {
addReadonlyFolder(this, entry, sfm, addedEntries);
addReadonlyFolder(entry, sfm, addedEntries, containers);
}
} else {
// only list the specified folders
......@@ -199,7 +184,7 @@ public class SharedFolderWebDAVMergeSource extends MergeSource {
for (RepositoryEntry entry:entries) {
if (entry.getAccess() >= RepositoryEntry.ACC_USERS || (entry.getAccess() == RepositoryEntry.ACC_OWNERS && entry.isMembersOnly())) {
// add folder (which is a repo entry) to root container if not present
addReadonlyFolder(this, entry, sfm, addedEntries);
addReadonlyFolder(entry, sfm, addedEntries, containers);
} else {
log.warn("Access denied on entry::" + entry.getKey(), null);
}
......@@ -207,9 +192,23 @@ public class SharedFolderWebDAVMergeSource extends MergeSource {
}
}
setMergedContainers(containers);
loadTime = System.currentTimeMillis();
init = true;
}
private void addReadonlyFolder(RepositoryEntry entry, SharedFolderManager sfm,
Set<Long> addedEntries, List<VFSContainer> containers) {
//
if (!addedEntries.contains(entry.getKey())) {
// add the entry (readonly)
VFSContainer folder = sfm.getNamedSharedFolder(entry, true);
folder.setLocalSecurityCallback(readOnlyCallback);
addContainerToList(folder, containers);
addedEntries.add(entry.getKey());
}
}
private List<Long> getSharedKeys() {
List<Long> publiclyReadableFoldersKeys = new ArrayList<Long>();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment