Skip to content

Commit

Permalink
XWIKI-21848: Migrate NotificationFilterPreferenceLivetableResults to …
Browse files Browse the repository at this point in the history
…a Live Data source (#2971)

  * Provide 2 different LD custom source: one for Custom Filter Preferences and one for System Filter Preferences: the reason for not going to a single LD source is that those LT are now very different and we use to hack the data source to provide different information. Having 2 different sources make things very more clear
  * Provide ordering / filtering on the Custom Filter source as it's the one with most entries
  * Don't provide any kind of ordering / filtering for System filter preferences: in XS we only have 6 items, and it's rare to have custom filters
  * Provide some new APIs where needed
  • Loading branch information
surli authored Mar 20, 2024
1 parent 153dbfa commit c376fa9
Show file tree
Hide file tree
Showing 56 changed files with 4,799 additions and 701 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public List<RecordableEventDescriptor> getRecordableEventDescriptors(boolean all
public RecordableEventDescriptor getDescriptorForEventType(String eventType, boolean allWikis)
throws EventStreamException
{
// FIXME: We should cache the descriptors for improving perf when calling multiple times this method.
return getRecordableEventDescriptors(allWikis).stream().filter(descriptor
-> eventType.equals(descriptor.getEventType())).findAny().orElse(null);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.xwiki.livedata.test.po;

import org.openqa.selenium.By;
import org.openqa.selenium.InvalidElementStateException;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebElement;
import org.xwiki.test.ui.po.BaseElement;

/**
* Abstract class representing different type of advanced panels in livedata.
*
* @version $Id$
* @since 16.3.0RC1
*/
public abstract class AbstractLiveDataAdvancedPanelElement extends BaseElement
{
protected final WebElement container;
protected final LiveDataElement liveData;

/**
* Default constructor.
* @param liveData the livedata the panel belongs to.
* @param container the container of the panel.
*/
public AbstractLiveDataAdvancedPanelElement(LiveDataElement liveData, WebElement container)
{
this.liveData = liveData;
this.container = container;
}

/**
* Close the panel.
*/
public void closePanel()
{
getDriver().findElementWithoutWaiting(this.container, By.className("close-button")).click();
}

/**
* Allow to click on links that are only visible when the mouse is on them (e.g. delete icons of filters)
* @param linkIdentifiers the identifier to find the link element in the dom.
*/
protected void clickOnMouseOverLinks(By linkContainer, By linkIdentifiers)
{
getDriver().findElementsWithoutWaiting(this.container, linkContainer)
.forEach(webElement -> {
// First we move to the link container to make the link appearing
getDriver().createActions().moveToElement(webElement).build().perform();
WebElement linkElement = getDriver().findElementWithoutWaiting(webElement, linkIdentifiers);
if (!linkElement.isDisplayed()) {
throw new InvalidElementStateException(String.format("The link [%s] should be displayed.",
linkElement));
}
// Click on the actual link
getDriver().createActions().moveToElement(linkElement).click().build().perform();
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.xwiki.livedata.test.po;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

/**
* Represents the advanced panel for filtering columns.
*
* @version $Id$
* @since 16.3.0RC1
*/
public class FiltersPanelElement extends AbstractLiveDataAdvancedPanelElement
{
/**
* Default constructor.
* @param liveData the livedata of the panel.
* @param container the container of the panel.
*/
public FiltersPanelElement(LiveDataElement liveData, WebElement container)
{
super(liveData, container);
}

/**
* Remove all filters.
*/
public void clearAllFilters()
{
this.clickOnMouseOverLinks(By.className("filter-group-title"), By.className("delete-filter-group"));
this.liveData.waitUntilReady();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,21 @@ public boolean isReady()
return isVueLoaded() && areComponentsLoaded();
}

private WebElement openDropDownMenu()
{
WebElement dropdownMenu = getRootElement().findElement(By.cssSelector(".livedata-dropdown-menu "));
dropdownMenu.click();
return dropdownMenu;
}

/**
* Click on the refresh button from the actions menu.
*
* @since 15.5
*/
public void refresh()
{
WebElement dropdownMenu = getRootElement().findElement(By.cssSelector(".livedata-dropdown-menu "));
dropdownMenu.click();
dropdownMenu.findElement(By.cssSelector(".livedata-action-refresh")).click();
openDropDownMenu().findElement(By.cssSelector(".livedata-action-refresh")).click();
}

/**
Expand All @@ -139,7 +144,7 @@ public LiveDataElement setPagination(int paginationNumber)
return this;
}

private void waitUntilReady()
public void waitUntilReady()
{
getDriver().waitUntilCondition(input -> isVueLoaded());

Expand Down Expand Up @@ -180,4 +185,48 @@ private WebElement getRootElement()
{
return getDriver().findElement(By.id(this.id));
}

/**
* Open the panel for advanced filter and returns it.
* @return an instance of {@link FiltersPanelElement} once it's opened.
* @since 16.3.0RC1
*/
public FiltersPanelElement openFiltersPanel()
{
openDropDownMenu().findElement(By.linkText("Filter...")).click();
return new FiltersPanelElement(this,
getRootElement().findElement(By.className("livedata-advanced-panel-filter")));
}

/**
* Open the panel for advanced sorting and returns it.
* @return an instance of {@link SortPanelElement} once it's opened.
* @since 16.3.0RC1
*/
public SortPanelElement openSortPanel()
{
openDropDownMenu().findElement(By.linkText("Sort...")).click();
return new SortPanelElement(this,
getRootElement().findElement(By.className("livedata-advanced-panel-sort")));
}

/**
* Clear all custom sorting that might have been put.
*/
public void clearAllSort()
{
SortPanelElement sortPanelElement = openSortPanel();
sortPanelElement.clearAllSort();
sortPanelElement.closePanel();
}

/**
* Clear all custom filters that might have been put.
*/
public void clearAllFilters()
{
FiltersPanelElement filtersPanelElement = openFiltersPanel();
filtersPanelElement.clearAllFilters();
filtersPanelElement.closePanel();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.xwiki.livedata.test.po;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

/**
* Represents the advanced panel for sorting columns.
*
* @version $Id$
* @since 16.3.0RC1
*/
public class SortPanelElement extends AbstractLiveDataAdvancedPanelElement
{
/**
* Default constructor.
* @param liveData the livedata of the panel.
* @param container the container of the panel.
*/
public SortPanelElement(LiveDataElement liveData, WebElement container)
{
super(liveData, container);
}

/**
* Remove all sorting on all columns.
*/
public void clearAllSort()
{
this.clickOnMouseOverLinks(By.className("sort-entry"), By.className("delete-sort"));
this.liveData.waitUntilReady();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.apache.http.NameValuePair;
Expand Down Expand Up @@ -76,6 +77,9 @@ public class TableLayoutElement extends BaseElement

private final LiveDataElement liveData;

private static final Pattern PAGINATION_SENTENCE_PATTERN =
Pattern.compile("^Entries (?<firstEntry>\\d+) - (?<lastEntry>\\d+) out of (?<totalEntries>\\d+)$");

/**
* @return the list of rows {@link WebElement}s
* @since 16.1.0RC1
Expand Down Expand Up @@ -688,6 +692,24 @@ public Set<String> getPaginationSizes()
.map(it -> it.getAttribute("value")).collect(Collectors.toSet());
}

private String getPaginationEntriesString()
{
return getRoot().findElement(By.className("pagination-current-entries")).getText().trim();
}

private java.util.regex.Matcher getPaginationMatcher()
{
return PAGINATION_SENTENCE_PATTERN.matcher(getPaginationEntriesString());
}

public long getTotalEntries()
{
java.util.regex.Matcher paginationMatcher = getPaginationMatcher();
if (!paginationMatcher.matches()) {
throw new IllegalStateException("Matcher does not match: " + getPaginationEntriesString());
}
return Long.parseLong(paginationMatcher.group("totalEntries"));
}

/**
* Clicks on an action button identified by its name, on a given row.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public class CachedFilterPreferencesModelBridge implements FilterPreferencesMode

private Map<EntityReference, Set<NotificationFilterPreference>> preferenceFilterCache;

private Map<EntityReference, Map<String, Boolean>> toggleCache;
private Map<EntityReference, Map<String, ToggleableNotificationFilterActivation>> toggleCache;

void invalidatePreferencefilter(EntityReference reference)
{
Expand Down Expand Up @@ -132,10 +132,10 @@ public Set<NotificationFilterPreference> getFilterPreferences(WikiReference wiki
}

@Override
public Map<String, Boolean> getToggleableFilterActivations(DocumentReference userReference)
throws NotificationException
public Map<String, ToggleableNotificationFilterActivation> getToggleableFilterActivations(
DocumentReference userReference) throws NotificationException
{
Map<String, Boolean> values = this.toggleCache.get(userReference);
Map<String, ToggleableNotificationFilterActivation> values = this.toggleCache.get(userReference);
if (values != null) {
return values;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.inject.Inject;
Expand Down Expand Up @@ -211,7 +212,10 @@ public Stream<NotificationFilter> getToggleableFilters(Collection<NotificationFi
public Map<String, Boolean> getToggeableFilterActivations(DocumentReference user)
throws NotificationException
{
return filterPreferencesModelBridge.getToggleableFilterActivations(user);
return filterPreferencesModelBridge.getToggleableFilterActivations(user)
.entrySet()
.stream()
.collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().isEnabled()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ default Set<NotificationFilterPreference> getFilterPreferences(WikiReference wik
* @throws NotificationException if an error happens
* @since 10.1RC1
*/
Map<String, Boolean> getToggleableFilterActivations(DocumentReference user) throws NotificationException;
Map<String, ToggleableNotificationFilterActivation> getToggleableFilterActivations(DocumentReference user)
throws NotificationException;

/**
* Delete a filter preference.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.xwiki.notifications.filters.internal;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.xwiki.notifications.NotificationFormat;
Expand Down Expand Up @@ -49,12 +48,4 @@ default List<NotificationFormat> getFormats()
{
return Arrays.asList(NotificationFormat.values());
}

/**
* @return the events handled by this filter
*/
default List<String> getEventTypes()
{
return Collections.emptyList();
}
}
Loading

0 comments on commit c376fa9

Please sign in to comment.