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