use of org.olat.modules.portfolio.Media in project openolat by klemens.
the class CitationHandler method createMedia.
@Override
public Media createMedia(String title, String description, Object mediaObject, String businessPath, Identity author) {
Media media = mediaDao.createMedia(title, description, (String) mediaObject, CITATION_MEDIA, businessPath, null, 60, author);
ThreadLocalUserActivityLogger.log(PortfolioLoggingAction.PORTFOLIO_MEDIA_ADDED, getClass(), LoggingResourceable.wrap(media));
return media;
}
use of org.olat.modules.portfolio.Media in project openolat by klemens.
the class FileHandler method createMedia.
public Media createMedia(String title, String description, File file, String filename, String businessPath, Identity author) {
Media media = mediaDao.createMedia(title, description, filename, FILE_TYPE, businessPath, null, 60, author);
ThreadLocalUserActivityLogger.log(PortfolioLoggingAction.PORTFOLIO_MEDIA_ADDED, getClass(), LoggingResourceable.wrap(media));
File mediaDir = fileStorage.generateMediaSubDirectory(media);
File mediaFile = new File(mediaDir, filename);
FileUtils.copyFileToFile(file, mediaFile, false);
String storagePath = fileStorage.getRelativePath(mediaDir);
mediaDao.updateStoragePath(media, storagePath, filename);
return media;
}
use of org.olat.modules.portfolio.Media in project openolat by klemens.
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 CategoryDAOTest method getMediaCategoriesStatistics.
@Test
public void getMediaCategoriesStatistics() {
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("pf-media-1");
Media media = mediaDao.createMedia("Media to categorize", "Media category", "Media content", "text", "[Media:0]", null, 10, id);
dbInstance.commit();
Category category = categoryDao.createAndPersistCategory("Cool");
OLATResourceable ores = OresHelper.createOLATResourceableInstance(Media.class, media.getKey());
categoryDao.appendRelation(ores, category);
dbInstance.commitAndCloseSession();
// load medias
List<CategoryStatistics> catStatistics = categoryDao.getMediaCategoriesStatistics(id);
Assert.assertNotNull(catStatistics);
Assert.assertEquals(1, catStatistics.size());
Assert.assertEquals(category.getName(), catStatistics.get(0).getName());
Assert.assertTrue(1 <= catStatistics.get(0).getCount());
}
use of org.olat.modules.portfolio.Media in project OpenOLAT by OpenOLAT.
the class CategoryDAOTest method getMediaCategories.
@Test
public void getMediaCategories() {
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("pf-media-1");
Media media = mediaDao.createMedia("Media to categorize", "Media category", "Media content", "text", "[Media:0]", null, 10, id);
dbInstance.commit();
Category category = categoryDao.createAndPersistCategory("Cool");
OLATResourceable ores = OresHelper.createOLATResourceableInstance(Media.class, media.getKey());
categoryDao.appendRelation(ores, category);
dbInstance.commitAndCloseSession();
// load medias
List<CategoryLight> categories = categoryDao.getMediaCategories(id);
Assert.assertNotNull(categories);
Assert.assertEquals(1, categories.size());
Assert.assertEquals(category.getName(), categories.get(0).getCategory());
}
Aggregations