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