Search in sources :

Example 16 with Versionable

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

the class FileUploadController method event.

@Override
public void event(UserRequest ureq, Controller source, Event event) {
    if (source == overwriteDialog) {
        if (event instanceof ButtonClickedEvent) {
            ButtonClickedEvent buttonClickedEvent = (ButtonClickedEvent) event;
            if (buttonClickedEvent.getPosition() == 0) {
                // ok
                doFinishOverwrite(ureq);
            } else if (buttonClickedEvent.getPosition() == 1) {
                // not ok
                // Upload renamed. Since we've already uploaded the file with a changed name, don't do anything much here...
                fileOverwritten = true;
                // ... and notify listeners.
                finishUpload(ureq);
            } else if (buttonClickedEvent.getPosition() == 2) {
                // cancel
                // Cancel. Remove the new file since it has already been uploaded. Note that we don't have to explicitly close the
                // dialog box since it closes itself whenever something gets clicked.
                doCancel(ureq);
            }
        }
    } else if (source == lockedFileDialog) {
        if (event instanceof ButtonClickedEvent) {
            ButtonClickedEvent buttonClickedEvent = (ButtonClickedEvent) event;
            if (buttonClickedEvent.getPosition() == 0) {
                // upload the file with a new name
                fileOverwritten = true;
                // ... and notify listeners.
                finishUpload(ureq);
            } else if (buttonClickedEvent.getPosition() == 1) {
                doCancel(ureq);
            }
        }
    } else if (source == commentVersionCtr) {
        doFinishComment(ureq);
    } else if (source == unlockCtr) {
        // Overwrite...
        String fileName = existingVFSItem.getName();
        if (!unlockCtr.keepLocked()) {
            vfsLockManager.unlock(existingVFSItem, getIdentity(), ureq.getUserSession().getRoles());
        }
        unlockDialogBox.deactivate();
        existingVFSItem.delete();
        newFile.rename(fileName);
        // ... and notify listeners.
        finishUpload(ureq);
    } else if (source == revisionListDialogBox) {
        removeAsListenerAndDispose(revisionListCtr);
        revisionListCtr = null;
        removeAsListenerAndDispose(revisionListDialogBox);
        revisionListDialogBox = null;
        doCancel(ureq);
    } else if (source == revisionListCtr) {
        revisionListDialogBox.deactivate();
        removeAsListenerAndDispose(revisionListDialogBox);
        revisionListDialogBox = null;
        if (FolderCommandStatus.STATUS_CANCELED == revisionListCtr.getStatus()) {
            // don't want to delete revisions, clean the temporary file
            doCancel(ureq);
        } else if (existingVFSItem instanceof Versionable && ((Versionable) existingVFSItem).getVersions().isVersioned()) {
            doFinishRevisionList(ureq);
        }
    }
}
Also used : ButtonClickedEvent(org.olat.core.gui.control.generic.modal.ButtonClickedEvent) Versionable(org.olat.core.util.vfs.version.Versionable)

Example 17 with Versionable

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

the class FileUploadController method doFinishRevisionList.

private void doFinishRevisionList(UserRequest ureq) {
    if (existingVFSItem.getParentContainer() != null) {
        existingVFSItem = existingVFSItem.getParentContainer().resolve(existingVFSItem.getName());
    }
    Versionable versionable = (Versionable) existingVFSItem;
    Versions versions = versionable.getVersions();
    int maxNumOfRevisions = getMaxNumOfRevisionsOfExistingVFSItem();
    if (maxNumOfRevisions < 0 || maxNumOfRevisions > versions.getRevisions().size()) {
        askForComment(ureq);
    } else {
        askToReduceRevisionList(ureq, versionable);
    }
}
Also used : Versionable(org.olat.core.util.vfs.version.Versionable) Versions(org.olat.core.util.vfs.version.Versions)

Example 18 with Versionable

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

the class FileUploadController method uploadVersionedFile.

