use of com.ibm.cloud.cloudant.v1.model.Ok in project cloudant-java-sdk by IBM.
the class CloudantTest method testGetGeoWOptions.
@Test
public void testGetGeoWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"bookmark\": \"bookmark\", \"features\": [{\"_id\": \"id\", \"_rev\": \"rev\", \"bbox\": [4], \"geometry\": {\"type\": \"Point\", \"coordinates\": [\"anyValue\"]}, \"properties\": {\"mapKey\": \"anyValue\"}, \"type\": \"Feature\"}], \"rows\": [{\"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\"}]}, \"geometry\": {\"type\": \"Point\", \"coordinates\": [\"anyValue\"]}, \"id\": \"id\", \"rev\": \"rev\"}], \"type\": \"FeatureCollection\"}";
String getGeoPath = "/testString/_design/testString/_geo/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the GetGeoOptions model
GetGeoOptions getGeoOptionsModel = new GetGeoOptions.Builder().db("testString").ddoc("testString").index("testString").bbox("testString").bookmark("testString").format("view").g("testString").includeDocs(false).lat(Double.valueOf("-90")).limit(Long.valueOf("0")).lon(Double.valueOf("-180")).nearest(false).radius(Double.valueOf("0")).rangex(Double.valueOf("0")).rangey(Double.valueOf("0")).relation("intersects").skip(Long.valueOf("0")).stale("ok").build();
// Invoke operation with valid options model (positive test)
Response<GeoResult> response = cloudantService.getGeo(getGeoOptionsModel).execute();
assertNotNull(response);
GeoResult responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "GET");
// Check query
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
// Get query params
assertEquals(query.get("bbox"), "testString");
assertEquals(query.get("bookmark"), "testString");
assertEquals(query.get("format"), "view");
assertEquals(query.get("g"), "testString");
assertEquals(Boolean.valueOf(query.get("include_docs")), Boolean.valueOf(false));
assertEquals(Double.valueOf(query.get("lat")), Double.valueOf("-90"));
assertEquals(Long.valueOf(query.get("limit")), Long.valueOf("0"));
assertEquals(Double.valueOf(query.get("lon")), Double.valueOf("-180"));
assertEquals(Boolean.valueOf(query.get("nearest")), Boolean.valueOf(false));
assertEquals(Double.valueOf(query.get("radius")), Double.valueOf("0"));
assertEquals(Double.valueOf(query.get("rangex")), Double.valueOf("0"));
assertEquals(Double.valueOf(query.get("rangey")), Double.valueOf("0"));
assertEquals(query.get("relation"), "intersects");
assertEquals(Long.valueOf(query.get("skip")), Long.valueOf("0"));
assertEquals(query.get("stale"), "ok");
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, getGeoPath);
}
use of com.ibm.cloud.cloudant.v1.model.Ok in project cloudant-java-sdk by IBM.
the class Cloudant method putSecurity.
/**
* Modify database permissions.
*
* Modify who has permission to read, write, or manage a database. This endpoint can be used to modify both Cloudant
* and CouchDB related permissions. Be careful: by removing a Cloudant API key, a member or an admin from the list of
* users that have access permissions, you remove it from the list of users that have access to the database.
*
* ### Note about nobody role
*
* The `nobody` username applies to all unauthenticated connection attempts. For example, if an application tries to
* read data from a database, but did not identify itself, the task can continue only if the `nobody` user has the
* role `_reader`.
*
* @param putSecurityOptions the {@link PutSecurityOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link Ok}
*/
public ServiceCall<Ok> putSecurity(PutSecurityOptions putSecurityOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(putSecurityOptions, "putSecurityOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", putSecurityOptions.db());
RequestBuilder builder = RequestBuilder.put(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_security", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "putSecurity");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
final JsonObject contentJson = new JsonObject();
if (putSecurityOptions.admins() != null) {
contentJson.add("admins", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(putSecurityOptions.admins()));
}
if (putSecurityOptions.members() != null) {
contentJson.add("members", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(putSecurityOptions.members()));
}
if (putSecurityOptions.cloudant() != null) {
contentJson.add("cloudant", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(putSecurityOptions.cloudant()));
}
if (putSecurityOptions.couchdbAuthOnly() != null) {
contentJson.addProperty("couchdb_auth_only", putSecurityOptions.couchdbAuthOnly());
}
builder.bodyJson(contentJson);
ResponseConverter<Ok> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Ok>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.cloud.cloudant.v1.model.Ok in project cloudant-java-sdk by IBM.
the class Cloudant method putCloudantSecurityConfiguration.
/**
* Modify only Cloudant related database permissions.
*
* Modify only Cloudant related permissions to database. Be careful: by removing an API key from the list, you remove
* the API key from the list of users that have access to the database.
*
* ### Note about nobody role
*
* The `nobody` username applies to all unauthenticated connection attempts. For example, if an application tries to
* read data from a database, but did not identify itself, the task can continue only if the `nobody` user has the
* role `_reader`.
*
* @param putCloudantSecurityConfigurationOptions the {@link PutCloudantSecurityConfigurationOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link Ok}
*/
public ServiceCall<Ok> putCloudantSecurityConfiguration(PutCloudantSecurityConfigurationOptions putCloudantSecurityConfigurationOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(putCloudantSecurityConfigurationOptions, "putCloudantSecurityConfigurationOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", putCloudantSecurityConfigurationOptions.db());
RequestBuilder builder = RequestBuilder.put(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_api/v2/db/{db}/_security", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "putCloudantSecurityConfiguration");
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("cloudant", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(putCloudantSecurityConfigurationOptions.cloudant()));
if (putCloudantSecurityConfigurationOptions.admins() != null) {
contentJson.add("admins", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(putCloudantSecurityConfigurationOptions.admins()));
}
if (putCloudantSecurityConfigurationOptions.members() != null) {
contentJson.add("members", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(putCloudantSecurityConfigurationOptions.members()));
}
if (putCloudantSecurityConfigurationOptions.couchdbAuthOnly() != null) {
contentJson.addProperty("couchdb_auth_only", putCloudantSecurityConfigurationOptions.couchdbAuthOnly());
}
builder.bodyJson(contentJson);
ResponseConverter<Ok> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Ok>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.cloud.cloudant.v1.model.Ok in project cloudant-java-sdk by IBM.
the class Cloudant method postGeoCleanup.
/**
* Cleanup old geospatial indexes.
*
* Cleanup old geospatial indexes from disk that have been superseded by newer index builds.
*
* @param postGeoCleanupOptions the {@link PostGeoCleanupOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link Ok}
*/
public ServiceCall<Ok> postGeoCleanup(PostGeoCleanupOptions postGeoCleanupOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(postGeoCleanupOptions, "postGeoCleanupOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", postGeoCleanupOptions.db());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_geo_cleanup", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postGeoCleanup");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
ResponseConverter<Ok> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Ok>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.cloud.cloudant.v1.model.Ok in project cloudant-java-sdk by IBM.
the class Cloudant method deleteDatabase.
/**
* Delete a database.
*
* Deletes the specified database and all documents and attachments contained within it. To avoid deleting a database,
* the server responds with a 400 HTTP status code when the request URL includes a `?rev=` parameter. This response
* suggests that a user wanted to delete a document but forgot to add the document ID to the URL.
*
* @param deleteDatabaseOptions the {@link DeleteDatabaseOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link Ok}
*/
public ServiceCall<Ok> deleteDatabase(DeleteDatabaseOptions deleteDatabaseOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(deleteDatabaseOptions, "deleteDatabaseOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", deleteDatabaseOptions.db());
RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "deleteDatabase");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
ResponseConverter<Ok> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Ok>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
Aggregations