All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.microsoft.azure.cognitiveservices.vision.faceapi.implementation.PersonGroupsImpl Maven / Gradle / Ivy

There is a newer version: 1.0.1-beta
Show newest version
/**
 * 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.CreatePersonGroupOptionalParameter;
import com.microsoft.azure.cognitiveservices.vision.faceapi.models.UpdatePersonGroupOptionalParameter;
import com.microsoft.azure.cognitiveservices.vision.faceapi.models.ListPersonGroupOptionalParameter;
import retrofit2.Retrofit;
import com.microsoft.azure.cognitiveservices.vision.faceapi.PersonGroups;
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.NameAndUserDataContract;
import com.microsoft.azure.cognitiveservices.vision.faceapi.models.PersonGroup;
import com.microsoft.azure.cognitiveservices.vision.faceapi.models.TrainingStatus;
import com.microsoft.rest.ServiceCallback;
import com.microsoft.rest.ServiceFuture;
import com.microsoft.rest.ServiceResponse;
import java.io.IOException;
import java.util.List;
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.PUT;
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 PersonGroups.
 */
public class PersonGroupsImpl implements PersonGroups {
    /** The Retrofit service to perform REST calls. */
    private PersonGroupsService service;
    /** The service client containing this operation class. */
    private FaceAPIImpl client;

    /**
     * Initializes an instance of PersonGroupsImpl.
     *
     * @param retrofit the Retrofit instance built from a Retrofit Builder.
     * @param client the instance of the service client containing this operation class.
     */
    public PersonGroupsImpl(Retrofit retrofit, FaceAPIImpl client) {
        this.service = retrofit.create(PersonGroupsService.class);
        this.client = client;
    }

