Search in sources :

Example 11 with DeleteDocumentOptions

use of com.ibm.watson.language_translator.v3.model.DeleteDocumentOptions in project cloudant-java-sdk by IBM.

the class DeleteDoc method main.

public static void main(String[] args) {
    // 1. Create a client with `CLOUDANT` default service name ============
    Cloudant client = Cloudant.newInstance();
    // 2. Delete the document =============================================
    // Set the options to get the document out of the database if it exists
    String exampleDbName = "orders";
    String exampleDocId = "example";
    GetDocumentOptions documentInfoOptions = new GetDocumentOptions.Builder().db(exampleDbName).docId(exampleDocId).build();
    try {
        // Try to get the document if it previously existed in the database
        Document document = client.getDocument(documentInfoOptions).execute().getResult();
        // Delete the document from the database
        DeleteDocumentOptions deleteDocumentOptions = new DeleteDocumentOptions.Builder().db(exampleDbName).docId(// docId is required for DELETE
        exampleDocId).rev(// rev is required for DELETE
        document.getRev()).build();
        DocumentResult deleteDocumentResponse = client.deleteDocument(deleteDocumentOptions).execute().getResult();
        if (deleteDocumentResponse.isOk()) {
            System.out.println("You have deleted the document.");
        }
    } catch (NotFoundException nfe) {
        System.out.println("Cannot delete document because " + "either \"orders\" database or the \"example\" " + "document was not found.");
    }
}
Also used : DocumentResult(com.ibm.cloud.cloudant.v1.model.DocumentResult) GetDocumentOptions(com.ibm.cloud.cloudant.v1.model.GetDocumentOptions) NotFoundException(com.ibm.cloud.sdk.core.service.exception.NotFoundException) Cloudant(com.ibm.cloud.cloudant.v1.Cloudant) Document(com.ibm.cloud.cloudant.v1.model.Document) DeleteDocumentOptions(com.ibm.cloud.cloudant.v1.model.DeleteDocumentOptions)

Aggregations

RecordedRequest (okhttp3.mockwebserver.RecordedRequest)6 Test (org.testng.annotations.Test)5 DeleteDocumentOptions (com.ibm.cloud.cloudant.v1.model.DeleteDocumentOptions)4 MockResponse (okhttp3.mockwebserver.MockResponse)4 DocumentResult (com.ibm.cloud.cloudant.v1.model.DocumentResult)3 Document (com.ibm.cloud.cloudant.v1.model.Document)2 NotFoundException (com.ibm.cloud.sdk.core.service.exception.NotFoundException)2 DeleteDocumentOptions (com.ibm.watson.developer_cloud.discovery.v1.model.DeleteDocumentOptions)2 DeleteDocumentOptions (com.ibm.watson.discovery.v1.model.DeleteDocumentOptions)2 DeleteDocumentResponse (com.ibm.watson.discovery.v1.model.DeleteDocumentResponse)2 DeleteDocumentOptions (com.ibm.watson.discovery.v2.model.DeleteDocumentOptions)2 Test (org.junit.Test)2 GsonBuilder (com.google.gson.GsonBuilder)1 Cloudant (com.ibm.cloud.cloudant.v1.Cloudant)1 AllDocsResult (com.ibm.cloud.cloudant.v1.model.AllDocsResult)1 DocsResultRow (com.ibm.cloud.cloudant.v1.model.DocsResultRow)1 GetDocumentOptions (com.ibm.cloud.cloudant.v1.model.GetDocumentOptions)1 PostAllDocsOptions (com.ibm.cloud.cloudant.v1.model.PostAllDocsOptions)1 Authenticator (com.ibm.cloud.sdk.core.security.Authenticator)1 BearerTokenAuthenticator (com.ibm.cloud.sdk.core.security.BearerTokenAuthenticator)1