Search in sources :

Example 21 with OlatNamedContainerImpl

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

the class CoursesFoldersTest method testUploadFile.

@Test
public void testUploadFile() throws IOException, URISyntaxException {
    assertTrue(conn.login("administrator", "openolat"));
    URI uri = UriBuilder.fromUri(getNodeURI()).path("files").build();
    // create single page
    URL fileUrl = CoursesFoldersTest.class.getResource("singlepage.html");
    assertNotNull(fileUrl);
    File file = new File(fileUrl.toURI());
    HttpPut method = conn.createPut(uri, MediaType.APPLICATION_JSON, true);
    conn.addMultipart(method, file.getName(), file);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    OlatNamedContainerImpl folder = BCCourseNode.getNodeFolderContainer((BCCourseNode) bcNode, course1.getCourseEnvironment());
    VFSItem item = folder.resolve(file.getName());
    assertNotNull(item);
}
Also used : OlatNamedContainerImpl(org.olat.core.commons.modules.bc.vfs.OlatNamedContainerImpl) HttpResponse(org.apache.http.HttpResponse) VFSItem(org.olat.core.util.vfs.VFSItem) URI(java.net.URI) File(java.io.File) URL(java.net.URL) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 22 with OlatNamedContainerImpl

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

the class CollaborationTools method createFolderController.

/**
 * Creates a folder run controller with all rights enabled for everybody
 *
 * @param ureq
 * @param wControl
 * @param subsContext
 * @return Copnfigured FolderRunController
 */
public FolderRunController createFolderController(UserRequest ureq, WindowControl wControl, BusinessGroup businessGroup, boolean isAdmin, final SubscriptionContext subsContext) {
    // do not use a global translator since in the fututre a collaborationtools
    // may be shared among users
    Translator trans = Util.createPackageTranslator(this.getClass(), ureq.getLocale());
    OlatRootFolderImpl rootContainer = getSecuredFolder(businessGroup, subsContext, ureq.getIdentity(), isAdmin);
    OlatNamedContainerImpl namedContainer = new OlatNamedContainerImpl(trans.translate("folder"), rootContainer);
    FolderRunController frc = new FolderRunController(namedContainer, true, true, true, ureq, wControl);
    return frc;
}
Also used : OlatNamedContainerImpl(org.olat.core.commons.modules.bc.vfs.OlatNamedContainerImpl) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) Translator(org.olat.core.gui.translator.Translator) FolderRunController(org.olat.core.commons.modules.bc.FolderRunController)

Example 23 with OlatNamedContainerImpl

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

the class FileDocumentFactoryTest method testCreateHtmlDocument.

