use of org.olat.modules.portfolio.MediaLight in project openolat by klemens.
the class MediaDAOTest method searchByAuthor.
@Test
public void searchByAuthor() {
Identity author = JunitTestHelper.createAndPersistIdentityAsRndUser("pf-media-2");
Media media1 = mediaDao.createMedia("Media 1", "The media theory", "Media theory is very important subject", "Forum", "[Media:0]", null, 10, author);
Media media2 = mediaDao.createMedia("Media 2", "Java", "One of the most widespread programming language", "Forum", "[Media:0]", null, 10, author);
Media media3 = mediaDao.createMedia("Media 3", "Europe", "Un continent", "Forum", "[Media:0]", null, 10, author);
dbInstance.commit();
// not owned
Identity someoneElse = JunitTestHelper.createAndPersistIdentityAsRndUser("pf-media-2");
Media mediaAlt = mediaDao.createMedia("Media 3", "Europe", "Un continent", "Forum", "[Media:0]", null, 10, someoneElse);
dbInstance.commit();
// search owned medias
List<MediaLight> ownedMedias = mediaDao.searchByAuthor(author, null, null);
Assert.assertNotNull(ownedMedias);
Assert.assertEquals(3, ownedMedias.size());
Assert.assertTrue(ownedMedias.contains(media1));
Assert.assertTrue(ownedMedias.contains(media2));
Assert.assertTrue(ownedMedias.contains(media3));
Assert.assertFalse(ownedMedias.contains(mediaAlt));
// search medias
List<MediaLight> searchMedias = mediaDao.searchByAuthor(author, "Europe", null);
Assert.assertNotNull(searchMedias);
Assert.assertEquals(1, searchMedias.size());
Assert.assertFalse(searchMedias.contains(media1));
Assert.assertFalse(searchMedias.contains(media2));
Assert.assertTrue(searchMedias.contains(media3));
Assert.assertFalse(searchMedias.contains(mediaAlt));
}
use of org.olat.modules.portfolio.MediaLight in project OpenOLAT by OpenOLAT.
the class MediaDAOTest method searchByAuthor.
@Test
public void searchByAuthor() {
Identity author = JunitTestHelper.createAndPersistIdentityAsRndUser("pf-media-2");
Media media1 = mediaDao.createMedia("Media 1", "The media theory", "Media theory is very important subject", "Forum", "[Media:0]", null, 10, author);
Media media2 = mediaDao.createMedia("Media 2", "Java", "One of the most widespread programming language", "Forum", "[Media:0]", null, 10, author);
Media media3 = mediaDao.createMedia("Media 3", "Europe", "Un continent", "Forum", "[Media:0]", null, 10, author);
dbInstance.commit();
// not owned
Identity someoneElse = JunitTestHelper.createAndPersistIdentityAsRndUser("pf-media-2");
Media mediaAlt = mediaDao.createMedia("Media 3", "Europe", "Un continent", "Forum", "[Media:0]", null, 10, someoneElse);
dbInstance.commit();
// search owned medias
List<MediaLight> ownedMedias = mediaDao.searchByAuthor(author, null, null);
Assert.assertNotNull(ownedMedias);
Assert.assertEquals(3, ownedMedias.size());
Assert.assertTrue(ownedMedias.contains(media1));
Assert.assertTrue(ownedMedias.contains(media2));
Assert.assertTrue(ownedMedias.contains(media3));
Assert.assertFalse(ownedMedias.contains(mediaAlt));
// search medias
List<MediaLight> searchMedias = mediaDao.searchByAuthor(author, "Europe", null);
Assert.assertNotNull(searchMedias);
Assert.assertEquals(1, searchMedias.size());
Assert.assertFalse(searchMedias.contains(media1));
Assert.assertFalse(searchMedias.contains(media2));
Assert.assertTrue(searchMedias.contains(media3));
Assert.assertFalse(searchMedias.contains(mediaAlt));
}
use of org.olat.modules.portfolio.MediaLight in project OpenOLAT by OpenOLAT.
the class MediaCenterController method loadModel.
private void loadModel() {
String searchString = tableEl.getQuickSearchString();
List<String> tagNames = getSelectedTagNames();
Map<Long, MediaRow> currentMap = model.getObjects().stream().collect(Collectors.toMap(r -> r.getKey(), r -> r));
List<MediaLight> medias = portfolioService.searchOwnedMedias(getIdentity(), searchString, tagNames);
List<MediaRow> rows = new ArrayList<>(medias.size());
for (MediaLight media : medias) {
if (currentMap.containsKey(media.getKey())) {
rows.add(currentMap.get(media.getKey()));
} else {
MediaHandler handler = portfolioService.getMediaHandler(media.getType());
VFSLeaf thumbnail = handler.getThumbnail(media, THUMBNAIL_SIZE);
String mediaTitle = StringHelper.escapeHtml(media.getTitle());
FormLink openLink = uifactory.addFormLink("select_" + (++counter), "select", mediaTitle, null, flc, Link.NONTRANSLATED);
MediaRow row = new MediaRow(media, thumbnail, openLink, handler.getIconCssClass(media));
openLink.setUserObject(row);
rows.add(row);
}
}
model.setObjects(rows);
model.filter(tableEl.getSelectedFilters());
Map<Long, MediaRow> rowMap = model.getObjects().stream().collect(Collectors.toMap(r -> r.getKey(), r -> r));
Set<String> duplicateCategories = new HashSet<>();
List<CategoryLight> categories = portfolioService.getMediaCategories(getIdentity());
List<FormLink> newTagLinks = new ArrayList<>(categories.size());
for (CategoryLight category : categories) {
String name = category.getCategory();
MediaRow mRow = rowMap.get(category.getMediaKey());
if (mRow != null) {
mRow.addCategory(name);
}
if (duplicateCategories.contains(name)) {
continue;
}
duplicateCategories.add(name);
FormLink tagLink = uifactory.addFormLink("tag_" + (++counter), "tag", name, null, null, Link.NONTRANSLATED);
CategoryState state = new CategoryState(category, tagNames.contains(name));
tagLink.setUserObject(state);
if (state.isSelected()) {
tagLink.setCustomEnabledLinkCSS("tag label label-info o_disabled");
} else {
tagLink.setCustomEnabledLinkCSS("tag label label-info");
}
flc.add(tagLink);
newTagLinks.add(tagLink);
}
flc.contextPut("tagLinks", newTagLinks);
tagLinks = newTagLinks;
}
use of org.olat.modules.portfolio.MediaLight in project openolat by klemens.
the class MediaCenterController method loadModel.
private void loadModel() {
String searchString = tableEl.getQuickSearchString();
List<String> tagNames = getSelectedTagNames();
Map<Long, MediaRow> currentMap = model.getObjects().stream().collect(Collectors.toMap(r -> r.getKey(), r -> r));
List<MediaLight> medias = portfolioService.searchOwnedMedias(getIdentity(), searchString, tagNames);
List<MediaRow> rows = new ArrayList<>(medias.size());
for (MediaLight media : medias) {
if (currentMap.containsKey(media.getKey())) {
rows.add(currentMap.get(media.getKey()));
} else {
MediaHandler handler = portfolioService.getMediaHandler(media.getType());
VFSLeaf thumbnail = handler.getThumbnail(media, THUMBNAIL_SIZE);
String mediaTitle = StringHelper.escapeHtml(media.getTitle());
FormLink openLink = uifactory.addFormLink("select_" + (++counter), "select", mediaTitle, null, flc, Link.NONTRANSLATED);
MediaRow row = new MediaRow(media, thumbnail, openLink, handler.getIconCssClass(media));
openLink.setUserObject(row);
rows.add(row);
}
}
model.setObjects(rows);
model.filter(tableEl.getSelectedFilters());
Map<Long, MediaRow> rowMap = model.getObjects().stream().collect(Collectors.toMap(r -> r.getKey(), r -> r));
Set<String> duplicateCategories = new HashSet<>();
List<CategoryLight> categories = portfolioService.getMediaCategories(getIdentity());
List<FormLink> newTagLinks = new ArrayList<>(categories.size());
for (CategoryLight category : categories) {
String name = category.getCategory();
MediaRow mRow = rowMap.get(category.getMediaKey());
if (mRow != null) {
mRow.addCategory(name);
}
if (duplicateCategories.contains(name)) {
continue;
}
duplicateCategories.add(name);
FormLink tagLink = uifactory.addFormLink("tag_" + (++counter), "tag", name, null, null, Link.NONTRANSLATED);
CategoryState state = new CategoryState(category, tagNames.contains(name));
tagLink.setUserObject(state);
if (state.isSelected()) {
tagLink.setCustomEnabledLinkCSS("tag label label-info o_disabled");
} else {
tagLink.setCustomEnabledLinkCSS("tag label label-info");
}
flc.add(tagLink);
newTagLinks.add(tagLink);
}
flc.contextPut("tagLinks", newTagLinks);
tagLinks = newTagLinks;
}
Aggregations