Search in sources :

Example 21 with Cloudant

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

the class Cloudant method putReplicationDocument.

/**
 * Create or modify a replication using a replication document.
 *
 * Creates or modifies a document in the `_replicator` database to start a new replication or to edit an existing
 * replication.
 *
 * @param putReplicationDocumentOptions the {@link PutReplicationDocumentOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link DocumentResult}
 */
public ServiceCall<DocumentResult> putReplicationDocument(PutReplicationDocumentOptions putReplicationDocumentOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(putReplicationDocumentOptions, "putReplicationDocumentOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("doc_id", putReplicationDocumentOptions.docId());
    RequestBuilder builder = RequestBuilder.put(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_replicator/{doc_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "putReplicationDocument");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    if (putReplicationDocumentOptions.ifMatch() != null) {
        builder.header("If-Match", putReplicationDocumentOptions.ifMatch());
    }
    if (putReplicationDocumentOptions.batch() != null) {
        builder.query("batch", String.valueOf(putReplicationDocumentOptions.batch()));
    }
    if (putReplicationDocumentOptions.newEdits() != null) {
        builder.query("new_edits", String.valueOf(putReplicationDocumentOptions.newEdits()));
    }
    if (putReplicationDocumentOptions.rev() != null) {
        builder.query("rev", String.valueOf(putReplicationDocumentOptions.rev()));
    }
    builder.bodyContent(com.ibm.cloud.sdk.core.util.GsonSingleton.getGsonWithoutPrettyPrinting().toJson(putReplicationDocumentOptions.replicationDocument()), "application/json");
    ResponseConverter<DocumentResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<DocumentResult>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) DocumentResult(com.ibm.cloud.cloudant.v1.model.DocumentResult)

Example 22 with Cloudant

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

the class Cloudant method getActivityTrackerEvents.

/**
 * Retrieve Activity Tracker events information.
 *
 * Check event types that are being sent to IBM Cloud Activity Tracker for the IBM Cloudant instance.
 *
 * @param getActivityTrackerEventsOptions the {@link GetActivityTrackerEventsOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link ActivityTrackerEvents}
 */
public ServiceCall<ActivityTrackerEvents> getActivityTrackerEvents(GetActivityTrackerEventsOptions getActivityTrackerEventsOptions) {
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_api/v2/user/activity_tracker/events"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getActivityTrackerEvents");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    ResponseConverter<ActivityTrackerEvents> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<ActivityTrackerEvents>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : ActivityTrackerEvents(com.ibm.cloud.cloudant.v1.model.ActivityTrackerEvents) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder)

Example 23 with Cloudant

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

the class Cloudant method postDocument.

/**
 * Create or modify a document in a database.
 *
 * Creates or modifies a document in the specified database by using the supplied JSON document. If the JSON document
 * doesn't specify an `_id` field, then the document is created with a new unique ID generated by the UUID algorithm
 * that is configured for the server. If the document includes the `_id` field, then it is created with that `_id` or
 * updated if the `_id` already exists, and an appropriate `_rev` is included in the JSON document. If the `_id`
 * includes the `_local` or `_design` prefix, then this operation is used to create or modify local or design
 * documents respectively.
 *
 * @param postDocumentOptions the {@link PostDocumentOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link DocumentResult}
 */
public ServiceCall<DocumentResult> postDocument(PostDocumentOptions postDocumentOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(postDocumentOptions, "postDocumentOptions cannot be null");
    if (postDocumentOptions.document() != null && postDocumentOptions.contentType() == null) {
        postDocumentOptions = postDocumentOptions.newBuilder().contentType("application/json").build();
    }
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", postDocumentOptions.db());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postDocument");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    if (postDocumentOptions.contentType() != null) {
        builder.header("Content-Type", postDocumentOptions.contentType());
    }
    if (postDocumentOptions.batch() != null) {
        builder.query("batch", String.valueOf(postDocumentOptions.batch()));
    }
    builder.bodyContent(postDocumentOptions.contentType(), postDocumentOptions.document(), null, postDocumentOptions.body());
    ResponseConverter<DocumentResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<DocumentResult>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) DocumentResult(com.ibm.cloud.cloudant.v1.model.DocumentResult)

Example 24 with Cloudant

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

the class Cloudant method deleteDocument.

/**
 * Delete a document.
 *
 * Marks the specified document as deleted by adding a `_deleted` field with the value `true`. Documents with this
 * field are not returned within requests anymore but stay in the database. You must supply the current (latest)
 * revision, either by using the `rev` parameter or by using the `If-Match` header to specify the revision.
 *
 * @param deleteDocumentOptions the {@link DeleteDocumentOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link DocumentResult}
 */
public ServiceCall<DocumentResult> deleteDocument(DeleteDocumentOptions deleteDocumentOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(deleteDocumentOptions, "deleteDocumentOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", deleteDocumentOptions.db());
    pathParamsMap.put("doc_id", deleteDocumentOptions.docId());
    RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/{doc_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "deleteDocument");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    if (deleteDocumentOptions.ifMatch() != null) {
        builder.header("If-Match", deleteDocumentOptions.ifMatch());
    }
    if (deleteDocumentOptions.batch() != null) {
        builder.query("batch", String.valueOf(deleteDocumentOptions.batch()));
    }
    if (deleteDocumentOptions.rev() != null) {
        builder.query("rev", String.valueOf(deleteDocumentOptions.rev()));
    }
    ResponseConverter<DocumentResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<DocumentResult>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) DocumentResult(com.ibm.cloud.cloudant.v1.model.DocumentResult)

Example 25 with Cloudant

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

the class Cloudant method getSessionInformation.

/**
 * Retrieve current session cookie information.
 *
 * Retrieves information about the authenticated user's session.
 *
 * @param getSessionInformationOptions the {@link GetSessionInformationOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link SessionInformation}
 */
public ServiceCall<SessionInformation> getSessionInformation(GetSessionInformationOptions getSessionInformationOptions) {
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_session"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getSessionInformation");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    ResponseConverter<SessionInformation> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<SessionInformation>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : SessionInformation(com.ibm.cloud.cloudant.v1.model.SessionInformation) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder)

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