Search in sources :

Example 76 with MetaInfo

use of org.olat.core.commons.modules.bc.meta.MetaInfo in project OpenOLAT by OpenOLAT.

the class VideoHandler method getThumbnail.

@Override
public VFSLeaf getThumbnail(MediaLight media, Size size) {
    String storagePath = media.getStoragePath();
    VFSLeaf thumbnail = null;
    if (StringHelper.containsNonWhitespace(storagePath)) {
        VFSContainer storageContainer = fileStorage.getMediaContainer(media);
        VFSItem item = storageContainer.resolve(media.getRootFilename());
        if (item instanceof VFSLeaf) {
            VFSLeaf leaf = (VFSLeaf) item;
            if (leaf instanceof MetaTagged) {
                MetaInfo metaInfo = ((MetaTagged) leaf).getMetaInfo();
                thumbnail = metaInfo.getThumbnail(size.getHeight(), size.getWidth(), true);
            }
        }
    }
    return thumbnail;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) 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)

Example 77 with MetaInfo

use of org.olat.core.commons.modules.bc.meta.MetaInfo in project OpenOLAT by OpenOLAT.

the class VersionsFileManager method addToRevisions.

/**
 * @see org.olat.core.util.vfs.version.VersionsManager#addToRevisions(org.olat.core.util.vfs.version.Versionable, org.olat.core.id.Identity, java.lang.String)
 */
@Override
public boolean addToRevisions(Versionable currentVersion, Identity identity, String comment) {
    int maxNumOfVersions = versioningConfigurator.getMaxNumOfVersionsAllowed();
    if (maxNumOfVersions == 0) {
        // deactivated, return all ok
        return true;
    }
    VFSLeaf currentFile = (VFSLeaf) currentVersion;
    VFSLeaf versionFile = getCanonicalVersionXmlFile(currentFile, true);
    if (versionFile == null) {
        // cannot do something with the current file
        return false;
    }
    VFSContainer versionContainer = versionFile.getParentContainer();
    String name = currentFile.getName();
    // read from the
    Versions v = readVersions(currentFile, versionFile);
    if (!(v instanceof VersionsFileImpl)) {
        log.error("Wrong implementation of Versions: " + v);
        return false;
    }
    VersionsFileImpl versions = (VersionsFileImpl) v;
    boolean sameFile = isSameFile(currentFile, versions);
    String uuid = sameFile ? getLastRevisionFilename(versions) : UUID.randomUUID().toString() + "_" + name;
    String versionNr = getNextRevisionNr(versions);
    String currentAuthor = versions.getAuthor();
    long lastModifiedDate = 0;
    if (currentFile instanceof MetaTagged) {
        MetaInfo metaInfo = ((MetaTagged) currentFile).getMetaInfo();
        if (metaInfo != null) {
            metaInfo.clearThumbnails();
            if (currentAuthor == null) {
                currentAuthor = metaInfo.getAuthor();
            }
            lastModifiedDate = metaInfo.getLastModified();
        }
    }
    if (lastModifiedDate <= 0) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date());
        lastModifiedDate = cal.getTimeInMillis();
    }
    RevisionFileImpl newRevision = new RevisionFileImpl();
    newRevision.setUuid(UUID.randomUUID().toString());
    newRevision.setName(name);
    newRevision.setFilename(uuid);
    newRevision.setRevisionNr(versionNr);
    newRevision.setComment(versions.getComment());
    newRevision.setAuthor(currentAuthor);
    newRevision.setLastModified(lastModifiedDate);
    if (versions.getRevisions().isEmpty() && currentVersion instanceof MetaTagged) {
        MetaTagged metaTagged = (MetaTagged) currentVersion;
        versions.setCreator(metaTagged.getMetaInfo().getAuthor());
    }
    if (sameFile || VFSManager.copyContent(currentFile, versionContainer.createChildLeaf(uuid))) {
        if (identity != null) {
            versions.setAuthor(identity.getName());
        }
        if (maxNumOfVersions >= 0 && versions.getRevisions().size() >= maxNumOfVersions) {
            List<VFSRevision> revisions = versions.getRevisions();
            int numOfVersionsToDelete = Math.min(revisions.size(), (revisions.size() - maxNumOfVersions) + 1);
            if (numOfVersionsToDelete > 0) {
                List<VFSRevision> versionsToDelete = revisions.subList(0, numOfVersionsToDelete);
                deleteRevisions(currentVersion, versionsToDelete);
                versions = (VersionsFileImpl) currentVersion.getVersions();
            }
        }
        versions.setComment(comment);
        versions.getRevisions().add(newRevision);
        versions.setRevisionNr(getNextRevisionNr(versions));
        XStreamHelper.writeObject(mystream, versionFile, versions);
        if (currentVersion.getVersions() instanceof VersionsFileImpl) {
            ((VersionsFileImpl) currentVersion.getVersions()).update(versions);
        }
        return true;
    } else {
        log.error("Cannot create a version of this file: " + currentVersion);
    }
    return false;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) Calendar(java.util.Calendar) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) Date(java.util.Date)

Example 78 with MetaInfo