@Test
public void testCreateHtmlDocument() {
    String filePath = "SearchTestFolder";
    String htmlFileName = "test.html";
    String htmlText = "<html><head><meta name=\"generator\" content=\"olat-tinymce-1\"><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></head><body>" + "<H1>Test HTML Seite fuer JUnit Test</H1>" + "Dies ist<br />der Test&nbsp;Text" + // Text = 'Dies ist der Test Text'
    "</body></html>";
    // must include '\u00A0' !!! 19.5.2010/cg
    String text = "Test HTML Seite fuer JUnit Test Dies ist der Test\u00A0Text";
    // Create a test HTML File
    OlatRootFolderImpl rootFolder = new OlatRootFolderImpl(rootPath, null);
    OlatNamedContainerImpl namedFolder = new OlatNamedContainerImpl(filePath, rootFolder);
    VFSLeaf leaf = (VFSLeaf) namedFolder.resolve(htmlFileName);
    if (leaf != null) {
        leaf.delete();
    }
    leaf = namedFolder.createChildLeaf(htmlFileName);
    FileUtils.save(leaf.getOutputStream(false), htmlText, "utf-8");
    try {
        SearchResourceContext resourceContext = new SearchResourceContext();
        resourceContext.setBusinessControlFor(OresHelper.createOLATResourceableType("FileDocumentFactoryTest"));
        resourceContext.setFilePath(filePath + "/" + leaf.getName());
        Document htmlDocument = fileDocumentFactory.createDocument(resourceContext, leaf);
        // 1. Check content
        String content = htmlDocument.get(OlatDocument.CONTENT_FIELD_NAME);
        assertEquals("Wrong HTML content=" + content.trim() + " , must be =" + text.trim(), text.trim(), content.trim());
        // 2. Check resourceUrl
        String resourceUrl = htmlDocument.get(OlatDocument.RESOURCEURL_FIELD_NAME);
        assertEquals("Wrong ResourceUrl", "[FileDocumentFactoryTest:0][path=" + filePath + "/" + htmlFileName + "]", resourceUrl);
        // 3. Check File-Type
        String fileType = htmlDocument.get(OlatDocument.FILETYPE_FIELD_NAME);
        assertEquals("Wrong file-type", "type.file.html", fileType);
    } catch (IOException e) {
        fail("IOException=" + e.getMessage());
    } catch (DocumentAccessException e) {
        fail("DocumentAccessException=" + e.getMessage());
    }
}
Also used : OlatNamedContainerImpl(org.olat.core.commons.modules.bc.vfs.OlatNamedContainerImpl) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) SearchResourceContext(org.olat.search.service.SearchResourceContext) IOException(java.io.IOException) Document(org.apache.lucene.document.Document) OlatDocument(org.olat.search.model.OlatDocument) Test(org.junit.Test)

Example 24 with OlatNamedContainerImpl

use of org.olat.core.commons.modules.bc.vfs.OlatNamedContainerImpl 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.components.Component, org.olat.core.gui.control.Event)
 */
@Override
public void event(UserRequest ureq, Component source, Event event) {
    if (log.isDebug())
        log.debug("event source=" + source + " " + event.toString());
    if (source == btfButton) {
        // check if there are already assigned tasks
        CoursePropertyManager cpm = PersistingCoursePropertyManager.getInstance(course);
        List<Property> assignedProps = cpm.listCourseNodeProperties(node, null, null, TaskController.PROP_ASSIGNED);
        if (assignedProps.size() == 0) {
            // no task assigned
            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, ureq, getWindowControl());
            // listenTo(frc);
            frc.addControllerListener(this);
            CloseableModalController cmc = new CloseableModalController(getWindowControl(), translate("folder.close"), frc.getInitialComponent());
            cmc.activate();
        } else {
            // already assigned task => open dialog with warn
            String[] args = new String[] { new Integer(assignedProps.size()).toString() };
            dialogBoxController = activateOkCancelDialog(ureq, "", getTranslator().translate("taskfolder.overwriting.confirm", args), dialogBoxController);
        }
    } else if (source == vfButton) {
        // switch to new dialog
        OlatNamedContainerImpl namedContainer = TACourseNode.getNodeFolderContainer(node, course.getCourseEnvironment());
        Quota quota = QuotaManager.getInstance().getCustomQuota(namedContainer.getRelPath());
        if (quota == null) {
            Quota defQuota = QuotaManager.getInstance().getDefaultQuota(QuotaConstants.IDENTIFIER_DEFAULT_NODES);
            quota = QuotaManager.getInstance().createQuota(namedContainer.getRelPath(), defQuota.getQuotaKB(), defQuota.getUlLimitKB());
        }
        SubscriptionContext subContext = SolutionFileUploadNotificationHandler.getSubscriptionContext(course.getCourseEnvironment(), node);
        VFSSecurityCallback secCallback = new FullAccessWithQuotaCallback(quota, subContext);
        namedContainer.setLocalSecurityCallback(secCallback);
        FolderRunController folderCtrl = new FolderRunController(namedContainer, false, ureq, getWindowControl());
        CloseableModalController cmc = new CloseableModalController(getWindowControl(), translate("close"), folderCtrl.getInitialComponent());
        cmc.activate();
    } else if (source == editScoringConfigButton) {
        scoringController.setDisplayOnly(false);
        editScoring.contextPut("isOverwriting", new Boolean(true));
    }
}
Also used : CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) OlatNamedContainerImpl(org.olat.core.commons.modules.bc.vfs.OlatNamedContainerImpl) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) FullAccessWithQuotaCallback(org.olat.core.util.vfs.callbacks.FullAccessWithQuotaCallback) Quota(org.olat.core.util.vfs.Quota) FolderRunController(org.olat.core.commons.modules.bc.FolderRunController) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Property(org.olat.properties.Property) VFSSecurityCallback(org.olat.core.util.vfs.callbacks.VFSSecurityCallback) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager) PersistingCoursePropertyManager(org.olat.course.properties.PersistingCoursePropertyManager)

