Search in sources :

Example 16 with Versions

use of org.olat.core.util.vfs.version.Versions in project openolat by klemens.

the class FileCopyController method event.

@Override
public void event(UserRequest ureq, Controller source, Event event) {
    if (source instanceof FileLinkChooserController) {
        if (event == Event.DONE_EVENT || event == Event.CANCELLED_EVENT) {
            fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
        } else if (event instanceof URLChoosenEvent) {
            URLChoosenEvent choosenEvent = (URLChoosenEvent) event;
            String url = choosenEvent.getURL();
            if (url.indexOf("://") < 0) {
                VFSContainer cContainer = folderComponent.getExternContainerForCopy();
                VFSItem item = cContainer.resolve(url);
                if (item instanceof VFSLeaf) {
                    sourceLeaf = (VFSLeaf) item;
                    String filename = sourceLeaf.getName();
                    VFSContainer tContainer = folderComponent.getCurrentContainer();
                    newFile = tContainer.createChildLeaf(filename);
                    if (newFile == null) {
                        existingVFSItem = (VFSLeaf) tContainer.resolve(filename);
                        fileAlreadyExists(ureq);
                    } else {
                        finishUpload(ureq);
                    }
                } else {
                    fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
                }
            } else {
                fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
            }
        }
    } else if (source == overwriteDialog) {
        if (event instanceof ButtonClickedEvent) {
            ButtonClickedEvent buttonClickedEvent = (ButtonClickedEvent) event;
            if (buttonClickedEvent.getPosition() == 0) {
                // ok
                if (existingVFSItem instanceof Versionable && ((Versionable) existingVFSItem).getVersions().isVersioned()) {
                    // new version
                    String relPath = null;
                    if (existingVFSItem instanceof OlatRootFileImpl) {
                        relPath = ((OlatRootFileImpl) existingVFSItem).getRelPath();
                    }
                    int maxNumOfRevisions = FolderConfig.versionsAllowed(relPath);
                    if (maxNumOfRevisions == 0) {
                        // someone play with the configuration
                        // Overwrite...
                        String fileName = existingVFSItem.getName();
                        existingVFSItem.delete();
                        newFile = folderComponent.getCurrentContainer().createChildLeaf(fileName);
                        // ... and notify listeners.
                        finishUpload(ureq);
                    } else {
                        removeAsListenerAndDispose(commentVersionCtr);
                        boolean locked = vfsLockManager.isLocked(existingVFSItem);
                        commentVersionCtr = new VersionCommentController(ureq, getWindowControl(), locked, true);
                        listenTo(commentVersionCtr);
                        removeAsListenerAndDispose(commentVersionDialogBox);
                        commentVersionDialogBox = new CloseableModalController(getWindowControl(), translate("save"), commentVersionCtr.getInitialComponent());
                        listenTo(commentVersionDialogBox);
                        commentVersionDialogBox.activate();
                    }
                } else {
                    // if the file is locked, ask for unlocking it
                    if (vfsLockManager.isLocked(existingVFSItem)) {
                        removeAsListenerAndDispose(unlockCtr);
                        unlockCtr = new VersionCommentController(ureq, getWindowControl(), true, false);
                        listenTo(unlockCtr);
                        removeAsListenerAndDispose(unlockDialogBox);
                        unlockDialogBox = new CloseableModalController(getWindowControl(), translate("ok"), unlockCtr.getInitialComponent());
                        listenTo(unlockDialogBox);
                        unlockDialogBox.activate();
                    } else {
                        // Overwrite...
                        String fileName = existingVFSItem.getName();
                        existingVFSItem.delete();
                        newFile = folderComponent.getCurrentContainer().createChildLeaf(fileName);
                        // ... and notify listeners.
                        finishUpload(ureq);
                    }
                }
            } else if (buttonClickedEvent.getPosition() == 1) {
                // not ok
                // make newFile with the proposition of filename
                newFile = folderComponent.getCurrentContainer().createChildLeaf(renamedFilename);
                // ... and notify listeners.
                finishUpload(ureq);
            } else if (buttonClickedEvent.getPosition() == 2) {
            // cancel
            // cancel -> do nothing
            } else {
                throw new RuntimeException("Unknown button number " + buttonClickedEvent.getPosition());
            }
        }
    } else if (source == lockedFileDialog) {
        if (event instanceof ButtonClickedEvent) {
            ButtonClickedEvent buttonClickedEvent = (ButtonClickedEvent) event;
            switch(buttonClickedEvent.getPosition()) {
                case 0:
                    {
                        // ... and notify listeners.
                        newFile = existingVFSItem;
                        finishUpload(ureq);
                        break;
                    }
                case 1:
                    {
                        // cancel
                        fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
                        break;
                    }
                default:
                    throw new RuntimeException("Unknown button number " + buttonClickedEvent.getPosition());
            }
        }
    } else if (source == commentVersionCtr) {
        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, sourceLeaf.getInputStream());
        if (ok) {
            newFile = existingVFSItem;
        }
        finishSuccessfullUpload(existingVFSItem.getName(), ureq);
    } else if (source == unlockCtr) {
        // Overwrite...
        if (!unlockCtr.keepLocked()) {
            vfsLockManager.unlock(existingVFSItem, getIdentity(), ureq.getUserSession().getRoles());
        }
        unlockDialogBox.deactivate();
        newFile = existingVFSItem;
        // ... and notify listeners.
        finishSuccessfullUpload(existingVFSItem.getName(), ureq);
    } else if (source == revisionListCtr) {
        if (FolderCommandStatus.STATUS_CANCELED == revisionListCtr.getStatus()) {
            revisionListDialogBox.deactivate();
            // don't want to delete revisions
            fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
        } else {
            if (existingVFSItem instanceof Versionable && ((Versionable) existingVFSItem).getVersions().isVersioned()) {
                revisionListDialogBox.deactivate();
                Versionable versionable = (Versionable) existingVFSItem;
                Versions versions = versionable.getVersions();
                int maxNumOfRevisions = FolderConfig.versionsAllowed(null);
                if (maxNumOfRevisions < 0 || maxNumOfRevisions > versions.getRevisions().size()) {
                    removeAsListenerAndDispose(commentVersionCtr);
                    boolean locked = vfsLockManager.isLocked(existingVFSItem);
                    commentVersionCtr = new VersionCommentController(ureq, getWindowControl(), locked, true);
                    listenTo(commentVersionCtr);
                    removeAsListenerAndDispose(commentVersionDialogBox);
                    commentVersionDialogBox = new CloseableModalController(getWindowControl(), translate("save"), commentVersionCtr.getInitialComponent());
                    listenTo(commentVersionDialogBox);
                    commentVersionDialogBox.activate();
                } else {
                    removeAsListenerAndDispose(revisionListCtr);
                    revisionListCtr = new RevisionListController(ureq, getWindowControl(), versionable, false);
                    listenTo(revisionListCtr);
                    removeAsListenerAndDispose(revisionListDialogBox);
                    revisionListDialogBox = new CloseableModalController(getWindowControl(), translate("delete"), revisionListCtr.getInitialComponent());
                    listenTo(revisionListDialogBox);
                    revisionListDialogBox.activate();
                }
            }
        }
    }
}
Also used : ButtonClickedEvent(org.olat.core.gui.control.generic.modal.ButtonClickedEvent) FileLinkChooserController(org.olat.core.commons.controllers.linkchooser.FileLinkChooserController) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) Roles(org.olat.core.id.Roles) OlatRootFileImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFileImpl) RevisionListController(org.olat.core.commons.modules.bc.version.RevisionListController) Versionable(org.olat.core.util.vfs.version.Versionable) VersionCommentController(org.olat.core.commons.modules.bc.version.VersionCommentController) Versions(org.olat.core.util.vfs.version.Versions) URLChoosenEvent(org.olat.core.commons.controllers.linkchooser.URLChoosenEvent)