private void uploadVersionedFile(UserRequest ureq, String renamedFilename) {
    Versionable versionable = (Versionable) existingVFSItem;
    Versions versions = versionable.getVersions();
    int maxNumOfRevisions = getMaxNumOfRevisionsOfExistingVFSItem();
    if (maxNumOfRevisions == 0) {
        // it's possible if someone change the configuration
        // let calling method decide what to do.
        askOverwriteOrRename(ureq, renamedFilename);
    } else if (versions.getRevisions().isEmpty() || maxNumOfRevisions < 0 || maxNumOfRevisions > versions.getRevisions().size()) {
        // let calling method decide what to do.
        askNewVersionOrRename(ureq, renamedFilename);
    } else {
        // too many revisions
        askToReduceRevisionList(ureq, versionable);
    }
}
Also used : Versionable(org.olat.core.util.vfs.version.Versionable) Versions(org.olat.core.util.vfs.version.Versions)

Example 19 with Versionable

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

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 20 with Versionable

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

the class VFSResourceRoot method write.

@Override
public boolean write(String path, InputStream is, boolean overwrite, WebResource movedFrom) throws QuotaExceededException {
    VFSLeaf childLeaf;
    VFSItem file = resolveFile(path);
    if (file instanceof VFSLeaf) {
        if (overwrite) {
            // overwrite the file
            childLeaf = (VFSLeaf) file;
            // versioning
            if (childLeaf instanceof Versionable && ((Versionable) childLeaf).getVersions().isVersioned()) {
                if (childLeaf.getSize() == 0) {
                    VersionsManager.getInstance().createVersionsFor(childLeaf, true);
                } else {
                    VersionsManager.getInstance().addToRevisions((Versionable) childLeaf, identity, "");
                }
            }
        } else {
            return false;
        }
    } else if (file instanceof VFSContainer) {
        return false;
    } else {
        // create a new file
        int lastSlash = path.lastIndexOf('/');
        if (lastSlash == -1)
            return false;
        String parentPath = path.substring(0, lastSlash);
        VFSItem parentItem = resolveFile(parentPath);
        if (parentItem instanceof VFSContainer) {
            VFSContainer folder = (VFSContainer) parentItem;
            String name = path.substring(lastSlash + 1);
            childLeaf = folder.createChildLeaf(name);
        } else {
            return false;
        }
    }
    if (childLeaf == null) {
        return false;
    }
    try {
        copyVFS(childLeaf, is);
    } catch (QuotaExceededException e) {
        throw e;
    } catch (Exception e) {
        log.error("", e);
        return false;
    }
    VFSContainer inheritingCont = VFSManager.findInheritingSecurityCallbackContainer(childLeaf.getParentContainer());
    if (inheritingCont != null) {
        VFSSecurityCallback callback = inheritingCont.getLocalSecurityCallback();
        if (callback != null && callback.getSubscriptionContext() != null) {
            SubscriptionContext subContext = callback.getSubscriptionContext();
            NotificationsManager.getInstance().markPublisherNews(subContext, null, true);
        }
    }
    if (childLeaf instanceof MetaTagged && identity != null) {
        MetaInfo infos = ((MetaTagged) childLeaf).getMetaInfo();
        if (infos != null && !infos.hasAuthorIdentity()) {
            infos.setAuthor(identity);
            addLicense(infos, identity);
            infos.clearThumbnails();
        // infos.write(); the clearThumbnails call write()
        }
    }
    if (movedFrom instanceof VFSResource) {
        VFSResource vfsResource = (VFSResource) movedFrom;
        if (vfsResource.getItem() instanceof Versionable && ((Versionable) vfsResource.getItem()).getVersions().isVersioned()) {
            VFSLeaf currentVersion = (VFSLeaf) vfsResource.getItem();
            VersionsManager.getInstance().move(currentVersion, childLeaf, identity);
        }
    }
    return true;
}
Also used : Versionable(org.olat.core.util.vfs.version.Versionable) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) QuotaExceededException(org.olat.core.util.vfs.QuotaExceededException) 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) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) VFSSecurityCallback(org.olat.core.util.vfs.callbacks.VFSSecurityCallback) IOException(java.io.IOException) QuotaExceededException(org.olat.core.util.vfs.QuotaExceededException)

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