Search in sources :

Example 46 with VFSItem

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

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

the class QTIQPoolServiceProvider method importBeecomItem.

public QuestionItemImpl importBeecomItem(Identity owner, ItemAndMetadata itemAndMetadata, VFSContainer sourceDir, Locale defaultLocale) {
    QTIImportProcessor processor = new QTIImportProcessor(owner, defaultLocale);
    String editor = null;
    String editorVersion = null;
    Item item = itemAndMetadata.getItem();
    if (!item.isAlient()) {
        editor = "OpenOLAT";
        editorVersion = Settings.getVersion();
    }
    Document doc = QTIEditHelper.itemToXml(item);
    Element itemEl = (Element) doc.selectSingleNode("questestinterop/item");
    QuestionItemImpl qitem = processor.processItem(itemEl, "", null, editor, editorVersion, null, itemAndMetadata);
    // save to file System
    VFSContainer baseDir = qpoolFileStorage.getContainer(qitem.getDirectory());
    VFSLeaf leaf = baseDir.createChildLeaf(qitem.getRootFilename());
    QTIEditHelper.serialiazeDoc(doc, leaf);
    if (sourceDir != null) {
        List<String> materials = processor.getMaterials(itemEl);
        // copy materials
        for (String material : materials) {
            VFSItem sourceItem = sourceDir.resolve(material);
            if (sourceItem instanceof VFSLeaf) {
                VFSLeaf targetItem = baseDir.createChildLeaf(material);
                VFSManager.copyContent((VFSLeaf) sourceItem, targetItem);
            }
        }
    }
    return qitem;
}
Also used : Item(org.olat.ims.qti.editor.beecom.objects.Item) VFSItem(org.olat.core.util.vfs.VFSItem) QuestionItem(org.olat.modules.qpool.QuestionItem) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) Element(org.dom4j.Element) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) Document(org.dom4j.Document)

Example 48 with VFSItem

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

the class QTIQPoolServiceProvider method extractTextContent.

@Override
public String extractTextContent(QuestionItemFull item) {
    String content = null;
    if (item.getRootFilename() != null) {
        String dir = item.getDirectory();
        VFSContainer container = qpoolFileStorage.getContainer(dir);
        VFSItem file = container.resolve(item.getRootFilename());
        if (file instanceof VFSLeaf) {
            VFSLeaf leaf = (VFSLeaf) file;
            InputStream is = leaf.getInputStream();
            QTI12SAXHandler handler = new QTI12SAXHandler();
            try {
                XMLReader parser = XMLReaderFactory.createXMLReader();
                parser.setContentHandler(handler);
                parser.setEntityResolver(new IMSEntityResolver());
                parser.setFeature("http://xml.org/sax/features/validation", false);
                parser.parse(new InputSource(is));
            } catch (Exception e) {
                log.error("", e);
            } finally {
                FileUtils.closeSafely(is);
            }
            return handler.toString();
        }
    }
    return content;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) InputSource(org.xml.sax.InputSource) InputStream(java.io.InputStream) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) IMSEntityResolver(org.olat.ims.resources.IMSEntityResolver) XMLReader(org.xml.sax.XMLReader)

Example 49 with VFSItem

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

the class AssignmentEditController method updateAssignmentDocumentForm.

protected void updateAssignmentDocumentForm(UserRequest ureq) {
    if (mapperUri == null) {
        mapperUri = registerCacheableMapper(ureq, "assigment-" + CodeHelper.getRAMUniqueID(), new DocumentMapper());
        filesLayout.contextPut("mapperUri", mapperUri);
    }
    List<VFSItem> files = new ArrayList<>();
    if (assignment != null && StringHelper.containsNonWhitespace(assignment.getStorage())) {
        documentContainer = fileStorage.getAssignmentContainer(assignment);
        files.addAll(documentContainer.getItems(new SystemItemFilter()));
    }
    // add files from TempFolder
    if (tempUploadFolder != null) {
        files.addAll(tempUploadFolder.getItems(new SystemItemFilter()));
    }
    Collections.sort(files, new Comparator<VFSItem>() {

        final Collator c = Collator.getInstance(getLocale());

        @Override
        public int compare(final VFSItem o1, final VFSItem o2) {
            return c.compare((o1).getName(), (o2).getName());
        }
    });
    filesLayout.contextPut("files", files);
    // add delete links for each attachment if user is allowed to see them
    int count = 0;
    for (VFSItem file : files) {
        FormLink deleteLink = uifactory.addFormLink("delete_" + (++count), filesLayout, Link.BUTTON_XSMALL);
        deleteLink.setUserObject(file);
        deleteLink.setI18nKey("delete");
    }
    boolean hasFile = files.size() > 0;
    filesLayout.setVisible(files.size() > 0);
    filesLayout.showLabel(hasFile);
    documentUploadEl.showLabel(!hasFile);
}
Also used : ArrayList(java.util.ArrayList) VFSItem(org.olat.core.util.vfs.VFSItem) SystemItemFilter(org.olat.core.util.vfs.filters.SystemItemFilter) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) Collator(java.text.Collator)

Example 50 with VFSItem

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

the class AssignmentEditController method persistUploadedFiles.

private void persistUploadedFiles() {
    if (tempUploadFolder == null)
        return;
    VFSContainer container = portfolioFileStorage.getAssignmentContainer(assignment);
    if (container != null) {
        List<VFSItem> tmpFList = tempUploadFolder.getItems(new SystemItemFilter());
        for (VFSItem file : tmpFList) {
            try {
                VFSLeaf leaf = (VFSLeaf) file;
                VFSLeaf storedFile = container.createChildLeaf(leaf.getName());
                FileUtils.bcopy(leaf.getInputStream(), storedFile.getOutputStream(false), "");
            } catch (Exception e) {
                logError("", e);
            }
        }
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) SystemItemFilter(org.olat.core.util.vfs.filters.SystemItemFilter)

Aggregations

VFSItem (org.olat.core.util.vfs.VFSItem)546 VFSContainer (org.olat.core.util.vfs.VFSContainer)356 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)272 File (java.io.File)78 Test (org.junit.Test)68 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)68 ArrayList (java.util.ArrayList)64 InputStream (java.io.InputStream)52 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)52 Identity (org.olat.core.id.Identity)50 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)48 IOException (java.io.IOException)42 Date (java.util.Date)40 URI (java.net.URI)38 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)38 SystemItemFilter (org.olat.core.util.vfs.filters.SystemItemFilter)34 OutputStream (java.io.OutputStream)30 VFSMediaResource (org.olat.core.util.vfs.VFSMediaResource)28 HttpResponse (org.apache.http.HttpResponse)22 URL (java.net.URL)20