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 *            .me()
029 *            .businessUnits()
030 *            .withId("{ID}")
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 ByProjectKeyMeBusinessUnitsByIDPost extends
038        BodyApiMethod<ByProjectKeyMeBusinessUnitsByIDPost, com.commercetools.api.models.business_unit.BusinessUnit, com.commercetools.api.models.me.MyBusinessUnitUpdate>
039        implements com.commercetools.api.client.ConflictingTrait<ByProjectKeyMeBusinessUnitsByIDPost>,
040        com.commercetools.api.client.ExpandableTrait<ByProjectKeyMeBusinessUnitsByIDPost>,
041        com.commercetools.api.client.Deprecatable200Trait<ByProjectKeyMeBusinessUnitsByIDPost>,
042        com.commercetools.api.client.ErrorableTrait<ByProjectKeyMeBusinessUnitsByIDPost> {
043
044    private String projectKey;
045    private String ID;
046
047    private com.commercetools.api.models.me.MyBusinessUnitUpdate myBusinessUnitUpdate;
048
049    public ByProjectKeyMeBusinessUnitsByIDPost(final ApiHttpClient apiHttpClient, String projectKey, String ID,
050            com.commercetools.api.models.me.MyBusinessUnitUpdate myBusinessUnitUpdate) {
051        super(apiHttpClient);
052        this.projectKey = projectKey;
053        this.ID = ID;
054        this.myBusinessUnitUpdate = myBusinessUnitUpdate;
055    }
056
057    public ByProjectKeyMeBusinessUnitsByIDPost(ByProjectKeyMeBusinessUnitsByIDPost t) {
058        super(t);
059        this.projectKey = t.projectKey;
060        this.ID = t.ID;
061        this.myBusinessUnitUpdate = t.myBusinessUnitUpdate;
062    }
063
064    @Override
065    protected ApiHttpRequest buildHttpRequest() {
066        List<String> params = new ArrayList<>(getQueryParamUriStrings());
067        String httpRequestPath = String.format("%s/me/business-units/%s", this.projectKey, this.ID);
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(myBusinessUnitUpdate)));
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 getID() {
094        return this.ID;
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 setID(final String ID) {
106        this.ID = ID;
107    }
108
109    /**
110     * set expand with the specified value
111     * @param expand value to be set
112     * @param <TValue> value type
113     * @return ByProjectKeyMeBusinessUnitsByIDPost
114     */
115    public <TValue> ByProjectKeyMeBusinessUnitsByIDPost 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 ByProjectKeyMeBusinessUnitsByIDPost
124     */
125    public <TValue> ByProjectKeyMeBusinessUnitsByIDPost 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 ByProjectKeyMeBusinessUnitsByIDPost
133     */
134    public ByProjectKeyMeBusinessUnitsByIDPost 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 ByProjectKeyMeBusinessUnitsByIDPost
142     */
143    public ByProjectKeyMeBusinessUnitsByIDPost 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 ByProjectKeyMeBusinessUnitsByIDPost
151     */
152    public ByProjectKeyMeBusinessUnitsByIDPost withExpand(final Function<StringBuilder, StringBuilder> op) {
153        return copy().withQueryParam("expand", op.apply(new StringBuilder()));
154    }
155
156    /**
157     * add additional expand query parameter
158     * @param op builder for the value to be added
159     * @return ByProjectKeyMeBusinessUnitsByIDPost
160     */
161    public ByProjectKeyMeBusinessUnitsByIDPost addExpand(final Function<StringBuilder, StringBuilder> op) {
162        return copy().addQueryParam("expand", op.apply(new StringBuilder()));
163    }
164
165    /**
166     * set expand with the specified values
167     * @param expand values to be set
168     * @param <TValue> value type
169     * @return ByProjectKeyMeBusinessUnitsByIDPost
170     */
171    public <TValue> ByProjectKeyMeBusinessUnitsByIDPost withExpand(final Collection<TValue> expand) {
172        return copy().withoutQueryParam("expand")
173                .addQueryParams(
174                    expand.stream().map(s -> new ParamEntry<>("expand", s.toString())).collect(Collectors.toList()));
175    }
176
177    /**
178     * add additional expand query parameters
179     * @param expand values to be added
180     * @param <TValue> value type
181     * @return ByProjectKeyMeBusinessUnitsByIDPost
182     */
183    public <TValue> ByProjectKeyMeBusinessUnitsByIDPost addExpand(final Collection<TValue> expand) {
184        return copy().addQueryParams(
185            expand.stream().map(s -> new ParamEntry<>("expand", s.toString())).collect(Collectors.toList()));
186    }
187
188    public com.commercetools.api.models.me.MyBusinessUnitUpdate getBody() {
189        return myBusinessUnitUpdate;
190    }
191
192    public ByProjectKeyMeBusinessUnitsByIDPost withBody(
193            com.commercetools.api.models.me.MyBusinessUnitUpdate myBusinessUnitUpdate) {
194        ByProjectKeyMeBusinessUnitsByIDPost t = copy();
195        t.myBusinessUnitUpdate = myBusinessUnitUpdate;
196        return t;
197    }
198
199    @Override
200    public boolean equals(Object o) {
201        if (this == o)
202            return true;
203
204        if (o == null || getClass() != o.getClass())
205            return false;
206
207        ByProjectKeyMeBusinessUnitsByIDPost that = (ByProjectKeyMeBusinessUnitsByIDPost) o;
208
209        return new EqualsBuilder().append(projectKey, that.projectKey)
210                .append(ID, that.ID)
211                .append(myBusinessUnitUpdate, that.myBusinessUnitUpdate)
212                .isEquals();
213    }
214
215    @Override
216    public int hashCode() {
217        return new HashCodeBuilder(17, 37).append(projectKey).append(ID).append(myBusinessUnitUpdate).toHashCode();
218    }
219
220    @Override
221    protected ByProjectKeyMeBusinessUnitsByIDPost copy() {
222        return new ByProjectKeyMeBusinessUnitsByIDPost(this);
223    }
224}