Search in sources :

Example 6 with OlatRootFolderImpl

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

the class NodeExportVisitor method getIsolatedCourseFolder.

protected OlatRootFolderImpl getIsolatedCourseFolder() {
    // create local course folder
    OlatRootFolderImpl isolatedCourseFolder = new OlatRootFolderImpl(courseRootContainer.getRelPath() + File.separator + COURSEFOLDER, null);
    // generate course folder
    File fCourseFolder = isolatedCourseFolder.getBasefile();
    if (!fCourseFolder.exists() && !fCourseFolder.mkdirs()) {
        throw new OLATRuntimeException(this.getClass(), "could not create course's coursefolder path:" + fCourseFolder.getAbsolutePath(), null);
    }
    FullAccessWithQuotaCallback secCallback = new FullAccessWithLazyQuotaCallback(isolatedCourseFolder.getRelPath(), QuotaConstants.IDENTIFIER_DEFAULT_COURSE);
    isolatedCourseFolder.setLocalSecurityCallback(secCallback);
    return isolatedCourseFolder;
}
Also used : FullAccessWithLazyQuotaCallback(org.olat.core.util.vfs.callbacks.FullAccessWithLazyQuotaCallback) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) FullAccessWithQuotaCallback(org.olat.core.util.vfs.callbacks.FullAccessWithQuotaCallback) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) File(java.io.File)

Example 7 with OlatRootFolderImpl

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

the class VFSManager method resolveFile.

/**
 * @see org.olat.core.util.vfs.VFSItem#resolveFile(java.lang.String)
 */
public static VFSItem resolveFile(VFSContainer rootContainer, String path) {
    path = VFSManager.sanitizePath(path);
    if (path.equals("/")) {
        // slash or empty path -> return this vfsitem
        return rootContainer;
    }
    // to be returned as, the proper type of, VFSItem.
    if (rootContainer instanceof LocalFolderImpl) {
        String childName = extractChild(path);
        LocalFolderImpl l = (LocalFolderImpl) rootContainer;
        File t = new File(l.getBasefile().getAbsolutePath(), childName);
        if (t.exists()) {
            String bcroot = FolderConfig.getCanonicalRoot();
            String fsPath = t.getAbsolutePath();
            if (t.isDirectory()) {
                VFSContainer subContainer;
                if (fsPath.startsWith(bcroot)) {
                    fsPath = fsPath.substring(bcroot.length(), fsPath.length());
                    subContainer = new OlatRootFolderImpl(fsPath, rootContainer);
                } else {
                    subContainer = new LocalFolderImpl(t, rootContainer);
                }
                String subPath = path.substring(childName.length() + 1);
                return resolveFile(subContainer, subPath);
            } else {
                if (fsPath.startsWith(bcroot)) {
                    fsPath = fsPath.replace(bcroot, "");
                    return new OlatRootFileImpl(fsPath, rootContainer);
                } else {
                    return new LocalFileImpl(t, rootContainer);
                }
            }
        } else {
            return null;
        }
    }
    // leave original code block as fall-back for non-file-system-based implementations
    String childName = extractChild(path);
    List<VFSItem> children = rootContainer.getItems();
    for (VFSItem child : children) {
        String curName = child.getName();
        if (childName.equals(curName)) {
            // found , let child further resolve if needed
            return child.resolve(path.substring(childName.length() + 1));
        }
    }
    return null;
}
Also used : OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) OlatRootFileImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFileImpl) File(java.io.File) ContainerAndFile(org.olat.core.util.vfs.util.ContainerAndFile)

Example 8 with OlatRootFolderImpl

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

the class QuotaImpl method getRemainingSpace.

public Long getRemainingSpace() {
    long quotaKB = getQuotaKB().longValue();
    long remainingQuotaKB;
    if (quotaKB == Quota.UNLIMITED) {
        remainingQuotaKB = quotaKB;
    } else {
        OlatRootFolderImpl container = new OlatRootFolderImpl(path, null);
        long actualUsage = VFSManager.getUsageKB(container);
        if (quotaKB - actualUsage < 0) {
            remainingQuotaKB = 0l;
        } else {
            remainingQuotaKB = quotaKB - actualUsage;
        }
    }
    return new Long(remainingQuotaKB);
}
Also used : OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)

