ContentDashboardDropdownItemsProvider { public List<DropdownItem> getDropdownItems( ContentDashboardItem contentDashboardItem) { HttpServletRequest httpServletRequest = _portal.getHttpServletRequest( _liferayPortletRequest); Locale locale = _portal.getLocale(_liferayPortletRequest); DropdownItemList dropdownItemList = DropdownItemList.of( (DropdownItem[])TransformUtil.transformToArray( (List<ContentDashboardItemAction>) contentDashboardItem.getContentDashboardItemActions( httpServletRequest, ContentDashboardItemAction.Type.VIEW, ContentDashboardItemAction.Type.EDIT), contentDashboardItemAction -> _toDropdownItem( contentDashboardItemAction, locale), DropdownItem.class)); dropdownItemList.addAll( DropdownItemList.of( () -> { DropdownItem dropdownItem = new DropdownItem(); ResourceURL resourceURL = _liferayPortletResponse.createResourceURL(); resourceURL.setParameter( "backURL", _portal.getCurrentURL(_liferayPortletRequest)); InfoItemReference infoItemReference = contentDashboardItem.getInfoItemReference(); resourceURL.setParameter( "className", infoItemReference.getClassName()); resourceURL.setParameter( "classPK", String.valueOf(infoItemReference.getClassPK())); resourceURL.setResourceID( "/content_dashboard/get_content_dashboard_item_info"); dropdownItem.setData( HashMapBuilder.<String, Object>put( "action", "showInfo" ).put( "className", infoItemReference.getClassName() ).put( "classPK", infoItemReference.getClassPK() ).put( "fetchURL", String.valueOf(resourceURL) ).build()); dropdownItem.setIcon("info-circle-open"); dropdownItem.setLabel(_language.get(locale, "info")); dropdownItem.setQuickAction(true); return dropdownItem; })); dropdownItemList.addAll( TransformUtil.transform( (List<ContentDashboardItemAction>) contentDashboardItem.getContentDashboardItemActions( httpServletRequest, ContentDashboardItemAction.Type.VIEW_IN_PANEL), contentDashboardItemAction -> _toViewInPanelDropdownItem( contentDashboardItem, contentDashboardItemAction, locale))); return dropdownItemList; } ContentDashboardDropdownItemsProvider(
		Http http, Language language,
		LiferayPortletRequest liferayPortletRequest,
		LiferayPortletResponse liferayPortletResponse, Portal portal); List<DropdownItem> getDropdownItems(
		ContentDashboardItem contentDashboardItem);  }
