Search in sources :

Example 56 with MetaTagged

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

the class CmdMoveCopy method doMove.

private void doMove(UserRequest ureq) {
    FolderTreeModel ftm = (FolderTreeModel) selTree.getTreeModel();
    String selectedPath = ftm.getSelectedPath(selTree.getSelectedNode());
    if (selectedPath == null) {
        abortFailed(ureq, "failed");
        return;
    }
    VFSStatus vfsStatus = VFSConstants.SUCCESS;
    VFSContainer rootContainer = folderComponent.getRootContainer();
    VFSItem vfsItem = rootContainer.resolve(selectedPath);
    if (vfsItem == null || (vfsItem.canWrite() != VFSConstants.YES)) {
        abortFailed(ureq, "failed");
        return;
    }
    // copy the files
    VFSContainer target = (VFSContainer) vfsItem;
    List<VFSItem> sources = getSanityCheckedSourceItems(target, ureq);
    if (sources == null)
        return;
    boolean targetIsRelPath = (target instanceof OlatRelPathImpl);
    for (VFSItem vfsSource : sources) {
        if (targetIsRelPath && (target instanceof OlatRelPathImpl) && (vfsSource instanceof MetaTagged)) {
            // copy the metainfo first
            MetaInfo meta = ((MetaTagged) vfsSource).getMetaInfo();
            if (meta != null) {
                meta.moveCopyToDir((OlatRelPathImpl) target, move);
            }
        }
        VFSItem targetFile = target.resolve(vfsSource.getName());
        if (vfsSource instanceof VFSLeaf && targetFile != null && targetFile instanceof Versionable && ((Versionable) targetFile).getVersions().isVersioned()) {
            // add a new version to the file
            ((Versionable) targetFile).getVersions().addVersion(null, "", ((VFSLeaf) vfsSource).getInputStream());
        } else {
            vfsStatus = target.copyFrom(vfsSource);
        }
        if (vfsStatus != VFSConstants.SUCCESS) {
            String errorKey = "failed";
            if (vfsStatus == VFSConstants.ERROR_QUOTA_EXCEEDED)
                errorKey = "QuotaExceeded";
            abortFailed(ureq, errorKey);
            return;
        }
        if (move) {
            // if move, delete the source. Note that meta source
            // has already been delete (i.e. moved)
            vfsSource.delete();
        }
    }
    // after a copy or a move, notify the subscribers
    VFSSecurityCallback secCallback = VFSManager.findInheritedSecurityCallback(folderComponent.getCurrentContainer());
    if (secCallback != null) {
        SubscriptionContext subsContext = secCallback.getSubscriptionContext();
        if (subsContext != null) {
            NotificationsManager.getInstance().markPublisherNews(subsContext, ureq.getIdentity(), true);
        }
    }
    fireEvent(ureq, new FolderEvent(move ? FolderEvent.MOVE_EVENT : FolderEvent.COPY_EVENT, fileSelection.renderAsHtml()));
    notifyFinished(ureq);
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) FolderTreeModel(org.olat.core.gui.control.generic.folder.FolderTreeModel) OlatRelPathImpl(org.olat.core.util.vfs.OlatRelPathImpl) 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) Versionable(org.olat.core.util.vfs.version.Versionable) VFSStatus(org.olat.core.util.vfs.VFSStatus) FolderEvent(org.olat.core.commons.modules.bc.FolderEvent) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) VFSSecurityCallback(org.olat.core.util.vfs.callbacks.VFSSecurityCallback)

Example 57 with MetaTagged

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

the class CmdUnzip method doUnzip.

private boolean doUnzip(VFSLeaf vfsItem, VFSContainer currentContainer, UserRequest ureq, WindowControl wControl) {
    String name = vfsItem.getName();
    if (!name.toLowerCase().endsWith(".zip")) {
        wControl.setError(translator.translate("FileUnzipFailed", new String[] { vfsItem.getName() }));
        return false;
    }
    // we make a new folder with the same name as the zip file
    String sZipContainer = name.substring(0, name.length() - 4);
    boolean versioning = FolderConfig.versionsEnabled(currentContainer);
    VFSContainer zipContainer = currentContainer.createChildContainer(sZipContainer);
    if (zipContainer == null) {
        if (versioning) {
            zipContainer = (VFSContainer) currentContainer.resolve(sZipContainer);
        } else {
            // folder already exists... issue warning
            wControl.setError(translator.translate("unzip.alreadyexists", new String[] { sZipContainer }));
            return false;
        }
    } else if (zipContainer instanceof MetaTagged) {
        MetaInfo info = ((MetaTagged) zipContainer).getMetaInfo();
        if (info != null && ureq.getIdentity() != null) {
            info.setAuthor(ureq.getIdentity());
            info.write();
        }
    }
    if (!ZipUtil.unzipNonStrict(vfsItem, zipContainer, ureq.getIdentity(), versioning)) {
        // operation failed - rollback
        zipContainer.delete();
        wControl.setError(translator.translate("failed"));
        return false;
    } else {
        // check quota
        long quotaLeftKB = VFSManager.getQuotaLeftKB(currentContainer);
        if (quotaLeftKB != Quota.UNLIMITED && quotaLeftKB < 0) {
            // quota exceeded - rollback
            zipContainer.delete();
            wControl.setError(translator.translate("QuotaExceeded"));
            return false;
        }
    }
    return true;
}
Also used : 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)

