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