@Test public void testGetEditURL() { MockLiferayPortletRenderRequest mockLiferayPortletRenderRequest = new MockLiferayPortletRenderRequest(); MockLiferayPortletURL mockLiferayPortletURL = new MockLiferayPortletURL(); mockLiferayPortletRenderRequest.setAttribute( "null" + StringPool.DASH + WebKeys.CURRENT_PORTLET_URL, mockLiferayPortletURL); mockLiferayPortletRenderRequest.setAttribute( WebKeys.LOCALE, LocaleUtil.US); ContentDashboardDropdownItemsProvider contentDashboardDropdownItemsProvider = new ContentDashboardDropdownItemsProvider( _http, _language, mockLiferayPortletRenderRequest, new MockLiferayPortletRenderResponse(), new PortalImpl()); ContentDashboardItem contentDashboardItem = _getContentDashboardItem( Collections.singletonList( _getContentDashboardItemAction( "edit", ContentDashboardItemAction.Type.EDIT, "validURL"))); List<DropdownItem> dropdownItems = contentDashboardDropdownItemsProvider.getDropdownItems( contentDashboardItem); Stream<DropdownItem> stream = dropdownItems.stream(); DropdownItem editDropdownItem = stream.filter( dropdownItem -> Objects.equals( String.valueOf(dropdownItem.get("label")), "edit") ).findFirst( ).orElseThrow( () -> new AssertionError() ); Assert.assertEquals( "validURL", _http.getPath(String.valueOf(editDropdownItem.get("href")))); }
@Test public void testGetURLBackURL() { MockLiferayPortletRenderRequest mockLiferayPortletRenderRequest = new MockLiferayPortletRenderRequest(); MockLiferayPortletURL mockLiferayPortletURL = new MockLiferayPortletURL(); mockLiferayPortletRenderRequest.setAttribute( "null" + StringPool.DASH + WebKeys.CURRENT_PORTLET_URL, mockLiferayPortletURL); ContentDashboardDropdownItemsProvider contentDashboardDropdownItemsProvider = new ContentDashboardDropdownItemsProvider( _http, _language, mockLiferayPortletRenderRequest, new MockLiferayPortletRenderResponse(), new PortalImpl()); ContentDashboardItem contentDashboardItem = _getContentDashboardItem( Collections.singletonList( _getContentDashboardItemAction( "view", ContentDashboardItemAction.Type.VIEW, "validURL"))); List<DropdownItem> dropdownItems = contentDashboardDropdownItemsProvider.getDropdownItems( contentDashboardItem); Stream<DropdownItem> stream = dropdownItems.stream(); DropdownItem viewDropdownItem = stream.filter( dropdownItem -> Objects.equals( String.valueOf(dropdownItem.get("label")), "view") ).findFirst( ).orElseThrow( () -> new AssertionError() ); Assert.assertEquals( HtmlUtil.escapeURL(String.valueOf(mockLiferayPortletURL)), _http.getParameter( String.valueOf(viewDropdownItem.get("href")), "p_l_back_url")); }
@Test public void testGetURLBackURLWithBackURLParameter() { MockLiferayPortletRenderRequest mockLiferayPortletRenderRequest = new MockLiferayPortletRenderRequest(); mockLiferayPortletRenderRequest.setAttribute( "null" + StringPool.DASH + WebKeys.CURRENT_PORTLET_URL, new MockLiferayPortletURL()); String backURL = RandomTestUtil.randomString(); mockLiferayPortletRenderRequest.setParameter("backURL", backURL); ContentDashboardDropdownItemsProvider contentDashboardDropdownItemsProvider = new ContentDashboardDropdownItemsProvider( _http, _language, mockLiferayPortletRenderRequest, new MockLiferayPortletRenderResponse(), new PortalImpl()); ContentDashboardItem contentDashboardItem = _getContentDashboardItem( Collections.singletonList( _getContentDashboardItemAction( "view", ContentDashboardItemAction.Type.VIEW, "validURL"))); List<DropdownItem> dropdownItems = contentDashboardDropdownItemsProvider.getDropdownItems( contentDashboardItem); Stream<DropdownItem> stream = dropdownItems.stream(); DropdownItem viewDropdownItem = stream.filter( dropdownItem -> Objects.equals( String.valueOf(dropdownItem.get("label")), "view") ).findFirst( ).orElseThrow( () -> new AssertionError() ); Assert.assertEquals( backURL, _http.getParameter( String.valueOf(viewDropdownItem.get("href")), "p_l_back_url")); }
@Test public void testGetViewInPanelURL() { MockLiferayPortletRenderRequest mockLiferayPortletRenderRequest = new MockLiferayPortletRenderRequest(); MockLiferayPortletURL mockLiferayPortletURL = new MockLiferayPortletURL(); mockLiferayPortletRenderRequest.setAttribute( "null" + StringPool.DASH + WebKeys.CURRENT_PORTLET_URL, mockLiferayPortletURL); mockLiferayPortletRenderRequest.setAttribute( WebKeys.LOCALE, LocaleUtil.US); ContentDashboardDropdownItemsProvider contentDashboardDropdownItemsProvider = new ContentDashboardDropdownItemsProvider( _http, _language, mockLiferayPortletRenderRequest, new MockLiferayPortletRenderResponse(), new PortalImpl()); ContentDashboardItem contentDashboardItem = _getContentDashboardItem( Collections.singletonList( _getContentDashboardItemAction( "viewInPanel", ContentDashboardItemAction.Type.VIEW_IN_PANEL, "validURL"))); List<DropdownItem> dropdownItems = contentDashboardDropdownItemsProvider.getDropdownItems( contentDashboardItem); Stream<DropdownItem> stream = dropdownItems.stream(); DropdownItem viewInPanelDropdownItem = stream.filter( dropdownItem -> Objects.equals( String.valueOf(dropdownItem.get("label")), "viewInPanel") ).findFirst( ).orElseThrow( () -> new AssertionError() ); Map<String, Object> data = (Map<String, Object>)viewInPanelDropdownItem.get("data"); Assert.assertEquals("showMetrics", String.valueOf(data.get("action"))); Assert.assertEquals("validURL", String.valueOf(data.get("fetchURL"))); }
@Test public void testGetViewURL() { MockLiferayPortletRenderRequest mockLiferayPortletRenderRequest = new MockLiferayPortletRenderRequest(); MockLiferayPortletURL mockLiferayPortletURL = new MockLiferayPortletURL(); mockLiferayPortletRenderRequest.setAttribute( "null" + StringPool.DASH + WebKeys.CURRENT_PORTLET_URL, mockLiferayPortletURL); mockLiferayPortletRenderRequest.setAttribute( WebKeys.LOCALE, LocaleUtil.US); ContentDashboardDropdownItemsProvider contentDashboardDropdownItemsProvider = new ContentDashboardDropdownItemsProvider( _http, _language, mockLiferayPortletRenderRequest, new MockLiferayPortletRenderResponse(), new PortalImpl()); ContentDashboardItem contentDashboardItem = _getContentDashboardItem( Collections.singletonList( _getContentDashboardItemAction( "view", ContentDashboardItemAction.Type.VIEW, "validURL"))); List<DropdownItem> dropdownItems = contentDashboardDropdownItemsProvider.getDropdownItems( contentDashboardItem); Stream<DropdownItem> stream = dropdownItems.stream(); DropdownItem viewDropdownItem = stream.filter( dropdownItem -> Objects.equals( String.valueOf(dropdownItem.get("label")), "view") ).findFirst( ).orElseThrow( () -> new AssertionError() ); Assert.assertEquals( "validURL", _http.getPath(String.valueOf(viewDropdownItem.get("href")))); }