Example 9 with OlatRootFolderImpl

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

the class CollaborationTools method deleteTools.

/**
 * delete all CollaborationTools stuff from the database, which is related to
 * the calling OLATResourceable.
 */
public void deleteTools(BusinessGroup businessGroupTodelete) {
    NarrowedPropertyManager npm = NarrowedPropertyManager.getInstance(ores);
    /*
		 * delete the forum, if existing
		 */
    ForumManager fom = ForumManager.getInstance();
    Property forumKeyProperty = npm.findProperty(null, null, PROP_CAT_BG_COLLABTOOLS, KEY_FORUM);
    if (forumKeyProperty != null) {
        // if there was a forum, delete it
        Long forumKey = forumKeyProperty.getLongValue();
        if (forumKey == null)
            throw new AssertException("property had no longValue, prop:" + forumKeyProperty);
        fom.deleteForum(forumKey);
    }
    /*
		 * delete the folder, if existing
		 */
    OlatRootFolderImpl vfsContainer = new OlatRootFolderImpl(getFolderRelPath(), null);
    File fFolderRoot = vfsContainer.getBasefile();
    if (fFolderRoot.exists()) {
        FileUtils.deleteDirsAndFiles(fFolderRoot, true, true);
    }
    /*
		 * delete the wiki if existing
		 */
    VFSContainer rootContainer = WikiManager.getInstance().getWikiRootContainer(ores);
    if (rootContainer != null)
        rootContainer.delete();
    /*
		 * Delete calendar if exists
		 */
    if (businessGroupTodelete != null) {
        CoreSpringFactory.getImpl(ImportToCalendarManager.class).deleteGroupImportedCalendars(businessGroupTodelete);
        CoreSpringFactory.getImpl(CalendarManager.class).deleteGroupCalendar(businessGroupTodelete);
    }
    /*
		 * delete chatRoom
		 */
    // no cleanup needed, automatically done when last user exits the room
    /*
		 * delete all Properties defining enabled/disabled CollabTool XY and the
		 * news content
		 */
    npm.deleteProperties(null, null, PROP_CAT_BG_COLLABTOOLS, null);
    /*
		 * Delete OpenMeetings room
		 */
    OpenMeetingsModule omModule = CoreSpringFactory.getImpl(OpenMeetingsModule.class);
    if (omModule.isEnabled()) {
        OpenMeetingsManager omManager = CoreSpringFactory.getImpl(OpenMeetingsManager.class);
        try {
            omManager.deleteAll(ores, null, null);
        } catch (OpenMeetingsException e) {
            log.error("A room could not be deleted for group: " + ores, e);
        }
    }
    /*
		 * and last but not least the cache is reseted
		 */
    cacheToolStates.clear();
    this.dirty = true;
}
Also used : AssertException(org.olat.core.logging.AssertException) VFSContainer(org.olat.core.util.vfs.VFSContainer) OpenMeetingsModule(org.olat.modules.openmeetings.OpenMeetingsModule) ImportToCalendarManager(org.olat.commons.calendar.manager.ImportToCalendarManager) ImportToCalendarManager(org.olat.commons.calendar.manager.ImportToCalendarManager) CalendarManager(org.olat.commons.calendar.CalendarManager) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) ForumManager(org.olat.modules.fo.manager.ForumManager) OpenMeetingsException(org.olat.modules.openmeetings.manager.OpenMeetingsException) NarrowedPropertyManager(org.olat.properties.NarrowedPropertyManager) Property(org.olat.properties.Property) File(java.io.File) OpenMeetingsManager(org.olat.modules.openmeetings.manager.OpenMeetingsManager)

Example 10 with OlatRootFolderImpl

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

the class TaskFolderCallback method event.

/**
 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
 */
