diff --git a/src/main/java/org/olat/course/nodes/PFCourseNode.java b/src/main/java/org/olat/course/nodes/PFCourseNode.java index 40cedcbd63a95b2f7bde57cd3f6b29888f38f829..fe24dd0fb8a6990c32a72e80907829c32c23eb7f 100644 --- a/src/main/java/org/olat/course/nodes/PFCourseNode.java +++ b/src/main/java/org/olat/course/nodes/PFCourseNode.java @@ -22,7 +22,9 @@ package org.olat.course.nodes; import java.io.File; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.ArrayList; import java.util.Date; +import java.util.List; import java.util.Locale; import java.util.zip.ZipOutputStream; @@ -164,9 +166,9 @@ public class PFCourseNode extends AbstractAccessableCourseNode { public boolean isInDropboxTimeFrame () { ModuleConfiguration config = getModuleConfiguration(); Date start = config.getBooleanEntry(CONFIG_KEY_DATESTART) != null ? - (Date) config.getDateValue(CONFIG_KEY_DATESTART) : new Date(); + config.getDateValue(CONFIG_KEY_DATESTART) : new Date(); Date end = config.getBooleanEntry(CONFIG_KEY_DATEEND) != null ? - (Date) config.getDateValue(CONFIG_KEY_DATEEND) : new Date(); + config.getDateValue(CONFIG_KEY_DATEEND) : new Date(); Date current = new Date(); return start.before(current) && end.after(current); @@ -182,13 +184,13 @@ public class PFCourseNode extends AbstractAccessableCourseNode { public Date getDateStart() { ModuleConfiguration config = getModuleConfiguration(); return config.getBooleanEntry(CONFIG_KEY_DATESTART) != null ? - (Date) config.getDateValue(CONFIG_KEY_DATESTART) : new Date(); + config.getDateValue(CONFIG_KEY_DATESTART) : new Date(); } public Date getDateEnd() { ModuleConfiguration config = getModuleConfiguration(); return config.getBooleanEntry(CONFIG_KEY_DATEEND) != null ? - (Date) config.getDateValue(CONFIG_KEY_DATEEND) : new Date(); + config.getDateValue(CONFIG_KEY_DATEEND) : new Date(); } @@ -228,28 +230,31 @@ public class PFCourseNode extends AbstractAccessableCourseNode { @Override public Controller createPeekViewRunController(UserRequest ureq, WindowControl wControl, UserCourseEnvironment userCourseEnv, NodeEvaluation ne) { - VFSContainer rootFolder = null; CourseEnvironment courseEnv = userCourseEnv.getCourseEnvironment(); Identity identity = userCourseEnv.getIdentityEnvironment().getIdentity(); - Path folderRelPath = null; + + List<VFSContainer> rootFolder = new ArrayList<>(); LocalFolderImpl baseContainer = courseEnv.getCourseBaseContainer(); PFManager pfManager = CoreSpringFactory.getImpl(PFManager.class); if (userCourseEnv.isCoach() || userCourseEnv.isAdmin()) { - folderRelPath = Paths.get(baseContainer.getBasefile().toPath().toString(), - PFManager.FILENAME_PARTICIPANTFOLDER, getIdent()); - rootFolder = new LocalFolderImpl(folderRelPath.toFile()); + List<Identity> participants = pfManager.getParticipants(identity, courseEnv, userCourseEnv.isAdmin()); + for(Identity participant:participants) { + Path folderRelPath = Paths.get(baseContainer.getBasefile().toPath().toString(), + PFManager.FILENAME_PARTICIPANTFOLDER, getIdent(), + pfManager.getIdFolderName(participant)); + rootFolder.add(new LocalFolderImpl(folderRelPath.toFile())); + } } else if (userCourseEnv.isParticipant()) { - folderRelPath = Paths.get(baseContainer.getBasefile().toPath().toString(), + Path folderRelPath = Paths.get(baseContainer.getBasefile().toPath().toString(), PFManager.FILENAME_PARTICIPANTFOLDER, getIdent(), pfManager.getIdFolderName(identity)); - rootFolder = new LocalFolderImpl(folderRelPath.toFile()); + rootFolder.add(new LocalFolderImpl(folderRelPath.toFile())); } - if (rootFolder == null) { + if (rootFolder.isEmpty()) { return super.createPeekViewRunController(ureq, wControl, userCourseEnv, ne); - } else { - return new PFPeekviewController(ureq, wControl, rootFolder, getIdent(), 4); } + return new PFPeekviewController(ureq, wControl, rootFolder, getIdent(), 4); } @Override diff --git a/src/main/java/org/olat/course/nodes/pf/ui/PFPeekviewController.java b/src/main/java/org/olat/course/nodes/pf/ui/PFPeekviewController.java index 7e2e58202c346e9ca67f3d20318fb93dc55e25b2..00a0135fb29aa54f8b7456f7d0a5704a2d66c466 100644 --- a/src/main/java/org/olat/course/nodes/pf/ui/PFPeekviewController.java +++ b/src/main/java/org/olat/course/nodes/pf/ui/PFPeekviewController.java @@ -25,7 +25,6 @@ import java.util.Comparator; import java.util.Date; import java.util.List; -import org.olat.core.CoreSpringFactory; import org.olat.core.commons.modules.bc.FolderModule; import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.Component; @@ -45,6 +44,7 @@ import org.olat.core.util.vfs.VFSItem; import org.olat.core.util.vfs.VFSLeaf; import org.olat.core.util.vfs.filters.VFSItemFilter; import org.olat.core.util.vfs.filters.VFSSystemItemFilter; +import org.springframework.beans.factory.annotation.Autowired; /** * * @author Fabian Kiefer, fabian.kiefer@frentix.com, http://www.frentix.com @@ -53,33 +53,34 @@ import org.olat.core.util.vfs.filters.VFSSystemItemFilter; public class PFPeekviewController extends BasicController implements Controller { // comparator to sort the messages list by creation date - private static final Comparator<VFSLeaf> dateSortingComparator = new Comparator<VFSLeaf>(){ - public int compare(final VFSLeaf leaf1, final VFSLeaf leaf2) { - return Long.valueOf(leaf2.getLastModified()).compareTo(leaf1.getLastModified()); //last first - }}; + private static final Comparator<VFSLeaf> dateSortingComparator = (leaf1, leaf2) -> + Long.compare(leaf2.getLastModified(), leaf1.getLastModified()); //last first // the current course node id private final String nodeId; private static final VFSItemFilter attachmentExcludeFilter = new VFSSystemItemFilter(); - public PFPeekviewController(UserRequest ureq, WindowControl wControl, VFSContainer rootFolder, String nodeId, int itemsToDisplay) { + @Autowired + private FolderModule folderModule; + + public PFPeekviewController(UserRequest ureq, WindowControl wControl, List<VFSContainer> folders, String nodeId, int itemsToDisplay) { super(ureq, wControl); this.nodeId = nodeId; VelocityContainer peekviewVC = createVelocityContainer("peekview"); // add items, only as many as configured List<VFSLeaf> allLeafs = new ArrayList<>(); - addItems(rootFolder, allLeafs); + for(VFSContainer rootFolder:folders) { + addItems(rootFolder, allLeafs); + } + // Sort messages by last modified date Collections.sort(allLeafs, dateSortingComparator); - boolean forceDownload = CoreSpringFactory.getImpl(FolderModule.class).isForceDownload(); + boolean forceDownload = folderModule.isForceDownload(); // only take the configured amount of messages List<VFSLeaf> leafs = new ArrayList<>(); - for (int i = 0; i < allLeafs.size(); i++) { - if (leafs.size() == itemsToDisplay) { - break; - } + for (int i = 0; i<allLeafs.size() && i<itemsToDisplay; i++) { VFSLeaf leaf = allLeafs.get(i); leafs.add(leaf); // add link to item @@ -90,8 +91,6 @@ public class PFPeekviewController extends BasicController implements Controller CSSHelper.createFiletypeIconCssClassFor(leaf.getName())); dlComp.setElementCssClass("o_gotoNode"); peekviewVC.put("nodeLinkDL_"+(i+1),dlComp); - } else { - // hu? don't konw how to work with non-local impls } } peekviewVC.contextPut("leafs", leafs); @@ -124,15 +123,10 @@ public class PFPeekviewController extends BasicController implements Controller // exclude files which are also excluded in FolderComponent for (VFSItem vfsItem : container.getItems(attachmentExcludeFilter)) { if (vfsItem instanceof VFSLeaf) { - // add leaf to our list - VFSLeaf leaf = (VFSLeaf) vfsItem; - allLeafs.add(leaf); + allLeafs.add((VFSLeaf)vfsItem); } else if (vfsItem instanceof VFSContainer) { // do it recursively for all children - VFSContainer childContainer = (VFSContainer) vfsItem; - addItems(childContainer, allLeafs); - } else { - // hu? + addItems((VFSContainer)vfsItem, allLeafs); } } }