Search in sources :

Example 1 with MediaLight

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));
}
Also used : MediaLight(org.olat.modules.portfolio.MediaLight) Media(org.olat.modules.portfolio.Media) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 2 with MediaLight

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));
}
Also used : MediaLight(org.olat.modules.portfolio.MediaLight) Media(org.olat.modules.portfolio.Media) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 3 with MediaLight

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;
}
Also used : FlexiTableElement(org.olat.core.gui.components.form.flexible.elements.FlexiTableElement) EPArtefactListChoosenEvent(org.olat.portfolio.ui.artefacts.view.EPArtefactListChoosenEvent) Activateable2(org.olat.core.gui.control.generic.dtabs.Activateable2) DefaultFlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel) Autowired(org.springframework.beans.factory.annotation.Autowired) MediaResource(org.olat.core.gui.media.MediaResource) OLATResourceable(org.olat.core.id.OLATResourceable) Size(org.olat.core.commons.services.image.Size) Media(org.olat.modules.portfolio.Media) FlexiTableFilter(org.olat.core.gui.components.form.flexible.elements.FlexiTableFilter) OresHelper(org.olat.core.util.resource.OresHelper) MediaRow(org.olat.modules.portfolio.ui.model.MediaRow) Map(java.util.Map) SortKey(org.olat.core.commons.persistence.SortKey) VelocityContainer(org.olat.core.gui.components.velocity.VelocityContainer) CalloutSettings(org.olat.core.gui.control.generic.closablewrapper.CalloutSettings) MediaCols(org.olat.modules.portfolio.ui.MediaDataModel.MediaCols) MediaHandler(org.olat.modules.portfolio.MediaHandler) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) FlexiTableColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) FlexiTableSort(org.olat.core.gui.components.form.flexible.elements.FlexiTableSort) WindowControl(org.olat.core.gui.control.WindowControl) FlexiTableRendererType(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableRendererType) PortfolioModule(org.olat.portfolio.PortfolioModule) Set(java.util.Set) MediaEvent(org.olat.modules.portfolio.ui.event.MediaEvent) Component(org.olat.core.gui.components.Component) LinkFactory(org.olat.core.gui.components.link.LinkFactory) Collectors(java.util.stream.Collectors) Mapper(org.olat.core.dispatcher.mapper.Mapper) DefaultFlexiTableCssDelegate(org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiTableCssDelegate) SelectionEvent(org.olat.core.gui.components.form.flexible.impl.elements.table.SelectionEvent) BasicController(org.olat.core.gui.control.controller.BasicController) List(java.util.List) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) Align(org.olat.core.gui.components.stack.TooledStackedPanel.Align) TooledController(org.olat.core.gui.components.stack.TooledController) CloseableCalloutWindowController(org.olat.core.gui.control.generic.closablewrapper.CloseableCalloutWindowController) TooledStackedPanel(org.olat.core.gui.components.stack.TooledStackedPanel) CategoryLight(org.olat.modules.portfolio.model.CategoryLight) CategoriesCellRenderer(org.olat.modules.portfolio.ui.component.CategoriesCellRenderer) FormEvent(org.olat.core.gui.components.form.flexible.impl.FormEvent) CollectCitationMediaController(org.olat.modules.portfolio.ui.media.CollectCitationMediaController) EPArtefactChoosenEvent(org.olat.portfolio.ui.artefacts.view.EPArtefactChoosenEvent) FormItem(org.olat.core.gui.components.form.flexible.FormItem) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Event(org.olat.core.gui.control.Event) FormBasicController(org.olat.core.gui.components.form.flexible.impl.FormBasicController) HttpServletRequest(javax.servlet.http.HttpServletRequest) FormItemContainer(org.olat.core.gui.components.form.flexible.FormItemContainer) ContextEntry(org.olat.core.id.context.ContextEntry) EPArtefactPoolRunController(org.olat.portfolio.ui.EPArtefactPoolRunController) StringHelper(org.olat.core.util.StringHelper) StateEntry(org.olat.core.id.context.StateEntry) FlexiTableDataModelFactory(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableDataModelFactory) PortfolioService(org.olat.modules.portfolio.PortfolioService) OrderBy(org.olat.repository.model.SearchMyRepositoryEntryViewParams.OrderBy) Link(org.olat.core.gui.components.link.Link) FlexiTableComponentDelegate(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableComponentDelegate) CollectTextMediaController(org.olat.modules.portfolio.ui.media.CollectTextMediaController) FlexiTableSearchEvent(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableSearchEvent) MediaSelectionEvent(org.olat.modules.portfolio.ui.event.MediaSelectionEvent) Controller(org.olat.core.gui.control.Controller) MediaLight(org.olat.modules.portfolio.MediaLight) EPFrontendManager(org.olat.portfolio.manager.EPFrontendManager) FlexiTableSortOptions(org.olat.core.gui.components.form.flexible.elements.FlexiTableSortOptions) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) MediaTypeCellRenderer(org.olat.modules.portfolio.ui.renderer.MediaTypeCellRenderer) UserRequest(org.olat.core.gui.UserRequest) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) MediaHandler(org.olat.modules.portfolio.MediaHandler) ArrayList(java.util.ArrayList) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) MediaLight(org.olat.modules.portfolio.MediaLight) CategoryLight(org.olat.modules.portfolio.model.CategoryLight) MediaRow(org.olat.modules.portfolio.ui.model.MediaRow) HashSet(java.util.HashSet)