use of org.olat.core.commons.modules.bc.meta.MetaInfo in project OpenOLAT by OpenOLAT.

the class DropboxController 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 ureq, Controller source, Event event) {
    if (source == fileChooserController) {
        cmc.deactivate();
        if (event.equals(Event.DONE_EVENT)) {
            boolean success = false;
            File fIn = fileChooserController.getUploadFile();
            VFSContainer fDropbox = getDropBox(ureq.getIdentity());
            String filename = fileChooserController.getUploadFileName();
            VFSLeaf fOut;
            if (fDropbox.resolve(filename) != null) {
                // FIXME ms: check if dropbox quota is exceeded -> clarify with customers
                fOut = fDropbox.createChildLeaf(getNewUniqueName(filename));
            } else {
                fOut = fDropbox.createChildLeaf(filename);
            }
            try {
                InputStream in = new FileInputStream(fIn);
                OutputStream out = new BufferedOutputStream(fOut.getOutputStream(false));
                success = FileUtils.copy(in, out);
                FileUtils.closeSafely(in);
                FileUtils.closeSafely(out);
            } catch (FileNotFoundException e) {
                logError("", e);
                return;
            }
            if (fOut instanceof MetaTagged) {
                MetaInfo info = ((MetaTagged) fOut).getMetaInfo();
                if (info != null) {
                    info.setAuthor(ureq.getIdentity());
                    info.write();
                }
            }
            if (success) {
                int numFiles = fDropbox.getItems().size();
                myContent.contextPut("numfiles", new String[] { Integer.toString(numFiles) });
                // assemble confirmation
                String confirmation = getConfirmation(ureq, fOut.getName());
                // send email if necessary
                Boolean sendEmail = (Boolean) config.get(TACourseNode.CONF_DROPBOX_ENABLEMAIL);
                if (sendEmail == null)
                    sendEmail = Boolean.FALSE;
                boolean sendMailError = false;
                if (sendEmail.booleanValue()) {
                    // send mail
                    MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
                    MailBundle bundle = new MailBundle();
                    bundle.setContext(context);
                    bundle.setToId(ureq.getIdentity());
                    bundle.setContent(translate("conf.mail.subject"), confirmation);
                    MailerResult result = CoreSpringFactory.getImpl(MailManager.class).sendMessage(bundle);
                    if (result.getFailedIdentites().size() > 0) {
                        List<Identity> disabledIdentities = new ArrayList<Identity>();
                        disabledIdentities = result.getFailedIdentites();
                        // show error that message can not be sent
                        ArrayList<String> myButtons = new ArrayList<String>();
                        myButtons.add(translate("back"));
                        String title = MailHelper.getTitleForFailedUsersError(ureq.getLocale());
                        String message = MailHelper.getMessageForFailedUsersError(ureq.getLocale(), disabledIdentities);
                        // add dropbox specific error message
                        message += "\n<br />" + translate("conf.mail.error");
                        // FIXME:FG:6.2: fix problem in info message, not here
                        message += "\n<br />\n<br />" + confirmation.replace("\n", "&#10;").replace("\r", "&#10;").replace("\u2028", "&#10;");
                        DialogBoxController noUsersErrorCtr = null;
                        noUsersErrorCtr = activateGenericDialog(ureq, title, message, myButtons, noUsersErrorCtr);
                        sendMailError = true;
                    } else if (result.getReturnCode() > 0) {
                        // show error that message can not be sent
                        ArrayList<String> myButtons = new ArrayList<String>();
                        myButtons.add(translate("back"));
                        DialogBoxController noUsersErrorCtr = null;
                        String message = translate("conf.mail.error");
                        // FIXME:FG:6.2: fix problem in info message, not here
                        message += "\n<br />\n<br />" + confirmation.replace("\n", "&#10;").replace("\r", "&#10;").replace("\u2028", "&#10;");
                        noUsersErrorCtr = activateGenericDialog(ureq, translate("error.header"), message, myButtons, noUsersErrorCtr);
                        sendMailError = true;
                    }
                }
                // inform subscription manager about new element
                if (subsContext != null) {
                    NotificationsManager.getInstance().markPublisherNews(subsContext, ureq.getIdentity(), true);
                }
                // FIXME:FG:6.2: fix problem in info message, not here
                if (!sendMailError) {
                    getWindowControl().setInfo(confirmation.replace("\n", "&#10;").replace("\r", "&#10;").replace("\u2028", "&#10;"));
                }
            } else {
                showInfo("dropbox.upload.failed");
            }
        }
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) MailContextImpl(org.olat.core.util.mail.MailContextImpl) MailContext(org.olat.core.util.mail.MailContext) MailerResult(org.olat.core.util.mail.MailerResult) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) VFSContainer(org.olat.core.util.vfs.VFSContainer) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileNotFoundException(java.io.FileNotFoundException) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) ArrayList(java.util.ArrayList) FileInputStream(java.io.FileInputStream) DialogBoxController(org.olat.core.gui.control.generic.modal.DialogBoxController) MailManager(org.olat.core.util.mail.MailManager) MailBundle(org.olat.core.util.mail.MailBundle) Identity(org.olat.core.id.Identity) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 79 with MetaInfo

