Search in sources :

Example 41 with MetaInfo

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

the class CmdDelete method event.

public void event(UserRequest ureq, Controller source, Event event) {
    if (source == dialogCtr) {
        if (DialogBoxUIFactory.isYesEvent(event)) {
            // do delete
            VFSContainer currentContainer = folderComponent.getCurrentContainer();
            List<String> files = fileSelection.getFiles();
            if (files.size() == 0) {
                // sometimes, browser sends empty form data...
                getWindowControl().setError(translator.translate("failed"));
                status = FolderCommandStatus.STATUS_FAILED;
                fireEvent(ureq, FOLDERCOMMAND_FINISHED);
            }
            for (String file : files) {
                VFSItem item = currentContainer.resolve(file);
                if (item != null && (item.canDelete() == VFSConstants.YES)) {
                    if (item instanceof MetaTagged) {
                        // delete all meta info
                        MetaInfo meta = ((MetaTagged) item).getMetaInfo();
                        if (meta != null) {
                            meta.deleteAll();
                        }
                    }
                    // delete the item itself
                    item.delete();
                } else {
                    getWindowControl().setWarning(translator.translate("del.partial"));
                }
            }
            String confirmationText = fileSelection.renderAsHtml();
            fireEvent(ureq, new FolderEvent(FolderEvent.DELETE_EVENT, confirmationText));
            fireEvent(ureq, FOLDERCOMMAND_FINISHED);
        } else {
            // abort
            status = FolderCommandStatus.STATUS_CANCELED;
            fireEvent(ureq, FOLDERCOMMAND_FINISHED);
        }
    }
}
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) VFSItem(org.olat.core.util.vfs.VFSItem) FolderEvent(org.olat.core.commons.modules.bc.FolderEvent)

Example 42 with MetaInfo

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

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 43 with MetaInfo

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

the class FileHandler 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)

Example 44 with MetaInfo

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

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)

Example 45 with MetaInfo

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

the class CmdZip method formOK.

/**
 * Creates a zipFile by using ZipUtil and fires Event.DONE_EVENT if successful.
 *
 * @see org.olat.core.commons.modules.bc.commands.AbstractCreateItemForm#formOK(org.olat.core.gui.UserRequest)
 */
@Override
protected void formOK(UserRequest ureq) {
    String name = textElement.getValue();
    if (!name.toLowerCase().endsWith(".zip")) {
        name += ".zip";
    }
    VFSItem zipFile = currentContainer.createChildLeaf(name);
    if (zipFile == null) {
        fireEvent(ureq, Event.FAILED_EVENT);
        return;
    }
    List<VFSItem> vfsFiles = new ArrayList<VFSItem>();
    for (String fileName : selection.getFiles()) {
        VFSItem item = currentContainer.resolve(fileName);
        if (item != null) {
            vfsFiles.add(item);
        }
    }
    if (!ZipUtil.zip(vfsFiles, (VFSLeaf) zipFile, true)) {
        // cleanup zip file
        zipFile.delete();
        status = FolderCommandStatus.STATUS_FAILED;
        fireEvent(ureq, FOLDERCOMMAND_FINISHED);
    } else {
        if (zipFile instanceof MetaTagged) {
            MetaInfo info = ((MetaTagged) zipFile).getMetaInfo();
            if (info != null) {
                info.setAuthor(ureq.getIdentity());
                info.write();
            }
        }
        fireEvent(ureq, new FolderEvent(FolderEvent.ZIP_EVENT, selection.renderAsHtml()));
        fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) 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) FolderEvent(org.olat.core.commons.modules.bc.FolderEvent)

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