com.microsoft.azure.cognitiveservices.vision.faceapi.implementation.PersonGroupPersonsImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of azure-cognitiveservices-faceapi Show documentation
Show all versions of azure-cognitiveservices-faceapi Show documentation
This package contains Microsoft Cognitive Service Face API SDK.
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
*/
package com.microsoft.azure.cognitiveservices.vision.faceapi.implementation;
import com.microsoft.azure.cognitiveservices.vision.faceapi.models.CreatePersonOptionalParameter;
import com.microsoft.azure.cognitiveservices.vision.faceapi.models.ListPersonOptionalParameter;
import com.microsoft.azure.cognitiveservices.vision.faceapi.models.UpdatePersonOptionalParameter;
import com.microsoft.azure.cognitiveservices.vision.faceapi.models.UpdateFaceOptionalParameter;
import com.microsoft.azure.cognitiveservices.vision.faceapi.models.AddPersonFaceFromUrlOptionalParameter;
import com.microsoft.azure.cognitiveservices.vision.faceapi.models.AddPersonFaceFromStreamOptionalParameter;
import retrofit2.Retrofit;
import com.microsoft.azure.cognitiveservices.vision.faceapi.PersonGroupPersons;
import com.google.common.base.Joiner;
import com.google.common.reflect.TypeToken;
import com.microsoft.azure.cognitiveservices.vision.faceapi.models.APIErrorException;
import com.microsoft.azure.cognitiveservices.vision.faceapi.models.ImageUrl;
import com.microsoft.azure.cognitiveservices.vision.faceapi.models.NameAndUserDataContract;
import com.microsoft.azure.cognitiveservices.vision.faceapi.models.PersistedFace;
import com.microsoft.azure.cognitiveservices.vision.faceapi.models.Person;
import com.microsoft.azure.cognitiveservices.vision.faceapi.models.UpdatePersonFaceRequest;
import com.microsoft.rest.CollectionFormat;
import com.microsoft.rest.ServiceCallback;
import com.microsoft.rest.ServiceFuture;
import com.microsoft.rest.ServiceResponse;
import com.microsoft.rest.Validator;
import java.io.IOException;
import java.util.List;
import java.util.UUID;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.Header;
import retrofit2.http.Headers;
import retrofit2.http.HTTP;
import retrofit2.http.PATCH;
import retrofit2.http.Path;
import retrofit2.http.POST;
import retrofit2.http.Query;
import retrofit2.Response;
import rx.functions.Func1;
import rx.Observable;
/**
* An instance of this class provides access to all the operations defined
* in PersonGroupPersons.
*/
public class PersonGroupPersonsImpl implements PersonGroupPersons {
/** The Retrofit service to perform REST calls. */
private PersonGroupPersonsService service;
/** The service client containing this operation class. */
private FaceAPIImpl client;
/**
* Initializes an instance of PersonGroupPersonsImpl.
*
* @param retrofit the Retrofit instance built from a Retrofit Builder.
* @param client the instance of the service client containing this operation class.
*/
public PersonGroupPersonsImpl(Retrofit retrofit, FaceAPIImpl client) {
this.service = retrofit.create(PersonGroupPersonsService.class);
this.client = client;
}
/**
* The interface defining all the services for PersonGroupPersons to be
* used by Retrofit to perform actually REST calls.
*/
interface PersonGroupPersonsService {
@Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.cognitiveservices.vision.faceapi.PersonGroupPersons createPerson" })
@POST("persongroups/{personGroupId}/persons")
Observable> createPerson(@Path("personGroupId") String personGroupId, @Header("accept-language") String acceptLanguage, @Body NameAndUserDataContract body, @Header("x-ms-parameterized-host") String parameterizedHost, @Header("User-Agent") String userAgent);
@Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.cognitiveservices.vision.faceapi.PersonGroupPersons listPerson" })
@GET("persongroups/{personGroupId}/persons")
Observable> listPerson(@Path("personGroupId") String personGroupId, @Query("start") String start, @Query("top") Integer top, @Header("accept-language") String acceptLanguage, @Header("x-ms-parameterized-host") String parameterizedHost, @Header("User-Agent") String userAgent);
@Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.cognitiveservices.vision.faceapi.PersonGroupPersons delete" })
@HTTP(path = "persongroups/{personGroupId}/persons/{personId}", method = "DELETE", hasBody = true)
Observable> delete(@Path("personGroupId") String personGroupId, @Path("personId") UUID personId, @Header("accept-language") String acceptLanguage, @Header("x-ms-parameterized-host") String parameterizedHost, @Header("User-Agent") String userAgent);
@Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.cognitiveservices.vision.faceapi.PersonGroupPersons get" })
@GET("persongroups/{personGroupId}/persons/{personId}")
Observable> get(@Path("personGroupId") String personGroupId, @Path("personId") UUID personId, @Header("accept-language") String acceptLanguage, @Header("x-ms-parameterized-host") String parameterizedHost, @Header("User-Agent") String userAgent);
@Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.cognitiveservices.vision.faceapi.PersonGroupPersons updatePerson" })
@PATCH("persongroups/{personGroupId}/persons/{personId}")
Observable> updatePerson(@Path("personGroupId") String personGroupId, @Path("personId") UUID personId, @Header("accept-language") String acceptLanguage, @Body NameAndUserDataContract body, @Header("x-ms-parameterized-host") String parameterizedHost, @Header("User-Agent") String userAgent);
@Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.cognitiveservices.vision.faceapi.PersonGroupPersons deleteFace" })
@HTTP(path = "persongroups/{personGroupId}/persons/{personId}/persistedFaces/{persistedFaceId}", method = "DELETE", hasBody = true)
Observable> deleteFace(@Path("personGroupId") String personGroupId, @Path("personId") UUID personId, @Path("persistedFaceId") UUID persistedFaceId, @Header("accept-language") String acceptLanguage, @Header("x-ms-parameterized-host") String parameterizedHost, @Header("User-Agent") String userAgent);
@Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.cognitiveservices.vision.faceapi.PersonGroupPersons getFace" })
@GET("persongroups/{personGroupId}/persons/{personId}/persistedFaces/{persistedFaceId}")
Observable> getFace(@Path("personGroupId") String personGroupId, @Path("personId") UUID personId, @Path("persistedFaceId") UUID persistedFaceId, @Header("accept-language") String acceptLanguage, @Header("x-ms-parameterized-host") String parameterizedHost, @Header("User-Agent") String userAgent);
@Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.cognitiveservices.vision.faceapi.PersonGroupPersons updateFace" })
@PATCH("persongroups/{personGroupId}/persons/{personId}/persistedFaces/{persistedFaceId}")
Observable> updateFace(@Path("personGroupId") String personGroupId, @Path("personId") UUID personId, @Path("persistedFaceId") UUID persistedFaceId, @Header("accept-language") String acceptLanguage, @Body UpdatePersonFaceRequest body, @Header("x-ms-parameterized-host") String parameterizedHost, @Header("User-Agent") String userAgent);
@Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.cognitiveservices.vision.faceapi.PersonGroupPersons addPersonFaceFromUrl" })
@POST("persongroups/{personGroupId}/persons/{personId}/persistedFaces")
Observable> addPersonFaceFromUrl(@Path("personGroupId") String personGroupId, @Path("personId") UUID personId, @Query("userData") String userData, @Query("targetFace") String targetFace, @Header("accept-language") String acceptLanguage, @Body ImageUrl imageUrl, @Header("x-ms-parameterized-host") String parameterizedHost, @Header("User-Agent") String userAgent);
@Headers({ "Content-Type: application/octet-stream", "x-ms-logging-context: com.microsoft.azure.cognitiveservices.vision.faceapi.PersonGroupPersons addPersonFaceFromStream" })
@POST("persongroups/{personGroupId}/persons/{personId}/persistedFaces")
Observable> addPersonFaceFromStream(@Path("personGroupId") String personGroupId, @Path("personId") UUID personId, @Query("userData") String userData, @Query("targetFace") String targetFace, @Body RequestBody image, @Header("accept-language") String acceptLanguage, @Header("x-ms-parameterized-host") String parameterizedHost, @Header("User-Agent") String userAgent);
}
/**
* Create a new person in a specified person group.
*
* @param personGroupId Id referencing a particular person group.
* @param createPersonOptionalParameter the object representing the optional parameters to be set before calling this API
* @throws IllegalArgumentException thrown if parameters fail the validation
* @throws APIErrorException thrown if the request is rejected by server
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
* @return the Person object if successful.
*/
public Person createPerson(String personGroupId, CreatePersonOptionalParameter createPersonOptionalParameter) {
return createPersonWithServiceResponseAsync(personGroupId, createPersonOptionalParameter).toBlocking().single().body();
}
/**
* Create a new person in a specified person group.
*
* @param personGroupId Id referencing a particular person group.
* @param createPersonOptionalParameter the object representing the optional parameters to be set before calling this API
* @param serviceCallback the async ServiceCallback to handle successful and failed responses.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceFuture} object
*/
public ServiceFuture createPersonAsync(String personGroupId, CreatePersonOptionalParameter createPersonOptionalParameter, final ServiceCallback serviceCallback) {
return ServiceFuture.fromResponse(createPersonWithServiceResponseAsync(personGroupId, createPersonOptionalParameter), serviceCallback);
}
/**
* Create a new person in a specified person group.
*
* @param personGroupId Id referencing a particular person group.
* @param createPersonOptionalParameter the object representing the optional parameters to be set before calling this API
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the Person object
*/
public Observable createPersonAsync(String personGroupId, CreatePersonOptionalParameter createPersonOptionalParameter) {
return createPersonWithServiceResponseAsync(personGroupId, createPersonOptionalParameter).map(new Func1, Person>() {
@Override
public Person call(ServiceResponse response) {
return response.body();
}
});
}
/**
* Create a new person in a specified person group.
*
* @param personGroupId Id referencing a particular person group.
* @param createPersonOptionalParameter the object representing the optional parameters to be set before calling this API
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the Person object
*/
public Observable> createPersonWithServiceResponseAsync(String personGroupId, CreatePersonOptionalParameter createPersonOptionalParameter) {
if (this.client.azureRegion() == null) {
throw new IllegalArgumentException("Parameter this.client.azureRegion() is required and cannot be null.");
}
if (personGroupId == null) {
throw new IllegalArgumentException("Parameter personGroupId is required and cannot be null.");
}
final String name = createPersonOptionalParameter != null ? createPersonOptionalParameter.name() : null;
final String userData = createPersonOptionalParameter != null ? createPersonOptionalParameter.userData() : null;
NameAndUserDataContract body = new NameAndUserDataContract();
body.withName(null);
body.withUserData(null);
String parameterizedHost = Joiner.on(", ").join("{AzureRegion}", this.client.azureRegion());
return createPersonWithServiceResponseAsync(personGroupId, name, userData);
}
/**
* Create a new person in a specified person group.
*
* @param personGroupId Id referencing a particular person group.
* @param name User defined name, maximum length is 128.
* @param userData User specified data. Length should not exceed 16KB.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the Person object
*/
public Observable> createPersonWithServiceResponseAsync(String personGroupId, String name, String userData) {
if (this.client.azureRegion() == null) {
throw new IllegalArgumentException("Parameter this.client.azureRegion() is required and cannot be null.");
}
if (personGroupId == null) {
throw new IllegalArgumentException("Parameter personGroupId is required and cannot be null.");
}
NameAndUserDataContract body = new NameAndUserDataContract();
body.withName(name);
body.withUserData(userData);
String parameterizedHost = Joiner.on(", ").join("{AzureRegion}", this.client.azureRegion());
return service.createPerson(personGroupId, this.client.acceptLanguage(), body, parameterizedHost, this.client.userAgent())
.flatMap(new Func1, Observable>>() {
@Override
public Observable> call(Response response) {
try {
ServiceResponse clientResponse = createPersonDelegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
private ServiceResponse createPersonDelegate(Response response) throws APIErrorException, IOException, IllegalArgumentException {
return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter())
.register(200, new TypeToken() { }.getType())
.registerError(APIErrorException.class)
.build(response);
}
/**
* List all persons in a person group, and retrieve person information (including personId, name, userData and persistedFaceIds of registered faces of the person).
*
* @param personGroupId Id referencing a particular person group.
* @param listPersonOptionalParameter the object representing the optional parameters to be set before calling this API
* @throws IllegalArgumentException thrown if parameters fail the validation
* @throws APIErrorException thrown if the request is rejected by server
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
* @return the List<Person> object if successful.
*/
public List listPerson(String personGroupId, ListPersonOptionalParameter listPersonOptionalParameter) {
return listPersonWithServiceResponseAsync(personGroupId, listPersonOptionalParameter).toBlocking().single().body();
}
/**
* List all persons in a person group, and retrieve person information (including personId, name, userData and persistedFaceIds of registered faces of the person).
*
* @param personGroupId Id referencing a particular person group.
* @param listPersonOptionalParameter the object representing the optional parameters to be set before calling this API
* @param serviceCallback the async ServiceCallback to handle successful and failed responses.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceFuture} object
*/
public ServiceFuture> listPersonAsync(String personGroupId, ListPersonOptionalParameter listPersonOptionalParameter, final ServiceCallback> serviceCallback) {
return ServiceFuture.fromResponse(listPersonWithServiceResponseAsync(personGroupId, listPersonOptionalParameter), serviceCallback);
}
/**
* List all persons in a person group, and retrieve person information (including personId, name, userData and persistedFaceIds of registered faces of the person).
*
* @param personGroupId Id referencing a particular person group.
* @param listPersonOptionalParameter the object representing the optional parameters to be set before calling this API
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the List<Person> object
*/
public Observable> listPersonAsync(String personGroupId, ListPersonOptionalParameter listPersonOptionalParameter) {
return listPersonWithServiceResponseAsync(personGroupId, listPersonOptionalParameter).map(new Func1>, List>() {
@Override
public List call(ServiceResponse> response) {
return response.body();
}
});
}
/**
* List all persons in a person group, and retrieve person information (including personId, name, userData and persistedFaceIds of registered faces of the person).
*
* @param personGroupId Id referencing a particular person group.
* @param listPersonOptionalParameter the object representing the optional parameters to be set before calling this API
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the List<Person> object
*/
public Observable>> listPersonWithServiceResponseAsync(String personGroupId, ListPersonOptionalParameter listPersonOptionalParameter) {
if (this.client.azureRegion() == null) {
throw new IllegalArgumentException("Parameter this.client.azureRegion() is required and cannot be null.");
}
if (personGroupId == null) {
throw new IllegalArgumentException("Parameter personGroupId is required and cannot be null.");
}
final String start = listPersonOptionalParameter != null ? listPersonOptionalParameter.start() : null;
final Integer top = listPersonOptionalParameter != null ? listPersonOptionalParameter.top() : null;
String parameterizedHost = Joiner.on(", ").join("{AzureRegion}", this.client.azureRegion());
return listPersonWithServiceResponseAsync(personGroupId, start, top);
}
/**
* List all persons in a person group, and retrieve person information (including personId, name, userData and persistedFaceIds of registered faces of the person).
*
* @param personGroupId Id referencing a particular person group.
* @param start Starting person id to return (used to list a range of persons).
* @param top Number of persons to return starting with the person id indicated by the 'start' parameter.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the List<Person> object
*/
public Observable>> listPersonWithServiceResponseAsync(String personGroupId, String start, Integer top) {
if (this.client.azureRegion() == null) {
throw new IllegalArgumentException("Parameter this.client.azureRegion() is required and cannot be null.");
}
if (personGroupId == null) {
throw new IllegalArgumentException("Parameter personGroupId is required and cannot be null.");
}
String parameterizedHost = Joiner.on(", ").join("{AzureRegion}", this.client.azureRegion());
return service.listPerson(personGroupId, start, top, this.client.acceptLanguage(), parameterizedHost, this.client.userAgent())
.flatMap(new Func1, Observable>>>() {
@Override
public Observable>> call(Response response) {
try {
ServiceResponse> clientResponse = listPersonDelegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
private ServiceResponse> listPersonDelegate(Response response) throws APIErrorException, IOException, IllegalArgumentException {
return this.client.restClient().responseBuilderFactory()., APIErrorException>newInstance(this.client.serializerAdapter())
.register(200, new TypeToken>() { }.getType())
.registerError(APIErrorException.class)
.build(response);
}
/**
* Delete an existing person from a person group. Persisted face images of the person will also be deleted.
*
* @param personGroupId Id referencing a particular person group.
* @param personId Id referencing a particular person.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @throws APIErrorException thrown if the request is rejected by server
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
*/
public void delete(String personGroupId, UUID personId) {
deleteWithServiceResponseAsync(personGroupId, personId).toBlocking().single().body();
}
/**
* Delete an existing person from a person group. Persisted face images of the person will also be deleted.
*
* @param personGroupId Id referencing a particular person group.
* @param personId Id referencing a particular person.
* @param serviceCallback the async ServiceCallback to handle successful and failed responses.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceFuture} object
*/
public ServiceFuture deleteAsync(String personGroupId, UUID personId, final ServiceCallback serviceCallback) {
return ServiceFuture.fromResponse(deleteWithServiceResponseAsync(personGroupId, personId), serviceCallback);
}
/**
* Delete an existing person from a person group. Persisted face images of the person will also be deleted.
*
* @param personGroupId Id referencing a particular person group.
* @param personId Id referencing a particular person.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceResponse} object if successful.
*/
public Observable deleteAsync(String personGroupId, UUID personId) {
return deleteWithServiceResponseAsync(personGroupId, personId).map(new Func1, Void>() {
@Override
public Void call(ServiceResponse response) {
return response.body();
}
});
}
/**
* Delete an existing person from a person group. Persisted face images of the person will also be deleted.
*
* @param personGroupId Id referencing a particular person group.
* @param personId Id referencing a particular person.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceResponse} object if successful.
*/
public Observable> deleteWithServiceResponseAsync(String personGroupId, UUID personId) {
if (this.client.azureRegion() == null) {
throw new IllegalArgumentException("Parameter this.client.azureRegion() is required and cannot be null.");
}
if (personGroupId == null) {
throw new IllegalArgumentException("Parameter personGroupId is required and cannot be null.");
}
if (personId == null) {
throw new IllegalArgumentException("Parameter personId is required and cannot be null.");
}
String parameterizedHost = Joiner.on(", ").join("{AzureRegion}", this.client.azureRegion());
return service.delete(personGroupId, personId, this.client.acceptLanguage(), parameterizedHost, this.client.userAgent())
.flatMap(new Func1, Observable>>() {
@Override
public Observable> call(Response response) {
try {
ServiceResponse clientResponse = deleteDelegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
private ServiceResponse deleteDelegate(Response response) throws APIErrorException, IOException, IllegalArgumentException {
return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter())
.register(200, new TypeToken() { }.getType())
.registerError(APIErrorException.class)
.build(response);
}
/**
* Retrieve a person's information, including registered persisted faces, name and userData.
*
* @param personGroupId Id referencing a particular person group.
* @param personId Id referencing a particular person.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @throws APIErrorException thrown if the request is rejected by server
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
* @return the Person object if successful.
*/
public Person get(String personGroupId, UUID personId) {
return getWithServiceResponseAsync(personGroupId, personId).toBlocking().single().body();
}
/**
* Retrieve a person's information, including registered persisted faces, name and userData.
*
* @param personGroupId Id referencing a particular person group.
* @param personId Id referencing a particular person.
* @param serviceCallback the async ServiceCallback to handle successful and failed responses.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceFuture} object
*/
public ServiceFuture getAsync(String personGroupId, UUID personId, final ServiceCallback serviceCallback) {
return ServiceFuture.fromResponse(getWithServiceResponseAsync(personGroupId, personId), serviceCallback);
}
/**
* Retrieve a person's information, including registered persisted faces, name and userData.
*
* @param personGroupId Id referencing a particular person group.
* @param personId Id referencing a particular person.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the Person object
*/
public Observable getAsync(String personGroupId, UUID personId) {
return getWithServiceResponseAsync(personGroupId, personId).map(new Func1, Person>() {
@Override
public Person call(ServiceResponse response) {
return response.body();
}
});
}
/**
* Retrieve a person's information, including registered persisted faces, name and userData.
*
* @param personGroupId Id referencing a particular person group.
* @param personId Id referencing a particular person.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the Person object
*/
public Observable> getWithServiceResponseAsync(String personGroupId, UUID personId) {
if (this.client.azureRegion() == null) {
throw new IllegalArgumentException("Parameter this.client.azureRegion() is required and cannot be null.");
}
if (personGroupId == null) {
throw new IllegalArgumentException("Parameter personGroupId is required and cannot be null.");
}
if (personId == null) {
throw new IllegalArgumentException("Parameter personId is required and cannot be null.");
}
String parameterizedHost = Joiner.on(", ").join("{AzureRegion}", this.client.azureRegion());
return service.get(personGroupId, personId, this.client.acceptLanguage(), parameterizedHost, this.client.userAgent())
.flatMap(new Func1, Observable>>() {
@Override
public Observable> call(Response response) {
try {
ServiceResponse clientResponse = getDelegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
private ServiceResponse getDelegate(Response response) throws APIErrorException, IOException, IllegalArgumentException {
return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter())
.register(200, new TypeToken() { }.getType())
.registerError(APIErrorException.class)
.build(response);
}
/**
* Update name or userData of a person.
*
* @param personGroupId Id referencing a particular person group.
* @param personId Id referencing a particular person.
* @param updatePersonOptionalParameter the object representing the optional parameters to be set before calling this API
* @throws IllegalArgumentException thrown if parameters fail the validation
* @throws APIErrorException thrown if the request is rejected by server
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
*/
public void updatePerson(String personGroupId, UUID personId, UpdatePersonOptionalParameter updatePersonOptionalParameter) {
updatePersonWithServiceResponseAsync(personGroupId, personId, updatePersonOptionalParameter).toBlocking().single().body();
}
/**
* Update name or userData of a person.
*
* @param personGroupId Id referencing a particular person group.
* @param personId Id referencing a particular person.
* @param updatePersonOptionalParameter the object representing the optional parameters to be set before calling this API
* @param serviceCallback the async ServiceCallback to handle successful and failed responses.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceFuture} object
*/
public ServiceFuture updatePersonAsync(String personGroupId, UUID personId, UpdatePersonOptionalParameter updatePersonOptionalParameter, final ServiceCallback serviceCallback) {
return ServiceFuture.fromResponse(updatePersonWithServiceResponseAsync(personGroupId, personId, updatePersonOptionalParameter), serviceCallback);
}
/**
* Update name or userData of a person.
*
* @param personGroupId Id referencing a particular person group.
* @param personId Id referencing a particular person.
* @param updatePersonOptionalParameter the object representing the optional parameters to be set before calling this API
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceResponse} object if successful.
*/
public Observable updatePersonAsync(String personGroupId, UUID personId, UpdatePersonOptionalParameter updatePersonOptionalParameter) {
return updatePersonWithServiceResponseAsync(personGroupId, personId, updatePersonOptionalParameter).map(new Func1, Void>() {
@Override
public Void call(ServiceResponse response) {
return response.body();
}
});
}
/**
* Update name or userData of a person.
*
* @param personGroupId Id referencing a particular person group.
* @param personId Id referencing a particular person.
* @param updatePersonOptionalParameter the object representing the optional parameters to be set before calling this API
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceResponse} object if successful.
*/
public Observable> updatePersonWithServiceResponseAsync(String personGroupId, UUID personId, UpdatePersonOptionalParameter updatePersonOptionalParameter) {
if (this.client.azureRegion() == null) {
throw new IllegalArgumentException("Parameter this.client.azureRegion() is required and cannot be null.");
}
if (personGroupId == null) {
throw new IllegalArgumentException("Parameter personGroupId is required and cannot be null.");
}
if (personId == null) {
throw new IllegalArgumentException("Parameter personId is required and cannot be null.");
}
final String name = updatePersonOptionalParameter != null ? updatePersonOptionalParameter.name() : null;
final String userData = updatePersonOptionalParameter != null ? updatePersonOptionalParameter.userData() : null;
NameAndUserDataContract body = new NameAndUserDataContract();
body.withName(null);
body.withUserData(null);
String parameterizedHost = Joiner.on(", ").join("{AzureRegion}", this.client.azureRegion());
return updatePersonWithServiceResponseAsync(personGroupId, personId, name, userData);
}
/**
* Update name or userData of a person.
*
* @param personGroupId Id referencing a particular person group.
* @param personId Id referencing a particular person.
* @param name User defined name, maximum length is 128.
* @param userData User specified data. Length should not exceed 16KB.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceResponse} object if successful.
*/
public Observable> updatePersonWithServiceResponseAsync(String personGroupId, UUID personId, String name, String userData) {
if (this.client.azureRegion() == null) {
throw new IllegalArgumentException("Parameter this.client.azureRegion() is required and cannot be null.");
}
if (personGroupId == null) {
throw new IllegalArgumentException("Parameter personGroupId is required and cannot be null.");
}
if (personId == null) {
throw new IllegalArgumentException("Parameter personId is required and cannot be null.");
}
NameAndUserDataContract body = new NameAndUserDataContract();
body.withName(name);
body.withUserData(userData);
String parameterizedHost = Joiner.on(", ").join("{AzureRegion}", this.client.azureRegion());
return service.updatePerson(personGroupId, personId, this.client.acceptLanguage(), body, parameterizedHost, this.client.userAgent())
.flatMap(new Func1, Observable>>() {
@Override
public Observable> call(Response response) {
try {
ServiceResponse clientResponse = updatePersonDelegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
private ServiceResponse updatePersonDelegate(Response response) throws APIErrorException, IOException, IllegalArgumentException {
return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter())
.register(200, new TypeToken() { }.getType())
.registerError(APIErrorException.class)
.build(response);
}
/**
* Delete a face from a person. Relative image for the persisted face will also be deleted.
*
* @param personGroupId Id referencing a particular person group.
* @param personId Id referencing a particular person.
* @param persistedFaceId Id referencing a particular persistedFaceId of an existing face.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @throws APIErrorException thrown if the request is rejected by server
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
*/
public void deleteFace(String personGroupId, UUID personId, UUID persistedFaceId) {
deleteFaceWithServiceResponseAsync(personGroupId, personId, persistedFaceId).toBlocking().single().body();
}
/**
* Delete a face from a person. Relative image for the persisted face will also be deleted.
*
* @param personGroupId Id referencing a particular person group.
* @param personId Id referencing a particular person.
* @param persistedFaceId Id referencing a particular persistedFaceId of an existing face.
* @param serviceCallback the async ServiceCallback to handle successful and failed responses.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceFuture} object
*/
public ServiceFuture deleteFaceAsync(String personGroupId, UUID personId, UUID persistedFaceId, final ServiceCallback serviceCallback) {
return ServiceFuture.fromResponse(deleteFaceWithServiceResponseAsync(personGroupId, personId, persistedFaceId), serviceCallback);
}
/**
* Delete a face from a person. Relative image for the persisted face will also be deleted.
*
* @param personGroupId Id referencing a particular person group.
* @param personId Id referencing a particular person.
* @param persistedFaceId Id referencing a particular persistedFaceId of an existing face.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceResponse} object if successful.
*/
public Observable deleteFaceAsync(String personGroupId, UUID personId, UUID persistedFaceId) {
return deleteFaceWithServiceResponseAsync(personGroupId, personId, persistedFaceId).map(new Func1, Void>() {
@Override
public Void call(ServiceResponse response) {
return response.body();
}
});
}
/**
* Delete a face from a person. Relative image for the persisted face will also be deleted.
*
* @param personGroupId Id referencing a particular person group.
* @param personId Id referencing a particular person.
* @param persistedFaceId Id referencing a particular persistedFaceId of an existing face.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceResponse} object if successful.
*/
public Observable> deleteFaceWithServiceResponseAsync(String personGroupId, UUID personId, UUID persistedFaceId) {
if (this.client.azureRegion() == null) {
throw new IllegalArgumentException("Parameter this.client.azureRegion() is required and cannot be null.");
}
if (personGroupId == null) {
throw new IllegalArgumentException("Parameter personGroupId is required and cannot be null.");
}
if (personId == null) {
throw new IllegalArgumentException("Parameter personId is required and cannot be null.");
}
if (persistedFaceId == null) {
throw new IllegalArgumentException("Parameter persistedFaceId is required and cannot be null.");
}
String parameterizedHost = Joiner.on(", ").join("{AzureRegion}", this.client.azureRegion());
return service.deleteFace(personGroupId, personId, persistedFaceId, this.client.acceptLanguage(), parameterizedHost, this.client.userAgent())
.flatMap(new Func1, Observable>>() {
@Override
public Observable> call(Response response) {
try {
ServiceResponse clientResponse = deleteFaceDelegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
private ServiceResponse deleteFaceDelegate(Response response) throws APIErrorException, IOException, IllegalArgumentException {
return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter())
.register(200, new TypeToken() { }.getType())
.registerError(APIErrorException.class)
.build(response);
}
/**
* Retrieve information about a persisted face (specified by persistedFaceId, personId and its belonging personGroupId).
*
* @param personGroupId Id referencing a particular person group.
* @param personId Id referencing a particular person.
* @param persistedFaceId Id referencing a particular persistedFaceId of an existing face.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @throws APIErrorException thrown if the request is rejected by server
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
* @return the PersistedFace object if successful.
*/
public PersistedFace getFace(String personGroupId, UUID personId, UUID persistedFaceId) {
return getFaceWithServiceResponseAsync(personGroupId, personId, persistedFaceId).toBlocking().single().body();
}
/**
* Retrieve information about a persisted face (specified by persistedFaceId, personId and its belonging personGroupId).
*
* @param personGroupId Id referencing a particular person group.
* @param personId Id referencing a particular person.
* @param persistedFaceId Id referencing a particular persistedFaceId of an existing face.
* @param serviceCallback the async ServiceCallback to handle successful and failed responses.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceFuture} object
*/
public ServiceFuture getFaceAsync(String personGroupId, UUID personId, UUID persistedFaceId, final ServiceCallback serviceCallback) {
return ServiceFuture.fromResponse(getFaceWithServiceResponseAsync(personGroupId, personId, persistedFaceId), serviceCallback);
}
/**
* Retrieve information about a persisted face (specified by persistedFaceId, personId and its belonging personGroupId).
*
* @param personGroupId Id referencing a particular person group.
* @param personId Id referencing a particular person.
* @param persistedFaceId Id referencing a particular persistedFaceId of an existing face.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the PersistedFace object
*/
public Observable getFaceAsync(String personGroupId, UUID personId, UUID persistedFaceId) {
return getFaceWithServiceResponseAsync(personGroupId, personId, persistedFaceId).map(new Func1, PersistedFace>() {
@Override
public PersistedFace call(ServiceResponse response) {
return response.body();
}
});
}
/**
* Retrieve information about a persisted face (specified by persistedFaceId, personId and its belonging personGroupId).
*
* @param personGroupId Id referencing a particular person group.
* @param personId Id referencing a particular person.
* @param persistedFaceId Id referencing a particular persistedFaceId of an existing face.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the PersistedFace object
*/
public Observable> getFaceWithServiceResponseAsync(String personGroupId, UUID personId, UUID persistedFaceId) {
if (this.client.azureRegion() == null) {
throw new IllegalArgumentException("Parameter this.client.azureRegion() is required and cannot be null.");
}
if (personGroupId == null) {
throw new IllegalArgumentException("Parameter personGroupId is required and cannot be null.");
}
if (personId == null) {
throw new IllegalArgumentException("Parameter personId is required and cannot be null.");
}
if (persistedFaceId == null) {
throw new IllegalArgumentException("Parameter persistedFaceId is required and cannot be null.");
}
String parameterizedHost = Joiner.on(", ").join("{AzureRegion}", this.client.azureRegion());
return service.getFace(personGroupId, personId, persistedFaceId, this.client.acceptLanguage(), parameterizedHost, this.client.userAgent())
.flatMap(new Func1, Observable>>() {
@Override
public Observable> call(Response response) {
try {
ServiceResponse clientResponse = getFaceDelegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
private ServiceResponse getFaceDelegate(Response response) throws APIErrorException, IOException, IllegalArgumentException {
return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter())
.register(200, new TypeToken() { }.getType())
.registerError(APIErrorException.class)
.build(response);
}
/**
* Update a person persisted face's userData field.
*
* @param personGroupId Id referencing a particular person group.
* @param personId Id referencing a particular person.
* @param persistedFaceId Id referencing a particular persistedFaceId of an existing face.
* @param updateFaceOptionalParameter the object representing the optional parameters to be set before calling this API
* @throws IllegalArgumentException thrown if parameters fail the validation
* @throws APIErrorException thrown if the request is rejected by server
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
*/
public void updateFace(String personGroupId, UUID personId, UUID persistedFaceId, UpdateFaceOptionalParameter updateFaceOptionalParameter) {
updateFaceWithServiceResponseAsync(personGroupId, personId, persistedFaceId, updateFaceOptionalParameter).toBlocking().single().body();
}
/**
* Update a person persisted face's userData field.
*
* @param personGroupId Id referencing a particular person group.
* @param personId Id referencing a particular person.
* @param persistedFaceId Id referencing a particular persistedFaceId of an existing face.
* @param updateFaceOptionalParameter the object representing the optional parameters to be set before calling this API
* @param serviceCallback the async ServiceCallback to handle successful and failed responses.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceFuture} object
*/
public ServiceFuture updateFaceAsync(String personGroupId, UUID personId, UUID persistedFaceId, UpdateFaceOptionalParameter updateFaceOptionalParameter, final ServiceCallback serviceCallback) {
return ServiceFuture.fromResponse(updateFaceWithServiceResponseAsync(personGroupId, personId, persistedFaceId, updateFaceOptionalParameter), serviceCallback);
}
/**
* Update a person persisted face's userData field.
*
* @param personGroupId Id referencing a particular person group.
* @param personId Id referencing a particular person.
* @param persistedFaceId Id referencing a particular persistedFaceId of an existing face.
* @param updateFaceOptionalParameter the object representing the optional parameters to be set before calling this API
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceResponse} object if successful.
*/
public Observable updateFaceAsync(String personGroupId, UUID personId, UUID persistedFaceId, UpdateFaceOptionalParameter updateFaceOptionalParameter) {
return updateFaceWithServiceResponseAsync(personGroupId, personId, persistedFaceId, updateFaceOptionalParameter).map(new Func1, Void>() {
@Override
public Void call(ServiceResponse response) {
return response.body();
}
});
}
/**
* Update a person persisted face's userData field.
*
* @param personGroupId Id referencing a particular person group.
* @param personId Id referencing a particular person.
* @param persistedFaceId Id referencing a particular persistedFaceId of an existing face.
* @param updateFaceOptionalParameter the object representing the optional parameters to be set before calling this API
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceResponse} object if successful.
*/
public Observable> updateFaceWithServiceResponseAsync(String personGroupId, UUID personId, UUID persistedFaceId, UpdateFaceOptionalParameter updateFaceOptionalParameter) {
if (this.client.azureRegion() == null) {
throw new IllegalArgumentException("Parameter this.client.azureRegion() is required and cannot be null.");
}
if (personGroupId == null) {
throw new IllegalArgumentException("Parameter personGroupId is required and cannot be null.");
}
if (personId == null) {
throw new IllegalArgumentException("Parameter personId is required and cannot be null.");
}
if (persistedFaceId == null) {
throw new IllegalArgumentException("Parameter persistedFaceId is required and cannot be null.");
}
final String userData = updateFaceOptionalParameter != null ? updateFaceOptionalParameter.userData() : null;
UpdatePersonFaceRequest body = new UpdatePersonFaceRequest();
body.withUserData(null);
String parameterizedHost = Joiner.on(", ").join("{AzureRegion}", this.client.azureRegion());
return updateFaceWithServiceResponseAsync(personGroupId, personId, persistedFaceId, userData);
}
/**
* Update a person persisted face's userData field.
*
* @param personGroupId Id referencing a particular person group.
* @param personId Id referencing a particular person.
* @param persistedFaceId Id referencing a particular persistedFaceId of an existing face.
* @param userData User-provided data attached to the face. The size limit is 1KB.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceResponse} object if successful.
*/
public Observable> updateFaceWithServiceResponseAsync(String personGroupId, UUID personId, UUID persistedFaceId, String userData) {
if (this.client.azureRegion() == null) {
throw new IllegalArgumentException("Parameter this.client.azureRegion() is required and cannot be null.");
}
if (personGroupId == null) {
throw new IllegalArgumentException("Parameter personGroupId is required and cannot be null.");
}
if (personId == null) {
throw new IllegalArgumentException("Parameter personId is required and cannot be null.");
}
if (persistedFaceId == null) {
throw new IllegalArgumentException("Parameter persistedFaceId is required and cannot be null.");
}
UpdatePersonFaceRequest body = new UpdatePersonFaceRequest();
body.withUserData(userData);
String parameterizedHost = Joiner.on(", ").join("{AzureRegion}", this.client.azureRegion());
return service.updateFace(personGroupId, personId, persistedFaceId, this.client.acceptLanguage(), body, parameterizedHost, this.client.userAgent())
.flatMap(new Func1, Observable>>() {
@Override
public Observable> call(Response response) {
try {
ServiceResponse clientResponse = updateFaceDelegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
private ServiceResponse updateFaceDelegate(Response response) throws APIErrorException, IOException, IllegalArgumentException {
return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter())
.register(200, new TypeToken() { }.getType())
.registerError(APIErrorException.class)
.build(response);
}
/**
* Add a representative face to a person for identification. The input face is specified as an image with a targetFace rectangle.
*
* @param personGroupId Id referencing a particular person group.
* @param personId Id referencing a particular person.
* @param url the String value
* @param addPersonFaceFromUrlOptionalParameter the object representing the optional parameters to be set before calling this API
* @throws IllegalArgumentException thrown if parameters fail the validation
* @throws APIErrorException thrown if the request is rejected by server
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
* @return the PersistedFace object if successful.
*/
public PersistedFace addPersonFaceFromUrl(String personGroupId, UUID personId, String url, AddPersonFaceFromUrlOptionalParameter addPersonFaceFromUrlOptionalParameter) {
return addPersonFaceFromUrlWithServiceResponseAsync(personGroupId, personId, url, addPersonFaceFromUrlOptionalParameter).toBlocking().single().body();
}
/**
* Add a representative face to a person for identification. The input face is specified as an image with a targetFace rectangle.
*
* @param personGroupId Id referencing a particular person group.
* @param personId Id referencing a particular person.
* @param url the String value
* @param addPersonFaceFromUrlOptionalParameter the object representing the optional parameters to be set before calling this API
* @param serviceCallback the async ServiceCallback to handle successful and failed responses.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceFuture} object
*/
public ServiceFuture addPersonFaceFromUrlAsync(String personGroupId, UUID personId, String url, AddPersonFaceFromUrlOptionalParameter addPersonFaceFromUrlOptionalParameter, final ServiceCallback serviceCallback) {
return ServiceFuture.fromResponse(addPersonFaceFromUrlWithServiceResponseAsync(personGroupId, personId, url, addPersonFaceFromUrlOptionalParameter), serviceCallback);
}
/**
* Add a representative face to a person for identification. The input face is specified as an image with a targetFace rectangle.
*
* @param personGroupId Id referencing a particular person group.
* @param personId Id referencing a particular person.
* @param url the String value
* @param addPersonFaceFromUrlOptionalParameter the object representing the optional parameters to be set before calling this API
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the PersistedFace object
*/
public Observable addPersonFaceFromUrlAsync(String personGroupId, UUID personId, String url, AddPersonFaceFromUrlOptionalParameter addPersonFaceFromUrlOptionalParameter) {
return addPersonFaceFromUrlWithServiceResponseAsync(personGroupId, personId, url, addPersonFaceFromUrlOptionalParameter).map(new Func1, PersistedFace>() {
@Override
public PersistedFace call(ServiceResponse response) {
return response.body();
}
});
}
/**
* Add a representative face to a person for identification. The input face is specified as an image with a targetFace rectangle.
*
* @param personGroupId Id referencing a particular person group.
* @param personId Id referencing a particular person.
* @param url the String value
* @param addPersonFaceFromUrlOptionalParameter the object representing the optional parameters to be set before calling this API
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the PersistedFace object
*/
public Observable> addPersonFaceFromUrlWithServiceResponseAsync(String personGroupId, UUID personId, String url, AddPersonFaceFromUrlOptionalParameter addPersonFaceFromUrlOptionalParameter) {
if (this.client.azureRegion() == null) {
throw new IllegalArgumentException("Parameter this.client.azureRegion() is required and cannot be null.");
}
if (personGroupId == null) {
throw new IllegalArgumentException("Parameter personGroupId is required and cannot be null.");
}
if (personId == null) {
throw new IllegalArgumentException("Parameter personId is required and cannot be null.");
}
if (url == null) {
throw new IllegalArgumentException("Parameter url is required and cannot be null.");
}
final String userData = addPersonFaceFromUrlOptionalParameter != null ? addPersonFaceFromUrlOptionalParameter.userData() : null;
final List targetFace = addPersonFaceFromUrlOptionalParameter != null ? addPersonFaceFromUrlOptionalParameter.targetFace() : null;
ImageUrl imageUrl = new ImageUrl();
imageUrl.withUrl(url);
String parameterizedHost = Joiner.on(", ").join("{AzureRegion}", this.client.azureRegion());
String targetFaceConverted = this.client.serializerAdapter().serializeList(targetFace, CollectionFormat.CSV);
return addPersonFaceFromUrlWithServiceResponseAsync(personGroupId, personId, url, userData, targetFace);
}
/**
* Add a representative face to a person for identification. The input face is specified as an image with a targetFace rectangle.
*
* @param personGroupId Id referencing a particular person group.
* @param personId Id referencing a particular person.
* @param url the String value
* @param userData User-specified data about the face for any purpose. The maximum length is 1KB.
* @param targetFace A face rectangle to specify the target face to be added to a person in the format of "targetFace=left,top,width,height". E.g. "targetFace=10,10,100,100". If there is more than one face in the image, targetFace is required to specify which face to add. No targetFace means there is only one face detected in the entire image.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the PersistedFace object
*/
public Observable> addPersonFaceFromUrlWithServiceResponseAsync(String personGroupId, UUID personId, String url, String userData, List targetFace) {
if (this.client.azureRegion() == null) {
throw new IllegalArgumentException("Parameter this.client.azureRegion() is required and cannot be null.");
}
if (personGroupId == null) {
throw new IllegalArgumentException("Parameter personGroupId is required and cannot be null.");
}
if (personId == null) {
throw new IllegalArgumentException("Parameter personId is required and cannot be null.");
}
if (url == null) {
throw new IllegalArgumentException("Parameter url is required and cannot be null.");
}
Validator.validate(targetFace);
ImageUrl imageUrl = new ImageUrl();
imageUrl.withUrl(url);
String parameterizedHost = Joiner.on(", ").join("{AzureRegion}", this.client.azureRegion());
String targetFaceConverted = this.client.serializerAdapter().serializeList(targetFace, CollectionFormat.CSV);
return service.addPersonFaceFromUrl(personGroupId, personId, userData, targetFaceConverted, this.client.acceptLanguage(), imageUrl, parameterizedHost, this.client.userAgent())
.flatMap(new Func1, Observable>>() {
@Override
public Observable> call(Response response) {
try {
ServiceResponse clientResponse = addPersonFaceFromUrlDelegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
private ServiceResponse addPersonFaceFromUrlDelegate(Response response) throws APIErrorException, IOException, IllegalArgumentException {
return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter())
.register(200, new TypeToken() { }.getType())
.registerError(APIErrorException.class)
.build(response);
}
/**
* Add a representative face to a person for identification. The input face is specified as an image with a targetFace rectangle.
*
* @param personGroupId Id referencing a particular person group.
* @param personId Id referencing a particular person.
* @param image An image stream.
* @param addPersonFaceFromStreamOptionalParameter the object representing the optional parameters to be set before calling this API
* @throws IllegalArgumentException thrown if parameters fail the validation
* @throws APIErrorException thrown if the request is rejected by server
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
* @return the PersistedFace object if successful.
*/
public PersistedFace addPersonFaceFromStream(String personGroupId, UUID personId, byte[] image, AddPersonFaceFromStreamOptionalParameter addPersonFaceFromStreamOptionalParameter) {
return addPersonFaceFromStreamWithServiceResponseAsync(personGroupId, personId, image, addPersonFaceFromStreamOptionalParameter).toBlocking().single().body();
}
/**
* Add a representative face to a person for identification. The input face is specified as an image with a targetFace rectangle.
*
* @param personGroupId Id referencing a particular person group.
* @param personId Id referencing a particular person.
* @param image An image stream.
* @param addPersonFaceFromStreamOptionalParameter the object representing the optional parameters to be set before calling this API
* @param serviceCallback the async ServiceCallback to handle successful and failed responses.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceFuture} object
*/
public ServiceFuture addPersonFaceFromStreamAsync(String personGroupId, UUID personId, byte[] image, AddPersonFaceFromStreamOptionalParameter addPersonFaceFromStreamOptionalParameter, final ServiceCallback serviceCallback) {
return ServiceFuture.fromResponse(addPersonFaceFromStreamWithServiceResponseAsync(personGroupId, personId, image, addPersonFaceFromStreamOptionalParameter), serviceCallback);
}
/**
* Add a representative face to a person for identification. The input face is specified as an image with a targetFace rectangle.
*
* @param personGroupId Id referencing a particular person group.
* @param personId Id referencing a particular person.
* @param image An image stream.
* @param addPersonFaceFromStreamOptionalParameter the object representing the optional parameters to be set before calling this API
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the PersistedFace object
*/
public Observable addPersonFaceFromStreamAsync(String personGroupId, UUID personId, byte[] image, AddPersonFaceFromStreamOptionalParameter addPersonFaceFromStreamOptionalParameter) {
return addPersonFaceFromStreamWithServiceResponseAsync(personGroupId, personId, image, addPersonFaceFromStreamOptionalParameter).map(new Func1, PersistedFace>() {
@Override
public PersistedFace call(ServiceResponse response) {
return response.body();
}
});
}
/**
* Add a representative face to a person for identification. The input face is specified as an image with a targetFace rectangle.
*
* @param personGroupId Id referencing a particular person group.
* @param personId Id referencing a particular person.
* @param image An image stream.
* @param addPersonFaceFromStreamOptionalParameter the object representing the optional parameters to be set before calling this API
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the PersistedFace object
*/
public Observable> addPersonFaceFromStreamWithServiceResponseAsync(String personGroupId, UUID personId, byte[] image, AddPersonFaceFromStreamOptionalParameter addPersonFaceFromStreamOptionalParameter) {
if (this.client.azureRegion() == null) {
throw new IllegalArgumentException("Parameter this.client.azureRegion() is required and cannot be null.");
}
if (personGroupId == null) {
throw new IllegalArgumentException("Parameter personGroupId is required and cannot be null.");
}
if (personId == null) {
throw new IllegalArgumentException("Parameter personId is required and cannot be null.");
}
if (image == null) {
throw new IllegalArgumentException("Parameter image is required and cannot be null.");
}
final String userData = addPersonFaceFromStreamOptionalParameter != null ? addPersonFaceFromStreamOptionalParameter.userData() : null;
final List targetFace = addPersonFaceFromStreamOptionalParameter != null ? addPersonFaceFromStreamOptionalParameter.targetFace() : null;
String parameterizedHost = Joiner.on(", ").join("{AzureRegion}", this.client.azureRegion());
String targetFaceConverted = this.client.serializerAdapter().serializeList(targetFace, CollectionFormat.CSV);
RequestBody imageConverted = RequestBody.create(MediaType.parse("application/octet-stream"), image);
return addPersonFaceFromStreamWithServiceResponseAsync(personGroupId, personId, image, userData, targetFace);
}
/**
* Add a representative face to a person for identification. The input face is specified as an image with a targetFace rectangle.
*
* @param personGroupId Id referencing a particular person group.
* @param personId Id referencing a particular person.
* @param image An image stream.
* @param userData User-specified data about the face for any purpose. The maximum length is 1KB.
* @param targetFace A face rectangle to specify the target face to be added to a person in the format of "targetFace=left,top,width,height". E.g. "targetFace=10,10,100,100". If there is more than one face in the image, targetFace is required to specify which face to add. No targetFace means there is only one face detected in the entire image.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the PersistedFace object
*/
public Observable> addPersonFaceFromStreamWithServiceResponseAsync(String personGroupId, UUID personId, byte[] image, String userData, List targetFace) {
if (this.client.azureRegion() == null) {
throw new IllegalArgumentException("Parameter this.client.azureRegion() is required and cannot be null.");
}
if (personGroupId == null) {
throw new IllegalArgumentException("Parameter personGroupId is required and cannot be null.");
}
if (personId == null) {
throw new IllegalArgumentException("Parameter personId is required and cannot be null.");
}
if (image == null) {
throw new IllegalArgumentException("Parameter image is required and cannot be null.");
}
Validator.validate(targetFace);
String parameterizedHost = Joiner.on(", ").join("{AzureRegion}", this.client.azureRegion());
String targetFaceConverted = this.client.serializerAdapter().serializeList(targetFace, CollectionFormat.CSV);
RequestBody imageConverted = RequestBody.create(MediaType.parse("application/octet-stream"), image);
return service.addPersonFaceFromStream(personGroupId, personId, userData, targetFaceConverted, imageConverted, this.client.acceptLanguage(), parameterizedHost, this.client.userAgent())
.flatMap(new Func1, Observable>>() {
@Override
public Observable> call(Response response) {
try {
ServiceResponse clientResponse = addPersonFaceFromStreamDelegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
private ServiceResponse addPersonFaceFromStreamDelegate(Response response) throws APIErrorException, IOException, IllegalArgumentException {
return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter())
.register(200, new TypeToken() { }.getType())
.registerError(APIErrorException.class)
.build(response);
}
}