Search in sources :

Example 1 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)

Example 2 with OlatRootFolderImpl

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

the class ConvertToGTACourseNode method convertDropbox.

private void convertDropbox(TaskList taskList, TACourseNode sourceNode, GTACourseNode gtaNode, CourseEnvironment courseEnv) {
    String dropbox = DropboxController.getDropboxPathRelToFolderRoot(courseEnv, sourceNode);
    OlatRootFolderImpl dropboxContainer = new OlatRootFolderImpl(dropbox, null);
    for (VFSItem userDropbox : dropboxContainer.getItems()) {
        if (userDropbox instanceof VFSContainer) {
            VFSContainer userDropContainer = (VFSContainer) userDropbox;
            String username = userDropContainer.getName();
            Identity assessedIdentity = securityManager.findIdentityByName(username);
            if (assessedIdentity != null) {
                VFSContainer sumbitContainer = gtaManager.getSubmitContainer(courseEnv, gtaNode, assessedIdentity);
                boolean dropped = false;
                for (VFSItem dropppedItem : userDropContainer.getItems()) {
                    if (dropppedItem instanceof VFSLeaf) {
                        VFSLeaf submittedDocument = sumbitContainer.createChildLeaf(dropppedItem.getName());
                        VFSManager.copyContent((VFSLeaf) dropppedItem, submittedDocument);
                        convertMetada(userDropContainer, sumbitContainer, dropppedItem.getName(), null, null);
                        dropped = true;
                    }
                }
                if (dropped) {
                    setTaskStatus(taskList, assessedIdentity, TaskProcess.submit, gtaNode);
                }
            }
        }
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) Identity(org.olat.core.id.Identity)

Example 3 with OlatRootFolderImpl

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

the class BinderTemplateHandler method importResource.

@Override
public RepositoryEntry importResource(Identity initialAuthor, String initialAuthorAlt, String displayname, String description, boolean withReferences, Locale locale, File file, String filename) {
    RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
    PortfolioService portfolioService = CoreSpringFactory.getImpl(PortfolioService.class);
    try {
        // create resource
        OLATResource resource = portfolioService.createBinderTemplateResource();
        OlatRootFolderImpl fResourceRootContainer = FileResourceManager.getInstance().getFileResourceRootImpl(resource);
        File fResourceFileroot = fResourceRootContainer.getBasefile();
        File zipRoot = new File(fResourceFileroot, FileResourceManager.ZIPDIR);
        FileResource.copyResource(file, filename, zipRoot);
        // create repository entry
        RepositoryEntry re = repositoryService.create(initialAuthor, initialAuthorAlt, "", displayname, description, resource, RepositoryEntry.ACC_OWNERS);
        // import binder
        File binderFile = new File(zipRoot, BinderTemplateResource.BINDER_XML);
        Binder transientBinder = BinderXStream.fromPath(binderFile.toPath());
        File posterImage = null;
        if (StringHelper.containsNonWhitespace(transientBinder.getImagePath())) {
            posterImage = new File(zipRoot, transientBinder.getImagePath());
        }
        portfolioService.importBinder(transientBinder, re, posterImage);
        RepositoryEntryImportExport rei = new RepositoryEntryImportExport(re, zipRoot);
        if (rei.anyExportedPropertiesAvailable()) {
            re = rei.importContent(re, fResourceRootContainer.createChildContainer("media"));
        }
        // delete the imported files
        FileUtils.deleteDirsAndFiles(zipRoot, true, true);
        return re;
    } catch (IOException e) {
        log.error("", e);
        return null;
    }
}
Also used : Binder(org.olat.modules.portfolio.Binder) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) PortfolioService(org.olat.modules.portfolio.PortfolioService) RepositoryEntryImportExport(org.olat.repository.RepositoryEntryImportExport) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) IOException(java.io.IOException) File(java.io.File) RepositoryService(org.olat.repository.RepositoryService)

Example 4 with OlatRootFolderImpl

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

the class VersionManagerTest method testDeleteRevisions_withSameFile.

/**
 * The test create an original file and 3 revisions with exactly
 * the same content. We delete the original and the first version.
 * We check that version 2 and 3 survives and that the file exists.
 *
 * @throws IOException
 */