@Override
public void event(UserRequest urequest, Controller source, Event event) {
    if (source == modulesForm) {
        boolean onoff = event.getCommand().endsWith("true");
        if (event.getCommand().startsWith("task")) {
            config.set(TACourseNode.CONF_TASK_ENABLED, new Boolean(onoff));
            myTabbedPane.setEnabled(taskTabPosition, onoff);
            if (onoff) {
                accessabilityVC.put("taskCondition", taskConditionC.getInitialComponent());
            } else {
                accessabilityVC.remove(taskConditionC.getInitialComponent());
            }
        } else if (event.getCommand().startsWith("dropbox")) {
            config.set(TACourseNode.CONF_DROPBOX_ENABLED, new Boolean(onoff));
            myTabbedPane.setEnabled(dropboxTabPosition, onoff);
            if (onoff) {
                accessabilityVC.put("dropCondition", dropConditionC.getInitialComponent());
            } else {
                accessabilityVC.remove(dropConditionC.getInitialComponent());
            }
        } else if (event.getCommand().startsWith("returnbox")) {
            config.set(TACourseNode.CONF_RETURNBOX_ENABLED, new Boolean(onoff));
            if (onoff) {
                accessabilityVC.put("returnboxCondition", returnboxConditionC.getInitialComponent());
            } else {
                accessabilityVC.remove(returnboxConditionC.getInitialComponent());
            }
        } else if (event.getCommand().startsWith("scoring")) {
            config.set(TACourseNode.CONF_SCORING_ENABLED, new Boolean(onoff));
            myTabbedPane.setEnabled(scoringTabPosition, onoff);
            if (onoff) {
                accessabilityVC.put("scoringCondition", scoringConditionC.getInitialComponent());
            } else {
                accessabilityVC.remove(scoringConditionC.getInitialComponent());
            }
        } else if (event.getCommand().startsWith("solution")) {
            config.set(TACourseNode.CONF_SOLUTION_ENABLED, new Boolean(onoff));
            myTabbedPane.setEnabled(solutionTabPosition, onoff);
            if (onoff) {
                accessabilityVC.put("solutionCondition", solutionConditionC.getInitialComponent());
            } else {
                accessabilityVC.remove(solutionConditionC.getInitialComponent());
            }
        }
        fireEvent(urequest, NodeEditController.NODECONFIG_CHANGED_EVENT);
        return;
    } else if (source == taskConditionC) {
        if (event == Event.CHANGED_EVENT) {
            node.setConditionTask(taskConditionC.getCondition());
            fireEvent(urequest, NodeEditController.NODECONFIG_CHANGED_EVENT);
        }
    } else if (source == dropConditionC) {
        if (event == Event.CHANGED_EVENT) {
            node.setConditionDrop(dropConditionC.getCondition());
            fireEvent(urequest, NodeEditController.NODECONFIG_CHANGED_EVENT);
        }
    } else if (source == returnboxConditionC) {
        if (event == Event.CHANGED_EVENT) {
            node.setConditionReturnbox(returnboxConditionC.getCondition());
            fireEvent(urequest, NodeEditController.NODECONFIG_CHANGED_EVENT);
        }
    } else if (source == scoringConditionC) {
        if (event == Event.CHANGED_EVENT) {
            node.setConditionScoring(scoringConditionC.getCondition());
            fireEvent(urequest, NodeEditController.NODECONFIG_CHANGED_EVENT);
        }
    } else if (source == solutionConditionC) {
        if (event == Event.CHANGED_EVENT) {
            node.setConditionSolution(solutionConditionC.getCondition());
            fireEvent(urequest, NodeEditController.NODECONFIG_CHANGED_EVENT);
        }
    } else if (source == dialogBoxController) {
        if (DialogBoxUIFactory.isOkEvent(event)) {
            // ok: open task folder
            String relPath = TACourseNode.getTaskFolderPathRelToFolderRoot(course, node);
            OlatRootFolderImpl rootFolder = new OlatRootFolderImpl(relPath, null);
            OlatNamedContainerImpl namedFolder = new OlatNamedContainerImpl(translate("taskfolder"), rootFolder);
            namedFolder.setLocalSecurityCallback(getTaskFolderSecCallback(relPath));
            frc = new FolderRunController(namedFolder, false, urequest, getWindowControl());
            listenTo(frc);
            CloseableModalController cmc = new CloseableModalController(getWindowControl(), translate("folder.close"), frc.getInitialComponent());
            cmc.activate();
            fireEvent(urequest, Event.CHANGED_EVENT);
        }
    } else if (source == taskController) {
        if (event == Event.CANCELLED_EVENT) {
            return;
        } else if (event == Event.DONE_EVENT) {
            config.set(TACourseNode.CONF_TASK_TYPE, taskController.getTaskType());
            config.set(TACourseNode.CONF_TASK_TEXT, taskController.getOptionalText());
            config.set(TACourseNode.CONF_TASK_SAMPLING_WITH_REPLACEMENT, new Boolean(taskController.getIsSamplingWithReplacement()));
            config.setBooleanEntry(TACourseNode.CONF_TASK_PREVIEW, taskController.isTaskPreviewMode());
            config.setBooleanEntry(TACourseNode.CONF_TASK_DESELECT, taskController.isTaskDeselectMode());
            fireEvent(urequest, NodeEditController.NODECONFIG_CHANGED_EVENT);
            return;
        }
    } else if (source == scoringController) {
        if (event == Event.CANCELLED_EVENT) {
            if (hasLogEntries) {
                scoringController.setDisplayOnly(true);
            }
            editScoring.contextPut("isOverwriting", new Boolean(false));
            return;
        } else if (event == Event.DONE_EVENT) {
            scoringController.updateModuleConfiguration(config);
            fireEvent(urequest, NodeEditController.NODECONFIG_CHANGED_EVENT);
        }
    } else if (source == dropboxForm) {
        if (event == Event.CANCELLED_EVENT) {
            return;
        } else if (event == Event.DONE_EVENT) {
            config.set(TACourseNode.CONF_DROPBOX_ENABLEMAIL, new Boolean(dropboxForm.mailEnabled()));
            config.set(TACourseNode.CONF_DROPBOX_CONFIRMATION, dropboxForm.getConfirmation());
            fireEvent(urequest, NodeEditController.NODECONFIG_CHANGED_EVENT);
            return;
        }
    } else if (source == frc && (event instanceof FolderEvent) && event.getCommand().equals(FolderEvent.DELETE_EVENT)) {
        String deletedTaskFile = getFileListAsComaSeparated(((FolderEvent) event).getFilename());
        // cancel task assignment
        identitiesToBeNotified = removeAssignedTask(course, deletedTaskFile);
        if (identitiesToBeNotified.size() > 0) {
            // prepare mailTemplate if they are any identities to be notified
            removeAsListenerAndDispose(mailCtr);
            RepositoryEntry repositoryEntry = RepositoryManager.getInstance().lookupRepositoryEntry(course, true);
            String courseURL = Settings.getServerContextPathURI() + "/url/RepositoryEntry/" + repositoryEntry.getKey();
            MailTemplate mailTemplate = this.createTaskDeletedMailTemplate(urequest, course.getCourseTitle(), courseURL, deletedTaskFile);
            mailCtr = new MailNotificationEditController(getWindowControl(), urequest, mailTemplate, true, false, true);
            listenTo(mailCtr);
            cmc = new CloseableModalController(getWindowControl(), translate("close"), mailCtr.getInitialComponent());
            listenTo(cmc);
            cmc.activate();
        }
    } else if (source == mailCtr) {
        if (event == Event.DONE_EVENT) {
            cmc.deactivate();
            if (identitiesToBeNotified != null && identitiesToBeNotified.size() > 0) {
                // sent email to all identities that used to have the deleted task assigned
                sendNotificationEmail(urequest, mailCtr.getMailTemplate(), identitiesToBeNotified);
            }
        } else if (event == Event.CANCELLED_EVENT) {
            cmc.deactivate();
        }
    } else {
        log.warn("Can not handle event in TACourseNodeEditController source=" + source + " " + event.toString());
    }
}
Also used : OlatNamedContainerImpl(org.olat.core.commons.modules.bc.vfs.OlatNamedContainerImpl) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) FolderRunController(org.olat.core.commons.modules.bc.FolderRunController) MailTemplate(org.olat.core.util.mail.MailTemplate) FolderEvent(org.olat.core.commons.modules.bc.FolderEvent) RepositoryEntry(org.olat.repository.RepositoryEntry) MailNotificationEditController(org.olat.core.util.mail.MailNotificationEditController)

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