001
002package com.commercetools.ml.client;
003
004import java.net.URI;
005import java.nio.charset.StandardCharsets;
006import java.time.Duration;
007import java.util.ArrayList;
008import java.util.List;
009import java.util.concurrent.CompletableFuture;
010
011import io.vrap.rmf.base.client.*;
012import io.vrap.rmf.base.client.utils.Generated;
013
014import org.apache.commons.lang3.builder.EqualsBuilder;
015import org.apache.commons.lang3.builder.HashCodeBuilder;
016
017/**
018 *
019 *
020 * <hr>
021 * <div class=code-example>
022 * <pre><code class='java'>{@code
023 *   CompletableFuture<ApiHttpResponse<com.commercetools.ml.models.common.TaskToken>> result = apiRoot
024 *            .withProjectKey("{projectKey}")
025 *            .similarities()
026 *            .products()
027 *            .post("")
028 *            .execute()
029 * }</code></pre>
030 * </div>
031 */
032@Generated(value = "io.vrap.rmf.codegen.rendering.CoreCodeGenerator", comments = "https://github.com/commercetools/rmf-codegen")
033public class ByProjectKeySimilaritiesProductsPostString extends
034        StringBodyApiMethod<ByProjectKeySimilaritiesProductsPostString, com.commercetools.ml.models.common.TaskToken> {
035
036    private String projectKey;
037
038    private String similarProductSearchRequest;
039
040    public ByProjectKeySimilaritiesProductsPostString(final ApiHttpClient apiHttpClient, String projectKey,
041            String similarProductSearchRequest) {
042        super(apiHttpClient);
043        this.projectKey = projectKey;
044        this.similarProductSearchRequest = similarProductSearchRequest;
045    }
046
047    public ByProjectKeySimilaritiesProductsPostString(ByProjectKeySimilaritiesProductsPostString t) {
048        super(t);
049        this.projectKey = t.projectKey;
050        this.similarProductSearchRequest = t.similarProductSearchRequest;
051    }
052
053    @Override
054    protected ApiHttpRequest buildHttpRequest() {
055        List<String> params = new ArrayList<>(getQueryParamUriStrings());
056        String httpRequestPath = String.format("%s/similarities/products", this.projectKey);
057        if (!params.isEmpty()) {
058            httpRequestPath += "?" + String.join("&", params);
059        }
060        return new ApiHttpRequest(ApiHttpMethod.POST, URI.create(httpRequestPath), getHeaders(),
061            similarProductSearchRequest.getBytes(StandardCharsets.UTF_8));
062
063    }
064
065    @Override
066    public ApiHttpResponse<com.commercetools.ml.models.common.TaskToken> executeBlocking(final ApiHttpClient client,
067            final Duration timeout) {
068        return executeBlocking(client, timeout, com.commercetools.ml.models.common.TaskToken.class);
069    }
070
071    @Override
072    public CompletableFuture<ApiHttpResponse<com.commercetools.ml.models.common.TaskToken>> execute(
073            final ApiHttpClient client) {
074        return execute(client, com.commercetools.ml.models.common.TaskToken.class);
075    }
076
077    public String getProjectKey() {
078        return this.projectKey;
079    }
080
081    public void setProjectKey(final String projectKey) {
082        this.projectKey = projectKey;
083    }
084
085    public String getBody() {
086        return similarProductSearchRequest;
087    }
088
089    public ByProjectKeySimilaritiesProductsPostString withBody(String similarProductSearchRequest) {
090        ByProjectKeySimilaritiesProductsPostString t = copy();
091        t.similarProductSearchRequest = similarProductSearchRequest;
092        return t;
093    }
094
095    @Override
096    public boolean equals(Object o) {
097        if (this == o)
098            return true;
099
100        if (o == null || getClass() != o.getClass())
101            return false;
102
103        ByProjectKeySimilaritiesProductsPostString that = (ByProjectKeySimilaritiesProductsPostString) o;
104
105        return new EqualsBuilder().append(projectKey, that.projectKey)
106                .append(similarProductSearchRequest, that.similarProductSearchRequest)
107                .isEquals();
108    }
109
110    @Override
111    public int hashCode() {
112        return new HashCodeBuilder(17, 37).append(projectKey).append(similarProductSearchRequest).toHashCode();
113    }
114
115    @Override
116    protected ByProjectKeySimilaritiesProductsPostString copy() {
117        return new ByProjectKeySimilaritiesProductsPostString(this);
118    }
119}