use of org.olat.core.commons.modules.bc.meta.tagged.MetaTagged in project OpenOLAT by OpenOLAT.
the class ImageHandler 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.tagged.MetaTagged 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.tagged.MetaTagged in project OpenOLAT by OpenOLAT.
the class VFSLockManagerImpl method lock.
@Override
public boolean lock(VFSItem item, Identity identity, Roles roles) {
if (item instanceof MetaTagged) {
MetaInfoFileImpl info = (MetaInfoFileImpl) ((MetaTagged) item).getMetaInfo();
info.setLockedBy(identity.getKey());
info.setLockedDate(new Date());
info.setLocked(true);
info.write();
File file = extractFile(item);
if (file != null && fileLocks.containsKey(file)) {
LockInfo lock = fileLocks.get(file);
if (lock != null) {
lock.setVfsLock(true);
}
}
return true;
}
return false;
}
use of org.olat.core.commons.modules.bc.meta.tagged.MetaTagged 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.tagged.MetaTagged 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");
}
}
}
}
Aggregations