You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2014/11/27 19:27:42 UTC
[2/2] camel git commit: CAMEL-8089 - Support paging and restricting
results from google drive
CAMEL-8089 - Support paging and restricting results from google drive
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f9044427
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f9044427
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f9044427
Branch: refs/heads/camel-2.14.x
Commit: f9044427ba92bf976381951f7af38c84354e3246
Parents: a6c54c5
Author: Jonathan Anstey <ja...@gmail.com>
Authored: Thu Nov 27 14:55:46 2014 -0330
Committer: Jonathan Anstey <ja...@gmail.com>
Committed: Thu Nov 27 14:56:56 2014 -0330
----------------------------------------------------------------------
.../google/drive/GoogleDriveConsumer.java | 12 ++++++-
.../google/drive/GoogleDriveProducer.java | 12 ++++++-
.../google/drive/DriveFilesIntegrationTest.java | 37 ++++++++++++++++++--
3 files changed, 56 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/f9044427/components/camel-google-drive/src/main/java/org/apache/camel/component/google/drive/GoogleDriveConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-google-drive/src/main/java/org/apache/camel/component/google/drive/GoogleDriveConsumer.java b/components/camel-google-drive/src/main/java/org/apache/camel/component/google/drive/GoogleDriveConsumer.java
index 0505bcf..266aa27 100644
--- a/components/camel-google-drive/src/main/java/org/apache/camel/component/google/drive/GoogleDriveConsumer.java
+++ b/components/camel-google-drive/src/main/java/org/apache/camel/component/google/drive/GoogleDriveConsumer.java
@@ -24,6 +24,7 @@ import com.google.api.client.googleapis.services.AbstractGoogleClientRequest;
import org.apache.camel.Processor;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.component.google.drive.internal.GoogleDriveApiName;
+import org.apache.camel.util.IntrospectionSupport;
import org.apache.camel.util.component.AbstractApiConsumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -43,9 +44,18 @@ public class GoogleDriveConsumer extends AbstractApiConsumer<GoogleDriveApiName,
protected Object doInvokeMethod(Map<String, Object> properties) throws RuntimeCamelException {
AbstractGoogleClientRequest request = (AbstractGoogleClientRequest) super.doInvokeMethod(properties);
try {
+ setProperty(properties, request, "q");
+ setProperty(properties, request, "maxResults");
+ setProperty(properties, request, "pageToken");
return request.execute();
- } catch (IOException e) {
+ } catch (Exception e) {
throw new RuntimeCamelException(e);
}
}
+
+ private void setProperty(Map<String, Object> properties, AbstractGoogleClientRequest request, String key) throws Exception {
+ if (properties.containsKey(key)) {
+ IntrospectionSupport.setProperty(getEndpoint().getCamelContext().getTypeConverter(), request, key, properties.get(key));
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/f9044427/components/camel-google-drive/src/main/java/org/apache/camel/component/google/drive/GoogleDriveProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-google-drive/src/main/java/org/apache/camel/component/google/drive/GoogleDriveProducer.java b/components/camel-google-drive/src/main/java/org/apache/camel/component/google/drive/GoogleDriveProducer.java
index d8b4b5c..55b815a 100644
--- a/components/camel-google-drive/src/main/java/org/apache/camel/component/google/drive/GoogleDriveProducer.java
+++ b/components/camel-google-drive/src/main/java/org/apache/camel/component/google/drive/GoogleDriveProducer.java
@@ -25,6 +25,7 @@ import org.apache.camel.RuntimeCamelException;
import org.apache.camel.component.google.drive.internal.GoogleDriveApiName;
import org.apache.camel.component.google.drive.internal.GoogleDriveConstants;
import org.apache.camel.component.google.drive.internal.GoogleDrivePropertiesHelper;
+import org.apache.camel.util.IntrospectionSupport;
import org.apache.camel.util.component.AbstractApiProducer;
import org.apache.camel.util.component.ApiMethod;
@@ -41,8 +42,11 @@ public class GoogleDriveProducer extends AbstractApiProducer<GoogleDriveApiName,
protected Object doInvokeMethod(ApiMethod method, Map<String, Object> properties) throws RuntimeCamelException {
AbstractGoogleClientRequest request = (AbstractGoogleClientRequest) super.doInvokeMethod(method, properties);
try {
+ setProperty(properties, request, "q");
+ setProperty(properties, request, "maxResults");
+ setProperty(properties, request, "pageToken");
return request.execute();
- } catch (IOException e) {
+ } catch (Exception e) {
throw new RuntimeCamelException(e);
}
}
@@ -50,4 +54,10 @@ public class GoogleDriveProducer extends AbstractApiProducer<GoogleDriveApiName,
protected String getThreadProfileName() {
return GoogleDriveConstants.THREAD_PROFILE_NAME;
}
+
+ private void setProperty(Map<String, Object> properties, AbstractGoogleClientRequest request, String key) throws Exception {
+ if (properties.containsKey(key)) {
+ IntrospectionSupport.setProperty(getEndpoint().getCamelContext().getTypeConverter(), request, key, properties.get(key));
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/f9044427/components/camel-google-drive/src/test/java/org/apache/camel/component/google/drive/DriveFilesIntegrationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-google-drive/src/test/java/org/apache/camel/component/google/drive/DriveFilesIntegrationTest.java b/components/camel-google-drive/src/test/java/org/apache/camel/component/google/drive/DriveFilesIntegrationTest.java
index bc15ec4..624ef7b 100644
--- a/components/camel-google-drive/src/test/java/org/apache/camel/component/google/drive/DriveFilesIntegrationTest.java
+++ b/components/camel-google-drive/src/test/java/org/apache/camel/component/google/drive/DriveFilesIntegrationTest.java
@@ -16,7 +16,10 @@
*/
package org.apache.camel.component.google.drive;
+import java.io.IOException;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import com.google.api.client.http.FileContent;
@@ -111,11 +114,39 @@ public class DriveFilesIntegrationTest extends AbstractGoogleDriveTestSupport {
@Test
public void testList() throws Exception {
// upload a test file
- File theTestFile = uploadTestFile();
+ File testFile = uploadTestFile();
- final FileList result = requestBody("direct://LIST", null);
+ FileList result = requestBody("direct://LIST", null);
assertNotNull("list result", result);
- LOG.debug("list: " + result);
+ assertTrue(result.getItems().size() >= 1);
+
+ File testFile2 = uploadTestFile();
+
+ Map<String, Object> headers = new HashMap<String, Object>();
+ headers.put("CamelGoogleDrive.maxResults", 1);
+
+ result = requestBodyAndHeaders("direct://LIST", null, headers);
+ assertNotNull("list result", result);
+ assertTrue(result.getItems().size() == 1);
+
+ // test paging the list
+ List<File> resultList = new ArrayList<File>();
+ String pageToken;
+ int i = 0;
+ do {
+ result = requestBodyAndHeaders("direct://LIST", null, headers);
+
+ resultList.addAll(result.getItems());
+ pageToken = result.getNextPageToken();
+ headers.put("CamelGoogleDrive.pageToken", pageToken);
+
+ i++;
+ } while (pageToken != null && pageToken.length() > 0 && i < 2);
+
+ // we should have 2 files in result (one file for each of the 2 pages)
+ assertTrue(resultList.size() == 2);
+ // they should be different files
+ assertFalse(resultList.get(0).getId().equals(resultList.get(1)));
}
@Ignore