    /**
     * The interface defining all the services for PersonGroups to be
     * used by Retrofit to perform actually REST calls.
     */
    interface PersonGroupsService {
        @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.cognitiveservices.vision.faceapi.PersonGroups createPersonGroup" })
        @PUT("persongroups/{personGroupId}")
        Observable> createPersonGroup(@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.PersonGroups delete" })
        @HTTP(path = "persongroups/{personGroupId}", method = "DELETE", hasBody = true)
        Observable> delete(@Path("personGroupId") String personGroupId, @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.PersonGroups get" })
        @GET("persongroups/{personGroupId}")
        Observable> get(@Path("personGroupId") String personGroupId, @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.PersonGroups updatePersonGroup" })
        @PATCH("persongroups/{personGroupId}")
        Observable> updatePersonGroup(@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.PersonGroups getTrainingStatus" })
        @GET("persongroups/{personGroupId}/training")
        Observable> getTrainingStatus(@Path("personGroupId") String personGroupId, @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.PersonGroups listPersonGroup" })
        @GET("persongroups")
        Observable> listPersonGroup(@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.PersonGroups train" })
        @POST("persongroups/{personGroupId}/train")
        Observable> train(@Path("personGroupId") String personGroupId, @Header("accept-language") String acceptLanguage, @Header("x-ms-parameterized-host") String parameterizedHost, @Header("User-Agent") String userAgent);

    }


    /**
     * Create a new person group with specified personGroupId, name and user-provided userData.
     *
     * @param personGroupId Id referencing a particular person group.
     * @param createPersonGroupOptionalParameter 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 createPersonGroup(String personGroupId, CreatePersonGroupOptionalParameter createPersonGroupOptionalParameter) {
        createPersonGroupWithServiceResponseAsync(personGroupId, createPersonGroupOptionalParameter).toBlocking().single().body();
    }

    /**
     * Create a new person group with specified personGroupId, name and user-provided userData.
     *
     * @param personGroupId Id referencing a particular person group.
     * @param createPersonGroupOptionalParameter 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 createPersonGroupAsync(String personGroupId, CreatePersonGroupOptionalParameter createPersonGroupOptionalParameter, final ServiceCallback serviceCallback) {
        return ServiceFuture.fromResponse(createPersonGroupWithServiceResponseAsync(personGroupId, createPersonGroupOptionalParameter), serviceCallback);
    }

    /**
     * Create a new person group with specified personGroupId, name and user-provided userData.
     *
     * @param personGroupId Id referencing a particular person group.
     * @param createPersonGroupOptionalParameter 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 createPersonGroupAsync(String personGroupId, CreatePersonGroupOptionalParameter createPersonGroupOptionalParameter) {
        return createPersonGroupWithServiceResponseAsync(personGroupId, createPersonGroupOptionalParameter).map(new Func1, Void>() {
            @Override
            public Void call(ServiceResponse response) {
                return response.body();
            }
        });
    }

    /**
     * Create a new person group with specified personGroupId, name and user-provided userData.
     *
     * @param personGroupId Id referencing a particular person group.
     * @param createPersonGroupOptionalParameter 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> createPersonGroupWithServiceResponseAsync(String personGroupId, CreatePersonGroupOptionalParameter createPersonGroupOptionalParameter) {
        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 = createPersonGroupOptionalParameter != null ? createPersonGroupOptionalParameter.name() : null;
        final String userData = createPersonGroupOptionalParameter != null ? createPersonGroupOptionalParameter.userData() : null;
        NameAndUserDataContract body = new NameAndUserDataContract();
        body.withName(null);
        body.withUserData(null);
        String parameterizedHost = Joiner.on(", ").join("{AzureRegion}", this.client.azureRegion());

        return createPersonGroupWithServiceResponseAsync(personGroupId, name, userData);
    }

    /**
     * Create a new person group with specified personGroupId, name and user-provided userData.
     *
     * @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 {@link ServiceResponse} object if successful.
     */
    public Observable> createPersonGroupWithServiceResponseAsync(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.createPersonGroup(personGroupId, this.client.acceptLanguage(), body, parameterizedHost, this.client.userAgent())
            .flatMap(new Func1, Observable>>() {
                @Override
                public Observable> call(Response response) {
                    try {
                        ServiceResponse clientResponse = createPersonGroupDelegate(response);
                        return Observable.just(clientResponse);
                    } catch (Throwable t) {
                        return Observable.error(t);
                    }
                }
            });
    }

    private ServiceResponse createPersonGroupDelegate(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 an existing person group. Persisted face images of all people in the person group will also be deleted.
     *
     * @param personGroupId Id referencing a particular person group.
     * @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) {
        deleteWithServiceResponseAsync(personGroupId).toBlocking().single().body();
    }

    /**
     * Delete an existing person group. Persisted face images of all people in the person group will also be deleted.
     *
     * @param personGroupId Id referencing a particular person group.
     * @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, final ServiceCallback serviceCallback) {
        return ServiceFuture.fromResponse(deleteWithServiceResponseAsync(personGroupId), serviceCallback);
    }

    /**
     * Delete an existing person group. Persisted face images of all people in the person group will also be deleted.
     *
     * @param personGroupId Id referencing a particular person group.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the {@link ServiceResponse} object if successful.
     */
    public Observable deleteAsync(String personGroupId) {
        return deleteWithServiceResponseAsync(personGroupId).map(new Func1, Void>() {
            @Override
            public Void call(ServiceResponse response) {
                return response.body();
            }
        });
    }

    /**
     * Delete an existing person group. Persisted face images of all people in the person group will also be deleted.
     *
     * @param personGroupId Id referencing a particular person group.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the {@link ServiceResponse} object if successful.
     */
    public Observable> deleteWithServiceResponseAsync(String personGroupId) {
        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.delete(personGroupId, 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 the information of a person group, including its name and userData.
     *
     * @param personGroupId Id referencing a particular person group.
     * @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 PersonGroup object if successful.
     */
    public PersonGroup get(String personGroupId) {
        return getWithServiceResponseAsync(personGroupId).toBlocking().single().body();
    }

    /**
     * Retrieve the information of a person group, including its name and userData.
     *
     * @param personGroupId Id referencing a particular person group.
     * @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, final ServiceCallback serviceCallback) {
        return ServiceFuture.fromResponse(getWithServiceResponseAsync(personGroupId), serviceCallback);
    }

    /**
     * Retrieve the information of a person group, including its name and userData.
     *
     * @param personGroupId Id referencing a particular person group.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the PersonGroup object
     */
    public Observable getAsync(String personGroupId) {
        return getWithServiceResponseAsync(personGroupId).map(new Func1, PersonGroup>() {
            @Override
            public PersonGroup call(ServiceResponse response) {
                return response.body();
            }
        });
    }

    /**
     * Retrieve the information of a person group, including its name and userData.
     *
     * @param personGroupId Id referencing a particular person group.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the PersonGroup object
     */
    public Observable> getWithServiceResponseAsync(String personGroupId) {
        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.get(personGroupId, 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 an existing person group's display name and userData. The properties which does not appear in request body will not be updated.
     *
     * @param personGroupId Id referencing a particular person group.
     * @param updatePersonGroupOptionalParameter 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 updatePersonGroup(String personGroupId, UpdatePersonGroupOptionalParameter updatePersonGroupOptionalParameter) {
        updatePersonGroupWithServiceResponseAsync(personGroupId, updatePersonGroupOptionalParameter).toBlocking().single().body();
    }

    /**
     * Update an existing person group's display name and userData. The properties which does not appear in request body will not be updated.
     *
     * @param personGroupId Id referencing a particular person group.
     * @param updatePersonGroupOptionalParameter 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 updatePersonGroupAsync(String personGroupId, UpdatePersonGroupOptionalParameter updatePersonGroupOptionalParameter, final ServiceCallback serviceCallback) {
        return ServiceFuture.fromResponse(updatePersonGroupWithServiceResponseAsync(personGroupId, updatePersonGroupOptionalParameter), serviceCallback);
    }

    /**
     * Update an existing person group's display name and userData. The properties which does not appear in request body will not be updated.
     *
     * @param personGroupId Id referencing a particular person group.
     * @param updatePersonGroupOptionalParameter 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 updatePersonGroupAsync(String personGroupId, UpdatePersonGroupOptionalParameter updatePersonGroupOptionalParameter) {
        return updatePersonGroupWithServiceResponseAsync(personGroupId, updatePersonGroupOptionalParameter).map(new Func1, Void>() {
            @Override
            public Void call(ServiceResponse response) {
                return response.body();
            }
        });
    }

    /**
     * Update an existing person group's display name and userData. The properties which does not appear in request body will not be updated.
     *
     * @param personGroupId Id referencing a particular person group.
     * @param updatePersonGroupOptionalParameter 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> updatePersonGroupWithServiceResponseAsync(String personGroupId, UpdatePersonGroupOptionalParameter updatePersonGroupOptionalParameter) {
        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 = updatePersonGroupOptionalParameter != null ? updatePersonGroupOptionalParameter.name() : null;
        final String userData = updatePersonGroupOptionalParameter != null ? updatePersonGroupOptionalParameter.userData() : null;
        NameAndUserDataContract body = new NameAndUserDataContract();
        body.withName(null);
        body.withUserData(null);
        String parameterizedHost = Joiner.on(", ").join("{AzureRegion}", this.client.azureRegion());

        return updatePersonGroupWithServiceResponseAsync(personGroupId, name, userData);
    }

    /**
     * Update an existing person group's display name and userData. The properties which does not appear in request body will not be updated.
     *
     * @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 {@link ServiceResponse} object if successful.
     */
    public Observable> updatePersonGroupWithServiceResponseAsync(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.updatePersonGroup(personGroupId, this.client.acceptLanguage(), body, parameterizedHost, this.client.userAgent())
            .flatMap(new Func1, Observable>>() {
                @Override
                public Observable> call(Response response) {
                    try {
                        ServiceResponse clientResponse = updatePersonGroupDelegate(response);
                        return Observable.just(clientResponse);
                    } catch (Throwable t) {
                        return Observable.error(t);
                    }
                }
            });
    }

    private ServiceResponse updatePersonGroupDelegate(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 the training status of a person group (completed or ongoing).
     *
     * @param personGroupId Id referencing a particular person group.
     * @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 TrainingStatus object if successful.
     */
    public TrainingStatus getTrainingStatus(String personGroupId) {
        return getTrainingStatusWithServiceResponseAsync(personGroupId).toBlocking().single().body();
    }

    /**
     * Retrieve the training status of a person group (completed or ongoing).
     *
     * @param personGroupId Id referencing a particular person group.
     * @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 getTrainingStatusAsync(String personGroupId, final ServiceCallback serviceCallback) {
        return ServiceFuture.fromResponse(getTrainingStatusWithServiceResponseAsync(personGroupId), serviceCallback);
    }

    /**
     * Retrieve the training status of a person group (completed or ongoing).
     *
     * @param personGroupId Id referencing a particular person group.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the TrainingStatus object
     */
    public Observable getTrainingStatusAsync(String personGroupId) {
        return getTrainingStatusWithServiceResponseAsync(personGroupId).map(new Func1, TrainingStatus>() {
            @Override
            public TrainingStatus call(ServiceResponse response) {
                return response.body();
            }
        });
    }

    /**
     * Retrieve the training status of a person group (completed or ongoing).
     *
     * @param personGroupId Id referencing a particular person group.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the TrainingStatus object
     */
    public Observable> getTrainingStatusWithServiceResponseAsync(String personGroupId) {
        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.getTrainingStatus(personGroupId, this.client.acceptLanguage(), parameterizedHost, this.client.userAgent())
            .flatMap(new Func1, Observable>>() {
                @Override
                public Observable> call(Response response) {
                    try {
                        ServiceResponse clientResponse = getTrainingStatusDelegate(response);
                        return Observable.just(clientResponse);
                    } catch (Throwable t) {
                        return Observable.error(t);
                    }
                }
            });
    }

    private ServiceResponse getTrainingStatusDelegate(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 person groups and their information.
     *
     * @param listPersonGroupOptionalParameter 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<PersonGroup> object if successful.
     */
    public List listPersonGroup(ListPersonGroupOptionalParameter listPersonGroupOptionalParameter) {
        return listPersonGroupWithServiceResponseAsync(listPersonGroupOptionalParameter).toBlocking().single().body();
    }

    /**
     * List person groups and their information.
     *
     * @param listPersonGroupOptionalParameter 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> listPersonGroupAsync(ListPersonGroupOptionalParameter listPersonGroupOptionalParameter, final ServiceCallback> serviceCallback) {
        return ServiceFuture.fromResponse(listPersonGroupWithServiceResponseAsync(listPersonGroupOptionalParameter), serviceCallback);
    }

    /**
     * List person groups and their information.
     *
     * @param listPersonGroupOptionalParameter 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<PersonGroup> object
     */
    public Observable> listPersonGroupAsync(ListPersonGroupOptionalParameter listPersonGroupOptionalParameter) {
        return listPersonGroupWithServiceResponseAsync(listPersonGroupOptionalParameter).map(new Func1>, List>() {
            @Override
            public List call(ServiceResponse> response) {
                return response.body();
            }
        });
    }

    /**
     * List person groups and their information.
     *
     * @param listPersonGroupOptionalParameter 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<PersonGroup> object
     */
    public Observable>> listPersonGroupWithServiceResponseAsync(ListPersonGroupOptionalParameter listPersonGroupOptionalParameter) {
        if (this.client.azureRegion() == null) {
            throw new IllegalArgumentException("Parameter this.client.azureRegion() is required and cannot be null.");
        }
        final String start = listPersonGroupOptionalParameter != null ? listPersonGroupOptionalParameter.start() : null;
        final Integer top = listPersonGroupOptionalParameter != null ? listPersonGroupOptionalParameter.top() : null;
        String parameterizedHost = Joiner.on(", ").join("{AzureRegion}", this.client.azureRegion());

        return listPersonGroupWithServiceResponseAsync(start, top);
    }

    /**
     * List person groups and their information.
     *
     * @param start List person groups from the least personGroupId greater than the "start".
     * @param top The number of person groups to list.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the List<PersonGroup> object
     */
    public Observable>> listPersonGroupWithServiceResponseAsync(String start, Integer top) {
        if (this.client.azureRegion() == null) {
            throw new IllegalArgumentException("Parameter this.client.azureRegion() is required and cannot be null.");
        }
        String parameterizedHost = Joiner.on(", ").join("{AzureRegion}", this.client.azureRegion());
        return service.listPersonGroup(start, top, this.client.acceptLanguage(), parameterizedHost, this.client.userAgent())
            .flatMap(new Func1, Observable>>>() {
                @Override
                public Observable>> call(Response response) {
                    try {
                        ServiceResponse> clientResponse = listPersonGroupDelegate(response);
                        return Observable.just(clientResponse);
                    } catch (Throwable t) {
                        return Observable.error(t);
                    }
                }
            });
    }

    private ServiceResponse> listPersonGroupDelegate(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);
    }

    /**
     * Queue a person group training task, the training task may not be started immediately.
     *
     * @param personGroupId Id referencing a particular person group.
     * @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 train(String personGroupId) {
        trainWithServiceResponseAsync(personGroupId).toBlocking().single().body();
    }

    /**
     * Queue a person group training task, the training task may not be started immediately.
     *
     * @param personGroupId Id referencing a particular person group.
     * @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 trainAsync(String personGroupId, final ServiceCallback serviceCallback) {
        return ServiceFuture.fromResponse(trainWithServiceResponseAsync(personGroupId), serviceCallback);
    }

    /**
     * Queue a person group training task, the training task may not be started immediately.
     *
     * @param personGroupId Id referencing a particular person group.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the {@link ServiceResponse} object if successful.
     */
    public Observable trainAsync(String personGroupId) {
        return trainWithServiceResponseAsync(personGroupId).map(new Func1, Void>() {
            @Override
            public Void call(ServiceResponse response) {
                return response.body();
            }
        });
    }

    /**
     * Queue a person group training task, the training task may not be started immediately.
     *
     * @param personGroupId Id referencing a particular person group.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the {@link ServiceResponse} object if successful.
     */
    public Observable> trainWithServiceResponseAsync(String personGroupId) {
        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.train(personGroupId, this.client.acceptLanguage(), parameterizedHost, this.client.userAgent())
            .flatMap(new Func1, Observable>>() {
                @Override
                public Observable> call(Response response) {
                    try {
                        ServiceResponse clientResponse = trainDelegate(response);
                        return Observable.just(clientResponse);
                    } catch (Throwable t) {
                        return Observable.error(t);
                    }
                }
            });
    }

    private ServiceResponse trainDelegate(Response response) throws APIErrorException, IOException, IllegalArgumentException {
        return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter())
                .register(202, new TypeToken() { }.getType())
                .registerError(APIErrorException.class)
                .build(response);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy