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