Search in sources :

Example 1 with UpdateDocumentOptions

use of com.ibm.watson.developer_cloud.discovery.v1.model.UpdateDocumentOptions in project java-sdk by watson-developer-cloud.

the class DiscoveryServiceTest method updateDocumentWithoutRequiredParametersFails.

@Test(expected = IllegalArgumentException.class)
public void updateDocumentWithoutRequiredParametersFails() {
    UpdateDocumentOptions options = new UpdateDocumentOptions.Builder(environmentId, collectionId, documentId).build();
    DocumentAccepted response = discoveryService.updateDocument(options).execute();
}
Also used : UpdateDocumentOptions(com.ibm.watson.developer_cloud.discovery.v1.model.UpdateDocumentOptions) DocumentAccepted(com.ibm.watson.developer_cloud.discovery.v1.model.DocumentAccepted) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 2 with UpdateDocumentOptions

use of com.ibm.watson.developer_cloud.discovery.v1.model.UpdateDocumentOptions in project java-sdk by watson-developer-cloud.

the class Discovery method updateDocument.

/**
 * Update a document.
 *
 * Replace an existing document. Starts ingesting a document with optional metadata.
 *
 * @param updateDocumentOptions the {@link UpdateDocumentOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link DocumentAccepted}
 */
public ServiceCall<DocumentAccepted> updateDocument(UpdateDocumentOptions updateDocumentOptions) {
    Validator.notNull(updateDocumentOptions, "updateDocumentOptions cannot be null");
    Validator.isTrue((updateDocumentOptions.file() != null) || (updateDocumentOptions.metadata() != null), "At least one of file or metadata must be supplied.");
    String[] pathSegments = { "v1/environments", "collections", "documents" };
    String[] pathParameters = { updateDocumentOptions.environmentId(), updateDocumentOptions.collectionId(), updateDocumentOptions.documentId() };
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    MultipartBody.Builder multipartBuilder = new MultipartBody.Builder();
    multipartBuilder.setType(MultipartBody.FORM);
    if (updateDocumentOptions.file() != null) {
        RequestBody fileBody = RequestUtils.inputStreamBody(updateDocumentOptions.file(), updateDocumentOptions.fileContentType());
        multipartBuilder.addFormDataPart("file", updateDocumentOptions.filename(), fileBody);
    }
    if (updateDocumentOptions.metadata() != null) {
        multipartBuilder.addFormDataPart("metadata", updateDocumentOptions.metadata());
    }
    builder.body(multipartBuilder.build());
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(DocumentAccepted.class));
}
Also used : DocumentAccepted(com.ibm.watson.developer_cloud.discovery.v1.model.DocumentAccepted) RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) MultipartBody(okhttp3.MultipartBody) RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) RequestBody(okhttp3.RequestBody)

Aggregations

DocumentAccepted (com.ibm.watson.developer_cloud.discovery.v1.model.DocumentAccepted)2 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)1 UpdateDocumentOptions (com.ibm.watson.developer_cloud.discovery.v1.model.UpdateDocumentOptions)1 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)1 MultipartBody (okhttp3.MultipartBody)1 RequestBody (okhttp3.RequestBody)1 Test (org.junit.Test)1