001
002package com.commercetools.api.client;
003
004import java.net.URI;
005import java.time.Duration;
006import java.util.ArrayList;
007import java.util.Collection;
008import java.util.List;
009import java.util.concurrent.CompletableFuture;
010import java.util.function.Function;
011import java.util.function.Supplier;
012import java.util.stream.Collectors;
013
014import io.vrap.rmf.base.client.*;
015import io.vrap.rmf.base.client.utils.Generated;
016
017import org.apache.commons.lang3.builder.EqualsBuilder;
018import org.apache.commons.lang3.builder.HashCodeBuilder;
019
020/**
021 *  <p>Check if Product Types exist. Responds with a <code>200 OK</code> status if any Product Types match the Query Predicate, or <code>404 Not Found</code> otherwise.</p>
022 *
023 * <hr>
024 * <div class=code-example>
025 * <pre><code class='java'>{@code
026 *   CompletableFuture<ApiHttpResponse<com.fasterxml.jackson.databind.JsonNode>> result = apiRoot
027 *            .withProjectKey("{projectKey}")
028 *            .productTypes()
029 *            .head()
030 *            .execute()
031 * }</code></pre>
032 * </div>
033 */
034@Generated(value = "io.vrap.rmf.codegen.rendering.CoreCodeGenerator", comments = "https://github.com/commercetools/rmf-codegen")
035public class ByProjectKeyProductTypesHead
036        extends ApiMethod<ByProjectKeyProductTypesHead, com.fasterxml.jackson.databind.JsonNode>
037        implements com.commercetools.api.client.ErrorableTrait<ByProjectKeyProductTypesHead>,
038        com.commercetools.api.client.Deprecatable200Trait<ByProjectKeyProductTypesHead> {
039
040    private String projectKey;
041
042    public ByProjectKeyProductTypesHead(final ApiHttpClient apiHttpClient, String projectKey) {
043        super(apiHttpClient);
044        this.projectKey = projectKey;
045    }
046
047    public ByProjectKeyProductTypesHead(ByProjectKeyProductTypesHead t) {
048        super(t);
049        this.projectKey = t.projectKey;
050    }
051
052    @Override
053    protected ApiHttpRequest buildHttpRequest() {
054        List<String> params = new ArrayList<>(getQueryParamUriStrings());
055        String httpRequestPath = String.format("%s/product-types", this.projectKey);
056        if (!params.isEmpty()) {
057            httpRequestPath += "?" + String.join("&", params);
058        }
059        return new ApiHttpRequest(ApiHttpMethod.HEAD, URI.create(httpRequestPath), getHeaders(), null);
060    }
061
062    @Override
063    public ApiHttpResponse<com.fasterxml.jackson.databind.JsonNode> executeBlocking(final ApiHttpClient client,
064            final Duration timeout) {
065        return executeBlocking(client, timeout, com.fasterxml.jackson.databind.JsonNode.class);
066    }
067
068    @Override
069    public CompletableFuture<ApiHttpResponse<com.fasterxml.jackson.databind.JsonNode>> execute(
070            final ApiHttpClient client) {
071        return execute(client, com.fasterxml.jackson.databind.JsonNode.class);
072    }
073
074    public String getProjectKey() {
075        return this.projectKey;
076    }
077
078    public List<String> getWhere() {
079        return this.getQueryParam("where");
080    }
081
082    public void setProjectKey(final String projectKey) {
083        this.projectKey = projectKey;
084    }
085
086    /**
087     * set where with the specified value
088     * @param where value to be set
089     * @param <TValue> value type
090     * @return ByProjectKeyProductTypesHead
091     */
092    public <TValue> ByProjectKeyProductTypesHead withWhere(final TValue where) {
093        return copy().withQueryParam("where", where);
094    }
095
096    /**
097     * add additional where query parameter
098     * @param where value to be added
099     * @param <TValue> value type
100     * @return ByProjectKeyProductTypesHead
101     */
102    public <TValue> ByProjectKeyProductTypesHead addWhere(final TValue where) {
103        return copy().addQueryParam("where", where);
104    }
105
106    /**
107     * set where with the specified value
108     * @param supplier supplier for the value to be set
109     * @return ByProjectKeyProductTypesHead
110     */
111    public ByProjectKeyProductTypesHead withWhere(final Supplier<String> supplier) {
112        return copy().withQueryParam("where", supplier.get());
113    }
114
115    /**
116     * add additional where query parameter
117     * @param supplier supplier for the value to be added
118     * @return ByProjectKeyProductTypesHead
119     */
120    public ByProjectKeyProductTypesHead addWhere(final Supplier<String> supplier) {
121        return copy().addQueryParam("where", supplier.get());
122    }
123
124    /**
125     * set where with the specified value
126     * @param op builder for the value to be set
127     * @return ByProjectKeyProductTypesHead
128     */
129    public ByProjectKeyProductTypesHead withWhere(final Function<StringBuilder, StringBuilder> op) {
130        return copy().withQueryParam("where", op.apply(new StringBuilder()));
131    }
132
133    /**
134     * add additional where query parameter
135     * @param op builder for the value to be added
136     * @return ByProjectKeyProductTypesHead
137     */
138    public ByProjectKeyProductTypesHead addWhere(final Function<StringBuilder, StringBuilder> op) {
139        return copy().addQueryParam("where", op.apply(new StringBuilder()));
140    }
141
142    /**
143     * set where with the specified values
144     * @param where values to be set
145     * @param <TValue> value type
146     * @return ByProjectKeyProductTypesHead
147     */
148    public <TValue> ByProjectKeyProductTypesHead withWhere(final Collection<TValue> where) {
149        return copy().withoutQueryParam("where")
150                .addQueryParams(
151                    where.stream().map(s -> new ParamEntry<>("where", s.toString())).collect(Collectors.toList()));
152    }
153
154    /**
155     * add additional where query parameters
156     * @param where values to be added
157     * @param <TValue> value type
158     * @return ByProjectKeyProductTypesHead
159     */
160    public <TValue> ByProjectKeyProductTypesHead addWhere(final Collection<TValue> where) {
161        return copy().addQueryParams(
162            where.stream().map(s -> new ParamEntry<>("where", s.toString())).collect(Collectors.toList()));
163    }
164
165    @Override
166    public boolean equals(Object o) {
167        if (this == o)
168            return true;
169
170        if (o == null || getClass() != o.getClass())
171            return false;
172
173        ByProjectKeyProductTypesHead that = (ByProjectKeyProductTypesHead) o;
174
175        return new EqualsBuilder().append(projectKey, that.projectKey).isEquals();
176    }
177
178    @Override
179    public int hashCode() {
180        return new HashCodeBuilder(17, 37).append(projectKey).toHashCode();
181    }
182
183    @Override
184    protected ByProjectKeyProductTypesHead copy() {
185        return new ByProjectKeyProductTypesHead(this);
186    }
187}