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>Either the scope <code>manage_products:{projectKey}</code> or <code>manage_categories:{projectKey}</code> is required.</p>
023 *  <p>Creating a Category produces the CategoryCreated Message.</p>
024 *
025 * <hr>
026 * <div class=code-example>
027 * <pre><code class='java'>{@code
028 *   CompletableFuture<ApiHttpResponse<com.commercetools.api.models.category.Category>> result = apiRoot
029 *            .withProjectKey("{projectKey}")
030 *            .categories()
031 *            .post("")
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 ByProjectKeyCategoriesPostString
038        extends StringBodyApiMethod<ByProjectKeyCategoriesPostString, com.commercetools.api.models.category.Category>
039        implements com.commercetools.api.client.ExpandableTrait<ByProjectKeyCategoriesPostString>,
040        com.commercetools.api.client.Deprecatable201Trait<ByProjectKeyCategoriesPostString>,
041        com.commercetools.api.client.ErrorableTrait<ByProjectKeyCategoriesPostString> {
042
043    private String projectKey;
044
045    private String categoryDraft;
046
047    public ByProjectKeyCategoriesPostString(final ApiHttpClient apiHttpClient, String projectKey,
048            String categoryDraft) {
049        super(apiHttpClient);
050        this.projectKey = projectKey;
051        this.categoryDraft = categoryDraft;
052    }
053
054    public ByProjectKeyCategoriesPostString(ByProjectKeyCategoriesPostString t) {
055        super(t);
056        this.projectKey = t.projectKey;
057        this.categoryDraft = t.categoryDraft;
058    }
059
060    @Override
061    protected ApiHttpRequest buildHttpRequest() {
062        List<String> params = new ArrayList<>(getQueryParamUriStrings());
063        String httpRequestPath = String.format("%s/categories", this.projectKey);
064        if (!params.isEmpty()) {
065            httpRequestPath += "?" + String.join("&", params);
066        }
067        return new ApiHttpRequest(ApiHttpMethod.POST, URI.create(httpRequestPath), getHeaders(),
068            categoryDraft.getBytes(StandardCharsets.UTF_8));
069
070    }
071
072    @Override
073    public ApiHttpResponse<com.commercetools.api.models.category.Category> executeBlocking(final ApiHttpClient client,
074            final Duration timeout) {
075        return executeBlocking(client, timeout, com.commercetools.api.models.category.Category.class);
076    }
077
078    @Override
079    public CompletableFuture<ApiHttpResponse<com.commercetools.api.models.category.Category>> execute(
080            final ApiHttpClient client) {
081        return execute(client, com.commercetools.api.models.category.Category.class);
082    }
083
084    public String getProjectKey() {
085        return this.projectKey;
086    }
087
088    public List<String> getExpand() {
089        return this.getQueryParam("expand");
090    }
091
092    public void setProjectKey(final String projectKey) {
093        this.projectKey = projectKey;
094    }
095
096    /**
097     * set expand with the specified value
098     * @param <TValue> value type
099     * @param expand value to be set
100     * @return ByProjectKeyCategoriesPostString
101     */
102    public <TValue> ByProjectKeyCategoriesPostString withExpand(final TValue expand) {
103        return copy().withQueryParam("expand", expand);
104    }
105
106    /**
107     * add additional expand query parameter
108     * @param <TValue> value type
109     * @param expand value to be added
110     * @return ByProjectKeyCategoriesPostString
111     */
112    public <TValue> ByProjectKeyCategoriesPostString addExpand(final TValue expand) {
113        return copy().addQueryParam("expand", expand);
114    }
115
116    /**
117     * set expand with the specified value
118     * @param supplier supplier for the value to be set
119     * @return ByProjectKeyCategoriesPostString
120     */
121    public ByProjectKeyCategoriesPostString withExpand(final Supplier<String> supplier) {
122        return copy().withQueryParam("expand", supplier.get());
123    }
124
125    /**
126     * add additional expand query parameter
127     * @param supplier supplier for the value to be added
128     * @return ByProjectKeyCategoriesPostString
129     */
130    public ByProjectKeyCategoriesPostString addExpand(final Supplier<String> supplier) {
131        return copy().addQueryParam("expand", supplier.get());
132    }
133
134    /**
135     * set expand with the specified value
136     * @param op builder for the value to be set
137     * @return ByProjectKeyCategoriesPostString
138     */
139    public ByProjectKeyCategoriesPostString withExpand(final Function<StringBuilder, StringBuilder> op) {
140        return copy().withQueryParam("expand", op.apply(new StringBuilder()));
141    }
142
143    /**
144     * add additional expand query parameter
145     * @param op builder for the value to be added
146     * @return ByProjectKeyCategoriesPostString
147     */
148    public ByProjectKeyCategoriesPostString addExpand(final Function<StringBuilder, StringBuilder> op) {
149        return copy().addQueryParam("expand", op.apply(new StringBuilder()));
150    }
151
152    /**
153     * set expand with the specified values
154     * @param <TValue> value type
155     * @param expand values to be set
156     * @return ByProjectKeyCategoriesPostString
157     */
158    public <TValue> ByProjectKeyCategoriesPostString withExpand(final Collection<TValue> expand) {
159        return copy().withoutQueryParam("expand")
160                .addQueryParams(
161                    expand.stream().map(s -> new ParamEntry<>("expand", s.toString())).collect(Collectors.toList()));
162    }
163
164    /**
165     * add additional expand query parameters
166     * @param <TValue> value type
167     * @param expand values to be added
168     * @return ByProjectKeyCategoriesPostString
169     */
170    public <TValue> ByProjectKeyCategoriesPostString addExpand(final Collection<TValue> expand) {
171        return copy().addQueryParams(
172            expand.stream().map(s -> new ParamEntry<>("expand", s.toString())).collect(Collectors.toList()));
173    }
174
175    public String getBody() {
176        return categoryDraft;
177    }
178
179    public ByProjectKeyCategoriesPostString withBody(String categoryDraft) {
180        ByProjectKeyCategoriesPostString t = copy();
181        t.categoryDraft = categoryDraft;
182        return t;
183    }
184
185    @Override
186    public boolean equals(Object o) {
187        if (this == o)
188            return true;
189
190        if (o == null || getClass() != o.getClass())
191            return false;
192
193        ByProjectKeyCategoriesPostString that = (ByProjectKeyCategoriesPostString) o;
194
195        return new EqualsBuilder().append(projectKey, that.projectKey)
196                .append(categoryDraft, that.categoryDraft)
197                .isEquals();
198    }
199
200    @Override
201    public int hashCode() {
202        return new HashCodeBuilder(17, 37).append(projectKey).append(categoryDraft).toHashCode();
203    }
204
205    @Override
206    protected ByProjectKeyCategoriesPostString copy() {
207        return new ByProjectKeyCategoriesPostString(this);
208    }
209}