Example 58 with MetaTagged

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

the class SendDocumentsByEMailController method setFiles.

protected void setFiles(VFSContainer rootContainer, List<VFSLeaf> leafs) {
    this.files = leafs;
    StringBuilder subjectSb = new StringBuilder();
    if (StringHelper.containsNonWhitespace(subjectElement.getValue())) {
        subjectSb.append(subjectElement.getValue()).append('\n').append('\n');
    }
    StringBuilder bodySb = new StringBuilder();
    if (StringHelper.containsNonWhitespace(bodyElement.getValue())) {
        bodySb.append(bodyElement.getValue()).append('\n').append('\n');
    }
    attachments = new ArrayList<File>();
    long fileSize = 0l;
    for (VFSLeaf file : files) {
        MetaInfo infos = null;
        if (file instanceof MetaTagged) {
            infos = ((MetaTagged) file).getMetaInfo();
        }
        // subject
        appendToSubject(file, infos, subjectSb);
        // body
        appendMetadatas(file, infos, bodySb);
        appendBusinessPath(rootContainer, file, bodySb);
        bodySb.append('\n').append('\n');
        fileSize += file.getSize();
        if (allowAttachments && file instanceof LocalFileImpl) {
            File f = ((LocalFileImpl) file).getBasefile();
            attachments.add(f);
        }
    }
    int mailQuota = CoreSpringFactory.getImpl(MailModule.class).getMaxSizeForAttachement();
    long fileSizeInMB = fileSize / (1024l * 1024l);
    if (allowAttachments) {
        if (fileSizeInMB > mailQuota) {
            attachments.clear();
            setFormWarning("send.mail.fileToBigForAttachments", new String[] { String.valueOf(mailQuota), String.valueOf(fileSizeInMB) });
        } else {
            List<FileInfo> infos = new ArrayList<FileInfo>(files.size());
            for (VFSLeaf file : files) {
                final String name = file.getName();
                final double size = file.getSize() / (1024.0 * 1024.0);
                final String sizeStr = formatMb.format(size);
                final String cssClass = CSSHelper.createFiletypeIconCssClassFor(file.getName());
                infos.add(new FileInfo(name, sizeStr, cssClass));
            }
            attachmentsLayout.contextPut("attachments", infos);
        }
    }
    subjectElement.setValue(subjectSb.toString());
    bodyElement.setValue(bodySb.toString());
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) ArrayList(java.util.ArrayList) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) MailModule(org.olat.core.util.mail.MailModule) File(java.io.File)

Example 59 with MetaTagged

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

the class ConvertToGTACourseNode method convertMetada.

private void convertMetada(VFSContainer source, VFSContainer target, String name, TaskDefinition taskDef, Solution solDef) {
    VFSItem sourceItem = source.resolve(name);
    VFSItem targetItem = target.resolve(name);
    if (sourceItem instanceof MetaTagged && targetItem instanceof MetaTagged) {
        MetaTagged taggedSource = (MetaTagged) sourceItem;
        MetaInfo metaSource = taggedSource.getMetaInfo();
        MetaTagged taggedTarget = (MetaTagged) targetItem;
        MetaInfo metaTarget = taggedTarget.getMetaInfo();
        if (metaSource != null) {
            if (taskDef != null) {
                if (StringHelper.containsNonWhitespace(metaSource.getTitle())) {
                    taskDef.setTitle(metaSource.getTitle());
                }
                taskDef.setDescription(metaSource.getComment());
            }
            if (solDef != null) {
                if (StringHelper.containsNonWhitespace(metaSource.getTitle())) {
                    solDef.setTitle(metaSource.getTitle());
                }
            }
            if (metaTarget != null) {
                metaTarget.copyValues(metaSource);
                metaTarget.write();
            }
        }
    }
}
Also used : 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 60 with MetaTagged

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

the class ImageHandler method getInformations.

@Override
public MediaInformations getInformations(Object mediaObject) {
    String title = null;
    String description = null;
    if (mediaObject instanceof MetaTagged) {
        MetaInfo meta = ((MetaTagged) mediaObject).getMetaInfo();
        title = meta.getTitle();
        description = meta.getComment();
    }
    return new Informations(title, description);
}
Also used : MediaInformations(org.olat.modules.portfolio.MediaInformations) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo)

Aggregations

MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)92 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)86 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)58 VFSItem (org.olat.core.util.vfs.VFSItem)48 VFSContainer (org.olat.core.util.vfs.VFSContainer)34 File (java.io.File)16 OutputStream (java.io.OutputStream)14 Versionable (org.olat.core.util.vfs.version.Versionable)12 IOException (java.io.IOException)10 InputStream (java.io.InputStream)10 ArrayList (java.util.ArrayList)10 Date (java.util.Date)10 MediaResource (org.olat.core.gui.media.MediaResource)10 VFSMediaResource (org.olat.core.util.vfs.VFSMediaResource)10 VFSSecurityCallback (org.olat.core.util.vfs.callbacks.VFSSecurityCallback)8 BufferedOutputStream (java.io.BufferedOutputStream)6 ByteArrayInputStream (java.io.ByteArrayInputStream)6 Test (org.junit.Test)6 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)6 NotFoundMediaResource (org.olat.core.gui.media.NotFoundMediaResource)6