use of com.ibm.watson.discovery.v1.model.DeleteDocumentOptions in project java-sdk by watson-developer-cloud.
the class Discovery method deleteDocument.
/**
* Delete a document.
*
* <p>If the given document ID is invalid, or if the document is not found, then the a success
* response is returned (HTTP status code `200`) with the status set to 'deleted'.
*
* @param deleteDocumentOptions the {@link DeleteDocumentOptions} containing the options for the
* call
* @return a {@link ServiceCall} with a result of type {@link DeleteDocumentResponse}
*/
public ServiceCall<DeleteDocumentResponse> 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("environment_id", deleteDocumentOptions.environmentId());
pathParamsMap.put("collection_id", deleteDocumentOptions.collectionId());
pathParamsMap.put("document_id", deleteDocumentOptions.documentId());
RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/collections/{collection_id}/documents/{document_id}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "deleteDocument");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
builder.query("version", String.valueOf(this.version));
ResponseConverter<DeleteDocumentResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<DeleteDocumentResponse>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.watson.discovery.v1.model.DeleteDocumentOptions in project knative-eventing-java-app by IBM.
the class CloudEventStoreCloudant method removeAllEvents.
@Override
public void removeAllEvents() throws Exception {
try {
PostAllDocsOptions docsOptions = new PostAllDocsOptions.Builder().db(this.dbName).includeDocs(true).build();
AllDocsResult allDocResults = this.client.postAllDocs(docsOptions).execute().getResult();
for (DocsResultRow docResult : allDocResults.getRows()) {
Document document = docResult.getDoc();
DeleteDocumentOptions deleteDocumentOptions = new DeleteDocumentOptions.Builder().db(this.dbName).docId(document.getId()).rev(document.getRev()).build();
DocumentResult deleteDocumentResponse = client.deleteDocument(deleteDocumentOptions).execute().getResult();
if (!deleteDocumentResponse.isOk()) {
logger.info("Could not delete a document.");
}
}
} catch (NotFoundException e) {
String errMsg = "Unable to retrieve all documents from Cloudant";
logger.error(errMsg, e);
throw new Exception(errMsg, e);
}
}
use of com.ibm.watson.discovery.v1.model.DeleteDocumentOptions in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method deleteDocumentIsSuccessful.
@Test
public void deleteDocumentIsSuccessful() {
Collection collection = createTestCollection();
String collectionId = collection.getCollectionId();
DocumentAccepted documentAccepted = createTestDocument("test_document", collectionId);
DeleteDocumentOptions deleteOptions = new DeleteDocumentOptions.Builder(environmentId, collectionId, documentAccepted.getDocumentId()).build();
discovery.deleteDocument(deleteOptions).execute();
}
use of com.ibm.watson.discovery.v1.model.DeleteDocumentOptions in project java-sdk by watson-developer-cloud.
the class DiscoveryTest method testDeleteDocumentWOptions.
@Test
public void testDeleteDocumentWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"document_id\": \"documentId\", \"status\": \"deleted\"}";
String deleteDocumentPath = "/v2/projects/testString/collections/testString/documents/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the DeleteDocumentOptions model
DeleteDocumentOptions deleteDocumentOptionsModel = new DeleteDocumentOptions.Builder().projectId("testString").collectionId("testString").documentId("testString").xWatsonDiscoveryForce(false).build();
// Invoke operation with valid options model (positive test)
Response<DeleteDocumentResponse> response = discoveryService.deleteDocument(deleteDocumentOptionsModel).execute();
assertNotNull(response);
DeleteDocumentResponse responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "DELETE");
// Check query
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
// Get query params
assertEquals(query.get("version"), "testString");
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, deleteDocumentPath);
}
use of com.ibm.watson.discovery.v1.model.DeleteDocumentOptions in project java-sdk by watson-developer-cloud.
the class LanguageTranslatorTest method testDeleteDocumentWOptions.
// Test the deleteDocument operation with a valid options model parameter
@Test
public void testDeleteDocumentWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "";
String deleteDocumentPath = "/v3/documents/testString";
server.enqueue(new MockResponse().setResponseCode(204).setBody(mockResponseBody));
// Construct an instance of the DeleteDocumentOptions model
DeleteDocumentOptions deleteDocumentOptionsModel = new DeleteDocumentOptions.Builder().documentId("testString").build();
// Invoke deleteDocument() with a valid options model and verify the result
Response<Void> response = languageTranslatorService.deleteDocument(deleteDocumentOptionsModel).execute();
assertNotNull(response);
Void responseObj = response.getResult();
assertNull(responseObj);
// Verify the contents of the request sent to the mock server
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "DELETE");
// Verify request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, deleteDocumentPath);
// Verify query params
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
assertEquals(query.get("version"), "2018-05-01");
}
Aggregations