use of org.olat.core.commons.modules.bc.meta.MetaInfo in project OpenOLAT by OpenOLAT.

the class SubmitDocumentsController method updateModel.

private void updateModel() {
    File[] documents = documentsDir.listFiles(new SystemFileFilter(true, false));
    List<SubmittedSolution> docList = new ArrayList<>(documents.length);
    for (File document : documents) {
        String filename = document.getName();
        String uploadedBy = null;
        VFSItem item = documentsContainer.resolve(filename);
        if (item instanceof MetaTagged) {
            MetaInfo metaInfo = ((MetaTagged) item).getMetaInfo();
            if (metaInfo != null && metaInfo.getAuthorIdentityKey() != null) {
                uploadedBy = userManager.getUserDisplayName(metaInfo.getAuthorIdentityKey());
            }
        }
        FormItem download;
        if (filename.endsWith(".html")) {
            download = uifactory.addFormLink("view-" + CodeHelper.getRAMUniqueID(), "view", filename, null, flc, Link.LINK | Link.NONTRANSLATED);
            download.setUserObject(filename);
        } else {
            download = uifactory.addDownloadLink("view-" + CodeHelper.getRAMUniqueID(), filename, null, document, tableEl);
        }
        docList.add(new SubmittedSolution(document, uploadedBy, download));
    }
    model.setObjects(docList);
    tableEl.reset();
    if (maxDocs > 0 && docList.size() >= maxDocs) {
        if (uploadDocButton != null) {
            uploadDocButton.setEnabled(false);
        }
        if (createDocButton != null) {
            createDocButton.setEnabled(false);
        }
        String msg = translate("error.max.documents", new String[] { Integer.toString(maxDocs) });
        flc.contextPut("maxDocsWarning", msg);
    } else {
        if (uploadDocButton != null) {
            uploadDocButton.setEnabled(true);
        }
        if (createDocButton != null) {
            createDocButton.setEnabled(true);
        }
        flc.contextPut("maxDocsWarning", Boolean.FALSE);
    }
    flc.contextPut("hasDocuments", Boolean.valueOf(hasUploadDocuments()));
}
Also used : FormItem(org.olat.core.gui.components.form.flexible.FormItem) ArrayList(java.util.ArrayList) 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) SystemFileFilter(org.olat.core.util.io.SystemFileFilter) File(java.io.File)

Example 80 with MetaInfo

use of org.olat.core.commons.modules.bc.meta.MetaInfo in project OpenOLAT by OpenOLAT.

the class SubmitDocumentsController method doCreateDocumentEditor.

private void doCreateDocumentEditor(UserRequest ureq, String documentName) {
    if (newDocumentEditorCtrl != null)
        return;
    if (maxDocs > 0 && maxDocs <= model.getRowCount()) {
        showWarning("error.max.documents");
    } else {
        VFSItem item = documentsContainer.resolve(documentName);
        if (item == null) {
            documentsContainer.createChildLeaf(documentName);
        } else {
            documentName = VFSManager.rename(documentsContainer, documentName);
            documentsContainer.createChildLeaf(documentName);
        }
        // add missing identity in meta info
        item = documentsContainer.resolve(documentName);
        if (item instanceof MetaTagged) {
            MetaInfo metadata = ((MetaTagged) item).getMetaInfo();
            metadata.setAuthor(ureq.getIdentity());
            metadata.write();
        }
        newDocumentEditorCtrl = WysiwygFactory.createWysiwygController(ureq, getWindowControl(), documentsContainer, documentName, "media", true, true);
        newDocumentEditorCtrl.getRichTextConfiguration().disableMedia();
        newDocumentEditorCtrl.getRichTextConfiguration().setAllowCustomMediaFactory(false);
        newDocumentEditorCtrl.setNewFile(true);
        listenTo(newDocumentEditorCtrl);
        cmc = new CloseableModalController(getWindowControl(), "close", newDocumentEditorCtrl.getInitialComponent());
        listenTo(cmc);
        cmc.activate();
    }
}
Also used : CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) 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)

Aggregations

MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)108 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)86 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)58 VFSItem (org.olat.core.util.vfs.VFSItem)52 VFSContainer (org.olat.core.util.vfs.VFSContainer)40 Date (java.util.Date)18 OutputStream (java.io.OutputStream)14 File (java.io.File)12 IOException (java.io.IOException)12 Versionable (org.olat.core.util.vfs.version.Versionable)12 InputStream (java.io.InputStream)10 ArrayList (java.util.ArrayList)10 FolderEvent (org.olat.core.commons.modules.bc.FolderEvent)10 MediaResource (org.olat.core.gui.media.MediaResource)10 Identity (org.olat.core.id.Identity)10 VFSMediaResource (org.olat.core.util.vfs.VFSMediaResource)10 FileInfo (org.olat.core.commons.modules.bc.FileInfo)8 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)8 SubscriptionListItem (org.olat.core.commons.services.notifications.model.SubscriptionListItem)8 VFSSecurityCallback (org.olat.core.util.vfs.callbacks.VFSSecurityCallback)8