use of li.naska.bgg.resource.v3.model.Collection in project java-sdk by watson-developer-cloud.
the class VisualRecognition method train.
/**
* Train a collection.
*
* <p>Start training on images in a collection. The collection must have enough training data and
* untrained data (the **training_status.objects.data_changed** is `true`). If training is in
* progress, the request queues the next training job.
*
* @param trainOptions the {@link TrainOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link Collection}
*/
public ServiceCall<Collection> train(TrainOptions trainOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(trainOptions, "trainOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("collection_id", trainOptions.collectionId());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v4/collections/{collection_id}/train", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("watson_vision_combined", "v4", "train");
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<Collection> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Collection>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of li.naska.bgg.resource.v3.model.Collection in project java-sdk by watson-developer-cloud.
the class VisualRecognition method createCollection.
/**
* Create a collection.
*
* <p>Create a collection that can be used to store images.
*
* <p>To create a collection without specifying a name and description, include an empty JSON
* object in the request body.
*
* <p>Encode the name and description in UTF-8 if they contain non-ASCII characters. The service
* assumes UTF-8 encoding if it encounters non-ASCII characters.
*
* @param createCollectionOptions the {@link CreateCollectionOptions} containing the options for
* the call
* @return a {@link ServiceCall} with a result of type {@link Collection}
*/
public ServiceCall<Collection> createCollection(CreateCollectionOptions createCollectionOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(createCollectionOptions, "createCollectionOptions cannot be null");
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v4/collections"));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("watson_vision_combined", "v4", "createCollection");
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));
final JsonObject contentJson = new JsonObject();
if (createCollectionOptions.name() != null) {
contentJson.addProperty("name", createCollectionOptions.name());
}
if (createCollectionOptions.description() != null) {
contentJson.addProperty("description", createCollectionOptions.description());
}
builder.bodyJson(contentJson);
ResponseConverter<Collection> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Collection>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of li.naska.bgg.resource.v3.model.Collection in project java-sdk by watson-developer-cloud.
the class VisualRecognition method getCollection.
/**
* Get collection details.
*
* <p>Get details of one collection.
*
* @param getCollectionOptions the {@link GetCollectionOptions} containing the options for the
* call
* @return a {@link ServiceCall} with a result of type {@link Collection}
*/
public ServiceCall<Collection> getCollection(GetCollectionOptions getCollectionOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(getCollectionOptions, "getCollectionOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("collection_id", getCollectionOptions.collectionId());
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v4/collections/{collection_id}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("watson_vision_combined", "v4", "getCollection");
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<Collection> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Collection>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of li.naska.bgg.resource.v3.model.Collection in project java-sdk by watson-developer-cloud.
the class VisualRecognitionTest method testUpdateCollectionWOptions.
@Test
public void testUpdateCollectionWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"collection_id\": \"collectionId\", \"name\": \"name\", \"description\": \"description\", \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\", \"image_count\": 10, \"training_status\": {\"objects\": {\"ready\": false, \"in_progress\": true, \"data_changed\": false, \"latest_failed\": true, \"rscnn_ready\": true, \"description\": \"description\"}}}";
String updateCollectionPath = "/v4/collections/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the UpdateCollectionOptions model
UpdateCollectionOptions updateCollectionOptionsModel = new UpdateCollectionOptions.Builder().collectionId("testString").name("testString").description("testString").build();
// Invoke operation with valid options model (positive test)
Response<Collection> response = visualRecognitionService.updateCollection(updateCollectionOptionsModel).execute();
assertNotNull(response);
Collection responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "POST");
// 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, updateCollectionPath);
}
use of li.naska.bgg.resource.v3.model.Collection in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceTest method getCollectionIsSuccessful.
/**
* Gets the collection is successful.
*
* @throws InterruptedException the interrupted exception
*/
@Test
public void getCollectionIsSuccessful() throws InterruptedException {
server.enqueue(jsonResponse(getCollResp));
GetCollectionOptions getRequest = new GetCollectionOptions.Builder(environmentId, collectionId).build();
Collection response = discoveryService.getCollection(getRequest).execute().getResult();
RecordedRequest request = server.takeRequest();
assertEquals(COLL2_PATH, request.getPath());
assertEquals(GET, request.getMethod());
assertEquals(getCollResp, response);
}
Aggregations