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