Search in sources :

Example 86 with VFSItem

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

the class ProjectDetailsDisplayController method doFileDelivery.

private void doFileDelivery(UserRequest ureq, final Project project, final CourseEnvironment courseEnv, final CourseNode cNode) {
    // Create a mapper to deliver the auto-download of the file. We have to
    // create a dedicated mapper here
    // and can not reuse the standard briefcase way of file delivering, some
    // very old fancy code
    // Mapper is cleaned up automatically by basic controller
    OlatRootFolderImpl rootFolder = new OlatRootFolderImpl(projectBrokerManager.getAttamchmentRelativeRootPath(project, courseEnv, cNode), null);
    VFSItem item = rootFolder.resolve(project.getAttachmentFileName());
    if (item instanceof VFSLeaf) {
        VFSLeaf attachment = (VFSLeaf) item;
        MediaResource resource = new VFSMediaResource(attachment);
        ureq.getDispatchResult().setResultingMediaResource(resource);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) VFSItem(org.olat.core.util.vfs.VFSItem) MediaResource(org.olat.core.gui.media.MediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Example 87 with VFSItem

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

the class ProjectBrokerManagerImpl method saveAttachedFile.

public void saveAttachedFile(Project project, String fileName, VFSLeaf uploadedItem, CourseEnvironment courseEnv, CourseNode cNode) {
    logDebug("saveAttachedFile file-name=" + uploadedItem.getName());
    OlatRootFolderImpl uploadVFSContainer = new OlatRootFolderImpl(getAttamchmentRelativeRootPath(project, courseEnv, cNode), null);
    logDebug("saveAttachedFile uploadVFSContainer.relPath=" + uploadVFSContainer.getRelPath());
    // only one attachment, delete other file
    for (Iterator<VFSItem> iterator = uploadVFSContainer.getItems().iterator(); iterator.hasNext(); ) {
        VFSItem item = iterator.next();
        // Project.getAttachmentFileName is the previous file-name, will not be deleted; student could have open detail-project page with previous attachemnt-link
        if (!item.getName().equals(project.getAttachmentFileName())) {
            item.delete();
        }
    }
    VFSLeaf newFile = (VFSLeaf) uploadVFSContainer.resolve(fileName);
    if (newFile == null) {
        newFile = uploadVFSContainer.createChildLeaf(fileName);
    }
    BufferedInputStream in = new BufferedInputStream(uploadedItem.getInputStream());
    BufferedOutputStream out = new BufferedOutputStream(newFile.getOutputStream(false));
    boolean success = false;
    if (in != null) {
        success = FileUtils.copy(in, out);
    }
    FileUtils.closeSafely(in);
    FileUtils.closeSafely(out);
    logDebug("saveAttachedFile success=" + success);
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) BufferedInputStream(java.io.BufferedInputStream) VFSItem(org.olat.core.util.vfs.VFSItem) BufferedOutputStream(java.io.BufferedOutputStream)

Example 88 with VFSItem

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

the class MessageEditController method createOrUpdateAttachmentListLayout.

// adds or updates the list of already existing attachments with a delete
// button for each
private void createOrUpdateAttachmentListLayout(FormItemContainer formLayout) {
    FormItem attachLayout = formLayout.getFormComponent("attachLayout");
    List<VFSItem> attachments = new ArrayList<VFSItem>();
    // add already existing attachments:
    if (message.getKey() != null) {
        VFSContainer msgContainer = fm.getMessageContainer(message.getForum().getKey(), message.getKey());
        attachments.addAll(msgContainer.getItems(exclFilter));
    }
    // add files from TempFolder
    attachments.addAll(getTempFolderFileList());
    Collections.sort(attachments, new Comparator<VFSItem>() {

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

        public int compare(final VFSItem o1, final VFSItem o2) {
            return c.compare((o1).getName(), (o2).getName());
        }
    });
    FormLayoutContainer tmpLayout;
    if (attachLayout == null) {
        String editPage = Util.getPackageVelocityRoot(this.getClass()) + "/attachments-editview.html";
        tmpLayout = FormLayoutContainer.createCustomFormLayout("attachLayout", getTranslator(), editPage);
        formLayout.add(tmpLayout);
    } else {
        tmpLayout = (FormLayoutContainer) attachLayout;
    }
    tmpLayout.contextPut("attachments", attachments);
    // add delete links for each attachment if user is allowed to see them
    int attNr = 1;
    for (VFSItem tmpFile : attachments) {
        FormLink tmpLink = uifactory.addFormLink(CMD_DELETE_ATTACHMENT + attNr, tmpLayout, Link.BUTTON_XSMALL);
        if (!(foCallback.mayEditMessageAsModerator() || ((userIsMsgCreator) && (msgHasChildren == false)))) {
            tmpLink.setEnabled(false);
            tmpLink.setVisible(false);
        }
        tmpLink.setUserObject(tmpFile);
        tmpLink.setI18nKey("attachments.remove.string");
        attNr++;
    }
}
Also used : FormItem(org.olat.core.gui.components.form.flexible.FormItem) VFSContainer(org.olat.core.util.vfs.VFSContainer) ArrayList(java.util.ArrayList) VFSItem(org.olat.core.util.vfs.VFSItem) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) Collator(java.text.Collator)

Example 89 with VFSItem

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

the class MessageEditController method persistTempUploadedFiles.

/**
 * - used locally if in edit mode where the msg-key is known
 * - called from ForumController after creating a thread or a reply to copy temp files to
 * msg-folder
 *
 * @param tmpMessage
 */
public void persistTempUploadedFiles(Message tmpMessage) {
    if (tmpMessage == null)
        throw new AssertException("Message may not be null to persist temp files");
    VFSContainer msgContainer = fm.getMessageContainer(forum.getKey(), message.getKey());
    if (msgContainer != null) {
        List<VFSItem> tmpFList = getTempFolderFileList();
        for (VFSItem file : tmpFList) {
            VFSLeaf leaf = (VFSLeaf) file;
            try {
                FileUtils.bcopy(leaf.getInputStream(), msgContainer.createChildLeaf(leaf.getName()).getOutputStream(false), "forumSaveUploadedFile");
            } catch (IOException e) {
                removeTempUploadedFiles();
                throw new RuntimeException("I/O error saving uploaded file:" + msgContainer + "/" + leaf.getName());
            }
        }
    }
    removeTempUploadedFiles();
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) AssertException(org.olat.core.logging.AssertException) DBRuntimeException(org.olat.core.logging.DBRuntimeException) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) IOException(java.io.IOException)