Example 4 with MediaLight

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;
}
Also used : FlexiTableElement(org.olat.core.gui.components.form.flexible.elements.FlexiTableElement) EPArtefactListChoosenEvent(org.olat.portfolio.ui.artefacts.view.EPArtefactListChoosenEvent) Activateable2(org.olat.core.gui.control.generic.dtabs.Activateable2) DefaultFlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel) Autowired(org.springframework.beans.factory.annotation.Autowired) MediaResource(org.olat.core.gui.media.MediaResource) OLATResourceable(org.olat.core.id.OLATResourceable) Size(org.olat.core.commons.services.image.Size) Media(org.olat.modules.portfolio.Media) FlexiTableFilter(org.olat.core.gui.components.form.flexible.elements.FlexiTableFilter) OresHelper(org.olat.core.util.resource.OresHelper) MediaRow(org.olat.modules.portfolio.ui.model.MediaRow) Map(java.util.Map) SortKey(org.olat.core.commons.persistence.SortKey) VelocityContainer(org.olat.core.gui.components.velocity.VelocityContainer) CalloutSettings(org.olat.core.gui.control.generic.closablewrapper.CalloutSettings) MediaCols(org.olat.modules.portfolio.ui.MediaDataModel.MediaCols) MediaHandler(org.olat.modules.portfolio.MediaHandler) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) FlexiTableColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) FlexiTableSort(org.olat.core.gui.components.form.flexible.elements.FlexiTableSort) WindowControl(org.olat.core.gui.control.WindowControl) FlexiTableRendererType(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableRendererType) PortfolioModule(org.olat.portfolio.PortfolioModule) Set(java.util.Set) MediaEvent(org.olat.modules.portfolio.ui.event.MediaEvent) Component(org.olat.core.gui.components.Component) LinkFactory(org.olat.core.gui.components.link.LinkFactory) Collectors(java.util.stream.Collectors) Mapper(org.olat.core.dispatcher.mapper.Mapper) DefaultFlexiTableCssDelegate(org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiTableCssDelegate) SelectionEvent(org.olat.core.gui.components.form.flexible.impl.elements.table.SelectionEvent) BasicController(org.olat.core.gui.control.controller.BasicController) List(java.util.List) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) Align(org.olat.core.gui.components.stack.TooledStackedPanel.Align) TooledController(org.olat.core.gui.components.stack.TooledController) CloseableCalloutWindowController(org.olat.core.gui.control.generic.closablewrapper.CloseableCalloutWindowController) TooledStackedPanel(org.olat.core.gui.components.stack.TooledStackedPanel) CategoryLight(org.olat.modules.portfolio.model.CategoryLight) CategoriesCellRenderer(org.olat.modules.portfolio.ui.component.CategoriesCellRenderer) FormEvent(org.olat.core.gui.components.form.flexible.impl.FormEvent) CollectCitationMediaController(org.olat.modules.portfolio.ui.media.CollectCitationMediaController) EPArtefactChoosenEvent(org.olat.portfolio.ui.artefacts.view.EPArtefactChoosenEvent) FormItem(org.olat.core.gui.components.form.flexible.FormItem) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Event(org.olat.core.gui.control.Event) FormBasicController(org.olat.core.gui.components.form.flexible.impl.FormBasicController) HttpServletRequest(javax.servlet.http.HttpServletRequest) FormItemContainer(org.olat.core.gui.components.form.flexible.FormItemContainer) ContextEntry(org.olat.core.id.context.ContextEntry) EPArtefactPoolRunController(org.olat.portfolio.ui.EPArtefactPoolRunController) StringHelper(org.olat.core.util.StringHelper) StateEntry(org.olat.core.id.context.StateEntry) FlexiTableDataModelFactory(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableDataModelFactory) PortfolioService(org.olat.modules.portfolio.PortfolioService) OrderBy(org.olat.repository.model.SearchMyRepositoryEntryViewParams.OrderBy) Link(org.olat.core.gui.components.link.Link) FlexiTableComponentDelegate(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableComponentDelegate) CollectTextMediaController(org.olat.modules.portfolio.ui.media.CollectTextMediaController) FlexiTableSearchEvent(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableSearchEvent) MediaSelectionEvent(org.olat.modules.portfolio.ui.event.MediaSelectionEvent) Controller(org.olat.core.gui.control.Controller) MediaLight(org.olat.modules.portfolio.MediaLight) EPFrontendManager(org.olat.portfolio.manager.EPFrontendManager) FlexiTableSortOptions(org.olat.core.gui.components.form.flexible.elements.FlexiTableSortOptions) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) MediaTypeCellRenderer(org.olat.modules.portfolio.ui.renderer.MediaTypeCellRenderer) UserRequest(org.olat.core.gui.UserRequest) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) MediaHandler(org.olat.modules.portfolio.MediaHandler) ArrayList(java.util.ArrayList) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) MediaLight(org.olat.modules.portfolio.MediaLight) CategoryLight(org.olat.modules.portfolio.model.CategoryLight) MediaRow(org.olat.modules.portfolio.ui.model.MediaRow) HashSet(java.util.HashSet)

Aggregations

Media (org.olat.modules.portfolio.Media)4 MediaLight (org.olat.modules.portfolio.MediaLight)4 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 SortKey (org.olat.core.commons.persistence.SortKey)2 Size (org.olat.core.commons.services.image.Size)2 Mapper (org.olat.core.dispatcher.mapper.Mapper)2 UserRequest (org.olat.core.gui.UserRequest)2 Component (org.olat.core.gui.components.Component)2 FormItem (org.olat.core.gui.components.form.flexible.FormItem)2 FormItemContainer (org.olat.core.gui.components.form.flexible.FormItemContainer)2 FlexiTableElement (org.olat.core.gui.components.form.flexible.elements.FlexiTableElement)2 FlexiTableFilter (org.olat.core.gui.components.form.flexible.elements.FlexiTableFilter)2 FlexiTableSort (org.olat.core.gui.components.form.flexible.elements.FlexiTableSort)2 FlexiTableSortOptions (org.olat.core.gui.components.form.flexible.elements.FlexiTableSortOptions)2