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