use of org.olat.core.commons.modules.bc.meta.MetaInfo in project OpenOLAT by OpenOLAT.
the class VideoHandler method getThumbnail.
@Override
public VFSLeaf getThumbnail(MediaLight media, Size size) {
String storagePath = media.getStoragePath();
VFSLeaf thumbnail = null;
if (StringHelper.containsNonWhitespace(storagePath)) {
VFSContainer storageContainer = fileStorage.getMediaContainer(media);
VFSItem item = storageContainer.resolve(media.getRootFilename());
if (item instanceof VFSLeaf) {
VFSLeaf leaf = (VFSLeaf) item;
if (leaf instanceof MetaTagged) {
MetaInfo metaInfo = ((MetaTagged) leaf).getMetaInfo();
thumbnail = metaInfo.getThumbnail(size.getHeight(), size.getWidth(), true);
}
}
}
return thumbnail;
}
use of org.olat.core.commons.modules.bc.meta.MetaInfo in project OpenOLAT by OpenOLAT.
the class VersionsFileManager method addToRevisions.
/**
* @see org.olat.core.util.vfs.version.VersionsManager#addToRevisions(org.olat.core.util.vfs.version.Versionable, org.olat.core.id.Identity, java.lang.String)
*/
@Override
public boolean addToRevisions(Versionable currentVersion, Identity identity, String comment) {
int maxNumOfVersions = versioningConfigurator.getMaxNumOfVersionsAllowed();
if (maxNumOfVersions == 0) {
// deactivated, return all ok
return true;
}
VFSLeaf currentFile = (VFSLeaf) currentVersion;
VFSLeaf versionFile = getCanonicalVersionXmlFile(currentFile, true);
if (versionFile == null) {
// cannot do something with the current file
return false;
}
VFSContainer versionContainer = versionFile.getParentContainer();
String name = currentFile.getName();
// read from the
Versions v = readVersions(currentFile, versionFile);
if (!(v instanceof VersionsFileImpl)) {
log.error("Wrong implementation of Versions: " + v);
return false;
}
VersionsFileImpl versions = (VersionsFileImpl) v;
boolean sameFile = isSameFile(currentFile, versions);
String uuid = sameFile ? getLastRevisionFilename(versions) : UUID.randomUUID().toString() + "_" + name;
String versionNr = getNextRevisionNr(versions);
String currentAuthor = versions.getAuthor();
long lastModifiedDate = 0;
if (currentFile instanceof MetaTagged) {
MetaInfo metaInfo = ((MetaTagged) currentFile).getMetaInfo();
if (metaInfo != null) {
metaInfo.clearThumbnails();
if (currentAuthor == null) {
currentAuthor = metaInfo.getAuthor();
}
lastModifiedDate = metaInfo.getLastModified();
}
}
if (lastModifiedDate <= 0) {
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
lastModifiedDate = cal.getTimeInMillis();
}
RevisionFileImpl newRevision = new RevisionFileImpl();
newRevision.setUuid(UUID.randomUUID().toString());
newRevision.setName(name);
newRevision.setFilename(uuid);
newRevision.setRevisionNr(versionNr);
newRevision.setComment(versions.getComment());
newRevision.setAuthor(currentAuthor);
newRevision.setLastModified(lastModifiedDate);
if (versions.getRevisions().isEmpty() && currentVersion instanceof MetaTagged) {
MetaTagged metaTagged = (MetaTagged) currentVersion;
versions.setCreator(metaTagged.getMetaInfo().getAuthor());
}
if (sameFile || VFSManager.copyContent(currentFile, versionContainer.createChildLeaf(uuid))) {
if (identity != null) {
versions.setAuthor(identity.getName());
}
if (maxNumOfVersions >= 0 && versions.getRevisions().size() >= maxNumOfVersions) {
List<VFSRevision> revisions = versions.getRevisions();
int numOfVersionsToDelete = Math.min(revisions.size(), (revisions.size() - maxNumOfVersions) + 1);
if (numOfVersionsToDelete > 0) {
List<VFSRevision> versionsToDelete = revisions.subList(0, numOfVersionsToDelete);
deleteRevisions(currentVersion, versionsToDelete);
versions = (VersionsFileImpl) currentVersion.getVersions();
}
}
versions.setComment(comment);
versions.getRevisions().add(newRevision);
versions.setRevisionNr(getNextRevisionNr(versions));
XStreamHelper.writeObject(mystream, versionFile, versions);
if (currentVersion.getVersions() instanceof VersionsFileImpl) {
((VersionsFileImpl) currentVersion.getVersions()).update(versions);
}
return true;
} else {
log.error("Cannot create a version of this file: " + currentVersion);
}
return false;
}
use of org.olat.core.commons.modules.bc.meta.MetaInfo in project OpenOLAT by OpenOLAT.
the class DropboxController method event.
/**
* @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
*/
@Override
public void event(UserRequest ureq, Controller source, Event event) {
if (source == fileChooserController) {
cmc.deactivate();
if (event.equals(Event.DONE_EVENT)) {
boolean success = false;
File fIn = fileChooserController.getUploadFile();
VFSContainer fDropbox = getDropBox(ureq.getIdentity());
String filename = fileChooserController.getUploadFileName();
VFSLeaf fOut;
if (fDropbox.resolve(filename) != null) {
// FIXME ms: check if dropbox quota is exceeded -> clarify with customers
fOut = fDropbox.createChildLeaf(getNewUniqueName(filename));
} else {
fOut = fDropbox.createChildLeaf(filename);
}
try {
InputStream in = new FileInputStream(fIn);
OutputStream out = new BufferedOutputStream(fOut.getOutputStream(false));
success = FileUtils.copy(in, out);
FileUtils.closeSafely(in);
FileUtils.closeSafely(out);
} catch (FileNotFoundException e) {
logError("", e);
return;
}
if (fOut instanceof MetaTagged) {
MetaInfo info = ((MetaTagged) fOut).getMetaInfo();
if (info != null) {
info.setAuthor(ureq.getIdentity());
info.write();
}
}
if (success) {
int numFiles = fDropbox.getItems().size();
myContent.contextPut("numfiles", new String[] { Integer.toString(numFiles) });
// assemble confirmation
String confirmation = getConfirmation(ureq, fOut.getName());
// send email if necessary
Boolean sendEmail = (Boolean) config.get(TACourseNode.CONF_DROPBOX_ENABLEMAIL);
if (sendEmail == null)
sendEmail = Boolean.FALSE;
boolean sendMailError = false;
if (sendEmail.booleanValue()) {
// send mail
MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
MailBundle bundle = new MailBundle();
bundle.setContext(context);
bundle.setToId(ureq.getIdentity());
bundle.setContent(translate("conf.mail.subject"), confirmation);
MailerResult result = CoreSpringFactory.getImpl(MailManager.class).sendMessage(bundle);
if (result.getFailedIdentites().size() > 0) {
List<Identity> disabledIdentities = new ArrayList<Identity>();
disabledIdentities = result.getFailedIdentites();
// show error that message can not be sent
ArrayList<String> myButtons = new ArrayList<String>();
myButtons.add(translate("back"));
String title = MailHelper.getTitleForFailedUsersError(ureq.getLocale());
String message = MailHelper.getMessageForFailedUsersError(ureq.getLocale(), disabledIdentities);
// add dropbox specific error message
message += "\n<br />" + translate("conf.mail.error");
// FIXME:FG:6.2: fix problem in info message, not here
message += "\n<br />\n<br />" + confirmation.replace("\n", " ").replace("\r", " ").replace("\u2028", " ");
DialogBoxController noUsersErrorCtr = null;
noUsersErrorCtr = activateGenericDialog(ureq, title, message, myButtons, noUsersErrorCtr);
sendMailError = true;
} else if (result.getReturnCode() > 0) {
// show error that message can not be sent
ArrayList<String> myButtons = new ArrayList<String>();
myButtons.add(translate("back"));
DialogBoxController noUsersErrorCtr = null;
String message = translate("conf.mail.error");
// FIXME:FG:6.2: fix problem in info message, not here
message += "\n<br />\n<br />" + confirmation.replace("\n", " ").replace("\r", " ").replace("\u2028", " ");
noUsersErrorCtr = activateGenericDialog(ureq, translate("error.header"), message, myButtons, noUsersErrorCtr);
sendMailError = true;
}
}
// inform subscription manager about new element
if (subsContext != null) {
NotificationsManager.getInstance().markPublisherNews(subsContext, ureq.getIdentity(), true);
}
// FIXME:FG:6.2: fix problem in info message, not here
if (!sendMailError) {
getWindowControl().setInfo(confirmation.replace("\n", " ").replace("\r", " ").replace("\u2028", " "));
}
} else {
showInfo("dropbox.upload.failed");
}
}
}
}
use of org.olat.core.commons.modules.bc.meta.MetaInfo in project OpenOLAT by OpenOLAT.
the class SubmitDocumentsController method updateModel.
private void updateModel() {
File[] documents = documentsDir.listFiles(new SystemFileFilter(true, false));
List<SubmittedSolution> docList = new ArrayList<>(documents.length);
for (File document : documents) {
String filename = document.getName();
String uploadedBy = null;
VFSItem item = documentsContainer.resolve(filename);
if (item instanceof MetaTagged) {
MetaInfo metaInfo = ((MetaTagged) item).getMetaInfo();
if (metaInfo != null && metaInfo.getAuthorIdentityKey() != null) {
uploadedBy = userManager.getUserDisplayName(metaInfo.getAuthorIdentityKey());
}
}
FormItem download;
if (filename.endsWith(".html")) {
download = uifactory.addFormLink("view-" + CodeHelper.getRAMUniqueID(), "view", filename, null, flc, Link.LINK | Link.NONTRANSLATED);
download.setUserObject(filename);
} else {
download = uifactory.addDownloadLink("view-" + CodeHelper.getRAMUniqueID(), filename, null, document, tableEl);
}
docList.add(new SubmittedSolution(document, uploadedBy, download));
}
model.setObjects(docList);
tableEl.reset();
if (maxDocs > 0 && docList.size() >= maxDocs) {
if (uploadDocButton != null) {
uploadDocButton.setEnabled(false);
}
if (createDocButton != null) {
createDocButton.setEnabled(false);
}
String msg = translate("error.max.documents", new String[] { Integer.toString(maxDocs) });
flc.contextPut("maxDocsWarning", msg);
} else {
if (uploadDocButton != null) {
uploadDocButton.setEnabled(true);
}
if (createDocButton != null) {
createDocButton.setEnabled(true);
}
flc.contextPut("maxDocsWarning", Boolean.FALSE);
}
flc.contextPut("hasDocuments", Boolean.valueOf(hasUploadDocuments()));
}
use of org.olat.core.commons.modules.bc.meta.MetaInfo in project OpenOLAT by OpenOLAT.
the class SubmitDocumentsController method doCreateDocumentEditor.
private void doCreateDocumentEditor(UserRequest ureq, String documentName) {
if (newDocumentEditorCtrl != null)
return;
if (maxDocs > 0 && maxDocs <= model.getRowCount()) {
showWarning("error.max.documents");
} else {
VFSItem item = documentsContainer.resolve(documentName);
if (item == null) {
documentsContainer.createChildLeaf(documentName);
} else {
documentName = VFSManager.rename(documentsContainer, documentName);
documentsContainer.createChildLeaf(documentName);
}
// add missing identity in meta info
item = documentsContainer.resolve(documentName);
if (item instanceof MetaTagged) {
MetaInfo metadata = ((MetaTagged) item).getMetaInfo();
metadata.setAuthor(ureq.getIdentity());
metadata.write();
}
newDocumentEditorCtrl = WysiwygFactory.createWysiwygController(ureq, getWindowControl(), documentsContainer, documentName, "media", true, true);
newDocumentEditorCtrl.getRichTextConfiguration().disableMedia();
newDocumentEditorCtrl.getRichTextConfiguration().setAllowCustomMediaFactory(false);
newDocumentEditorCtrl.setNewFile(true);
listenTo(newDocumentEditorCtrl);
cmc = new CloseableModalController(getWindowControl(), "close", newDocumentEditorCtrl.getInitialComponent());
listenTo(cmc);
cmc.activate();
}
}
Aggregations