Search in sources :

Example 16 with NamedContainerImpl

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

the class BCCourseNodeIndexer method doIndex.

@Override
public void doIndex(SearchResourceContext repositoryResourceContext, ICourse course, CourseNode courseNode, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    if (isLogDebugEnabled())
        logDebug("Index Briefcase...");
    BCCourseNode bcNode = (BCCourseNode) courseNode;
    SearchResourceContext courseNodeResourceContext = createSearchResourceContext(repositoryResourceContext, bcNode, TYPE);
    Document document = CourseNodeDocument.createDocument(courseNodeResourceContext, bcNode);
    indexWriter.addDocument(document);
    VFSContainer bcContainer = null;
    if (bcNode.getModuleConfiguration().getBooleanSafe(BCCourseNodeEditController.CONFIG_AUTO_FOLDER)) {
        bcContainer = BCCourseNode.getNodeFolderContainer(bcNode, course.getCourseEnvironment());
    } else {
        String subpath = courseNode.getModuleConfiguration().getStringValue(BCCourseNodeEditController.CONFIG_SUBPATH);
        if (subpath != null) {
            VFSItem item = course.getCourseEnvironment().getCourseFolderContainer().resolve(subpath);
            if (item instanceof VFSContainer) {
                bcContainer = new NamedContainerImpl(courseNode.getShortTitle(), (VFSContainer) item);
            }
        }
    }
    if (bcContainer != null) {
        doIndexVFSContainer(courseNodeResourceContext, bcContainer, indexWriter, "", FolderIndexerAccess.FULL_ACCESS);
    }
}
Also used : BCCourseNode(org.olat.course.nodes.BCCourseNode) SearchResourceContext(org.olat.search.service.SearchResourceContext) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) Document(org.apache.lucene.document.Document) CourseNodeDocument(org.olat.search.service.document.CourseNodeDocument) NamedContainerImpl(org.olat.core.util.vfs.NamedContainerImpl)

Example 17 with NamedContainerImpl

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

the class GroupfoldersWebDAVMergeSource method getGroupContainer.

private VFSContainer getGroupContainer(String name, BusinessGroup group, boolean isOwner) {
    String folderPath = collaborationManager.getFolderRelPath(group);
    // create container and set quota
    OlatRootFolderImpl localImpl = new OlatRootFolderImpl(folderPath, this);
    // already done in OlatRootFolderImpl localImpl.getBasefile().mkdirs(); // lazy initialize dirs
    String containerName = RequestUtil.normalizeFilename(name);
    NamedContainerImpl grpContainer = new GroupNamedContainer(containerName, localImpl);
    boolean writeAccess;
    if (!isOwner) {
        // check if participants have read/write access
        int folderAccess = CollaborationTools.FOLDER_ACCESS_ALL;
        Long lFolderAccess = collaborationManager.lookupFolderAccess(group);
        if (lFolderAccess != null) {
            folderAccess = lFolderAccess.intValue();
        }
        writeAccess = (folderAccess == CollaborationTools.FOLDER_ACCESS_ALL);
    } else {
        writeAccess = true;
    }
    VFSSecurityCallback secCallback;
    if (writeAccess) {
        SubscriptionContext sc = new SubscriptionContext(group, "toolfolder");
        secCallback = new FullAccessWithLazyQuotaCallback(folderPath, QuotaConstants.IDENTIFIER_DEFAULT_GROUPS, sc);
    } else {
        secCallback = new ReadOnlyCallback();
    }
    grpContainer.setLocalSecurityCallback(secCallback);
    return grpContainer;
}
Also used : FullAccessWithLazyQuotaCallback(org.olat.core.util.vfs.callbacks.FullAccessWithLazyQuotaCallback) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) ReadOnlyCallback(org.olat.core.util.vfs.callbacks.ReadOnlyCallback) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) VFSSecurityCallback(org.olat.core.util.vfs.callbacks.VFSSecurityCallback) NamedContainerImpl(org.olat.core.util.vfs.NamedContainerImpl)

Example 18 with NamedContainerImpl

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

the class MergedCourseContainer method addFolders.