Example 17 with Versions

use of org.olat.core.util.vfs.version.Versions in project openolat by klemens.

the class DeletedFileListController method loadModel.

private void loadModel(UserRequest ureq) {
    Collection<String> names = new HashSet<String>();
    for (Versions deletedFile : deletedFiles) {
        if (deletedFile.getCreator() != null && !"-".equals(deletedFile.getCreator())) {
            names.add(deletedFile.getCreator());
        }
        VFSRevision lastRevision = getLastRevision(deletedFile);
        if (lastRevision != null && lastRevision.getAuthor() != null && !"-".equals(lastRevision.getAuthor())) {
            names.add(lastRevision.getAuthor());
        }
    }
    Map<String, String> mappedFullnames = userManager.getUserDisplayNamesByUserName(names);
    DeletedFileListDataModel model = new DeletedFileListDataModel(deletedFiles, mappedFullnames, ureq.getLocale());
    deletedFilesListTableCtr.setTableDataModel(model);
}
Also used : Versions(org.olat.core.util.vfs.version.Versions) VFSRevision(org.olat.core.util.vfs.version.VFSRevision) HashSet(java.util.HashSet)

Example 18 with Versions

use of org.olat.core.util.vfs.version.Versions in project openolat by klemens.

the class DeletedFileListController method renderVersionsAsHtml.

