use of com.ibm.cloud.cloudant.v1.model.ViewQueriesResult in project cloudant-java-sdk by IBM.
the class Cloudant method postViewQueries.
/**
* Multi-query a MapReduce view.
*
* This operation runs multiple specified view queries against the view function from the specified design document.
*
* @param postViewQueriesOptions the {@link PostViewQueriesOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link ViewQueriesResult}
*/
public ServiceCall<ViewQueriesResult> postViewQueries(PostViewQueriesOptions postViewQueriesOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(postViewQueriesOptions, "postViewQueriesOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", postViewQueriesOptions.db());
pathParamsMap.put("ddoc", postViewQueriesOptions.ddoc());
pathParamsMap.put("view", postViewQueriesOptions.view());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_design/{ddoc}/_view/{view}/queries", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postViewQueries");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
final JsonObject contentJson = new JsonObject();
contentJson.add("queries", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postViewQueriesOptions.queries()));
builder.bodyJson(contentJson);
ResponseConverter<ViewQueriesResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<ViewQueriesResult>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.cloud.cloudant.v1.model.ViewQueriesResult in project cloudant-java-sdk by IBM.
the class CloudantTest method testPostViewQueriesWOptions.
@Test
public void testPostViewQueriesWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"results\": [{\"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 postViewQueriesPath = "/testString/_design/testString/_view/testString/queries";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the ViewQuery model
ViewQuery viewQueryModel = new ViewQuery.Builder().attEncodingInfo(false).attachments(false).conflicts(false).descending(false).includeDocs(true).inclusiveEnd(true).limit(Long.valueOf("5")).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("testString"))).reduce(true).stable(false).startkey("testString").startkeyDocid("testString").update("true").build();
// Construct an instance of the PostViewQueriesOptions model
PostViewQueriesOptions postViewQueriesOptionsModel = new PostViewQueriesOptions.Builder().db("testString").ddoc("testString").view("testString").queries(new java.util.ArrayList<ViewQuery>(java.util.Arrays.asList(viewQueryModel))).build();
// Invoke operation with valid options model (positive test)
Response<ViewQueriesResult> response = cloudantService.postViewQueries(postViewQueriesOptionsModel).execute();
assertNotNull(response);
ViewQueriesResult 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, postViewQueriesPath);
}
use of com.ibm.cloud.cloudant.v1.model.ViewQueriesResult in project cloudant-java-sdk by IBM.
the class ViewQueriesResultTest method testViewQueriesResult.
@Test
public void testViewQueriesResult() throws Throwable {
ViewQueriesResult viewQueriesResultModel = new ViewQueriesResult();
assertNull(viewQueriesResultModel.getResults());
}
Aggregations