@Test
public void testDeleteRevisions_withSameFile() throws IOException {
    OlatRootFolderImpl rootTest = new OlatRootFolderImpl("/ver-" + UUID.randomUUID(), null);
    String filename = getRandomName();
    VFSLeaf file = rootTest.createChildLeaf(filename);
    OutputStream out = file.getOutputStream(false);
    InputStream in = VersionManagerTest.class.getResourceAsStream("test.txt");
    int byteCopied = IOUtils.copy(in, out);
    IOUtils.closeQuietly(in);
    assertFalse(byteCopied == 0);
    assertTrue(file instanceof Versionable);
    // save a first version
    Versionable versionedFile = (Versionable) file;
    InputStream in1 = VersionManagerTest.class.getResourceAsStream("test.txt");
    versionedFile.getVersions().addVersion(id2, "Version 1", in1);
    IOUtils.closeQuietly(in1);
    // save a second version
    InputStream in2 = VersionManagerTest.class.getResourceAsStream("test.txt");
    versionedFile.getVersions().addVersion(id2, "Version 2", in2);
    IOUtils.closeQuietly(in2);
    // save a third version
    InputStream in3 = VersionManagerTest.class.getResourceAsStream("test.txt");
    versionedFile.getVersions().addVersion(id2, "Version 3", in2);
    IOUtils.closeQuietly(in3);
    // delete revisions
    versionManager.deleteRevisions(versionedFile, versionedFile.getVersions().getRevisions().subList(0, 2));
    // check number of versions
    VFSItem reloadFile = rootTest.resolve(filename);
    assertTrue(reloadFile instanceof Versionable);
    Versionable reloadedVersionedFile = (Versionable) reloadFile;
    List<VFSRevision> revisions = reloadedVersionedFile.getVersions().getRevisions();
    Assert.assertNotNull(revisions);
    Assert.assertEquals(1, revisions.size());
    // check surviving versions
    Assert.assertEquals("Version 2", revisions.get(0).getComment());
    Assert.assertEquals("Version 3", reloadedVersionedFile.getVersions().getComment());
    // check that the last backup file exists
    RevisionFileImpl revision2 = (RevisionFileImpl) revisions.get(0);
    VFSLeaf revision2File = revision2.getFile();
    Assert.assertNotNull(revision2File);
    Assert.assertTrue(revision2File.exists());
    // check if there is only one backup file
    VFSContainer versionContainer = versionManager.getCanonicalVersionFolder(file.getParentContainer(), false);
    Assert.assertNotNull(versionContainer);
    List<VFSItem> items = versionContainer.getItems(new SystemItemFilter());
    Assert.assertNotNull(items);
    Assert.assertEquals(2, items.size());
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) SystemItemFilter(org.olat.core.util.vfs.filters.SystemItemFilter) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) Test(org.junit.Test)

Example 5 with OlatRootFolderImpl

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

the class VersionManagerTest method testAuthorsAndCreators.

@Test
public void testAuthorsAndCreators() throws IOException {
    // create a file
    OlatRootFolderImpl rootTest = new OlatRootFolderImpl("/test2", null);
    String filename = getRandomName();
    VFSLeaf file = rootTest.createChildLeaf(filename);
    OutputStream out = file.getOutputStream(false);
    InputStream in = VersionManagerTest.class.getResourceAsStream("test.txt");
    int byteCopied = IOUtils.copy(in, out);
    IOUtils.closeQuietly(in);
    assertFalse(byteCopied == 0);
    assertTrue(file instanceof Versionable);
    assertTrue(file instanceof MetaTagged);
    // set the author
    MetaTagged metaTagged = (MetaTagged) file;
    MetaInfo metaInfo = metaTagged.getMetaInfo();
    metaInfo.setAuthor(id1);
    metaInfo.setCreator(id1.getName());
    metaInfo.write();
    // save a first version -> id2
    Versionable versionedFile1 = (Versionable) file;
    InputStream in1 = new ByteArrayInputStream("Hello version 1".getBytes());
    versionedFile1.getVersions().addVersion(id2, "Version 1", in1);
    IOUtils.closeQuietly(in1);
    // save a second version -> id1
    Versionable versionedFile2 = (Versionable) file;
    InputStream in2 = new ByteArrayInputStream("Hello version 2".getBytes());
    versionedFile2.getVersions().addVersion(id1, "Version 2", in2);
    IOUtils.closeQuietly(in2);
    // save a third version -> id2
    Versionable versionedFile3 = (Versionable) file;
    InputStream in3 = new ByteArrayInputStream("Hello version 3".getBytes());
    versionedFile3.getVersions().addVersion(id2, "Version 3", in3);
    IOUtils.closeQuietly(in3);
    // make the checks
    VFSItem retrievedFile = rootTest.resolve(filename);
    assertTrue(retrievedFile instanceof Versionable);
    Versions versions = versionManager.createVersionsFor((VFSLeaf) retrievedFile);
    List<VFSRevision> revisions = versions.getRevisions();
    assertNotNull(revisions);
    assertEquals(3, revisions.size());
    assertTrue(retrievedFile instanceof MetaTagged);
    VFSRevision revision0 = revisions.get(0);
    // we don't set an author for the original file
    assertEquals(id1.getName(), revision0.getAuthor());
    VFSRevision revision1 = revisions.get(1);
    assertEquals(id2.getName(), revision1.getAuthor());
    VFSRevision revision2 = revisions.get(2);
    assertEquals(id1.getName(), revision2.getAuthor());
    // current
    assertEquals(id2.getName(), versions.getAuthor());
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) VFSItem(org.olat.core.util.vfs.VFSItem) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

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