private void addFolders(PersistingCourseImpl course, MergeSource nodesContainer, TreeNode courseNode) {
    if (courseNode == null)
        return;
    for (int i = 0; i < courseNode.getChildCount(); i++) {
        TreeNode child = (TreeNode) courseNode.getChildAt(i);
        NodeEvaluation nodeEval;
        if (child.getUserObject() instanceof NodeEvaluation) {
            nodeEval = (NodeEvaluation) child.getUserObject();
        } else {
            continue;
        }
        if (nodeEval != null && nodeEval.getCourseNode() != null) {
            CourseNode courseNodeChild = nodeEval.getCourseNode();
            String folderName = RequestUtil.normalizeFilename(courseNodeChild.getShortTitle());
            if (courseNodeChild instanceof BCCourseNode) {
                final BCCourseNode bcNode = (BCCourseNode) courseNodeChild;
                // add folder not to merge source. Use name and node id to have unique name
                VFSContainer rootFolder = getBCContainer(course, bcNode, nodeEval, false);
                boolean canDownload = nodeEval.isCapabilityAccessible("download");
                if (canDownload && rootFolder != null) {
                    if (courseReadOnly) {
                        rootFolder.setLocalSecurityCallback(new ReadOnlyCallback());
                    } else if (nodeEval.isCapabilityAccessible("upload")) {
                    // inherit the security callback from the course as for author
                    } else {
                        rootFolder.setLocalSecurityCallback(new ReadOnlyCallback());
                    }
                    folderName = getFolderName(nodesContainer, bcNode, folderName);
                    // Create a container for this node content and wrap it with a merge source which is attached to tree
                    VFSContainer nodeContentContainer = new NamedContainerImpl(folderName, rootFolder);
                    MergeSource courseNodeContainer = new MergeSource(nodesContainer, folderName);
                    courseNodeContainer.addContainersChildren(nodeContentContainer, true);
                    nodesContainer.addContainer(courseNodeContainer);
                    // Do recursion for all children
                    addFolders(course, courseNodeContainer, child);
                } else {
                    // For non-folder course nodes, add merge source (no files to show) ...
                    MergeSource courseNodeContainer = new MergeSource(null, folderName);
                    // , then do recursion for all children ...
                    addFolders(course, courseNodeContainer, child);
                    // ... but only add this container if it contains any children with at least one BC course node
                    if (courseNodeContainer.getItems().size() > 0) {
                        nodesContainer.addContainer(courseNodeContainer);
                    }
                }
            } else if (courseNodeChild instanceof PFCourseNode) {
                final PFCourseNode pfNode = (PFCourseNode) courseNodeChild;
                // add folder not to merge source. Use name and node id to have unique name
                PFManager pfManager = CoreSpringFactory.getImpl(PFManager.class);
                folderName = getFolderName(nodesContainer, pfNode, folderName);
                MergeSource courseNodeContainer = new MergeSource(nodesContainer, folderName);
                UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(identityEnv, course.getCourseEnvironment());
                VFSContainer rootFolder = pfManager.provideCoachOrParticipantContainer(pfNode, userCourseEnv, identityEnv.getIdentity(), courseReadOnly);
                VFSContainer nodeContentContainer = new NamedContainerImpl(folderName, rootFolder);
                courseNodeContainer.addContainersChildren(nodeContentContainer, true);
                addFolders(course, courseNodeContainer, child);
                nodesContainer.addContainer(courseNodeContainer);
            } else {
                // For non-folder course nodes, add merge source (no files to show) ...
                MergeSource courseNodeContainer = new MergeSource(null, folderName);
                // , then do recursion for all children ...
                addFolders(course, courseNodeContainer, child);
                // ... but only add this container if it contains any children with at least one BC course node
                if (courseNodeContainer.getItems().size() > 0) {
                    nodesContainer.addContainer(courseNodeContainer);
                }
            }
        }
    }
}
Also used : PFCourseNode(org.olat.course.nodes.PFCourseNode) PFManager(org.olat.course.nodes.pf.manager.PFManager) ReadOnlyCallback(org.olat.core.util.vfs.callbacks.ReadOnlyCallback) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) VFSContainer(org.olat.core.util.vfs.VFSContainer) BCCourseNode(org.olat.course.nodes.BCCourseNode) MergeSource(org.olat.core.util.vfs.MergeSource) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) TreeNode(org.olat.core.gui.components.tree.TreeNode) PFCourseNode(org.olat.course.nodes.PFCourseNode) CourseNode(org.olat.course.nodes.CourseNode) BCCourseNode(org.olat.course.nodes.BCCourseNode) NodeEvaluation(org.olat.course.run.userview.NodeEvaluation) NamedContainerImpl(org.olat.core.util.vfs.NamedContainerImpl)

