-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving shared MAM Query representation into abstract class
The Monitoring Service plugin's XEP-0313: Message Archive Management implementation contains at least six similar query implementations. The code that is duplicated between them is moved to abstract classes, that the original code now inherits from. This reduces code duplication and makes it easier to add new query types.
- Loading branch information
Showing
9 changed files
with
399 additions
and
215 deletions.
There are no files selected for viewing
110 changes: 110 additions & 0 deletions
110
src/java/com/reucon/openfire/plugin/archive/impl/AbstractPaginatedMamMucQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* Copyright (C) 2024 Ignite Realtime Foundation. All rights reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.reucon.openfire.plugin.archive.impl; | ||
|
||
import org.jivesoftware.openfire.muc.MUCRoom; | ||
import org.xmpp.packet.JID; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
import java.util.Date; | ||
|
||
/** | ||
* Representation of a MAM query that is querying a multi-user chat-based archive. | ||
* | ||
* @author Guus der Kinderen, [email protected] | ||
*/ | ||
public abstract class AbstractPaginatedMamMucQuery extends AbstractPaginatedMamQuery | ||
{ | ||
/** | ||
* The MUC room instance that owns the message archive. | ||
*/ | ||
@Nonnull | ||
protected final MUCRoom room; | ||
|
||
/** | ||
* To be able to return not only the public messages exchanged in the room, but also the private messages that are | ||
* relevant for the user that performs this query, an additional JID is provided as the 'messageOwner' argument. | ||
* This identifies the user for which to retrieve the (private) messages. | ||
*/ | ||
@Nonnull | ||
protected final JID messageOwner; | ||
|
||
/** | ||
* Creates a query for messages from a message archive. | ||
* <p> | ||
* To be able to return not only the public messages exchanged in the room, but also the private messages that are | ||
* relevant for the user that performs this query, an additional JID is provided as the 'messageOwner' argument. | ||
* This identifies the user for which to retrieve the (private) messages. | ||
* | ||
* @param startDate Start (inclusive) of period for which to return messages. EPOCH will be used if no value is provided. | ||
* @param endDate End (inclusive) of period for which to return messages. 'now' will be used if no value is provided. | ||
* @param room The multi-user chat room that is the message archive owner. | ||
* @param messageOwner The entity for which to return messages (typically the JID of the entity making the request). | ||
* @param with An optional conversation partner | ||
*/ | ||
public AbstractPaginatedMamMucQuery(@Nullable final Date startDate, @Nullable final Date endDate, @Nonnull final MUCRoom room, @Nonnull final JID messageOwner, @Nullable final JID with) | ||
{ | ||
super(startDate, endDate, room.getJID(), with); | ||
this.messageOwner = messageOwner; | ||
this.room = room; | ||
} | ||
|
||
/** | ||
* Creates a query for messages from a message archive. | ||
* <p> | ||
* To be able to return not only the public messages exchanged in the room, but also the private messages that are | ||
* relevant for the user that performs this query, an additional JID is provided as the 'messageOwner' argument. | ||
* This identifies the user for which to retrieve the (private) messages. | ||
* | ||
* @param startDate Start (inclusive) of period for which to return messages. EPOCH will be used if no value is provided. | ||
* @param endDate End (inclusive) of period for which to return messages. 'now' will be used if no value is provided. | ||
* @param room The multi-user chat room that is the message archive owner. | ||
* @param messageOwner The entity for which to return messages (typically the JID of the entity making the request). | ||
* @param with An optional conversation partner | ||
* @param query A search string to be used for text-based search. | ||
*/ | ||
public AbstractPaginatedMamMucQuery(@Nullable final Date startDate, @Nullable final Date endDate, @Nonnull final MUCRoom room, @Nonnull final JID messageOwner, @Nullable final JID with, @Nonnull final String query) | ||
{ | ||
super(startDate, endDate, room.getJID(), with, query); | ||
this.messageOwner = messageOwner; | ||
this.room = room; | ||
} | ||
|
||
@Nonnull | ||
public MUCRoom getRoom() | ||
{ | ||
return room; | ||
} | ||
|
||
@Nonnull | ||
public JID getMessageOwner() | ||
{ | ||
return messageOwner; | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return "AbstractPaginatedMamMucQuery{" + | ||
"messageOwner=" + messageOwner + | ||
", startDate=" + startDate + | ||
", endDate=" + endDate + | ||
", archiveOwner=" + archiveOwner + | ||
", with=" + with + | ||
", query='" + query + '\'' + | ||
'}'; | ||
} | ||
} |
158 changes: 158 additions & 0 deletions
158
src/java/com/reucon/openfire/plugin/archive/impl/AbstractPaginatedMamQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
/* | ||
* Copyright (C) 2024 Ignite Realtime Foundation. All rights reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.reucon.openfire.plugin.archive.impl; | ||
|
||
import com.reucon.openfire.plugin.archive.model.ArchivedMessage; | ||
import org.xmpp.packet.JID; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
/** | ||
* Representation of a MAM query. | ||
* | ||
* @author Guus der Kinderen, [email protected] | ||
*/ | ||
public abstract class AbstractPaginatedMamQuery | ||
{ | ||
/** | ||
* Start (inclusive) of period for which to return messages. | ||
*/ | ||
@Nonnull | ||
protected final Date startDate; | ||
|
||
/** | ||
* End (inclusive) of period for which to return messages. | ||
*/ | ||
@Nonnull | ||
protected final Date endDate; | ||
|
||
/** | ||
* The message archive owner. | ||
*/ | ||
@Nonnull | ||
protected final JID archiveOwner; | ||
|
||
/** | ||
* An optional conversation partner. | ||
*/ | ||
@Nullable | ||
protected final JID with; | ||
|
||
/** | ||
* A search filter to be used for text-based search. | ||
*/ | ||
@Nullable | ||
protected final String query; | ||
|
||
/** | ||
* Creates a query for messages from a message archive. | ||
* | ||
* @param startDate Start (inclusive) of period for which to return messages. EPOCH will be used if no value is provided. | ||
* @param endDate End (inclusive) of period for which to return messages. 'now' will be used if no value is provided. | ||
* @param archiveOwner The message archive owner. | ||
* @param with An optional conversation partner | ||
*/ | ||
public AbstractPaginatedMamQuery(@Nullable final Date startDate, @Nullable final Date endDate, @Nonnull final JID archiveOwner, @Nullable final JID with) | ||
{ | ||
this.startDate = startDate == null ? new Date( 0L ) : startDate ; | ||
this.endDate = endDate == null ? new Date() : endDate; | ||
this.archiveOwner = archiveOwner; | ||
this.with = with; | ||
this.query = null; | ||
} | ||
|
||
/** | ||
* Creates a query for messages from a message archive. | ||
* | ||
* @param startDate Start (inclusive) of period for which to return messages. EPOCH will be used if no value is provided. | ||
* @param endDate End (inclusive) of period for which to return messages. 'now' will be used if no value is provided. | ||
* @param archiveOwner The message archive owner. | ||
* @param with An optional conversation partner | ||
* @param query A search string to be used for text-based search. | ||
*/ | ||
public AbstractPaginatedMamQuery(@Nullable final Date startDate, @Nullable final Date endDate, @Nonnull final JID archiveOwner, @Nullable final JID with, @Nonnull final String query) | ||
{ | ||
this.startDate = startDate == null ? new Date( 0L ) : startDate ; | ||
this.endDate = endDate == null ? new Date() : endDate; | ||
this.archiveOwner = archiveOwner; | ||
this.with = with; | ||
this.query = query; | ||
} | ||
|
||
/** | ||
* Get a page of a potentially larger list of archived messages that are the result of this query. | ||
* | ||
* @param after an optional message identifier that acts as a starting point (exclusive) of the messages to be returned. | ||
* @param before an optional message identifier that acts as an end point (exclusive) of the messages to be returned. | ||
* @param maxResults The maximum number of archived messages to return | ||
* @param isPagingBackwards true if the order of the messages is from new to old, otherwise false. | ||
* @return A list of archived messages | ||
* @throws DataRetrievalException On any problem that occurs while retrieving the page of archived messages. | ||
*/ | ||
abstract protected List<ArchivedMessage> getPage(@Nullable final Long after, @Nullable final Long before, final int maxResults, final boolean isPagingBackwards) throws DataRetrievalException; | ||
|
||
/** | ||
* Returns the amount of messages that are in the entire, unlimited/unpaged, result set. | ||
* <p> | ||
* The returned number is allowed to be an approximation. | ||
* | ||
* @return A message count, or -1 if unavailable. | ||
*/ | ||
abstract protected int getTotalCount(); | ||
|
||
@Nonnull | ||
public Date getStartDate() | ||
{ | ||
return startDate; | ||
} | ||
|
||
@Nonnull | ||
public Date getEndDate() | ||
{ | ||
return endDate; | ||
} | ||
|
||
@Nonnull | ||
public JID getArchiveOwner() | ||
{ | ||
return archiveOwner; | ||
} | ||
|
||
@Nullable | ||
public JID getWith() | ||
{ | ||
return with; | ||
} | ||
|
||
@Nullable | ||
public String getQuery() { | ||
return query; | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return "AbstractPaginatedMamQuery{" + | ||
"startDate=" + startDate + | ||
", endDate=" + endDate + | ||
", archiveOwner=" + archiveOwner + | ||
", with=" + with + | ||
", query='" + query + '\'' + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.