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 *
022 *
023 * <hr>
024 * <div class=code-example>
025 * <pre><code class='java'>{@code
026 *   CompletableFuture<ApiHttpResponse<com.commercetools.api.models.product_selection.ProductSelection>> result = apiRoot
027 *            .withProjectKey("{projectKey}")
028 *            .productSelections()
029 *            .withId("{ID}")
030 *            .get()
031 *            .execute()
032 * }</code></pre>
033 * </div>
034 */
035@Generated(value = "io.vrap.rmf.codegen.rendering.CoreCodeGenerator", comments = "https://github.com/commercetools/rmf-codegen")
036public class ByProjectKeyProductSelectionsByIDGet extends
037        ApiMethod<ByProjectKeyProductSelectionsByIDGet, com.commercetools.api.models.product_selection.ProductSelection>
038        implements com.commercetools.api.client.ExpandableTrait<ByProjectKeyProductSelectionsByIDGet>,
039        com.commercetools.api.client.ErrorableTrait<ByProjectKeyProductSelectionsByIDGet>,
040        com.commercetools.api.client.Deprecatable200Trait<ByProjectKeyProductSelectionsByIDGet> {
041
042    private String projectKey;
043    private String ID;
044
045    public ByProjectKeyProductSelectionsByIDGet(final ApiHttpClient apiHttpClient, String projectKey, String ID) {
046        super(apiHttpClient);
047        this.projectKey = projectKey;
048        this.ID = ID;
049    }
050
051    public ByProjectKeyProductSelectionsByIDGet(ByProjectKeyProductSelectionsByIDGet t) {
052        super(t);
053        this.projectKey = t.projectKey;
054        this.ID = t.ID;
055    }
056
057    @Override
058    protected ApiHttpRequest buildHttpRequest() {
059        List<String> params = new ArrayList<>(getQueryParamUriStrings());
060        String httpRequestPath = String.format("%s/product-selections/%s", this.projectKey, this.ID);
061        if (!params.isEmpty()) {
062            httpRequestPath += "?" + String.join("&", params);
063        }
064        return new ApiHttpRequest(ApiHttpMethod.GET, URI.create(httpRequestPath), getHeaders(), null);
065    }
066
067    @Override
068    public ApiHttpResponse<com.commercetools.api.models.product_selection.ProductSelection> executeBlocking(
069            final ApiHttpClient client, final Duration timeout) {
070        return executeBlocking(client, timeout, com.commercetools.api.models.product_selection.ProductSelection.class);
071    }
072
073    @Override
074    public CompletableFuture<ApiHttpResponse<com.commercetools.api.models.product_selection.ProductSelection>> execute(
075            final ApiHttpClient client) {
076        return execute(client, com.commercetools.api.models.product_selection.ProductSelection.class);
077    }
078
079    public String getProjectKey() {
080        return this.projectKey;
081    }
082
083    public String getID() {
084        return this.ID;
085    }
086
087    public List<String> getExpand() {
088        return this.getQueryParam("expand");
089    }
090
091    public void setProjectKey(final String projectKey) {
092        this.projectKey = projectKey;
093    }
094
095    public void setID(final String ID) {
096        this.ID = ID;
097    }
098
099    /**
100     * set expand with the specified value
101     * @param expand value to be set
102     * @param <TValue> value type
103     * @return ByProjectKeyProductSelectionsByIDGet
104     */
105    public <TValue> ByProjectKeyProductSelectionsByIDGet withExpand(final TValue expand) {
106        return copy().withQueryParam("expand", expand);
107    }
108
109    /**
110     * add additional expand query parameter
111     * @param expand value to be added
112     * @param <TValue> value type
113     * @return ByProjectKeyProductSelectionsByIDGet
114     */
115    public <TValue> ByProjectKeyProductSelectionsByIDGet addExpand(final TValue expand) {
116        return copy().addQueryParam("expand", expand);
117    }
118
119    /**
120     * set expand with the specified value
121     * @param supplier supplier for the value to be set
122     * @return ByProjectKeyProductSelectionsByIDGet
123     */
124    public ByProjectKeyProductSelectionsByIDGet withExpand(final Supplier<String> supplier) {
125        return copy().withQueryParam("expand", supplier.get());
126    }
127
128    /**
129     * add additional expand query parameter
130     * @param supplier supplier for the value to be added
131     * @return ByProjectKeyProductSelectionsByIDGet
132     */
133    public ByProjectKeyProductSelectionsByIDGet addExpand(final Supplier<String> supplier) {
134        return copy().addQueryParam("expand", supplier.get());
135    }
136
137    /**
138     * set expand with the specified value
139     * @param op builder for the value to be set
140     * @return ByProjectKeyProductSelectionsByIDGet
141     */
142    public ByProjectKeyProductSelectionsByIDGet withExpand(final Function<StringBuilder, StringBuilder> op) {
143        return copy().withQueryParam("expand", op.apply(new StringBuilder()));
144    }
145
146    /**
147     * add additional expand query parameter
148     * @param op builder for the value to be added
149     * @return ByProjectKeyProductSelectionsByIDGet
150     */
151    public ByProjectKeyProductSelectionsByIDGet addExpand(final Function<StringBuilder, StringBuilder> op) {
152        return copy().addQueryParam("expand", op.apply(new StringBuilder()));
153    }
154
155    /**
156     * set expand with the specified values
157     * @param expand values to be set
158     * @param <TValue> value type
159     * @return ByProjectKeyProductSelectionsByIDGet
160     */
161    public <TValue> ByProjectKeyProductSelectionsByIDGet withExpand(final Collection<TValue> expand) {
162        return copy().withoutQueryParam("expand")
163                .addQueryParams(
164                    expand.stream().map(s -> new ParamEntry<>("expand", s.toString())).collect(Collectors.toList()));
165    }
166
167    /**
168     * add additional expand query parameters
169     * @param expand values to be added
170     * @param <TValue> value type
171     * @return ByProjectKeyProductSelectionsByIDGet
172     */
173    public <TValue> ByProjectKeyProductSelectionsByIDGet addExpand(final Collection<TValue> expand) {
174        return copy().addQueryParams(
175            expand.stream().map(s -> new ParamEntry<>("expand", s.toString())).collect(Collectors.toList()));
176    }
177
178    @Override
179    public boolean equals(Object o) {
180        if (this == o)
181            return true;
182
183        if (o == null || getClass() != o.getClass())
184            return false;
185
186        ByProjectKeyProductSelectionsByIDGet that = (ByProjectKeyProductSelectionsByIDGet) o;
187
188        return new EqualsBuilder().append(projectKey, that.projectKey).append(ID, that.ID).isEquals();
189    }
190
191    @Override
192    public int hashCode() {
193        return new HashCodeBuilder(17, 37).append(projectKey).append(ID).toHashCode();
194    }
195
196    @Override
197    protected ByProjectKeyProductSelectionsByIDGet copy() {
198        return new ByProjectKeyProductSelectionsByIDGet(this);
199    }
200}