Search in sources :

Example 26 with Versionable

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

the class FileUploadController method doFinishComment.

private void doFinishComment(UserRequest ureq) {
    String comment = commentVersionCtr.getComment();
    Roles roles = ureq.getUserSession().getRoles();
    boolean locked = vfsLockManager.isLocked(existingVFSItem);
    if (locked && !commentVersionCtr.keepLocked()) {
        vfsLockManager.unlock(existingVFSItem, getIdentity(), roles);
    }
    commentVersionDialogBox.deactivate();
    if (revisionListDialogBox != null) {
        revisionListDialogBox.deactivate();
    }
    // ok, new version of the file
    Versionable existingVersionableItem = (Versionable) existingVFSItem;
    boolean ok = existingVersionableItem.getVersions().addVersion(ureq.getIdentity(), comment, newFile.getInputStream());
    if (ok) {
        newFile.deleteSilently();
        // what can i do if existingVFSItem is a container
        if (existingVFSItem instanceof VFSLeaf) {
            newFile = (VFSLeaf) existingVFSItem;
        }
    }
    finishUpload(ureq);
}
Also used : Versionable(org.olat.core.util.vfs.version.Versionable) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) Roles(org.olat.core.id.Roles)

Example 27 with Versionable

use of org.olat.core.util.vfs.version.Versionable 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 28 with Versionable

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

the class FolderComponent method sort.

/**
 * Sorts the bc folder components table
 *
 * @param col The column to sort
 */
private void sort(String col) {
    currentSortOrder = col;
    if (col.equals(SORT_NAME)) {
        // sort after file name?
        comparator = new Comparator<VFSItem>() {

            @Override
            public int compare(VFSItem o1, VFSItem o2) {
                if (sortAsc) {
                    if ((o1 instanceof VFSLeaf && o2 instanceof VFSLeaf) || (!(o1 instanceof VFSLeaf) && !(o2 instanceof VFSLeaf))) {
                        return collator.compare(o1.getName(), o2.getName());
                    } else {
                        if (!(o1 instanceof VFSLeaf)) {
                            return -1;
                        } else {
                            return 1;
                        }
                    }
                } else {
                    if ((o1 instanceof VFSLeaf && o2 instanceof VFSLeaf) || (!(o1 instanceof VFSLeaf) && !(o2 instanceof VFSLeaf))) {
                        return collator.compare(o2.getName(), o1.getName());
                    } else {
                        if (!(o1 instanceof VFSLeaf)) {
                            return -1;
                        } else {
                            return 1;
                        }
                    }
                }
            }
        };
    } else if (col.equals(SORT_DATE)) {
        // sort after modification date (if same, then name)
        comparator = new Comparator<VFSItem>() {

            @Override
            public int compare(VFSItem o1, VFSItem o2) {
                if (o1.getLastModified() < o2.getLastModified())
                    return ((sortAsc) ? -1 : 1);
                else if (o1.getLastModified() > o2.getLastModified())
                    return ((sortAsc) ? 1 : -1);
                else {
                    if (sortAsc)
                        return collator.compare(o1.getName(), o2.getName());
                    else
                        return collator.compare(o2.getName(), o1.getName());
                }
            }
        };
    } else if (col.equals(SORT_SIZE)) {
        // sort after file size, folders always on top
        comparator = new Comparator<VFSItem>() {

            @Override
            public int compare(VFSItem o1, VFSItem o2) {
                VFSLeaf leaf1 = null;
                if (o1 instanceof VFSLeaf) {
                    leaf1 = (VFSLeaf) o1;
                }
                VFSLeaf leaf2 = null;
                if (o2 instanceof VFSLeaf) {
                    leaf2 = (VFSLeaf) o2;
                }
                if (// folders are always smaller
                leaf1 == null && leaf2 != null)
                    // folders are always smaller
                    return -1;
                else if (// folders are always smaller
                leaf1 != null && leaf2 == null)
                    // folders are always smaller
                    return 1;
                else if (// if two folders, sort after name
                leaf1 == null && leaf2 == null)
                    if (sortAsc)
                        return collator.compare(o1.getName(), o2.getName());
                    else
                        return collator.compare(o2.getName(), o1.getName());
                else // if two leafes, sort after size
                if (sortAsc)
                    return ((leaf1.getSize() < leaf2.getSize()) ? -1 : 1);
                else
                    return ((leaf1.getSize() < leaf2.getSize()) ? 1 : -1);
            }
        };
    } else if (col.equals(SORT_REV)) {
        // sort after revision number, folders always on top
        comparator = new Comparator<VFSItem>() {

            @Override
            public int compare(VFSItem o1, VFSItem o2) {
                Versionable v1 = null;
                Versionable v2 = null;
                if (o1 instanceof Versionable) {
                    v1 = (Versionable) o1;
                }
                if (o2 instanceof Versionable) {
                    v2 = (Versionable) o2;
                }
                if (v1 == null) {
                    return -1;
                } else if (v2 == null) {
                    return 1;
                }
                String r1 = v1.getVersions().getRevisionNr();
                String r2 = v2.getVersions().getRevisionNr();
                if (r1 == null) {
                    return -1;
                } else if (r2 == null) {
                    return 1;
                }
                return (sortAsc) ? collator.compare(r1, r2) : collator.compare(r2, r1);
            }
        };
    } else if (col.equals(SORT_LOCK)) {
        // sort after modification date (if same, then name)
        comparator = new LockComparator(sortAsc, collator);
    }
    // if not empty the update list
    if (currentContainerChildren != null)
        updateChildren();
}
Also used : Versionable(org.olat.core.util.vfs.version.Versionable) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSItem(org.olat.core.util.vfs.VFSItem) LockComparator(org.olat.core.commons.modules.bc.meta.tagged.LockComparator) LockComparator(org.olat.core.commons.modules.bc.meta.tagged.LockComparator) Comparator(java.util.Comparator)

