Skip to content

Codegen/visual recognition #886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,13 @@ protected void setAuthentication(okhttp3.Request.Builder builder) {
*/
public ServiceCall<ClassifiedImages> classify(ClassifyOptions classifyOptions) {
Validator.notNull(classifyOptions, "classifyOptions cannot be null");
Validator.isTrue((classifyOptions.imagesFile() != null) || (classifyOptions.url() != null) || (classifyOptions
.threshold() != null) || (classifyOptions.owners() != null) || (classifyOptions.classifierIds() != null),
"At least one of imagesFile, url, threshold, owners, or classifierIds must be supplied.");
Validator.isTrue((classifyOptions.imagesFile() != null)
|| (classifyOptions.url() != null)
|| (classifyOptions.threshold() != null)
|| (classifyOptions.owners() != null)
|| (classifyOptions.classifierIds() != null)
|| (classifyOptions.parameters() != null),
"At least one of imagesFile, url, threshold, owners, classifierIds, or parameters must be supplied.");
RequestBuilder builder = RequestBuilder.post("/v3/classify");
builder.query(VERSION, versionDate);
if (classifyOptions.acceptLanguage() != null) {
Expand All @@ -131,6 +135,9 @@ public ServiceCall<ClassifiedImages> classify(ClassifyOptions classifyOptions) {
.imagesFileContentType());
multipartBuilder.addFormDataPart("images_file", classifyOptions.imagesFilename(), imagesFileBody);
}
if (classifyOptions.parameters() != null) {
multipartBuilder.addFormDataPart("parameters", classifyOptions.parameters());
}
if (classifyOptions.url() != null) {
multipartBuilder.addFormDataPart("url", classifyOptions.url());
}
Expand Down Expand Up @@ -170,8 +177,10 @@ public ServiceCall<ClassifiedImages> classify() {
*/
public ServiceCall<DetectedFaces> detectFaces(DetectFacesOptions detectFacesOptions) {
Validator.notNull(detectFacesOptions, "detectFacesOptions cannot be null");
Validator.isTrue((detectFacesOptions.imagesFile() != null) || (detectFacesOptions.url() != null),
"At least one of imagesFile or url must be supplied.");
Validator.isTrue((detectFacesOptions.imagesFile() != null)
|| (detectFacesOptions.url() != null)
|| (detectFacesOptions.parameters() != null),
"At least one of imagesFile, url, or parameters must be supplied.");
RequestBuilder builder = RequestBuilder.post("/v3/detect_faces");
builder.query(VERSION, versionDate);
MultipartBody.Builder multipartBuilder = new MultipartBody.Builder();
Expand All @@ -181,6 +190,9 @@ public ServiceCall<DetectedFaces> detectFaces(DetectFacesOptions detectFacesOpti
.imagesFileContentType());
multipartBuilder.addFormDataPart("images_file", detectFacesOptions.imagesFilename(), imagesFileBody);
}
if (detectFacesOptions.parameters() != null) {
multipartBuilder.addFormDataPart("parameters", detectFacesOptions.parameters());
}
if (detectFacesOptions.url() != null) {
multipartBuilder.addFormDataPart("url", detectFacesOptions.url());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
*/
package com.ibm.watson.developer_cloud.visual_recognition.v3.model;

import com.ibm.watson.developer_cloud.service.model.GenericModel;
import com.ibm.watson.developer_cloud.util.Validator;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import com.ibm.watson.developer_cloud.service.model.GenericModel;
import com.ibm.watson.developer_cloud.util.Validator;

/**
* The classify options.
*/
Expand Down Expand Up @@ -59,6 +59,8 @@ public interface AcceptLanguage {
private List<String> owners;
private List<String> classifierIds;
private String imagesFileContentType;
@Deprecated
private String parameters;

/**
* Builder.
Expand All @@ -72,6 +74,8 @@ public static class Builder {
private List<String> owners;
private List<String> classifierIds;
private String imagesFileContentType;
@Deprecated
private String parameters;

private Builder(ClassifyOptions classifyOptions) {
imagesFile = classifyOptions.imagesFile;
Expand All @@ -82,6 +86,7 @@ private Builder(ClassifyOptions classifyOptions) {
owners = classifyOptions.owners;
classifierIds = classifyOptions.classifierIds;
imagesFileContentType = classifyOptions.imagesFileContentType;
parameters = classifyOptions.parameters;
}

/**
Expand Down Expand Up @@ -232,6 +237,18 @@ public Builder imagesFile(File imagesFile) throws FileNotFoundException {
this.imagesFilename = imagesFile.getName();
return this;
}

/**
* Set the parameters.
*
* @param parameters the parameters
* @return the ClassifyOptions builder
* @deprecated replaced by the top-level parameters url, threshold, owners, and classifierIds
*/
public Builder parameters(String parameters) {
this.parameters = parameters;
return this;
}
}

private ClassifyOptions(Builder builder) {
Expand All @@ -243,6 +260,7 @@ private ClassifyOptions(Builder builder) {
owners = builder.owners;
classifierIds = builder.classifierIds;
imagesFileContentType = builder.imagesFileContentType;
parameters = builder.parameters;
}

/**
Expand Down Expand Up @@ -362,4 +380,14 @@ public List<String> classifierIds() {
public String imagesFileContentType() {
return imagesFileContentType;
}

/**
* Gets the parameters.
*
* @return the parameters
* @deprecated replaced by the top-level parameters url, threshold, owners, and classifierIds
*/
public String parameters() {
return parameters;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
*/
package com.ibm.watson.developer_cloud.visual_recognition.v3.model;

import com.ibm.watson.developer_cloud.service.model.GenericModel;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

import com.ibm.watson.developer_cloud.service.model.GenericModel;

/**
* The detectFaces options.
*/
Expand All @@ -28,6 +28,8 @@ public class DetectFacesOptions extends GenericModel {
private String imagesFilename;
private String url;
private String imagesFileContentType;
@Deprecated
private String parameters;

/**
* Builder.
Expand All @@ -37,12 +39,15 @@ public static class Builder {
private String imagesFilename;
private String url;
private String imagesFileContentType;
@Deprecated
private String parameters;

private Builder(DetectFacesOptions detectFacesOptions) {
imagesFile = detectFacesOptions.imagesFile;
imagesFilename = detectFacesOptions.imagesFilename;
url = detectFacesOptions.url;
imagesFileContentType = detectFacesOptions.imagesFileContentType;
parameters = detectFacesOptions.parameters;
}

/**
Expand Down Expand Up @@ -117,13 +122,26 @@ public Builder imagesFile(File imagesFile) throws FileNotFoundException {
this.imagesFilename = imagesFile.getName();
return this;
}

/**
* Set the parameters.
*
* @param parameters the parameters
* @return the DetectFacesOptions builder
* @deprecated replaced by the url parameter
*/
public Builder parameters(String parameters) {
this.parameters = parameters;
return this;
}
}

private DetectFacesOptions(Builder builder) {
imagesFile = builder.imagesFile;
imagesFilename = builder.imagesFilename;
url = builder.url;
imagesFileContentType = builder.imagesFileContentType;
parameters = builder.parameters;
}

/**
Expand Down Expand Up @@ -180,4 +198,14 @@ public String url() {
public String imagesFileContentType() {
return imagesFileContentType;
}

/**
* Gets the parameters.
*
* @return the parameters
* @deprecated replaced by the url parameter
*/
public String parameters() {
return parameters;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private void assertClassifyImage(ClassifiedImages result, ClassifyOptions option
assertNotNull(result.getImages().get(0).getClassifiers());
assertTrue(!result.getImages().get(0).getClassifiers().isEmpty());

if (options.url() != null) {
if (options.url() != null || (options.parameters() != null && options.parameters().contains("url"))) {
assertNotNull(result.getImages().get(0).getResolvedUrl());
assertNotNull(result.getImages().get(0).getSourceUrl());
} else {
Expand All @@ -86,7 +86,7 @@ private void assertDetectedFaces(DetectedFaces detectedFaces, DetectFacesOptions
assertNull(detectedFaces.getImages().get(0).getError());
assertNotNull(detectedFaces.getImages().get(0).getFaces());

if (options.url() != null) {
if (options.url() != null || (options.parameters() != null && options.parameters().contains("url"))) {
assertEquals(IMAGE_FACE_URL, detectedFaces.getImages().get(0).getResolvedUrl());
assertEquals(IMAGE_FACE_URL, detectedFaces.getImages().get(0).getSourceUrl());
} else {
Expand Down Expand Up @@ -151,6 +151,20 @@ public void testClassifyImagesFromUrl() {
assertClassifyImage(result, options);
}

/**
* Test classify images from url using the deprecated parameters option.
*/
@Test
public void testClassifyImagesFromUrlUsingParameters() {
String parameters = "{\"url\":\"" + IMAGE_URL + "\"}";

ClassifyOptions options = new ClassifyOptions.Builder()
.parameters(parameters)
.build();
ClassifiedImages result = service.classify(options).execute();
assertClassifyImage(result, options);
}

/**
* Test create a classifier.
*
Expand Down Expand Up @@ -289,6 +303,21 @@ public void testDetectFacesFromUrl() {
assertDetectedFaces(detectedFaces, options);
}

/**
* Test detect faces from url using the deprecated parameters option.
*/
@Test
public void testDetectFacesFromUrlUsingParameters() {
String parameters = "{\"url\":\"" + IMAGE_FACE_URL + "\"}";

DetectFacesOptions options = new DetectFacesOptions.Builder()
.parameters(parameters)
.build();

DetectedFaces detectedFaces = service.detectFaces(options).execute();
assertDetectedFaces(detectedFaces, options);
}

/**
* Test list all the classifiers.
*/
Expand Down