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>If the Customer exists in the Project but the <code>stores</code> field references a different Store, this method returns a ResourceNotFound error.</p>
022 *
023 * <hr>
024 * <div class=code-example>
025 * <pre><code class='java'>{@code
026 *   CompletableFuture<ApiHttpResponse<com.commercetools.api.models.customer.Customer>> result = apiRoot
027 *            .withProjectKey("{projectKey}")
028 *            .inStoreKeyWithStoreKeyValue("{storeKey}")
029 *            .customers()
030 *            .withId("{ID}")
031 *            .post(null)
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 ByProjectKeyInStoreKeyByStoreKeyCustomersByIDPost extends
038        BodyApiMethod<ByProjectKeyInStoreKeyByStoreKeyCustomersByIDPost, com.commercetools.api.models.customer.Customer, com.commercetools.api.models.customer.CustomerUpdate>
039        implements com.commercetools.api.client.ConflictingTrait<ByProjectKeyInStoreKeyByStoreKeyCustomersByIDPost>,
040        com.commercetools.api.client.ExpandableTrait<ByProjectKeyInStoreKeyByStoreKeyCustomersByIDPost>,
041        com.commercetools.api.client.Deprecatable200Trait<ByProjectKeyInStoreKeyByStoreKeyCustomersByIDPost>,
042        com.commercetools.api.client.ErrorableTrait<ByProjectKeyInStoreKeyByStoreKeyCustomersByIDPost> {
043
044    private String projectKey;
045    private String storeKey;
046    private String ID;
047
048    private com.commercetools.api.models.customer.CustomerUpdate customerUpdate;
049
050    public ByProjectKeyInStoreKeyByStoreKeyCustomersByIDPost(final ApiHttpClient apiHttpClient, String projectKey,
051            String storeKey, String ID, com.commercetools.api.models.customer.CustomerUpdate customerUpdate) {
052        super(apiHttpClient);
053        this.projectKey = projectKey;
054        this.storeKey = storeKey;
055        this.ID = ID;
056        this.customerUpdate = customerUpdate;
057    }
058
059    public ByProjectKeyInStoreKeyByStoreKeyCustomersByIDPost(ByProjectKeyInStoreKeyByStoreKeyCustomersByIDPost t) {
060        super(t);
061        this.projectKey = t.projectKey;
062        this.storeKey = t.storeKey;
063        this.ID = t.ID;
064        this.customerUpdate = t.customerUpdate;
065    }
066
067    @Override
068    protected ApiHttpRequest buildHttpRequest() {
069        List<String> params = new ArrayList<>(getQueryParamUriStrings());
070        String httpRequestPath = String.format("%s/in-store/key=%s/customers/%s", this.projectKey, this.storeKey,
071            this.ID);
072        if (!params.isEmpty()) {
073            httpRequestPath += "?" + String.join("&", params);
074        }
075        return new ApiHttpRequest(ApiHttpMethod.POST, URI.create(httpRequestPath), getHeaders(),
076            io.vrap.rmf.base.client.utils.json.JsonUtils
077                    .executing(() -> apiHttpClient().getSerializerService().toJsonByteArray(customerUpdate)));
078
079    }
080
081    @Override
082    public ApiHttpResponse<com.commercetools.api.models.customer.Customer> executeBlocking(final ApiHttpClient client,
083            final Duration timeout) {
084        return executeBlocking(client, timeout, com.commercetools.api.models.customer.Customer.class);
085    }
086
087    @Override
088    public CompletableFuture<ApiHttpResponse<com.commercetools.api.models.customer.Customer>> execute(
089            final ApiHttpClient client) {
090        return execute(client, com.commercetools.api.models.customer.Customer.class);
091    }
092
093    public String getProjectKey() {
094        return this.projectKey;
095    }
096
097    public String getStoreKey() {
098        return this.storeKey;
099    }
100
101    public String getID() {
102        return this.ID;
103    }
104
105    public List<String> getExpand() {
106        return this.getQueryParam("expand");
107    }
108
109    public void setProjectKey(final String projectKey) {
110        this.projectKey = projectKey;
111    }
112
113    public void setStoreKey(final String storeKey) {
114        this.storeKey = storeKey;
115    }
116
117    public void setID(final String ID) {
118        this.ID = ID;
119    }
120
121    /**
122     * set expand with the specified value
123     * @param expand value to be set
124     * @param <TValue> value type
125     * @return ByProjectKeyInStoreKeyByStoreKeyCustomersByIDPost
126     */
127    public <TValue> ByProjectKeyInStoreKeyByStoreKeyCustomersByIDPost withExpand(final TValue expand) {
128        return copy().withQueryParam("expand", expand);
129    }
130
131    /**
132     * add additional expand query parameter
133     * @param expand value to be added
134     * @param <TValue> value type
135     * @return ByProjectKeyInStoreKeyByStoreKeyCustomersByIDPost
136     */
137    public <TValue> ByProjectKeyInStoreKeyByStoreKeyCustomersByIDPost addExpand(final TValue expand) {
138        return copy().addQueryParam("expand", expand);
139    }
140
141    /**
142     * set expand with the specified value
143     * @param supplier supplier for the value to be set
144     * @return ByProjectKeyInStoreKeyByStoreKeyCustomersByIDPost
145     */
146    public ByProjectKeyInStoreKeyByStoreKeyCustomersByIDPost withExpand(final Supplier<String> supplier) {
147        return copy().withQueryParam("expand", supplier.get());
148    }
149
150    /**
151     * add additional expand query parameter
152     * @param supplier supplier for the value to be added
153     * @return ByProjectKeyInStoreKeyByStoreKeyCustomersByIDPost
154     */
155    public ByProjectKeyInStoreKeyByStoreKeyCustomersByIDPost addExpand(final Supplier<String> supplier) {
156        return copy().addQueryParam("expand", supplier.get());
157    }
158
159    /**
160     * set expand with the specified value
161     * @param op builder for the value to be set
162     * @return ByProjectKeyInStoreKeyByStoreKeyCustomersByIDPost
163     */
164    public ByProjectKeyInStoreKeyByStoreKeyCustomersByIDPost withExpand(
165            final Function<StringBuilder, StringBuilder> op) {
166        return copy().withQueryParam("expand", op.apply(new StringBuilder()));
167    }
168
169    /**
170     * add additional expand query parameter
171     * @param op builder for the value to be added
172     * @return ByProjectKeyInStoreKeyByStoreKeyCustomersByIDPost
173     */
174    public ByProjectKeyInStoreKeyByStoreKeyCustomersByIDPost addExpand(
175            final Function<StringBuilder, StringBuilder> op) {
176        return copy().addQueryParam("expand", op.apply(new StringBuilder()));
177    }
178
179    /**
180     * set expand with the specified values
181     * @param expand values to be set
182     * @param <TValue> value type
183     * @return ByProjectKeyInStoreKeyByStoreKeyCustomersByIDPost
184     */
185    public <TValue> ByProjectKeyInStoreKeyByStoreKeyCustomersByIDPost withExpand(final Collection<TValue> expand) {
186        return copy().withoutQueryParam("expand")
187                .addQueryParams(
188                    expand.stream().map(s -> new ParamEntry<>("expand", s.toString())).collect(Collectors.toList()));
189    }
190
191    /**
192     * add additional expand query parameters
193     * @param expand values to be added
194     * @param <TValue> value type
195     * @return ByProjectKeyInStoreKeyByStoreKeyCustomersByIDPost
196     */
197    public <TValue> ByProjectKeyInStoreKeyByStoreKeyCustomersByIDPost addExpand(final Collection<TValue> expand) {
198        return copy().addQueryParams(
199            expand.stream().map(s -> new ParamEntry<>("expand", s.toString())).collect(Collectors.toList()));
200    }
201
202    public com.commercetools.api.models.customer.CustomerUpdate getBody() {
203        return customerUpdate;
204    }
205
206    public ByProjectKeyInStoreKeyByStoreKeyCustomersByIDPost withBody(
207            com.commercetools.api.models.customer.CustomerUpdate customerUpdate) {
208        ByProjectKeyInStoreKeyByStoreKeyCustomersByIDPost t = copy();
209        t.customerUpdate = customerUpdate;
210        return t;
211    }
212
213    @Override
214    public boolean equals(Object o) {
215        if (this == o)
216            return true;
217
218        if (o == null || getClass() != o.getClass())
219            return false;
220
221        ByProjectKeyInStoreKeyByStoreKeyCustomersByIDPost that = (ByProjectKeyInStoreKeyByStoreKeyCustomersByIDPost) o;
222
223        return new EqualsBuilder().append(projectKey, that.projectKey)
224                .append(storeKey, that.storeKey)
225                .append(ID, that.ID)
226                .append(customerUpdate, that.customerUpdate)
227                .isEquals();
228    }
229
230    @Override
231    public int hashCode() {
232        return new HashCodeBuilder(17, 37).append(projectKey)
233                .append(storeKey)
234                .append(ID)
235                .append(customerUpdate)
236                .toHashCode();
237    }
238
239    @Override
240    protected ByProjectKeyInStoreKeyByStoreKeyCustomersByIDPost copy() {
241        return new ByProjectKeyInStoreKeyByStoreKeyCustomersByIDPost(this);
242    }
243}