private String renderVersionsAsHtml(List<Versions> versions) {
    StringBuilder sb = new StringBuilder();
    sb.append("<ul>");
    for (Versions version : versions) {
        VFSRevision lastRevision = getLastRevision(version);
        if (lastRevision != null) {
            sb.append("<li>").append(lastRevision.getName()).append("</li>");
        }
    }
    sb.append("</ul>");
    return sb.toString();
}
Also used : Versions(org.olat.core.util.vfs.version.Versions) VFSRevision(org.olat.core.util.vfs.version.VFSRevision)

Example 19 with Versions

use of org.olat.core.util.vfs.version.Versions in project openolat by klemens.

the class DeletedFileListController method event.

@Override
protected void event(UserRequest ureq, Controller source, Event event) {
    if (source == deletedFilesListTableCtr) {
        if (event instanceof TableEvent) {
            TableEvent tEvent = (TableEvent) event;
            int row = tEvent.getRowId();
            if (CMD_DOWNLOAD.equals(tEvent.getActionId())) {
                VFSRevision version = getLastRevision(deletedFiles.get(row));
                MediaResource resource = new VFSRevisionMediaResource(version, true);
                ureq.getDispatchResult().setResultingMediaResource(resource);
            } else if (CMD_RESTORE.equals(tEvent.getActionId())) {
                VFSRevision version = getLastRevision(deletedFiles.get(row));
                if (VersionsManager.getInstance().restore(container, version)) {
                    status = FolderCommandStatus.STATUS_SUCCESS;
                    fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
                } else {
                    status = FolderCommandStatus.STATUS_FAILED;
                // ERROR
                }
            }
        } else if (event instanceof TableMultiSelectEvent) {
            TableMultiSelectEvent tEvent = (TableMultiSelectEvent) event;
            if (CMD_CANCEL.equals(tEvent.getAction())) {
                status = FolderCommandStatus.STATUS_CANCELED;
                fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
            } else if (CMD_RESTORE.equals(tEvent.getAction())) {
                List<VFSRevision> selectedRevisions = getSelectedRevisions(tEvent.getSelection());
                boolean allOk = true;
                for (VFSRevision revision : selectedRevisions) {
                    allOk &= VersionsManager.getInstance().restore(container, revision);
                }
                if (allOk) {
                    status = FolderCommandStatus.STATUS_SUCCESS;
                    fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
                } else {
                    status = FolderCommandStatus.STATUS_FAILED;
                }
            } else if (CMD_DELETE.equals(tEvent.getAction())) {
                List<Versions> versionsToDelete = getSelectedVersions(tEvent.getSelection());
                if (!versionsToDelete.isEmpty()) {
                    String msg = translate("version.del.confirm") + "<p>" + renderVersionsAsHtml(versionsToDelete) + "</p>";
                    // create dialog controller
                    dialogCtr = activateYesNoDialog(ureq, translate("version.del.header"), msg, dialogCtr);
                    dialogCtr.setUserObject(versionsToDelete);
                }
            }
        }
    } else if (source == dialogCtr) {
        if (DialogBoxUIFactory.isYesEvent(event)) {
            @SuppressWarnings("unchecked") List<Versions> versionsToDelete = (List<Versions>) dialogCtr.getUserObject();
            VersionsManager.getInstance().deleteVersions(versionsToDelete);
            status = FolderCommandStatus.STATUS_SUCCESS;
            fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
        }
    }
}
Also used : Versions(org.olat.core.util.vfs.version.Versions) TableEvent(org.olat.core.gui.components.table.TableEvent) VFSRevision(org.olat.core.util.vfs.version.VFSRevision) VFSRevisionMediaResource(org.olat.core.util.vfs.VFSRevisionMediaResource) TableMultiSelectEvent(org.olat.core.gui.components.table.TableMultiSelectEvent) MediaResource(org.olat.core.gui.media.MediaResource) VFSRevisionMediaResource(org.olat.core.util.vfs.VFSRevisionMediaResource) ArrayList(java.util.ArrayList) List(java.util.List)

