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();
}
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);
}
}
}
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()));
}
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;
}
Aggregations