Search in sources :

Example 11 with VFSRevision

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

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

use of org.olat.core.util.vfs.version.VFSRevision 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)

Example 14 with VFSRevision

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

the class RevisionListController method getSelectedRevisions.

private List<VFSRevision> getSelectedRevisions(BitSet objectMarkers) {
    List<VFSRevision> allVersions = versionedFile.getVersions().getRevisions();
    List<VFSRevision> results = new ArrayList<VFSRevision>();
    for (int i = objectMarkers.nextSetBit(0); i >= 0; i = objectMarkers.nextSetBit(i + 1)) {
        if (i >= 0 && i < allVersions.size()) {
            VFSRevision elem = allVersions.get(i);
            results.add(elem);
        }
    }
    return results;
}
Also used : VFSRevision(org.olat.core.util.vfs.version.VFSRevision) ArrayList(java.util.ArrayList)

Aggregations

VFSRevision (org.olat.core.util.vfs.version.VFSRevision)14 ArrayList (java.util.ArrayList)8 Versions (org.olat.core.util.vfs.version.Versions)8 HashSet (java.util.HashSet)4 List (java.util.List)4 TableEvent (org.olat.core.gui.components.table.TableEvent)4 TableMultiSelectEvent (org.olat.core.gui.components.table.TableMultiSelectEvent)4 MediaResource (org.olat.core.gui.media.MediaResource)4 VFSRevisionMediaResource (org.olat.core.util.vfs.VFSRevisionMediaResource)4 DecimalFormat (java.text.DecimalFormat)2 DecimalFormatSymbols (java.text.DecimalFormatSymbols)2 HashMap (java.util.HashMap)2 IdentityShort (org.olat.basesecurity.IdentityShort)2 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)2 VFSMediaResource (org.olat.core.util.vfs.VFSMediaResource)2 OrphanVersion (org.olat.core.util.vfs.version.OrphanVersion)2