Example 19 with NamedContainerImpl

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

the class MergedCourseContainer method initSharedFolder.

/**
 * Grab any shared folder that is configured, but only when in unchecked
 * security mode (no identity environment) or when the user has course
 * admin rights
 *
 * @param persistingCourse
 */
private void initSharedFolder(PersistingCourseImpl persistingCourse) {
    CourseConfig courseConfig = persistingCourse.getCourseConfig();
    String sfSoftkey = courseConfig.getSharedFolderSoftkey();
    if (StringHelper.containsNonWhitespace(sfSoftkey) && !CourseConfig.VALUE_EMPTY_SHAREDFOLDER_SOFTKEY.equals(sfSoftkey)) {
        RepositoryEntry re = persistingCourse.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
        if (identityEnv == null || identityEnv.getRoles().isOLATAdmin() || RepositoryManager.getInstance().isOwnerOfRepositoryEntry(identityEnv.getIdentity(), re)) {
            OLATResource sharedResource = CoreSpringFactory.getImpl(RepositoryService.class).loadRepositoryEntryResourceBySoftKey(sfSoftkey);
            if (sharedResource != null) {
                OlatRootFolderImpl sharedFolder = SharedFolderManager.getInstance().getSharedFolder(sharedResource);
                if (sharedFolder != null) {
                    if (courseConfig.isSharedFolderReadOnlyMount() || courseReadOnly) {
                        sharedFolder.setLocalSecurityCallback(new ReadOnlyCallback());
                    }
                    // add local course folder's children as read/write source and any sharedfolder as subfolder
                    addContainer(new NamedContainerImpl("_sharedfolder", sharedFolder));
                }
            }
        }
    }
}
Also used : OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) ReadOnlyCallback(org.olat.core.util.vfs.callbacks.ReadOnlyCallback) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) NamedContainerImpl(org.olat.core.util.vfs.NamedContainerImpl) CourseConfig(org.olat.course.config.CourseConfig) RepositoryService(org.olat.repository.RepositoryService)

Example 20 with NamedContainerImpl

use of org.olat.core.util.vfs.NamedContainerImpl 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

NamedContainerImpl (org.olat.core.util.vfs.NamedContainerImpl)30 VFSContainer (org.olat.core.util.vfs.VFSContainer)24 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)14 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)12 VirtualContainer (org.olat.core.util.vfs.VirtualContainer)10 Path (java.nio.file.Path)8 ReadOnlyCallback (org.olat.core.util.vfs.callbacks.ReadOnlyCallback)8 VFSSecurityCallback (org.olat.core.util.vfs.callbacks.VFSSecurityCallback)8 Translator (org.olat.core.gui.translator.Translator)6 MergeSource (org.olat.core.util.vfs.MergeSource)6 BCCourseNode (org.olat.course.nodes.BCCourseNode)6 RepositoryEntry (org.olat.repository.RepositoryEntry)6 Locale (java.util.Locale)4 Identity (org.olat.core.id.Identity)4 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)4 CourseNode (org.olat.course.nodes.CourseNode)4 PFCourseNode (org.olat.course.nodes.PFCourseNode)4 PFManager (org.olat.course.nodes.pf.manager.PFManager)4 TaxonomyVFSSecurityCallback (org.olat.modules.taxonomy.ui.component.TaxonomyVFSSecurityCallback)4 IOException (java.io.IOException)2