use of org.olat.core.commons.modules.bc.meta.tagged.MetaTagged 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.tagged.MetaTagged 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.tagged.MetaTagged in project OpenOLAT by OpenOLAT.
the class SendDocumentsByEMailController method setFiles.
protected void setFiles(VFSContainer rootContainer, List<VFSLeaf> leafs) {
this.files = leafs;
StringBuilder subjectSb = new StringBuilder();
if (StringHelper.containsNonWhitespace(subjectElement.getValue())) {
subjectSb.append(subjectElement.getValue()).append('\n').append('\n');
}
StringBuilder bodySb = new StringBuilder();
if (StringHelper.containsNonWhitespace(bodyElement.getValue())) {
bodySb.append(bodyElement.getValue()).append('\n').append('\n');
}
attachments = new ArrayList<File>();
long fileSize = 0l;
for (VFSLeaf file : files) {
MetaInfo infos = null;
if (file instanceof MetaTagged) {
infos = ((MetaTagged) file).getMetaInfo();
}
// subject
appendToSubject(file, infos, subjectSb);
// body
appendMetadatas(file, infos, bodySb);
appendBusinessPath(rootContainer, file, bodySb);
bodySb.append('\n').append('\n');
fileSize += file.getSize();
if (allowAttachments && file instanceof LocalFileImpl) {
File f = ((LocalFileImpl) file).getBasefile();
attachments.add(f);
}
}
int mailQuota = CoreSpringFactory.getImpl(MailModule.class).getMaxSizeForAttachement();
long fileSizeInMB = fileSize / (1024l * 1024l);
if (allowAttachments) {
if (fileSizeInMB > mailQuota) {
attachments.clear();
setFormWarning("send.mail.fileToBigForAttachments", new String[] { String.valueOf(mailQuota), String.valueOf(fileSizeInMB) });
} else {
List<FileInfo> infos = new ArrayList<FileInfo>(files.size());
for (VFSLeaf file : files) {
final String name = file.getName();
final double size = file.getSize() / (1024.0 * 1024.0);
final String sizeStr = formatMb.format(size);
final String cssClass = CSSHelper.createFiletypeIconCssClassFor(file.getName());
infos.add(new FileInfo(name, sizeStr, cssClass));
}
attachmentsLayout.contextPut("attachments", infos);
}
}
subjectElement.setValue(subjectSb.toString());
bodyElement.setValue(bodySb.toString());
}
use of org.olat.core.commons.modules.bc.meta.tagged.MetaTagged in project OpenOLAT by OpenOLAT.
the class ConvertToGTACourseNode method convertMetada.
private void convertMetada(VFSContainer source, VFSContainer target, String name, TaskDefinition taskDef, Solution solDef) {
VFSItem sourceItem = source.resolve(name);
VFSItem targetItem = target.resolve(name);
if (sourceItem instanceof MetaTagged && targetItem instanceof MetaTagged) {
MetaTagged taggedSource = (MetaTagged) sourceItem;
MetaInfo metaSource = taggedSource.getMetaInfo();
MetaTagged taggedTarget = (MetaTagged) targetItem;
MetaInfo metaTarget = taggedTarget.getMetaInfo();
if (metaSource != null) {
if (taskDef != null) {
if (StringHelper.containsNonWhitespace(metaSource.getTitle())) {
taskDef.setTitle(metaSource.getTitle());
}
taskDef.setDescription(metaSource.getComment());
}
if (solDef != null) {
if (StringHelper.containsNonWhitespace(metaSource.getTitle())) {
solDef.setTitle(metaSource.getTitle());
}
}
if (metaTarget != null) {
metaTarget.copyValues(metaSource);
metaTarget.write();
}
}
}
}
use of org.olat.core.commons.modules.bc.meta.tagged.MetaTagged in project OpenOLAT by OpenOLAT.
the class ImageHandler method getInformations.
@Override
public MediaInformations getInformations(Object mediaObject) {
String title = null;
String description = null;
if (mediaObject instanceof MetaTagged) {
MetaInfo meta = ((MetaTagged) mediaObject).getMetaInfo();
title = meta.getTitle();
description = meta.getComment();
}
return new Informations(title, description);
}
Aggregations