Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XWIKI-21848: Migrate NotificationFilterPreferenceLivetableResults to a Live Data source #2971

Merged
merged 25 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
18f2bd6
XWIKI-21848: Migrate NotificationFilterPreferenceLivetableResults to …
surli Mar 5, 2024
213d028
XWIKI-21848: Migrate NotificationFilterPreferenceLivetableResults to …
surli Mar 5, 2024
e294b94
XWIKI-21848: Migrate NotificationFilterPreferenceLivetableResults to …
surli Mar 6, 2024
c44675c
XWIKI-21848: Migrate NotificationFilterPreferenceLivetableResults to …
surli Mar 6, 2024
8104f94
XWIKI-21848: Migrate NotificationFilterPreferenceLivetableResults to …
surli Mar 6, 2024
9141efc
XWIKI-21848: Migrate NotificationFilterPreferenceLivetableResults to …
surli Mar 7, 2024
aa71237
XWIKI-21848: Migrate NotificationFilterPreferenceLivetableResults to …
surli Mar 7, 2024
51d95a3
XWIKI-21848: Migrate NotificationFilterPreferenceLivetableResults to …
surli Mar 7, 2024
bd0e995
XWIKI-21848: Migrate NotificationFilterPreferenceLivetableResults to …
surli Mar 8, 2024
fefbadd
XWIKI-21848: Migrate NotificationFilterPreferenceLivetableResults to …
surli Mar 8, 2024
9de3402
XWIKI-21848: Migrate NotificationFilterPreferenceLivetableResults to …
surli Mar 8, 2024
3967dce
XWIKI-21848: Migrate NotificationFilterPreferenceLivetableResults to …
surli Mar 13, 2024
30a5876
XWIKI-21848: Migrate NotificationFilterPreferenceLivetableResults to …
surli Mar 13, 2024
a52c1fa
XWIKI-21848: Migrate NotificationFilterPreferenceLivetableResults to …
surli Mar 13, 2024
3c3b574
XWIKI-21848: Migrate NotificationFilterPreferenceLivetableResults to …
surli Mar 13, 2024
4b102eb
XWIKI-21848: Migrate NotificationFilterPreferenceLivetableResults to …
surli Mar 13, 2024
ed23e99
XWIKI-21848: Migrate NotificationFilterPreferenceLivetableResults to …
surli Mar 13, 2024
175afe2
XWIKI-21848: Migrate NotificationFilterPreferenceLivetableResults to …
surli Mar 14, 2024
8ee0087
XWIKI-21848: Migrate NotificationFilterPreferenceLivetableResults to …
surli Mar 18, 2024
c50b86a
XWIKI-21848: Migrate NotificationFilterPreferenceLivetableResults to …
surli Mar 18, 2024
5aa87cb
XWIKI-21848: Migrate NotificationFilterPreferenceLivetableResults to …
surli Mar 18, 2024
16cb25b
XWIKI-21848: Migrate NotificationFilterPreferenceLivetableResults to …
surli Mar 18, 2024
ee34d32
XWIKI-21848: Migrate NotificationFilterPreferenceLivetableResults to …
surli Mar 18, 2024
29f57a7
XWIKI-21848: Migrate NotificationFilterPreferenceLivetableResults to …
surli Mar 20, 2024
360ee91
Merge branch 'master' into custom-ld-source-notif-filters
surli Mar 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading