Search in sources :

Example 6 with VirtualContainer

use of org.olat.core.util.vfs.VirtualContainer in project OpenOLAT by OpenOLAT.

the class CoursefolderWebDAVMergeSource method appendCourses.

private void appendCourses(List<RepositoryEntry> courseEntries, boolean editor, List<VFSContainer> containers, boolean useTerms, Map<String, VFSContainer> terms, VirtualContainer noTermContainer, VirtualContainer finishedContainer, boolean prependReference, UniqueNames container) {
    // Add all found repo entries to merge source
    int count = 0;
    for (RepositoryEntry re : courseEntries) {
        if (container.isDuplicate(re)) {
            continue;
        }
        String displayName = re.getDisplayname();
        if (prependReference && StringHelper.containsNonWhitespace(re.getExternalRef())) {
            displayName = re.getExternalRef() + " " + displayName;
        }
        String courseTitle = RequestUtil.normalizeFilename(displayName);
        if (finishedContainer != null && re.getRepositoryEntryStatus().isClosed()) {
            String name = container.getFinishedUniqueName(courseTitle);
            NamedContainerImpl cfContainer = new CoursefolderWebDAVNamedContainer(name, re, editor ? null : identityEnv);
            finishedContainer.getItems().add(cfContainer);
        } else if (useTerms) {
            RepositoryEntryLifecycle lc = re.getLifecycle();
            if (lc != null && !lc.isPrivateCycle()) {
                // when a semester term info is found, add it to corresponding term folder
                String termSoftKey = lc.getSoftKey();
                VFSContainer termContainer = terms.get(termSoftKey);
                if (termContainer == null) {
                    // folder for this semester term does not yet exist, create one and add to map
                    String normalizedKey = RequestUtil.normalizeFilename(termSoftKey);
                    termContainer = new VirtualContainer(normalizedKey);
                    terms.put(termSoftKey, termContainer);
                    addContainerToList(termContainer, containers);
                }
                String name = container.getTermUniqueName(termSoftKey, courseTitle);
                NamedContainerImpl cfContainer = new CoursefolderWebDAVNamedContainer(name, re, editor ? null : identityEnv);
                termContainer.getItems().add(cfContainer);
            } else {
                // no semester term found, add to no-term folder
                String name = container.getNoTermUniqueName(courseTitle);
                NamedContainerImpl cfContainer = new CoursefolderWebDAVNamedContainer(name, re, editor ? null : identityEnv);
                noTermContainer.getItems().add(cfContainer);
            }
        } else {
            String name = container.getContainersUniqueName(courseTitle);
            NamedContainerImpl cfContainer = new CoursefolderWebDAVNamedContainer(name, re, editor ? null : identityEnv);
            addContainerToList(cfContainer, containers);
        }
        if (++count % 5 == 0) {
            DBFactory.getInstance().commitAndCloseSession();
        }
    }
}
Also used : RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) VFSContainer(org.olat.core.util.vfs.VFSContainer) RepositoryEntry(org.olat.repository.RepositoryEntry) NamedContainerImpl(org.olat.core.util.vfs.NamedContainerImpl) VirtualContainer(org.olat.core.util.vfs.VirtualContainer)

Example 7 with VirtualContainer

use of org.olat.core.util.vfs.VirtualContainer in project OpenOLAT by OpenOLAT.

the class CoursefolderWebDAVMergeSource method loadMergedContainers.

@Override
protected List<VFSContainer> loadMergedContainers() {
    List<VFSContainer> containers = new ArrayList<>();
    Map<String, VFSContainer> terms = null;
    VirtualContainer noTermContainer = null;
    VirtualContainer finishedContainer = null;
    boolean useTerms = webDAVModule.isTermsFoldersEnabled();
    if (useTerms) {
        // prepare no-terms folder for all resources without semester term info or private date
        terms = new HashMap<String, VFSContainer>();
        noTermContainer = new VirtualContainer("_other");
    } else {
        finishedContainer = new VirtualContainer("_finished");
    }
    boolean prependReference = webDAVModule.isPrependCourseReferenceToTitle();
    UniqueNames container = new UniqueNames();
    List<RepositoryEntry> editorEntries = repositoryManager.queryByOwner(getIdentity(), "CourseModule");
    appendCourses(editorEntries, true, containers, useTerms, terms, noTermContainer, finishedContainer, prependReference, container);
    // add courses as participant and coaches
    if (webDAVModule.isEnableLearnersParticipatingCourses()) {
        List<RepositoryEntry> entries = repositoryManager.getLearningResourcesAsParticipantAndCoach(getIdentity(), "CourseModule");
        appendCourses(entries, false, containers, useTerms, terms, noTermContainer, finishedContainer, prependReference, container);
    }
    // add bookmarked courses
    if (webDAVModule.isEnableLearnersBookmarksCourse()) {
        List<RepositoryEntry> bookmarkedEntries = repositoryManager.getLearningResourcesAsBookmark(getIdentity(), identityEnv.getRoles(), "CourseModule", 0, -1);
        appendCourses(bookmarkedEntries, false, containers, useTerms, terms, noTermContainer, finishedContainer, prependReference, container);
    }
    if (useTerms) {
        // add no-terms folder if any have been found
        if (noTermContainer.getItems().size() > 0) {
            addContainerToList(noTermContainer, containers);
        }
    } else if (finishedContainer.getItems().size() > 0) {
        addContainerToList(finishedContainer, containers);
    }
    return containers;
}
Also used : VFSContainer(org.olat.core.util.vfs.VFSContainer) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) VirtualContainer(org.olat.core.util.vfs.VirtualContainer)

