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>Retrieves all the ShippingMethods that can ship to the given Location for an OrderEdit.</p>
022 *  <p>If the OrderEdit preview cannot be generated, an EditPreviewFailed error is returned.</p>
023 *
024 * <hr>
025 * <div class=code-example>
026 * <pre><code class='java'>{@code
027 *   CompletableFuture<ApiHttpResponse<com.commercetools.api.models.shipping_method.ShippingMethodPagedQueryResponse>> result = apiRoot
028 *            .withProjectKey("{projectKey}")
029 *            .shippingMethods()
030 *            .matchingOrderedit()
031 *            .get()
032 *            .withOrderEditId(orderEditId)
033 *            .withCountry(country)
034 *            .execute()
035 * }</code></pre>
036 * </div>
037 */
038@Generated(value = "io.vrap.rmf.codegen.rendering.CoreCodeGenerator", comments = "https://github.com/commercetools/rmf-codegen")
039public class ByProjectKeyShippingMethodsMatchingOrdereditGet extends
040        ApiMethod<ByProjectKeyShippingMethodsMatchingOrdereditGet, com.commercetools.api.models.shipping_method.ShippingMethodPagedQueryResponse>
041        implements com.commercetools.api.client.ErrorableTrait<ByProjectKeyShippingMethodsMatchingOrdereditGet>,
042        com.commercetools.api.client.Deprecatable200Trait<ByProjectKeyShippingMethodsMatchingOrdereditGet> {
043
044    private String projectKey;
045
046    public ByProjectKeyShippingMethodsMatchingOrdereditGet(final ApiHttpClient apiHttpClient, String projectKey) {
047        super(apiHttpClient);
048        this.projectKey = projectKey;
049    }
050
051    public ByProjectKeyShippingMethodsMatchingOrdereditGet(ByProjectKeyShippingMethodsMatchingOrdereditGet t) {
052        super(t);
053        this.projectKey = t.projectKey;
054    }
055
056    @Override
057    protected ApiHttpRequest buildHttpRequest() {
058        List<String> params = new ArrayList<>(getQueryParamUriStrings());
059        String httpRequestPath = String.format("%s/shipping-methods/matching-orderedit", this.projectKey);
060        if (!params.isEmpty()) {
061            httpRequestPath += "?" + String.join("&", params);
062        }
063        return new ApiHttpRequest(ApiHttpMethod.GET, URI.create(httpRequestPath), getHeaders(), null);
064    }
065
066    @Override
067    public ApiHttpResponse<com.commercetools.api.models.shipping_method.ShippingMethodPagedQueryResponse> executeBlocking(
068            final ApiHttpClient client, final Duration timeout) {
069        return executeBlocking(client, timeout,
070            com.commercetools.api.models.shipping_method.ShippingMethodPagedQueryResponse.class);
071    }
072
073    @Override
074    public CompletableFuture<ApiHttpResponse<com.commercetools.api.models.shipping_method.ShippingMethodPagedQueryResponse>> execute(
075            final ApiHttpClient client) {
076        return execute(client, com.commercetools.api.models.shipping_method.ShippingMethodPagedQueryResponse.class);
077    }
078
079    public String getProjectKey() {
080        return this.projectKey;
081    }
082
083    public List<String> getOrderEditId() {
084        return this.getQueryParam("orderEditId");
085    }
086
087    public List<String> getCountry() {
088        return this.getQueryParam("country");
089    }
090
091    public List<String> getState() {
092        return this.getQueryParam("state");
093    }
094
095    public void setProjectKey(final String projectKey) {
096        this.projectKey = projectKey;
097    }
098
099    /**
100     * set orderEditId with the specified value
101     * @param orderEditId value to be set
102     * @param <TValue> value type
103     * @return ByProjectKeyShippingMethodsMatchingOrdereditGet
104     */
105    public <TValue> ByProjectKeyShippingMethodsMatchingOrdereditGet withOrderEditId(final TValue orderEditId) {
106        return copy().withQueryParam("orderEditId", orderEditId);
107    }
108
109    /**
110     * add additional orderEditId query parameter
111     * @param orderEditId value to be added
112     * @param <TValue> value type
113     * @return ByProjectKeyShippingMethodsMatchingOrdereditGet
114     */
115    public <TValue> ByProjectKeyShippingMethodsMatchingOrdereditGet addOrderEditId(final TValue orderEditId) {
116        return copy().addQueryParam("orderEditId", orderEditId);
117    }
118
119    /**
120     * set orderEditId with the specified value
121     * @param supplier supplier for the value to be set
122     * @return ByProjectKeyShippingMethodsMatchingOrdereditGet
123     */
124    public ByProjectKeyShippingMethodsMatchingOrdereditGet withOrderEditId(final Supplier<String> supplier) {
125        return copy().withQueryParam("orderEditId", supplier.get());
126    }
127
128    /**
129     * add additional orderEditId query parameter
130     * @param supplier supplier for the value to be added
131     * @return ByProjectKeyShippingMethodsMatchingOrdereditGet
132     */
133    public ByProjectKeyShippingMethodsMatchingOrdereditGet addOrderEditId(final Supplier<String> supplier) {
134        return copy().addQueryParam("orderEditId", supplier.get());
135    }
136
137    /**
138     * set orderEditId with the specified value
139     * @param op builder for the value to be set
140     * @return ByProjectKeyShippingMethodsMatchingOrdereditGet
141     */
142    public ByProjectKeyShippingMethodsMatchingOrdereditGet withOrderEditId(
143            final Function<StringBuilder, StringBuilder> op) {
144        return copy().withQueryParam("orderEditId", op.apply(new StringBuilder()));
145    }
146
147    /**
148     * add additional orderEditId query parameter
149     * @param op builder for the value to be added
150     * @return ByProjectKeyShippingMethodsMatchingOrdereditGet
151     */
152    public ByProjectKeyShippingMethodsMatchingOrdereditGet addOrderEditId(
153            final Function<StringBuilder, StringBuilder> op) {
154        return copy().addQueryParam("orderEditId", op.apply(new StringBuilder()));
155    }
156
157    /**
158     * set orderEditId with the specified values
159     * @param orderEditId values to be set
160     * @param <TValue> value type
161     * @return ByProjectKeyShippingMethodsMatchingOrdereditGet
162     */
163    public <TValue> ByProjectKeyShippingMethodsMatchingOrdereditGet withOrderEditId(
164            final Collection<TValue> orderEditId) {
165        return copy().withoutQueryParam("orderEditId")
166                .addQueryParams(orderEditId.stream()
167                        .map(s -> new ParamEntry<>("orderEditId", s.toString()))
168                        .collect(Collectors.toList()));
169    }
170
171    /**
172     * add additional orderEditId query parameters
173     * @param orderEditId values to be added
174     * @param <TValue> value type
175     * @return ByProjectKeyShippingMethodsMatchingOrdereditGet
176     */
177    public <TValue> ByProjectKeyShippingMethodsMatchingOrdereditGet addOrderEditId(
178            final Collection<TValue> orderEditId) {
179        return copy().addQueryParams(
180            orderEditId.stream().map(s -> new ParamEntry<>("orderEditId", s.toString())).collect(Collectors.toList()));
181    }
182
183    /**
184     * set country with the specified value
185     * @param country value to be set
186     * @param <TValue> value type
187     * @return ByProjectKeyShippingMethodsMatchingOrdereditGet
188     */
189    public <TValue> ByProjectKeyShippingMethodsMatchingOrdereditGet withCountry(final TValue country) {
190        return copy().withQueryParam("country", country);
191    }
192
193    /**
194     * add additional country query parameter
195     * @param country value to be added
196     * @param <TValue> value type
197     * @return ByProjectKeyShippingMethodsMatchingOrdereditGet
198     */
199    public <TValue> ByProjectKeyShippingMethodsMatchingOrdereditGet addCountry(final TValue country) {
200        return copy().addQueryParam("country", country);
201    }
202
203    /**
204     * set country with the specified value
205     * @param supplier supplier for the value to be set
206     * @return ByProjectKeyShippingMethodsMatchingOrdereditGet
207     */
208    public ByProjectKeyShippingMethodsMatchingOrdereditGet withCountry(final Supplier<String> supplier) {
209        return copy().withQueryParam("country", supplier.get());
210    }
211
212    /**
213     * add additional country query parameter
214     * @param supplier supplier for the value to be added
215     * @return ByProjectKeyShippingMethodsMatchingOrdereditGet
216     */
217    public ByProjectKeyShippingMethodsMatchingOrdereditGet addCountry(final Supplier<String> supplier) {
218        return copy().addQueryParam("country", supplier.get());
219    }
220
221    /**
222     * set country with the specified value
223     * @param op builder for the value to be set
224     * @return ByProjectKeyShippingMethodsMatchingOrdereditGet
225     */
226    public ByProjectKeyShippingMethodsMatchingOrdereditGet withCountry(
227            final Function<StringBuilder, StringBuilder> op) {
228        return copy().withQueryParam("country", op.apply(new StringBuilder()));
229    }
230
231    /**
232     * add additional country query parameter
233     * @param op builder for the value to be added
234     * @return ByProjectKeyShippingMethodsMatchingOrdereditGet
235     */
236    public ByProjectKeyShippingMethodsMatchingOrdereditGet addCountry(final Function<StringBuilder, StringBuilder> op) {
237        return copy().addQueryParam("country", op.apply(new StringBuilder()));
238    }
239
240    /**
241     * set country with the specified values
242     * @param country values to be set
243     * @param <TValue> value type
244     * @return ByProjectKeyShippingMethodsMatchingOrdereditGet
245     */
246    public <TValue> ByProjectKeyShippingMethodsMatchingOrdereditGet withCountry(final Collection<TValue> country) {
247        return copy().withoutQueryParam("country")
248                .addQueryParams(
249                    country.stream().map(s -> new ParamEntry<>("country", s.toString())).collect(Collectors.toList()));
250    }
251
252    /**
253     * add additional country query parameters
254     * @param country values to be added
255     * @param <TValue> value type
256     * @return ByProjectKeyShippingMethodsMatchingOrdereditGet
257     */
258    public <TValue> ByProjectKeyShippingMethodsMatchingOrdereditGet addCountry(final Collection<TValue> country) {
259        return copy().addQueryParams(
260            country.stream().map(s -> new ParamEntry<>("country", s.toString())).collect(Collectors.toList()));
261    }
262
263    /**
264     * set state with the specified value
265     * @param state value to be set
266     * @param <TValue> value type
267     * @return ByProjectKeyShippingMethodsMatchingOrdereditGet
268     */
269    public <TValue> ByProjectKeyShippingMethodsMatchingOrdereditGet withState(final TValue state) {
270        return copy().withQueryParam("state", state);
271    }
272
273    /**
274     * add additional state query parameter
275     * @param state value to be added
276     * @param <TValue> value type
277     * @return ByProjectKeyShippingMethodsMatchingOrdereditGet
278     */
279    public <TValue> ByProjectKeyShippingMethodsMatchingOrdereditGet addState(final TValue state) {
280        return copy().addQueryParam("state", state);
281    }
282
283    /**
284     * set state with the specified value
285     * @param supplier supplier for the value to be set
286     * @return ByProjectKeyShippingMethodsMatchingOrdereditGet
287     */
288    public ByProjectKeyShippingMethodsMatchingOrdereditGet withState(final Supplier<String> supplier) {
289        return copy().withQueryParam("state", supplier.get());
290    }
291
292    /**
293     * add additional state query parameter
294     * @param supplier supplier for the value to be added
295     * @return ByProjectKeyShippingMethodsMatchingOrdereditGet
296     */
297    public ByProjectKeyShippingMethodsMatchingOrdereditGet addState(final Supplier<String> supplier) {
298        return copy().addQueryParam("state", supplier.get());
299    }
300
301    /**
302     * set state with the specified value
303     * @param op builder for the value to be set
304     * @return ByProjectKeyShippingMethodsMatchingOrdereditGet
305     */
306    public ByProjectKeyShippingMethodsMatchingOrdereditGet withState(final Function<StringBuilder, StringBuilder> op) {
307        return copy().withQueryParam("state", op.apply(new StringBuilder()));
308    }
309
310    /**
311     * add additional state query parameter
312     * @param op builder for the value to be added
313     * @return ByProjectKeyShippingMethodsMatchingOrdereditGet
314     */
315    public ByProjectKeyShippingMethodsMatchingOrdereditGet addState(final Function<StringBuilder, StringBuilder> op) {
316        return copy().addQueryParam("state", op.apply(new StringBuilder()));
317    }
318
319    /**
320     * set state with the specified values
321     * @param state values to be set
322     * @param <TValue> value type
323     * @return ByProjectKeyShippingMethodsMatchingOrdereditGet
324     */
325    public <TValue> ByProjectKeyShippingMethodsMatchingOrdereditGet withState(final Collection<TValue> state) {
326        return copy().withoutQueryParam("state")
327                .addQueryParams(
328                    state.stream().map(s -> new ParamEntry<>("state", s.toString())).collect(Collectors.toList()));
329    }
330
331    /**
332     * add additional state query parameters
333     * @param state values to be added
334     * @param <TValue> value type
335     * @return ByProjectKeyShippingMethodsMatchingOrdereditGet
336     */
337    public <TValue> ByProjectKeyShippingMethodsMatchingOrdereditGet addState(final Collection<TValue> state) {
338        return copy().addQueryParams(
339            state.stream().map(s -> new ParamEntry<>("state", s.toString())).collect(Collectors.toList()));
340    }
341
342    @Override
343    public boolean equals(Object o) {
344        if (this == o)
345            return true;
346
347        if (o == null || getClass() != o.getClass())
348            return false;
349
350        ByProjectKeyShippingMethodsMatchingOrdereditGet that = (ByProjectKeyShippingMethodsMatchingOrdereditGet) o;
351
352        return new EqualsBuilder().append(projectKey, that.projectKey).isEquals();
353    }
354
355    @Override
356    public int hashCode() {
357        return new HashCodeBuilder(17, 37).append(projectKey).toHashCode();
358    }
359
360    @Override
361    protected ByProjectKeyShippingMethodsMatchingOrdereditGet copy() {
362        return new ByProjectKeyShippingMethodsMatchingOrdereditGet(this);
363    }
364}