Search in sources :

Example 1 with DeleteDocumentResponse

use of com.ibm.watson.discovery.v2.model.DeleteDocumentResponse in project java-sdk by watson-developer-cloud.

the class DiscoveryServiceTest method deleteDocumentIsSuccessful.

/**
 * Delete document is successful.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void deleteDocumentIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(deleteDocResp));
    DeleteDocumentOptions deleteRequest = new DeleteDocumentOptions.Builder(environmentId, collectionId, documentId).build();
    DeleteDocumentResponse response = discoveryService.deleteDocument(deleteRequest).execute().getResult();
    RecordedRequest request = server.takeRequest();
    assertEquals(DOCS2_PATH, request.getPath());
    assertEquals(DELETE, request.getMethod());
    assertEquals(deleteDocResp.getDocumentId(), response.getDocumentId());
    assertEquals(deleteDocResp.getStatus(), response.getStatus());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) DeleteDocumentResponse(com.ibm.watson.discovery.v1.model.DeleteDocumentResponse) DeleteDocumentOptions(com.ibm.watson.discovery.v1.model.DeleteDocumentOptions) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Example 2 with DeleteDocumentResponse

use of com.ibm.watson.discovery.v2.model.DeleteDocumentResponse 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);
}
Also used : DeleteDocumentResponse(com.ibm.watson.discovery.v1.model.DeleteDocumentResponse) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap)

Example 3 with DeleteDocumentResponse

use of com.ibm.watson.discovery.v2.model.DeleteDocumentResponse 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'.
 *
 * <p>**Note:** This operation only works on collections created to accept direct file uploads. It
 * cannot be used to modify a collection that connects to an external source such as Microsoft
 * SharePoint.
 *
 * <p>**Note:** Segments of an uploaded document cannot be deleted individually. Delete all
 * segments by deleting using the `parent_document_id` of a segment result.
 *
 * @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("project_id", deleteDocumentOptions.projectId());
    pathParamsMap.put("collection_id", deleteDocumentOptions.collectionId());
    pathParamsMap.put("document_id", deleteDocumentOptions.documentId());
    RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/projects/{project_id}/collections/{collection_id}/documents/{document_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "deleteDocument");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    if (deleteDocumentOptions.xWatsonDiscoveryForce() != null) {
        builder.header("X-Watson-Discovery-Force", deleteDocumentOptions.xWatsonDiscoveryForce());
    }
    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);
}
Also used : DeleteDocumentResponse(com.ibm.watson.discovery.v2.model.DeleteDocumentResponse) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap)

Example 4 with DeleteDocumentResponse

use of com.ibm.watson.discovery.v2.model.DeleteDocumentResponse 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);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) DeleteDocumentResponse(com.ibm.watson.discovery.v2.model.DeleteDocumentResponse) DeleteDocumentOptions(com.ibm.watson.discovery.v2.model.DeleteDocumentOptions) Test(org.testng.annotations.Test)

Example 5 with DeleteDocumentResponse

use of com.ibm.watson.discovery.v2.model.DeleteDocumentResponse in project java-sdk by watson-developer-cloud.

the class DiscoveryTest method testDeleteDocumentWOptions.

// Test the deleteDocument operation with a valid options model parameter
@Test
public void testDeleteDocumentWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"document_id\": \"documentId\", \"status\": \"deleted\"}";
    String deleteDocumentPath = "/v1/environments/testString/collections/testString/documents/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the DeleteDocumentOptions model
    DeleteDocumentOptions deleteDocumentOptionsModel = new DeleteDocumentOptions.Builder().environmentId("testString").collectionId("testString").documentId("testString").build();
    // Invoke deleteDocument() with a valid options model and verify the result
    Response<DeleteDocumentResponse> response = discoveryService.deleteDocument(deleteDocumentOptionsModel).execute();
    assertNotNull(response);
    DeleteDocumentResponse responseObj = response.getResult();
    assertNotNull(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"), "testString");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) DeleteDocumentResponse(com.ibm.watson.discovery.v1.model.DeleteDocumentResponse) DeleteDocumentOptions(com.ibm.watson.discovery.v1.model.DeleteDocumentOptions) Test(org.testng.annotations.Test)

Aggregations

DeleteDocumentResponse (com.ibm.watson.discovery.v1.model.DeleteDocumentResponse)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)2 DeleteDocumentOptions (com.ibm.watson.discovery.v1.model.DeleteDocumentOptions)2 DeleteDocumentResponse (com.ibm.watson.discovery.v2.model.DeleteDocumentResponse)2 HashMap (java.util.HashMap)2 MockResponse (okhttp3.mockwebserver.MockResponse)2 Test (org.testng.annotations.Test)2 WatsonServiceUnitTest (com.ibm.watson.common.WatsonServiceUnitTest)1 DeleteDocumentOptions (com.ibm.watson.discovery.v2.model.DeleteDocumentOptions)1