Example 8 with VirtualContainer

use of org.olat.core.util.vfs.VirtualContainer in project openolat by klemens.

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 9 with VirtualContainer

use of org.olat.core.util.vfs.VirtualContainer in project openolat by klemens.

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 10 with VirtualContainer

use of org.olat.core.util.vfs.VirtualContainer in project openolat by klemens.

the class CoursefolderWebDAVMergeSource method appendCourses.

private void appendCourses(List<RepositoryEntry> courseEntries, boolean editor, List<VFSContainer> containers, boolean useTerms, Map<String, VFSContainer> terms, VirtualContainer noTermContainer, VirtualContainer finishedContainer, boolean prependReference, UniqueNames container) {
    // Add all found repo entries to merge source
    int count = 0;
    for (RepositoryEntry re : courseEntries) {
        if (container.isDuplicate(re)) {
            continue;
        }
        String displayName = re.getDisplayname();
        if (prependReference && StringHelper.containsNonWhitespace(re.getExternalRef())) {
            displayName = re.getExternalRef() + " " + displayName;
        }
        String courseTitle = RequestUtil.normalizeFilename(displayName);
        if (finishedContainer != null && re.getRepositoryEntryStatus().isClosed()) {
            String name = container.getFinishedUniqueName(courseTitle);
            NamedContainerImpl cfContainer = new CoursefolderWebDAVNamedContainer(name, re, editor ? null : identityEnv);
            finishedContainer.getItems().add(cfContainer);
        } else if (useTerms) {
            RepositoryEntryLifecycle lc = re.getLifecycle();
            if (lc != null && !lc.isPrivateCycle()) {
                // when a semester term info is found, add it to corresponding term folder
                String termSoftKey = lc.getSoftKey();
                VFSContainer termContainer = terms.get(termSoftKey);
                if (termContainer == null) {
                    // folder for this semester term does not yet exist, create one and add to map
                    String normalizedKey = RequestUtil.normalizeFilename(termSoftKey);
                    termContainer = new VirtualContainer(normalizedKey);
                    terms.put(termSoftKey, termContainer);
                    addContainerToList(termContainer, containers);
                }
                String name = container.getTermUniqueName(termSoftKey, courseTitle);
                NamedContainerImpl cfContainer = new CoursefolderWebDAVNamedContainer(name, re, editor ? null : identityEnv);
                termContainer.getItems().add(cfContainer);
            } else {
                // no semester term found, add to no-term folder
                String name = container.getNoTermUniqueName(courseTitle);
                NamedContainerImpl cfContainer = new CoursefolderWebDAVNamedContainer(name, re, editor ? null : identityEnv);
                noTermContainer.getItems().add(cfContainer);
            }
        } else {
            String name = container.getContainersUniqueName(courseTitle);
            NamedContainerImpl cfContainer = new CoursefolderWebDAVNamedContainer(name, re, editor ? null : identityEnv);
            addContainerToList(cfContainer, containers);
        }
        if (++count % 5 == 0) {
            DBFactory.getInstance().commitAndCloseSession();
        }
    }
}
Also used : RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) VFSContainer(org.olat.core.util.vfs.VFSContainer) RepositoryEntry(org.olat.repository.RepositoryEntry) NamedContainerImpl(org.olat.core.util.vfs.NamedContainerImpl) VirtualContainer(org.olat.core.util.vfs.VirtualContainer)

Aggregations

VirtualContainer (org.olat.core.util.vfs.VirtualContainer)20 VFSContainer (org.olat.core.util.vfs.VFSContainer)16 NamedContainerImpl (org.olat.core.util.vfs.NamedContainerImpl)10 Path (java.nio.file.Path)8 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)8 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)8 Translator (org.olat.core.gui.translator.Translator)6 Identity (org.olat.core.id.Identity)6 VFSSecurityCallback (org.olat.core.util.vfs.callbacks.VFSSecurityCallback)6 RepositoryEntry (org.olat.repository.RepositoryEntry)6 Locale (java.util.Locale)4 ReadOnlyCallback (org.olat.core.util.vfs.callbacks.ReadOnlyCallback)4 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)2 MetaInfoFactory (org.olat.core.commons.modules.bc.meta.MetaInfoFactory)2 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)2 License (org.olat.core.commons.services.license.License)2 LicenseRenderer (org.olat.core.commons.services.license.ui.LicenseRenderer)2