Search in sources :

Example 31 with OlatRootFolderImpl

use of org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl in project OpenOLAT by OpenOLAT.

the class PFManager method getLastUpdated.

/**
 * Gets the last updated file for each participant.
 *
 * @param courseEnv
 * @param pfNode
 * @param identity
 * @return the last updated file as Date
 */
private Date getLastUpdated(CourseEnvironment courseEnv, PFCourseNode pfNode, Identity identity, String fileName) {
    Date latest = null;
    List<Long> lastUpdated = new ArrayList<>();
    OlatRootFolderImpl baseContainer = courseEnv.getCourseBaseContainer();
    Path path = Paths.get(baseContainer.getBasefile().toPath().toString(), FILENAME_PARTICIPANTFOLDER, pfNode.getIdent(), getIdFolderName(identity), fileName);
    try {
        Files.walkFileTree(path, new SimpleFileVisitor<Path>() {

            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                lastUpdated.add(attrs.lastModifiedTime().toMillis());
                return FileVisitResult.CONTINUE;
            }
        });
    } catch (IOException e) {
        log.error("Unknown IOE", e);
    }
    Collections.sort(lastUpdated);
    if (lastUpdated.size() > 0) {
        latest = new Date(lastUpdated.get(lastUpdated.size() - 1));
    }
    return latest;
}
Also used : Path(java.nio.file.Path) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) ArrayList(java.util.ArrayList) FileVisitResult(java.nio.file.FileVisitResult) IOException(java.io.IOException) Date(java.util.Date) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Example 32 with OlatRootFolderImpl

use of org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl in project OpenOLAT by OpenOLAT.

the class PFManager method provideParticipantFolder.

/**
 * Provide participant folder in GUI.
 *
 * @param pfNode
 * @param pfView
 * @param courseEnv
 * @param identity
 * @param isCoach
 * @return the VFS container
 */
public VFSContainer provideParticipantFolder(PFCourseNode pfNode, PFView pfView, Translator translator, CourseEnvironment courseEnv, Identity identity, boolean isCoach, boolean readOnly) {
    SubscriptionContext nodefolderSubContext = CourseModule.createSubscriptionContext(courseEnv, pfNode);
    String path = courseEnv.getCourseBaseContainer().getRelPath() + "/" + FILENAME_PARTICIPANTFOLDER;
    VFSContainer courseElementBaseContainer = new OlatRootFolderImpl(path, null);
    Path relPath = Paths.get(pfNode.getIdent(), getIdFolderName(identity));
    VFSContainer userBaseContainer = VFSManager.resolveOrCreateContainerFromPath(courseElementBaseContainer, relPath.toString());
    String baseContainerName = userManager.getUserDisplayName(identity);
    VirtualContainer namedCourseFolder = new VirtualContainer(baseContainerName);
    namedCourseFolder.setLocalSecurityCallback(new ReadOnlyCallback(nodefolderSubContext));
    VFSContainer dropContainer = new NamedContainerImpl(PFView.onlyDrop.equals(pfView) || PFView.onlyReturn.equals(pfView) ? baseContainerName : translator.translate("drop.box"), VFSManager.resolveOrCreateContainerFromPath(userBaseContainer, FILENAME_DROPBOX));
    if (pfNode.hasParticipantBoxConfigured()) {
        namedCourseFolder.addItem(dropContainer);
    }
    VFSContainer returnContainer = new NamedContainerImpl(PFView.onlyDrop.equals(pfView) || PFView.onlyReturn.equals(pfView) ? baseContainerName : translator.translate("return.box"), VFSManager.resolveOrCreateContainerFromPath(userBaseContainer, FILENAME_RETURNBOX));
    if (pfNode.hasCoachBoxConfigured()) {
        namedCourseFolder.addItem(returnContainer);
    }
    if (readOnly) {
        dropContainer.setLocalSecurityCallback(new ReadOnlyCallback(nodefolderSubContext));
        returnContainer.setLocalSecurityCallback(new ReadOnlyCallback(nodefolderSubContext));
    } else {
        if (isCoach) {
            dropContainer.setLocalSecurityCallback(new ReadOnlyCallback(nodefolderSubContext));
            returnContainer.setLocalSecurityCallback(new ReadWriteDeleteCallback(nodefolderSubContext));
        } else {
            VFSContainer dropbox = resolveOrCreateDropFolder(courseEnv, pfNode, identity);
            VFSSecurityCallback callback = calculateCallback(courseEnv, pfNode, dropbox, false);
            dropContainer.setLocalSecurityCallback(callback);
            returnContainer.setLocalSecurityCallback(new ReadOnlyCallback(nodefolderSubContext));
        }
    }
    VFSContainer folderRunContainer;
    switch(pfView) {
        case dropAndReturn:
            folderRunContainer = namedCourseFolder;
            break;
        case onlyDrop:
            folderRunContainer = dropContainer;
            break;
        case onlyReturn:
            folderRunContainer = returnContainer;
            break;
        default:
            folderRunContainer = namedCourseFolder;
            break;
    }
    return folderRunContainer;
}
Also used : Path(java.nio.file.Path) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) VFSContainer(org.olat.core.util.vfs.VFSContainer) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) VFSSecurityCallback(org.olat.core.util.vfs.callbacks.VFSSecurityCallback) NamedContainerImpl(org.olat.core.util.vfs.NamedContainerImpl) VirtualContainer(org.olat.core.util.vfs.VirtualContainer)

Example 33 with OlatRootFolderImpl

use of org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl in project OpenOLAT by OpenOLAT.

the class PFManager method provideParticipantContainer.

/**
 * Provide participant view in webdav.
 *
 * @param pfNode
 * @param courseEnv
 * @param identity
 * @return the VFS container
 */
private VFSContainer provideParticipantContainer(PFCourseNode pfNode, CourseEnvironment courseEnv, Identity identity, boolean courseReadOnly) {
    Locale locale = I18nManager.getInstance().getLocaleOrDefault(identity.getUser().getPreferences().getLanguage());
    Translator translator = Util.createPackageTranslator(PFRunController.class, locale);
    SubscriptionContext subsContext = CourseModule.createSubscriptionContext(courseEnv, pfNode);
    String path = courseEnv.getCourseBaseContainer().getRelPath() + "/" + FILENAME_PARTICIPANTFOLDER;
    VFSContainer courseElementBaseContainer = new OlatRootFolderImpl(path, null);
    VirtualContainer namedCourseFolder = new VirtualContainer(identity.getName());
    Path relPath = Paths.get(pfNode.getIdent(), getIdFolderName(identity));
    VFSContainer userBaseContainer = VFSManager.resolveOrCreateContainerFromPath(courseElementBaseContainer, relPath.toString());
    if (pfNode.hasParticipantBoxConfigured()) {
        VFSContainer dropContainer = new NamedContainerImpl(translator.translate("drop.box"), VFSManager.resolveOrCreateContainerFromPath(userBaseContainer, FILENAME_DROPBOX));
        if (courseReadOnly) {
            dropContainer.setLocalSecurityCallback(new ReadOnlyCallback(subsContext));
        } else {
            VFSContainer dropbox = resolveOrCreateDropFolder(courseEnv, pfNode, identity);
            VFSSecurityCallback callback = calculateCallback(courseEnv, pfNode, dropbox, true);
            dropContainer.setLocalSecurityCallback(callback);
        }
        namedCourseFolder.addItem(dropContainer);
    }
    if (pfNode.hasCoachBoxConfigured()) {
        VFSContainer returnContainer = new NamedContainerImpl(translator.translate("return.box"), VFSManager.resolveOrCreateContainerFromPath(userBaseContainer, FILENAME_RETURNBOX));
        returnContainer.setLocalSecurityCallback(new ReadOnlyCallback(subsContext));
        namedCourseFolder.addItem(returnContainer);
    }
    return namedCourseFolder;
}
Also used : Locale(java.util.Locale) Path(java.nio.file.Path) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) Translator(org.olat.core.gui.translator.Translator) VFSContainer(org.olat.core.util.vfs.VFSContainer) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) VFSSecurityCallback(org.olat.core.util.vfs.callbacks.VFSSecurityCallback) NamedContainerImpl(org.olat.core.util.vfs.NamedContainerImpl) VirtualContainer(org.olat.core.util.vfs.VirtualContainer)

Example 34 with OlatRootFolderImpl

use of org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl in project OpenOLAT by OpenOLAT.

the class PFManager method provideAdminContainer.

/**
 * Provide admin view for webdav, contains all participants of the course.
 *
 * @param pfNode the pf node
 * @param courseEnv the course env
 * @return the VFS container
 */
public VFSContainer provideAdminContainer(PFCourseNode pfNode, CourseEnvironment courseEnv) {
    Translator translator = Util.createPackageTranslator(PFRunController.class, I18nModule.getDefaultLocale());
    SubscriptionContext nodefolderSubContext = CourseModule.createSubscriptionContext(courseEnv, pfNode);
    RepositoryEntry re = courseEnv.getCourseGroupManager().getCourseEntry();
    List<Identity> participants = repositoryEntryRelationDao.getMembers(re, RepositoryEntryRelationType.both, GroupRoles.participant.name());
    participants = new ArrayList<>(new HashSet<>(participants));
    String path = courseEnv.getCourseBaseContainer().getRelPath() + "/" + FILENAME_PARTICIPANTFOLDER;
    VFSContainer courseElementBaseContainer = new OlatRootFolderImpl(path, null);
    VirtualContainer namedCourseFolder = new VirtualContainer(translator.translate("participant.folder"));
    for (Identity participant : participants) {
        Path relPath = Paths.get(pfNode.getIdent(), getIdFolderName(participant));
        VFSContainer userBaseContainer = VFSManager.resolveOrCreateContainerFromPath(courseElementBaseContainer, relPath.toString());
        String participantfoldername = userManager.getUserDisplayName(participant);
        VirtualContainer participantFolder = new VirtualContainer(participantfoldername);
        participantFolder.setParentContainer(namedCourseFolder);
        namedCourseFolder.addItem(participantFolder);
        if (pfNode.hasParticipantBoxConfigured()) {
            VFSContainer dropContainer = new NamedContainerImpl(translator.translate("drop.box"), VFSManager.resolveOrCreateContainerFromPath(userBaseContainer, FILENAME_DROPBOX));
            dropContainer.setLocalSecurityCallback(new ReadOnlyCallback(nodefolderSubContext));
            participantFolder.addItem(dropContainer);
        }
        if (pfNode.hasCoachBoxConfigured()) {
            VFSContainer returnContainer = new NamedContainerImpl(translator.translate("return.box"), VFSManager.resolveOrCreateContainerFromPath(userBaseContainer, FILENAME_RETURNBOX));
            returnContainer.setLocalSecurityCallback(new ReadWriteDeleteCallback(nodefolderSubContext));
            participantFolder.addItem(returnContainer);
        }
    }
    return namedCourseFolder;
}
Also used : Path(java.nio.file.Path) VFSContainer(org.olat.core.util.vfs.VFSContainer) RepositoryEntry(org.olat.repository.RepositoryEntry) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) Translator(org.olat.core.gui.translator.Translator) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Identity(org.olat.core.id.Identity) NamedContainerImpl(org.olat.core.util.vfs.NamedContainerImpl) HashSet(java.util.HashSet) VirtualContainer(org.olat.core.util.vfs.VirtualContainer)

Example 35 with OlatRootFolderImpl

use of org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl in project OpenOLAT by OpenOLAT.

the class ProjectDetailsDisplayController method doFileDelivery.

private void doFileDelivery(UserRequest ureq, final Project project, final CourseEnvironment courseEnv, final CourseNode cNode) {
    // Create a mapper to deliver the auto-download of the file. We have to
    // create a dedicated mapper here
    // and can not reuse the standard briefcase way of file delivering, some
    // very old fancy code
    // Mapper is cleaned up automatically by basic controller
    OlatRootFolderImpl rootFolder = new OlatRootFolderImpl(projectBrokerManager.getAttamchmentRelativeRootPath(project, courseEnv, cNode), null);
    VFSItem item = rootFolder.resolve(project.getAttachmentFileName());
    if (item instanceof VFSLeaf) {
        VFSLeaf attachment = (VFSLeaf) item;
        MediaResource resource = new VFSMediaResource(attachment);
        ureq.getDispatchResult().setResultingMediaResource(resource);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) VFSItem(org.olat.core.util.vfs.VFSItem) MediaResource(org.olat.core.gui.media.MediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Aggregations

OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)214 VFSContainer (org.olat.core.util.vfs.VFSContainer)86 VFSItem (org.olat.core.util.vfs.VFSItem)68 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)58 Identity (org.olat.core.id.Identity)50 Test (org.junit.Test)48 File (java.io.File)36 InputStream (java.io.InputStream)30 OlatNamedContainerImpl (org.olat.core.commons.modules.bc.vfs.OlatNamedContainerImpl)28 OutputStream (java.io.OutputStream)26 VFSSecurityCallback (org.olat.core.util.vfs.callbacks.VFSSecurityCallback)24 URI (java.net.URI)22 RepositoryEntry (org.olat.repository.RepositoryEntry)22 ByteArrayInputStream (java.io.ByteArrayInputStream)20 Path (java.nio.file.Path)20 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)18 IOException (java.io.IOException)16 HttpResponse (org.apache.http.HttpResponse)14 CollaborationTools (org.olat.collaboration.CollaborationTools)14 FolderRunController (org.olat.core.commons.modules.bc.FolderRunController)14