Note To Self – SAK-11544 destined for 2-5-x

I finally got back to this!
Stuff to merge for SAK-11544
I took a copy of the 2-5-x code and reapplied the mods to that code and tested it. I attach the file that should slide right into 2-5-x.
search-impl/impl/src/java/org/sakaiproject/search/component/adapter/message/MessageContentProducer.java
Actually most of the differences were in formatting – someone had checked out the code – made a small mod but reformatted the code w.r.t. line ends and checked it back in. So it looks like there are lots of differences – it was not a refactor – just a reformat :)
This code should go in and make pretty diffs.


$ svn diff
Index: search-impl/impl/src/java/org/sakaiproject/search/component/adapter/message/MessageContentProducer.java
===================================================================
— search-impl/impl/src/java/org/sakaiproject/search/component/adapter/message/MessageContentProducer.java (revision 45952)
+++ search-impl/impl/src/java/org/sakaiproject/search/component/adapter/message/MessageContentProducer.java (working copy)
@@ -49,6 +49,7 @@
import org.sakaiproject.search.component.Messages;
import org.sakaiproject.search.model.SearchBuilderItem;
import org.sakaiproject.search.util.HTMLParser;
+import org.sakaiproject.javax.PagingPosition;
/**
* @author ieb
@@ -499,17 +500,22 @@
final Iterator ci = l.iterator();
return new Iterator()
{
– Iterator mi = null;
+ MessageChannel mc = null;
+ int messageCount = -1;
+ int nextMessage = -1; // Index overall messages – Starts at 1
+ List messages = null;
+ int listPos = 0; // Index each chunk – Starts at zero
+ int chunkSize = 100; // Retrieve 100 at a time
public boolean hasNext()
{
– if (mi == null)
+ if (mc == null)
{
return nextIterator();
}
else
{
– if (mi.hasNext())
+ if (messageCount > 1 && nextMessage <= messageCount)
{
return true;
}
@@ -528,13 +534,12 @@
String chanellId = (String) ci.next();
try
{
– MessageChannel c = messageService
– .getChannel(messageService.channelReference(
– context, chanellId));
– List messages = c.getMessages(null, true);
– mi = messages.iterator();
– if (mi.hasNext())
+ mc = messageService.getChannel(messageService
+ .channelReference(context, chanellId));
+ messageCount = mc.getCount();
+ if (messageCount > 0 )
{
+ nextMessage = 1; // Pager starts at 1
return true;
}
}
@@ -542,22 +547,56 @@
{
ex.printStackTrace();
log.warn(“Failed to get channel ” + chanellId); //$NON-NLS-1$

}
}
+ mc = null;
+ nextMessage = -1;
+ messageCount = -1;
return false;
}
+ /*
+ * Loop though the messages in the channel grabbing them
+ * in chunkSize chunks for efficiency.
+ */
public Object next()
{
– Message m = (Message) mi.next();
– return m.getReference();
+ if ( messages != null && listPos >= 0 && listPos < messages.size() )
+ {
+ Message m = (Message) messages.get(listPos);
+ nextMessage = nextMessage + 1;
+ listPos = listPos + 1;
+ return m.getReference();
+ }
+
+ // Retrieve the next “chunk”
+ PagingPosition pages = new PagingPosition(nextMessage, (nextMessage + chunkSize – 1));
+ try
+ {
+ messages = mc.getMessages(null, true, pages);
+ if ( messages != null && messages.size() > 0 )
+ {
+ listPos = 0;
+ Message m = (Message) messages.get(listPos);
+ nextMessage = nextMessage + 1;
+ listPos = listPos + 1;
+ return m.getReference();
+ }
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ log.warn(“Failed to get message ” + nextMessage); //$NON-NLS-1$
+
+ }
+ // We are done looping through this channel
+ nextMessage = messageCount + 1;
+ return null;
}
public void remove()
{
– throw new UnsupportedOperationException(
– “Remove not implemented”); //$NON-NLS-1$
+ throw new UnsupportedOperationException(“Remove not implemented”); //$NON-NLS-1$
}
};