use of com.ibm.watson.developer_cloud.discovery.v1.model.configuration.Configuration in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method createConfiguration.
private Configuration createConfiguration(CreateConfigurationOptions createOptions) {
Configuration createResponse = discovery.createConfiguration(createOptions).execute();
configurationIds.add(createResponse.getConfigurationId());
return createResponse;
}
use of com.ibm.watson.developer_cloud.discovery.v1.model.configuration.Configuration in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method updateDocumentIsSuccessful.
@Test
public void updateDocumentIsSuccessful() {
Collection collection = createTestCollection();
String collectionId = collection.getCollectionId();
DocumentAccepted documentAccepted = createTestDocument("test_document", collectionId);
uniqueName = UUID.randomUUID().toString();
Configuration testConfig = createTestConfig();
String myDocumentJson = "{\"field\":\"value2\"}";
InputStream documentStream = new ByteArrayInputStream(myDocumentJson.getBytes());
UpdateDocumentOptions.Builder updateBuilder = new UpdateDocumentOptions.Builder(environmentId, collectionId, documentAccepted.getDocumentId());
updateBuilder.file(documentStream).fileContentType(HttpMediaType.APPLICATION_JSON);
updateBuilder.filename("test_file");
// updateBuilder.configurationId(testConfig.getConfigurationId());
DocumentAccepted updateResponse = discovery.updateDocument(updateBuilder.build()).execute();
GetDocumentStatusOptions getOptions = new GetDocumentStatusOptions.Builder(environmentId, collectionId, updateResponse.getDocumentId()).build();
DocumentStatus getResponse = discovery.getDocumentStatus(getOptions).execute();
assertTrue(getResponse.getStatus().equals(DocumentStatus.Status.AVAILABLE) || getResponse.getStatus().equals(DocumentStatus.Status.PROCESSING));
}
use of com.ibm.watson.developer_cloud.discovery.v1.model.configuration.Configuration in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method deleteCollectionIsSuccessful.
@Test
public void deleteCollectionIsSuccessful() {
Configuration createConfigResponse = createTestConfig();
String uniqueCollectionName = uniqueName + "-collection";
CreateCollectionOptions.Builder createCollectionBuilder = new CreateCollectionOptions.Builder(environmentId, uniqueCollectionName).configurationId(createConfigResponse.getConfigurationId());
Collection createResponse = createCollection(createCollectionBuilder.build());
// need to wait for collection to be ready
DeleteCollectionOptions deleteOptions = new DeleteCollectionOptions.Builder(environmentId, createResponse.getCollectionId()).build();
deleteCollection(deleteOptions);
}
use of com.ibm.watson.developer_cloud.discovery.v1.model.configuration.Configuration in project java-sdk by watson-developer-cloud.
the class Discovery method getConfiguration.
/**
* Get configuration details.
*
* @param getConfigurationOptions the {@link GetConfigurationOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link Configuration}
*/
public ServiceCall<Configuration> getConfiguration(GetConfigurationOptions getConfigurationOptions) {
Validator.notNull(getConfigurationOptions, "getConfigurationOptions cannot be null");
String[] pathSegments = { "v1/environments", "configurations" };
String[] pathParameters = { getConfigurationOptions.environmentId(), getConfigurationOptions.configurationId() };
RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Configuration.class));
}
use of com.ibm.watson.developer_cloud.discovery.v1.model.configuration.Configuration 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));
}
Aggregations