streams-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sblack...@apache.org
Subject [6/7] git commit: updated per peer review feedback
Date Fri, 08 Aug 2014 16:49:57 GMT
updated per peer review feedback


Project: http://git-wip-us.apache.org/repos/asf/incubator-streams/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-streams/commit/a14456fd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-streams/tree/a14456fd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-streams/diff/a14456fd

Branch: refs/heads/master
Commit: a14456fda013087e35f485043322782ac6a81989
Parents: 19b380f
Author: sblackmon <sblackmon@w2odigital.com>
Authored: Thu Aug 7 17:46:09 2014 -0500
Committer: sblackmon <sblackmon@w2odigital.com>
Committed: Thu Aug 7 17:46:09 2014 -0500

----------------------------------------------------------------------
 .../provider/TwitterTimelineProvider.java       | 58 +++++++-------------
 .../provider/TwitterTimelineProviderTask.java   |  4 +-
 2 files changed, 21 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/a14456fd/streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/provider/TwitterTimelineProvider.java
----------------------------------------------------------------------
diff --git a/streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/provider/TwitterTimelineProvider.java
b/streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/provider/TwitterTimelineProvider.java
index a7b39c1..8d9ee46 100644
--- a/streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/provider/TwitterTimelineProvider.java
+++ b/streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/provider/TwitterTimelineProvider.java
@@ -230,10 +230,27 @@ public class TwitterTimelineProvider implements StreamsProvider, Serializable
{
         Preconditions.checkNotNull(config.getOauth().getAccessTokenSecret());
         Preconditions.checkNotNull(config.getInfo());
 
-        ImmutableList<String> screenNames = ImmutableList.copyOf(screenNamesOnly(config.getInfo()));
-        List<Long> ids = numericIdsOnly(config.getInfo());
+        consolidateToIDs();
+    }
+
+    /**
+     * Using the "info" list that is contained in the configuration, ensure that all
+     * account identifiers are converted to IDs (Longs) instead of screenNames (Strings)
+     */
+    private void consolidateToIDs() {
+        List<String> screenNames = Lists.newArrayList();
+        ids = Lists.newArrayList();
+
+        for(Object account : config.getInfo()) {
+            if(account instanceof String) {
+                screenNames.add((String)account);
+            } else if (account instanceof Long) {
+                ids.add(Long.parseLong(Objects.toString(account, null)));
+            }
+        }
 
         // Twitter allows for batches up to 100 per request, but you cannot mix types
+        screenNameBatches = new ArrayList<String[]>();
         while(screenNames.size() >= 100) {
             screenNameBatches.add(screenNames.subList(0, 100).toArray(new String[0]));
             screenNames = screenNames.subList(100, screenNames.size());
@@ -248,7 +265,6 @@ public class TwitterTimelineProvider implements StreamsProvider, Serializable
{
             Collection<Long> batchIds = retrieveIds(screenNameBatchIterator.next());
             ids.addAll(batchIds);
         }
-
     }
 
     protected Twitter getTwitterClient()
@@ -275,42 +291,6 @@ public class TwitterTimelineProvider implements StreamsProvider, Serializable
{
         shutdownAndAwaitTermination(executor);
     }
 
-    protected List<Long> numericIdsOnly(List<String> allIds) {
-        List<Long> result = Lists.newArrayList();
-        for(String id : allIds) {
-            if(id != null)
-            {
-                // See if it is a long, if it is, add it to the user iD list, if it is not,
add it to the
-                // screen name list
-                try {
-                    result.add(Long.parseLong(id));
-                } catch (NumberFormatException e) {}
-
-            }
-        }
-        return result;
-    }
-
-    protected List<String> screenNamesOnly(List<String> allIds) {
-        List<String> result = Lists.newArrayList();
-        for(String id : allIds) {
-            if(id != null)
-            {
-                String potentialScreenName = id.replaceAll("@", "").trim().toLowerCase();
-
-                // See if it is a long, if it is, add it to the user iD list, if it is not,
add it to the
-                // screen name list
-                try {
-                    Long.parseLong(id);
-                } catch (NumberFormatException e) {
-                    result.add(potentialScreenName);
-                }
-
-            }
-        }
-        return result;
-    }
-
     protected void addDatum(StreamsDatum datum) {
         try {
             lock.readLock().lock();

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/a14456fd/streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/provider/TwitterTimelineProviderTask.java
----------------------------------------------------------------------
diff --git a/streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/provider/TwitterTimelineProviderTask.java
b/streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/provider/TwitterTimelineProviderTask.java
index 0ad8ac3..96fbb42 100644
--- a/streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/provider/TwitterTimelineProviderTask.java
+++ b/streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/provider/TwitterTimelineProviderTask.java
@@ -48,8 +48,6 @@ public class TwitterTimelineProviderTask implements Runnable {
 
         Paging paging = new Paging(1, 200);
         List<Status> statuses = null;
-        boolean KeepGoing = true;
-        boolean hadFailure = false;
 
         do
         {
@@ -64,6 +62,8 @@ public class TwitterTimelineProviderTask implements Runnable {
 
                 try
                 {
+                    this.client = provider.getTwitterClient();
+
                     statuses = client.getUserTimeline(id, paging);
 
                     for (Status tStat : statuses)


Mime
View raw message