Search in sources :

Example 66 with MetaInfo

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

the class FileUploadController method finishSuccessfullUpload.

/**
 * Internal helper to finish the upload and add metadata
 */
private void finishSuccessfullUpload(String filePath, VFSItem item, UserRequest ureq) {
    if (item instanceof OlatRootFileImpl) {
        OlatRootFileImpl relPathItem = (OlatRootFileImpl) item;
        // create meta data
        MetaInfo meta = metaInfoFactory.createMetaInfoFor(relPathItem);
        if (metaDataCtr != null) {
            meta = metaDataCtr.getMetaInfo(meta);
        }
        meta.setAuthor(getIdentity());
        // if overwrite an older file
        meta.clearThumbnails();
        meta.write();
    }
    if (item == null) {
        logError("File cannot be uploaded: " + filePath, null);
    } else {
        ThreadLocalUserActivityLogger.log(FolderLoggingAction.FILE_UPLOADED, getClass(), CoreLoggingResourceable.wrapUploadFile(filePath));
        // Notify listeners about upload
        fireEvent(ureq, new FolderEvent(FolderEvent.UPLOAD_EVENT, item));
    }
}
Also used : MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) OlatRootFileImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFileImpl)

Example 67 with MetaInfo

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

the class CmdEditMeta method event.

@Override
public void event(UserRequest ureq, Controller source, Event event) {
    if (source == metaInfoCtr && event == Event.DONE_EVENT) {
        MetaInfo meta = metaInfoCtr.getMetaInfo();
        String fileName = metaInfoCtr.getFilename();
        if (meta != null) {
            meta.write();
            if (metaInfoCtr.isFileRenamed()) {
                // IMPORTANT: First rename the meta data because underlying file
                // has to exist in order to work properly on it's meta data.
                VFSContainer container = currentItem.getParentContainer();
                if (container.resolve(fileName) != null) {
                    getWindowControl().setError(translator.translate("TargetNameAlreadyUsed"));
                    status = FolderCommandStatus.STATUS_FAILED;
                } else {
                    meta.rename(fileName);
                    if (VFSConstants.NO.equals(currentItem.rename(fileName))) {
                        getWindowControl().setError(translator.translate("FileRenameFailed", new String[] { fileName }));
                        status = FolderCommandStatus.STATUS_FAILED;
                    }
                }
            }
        }
        fireEvent(ureq, new FolderEvent(FolderEvent.EDIT_EVENT, fileName));
        notifyFinished(ureq);
    } else if (event == Event.CANCELLED_EVENT) {
        fireEvent(ureq, FOLDERCOMMAND_FINISHED);
    }
}
Also used : VFSContainer(org.olat.core.util.vfs.VFSContainer) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) FolderEvent(org.olat.core.commons.modules.bc.FolderEvent)

Example 68 with MetaInfo

use of org.olat.core.commons.modules.bc.meta.MetaInfo 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 69 with MetaInfo

use of org.olat.core.commons.modules.bc.meta.MetaInfo 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 70 with MetaInfo

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

the class OlatRootFolderTreeModel method createNode.

/**
 * Create a node out of a relative path vfs item. The user object is set to
 * the relative path.
 *
 * @param item
 */
private OlatRootFolderTreeNode createNode(OlatRelPathImpl item) {
    OlatRootFolderTreeNode node = new OlatRootFolderTreeNode(item, this);
    MetaInfo meta = metaInfoFactory.createMetaInfoFor(item);
    if (meta != null) {
        String title = meta.getTitle();
        if (StringHelper.containsNonWhitespace(title)) {
            node.setTitle(title);
        } else {
            node.setTitle(meta.getName());
        }
    } else {
    // TODO:GW log warning that
    // "metadate couldn't be loaded for folder relpath: " +
    // folder.getRelPath();
    }
    node.setUserObject(item.getRelPath());
    return node;
}
Also used : MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo)

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