001
002package com.commercetools.api.client;
003
004import java.net.URI;
005import java.nio.charset.StandardCharsets;
006import java.time.Duration;
007import java.util.ArrayList;
008import java.util.Collection;
009import java.util.List;
010import java.util.concurrent.CompletableFuture;
011import java.util.function.Function;
012import java.util.function.Supplier;
013import java.util.stream.Collectors;
014
015import io.vrap.rmf.base.client.*;
016import io.vrap.rmf.base.client.utils.Generated;
017
018import org.apache.commons.lang3.builder.EqualsBuilder;
019import org.apache.commons.lang3.builder.HashCodeBuilder;
020
021/**
022 *  <p>If the <code>anonymousCart</code> field is set on the CustomerDraft, then the newly created Customer will be assigned to that Cart. Similarly, if the <code>anonymousId</code> field is set, the Customer will be set on all Carts, Orders, ShoppingLists and Payments with the same <code>anonymousId</code>. Creating a Customer produces the CustomerCreated Message.</p>
023 *
024 * <hr>
025 * <div class=code-example>
026 * <pre><code class='java'>{@code
027 *   CompletableFuture<ApiHttpResponse<com.commercetools.api.models.customer.CustomerSignInResult>> result = apiRoot
028 *            .withProjectKey("{projectKey}")
029 *            .customers()
030 *            .post("")
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 ByProjectKeyCustomersPostString extends
037        StringBodyApiMethod<ByProjectKeyCustomersPostString, com.commercetools.api.models.customer.CustomerSignInResult>
038        implements com.commercetools.api.client.ExpandableTrait<ByProjectKeyCustomersPostString>,
039        com.commercetools.api.client.Deprecatable201Trait<ByProjectKeyCustomersPostString>,
040        com.commercetools.api.client.ErrorableTrait<ByProjectKeyCustomersPostString> {
041
042    private String projectKey;
043
044    private String customerDraft;
045
046    public ByProjectKeyCustomersPostString(final ApiHttpClient apiHttpClient, String projectKey, String customerDraft) {
047        super(apiHttpClient);
048        this.projectKey = projectKey;
049        this.customerDraft = customerDraft;
050    }
051
052    public ByProjectKeyCustomersPostString(ByProjectKeyCustomersPostString t) {
053        super(t);
054        this.projectKey = t.projectKey;
055        this.customerDraft = t.customerDraft;
056    }
057
058    @Override
059    protected ApiHttpRequest buildHttpRequest() {
060        List<String> params = new ArrayList<>(getQueryParamUriStrings());
061        String httpRequestPath = String.format("%s/customers", this.projectKey);
062        if (!params.isEmpty()) {
063            httpRequestPath += "?" + String.join("&", params);
064        }
065        return new ApiHttpRequest(ApiHttpMethod.POST, URI.create(httpRequestPath), getHeaders(),
066            customerDraft.getBytes(StandardCharsets.UTF_8));
067
068    }
069
070    @Override
071    public ApiHttpResponse<com.commercetools.api.models.customer.CustomerSignInResult> executeBlocking(
072            final ApiHttpClient client, final Duration timeout) {
073        return executeBlocking(client, timeout, com.commercetools.api.models.customer.CustomerSignInResult.class);
074    }
075
076    @Override
077    public CompletableFuture<ApiHttpResponse<com.commercetools.api.models.customer.CustomerSignInResult>> execute(
078            final ApiHttpClient client) {
079        return execute(client, com.commercetools.api.models.customer.CustomerSignInResult.class);
080    }
081
082    public String getProjectKey() {
083        return this.projectKey;
084    }
085
086    public List<String> getExpand() {
087        return this.getQueryParam("expand");
088    }
089
090    public void setProjectKey(final String projectKey) {
091        this.projectKey = projectKey;
092    }
093
094    /**
095     * set expand with the specified value
096     * @param <TValue> value type
097     * @param expand value to be set
098     * @return ByProjectKeyCustomersPostString
099     */
100    public <TValue> ByProjectKeyCustomersPostString withExpand(final TValue expand) {
101        return copy().withQueryParam("expand", expand);
102    }
103
104    /**
105     * add additional expand query parameter
106     * @param <TValue> value type
107     * @param expand value to be added
108     * @return ByProjectKeyCustomersPostString
109     */
110    public <TValue> ByProjectKeyCustomersPostString addExpand(final TValue expand) {
111        return copy().addQueryParam("expand", expand);
112    }
113
114    /**
115     * set expand with the specified value
116     * @param supplier supplier for the value to be set
117     * @return ByProjectKeyCustomersPostString
118     */
119    public ByProjectKeyCustomersPostString withExpand(final Supplier<String> supplier) {
120        return copy().withQueryParam("expand", supplier.get());
121    }
122
123    /**
124     * add additional expand query parameter
125     * @param supplier supplier for the value to be added
126     * @return ByProjectKeyCustomersPostString
127     */
128    public ByProjectKeyCustomersPostString addExpand(final Supplier<String> supplier) {
129        return copy().addQueryParam("expand", supplier.get());
130    }
131
132    /**
133     * set expand with the specified value
134     * @param op builder for the value to be set
135     * @return ByProjectKeyCustomersPostString
136     */
137    public ByProjectKeyCustomersPostString withExpand(final Function<StringBuilder, StringBuilder> op) {
138        return copy().withQueryParam("expand", op.apply(new StringBuilder()));
139    }
140
141    /**
142     * add additional expand query parameter
143     * @param op builder for the value to be added
144     * @return ByProjectKeyCustomersPostString
145     */
146    public ByProjectKeyCustomersPostString addExpand(final Function<StringBuilder, StringBuilder> op) {
147        return copy().addQueryParam("expand", op.apply(new StringBuilder()));
148    }
149
150    /**
151     * set expand with the specified values
152     * @param <TValue> value type
153     * @param expand values to be set
154     * @return ByProjectKeyCustomersPostString
155     */
156    public <TValue> ByProjectKeyCustomersPostString withExpand(final Collection<TValue> expand) {
157        return copy().withoutQueryParam("expand")
158                .addQueryParams(
159                    expand.stream().map(s -> new ParamEntry<>("expand", s.toString())).collect(Collectors.toList()));
160    }
161
162    /**
163     * add additional expand query parameters
164     * @param <TValue> value type
165     * @param expand values to be added
166     * @return ByProjectKeyCustomersPostString
167     */
168    public <TValue> ByProjectKeyCustomersPostString addExpand(final Collection<TValue> expand) {
169        return copy().addQueryParams(
170            expand.stream().map(s -> new ParamEntry<>("expand", s.toString())).collect(Collectors.toList()));
171    }
172
173    public String getBody() {
174        return customerDraft;
175    }
176
177    public ByProjectKeyCustomersPostString withBody(String customerDraft) {
178        ByProjectKeyCustomersPostString t = copy();
179        t.customerDraft = customerDraft;
180        return t;
181    }
182
183    @Override
184    public boolean equals(Object o) {
185        if (this == o)
186            return true;
187
188        if (o == null || getClass() != o.getClass())
189            return false;
190
191        ByProjectKeyCustomersPostString that = (ByProjectKeyCustomersPostString) o;
192
193        return new EqualsBuilder().append(projectKey, that.projectKey)
194                .append(customerDraft, that.customerDraft)
195                .isEquals();
196    }
197
198    @Override
199    public int hashCode() {
200        return new HashCodeBuilder(17, 37).append(projectKey).append(customerDraft).toHashCode();
201    }
202
203    @Override
204    protected ByProjectKeyCustomersPostString copy() {
205        return new ByProjectKeyCustomersPostString(this);
206    }
207}