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