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();
}
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));
}
Aggregations