Example 20 with Versions

use of org.olat.core.util.vfs.version.Versions in project openolat by klemens.

the class RevisionListController method loadModel.

private void loadModel(VFSLeaf versionedLeaf) {
    Versions versions = versionedFile.getVersions();
    List<VFSRevision> revisions = new ArrayList<VFSRevision>(versions.getRevisions());
    revisions.add(new CurrentRevision(versionedLeaf, versions));
    Collection<String> names = new HashSet<String>();
    for (VFSRevision revision : revisions) {
        if (revision.getAuthor() != null) {
            names.add(revision.getAuthor());
        }
    }
    Map<String, IdentityShort> mappedIdentities = new HashMap<String, IdentityShort>();
    for (IdentityShort identity : BaseSecurityManager.getInstance().findShortIdentitiesByName(names)) {
        mappedIdentities.put(identity.getName(), identity);
    }
    revisionListTableCtr.setTableDataModel(new RevisionListDataModel(revisions, mappedIdentities, getLocale()));
}
Also used : Versions(org.olat.core.util.vfs.version.Versions) HashMap(java.util.HashMap) VFSRevision(org.olat.core.util.vfs.version.VFSRevision) IdentityShort(org.olat.basesecurity.IdentityShort) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Aggregations

Versions (org.olat.core.util.vfs.version.Versions)20 Versionable (org.olat.core.util.vfs.version.Versionable)10 VFSRevision (org.olat.core.util.vfs.version.VFSRevision)8 RevisionListController (org.olat.core.commons.modules.bc.version.RevisionListController)6 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)6 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 OlatRootFileImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFileImpl)4 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)4 Date (java.util.Date)2 HashMap (java.util.HashMap)2 List (java.util.List)2 IdentityShort (org.olat.basesecurity.IdentityShort)2 FileLinkChooserController (org.olat.core.commons.controllers.linkchooser.FileLinkChooserController)2 URLChoosenEvent (org.olat.core.commons.controllers.linkchooser.URLChoosenEvent)2 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)2 MetaInfoFactory (org.olat.core.commons.modules.bc.meta.MetaInfoFactory)2 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)2 VersionCommentController (org.olat.core.commons.modules.bc.version.VersionCommentController)2 License (org.olat.core.commons.services.license.License)2