use of com.ibm.watson.developer_cloud.http.RequestBuilder in project java-sdk by watson-developer-cloud.
the class Discovery method deleteEnvironment.
/**
* Delete environment.
*
* @param deleteEnvironmentOptions the {@link DeleteEnvironmentOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of Void
*/
public ServiceCall<Void> deleteEnvironment(DeleteEnvironmentOptions deleteEnvironmentOptions) {
Validator.notNull(deleteEnvironmentOptions, "deleteEnvironmentOptions cannot be null");
String[] pathSegments = { "v1/environments" };
String[] pathParameters = { deleteEnvironmentOptions.environmentId() };
RequestBuilder builder = RequestBuilder.delete(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
return createServiceCall(builder.build(), ResponseConverterUtils.getVoid());
}
use of com.ibm.watson.developer_cloud.http.RequestBuilder in project java-sdk by watson-developer-cloud.
the class Discovery method deleteDocument.
/**
* Delete a document.
*
* 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 response type of Void
*/
public ServiceCall<Void> deleteDocument(DeleteDocumentOptions deleteDocumentOptions) {
Validator.notNull(deleteDocumentOptions, "deleteDocumentOptions cannot be null");
String[] pathSegments = { "v1/environments", "collections", "documents" };
String[] pathParameters = { deleteDocumentOptions.environmentId(), deleteDocumentOptions.collectionId(), deleteDocumentOptions.documentId() };
RequestBuilder builder = RequestBuilder.delete(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
return createServiceCall(builder.build(), ResponseConverterUtils.getVoid());
}
use of com.ibm.watson.developer_cloud.http.RequestBuilder in project java-sdk by watson-developer-cloud.
the class Discovery method updateTrainingExample.
/**
* Changes the label or cross reference query for this training example.
*
* @param updateTrainingExampleOptions the {@link UpdateTrainingExampleOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link TrainingExample}
*/
public ServiceCall<TrainingExample> updateTrainingExample(UpdateTrainingExampleOptions updateTrainingExampleOptions) {
Validator.notNull(updateTrainingExampleOptions, "updateTrainingExampleOptions cannot be null");
String[] pathSegments = { "v1/environments", "collections", "training_data", "examples" };
String[] pathParameters = { updateTrainingExampleOptions.environmentId(), updateTrainingExampleOptions.collectionId(), updateTrainingExampleOptions.queryId(), updateTrainingExampleOptions.exampleId() };
RequestBuilder builder = RequestBuilder.put(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
final JsonObject contentJson = new JsonObject();
if (updateTrainingExampleOptions.crossReference() != null) {
contentJson.addProperty("cross_reference", updateTrainingExampleOptions.crossReference());
}
if (updateTrainingExampleOptions.relevance() != null) {
contentJson.addProperty("relevance", updateTrainingExampleOptions.relevance());
}
builder.bodyJson(contentJson);
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(TrainingExample.class));
}
use of com.ibm.watson.developer_cloud.http.RequestBuilder in project java-sdk by watson-developer-cloud.
the class Discovery method testConfigurationInEnvironment.
/**
* Test configuration.
*
* Runs a sample document through the default or your configuration and returns diagnostic information designed to
* help you understand how the document was processed. The document is not added to the index.
*
* @param testConfigurationInEnvironmentOptions the {@link TestConfigurationInEnvironmentOptions} containing the
* options for the call
* @return a {@link ServiceCall} with a response type of {@link TestDocument}
*/
public ServiceCall<TestDocument> testConfigurationInEnvironment(TestConfigurationInEnvironmentOptions testConfigurationInEnvironmentOptions) {
Validator.notNull(testConfigurationInEnvironmentOptions, "testConfigurationInEnvironmentOptions cannot be null");
Validator.isTrue((testConfigurationInEnvironmentOptions.configuration() != null) || (testConfigurationInEnvironmentOptions.file() != null) || (testConfigurationInEnvironmentOptions.metadata() != null), "At least one of configuration, file, or metadata must be supplied.");
String[] pathSegments = { "v1/environments", "preview" };
String[] pathParameters = { testConfigurationInEnvironmentOptions.environmentId() };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
if (testConfigurationInEnvironmentOptions.step() != null) {
builder.query("step", testConfigurationInEnvironmentOptions.step());
}
if (testConfigurationInEnvironmentOptions.configurationId() != null) {
builder.query("configuration_id", testConfigurationInEnvironmentOptions.configurationId());
}
MultipartBody.Builder multipartBuilder = new MultipartBody.Builder();
multipartBuilder.setType(MultipartBody.FORM);
if (testConfigurationInEnvironmentOptions.configuration() != null) {
multipartBuilder.addFormDataPart("configuration", testConfigurationInEnvironmentOptions.configuration());
}
if (testConfigurationInEnvironmentOptions.file() != null) {
RequestBody fileBody = RequestUtils.inputStreamBody(testConfigurationInEnvironmentOptions.file(), testConfigurationInEnvironmentOptions.fileContentType());
multipartBuilder.addFormDataPart("file", testConfigurationInEnvironmentOptions.filename(), fileBody);
}
if (testConfigurationInEnvironmentOptions.metadata() != null) {
multipartBuilder.addFormDataPart("metadata", testConfigurationInEnvironmentOptions.metadata());
}
builder.body(multipartBuilder.build());
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(TestDocument.class));
}
use of com.ibm.watson.developer_cloud.http.RequestBuilder in project java-sdk by watson-developer-cloud.
the class Discovery method updateCollection.
/**
* Update a collection.
*
* @param updateCollectionOptions the {@link UpdateCollectionOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link Collection}
*/
public ServiceCall<Collection> updateCollection(UpdateCollectionOptions updateCollectionOptions) {
Validator.notNull(updateCollectionOptions, "updateCollectionOptions cannot be null");
String[] pathSegments = { "v1/environments", "collections" };
String[] pathParameters = { updateCollectionOptions.environmentId(), updateCollectionOptions.collectionId() };
RequestBuilder builder = RequestBuilder.put(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
final JsonObject contentJson = new JsonObject();
if (updateCollectionOptions.name() != null) {
contentJson.addProperty("name", updateCollectionOptions.name());
}
if (updateCollectionOptions.description() != null) {
contentJson.addProperty("description", updateCollectionOptions.description());
}
if (updateCollectionOptions.configurationId() != null) {
contentJson.addProperty("configuration_id", updateCollectionOptions.configurationId());
}
builder.bodyJson(contentJson);
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Collection.class));
}
Aggregations