You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2015/05/30 09:18:42 UTC

[1/2] camel git commit: CAMEL-8817: Expose additional geolocation search api.

Repository: camel
Updated Branches:
  refs/heads/master 5e10ebaf6 -> 93f76929e


CAMEL-8817: Expose additional geolocation search api.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/04971dcc
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/04971dcc
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/04971dcc

Branch: refs/heads/master
Commit: 04971dccfecb168285a43be083cc79e34ce9b909
Parents: 5e10eba
Author: Jason Taylor <ja...@baesystemsdetica.com>
Authored: Fri May 29 11:17:13 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat May 30 09:16:06 2015 +0200

----------------------------------------------------------------------
 .../component/twitter/TwitterConfiguration.java | 57 ++++++++++++++++++++
 .../twitter/consumer/search/SearchConsumer.java | 37 ++++++++++---
 2 files changed, 86 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/04971dcc/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConfiguration.java b/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConfiguration.java
index 413c47f..9a47954 100644
--- a/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConfiguration.java
+++ b/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConfiguration.java
@@ -69,6 +69,15 @@ public class TwitterConfiguration {
     private String httpProxyPassword;
     @UriParam
     private Integer httpProxyPort;
+    @UriParam
+    private Double latitude;
+    @UriParam
+    private Double longitude;
+    @UriParam
+    private Double radius;
+    @UriParam(defaultValue = "km")
+    private String distanceMetric;
+    
     
     /**
      * Singleton, on demand instances of Twitter4J's Twitter & TwitterStream.
@@ -352,4 +361,52 @@ public class TwitterConfiguration {
     public int getHttpProxyPort() {
         return httpProxyPort;
     }
+
+    public Double getLongitude() {
+    	return longitude;
+    }
+
+    /**
+     * Used by the non-stream geography search.
+     * @param longitude
+     */
+    public void setLongitude(Double longitude) {
+    	this.longitude = longitude;
+    }
+
+    public Double getRadius() {
+    	return radius;
+    }
+
+    /**
+     * Used by the non-stream geography search.
+     * @param radius
+     */
+    public void setRadius(Double radius) {
+    	this.radius = radius;
+    }
+
+    public String getDistanceMetric() {
+    	return distanceMetric;
+    }
+
+    /**
+     * Used by the non-stream geography search, defaults to km.
+     * @param distanceMetric
+     */
+    public void setDistanceMetric(String distanceMetric) {
+    	this.distanceMetric = distanceMetric;
+    }
+
+    public Double getLatitude() {
+    	return latitude;
+    }
+
+    /**
+     * Used by the non-stream geography search.
+     * @param latitude
+     */
+    public void setLatitude(Double latitude) {
+    	this.latitude = latitude;
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/04971dcc/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/search/SearchConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/search/SearchConsumer.java b/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/search/SearchConsumer.java
index 599f9f3..d42c914 100644
--- a/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/search/SearchConsumer.java
+++ b/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/search/SearchConsumer.java
@@ -24,7 +24,10 @@ import org.apache.camel.component.twitter.consumer.Twitter4JConsumer;
 import org.apache.camel.util.ObjectHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+
+import twitter4j.GeoLocation;
 import twitter4j.Query;
+import twitter4j.Query.Unit;
 import twitter4j.QueryResult;
 import twitter4j.Status;
 import twitter4j.Twitter;
@@ -42,14 +45,23 @@ public class SearchConsumer extends Twitter4JConsumer {
     }
 
     public List<Status> pollConsume() throws TwitterException {
-        String keywords = te.getProperties().getKeywords();
-        Query query = new Query(keywords);
-        if (te.getProperties().isFilterOld()) {
-            query.setSinceId(lastId);
-        }
-        
-        LOG.debug("Searching twitter with keywords: {}", keywords);
-        return search(query);
+    	String keywords = te.getProperties().getKeywords();
+
+    	Query query;
+
+    	if(keywords!=null && keywords.trim().length() > 0) {
+    		query = new Query(keywords);
+    		LOG.debug("Searching twitter with keywords: {}", keywords);
+    	} else {
+    		query = new Query();
+    		LOG.debug("Searching twitter without keywords.");
+    	}
+
+    	if (te.getProperties().isFilterOld()) {
+    		query.setSinceId(lastId);
+    	}
+
+    	return search(query);
     }
 
     public List<Status> directConsume() throws TwitterException {
@@ -78,6 +90,15 @@ public class SearchConsumer extends Twitter4JConsumer {
             numberOfPages = te.getProperties().getNumberOfPages();
         }
         
+        if (ObjectHelper.isNotEmpty(te.getProperties().getLatitude()) &&
+        		ObjectHelper.isNotEmpty(te.getProperties().getLongitude()) &&
+        		ObjectHelper.isNotEmpty(te.getProperties().getRadius())) {
+        	GeoLocation location = new GeoLocation(te.getProperties().getLatitude(), te.getProperties().getLongitude());
+        	query.setGeoCode(location, te.getProperties().getRadius(), Unit.valueOf(te.getProperties().getDistanceMetric()));
+
+        	LOG.debug("Searching with additional geolocation parameters.");
+        }
+        
         LOG.debug("Searching with {} pages.", numberOfPages);
 
         Twitter twitter = te.getProperties().getTwitter();


[2/2] camel git commit: Fixed CS

Posted by da...@apache.org.
Fixed CS


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/93f76929
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/93f76929
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/93f76929

Branch: refs/heads/master
Commit: 93f76929e5515d0777729a7e8839aaaa747c111b
Parents: 04971dc
Author: Claus Ibsen <da...@apache.org>
Authored: Sat May 30 09:23:22 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat May 30 09:23:22 2015 +0200

----------------------------------------------------------------------
 .../component/twitter/TwitterConfiguration.java | 56 +++++++++++---------
 .../twitter/consumer/search/SearchConsumer.java | 49 +++++++++--------
 2 files changed, 55 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/93f76929/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConfiguration.java b/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConfiguration.java
index 9a47954..e8735ae 100644
--- a/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConfiguration.java
+++ b/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConfiguration.java
@@ -75,10 +75,9 @@ public class TwitterConfiguration {
     private Double longitude;
     @UriParam
     private Double radius;
-    @UriParam(defaultValue = "km")
+    @UriParam(defaultValue = "km", enums = "mi,km")
     private String distanceMetric;
-    
-    
+
     /**
      * Singleton, on demand instances of Twitter4J's Twitter & TwitterStream.
      * This should not be created by an endpoint's doStart(), etc., since
@@ -363,50 +362,57 @@ public class TwitterConfiguration {
     }
 
     public Double getLongitude() {
-    	return longitude;
+        return longitude;
     }
 
     /**
-     * Used by the non-stream geography search.
-     * @param longitude
+     * Used by the non-stream geography search to search by longitude.
+     * <p/>
+     * You need to configure all the following options: longitude, latitude, radius, and distanceMetric.
      */
     public void setLongitude(Double longitude) {
-    	this.longitude = longitude;
+        this.longitude = longitude;
     }
 
-    public Double getRadius() {
-    	return radius;
+    public Double getLatitude() {
+        return latitude;
     }
 
     /**
-     * Used by the non-stream geography search.
-     * @param radius
+     * Used by the non-stream geography search to search by lattitude.
+     * <p/>
+     * You need to configure all the following options: longitude, latitude, radius, and distanceMetric.
      */
-    public void setRadius(Double radius) {
-    	this.radius = radius;
+    public void setLatitude(Double latitude) {
+        this.latitude = latitude;
     }
 
-    public String getDistanceMetric() {
-    	return distanceMetric;
+    public Double getRadius() {
+        return radius;
     }
 
     /**
-     * Used by the non-stream geography search, defaults to km.
-     * @param distanceMetric
+     * Used by the non-stream geography search to search by radius.
+     * <p/>
+     * You need to configure all the following options: longitude, latitude, radius, and distanceMetric.
      */
-    public void setDistanceMetric(String distanceMetric) {
-    	this.distanceMetric = distanceMetric;
+    public void setRadius(Double radius) {
+        this.radius = radius;
     }
 
-    public Double getLatitude() {
-    	return latitude;
+    public String getDistanceMetric() {
+        return distanceMetric;
     }
 
     /**
-     * Used by the non-stream geography search.
-     * @param latitude
+     * Used by the non-stream geography search, to search by radius using the configured metrics.
+     * <p/>
+     * The unit can either be mi for miles, or km for kilometers.
+     * <p/>
+     * You need to configure all the following options: longitude, latitude, radius, and distanceMetric.
      */
-    public void setLatitude(Double latitude) {
-    	this.latitude = latitude;
+    public void setDistanceMetric(String distanceMetric) {
+        this.distanceMetric = distanceMetric;
     }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/93f76929/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/search/SearchConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/search/SearchConsumer.java b/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/search/SearchConsumer.java
index d42c914..4b2cdf1 100644
--- a/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/search/SearchConsumer.java
+++ b/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/search/SearchConsumer.java
@@ -24,7 +24,6 @@ import org.apache.camel.component.twitter.consumer.Twitter4JConsumer;
 import org.apache.camel.util.ObjectHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-
 import twitter4j.GeoLocation;
 import twitter4j.Query;
 import twitter4j.Query.Unit;
@@ -45,23 +44,23 @@ public class SearchConsumer extends Twitter4JConsumer {
     }
 
     public List<Status> pollConsume() throws TwitterException {
-    	String keywords = te.getProperties().getKeywords();
+        String keywords = te.getProperties().getKeywords();
 
-    	Query query;
+        Query query;
 
-    	if(keywords!=null && keywords.trim().length() > 0) {
-    		query = new Query(keywords);
-    		LOG.debug("Searching twitter with keywords: {}", keywords);
-    	} else {
-    		query = new Query();
-    		LOG.debug("Searching twitter without keywords.");
-    	}
+        if (keywords != null && keywords.trim().length() > 0) {
+            query = new Query(keywords);
+            LOG.debug("Searching twitter with keywords: {}", keywords);
+        } else {
+            query = new Query();
+            LOG.debug("Searching twitter without keywords.");
+        }
 
-    	if (te.getProperties().isFilterOld()) {
-    		query.setSinceId(lastId);
-    	}
+        if (te.getProperties().isFilterOld()) {
+            query.setSinceId(lastId);
+        }
 
-    	return search(query);
+        return search(query);
     }
 
     public List<Status> directConsume() throws TwitterException {
@@ -70,14 +69,14 @@ public class SearchConsumer extends Twitter4JConsumer {
             return Collections.emptyList();
         }
         Query query = new Query(keywords);
-        
+
         LOG.debug("Searching twitter with keywords: {}", keywords);
         return search(query);
     }
 
     private List<Status> search(Query query) throws TwitterException {
         Integer numberOfPages = 1;
-        
+
         if (ObjectHelper.isNotEmpty(te.getProperties().getLang())) {
             query.setLang(te.getProperties().getLang());
         }
@@ -89,16 +88,16 @@ public class SearchConsumer extends Twitter4JConsumer {
         if (ObjectHelper.isNotEmpty(te.getProperties().getNumberOfPages())) {
             numberOfPages = te.getProperties().getNumberOfPages();
         }
-        
-        if (ObjectHelper.isNotEmpty(te.getProperties().getLatitude()) &&
-        		ObjectHelper.isNotEmpty(te.getProperties().getLongitude()) &&
-        		ObjectHelper.isNotEmpty(te.getProperties().getRadius())) {
-        	GeoLocation location = new GeoLocation(te.getProperties().getLatitude(), te.getProperties().getLongitude());
-        	query.setGeoCode(location, te.getProperties().getRadius(), Unit.valueOf(te.getProperties().getDistanceMetric()));
-
-        	LOG.debug("Searching with additional geolocation parameters.");
+
+        if (ObjectHelper.isNotEmpty(te.getProperties().getLatitude())
+                && ObjectHelper.isNotEmpty(te.getProperties().getLongitude())
+                && ObjectHelper.isNotEmpty(te.getProperties().getRadius())) {
+            GeoLocation location = new GeoLocation(te.getProperties().getLatitude(), te.getProperties().getLongitude());
+            query.setGeoCode(location, te.getProperties().getRadius(), Unit.valueOf(te.getProperties().getDistanceMetric()));
+
+            LOG.debug("Searching with additional geolocation parameters.");
         }
-        
+
         LOG.debug("Searching with {} pages.", numberOfPages);
 
         Twitter twitter = te.getProperties().getTwitter();