Search in sources :

Example 96 with VFSContainer

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

the class PFCourseNode method createPeekViewRunController.

@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;
    OlatRootFolderImpl 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());
    } else if (userCourseEnv.isParticipant()) {
        folderRelPath = Paths.get(baseContainer.getBasefile().toPath().toString(), PFManager.FILENAME_PARTICIPANTFOLDER, getIdent(), pfManager.getIdFolderName(identity));
        rootFolder = new LocalFolderImpl(folderRelPath.toFile());
    }
    if (rootFolder == null) {
        return super.createPeekViewRunController(ureq, wControl, userCourseEnv, ne);
    } else {
        return new PFPeekviewController(ureq, wControl, rootFolder, getIdent(), 4);
    }
}
Also used : Path(java.nio.file.Path) PFManager(org.olat.course.nodes.pf.manager.PFManager) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) VFSContainer(org.olat.core.util.vfs.VFSContainer) PFPeekviewController(org.olat.course.nodes.pf.ui.PFPeekviewController) Identity(org.olat.core.id.Identity) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 97 with VFSContainer

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

the class CheckListRunController method forgeCheckboxWrapper.

private CheckboxWrapper forgeCheckboxWrapper(Checkbox checkbox, DBCheck check, boolean readOnly, FormItemContainer formLayout) {
    String[] values = new String[] { translate(checkbox.getLabel().i18nKey()) };
    boolean canCheck = CheckboxReleaseEnum.userAndCoach.equals(checkbox.getRelease());
    String boxId = "box_" + checkbox.getCheckboxId();
    MultipleSelectionElement el = uifactory.addCheckboxesHorizontal(boxId, null, formLayout, onKeys, values);
    el.setEnabled(canCheck && !readOnly && !userCourseEnv.isCourseReadOnly());
    el.addActionListener(FormEvent.ONCHANGE);
    DownloadLink downloadLink = null;
    if (StringHelper.containsNonWhitespace(checkbox.getFilename())) {
        VFSContainer container = checkboxManager.getFileContainer(userCourseEnv.getCourseEnvironment(), courseNode);
        VFSItem item = container.resolve(checkbox.getFilename());
        if (item instanceof VFSLeaf) {
            String name = "file_" + checkbox.getCheckboxId();
            downloadLink = uifactory.addDownloadLink(name, checkbox.getFilename(), null, (VFSLeaf) item, formLayout);
        }
    }
    CheckboxWrapper wrapper = new CheckboxWrapper(checkbox, downloadLink, el);
    el.setUserObject(wrapper);
    if (check != null && check.getChecked() != null && check.getChecked().booleanValue()) {
        el.select(onKeys[0], true);
        wrapper.setDbCheckbox(check.getCheckbox());
        wrapper.setScore(check.getScore());
    }
    if (downloadLink != null) {
        downloadLink.setUserObject(wrapper);
    }
    return wrapper;
}
Also used : DownloadLink(org.olat.core.gui.components.form.flexible.elements.DownloadLink) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem)

Example 98 with VFSContainer

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

the class CheckboxEditController method getFileContainer.

private VFSContainer getFileContainer() {
    VFSContainer container;
    if (courseNode == null) {
        File tmp = new File(FolderConfig.getCanonicalTmpDir(), checkbox.getCheckboxId());
        container = new LocalFolderImpl(tmp);
    } else {
        ICourse course = CourseFactory.loadCourse(courseOres);
        CourseEnvironment courseEnv = course.getCourseEnvironment();
        container = checkboxManager.getFileContainer(courseEnv, courseNode);
    }
    return container;
}
Also used : CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) VFSContainer(org.olat.core.util.vfs.VFSContainer) ICourse(org.olat.course.ICourse) File(java.io.File) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 99 with VFSContainer

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

the class CheckboxEditController method doDownloadFile.

private void doDownloadFile(UserRequest ureq) {
    VFSContainer container = getFileContainer();
    VFSItem item = container.resolve(checkbox.getFilename());
    if (item instanceof VFSLeaf) {
        VFSMediaResource rsrc = new VFSMediaResource((VFSLeaf) item);
        rsrc.setDownloadable(true);
        ureq.getDispatchResult().setResultingMediaResource(rsrc);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Example 100 with VFSContainer

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

the class CheckboxEditController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    checkbox.setTitle(titleEl.getValue());
    String releaseKey = releaseEl.getSelectedKey();
    checkbox.setRelease(CheckboxReleaseEnum.valueOf(releaseKey));
    String labelKey = labelEl.getSelectedKey();
    checkbox.setLabel(CheckboxLabelEnum.valueOf(labelKey));
    if (awardPointEl.isAtLeastSelected(1)) {
        Float points = null;
        try {
            points = new Float(Float.parseFloat(pointsEl.getValue()));
        } catch (NumberFormatException e) {
        // check in validation
        }
        checkbox.setPoints(points);
    } else {
        checkbox.setPoints(null);
    }
    checkbox.setDescription(descriptionEl.getValue());
    if (Boolean.TRUE.equals(deleteFile)) {
        checkbox.setFilename(null);
        VFSContainer container = getFileContainer();
        for (VFSItem chd : container.getItems()) {
            chd.delete();
        }
    }
    File uploadedFile = fileEl.getUploadFile();
    if (uploadedFile != null) {
        String filename = fileEl.getUploadFileName();
        checkbox.setFilename(filename);
        VFSContainer container = getFileContainer();
        VFSLeaf leaf = container.createChildLeaf(filename);
        try (InputStream inStream = new FileInputStream(uploadedFile)) {
            VFSManager.copyContent(inStream, leaf);
        } catch (IOException e) {
            logError("", e);
        }
    }
    if (courseNode != null) {
        ILoggingAction action = newCheckbox ? CourseLoggingAction.CHECKLIST_CHECKBOX_CREATED : CourseLoggingAction.CHECKLIST_CHECKBOX_UPDATED;
        ThreadLocalUserActivityLogger.log(action, getClass(), LoggingResourceable.wrap(courseNode), LoggingResourceable.wrapNonOlatResource(StringResourceableType.checkbox, checkbox.getCheckboxId(), checkbox.getTitle()));
    }
    fireEvent(ureq, Event.CHANGED_EVENT);
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) VFSContainer(org.olat.core.util.vfs.VFSContainer) ILoggingAction(org.olat.core.logging.activity.ILoggingAction) VFSItem(org.olat.core.util.vfs.VFSItem) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

VFSContainer (org.olat.core.util.vfs.VFSContainer)962 VFSItem (org.olat.core.util.vfs.VFSItem)364 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)338 File (java.io.File)170 Test (org.junit.Test)136 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)86 Identity (org.olat.core.id.Identity)86 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)76 RepositoryEntry (org.olat.repository.RepositoryEntry)76 IOException (java.io.IOException)74 InputStream (java.io.InputStream)64 ArrayList (java.util.ArrayList)64 Date (java.util.Date)60 URI (java.net.URI)56 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)42 OutputStream (java.io.OutputStream)40 HttpResponse (org.apache.http.HttpResponse)38 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)34 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)34 BlogFileResource (org.olat.fileresource.types.BlogFileResource)34