Example 25 with OlatNamedContainerImpl

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

the class ReturnboxFullAccessCallback method init.

protected void init(UserRequest ureq) {
    myContent = createVelocityContainer("dropboxscoring");
    taskLaunchButton = LinkFactory.createButton("task.launch", myContent, this);
    cancelTaskButton = LinkFactory.createButton("task.cancel", myContent, this);
    cancelTaskButton.setVisible(!userCourseEnv.isCourseReadOnly());
    putInitialPanel(myContent);
    ModuleConfiguration modConfig = node.getModuleConfiguration();
    Boolean bValue = (Boolean) modConfig.get(TACourseNode.CONF_TASK_ENABLED);
    myContent.contextPut("hasTask", (bValue != null) ? bValue : new Boolean(false));
    // configured value
    Boolean hasDropbox = (Boolean) modConfig.get(TACourseNode.CONF_DROPBOX_ENABLED);
    Boolean hasDropboxValue = (hasDropbox != null) ? hasDropbox : new Boolean(true);
    myContent.contextPut("hasDropbox", hasDropboxValue);
    Boolean hasReturnbox = (Boolean) modConfig.get(TACourseNode.CONF_RETURNBOX_ENABLED);
    myContent.contextPut("hasReturnbox", (hasReturnbox != null) ? hasReturnbox : hasDropboxValue);
    // dropbox display
    Identity assessee = userCourseEnv.getIdentityEnvironment().getIdentity();
    String assesseeName = assessee.getName();
    UserManager userManager = CoreSpringFactory.getImpl(UserManager.class);
    String assesseeFullName = StringHelper.escapeHtml(userManager.getUserDisplayName(assessee));
    // notification
    if (hasNotification) {
        subsContext = DropboxFileUploadNotificationHandler.getSubscriptionContext(userCourseEnv.getCourseEnvironment(), node);
        if (subsContext != null) {
            String path = DropboxController.getDropboxPathRelToFolderRoot(userCourseEnv.getCourseEnvironment(), node);
            contextualSubscriptionCtr = AbstractTaskNotificationHandler.createContextualSubscriptionController(ureq, this.getWindowControl(), path, subsContext, DropboxController.class);
            myContent.put("subscription", contextualSubscriptionCtr.getInitialComponent());
            myContent.contextPut("hasNotification", Boolean.TRUE);
        }
    } else {
        myContent.contextPut("hasNotification", Boolean.FALSE);
    }
    OlatRootFolderImpl rootDropbox = new OlatRootFolderImpl(getDropboxFilePath(assesseeName), null);
    rootDropbox.setLocalSecurityCallback(getDropboxVfsSecurityCallback());
    OlatNamedContainerImpl namedDropbox = new OlatNamedContainerImpl(assesseeFullName, rootDropbox);
    namedDropbox.setLocalSecurityCallback(getDropboxVfsSecurityCallback());
    dropboxFolderRunController = new FolderRunController(namedDropbox, false, ureq, getWindowControl());
    listenTo(dropboxFolderRunController);
    myContent.put("dropbox", dropboxFolderRunController.getInitialComponent());
    Identity assessedIdentity = userCourseEnv.getIdentityEnvironment().getIdentity();
    // returnbox display
    OlatRootFolderImpl rootReturnbox = new OlatRootFolderImpl(getReturnboxFilePath(assesseeName), null);
    VFSSecurityCallback secCallback = getReturnboxVfsSecurityCallback(rootReturnbox.getRelPath(), assessedIdentity);
    rootReturnbox.setLocalSecurityCallback(secCallback);
    OlatNamedContainerImpl namedReturnbox = new OlatNamedContainerImpl(assesseeFullName, rootReturnbox);
    namedReturnbox.setLocalSecurityCallback(secCallback);
    returnboxFolderRunController = new FolderRunController(namedReturnbox, false, ureq, getWindowControl());
    returnboxFolderRunController.disableSubscriptionController();
    listenTo(returnboxFolderRunController);
    myContent.put("returnbox", returnboxFolderRunController.getInitialComponent());
    // insert Status Pull-Down Menu depending on user role == author
    boolean isAuthor = ureq.getUserSession().getRoles().isAuthor();
    boolean isTutor = userCourseEnv.getCourseEnvironment().getCourseGroupManager().isIdentityCourseCoach(ureq.getIdentity());
    if (((AssessableCourseNode) node).hasStatusConfigured() && (isAuthor || isTutor)) {
        myContent.contextPut("hasStatusPullDown", Boolean.TRUE);
        statusForm = new StatusForm(ureq, getWindowControl(), userCourseEnv.isCourseReadOnly());
        listenTo(statusForm);
        // get identity not from request (this would be an author)
        StatusManager.getInstance().loadStatusFormData(statusForm, node, userCourseEnv);
        myContent.put("statusForm", statusForm.getInitialComponent());
    }
    assignedTask = TaskController.getAssignedTask(assessedIdentity, userCourseEnv.getCourseEnvironment(), node);
    if (assignedTask != null) {
        myContent.contextPut("assignedtask", assignedTask);
        myContent.contextPut("taskIcon", CSSHelper.createFiletypeIconCssClassFor(assignedTask));
        if (!(assignedTask.toLowerCase().endsWith(".html") || assignedTask.toLowerCase().endsWith(".htm") || assignedTask.toLowerCase().endsWith(".txt"))) {
            taskLaunchButton.setTarget("_blank");
        }
    }
}
Also used : OlatNamedContainerImpl(org.olat.core.commons.modules.bc.vfs.OlatNamedContainerImpl) ModuleConfiguration(org.olat.modules.ModuleConfiguration) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) UserManager(org.olat.user.UserManager) FolderRunController(org.olat.core.commons.modules.bc.FolderRunController) Identity(org.olat.core.id.Identity) VFSSecurityCallback(org.olat.core.util.vfs.callbacks.VFSSecurityCallback)

Aggregations

OlatNamedContainerImpl (org.olat.core.commons.modules.bc.vfs.OlatNamedContainerImpl)42 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)28 FolderRunController (org.olat.core.commons.modules.bc.FolderRunController)16 VFSItem (org.olat.core.util.vfs.VFSItem)12 Test (org.junit.Test)10 VFSContainer (org.olat.core.util.vfs.VFSContainer)10 VFSSecurityCallback (org.olat.core.util.vfs.callbacks.VFSSecurityCallback)10 URI (java.net.URI)8 HttpResponse (org.apache.http.HttpResponse)8 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)8 HttpPut (org.apache.http.client.methods.HttpPut)6 Quota (org.olat.core.util.vfs.Quota)6 FullAccessWithQuotaCallback (org.olat.core.util.vfs.callbacks.FullAccessWithQuotaCallback)6 ReadOnlyCallback (org.olat.core.util.vfs.callbacks.ReadOnlyCallback)6 File (java.io.File)4 IOException (java.io.IOException)4 URL (java.net.URL)4 Identity (org.olat.core.id.Identity)4 OLATResourceable (org.olat.core.id.OLATResourceable)4 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)4