Author: janstey
Date: Fri Dec 5 12:10:50 2008
New Revision: 723844
URL: http://svn.apache.org/viewvc?rev=723844&view=rev
Log:
CAMEL-1101 - Add option to sort entries by published date.
Added:
activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/component/rss/PublishedDateComparator.java
(with props)
activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssEntrySortDefaultsTest.java
(with props)
activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssEntrySortTest.java
(with props)
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/AggregatorType.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/AggregationCollection.java
activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/feed/FeedEndpoint.java
activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/component/rss/RssEndpoint.java
activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/component/rss/RssEntryPollingConsumer.java
activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/component/rss/UpdatedDateFilter.java
activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssEntryPollingConsumerTest.java
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java?rev=723844&r1=723843&r2=723844&view=diff
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java
(original)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java
Fri Dec 5 12:10:50 2008
@@ -270,6 +270,21 @@
}
/**
+ * Validates that the assertions fail on this endpoint
+
+ * @param timeoutForEmptyEndpoints the timeout in milliseconds that we
+ * should wait for the test to be true
+ */
+ public void assertIsNotSatisfied(long timeoutForEmptyEndpoints) throws
InterruptedException {
+ try {
+ assertIsSatisfied(timeoutForEmptyEndpoints);
+ fail("Expected assertion failure!");
+ } catch (AssertionError e) {
+ LOG.info("Caught expected failure: " + e);
+ }
+ }
+
+ /**
* Specifies the expected number of message exchanges that should be
* received by this endpoint
*
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/AggregatorType.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/AggregatorType.java?rev=723844&r1=723843&r2=723844&view=diff
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/AggregatorType.java
(original)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/AggregatorType.java
Fri Dec 5 12:10:50 2008
@@ -289,7 +289,7 @@
//-------------------------------------------------------------------------
/**
- * Sets the in batch size for number of exchanges recieved
+ * Sets the in batch size for number of exchanges received
*
* @param batchSize the batch size
* @return builder
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/AggregationCollection.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/AggregationCollection.java?rev=723844&r1=723843&r2=723844&view=diff
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/AggregationCollection.java
(original)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/AggregationCollection.java
Fri Dec 5 12:10:50 2008
@@ -69,7 +69,7 @@
int size();
/**
- * Clears this colleciton
+ * Clears this collection
*/
void clear();
Modified:
activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/feed/FeedEndpoint.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/feed/FeedEndpoint.java?rev=723844&r1=723843&r2=723844&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/feed/FeedEndpoint.java
(original)
+++
activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/feed/FeedEndpoint.java
Fri Dec 5 12:10:50 2008
@@ -35,6 +35,7 @@
protected Date lastUpdate;
protected boolean filter = true;
private boolean feedHeader = true;
+ private boolean sortEntries = false;
public FeedEndpoint(String endpointUri, FeedComponent component, String
feedUri) {
super(endpointUri, component);
@@ -163,6 +164,17 @@
return feedHeader;
}
+ /**
+ * Sets whether to sort entries by published date. Only works when
splitEntries = true.
+ */
+ public void setSortEntries(boolean sortEntries) {
+ this.sortEntries = sortEntries;
+ }
+
+ public boolean isSortEntries() {
+ return sortEntries ;
+ }
+
// Implementation methods
//-------------------------------------------------------------------------
Added:
activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/component/rss/PublishedDateComparator.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/component/rss/PublishedDateComparator.java?rev=723844&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/component/rss/PublishedDateComparator.java
(added)
+++
activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/component/rss/PublishedDateComparator.java
Fri Dec 5 12:10:50 2008
@@ -0,0 +1,32 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.camel.component.rss;
+
+import com.sun.syndication.feed.synd.SyndEntry;
+
+import java.util.Comparator;
+
+public class PublishedDateComparator implements Comparator {
+
+ public int compare(Object o1, Object o2) {
+ SyndEntry s1 = (SyndEntry) o1;
+ SyndEntry s2 = (SyndEntry) o2;
+ return s2.getPublishedDate().compareTo(s1.getPublishedDate());
+ }
+
+}
\ No newline at end of file
Propchange:
activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/component/rss/PublishedDateComparator.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/component/rss/RssEndpoint.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/component/rss/RssEndpoint.java?rev=723844&r1=723843&r2=723844&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/component/rss/RssEndpoint.java
(original)
+++
activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/component/rss/RssEndpoint.java
Fri Dec 5 12:10:50 2008
@@ -44,7 +44,7 @@
*/
public static final String HEADER_RSS_FEED =
"org.apache.camel.component.rss.feed";
protected static final transient Log LOG =
LogFactory.getLog(RssEndpoint.class);
-
+
public RssEndpoint(String endpointUri, FeedComponent component, String
feedUri) {
super(endpointUri, component, feedUri);
}
Modified:
activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/component/rss/RssEntryPollingConsumer.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/component/rss/RssEntryPollingConsumer.java?rev=723844&r1=723843&r2=723844&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/component/rss/RssEntryPollingConsumer.java
(original)
+++
activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/component/rss/RssEntryPollingConsumer.java
Fri Dec 5 12:10:50 2008
@@ -16,12 +16,15 @@
*/
package org.apache.camel.component.rss;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.Date;
import com.sun.syndication.feed.synd.SyndFeed;
import org.apache.camel.Processor;
import org.apache.camel.component.feed.EntryFilter;
+import org.apache.camel.component.feed.FeedEndpoint;
import org.apache.camel.component.feed.FeedEntryPollingConsumer;
@@ -39,10 +42,17 @@
protected void populateList(Object feed) throws Exception {
if (list == null) {
list = ((SyndFeed)feed).getEntries();
+ if (endpoint.isSortEntries()) {
+ sortEntries();
+ }
entryIndex = list.size() - 1;
}
}
+ protected void sortEntries() {
+ Collections.sort(list, new PublishedDateComparator());
+ }
+
@Override
protected Object createFeed() throws Exception {
return RssUtils.createFeed(endpoint.getFeedUri());
@@ -55,5 +65,5 @@
protected EntryFilter createEntryFilter(Date lastUpdate) {
return new UpdatedDateFilter(lastUpdate);
- }
+ }
}
Modified:
activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/component/rss/UpdatedDateFilter.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/component/rss/UpdatedDateFilter.java?rev=723844&r1=723843&r2=723844&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/component/rss/UpdatedDateFilter.java
(original)
+++
activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/component/rss/UpdatedDateFilter.java
Fri Dec 5 12:10:50 2008
@@ -42,6 +42,9 @@
public boolean isValidEntry(FeedEndpoint endpoint, Object feed, Object
entry) {
Date updated = ((SyndEntry)entry).getUpdatedDate();
+ if (updated == null) { // never been updated so get published date
+ updated = ((SyndEntry)entry).getPublishedDate();
+ }
if (updated == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("No updated time for entry so assuming its valid:
entry=[" + entry + "]");
@@ -49,7 +52,7 @@
return true;
}
if (lastUpdate != null) {
- if (lastUpdate.after(updated)) {
+ if (lastUpdate.after(updated) || lastUpdate.equals(updated)) {
if (LOG.isDebugEnabled()) {
LOG.debug("Entry is older than lastupdate=[" + lastUpdate
+ "], no valid entry=[" + entry + "]");
@@ -57,7 +60,7 @@
return false;
}
}
- lastUpdate = updated;
+ lastUpdate = updated;
return true;
}
Modified:
activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssEntryPollingConsumerTest.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssEntryPollingConsumerTest.java?rev=723844&r1=723843&r2=723844&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssEntryPollingConsumerTest.java
(original)
+++
activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssEntryPollingConsumerTest.java
Fri Dec 5 12:10:50 2008
@@ -31,7 +31,7 @@
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
-
from("rss:file:src/test/data/rss20.xml?splitEntries=true&consumer.delay=100").to("mock:result");
+
from("rss:file:src/test/data/rss20.xml?splitEntries=true&sortEntries=true&consumer.delay=100").to("mock:result");
}
};
}
Added:
activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssEntrySortDefaultsTest.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssEntrySortDefaultsTest.java?rev=723844&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssEntrySortDefaultsTest.java
(added)
+++
activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssEntrySortDefaultsTest.java
Fri Dec 5 12:10:50 2008
@@ -0,0 +1,44 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.camel.component.rss;
+
+import com.sun.syndication.feed.synd.SyndEntry;
+import com.sun.syndication.feed.synd.SyndFeed;
+
+import java.util.Date;
+
+import javax.naming.Context;
+
+import org.apache.camel.Body;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.ExpressionBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.util.jndi.JndiContext;
+
+public class RssEntrySortDefaultsTest extends RssEntrySortTest {
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() throws Exception {
+
from("rss:file:src/test/data/rss20.xml?splitEntries=true&sortEntries=true&consumer.delay=50").to("mock:sorted");
+
+ // should NOT sort by default
+
from("rss:file:src/test/data/rss20.xml?splitEntries=true&consumer.delay=50").to("mock:unsorted");
+ }
+ };
+ }
+}
Propchange:
activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssEntrySortDefaultsTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssEntrySortTest.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssEntrySortTest.java?rev=723844&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssEntrySortTest.java
(added)
+++
activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssEntrySortTest.java
Fri Dec 5 12:10:50 2008
@@ -0,0 +1,73 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.camel.component.rss;
+
+import com.sun.syndication.feed.synd.SyndEntry;
+import com.sun.syndication.feed.synd.SyndFeed;
+
+import java.util.Date;
+
+import javax.naming.Context;
+
+import org.apache.camel.Body;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.ExpressionBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.util.jndi.JndiContext;
+
+public class RssEntrySortTest extends ContextTestSupport {
+
+ public void testSortedEntries() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:sorted");
+ mock.expectsAscending(ExpressionBuilder.beanExpression("myBean",
"getPubDate"));
+ mock.expectedMessageCount(10);
+ mock.assertIsSatisfied();
+ }
+
+ public void testUnSortedEntries() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:unsorted");
+ mock.expectsAscending(ExpressionBuilder.beanExpression("myBean",
"getPubDate"));
+ mock.expectedMessageCount(10);
+ mock.setResultWaitTime(2000L);
+ mock.assertIsNotSatisfied(2000L);
+ }
+
+ @Override
+ protected Context createJndiContext() throws Exception {
+ JndiContext jndi = new JndiContext();
+ jndi.bind("myBean", new MyBean());
+ return jndi;
+ }
+
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() throws Exception {
+
from("rss:file:src/test/data/rss20.xml?splitEntries=true&sortEntries=true&consumer.delay=50").to("mock:sorted");
+
from("rss:file:src/test/data/rss20.xml?splitEntries=true&sortEntries=false&consumer.delay=50").to("mock:unsorted");
+ }
+ };
+ }
+
+ public static class MyBean {
+ public Date getPubDate(@Body Object body) {
+ SyndFeed feed = (SyndFeed) body;
+ SyndEntry syndEntry = (SyndEntry) feed.getEntries().get(0);
+ return syndEntry.getPublishedDate();
+ }
+ }
+}
Propchange:
activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssEntrySortTest.java
------------------------------------------------------------------------------
svn:eol-style = native