Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -204,6 +204,13 @@ public interface Event
*/
String FIELD_REMOTE_OBSERVATION_ID = "observationInstanceId";

/**
* Field storing the prefiltering date information.
*
* @since 17.10.0
*/
String FIELD_PREFILTERING_DATE = "preFilteringDate";

/** The importance of an event. */
enum Importance
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
*/
package org.xwiki.eventstream.store.solr.internal;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

import org.xwiki.component.annotation.Component;
import org.xwiki.eventstream.Event;
import org.xwiki.eventstream.store.solr.internal.migration.SolrDocumentMigration171000000;
import org.xwiki.search.solr.AbstractSolrCoreInitializer;
import org.xwiki.search.solr.SolrException;

Expand Down Expand Up @@ -79,6 +81,9 @@ public class EventsSolrCoreInitializer extends AbstractSolrCoreInitializer
*/
public static final String FIELD_DOCUMENT_INDEX = "document_index";

@Inject
private SolrDocumentMigration171000000 migration171000000;

@Override
protected long getVersion()
{
Expand Down Expand Up @@ -129,6 +134,10 @@ protected void migrateSchema(long cversion) throws SolrException
if (cversion < SCHEMA_VERSION_14_7) {
setStringField(Event.FIELD_REMOTE_OBSERVATION_ID, false, false);
}
if (cversion < SCHEMA_VERSION_17_10) {
setPDateField(Event.FIELD_PREFILTERING_DATE, false, false);
this.migration171000000.migrateAllDocuments(this.core);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ protected Event syncPrefilterEvent(Event event) throws EventStreamException
this.utils.set(EventsSolrCoreInitializer.SOLR_FIELD_ID, event.getId(), document);

this.utils.setAtomic(SolrUtils.ATOMIC_UPDATE_MODIFIER_SET, Event.FIELD_PREFILTERED, true, document);
this.utils.set(Event.FIELD_PREFILTERING_DATE, new Date(), document);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect it to be set as an atomic update too.


try {
this.client.add(document);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* 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.eventstream.store.solr.internal.migration;

import java.io.IOException;
import java.util.Date;

import javax.inject.Inject;

import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.SolrInputDocument;
import org.slf4j.Logger;
import org.xwiki.component.annotation.Component;
import org.xwiki.eventstream.Event;
import org.xwiki.search.solr.SolrException;
import org.xwiki.search.solr.SolrUtils;
import org.xwiki.search.solr.XWikiSolrCore;

import jakarta.inject.Singleton;

/**
* Migration of documents after introducing {@link Event#FIELD_PREFILTERING_DATE}.
*
* @version $Id$
* @since 17.10.0
*/
@Component(roles = SolrDocumentMigration171000000.class)
@Singleton
public class SolrDocumentMigration171000000
{
/**
* Number of documents to consider at once for migration.
*/
private static final int BATCH_MIGRATION_SIZE = 100;

@Inject
private SolrUtils solrUtils;

@Inject
private Logger logger;

/**
* Perform migration of documents to fill the field {@link Event#FIELD_PREFILTERING_DATE}.
*
* @param core the core for which to perform the migration.
* @throws SolrException in case of problem when performing the migration.
*/
public void migrateAllDocuments(XWikiSolrCore core) throws SolrException
{
SolrDocumentList documentList;
int startIndex = 0;
int totalMigrated = 0;
long totalNumber = 0;
do {
SolrQuery solrQuery = new SolrQuery("*:*")
.setStart(startIndex)
.setRows(BATCH_MIGRATION_SIZE)
.setSort(Event.FIELD_DATE, SolrQuery.ORDER.desc);
try {
QueryResponse queryResponse = core.getClient().query(solrQuery);
documentList = queryResponse.getResults();
totalNumber = queryResponse.getResults().getNumFound();
if (!documentList.isEmpty()) {
for (SolrDocument solrDocument : documentList) {
String id = this.solrUtils.getId(solrDocument);
Date date = this.solrUtils.get(Event.FIELD_DATE, solrDocument);

SolrInputDocument solrInputDocument = new SolrInputDocument();
this.solrUtils.setId(id, solrInputDocument);
this.solrUtils.set(Event.FIELD_PREFILTERING_DATE, date, solrInputDocument);
core.getClient().add(solrInputDocument);
}
startIndex += BATCH_MIGRATION_SIZE;
totalMigrated += documentList.size();
logger.info("[{}] Solr events information migrated on [{}].", totalMigrated, totalNumber);
}
} catch (SolrServerException | IOException e) {
throw new SolrException("Error when performing 171000000 Solr events documents migration", e);
}
} while (!documentList.isEmpty() && totalMigrated < totalNumber);

if (totalMigrated > 0) {
// We commit when all documents are migrated.
try {
core.getClient().commit();
} catch (SolrServerException | IOException e) {
throw new SolrException("Error when committing after performing 171000000 Solr "
+ "events documents migration.",
e);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
org.xwiki.eventstream.store.solr.internal.migration.SolrDocumentMigration171000000
org.xwiki.eventstream.store.solr.internal.EventsSolrCoreInitializer
org.xwiki.eventstream.store.solr.internal.SolrEventStore
org.xwiki.eventstream.store.solr.internal.WikiDeletedListener
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.xwiki.eventstream.internal.DefaultEventStatus;
import org.xwiki.eventstream.query.SimpleEventQuery;
import org.xwiki.eventstream.query.SortableEventQuery.SortClause.Order;
import org.xwiki.eventstream.store.solr.internal.migration.SolrDocumentMigration171000000;
import org.xwiki.model.internal.reference.converter.EntityReferenceConverter;
import org.xwiki.model.internal.reference.converter.WikiReferenceConverter;
import org.xwiki.model.reference.DocumentReference;
Expand Down Expand Up @@ -165,6 +166,9 @@ public class EventStoreTest
@MockComponent
private WikiDescriptorManager wikis;

@MockComponent
private SolrDocumentMigration171000000 migration171000000;

@InjectComponentManager
private MockitoComponentManager componentManager;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
package org.xwiki.notifications.filters.expression;

import org.xwiki.stability.Unstable;

/**
* The several properties you can have in an {@link org.xwiki.eventstream.Event}.
*
Expand Down Expand Up @@ -96,5 +98,12 @@ public enum EventProperty
*
* @since 14.7RC1
*/
REMOTE_OBSERVATION_ID
REMOTE_OBSERVATION_ID,
/**
* The date of the prefiltering of the event.
*
* @since 17.10.0
*/
@Unstable
PREFILTERING_DATE
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected List<CompositeEvent> retrieveCompositeEventList(DocumentReference user
notificationParameters.user = user;
notificationParameters.format = NotificationFormat.EMAIL;
notificationParameters.expectedCount = Integer.MAX_VALUE / 4;
notificationParameters.fromDate = this.lastTrigger;
notificationParameters.fromPrefilteringDate = this.lastTrigger;
notificationParameters.endDateIncluded = false;
notificationParametersFactory.useUserPreferences(notificationParameters);
UserReference userReference = this.userReferenceResolver.resolve(user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void test() throws Exception
notificationParameters.user = userA;
notificationParameters.format = NotificationFormat.EMAIL;
notificationParameters.expectedCount = Integer.MAX_VALUE / 4;
notificationParameters.fromDate = new Date(0L);
notificationParameters.fromPrefilteringDate = new Date(0L);
notificationParameters.endDateIncluded = false;

when(this.notificationManager.getRawEvents(notificationParameters))
Expand All @@ -199,7 +199,7 @@ void test() throws Exception
notificationParameters2.user = userC;
notificationParameters2.format = NotificationFormat.EMAIL;
notificationParameters2.expectedCount = Integer.MAX_VALUE / 4;
notificationParameters2.fromDate = new Date(0L);
notificationParameters2.fromPrefilteringDate = new Date(0L);
notificationParameters2.endDateIncluded = false;

when(this.notificationManager.getRawEvents(notificationParameters2))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.xwiki.notifications.filters.NotificationFilter;
import org.xwiki.notifications.filters.NotificationFilterPreference;
import org.xwiki.notifications.preferences.NotificationPreference;
import org.xwiki.stability.Unstable;
import org.xwiki.text.XWikiToStringBuilder;

/**
Expand Down Expand Up @@ -105,6 +106,14 @@ public class NotificationParameters
*/
public String groupingEventTarget = "alert";

/**
* Don't get notifications filtered before that date.
*
* @since 17.10.0
*/
@Unstable
public Date fromPrefilteringDate;

@Override
public boolean equals(Object o)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public class ExpressionNodeToEventQueryConverter
PROPERTY_MAPPING.put(EventProperty.TITLE, Event.FIELD_TITLE);
PROPERTY_MAPPING.put(EventProperty.BODY, Event.FIELD_BODY);
PROPERTY_MAPPING.put(EventProperty.DOCUMENT_VERSION, Event.FIELD_DOCUMENTVERSION);
PROPERTY_MAPPING.put(EventProperty.PREFILTERING_DATE, Event.FIELD_PREFILTERING_DATE);
}

@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ public ExpressionNode generateQueryExpression(NotificationParameters parameters)
new GreaterThanNode(new PropertyValueNode(EventProperty.DATE), new DateValueNode(parameters.fromDate));
}

if (parameters.fromPrefilteringDate != null) {
topNode = new GreaterThanNode(new PropertyValueNode(EventProperty.PREFILTERING_DATE),
new DateValueNode(parameters.fromPrefilteringDate));
}

// Condition 2: handle other preferences
AbstractOperatorNode preferencesNode = handleEventPreferences(parameters);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ public abstract class AbstractSolrCoreInitializer implements SolrCoreInitializer
*/
public static final long SCHEMA_VERSION_16_7 = 160700000;

/**
* The base schema version for XWiki 17.10.0.
*
* @since 17.10.0
*/
public static final long SCHEMA_VERSION_17_10 = 171000000;

/**
* The base schema version.
*/
Expand Down