Example 90 with VFSItem

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

the class MessageListController method addMessageToCurrentMessagesAndVC.

private void addMessageToCurrentMessagesAndVC(UserRequest ureq, MessageLight m, MessageView messageView, Map<String, Mark> marks, Map<String, MarkResourceStat> stats, Map<String, Long> artefactStats, Set<Long> readSet) {
    // all values belonging to a message are stored in this map
    // these values can be accessed in velocity. make sure you clean up
    // everything
    // you create here in disposeCurrentMessages()!
    String keyString = m.getKey().toString();
    if (readSet == null || readSet.contains(m.getKey())) {
        messageView.setNewMessage(false);
    } else {
        // mark now as read
        markRead(m);
        messageView.setNewMessage(true);
    }
    // add some data now
    messageView.setFormattedCreationDate(formatter.formatDateAndTime(m.getCreationDate()));
    messageView.setFormattedLastModified(formatter.formatDateAndTime(m.getLastModified()));
    Identity creator = m.getCreator();
    Identity modifier = m.getModifier();
    if (modifier != null) {
        messageView.setModified(true);
        if (modifier.equals(creator) && StringHelper.containsNonWhitespace(m.getPseudonym())) {
            messageView.setModifierPseudonym(m.getPseudonym());
        } else {
            messageView.setModifierFirstName(modifier.getUser().getProperty(UserConstants.FIRSTNAME, getLocale()));
            messageView.setModifierLastName(modifier.getUser().getProperty(UserConstants.LASTNAME, getLocale()));
        }
    } else {
        messageView.setModified(false);
    }
    boolean userIsMsgCreator = false;
    // keeps the first 15 chars
    if (creator != null) {
        userIsMsgCreator = getIdentity().equals(creator);
        if (!StringHelper.containsNonWhitespace(m.getPseudonym())) {
            messageView.setCreatorFirstname(Formatter.truncate(creator.getUser().getProperty(UserConstants.FIRSTNAME, getLocale()), 18));
            messageView.setCreatorLastname(Formatter.truncate(creator.getUser().getProperty(UserConstants.LASTNAME, getLocale()), 18));
        }
    }
    // message attachments
    VFSContainer msgContainer = forumManager.getMessageContainer(forum.getKey(), m.getKey());
    messageView.setMessageContainer(msgContainer);
    List<VFSItem> attachments = new ArrayList<VFSItem>(msgContainer.getItems(new VFSItemMetaFilter()));
    messageView.setAttachments(attachments);
    // number of children and modify/delete permissions
    int numOfChildren = messageView.getNumOfChildren();
    messageView.setAuthor(userIsMsgCreator);
    boolean threadTop = m.getThreadtop() == null;
    messageView.setThreadTop(threadTop);
    boolean isThreadClosed;
    if (threadTop) {
        isThreadClosed = Status.getStatus(m.getStatusCode()).isClosed();
    } else {
        if (thread == null) {
            isThreadClosed = Status.getStatus(m.getThreadtop().getStatusCode()).isClosed();
        } else {
            isThreadClosed = Status.getStatus(thread.getStatusCode()).isClosed();
        }
    }
    messageView.setClosed(isThreadClosed);
    if (!guestOnly && !m.isGuest() && creator != null && !StringHelper.containsNonWhitespace(m.getPseudonym())) {
        // add portrait to map for later disposal and key for rendering in velocity
        DisplayPortraitController portrait = new DisplayPortraitController(ureq, getWindowControl(), creator, true, true, false, true);
        messageView.setPortrait(portrait);
        mainVC.put("portrait_".concat(keyString), portrait.getInitialComponent());
        // Add link with username that is clickable
        String creatorFullName = StringHelper.escapeHtml(UserManager.getInstance().getUserDisplayName(creator));
        Link visitingCardLink = LinkFactory.createCustomLink("vc_".concat(keyString), "vc", creatorFullName, Link.LINK_CUSTOM_CSS + Link.NONTRANSLATED, mainVC, this);
        visitingCardLink.setUserObject(creator);
        LinkPopupSettings settings = new LinkPopupSettings(800, 600, "_blank");
        visitingCardLink.setPopup(settings);
    }
    if (!isThreadClosed) {
        if ((numOfChildren == 0 && userIsMsgCreator && foCallback.mayDeleteOwnMessage()) || foCallback.mayDeleteMessageAsModerator()) {
            Link deleteLink = LinkFactory.createCustomLink("dl_".concat(keyString), "dl", "msg.delete", Link.BUTTON_SMALL, mainVC, this);
            deleteLink.setIconLeftCSS("o_icon o_icon-fw o_icon_delete_item");
            deleteLink.setUserObject(messageView);
        }
        if ((numOfChildren == 0 && userIsMsgCreator && foCallback.mayEditOwnMessage()) || foCallback.mayEditMessageAsModerator()) {
            Link editLink = LinkFactory.createCustomLink("ed_".concat(keyString), "ed", "msg.update", Link.BUTTON_SMALL, mainVC, this);
            editLink.setIconLeftCSS("o_icon o_icon-fw o_icon_edit");
            editLink.setUserObject(messageView);
        }
        if (foCallback.mayReplyMessage()) {
            Link quoteLink = LinkFactory.createCustomLink("qt_".concat(keyString), "qt", "msg.quote", Link.BUTTON_SMALL, mainVC, this);
            quoteLink.setElementCssClass("o_sel_forum_reply_quoted");
            quoteLink.setIconLeftCSS("o_icon o_icon-fw o_icon_reply_with_quote");
            quoteLink.setUserObject(messageView);
            Link replyLink = LinkFactory.createCustomLink("rp_".concat(keyString), "rp", "msg.reply", Link.BUTTON_SMALL, mainVC, this);
            replyLink.setElementCssClass("o_sel_forum_reply");
            replyLink.setIconLeftCSS("o_icon o_icon-fw o_icon_reply");
            replyLink.setUserObject(messageView);
        }
        if (foCallback.mayEditMessageAsModerator()) {
            if (!threadTop) {
                Link splitLink = LinkFactory.createCustomLink("split_".concat(keyString), "split", "msg.split", Link.LINK, mainVC, this);
                splitLink.setIconLeftCSS("o_icon o_icon-fw o_icon_split");
                splitLink.setUserObject(messageView);
                Link moveLink = LinkFactory.createCustomLink("move_".concat(keyString), "move", "msg.move", Link.LINK, mainVC, this);
                moveLink.setIconLeftCSS("o_icon o_icon-fw o_icon_move");
                moveLink.setUserObject(messageView);
            }
            Link exileLink = LinkFactory.createCustomLink("exile_".concat(keyString), "exile", "msg.exile", Link.LINK, mainVC, this);
            exileLink.setIconLeftCSS("o_icon o_icon-fw o_forum_status_thread_icon");
            exileLink.setUserObject(messageView);
        }
    }
    Mark currentMark = marks.get(keyString);
    MarkResourceStat stat = stats.get(keyString);
    if (!guestOnly) {
        String businessPath = currentMark == null ? getWindowControl().getBusinessControl().getAsString() + "[Message:" + m.getKey() + "]" : currentMark.getBusinessPath();
        Controller markCtrl = markingService.getMarkController(ureq, getWindowControl(), currentMark, stat, forumOres, keyString, businessPath);
        mainVC.put("mark_".concat(keyString), markCtrl.getInitialComponent());
    }
    if (userIsMsgCreator && !StringHelper.containsNonWhitespace(m.getPseudonym())) {
        OLATResourceable messageOres = OresHelper.createOLATResourceableInstance("Forum", m.getKey());
        String businessPath = BusinessControlFactory.getInstance().getAsString(getWindowControl().getBusinessControl()) + "[Message:" + m.getKey() + "]";
        Long artefact = artefactStats.get(businessPath);
        int numOfArtefact = artefact == null ? 0 : artefact.intValue();
        if (portfolioModule.isEnabled()) {
            String collectorId = "eportfolio_" + keyString;
            Component collectorCmp = new MediaCollectorComponent(collectorId, getWindowControl(), m, forumMediaHandler, businessPath);
            mainVC.put(collectorId, collectorCmp);
        } else {
            Controller ePFCollCtrl = EPUIFactory.createArtefactCollectWizzardController(ureq, getWindowControl(), numOfArtefact, messageOres, businessPath);
            if (ePFCollCtrl != null) {
                messageView.setArtefact(ePFCollCtrl);
                mainVC.put("eportfolio_" + keyString, ePFCollCtrl.getInitialComponent());
            }
        }
    }
}
Also used : VFSItemMetaFilter(org.olat.core.util.vfs.filters.VFSItemMetaFilter) DisplayPortraitController(org.olat.user.DisplayPortraitController) MarkResourceStat(org.olat.core.commons.services.mark.MarkResourceStat) MediaCollectorComponent(org.olat.modules.portfolio.ui.component.MediaCollectorComponent) OLATResourceable(org.olat.core.id.OLATResourceable) VFSContainer(org.olat.core.util.vfs.VFSContainer) ArrayList(java.util.ArrayList) VFSItem(org.olat.core.util.vfs.VFSItem) Mark(org.olat.core.commons.services.mark.Mark) DisplayPortraitController(org.olat.user.DisplayPortraitController) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) DialogBoxController(org.olat.core.gui.control.generic.modal.DialogBoxController) BasicController(org.olat.core.gui.control.controller.BasicController) StepsMainRunController(org.olat.core.gui.control.generic.wizard.StepsMainRunController) UserInfoMainController(org.olat.user.UserInfoMainController) Controller(org.olat.core.gui.control.Controller) LinkPopupSettings(org.olat.core.gui.components.link.LinkPopupSettings) Identity(org.olat.core.id.Identity) Component(org.olat.core.gui.components.Component) MediaCollectorComponent(org.olat.modules.portfolio.ui.component.MediaCollectorComponent) Link(org.olat.core.gui.components.link.Link)

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