use of org.olat.core.commons.modules.bc.meta.MetaInfo in project OpenOLAT by OpenOLAT.
the class FileUploadController method finishSuccessfullUpload.
/**
* Internal helper to finish the upload and add metadata
*/
private void finishSuccessfullUpload(String filePath, VFSItem item, UserRequest ureq) {
if (item instanceof OlatRootFileImpl) {
OlatRootFileImpl relPathItem = (OlatRootFileImpl) item;
// create meta data
MetaInfo meta = metaInfoFactory.createMetaInfoFor(relPathItem);
if (metaDataCtr != null) {
meta = metaDataCtr.getMetaInfo(meta);
}
meta.setAuthor(getIdentity());
// if overwrite an older file
meta.clearThumbnails();
meta.write();
}
if (item == null) {
logError("File cannot be uploaded: " + filePath, null);
} else {
ThreadLocalUserActivityLogger.log(FolderLoggingAction.FILE_UPLOADED, getClass(), CoreLoggingResourceable.wrapUploadFile(filePath));
// Notify listeners about upload
fireEvent(ureq, new FolderEvent(FolderEvent.UPLOAD_EVENT, item));
}
}
use of org.olat.core.commons.modules.bc.meta.MetaInfo in project OpenOLAT by OpenOLAT.
the class CmdEditMeta method event.
@Override
public void event(UserRequest ureq, Controller source, Event event) {
if (source == metaInfoCtr && event == Event.DONE_EVENT) {
MetaInfo meta = metaInfoCtr.getMetaInfo();
String fileName = metaInfoCtr.getFilename();
if (meta != null) {
meta.write();
if (metaInfoCtr.isFileRenamed()) {
// IMPORTANT: First rename the meta data because underlying file
// has to exist in order to work properly on it's meta data.
VFSContainer container = currentItem.getParentContainer();
if (container.resolve(fileName) != null) {
getWindowControl().setError(translator.translate("TargetNameAlreadyUsed"));
status = FolderCommandStatus.STATUS_FAILED;
} else {
meta.rename(fileName);
if (VFSConstants.NO.equals(currentItem.rename(fileName))) {
getWindowControl().setError(translator.translate("FileRenameFailed", new String[] { fileName }));
status = FolderCommandStatus.STATUS_FAILED;
}
}
}
}
fireEvent(ureq, new FolderEvent(FolderEvent.EDIT_EVENT, fileName));
notifyFinished(ureq);
} else if (event == Event.CANCELLED_EVENT) {
fireEvent(ureq, FOLDERCOMMAND_FINISHED);
}
}
use of org.olat.core.commons.modules.bc.meta.MetaInfo 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.commons.modules.bc.meta.MetaInfo in project OpenOLAT by OpenOLAT.
the class CmdUnzip method doUnzip.
private boolean doUnzip(VFSLeaf vfsItem, VFSContainer currentContainer, UserRequest ureq, WindowControl wControl) {
String name = vfsItem.getName();
if (!name.toLowerCase().endsWith(".zip")) {
wControl.setError(translator.translate("FileUnzipFailed", new String[] { vfsItem.getName() }));
return false;
}
// we make a new folder with the same name as the zip file
String sZipContainer = name.substring(0, name.length() - 4);
boolean versioning = FolderConfig.versionsEnabled(currentContainer);
VFSContainer zipContainer = currentContainer.createChildContainer(sZipContainer);
if (zipContainer == null) {
if (versioning) {
zipContainer = (VFSContainer) currentContainer.resolve(sZipContainer);
} else {
// folder already exists... issue warning
wControl.setError(translator.translate("unzip.alreadyexists", new String[] { sZipContainer }));
return false;
}
} else if (zipContainer instanceof MetaTagged) {
MetaInfo info = ((MetaTagged) zipContainer).getMetaInfo();
if (info != null && ureq.getIdentity() != null) {
info.setAuthor(ureq.getIdentity());
info.write();
}
}
if (!ZipUtil.unzipNonStrict(vfsItem, zipContainer, ureq.getIdentity(), versioning)) {
// operation failed - rollback
zipContainer.delete();
wControl.setError(translator.translate("failed"));
return false;
} else {
// check quota
long quotaLeftKB = VFSManager.getQuotaLeftKB(currentContainer);
if (quotaLeftKB != Quota.UNLIMITED && quotaLeftKB < 0) {
// quota exceeded - rollback
zipContainer.delete();
wControl.setError(translator.translate("QuotaExceeded"));
return false;
}
}
return true;
}
use of org.olat.core.commons.modules.bc.meta.MetaInfo in project OpenOLAT by OpenOLAT.
the class OlatRootFolderTreeModel method createNode.
/**
* Create a node out of a relative path vfs item. The user object is set to
* the relative path.
*
* @param item
*/
private OlatRootFolderTreeNode createNode(OlatRelPathImpl item) {
OlatRootFolderTreeNode node = new OlatRootFolderTreeNode(item, this);
MetaInfo meta = metaInfoFactory.createMetaInfoFor(item);
if (meta != null) {
String title = meta.getTitle();
if (StringHelper.containsNonWhitespace(title)) {
node.setTitle(title);
} else {
node.setTitle(meta.getName());
}
} else {
// TODO:GW log warning that
// "metadate couldn't be loaded for folder relpath: " +
// folder.getRelPath();
}
node.setUserObject(item.getRelPath());
return node;
}
Aggregations