use of com.ibm.cloud.cloudant.v1.model.ViewResult in project cloudant-java-sdk by IBM.
the class ViewResultTest method testViewResult.
@Test
public void testViewResult() throws Throwable {
ViewResult viewResultModel = new ViewResult();
assertNull(viewResultModel.getTotalRows());
assertNull(viewResultModel.getUpdateSeq());
assertNull(viewResultModel.getRows());
}
use of com.ibm.cloud.cloudant.v1.model.ViewResult in project cloudant-java-sdk by IBM.
the class CloudantTest method testPostPartitionViewWOptions.
@Test
public void testPostPartitionViewWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"total_rows\": 0, \"update_seq\": \"updateSeq\", \"rows\": [{\"caused_by\": \"causedBy\", \"error\": \"error\", \"reason\": \"reason\", \"doc\": {\"_attachments\": {\"mapKey\": {\"content_type\": \"contentType\", \"data\": \"VGhpcyBpcyBhbiBlbmNvZGVkIGJ5dGUgYXJyYXku\", \"digest\": \"digest\", \"encoded_length\": 0, \"encoding\": \"encoding\", \"follows\": false, \"length\": 0, \"revpos\": 1, \"stub\": true}}, \"_conflicts\": [\"conflicts\"], \"_deleted\": false, \"_deleted_conflicts\": [\"deletedConflicts\"], \"_id\": \"id\", \"_local_seq\": \"localSeq\", \"_rev\": \"rev\", \"_revisions\": {\"ids\": [\"ids\"], \"start\": 1}, \"_revs_info\": [{\"rev\": \"rev\", \"status\": \"available\"}]}, \"id\": \"id\", \"key\": \"anyValue\", \"value\": \"anyValue\"}]}";
String postPartitionViewPath = "/testString/_partition/testString/_design/testString/_view/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the PostPartitionViewOptions model
PostPartitionViewOptions postPartitionViewOptionsModel = new PostPartitionViewOptions.Builder().db("testString").partitionKey("testString").ddoc("testString").view("testString").attEncodingInfo(false).attachments(false).conflicts(false).descending(false).includeDocs(true).inclusiveEnd(true).limit(Long.valueOf("10")).skip(Long.valueOf("0")).updateSeq(false).endkey("testString").endkeyDocid("testString").group(false).groupLevel(Long.valueOf("1")).key("testString").keys(new java.util.ArrayList<Object>(java.util.Arrays.asList("examplekey"))).reduce(true).stable(false).startkey("testString").startkeyDocid("testString").update("true").build();
// Invoke operation with valid options model (positive test)
Response<ViewResult> response = cloudantService.postPartitionView(postPartitionViewOptionsModel).execute();
assertNotNull(response);
ViewResult responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "POST");
// Check query
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNull(query);
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, postPartitionViewPath);
}
use of com.ibm.cloud.cloudant.v1.model.ViewResult in project cloudant-java-sdk by IBM.
the class Cloudant method postView.
/**
* Query a MapReduce view.
*
* This operation queries the specified MapReduce view of the specified design document. By default, the map and
* reduce functions of the view are run to update the view before returning the response. The advantage of using the
* HTTP `POST` method is that the query is submitted as a JSON object in the request body. This avoids the limitations
* of passing query options as URL query parameters of a `GET` request.
*
* @param postViewOptions the {@link PostViewOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link ViewResult}
*/
public ServiceCall<ViewResult> postView(PostViewOptions postViewOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(postViewOptions, "postViewOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", postViewOptions.db());
pathParamsMap.put("ddoc", postViewOptions.ddoc());
pathParamsMap.put("view", postViewOptions.view());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_design/{ddoc}/_view/{view}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postView");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
final JsonObject contentJson = new JsonObject();
if (postViewOptions.attEncodingInfo() != null) {
contentJson.addProperty("att_encoding_info", postViewOptions.attEncodingInfo());
}
if (postViewOptions.attachments() != null) {
contentJson.addProperty("attachments", postViewOptions.attachments());
}
if (postViewOptions.conflicts() != null) {
contentJson.addProperty("conflicts", postViewOptions.conflicts());
}
if (postViewOptions.descending() != null) {
contentJson.addProperty("descending", postViewOptions.descending());
}
if (postViewOptions.includeDocs() != null) {
contentJson.addProperty("include_docs", postViewOptions.includeDocs());
}
if (postViewOptions.inclusiveEnd() != null) {
contentJson.addProperty("inclusive_end", postViewOptions.inclusiveEnd());
}
if (postViewOptions.limit() != null) {
contentJson.addProperty("limit", postViewOptions.limit());
}
if (postViewOptions.skip() != null) {
contentJson.addProperty("skip", postViewOptions.skip());
}
if (postViewOptions.updateSeq() != null) {
contentJson.addProperty("update_seq", postViewOptions.updateSeq());
}
if (postViewOptions.endkey() != null) {
contentJson.add("endkey", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postViewOptions.endkey()));
}
if (postViewOptions.endkeyDocid() != null) {
contentJson.addProperty("endkey_docid", postViewOptions.endkeyDocid());
}
if (postViewOptions.group() != null) {
contentJson.addProperty("group", postViewOptions.group());
}
if (postViewOptions.groupLevel() != null) {
contentJson.addProperty("group_level", postViewOptions.groupLevel());
}
if (postViewOptions.key() != null) {
contentJson.add("key", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postViewOptions.key()));
}
if (postViewOptions.keys() != null) {
contentJson.add("keys", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postViewOptions.keys()));
}
if (postViewOptions.reduce() != null) {
contentJson.addProperty("reduce", postViewOptions.reduce());
}
if (postViewOptions.stable() != null) {
contentJson.addProperty("stable", postViewOptions.stable());
}
if (postViewOptions.startkey() != null) {
contentJson.add("startkey", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postViewOptions.startkey()));
}
if (postViewOptions.startkeyDocid() != null) {
contentJson.addProperty("startkey_docid", postViewOptions.startkeyDocid());
}
if (postViewOptions.update() != null) {
contentJson.addProperty("update", postViewOptions.update());
}
builder.bodyJson(contentJson);
ResponseConverter<ViewResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<ViewResult>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.cloud.cloudant.v1.model.ViewResult in project cloudant-java-sdk by IBM.
the class CloudantTest method testPostViewWOptions.
@Test
public void testPostViewWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"total_rows\": 0, \"update_seq\": \"updateSeq\", \"rows\": [{\"caused_by\": \"causedBy\", \"error\": \"error\", \"reason\": \"reason\", \"doc\": {\"_attachments\": {\"mapKey\": {\"content_type\": \"contentType\", \"data\": \"VGhpcyBpcyBhbiBlbmNvZGVkIGJ5dGUgYXJyYXku\", \"digest\": \"digest\", \"encoded_length\": 0, \"encoding\": \"encoding\", \"follows\": false, \"length\": 0, \"revpos\": 1, \"stub\": true}}, \"_conflicts\": [\"conflicts\"], \"_deleted\": false, \"_deleted_conflicts\": [\"deletedConflicts\"], \"_id\": \"id\", \"_local_seq\": \"localSeq\", \"_rev\": \"rev\", \"_revisions\": {\"ids\": [\"ids\"], \"start\": 1}, \"_revs_info\": [{\"rev\": \"rev\", \"status\": \"available\"}]}, \"id\": \"id\", \"key\": \"anyValue\", \"value\": \"anyValue\"}]}";
String postViewPath = "/testString/_design/testString/_view/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the PostViewOptions model
PostViewOptions postViewOptionsModel = new PostViewOptions.Builder().db("testString").ddoc("testString").view("testString").attEncodingInfo(false).attachments(false).conflicts(false).descending(false).includeDocs(true).inclusiveEnd(true).limit(Long.valueOf("10")).skip(Long.valueOf("0")).updateSeq(false).endkey("testString").endkeyDocid("testString").group(false).groupLevel(Long.valueOf("1")).key("testString").keys(new java.util.ArrayList<Object>(java.util.Arrays.asList("examplekey"))).reduce(true).stable(false).startkey("testString").startkeyDocid("testString").update("true").build();
// Invoke operation with valid options model (positive test)
Response<ViewResult> response = cloudantService.postView(postViewOptionsModel).execute();
assertNotNull(response);
ViewResult responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "POST");
// Check query
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNull(query);
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, postViewPath);
}
use of com.ibm.cloud.cloudant.v1.model.ViewResult in project cloudant-java-sdk by IBM.
the class Cloudant method postPartitionView.
/**
* Query a database partition MapReduce view function.
*
* Runs the specified view function from the specified design document. Unlike `GET /{db}/_design/{ddoc}/_view/{view}`
* for accessing views, the POST method supports the specification of explicit keys to be retrieved from the view
* results. The remainder of the POST view functionality is identical to the `GET /{db}/_design/{ddoc}/_view/{view}`
* API.
*
* @param postPartitionViewOptions the {@link PostPartitionViewOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link ViewResult}
*/
public ServiceCall<ViewResult> postPartitionView(PostPartitionViewOptions postPartitionViewOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(postPartitionViewOptions, "postPartitionViewOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", postPartitionViewOptions.db());
pathParamsMap.put("partition_key", postPartitionViewOptions.partitionKey());
pathParamsMap.put("ddoc", postPartitionViewOptions.ddoc());
pathParamsMap.put("view", postPartitionViewOptions.view());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_partition/{partition_key}/_design/{ddoc}/_view/{view}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postPartitionView");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
final JsonObject contentJson = new JsonObject();
if (postPartitionViewOptions.attEncodingInfo() != null) {
contentJson.addProperty("att_encoding_info", postPartitionViewOptions.attEncodingInfo());
}
if (postPartitionViewOptions.attachments() != null) {
contentJson.addProperty("attachments", postPartitionViewOptions.attachments());
}
if (postPartitionViewOptions.conflicts() != null) {
contentJson.addProperty("conflicts", postPartitionViewOptions.conflicts());
}
if (postPartitionViewOptions.descending() != null) {
contentJson.addProperty("descending", postPartitionViewOptions.descending());
}
if (postPartitionViewOptions.includeDocs() != null) {
contentJson.addProperty("include_docs", postPartitionViewOptions.includeDocs());
}
if (postPartitionViewOptions.inclusiveEnd() != null) {
contentJson.addProperty("inclusive_end", postPartitionViewOptions.inclusiveEnd());
}
if (postPartitionViewOptions.limit() != null) {
contentJson.addProperty("limit", postPartitionViewOptions.limit());
}
if (postPartitionViewOptions.skip() != null) {
contentJson.addProperty("skip", postPartitionViewOptions.skip());
}
if (postPartitionViewOptions.updateSeq() != null) {
contentJson.addProperty("update_seq", postPartitionViewOptions.updateSeq());
}
if (postPartitionViewOptions.endkey() != null) {
contentJson.add("endkey", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postPartitionViewOptions.endkey()));
}
if (postPartitionViewOptions.endkeyDocid() != null) {
contentJson.addProperty("endkey_docid", postPartitionViewOptions.endkeyDocid());
}
if (postPartitionViewOptions.group() != null) {
contentJson.addProperty("group", postPartitionViewOptions.group());
}
if (postPartitionViewOptions.groupLevel() != null) {
contentJson.addProperty("group_level", postPartitionViewOptions.groupLevel());
}
if (postPartitionViewOptions.key() != null) {
contentJson.add("key", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postPartitionViewOptions.key()));
}
if (postPartitionViewOptions.keys() != null) {
contentJson.add("keys", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postPartitionViewOptions.keys()));
}
if (postPartitionViewOptions.reduce() != null) {
contentJson.addProperty("reduce", postPartitionViewOptions.reduce());
}
if (postPartitionViewOptions.stable() != null) {
contentJson.addProperty("stable", postPartitionViewOptions.stable());
}
if (postPartitionViewOptions.startkey() != null) {
contentJson.add("startkey", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postPartitionViewOptions.startkey()));
}
if (postPartitionViewOptions.startkeyDocid() != null) {
contentJson.addProperty("startkey_docid", postPartitionViewOptions.startkeyDocid());
}
if (postPartitionViewOptions.update() != null) {
contentJson.addProperty("update", postPartitionViewOptions.update());
}
builder.bodyJson(contentJson);
ResponseConverter<ViewResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<ViewResult>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
Aggregations