Search in sources :

Example 1 with UpdateObjectMetadataOptions

use of com.ibm.watson.visual_recognition.v4.model.UpdateObjectMetadataOptions in project java-sdk by watson-developer-cloud.

the class VisualRecognition method updateObjectMetadata.

/**
 * Update an object name.
 *
 * <p>Update the name of an object. A successful request updates the training data for all images
 * that use the object.
 *
 * @param updateObjectMetadataOptions the {@link UpdateObjectMetadataOptions} containing the
 *     options for the call
 * @return a {@link ServiceCall} with a result of type {@link UpdateObjectMetadata}
 */
public ServiceCall<UpdateObjectMetadata> updateObjectMetadata(UpdateObjectMetadataOptions updateObjectMetadataOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(updateObjectMetadataOptions, "updateObjectMetadataOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("collection_id", updateObjectMetadataOptions.collectionId());
    pathParamsMap.put("object", updateObjectMetadataOptions.object());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v4/collections/{collection_id}/objects/{object}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("watson_vision_combined", "v4", "updateObjectMetadata");
    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();
    contentJson.addProperty("object", updateObjectMetadataOptions.newObject());
    builder.bodyJson(contentJson);
    ResponseConverter<UpdateObjectMetadata> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<UpdateObjectMetadata>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) UpdateObjectMetadata(com.ibm.watson.visual_recognition.v4.model.UpdateObjectMetadata)

Example 2 with UpdateObjectMetadataOptions

use of com.ibm.watson.visual_recognition.v4.model.UpdateObjectMetadataOptions in project java-sdk by watson-developer-cloud.

the class VisualRecognitionTest method testUpdateObjectMetadataWOptions.

@Test
public void testUpdateObjectMetadataWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"object\": \"object\", \"count\": 5}";
    String updateObjectMetadataPath = "/v4/collections/testString/objects/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the UpdateObjectMetadataOptions model
    UpdateObjectMetadataOptions updateObjectMetadataOptionsModel = new UpdateObjectMetadataOptions.Builder().collectionId("testString").object("testString").newObject("testString").build();
    // Invoke operation with valid options model (positive test)
    Response<UpdateObjectMetadata> response = visualRecognitionService.updateObjectMetadata(updateObjectMetadataOptionsModel).execute();
    assertNotNull(response);
    UpdateObjectMetadata 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, updateObjectMetadataPath);
}
Also used : UpdateObjectMetadataOptions(com.ibm.watson.visual_recognition.v4.model.UpdateObjectMetadataOptions) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) UpdateObjectMetadata(com.ibm.watson.visual_recognition.v4.model.UpdateObjectMetadata) Test(org.testng.annotations.Test)

Aggregations

UpdateObjectMetadata (com.ibm.watson.visual_recognition.v4.model.UpdateObjectMetadata)2 JsonObject (com.google.gson.JsonObject)1 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 UpdateObjectMetadataOptions (com.ibm.watson.visual_recognition.v4.model.UpdateObjectMetadataOptions)1 HashMap (java.util.HashMap)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 Test (org.testng.annotations.Test)1