Example 29 with Versionable

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

the class CmdViewRevisions method execute.

public Controller execute(FolderComponent folderComponent, UserRequest ureq, WindowControl wControl, Translator translator) {
    if (revisionListCtr != null) {
        removeAsListenerAndDispose(revisionListCtr);
    }
    String pos = ureq.getParameter(ListRenderer.PARAM_VERID);
    if (!StringHelper.containsNonWhitespace(pos)) {
        // somehow parameter did not make it to us
        status = FolderCommandStatus.STATUS_FAILED;
        getWindowControl().setError(translator.translate("failed"));
        return null;
    }
    status = FolderCommandHelper.sanityCheck(wControl, folderComponent);
    if (status == FolderCommandStatus.STATUS_SUCCESS) {
        currentItem = folderComponent.getCurrentContainerChildren().get(Integer.parseInt(pos));
        status = FolderCommandHelper.sanityCheck2(wControl, folderComponent, currentItem);
    }
    if (status == FolderCommandStatus.STATUS_FAILED) {
        return null;
    }
    if (!(currentItem instanceof Versionable)) {
        status = FolderCommandStatus.STATUS_FAILED;
        getWindowControl().setError(translator.translate("failed"));
        return null;
    }
    setTranslator(translator);
    boolean locked = vfsLockManager.isLockedForMe(currentItem, ureq.getIdentity(), ureq.getUserSession().getRoles());
    revisionListCtr = new RevisionListController(ureq, wControl, (Versionable) currentItem, locked);
    listenTo(revisionListCtr);
    putInitialPanel(revisionListCtr.getInitialComponent());
    return this;
}
Also used : Versionable(org.olat.core.util.vfs.version.Versionable) RevisionListController(org.olat.core.commons.modules.bc.version.RevisionListController)

Example 30 with Versionable

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

the class NodeExportVisitor method writeObject.

/**
 * Write a structure to an XML file in the course base path folder.
 *
 * @param fileName
 * @param obj
 */
private void writeObject(String fileName, Object obj) {
    VFSItem vfsItem = getCourseBaseContainer().resolve(fileName);
    if (vfsItem == null) {
        vfsItem = getCourseBaseContainer().createChildLeaf(fileName);
    } else if (vfsItem.exists() && vfsItem instanceof Versionable) {
        try {
            VersionsFileManager.getInstance().addToRevisions((Versionable) vfsItem, null, "");
        } catch (Exception e) {
            log.error("Cannot versioned " + fileName, e);
        }
    }
    XStream xstream = CourseXStreamAliases.getWriteCourseXStream();
    XStreamHelper.writeObject(xstream, (VFSLeaf) vfsItem, obj);
}
Also used : Versionable(org.olat.core.util.vfs.version.Versionable) XStream(com.thoughtworks.xstream.XStream) VFSItem(org.olat.core.util.vfs.VFSItem) AssertException(org.olat.core.logging.AssertException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException)

Aggregations

Versionable (org.olat.core.util.vfs.version.Versionable)40 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)20 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)12 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)12 VFSContainer (org.olat.core.util.vfs.VFSContainer)12 VFSItem (org.olat.core.util.vfs.VFSItem)12 Versions (org.olat.core.util.vfs.version.Versions)10 IOException (java.io.IOException)8 BufferedOutputStream (java.io.BufferedOutputStream)6 InputStream (java.io.InputStream)6 OutputStream (java.io.OutputStream)6 RevisionListController (org.olat.core.commons.modules.bc.version.RevisionListController)6 AssertException (org.olat.core.logging.AssertException)6 File (java.io.File)4 FileOutputStream (java.io.FileOutputStream)4 Date (java.util.Date)4 ZipInputStream (java.util.zip.ZipInputStream)4 ZipOutputStream (java.util.zip.ZipOutputStream)4 OlatRootFileImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFileImpl)4 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)4