use of org.olat.modules.portfolio.Media in project OpenOLAT by OpenOLAT.
the class ForumMediaHandler method createMedia.
@Override
public Media createMedia(String title, String description, Object mediaObject, String businessPath, Identity author) {
Message message = null;
if (mediaObject instanceof Message) {
// reload the message
message = (Message) mediaObject;
message = forumManager.loadMessage(message.getKey());
} else if (mediaObject instanceof MessageLight) {
MessageLight messageLight = (MessageLight) mediaObject;
message = forumManager.loadMessage(messageLight.getKey());
}
String content = message.getBody();
Media media = mediaDao.createMedia(title, description, content, FORUM_HANDLER, businessPath, null, 70, author);
ThreadLocalUserActivityLogger.log(PortfolioLoggingAction.PORTFOLIO_MEDIA_ADDED, getClass(), LoggingResourceable.wrap(media));
File messageDir = forumManager.getMessageDirectory(message.getForum().getKey(), message.getKey(), false);
if (messageDir != null && messageDir.exists()) {
File[] attachments = messageDir.listFiles();
if (attachments.length > 0) {
File mediaDir = fileStorage.generateMediaSubDirectory(media);
for (File attachment : attachments) {
FileUtils.copyFileToDir(attachment, mediaDir, "Forum media");
}
String storagePath = fileStorage.getRelativePath(mediaDir);
media = mediaDao.updateStoragePath(media, storagePath, null);
}
}
return media;
}
use of org.olat.modules.portfolio.Media in project OpenOLAT by OpenOLAT.
the class ForumMediaHandler method createMedia.
@Override
public Media createMedia(AbstractArtefact artefact) {
VFSContainer artefactFolder = oldPortfolioManager.getArtefactContainer(artefact);
String businessPath = artefact.getBusinessPath();
if (businessPath == null) {
businessPath = "[PortfolioV2:0][MediaCenter:0]";
}
Media media = mediaDao.createMedia(artefact.getTitle(), artefact.getDescription(), null, FORUM_HANDLER, businessPath, artefact.getKey().toString(), artefact.getSignature(), artefact.getAuthor());
ThreadLocalUserActivityLogger.log(PortfolioLoggingAction.PORTFOLIO_MEDIA_ADDED, getClass(), LoggingResourceable.wrap(media));
List<VFSItem> items = artefactFolder.getItems(new SystemItemFilter());
if (items.size() > 0) {
File mediaDir = fileStorage.generateMediaSubDirectory(media);
String storagePath = fileStorage.getRelativePath(mediaDir);
mediaDao.updateStoragePath(media, storagePath, null);
VFSContainer mediaContainer = fileStorage.getMediaContainer(media);
VFSManager.copyContent(artefactFolder, mediaContainer);
}
return media;
}
use of org.olat.modules.portfolio.Media in project OpenOLAT by OpenOLAT.
the class ImageMediaEditorController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
Media media = mediaPart.getMedia();
File mediaDir = new File(FolderConfig.getCanonicalRoot(), media.getStoragePath());
File mediaFile = new File(mediaDir, media.getRootFilename());
ImageFormItem imageEl = new ImageFormItem(ureq.getUserSession(), "image");
imageEl.setMedia(mediaFile);
formLayout.add("image", imageEl);
alignmentEl = uifactory.addDropdownSingleselect("alignment", null, formLayout, alignmentKeys, alignmentKeys, null);
alignmentEl.addActionListener(FormEvent.ONCHANGE);
if (StringHelper.containsNonWhitespace(mediaPart.getLayoutOptions())) {
for (String alignmentKey : alignmentKeys) {
if (mediaPart.getLayoutOptions().contains(alignmentKey)) {
alignmentEl.select(alignmentKey, true);
}
}
}
}
use of org.olat.modules.portfolio.Media in project OpenOLAT by OpenOLAT.
the class MediaDAOTest method usedInBinders.
@Test
public void usedInBinders() {
Identity author = JunitTestHelper.createAndPersistIdentityAsRndUser("pf-media-2");
Binder binder = portfolioService.createNewBinder("Binder p2", "A binder with 2 page", null, author);
Section section = binderDao.createSection("Section", "First section", null, null, binder);
dbInstance.commitAndCloseSession();
Section reloadedSection = binderDao.loadSectionByKey(section.getKey());
Page page = pageDao.createAndPersist("Page 1", "A page with content.", null, null, true, reloadedSection, null);
Media media = mediaDao.createMedia("Media", "Binder", "Une citation sur les classeurs", TextHandler.TEXT_MEDIA, "[Media:0]", null, 10, author);
dbInstance.commitAndCloseSession();
MediaPart mediaPart = new MediaPart();
mediaPart.setMedia(media);
PageBody reloadedBody = pageDao.loadPageBodyByKey(page.getBody().getKey());
pageDao.persistPart(reloadedBody, mediaPart);
dbInstance.commitAndCloseSession();
// reload
List<BinderPageUsage> binders = mediaDao.usedInBinders(media);
Assert.assertNotNull(binders);
Assert.assertEquals(1, binders.size());
Assert.assertTrue(binders.get(0).getBinderKey().equals(binder.getKey()));
}
use of org.olat.modules.portfolio.Media in project openolat by klemens.
the class MediaDAO method deleteMedia.
public void deleteMedia(Media media) {
if (StringHelper.containsNonWhitespace(media.getRootFilename())) {
VFSContainer container = fileStorage.getMediaContainer(media);
VFSItem item = container.resolve(media.getRootFilename());
if (item instanceof VFSLeaf) {
((VFSLeaf) item).delete();
}
}
Media reloadedMedia = dbInstance.getCurrentEntityManager().getReference(MediaImpl.class, media.getKey());
dbInstance.getCurrentEntityManager().remove(reloadedMedia);
}
Aggregations