Search in sources :

Example 56 with Cloudant

use of com.ibm.cloud.cloudant.v1.Cloudant in project cloudant-java-sdk by IBM.

the class Cloudant method getServerInformation.

/**
 * Retrieve server instance information.
 *
 * When you access the root of an instance, IBM Cloudant returns meta-information about the instance. The response
 * includes a JSON structure that contains information about the server, including a welcome message and the server's
 * version.
 *
 * @param getServerInformationOptions the {@link GetServerInformationOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link ServerInformation}
 */
public ServiceCall<ServerInformation> getServerInformation(GetServerInformationOptions getServerInformationOptions) {
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getServerInformation");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    ResponseConverter<ServerInformation> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<ServerInformation>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) ServerInformation(com.ibm.cloud.cloudant.v1.model.ServerInformation)

Example 57 with Cloudant

use of com.ibm.cloud.cloudant.v1.Cloudant 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);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) Ok(com.ibm.cloud.cloudant.v1.model.Ok)

Example 58 with Cloudant

use of com.ibm.cloud.cloudant.v1.Cloudant 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);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) Ok(com.ibm.cloud.cloudant.v1.model.Ok)

Example 59 with Cloudant

use of com.ibm.cloud.cloudant.v1.Cloudant in project cloudant-java-sdk by IBM.

the class Cloudant method getPartitionInformation.

/**
 * Retrieve information about a database partition.
 *
 * Given a partition key, return the database name, sizes, partition, doc count, and doc delete count.
 *
 * @param getPartitionInformationOptions the {@link GetPartitionInformationOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link PartitionInformation}
 */
public ServiceCall<PartitionInformation> getPartitionInformation(GetPartitionInformationOptions getPartitionInformationOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getPartitionInformationOptions, "getPartitionInformationOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", getPartitionInformationOptions.db());
    pathParamsMap.put("partition_key", getPartitionInformationOptions.partitionKey());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_partition/{partition_key}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getPartitionInformation");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    ResponseConverter<PartitionInformation> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<PartitionInformation>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) PartitionInformation(com.ibm.cloud.cloudant.v1.model.PartitionInformation)

Example 60 with Cloudant

use of com.ibm.cloud.cloudant.v1.Cloudant in project cloudant-java-sdk by IBM.

the class Cloudant method getLocalDocument.

/**
 * Retrieve a local document.
 *
 * Retrieves the specified local document. The semantics are identical to accessing a standard document in the
 * specified database, except that the document is not replicated.
 *
 * @param getLocalDocumentOptions the {@link GetLocalDocumentOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Document}
 */
public ServiceCall<Document> getLocalDocument(GetLocalDocumentOptions getLocalDocumentOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getLocalDocumentOptions, "getLocalDocumentOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", getLocalDocumentOptions.db());
    pathParamsMap.put("doc_id", getLocalDocumentOptions.docId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_local/{doc_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getLocalDocument");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    if (getLocalDocumentOptions.accept() != null) {
        builder.header("Accept", getLocalDocumentOptions.accept());
    }
    if (getLocalDocumentOptions.ifNoneMatch() != null) {
        builder.header("If-None-Match", getLocalDocumentOptions.ifNoneMatch());
    }
    if (getLocalDocumentOptions.attachments() != null) {
        builder.query("attachments", String.valueOf(getLocalDocumentOptions.attachments()));
    }
    if (getLocalDocumentOptions.attEncodingInfo() != null) {
        builder.query("att_encoding_info", String.valueOf(getLocalDocumentOptions.attEncodingInfo()));
    }
    if (getLocalDocumentOptions.localSeq() != null) {
        builder.query("local_seq", String.valueOf(getLocalDocumentOptions.localSeq()));
    }
    ResponseConverter<Document> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Document>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) ReplicationDocument(com.ibm.cloud.cloudant.v1.model.ReplicationDocument) DesignDocument(com.ibm.cloud.cloudant.v1.model.DesignDocument) Document(com.ibm.cloud.cloudant.v1.model.Document) SchedulerDocument(com.ibm.cloud.cloudant.v1.model.SchedulerDocument)

Aggregations

RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)70 HashMap (java.util.HashMap)51 JsonObject (com.google.gson.JsonObject)23 DocumentResult (com.ibm.cloud.cloudant.v1.model.DocumentResult)17 Ok (com.ibm.cloud.cloudant.v1.model.Ok)11 Document (com.ibm.cloud.cloudant.v1.model.Document)9 List (java.util.List)8 AllDocsResult (com.ibm.cloud.cloudant.v1.model.AllDocsResult)6 NotFoundException (com.ibm.cloud.sdk.core.service.exception.NotFoundException)6 ArrayList (java.util.ArrayList)6 Cloudant (com.ibm.cloud.cloudant.v1.Cloudant)5 SecurityObject (com.ibm.cloud.cloudant.v1.model.SecurityObject)5 Test (org.testng.annotations.Test)5 DesignDocument (com.ibm.cloud.cloudant.v1.model.DesignDocument)3 GetDocumentOptions (com.ibm.cloud.cloudant.v1.model.GetDocumentOptions)3 PostAllDocsOptions (com.ibm.cloud.cloudant.v1.model.PostAllDocsOptions)3 PostDocumentOptions (com.ibm.cloud.cloudant.v1.model.PostDocumentOptions)3 ReplicationDocument (com.ibm.cloud.cloudant.v1.model.ReplicationDocument)3 MockResponse (okhttp3.mockwebserver.MockResponse)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3