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 *  <p>Deleting an AssociateRole generates the AssociateRoleDeleted Message. An AssociateRole can only be deleted if it is not assigned to any Associates.</p>
022 *
023 * <hr>
024 * <div class=code-example>
025 * <pre><code class='java'>{@code
026 *   CompletableFuture<ApiHttpResponse<com.commercetools.api.models.associate_role.AssociateRole>> result = apiRoot
027 *            .withProjectKey("{projectKey}")
028 *            .associateRoles()
029 *            .withKey("{key}")
030 *            .delete()
031 *            .withVersion(version)
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 ByProjectKeyAssociateRolesKeyByKeyDelete extends
038        ApiMethod<ByProjectKeyAssociateRolesKeyByKeyDelete, com.commercetools.api.models.associate_role.AssociateRole>
039        implements com.commercetools.api.client.VersionedTrait<ByProjectKeyAssociateRolesKeyByKeyDelete>,
040        com.commercetools.api.client.ConflictingTrait<ByProjectKeyAssociateRolesKeyByKeyDelete>,
041        com.commercetools.api.client.ExpandableTrait<ByProjectKeyAssociateRolesKeyByKeyDelete>,
042        com.commercetools.api.client.ErrorableTrait<ByProjectKeyAssociateRolesKeyByKeyDelete>,
043        com.commercetools.api.client.Deprecatable200Trait<ByProjectKeyAssociateRolesKeyByKeyDelete> {
044
045    private String projectKey;
046    private String key;
047
048    public ByProjectKeyAssociateRolesKeyByKeyDelete(final ApiHttpClient apiHttpClient, String projectKey, String key) {
049        super(apiHttpClient);
050        this.projectKey = projectKey;
051        this.key = key;
052    }
053
054    public ByProjectKeyAssociateRolesKeyByKeyDelete(ByProjectKeyAssociateRolesKeyByKeyDelete t) {
055        super(t);
056        this.projectKey = t.projectKey;
057        this.key = t.key;
058    }
059
060    @Override
061    protected ApiHttpRequest buildHttpRequest() {
062        List<String> params = new ArrayList<>(getQueryParamUriStrings());
063        String httpRequestPath = String.format("%s/associate-roles/key=%s", this.projectKey, this.key);
064        if (!params.isEmpty()) {
065            httpRequestPath += "?" + String.join("&", params);
066        }
067        return new ApiHttpRequest(ApiHttpMethod.DELETE, URI.create(httpRequestPath), getHeaders(), null);
068    }
069
070    @Override
071    public ApiHttpResponse<com.commercetools.api.models.associate_role.AssociateRole> executeBlocking(
072            final ApiHttpClient client, final Duration timeout) {
073        return executeBlocking(client, timeout, com.commercetools.api.models.associate_role.AssociateRole.class);
074    }
075
076    @Override
077    public CompletableFuture<ApiHttpResponse<com.commercetools.api.models.associate_role.AssociateRole>> execute(
078            final ApiHttpClient client) {
079        return execute(client, com.commercetools.api.models.associate_role.AssociateRole.class);
080    }
081
082    public String getProjectKey() {
083        return this.projectKey;
084    }
085
086    public String getKey() {
087        return this.key;
088    }
089
090    public List<String> getVersion() {
091        return this.getQueryParam("version");
092    }
093
094    public List<String> getExpand() {
095        return this.getQueryParam("expand");
096    }
097
098    public void setProjectKey(final String projectKey) {
099        this.projectKey = projectKey;
100    }
101
102    public void setKey(final String key) {
103        this.key = key;
104    }
105
106    /**
107     * set version with the specified value
108     * @param version value to be set
109     * @param <TValue> value type
110     * @return ByProjectKeyAssociateRolesKeyByKeyDelete
111     */
112    public <TValue> ByProjectKeyAssociateRolesKeyByKeyDelete withVersion(final TValue version) {
113        return copy().withQueryParam("version", version);
114    }
115
116    /**
117     * add additional version query parameter
118     * @param version value to be added
119     * @param <TValue> value type
120     * @return ByProjectKeyAssociateRolesKeyByKeyDelete
121     */
122    public <TValue> ByProjectKeyAssociateRolesKeyByKeyDelete addVersion(final TValue version) {
123        return copy().addQueryParam("version", version);
124    }
125
126    /**
127     * set version with the specified value
128     * @param supplier supplier for the value to be set
129     * @return ByProjectKeyAssociateRolesKeyByKeyDelete
130     */
131    public ByProjectKeyAssociateRolesKeyByKeyDelete withVersion(final Supplier<Long> supplier) {
132        return copy().withQueryParam("version", supplier.get());
133    }
134
135    /**
136     * add additional version query parameter
137     * @param supplier supplier for the value to be added
138     * @return ByProjectKeyAssociateRolesKeyByKeyDelete
139     */
140    public ByProjectKeyAssociateRolesKeyByKeyDelete addVersion(final Supplier<Long> supplier) {
141        return copy().addQueryParam("version", supplier.get());
142    }
143
144    /**
145     * set version with the specified value
146     * @param op builder for the value to be set
147     * @return ByProjectKeyAssociateRolesKeyByKeyDelete
148     */
149    public ByProjectKeyAssociateRolesKeyByKeyDelete withVersion(final Function<StringBuilder, StringBuilder> op) {
150        return copy().withQueryParam("version", op.apply(new StringBuilder()));
151    }
152
153    /**
154     * add additional version query parameter
155     * @param op builder for the value to be added
156     * @return ByProjectKeyAssociateRolesKeyByKeyDelete
157     */
158    public ByProjectKeyAssociateRolesKeyByKeyDelete addVersion(final Function<StringBuilder, StringBuilder> op) {
159        return copy().addQueryParam("version", op.apply(new StringBuilder()));
160    }
161
162    /**
163     * set version with the specified values
164     * @param version values to be set
165     * @param <TValue> value type
166     * @return ByProjectKeyAssociateRolesKeyByKeyDelete
167     */
168    public <TValue> ByProjectKeyAssociateRolesKeyByKeyDelete withVersion(final Collection<TValue> version) {
169        return copy().withoutQueryParam("version")
170                .addQueryParams(
171                    version.stream().map(s -> new ParamEntry<>("version", s.toString())).collect(Collectors.toList()));
172    }
173
174    /**
175     * add additional version query parameters
176     * @param version values to be added
177     * @param <TValue> value type
178     * @return ByProjectKeyAssociateRolesKeyByKeyDelete
179     */
180    public <TValue> ByProjectKeyAssociateRolesKeyByKeyDelete addVersion(final Collection<TValue> version) {
181        return copy().addQueryParams(
182            version.stream().map(s -> new ParamEntry<>("version", s.toString())).collect(Collectors.toList()));
183    }
184
185    /**
186     * set expand with the specified value
187     * @param expand value to be set
188     * @param <TValue> value type
189     * @return ByProjectKeyAssociateRolesKeyByKeyDelete
190     */
191    public <TValue> ByProjectKeyAssociateRolesKeyByKeyDelete withExpand(final TValue expand) {
192        return copy().withQueryParam("expand", expand);
193    }
194
195    /**
196     * add additional expand query parameter
197     * @param expand value to be added
198     * @param <TValue> value type
199     * @return ByProjectKeyAssociateRolesKeyByKeyDelete
200     */
201    public <TValue> ByProjectKeyAssociateRolesKeyByKeyDelete addExpand(final TValue expand) {
202        return copy().addQueryParam("expand", expand);
203    }
204
205    /**
206     * set expand with the specified value
207     * @param supplier supplier for the value to be set
208     * @return ByProjectKeyAssociateRolesKeyByKeyDelete
209     */
210    public ByProjectKeyAssociateRolesKeyByKeyDelete withExpand(final Supplier<String> supplier) {
211        return copy().withQueryParam("expand", supplier.get());
212    }
213
214    /**
215     * add additional expand query parameter
216     * @param supplier supplier for the value to be added
217     * @return ByProjectKeyAssociateRolesKeyByKeyDelete
218     */
219    public ByProjectKeyAssociateRolesKeyByKeyDelete addExpand(final Supplier<String> supplier) {
220        return copy().addQueryParam("expand", supplier.get());
221    }
222
223    /**
224     * set expand with the specified value
225     * @param op builder for the value to be set
226     * @return ByProjectKeyAssociateRolesKeyByKeyDelete
227     */
228    public ByProjectKeyAssociateRolesKeyByKeyDelete withExpand(final Function<StringBuilder, StringBuilder> op) {
229        return copy().withQueryParam("expand", op.apply(new StringBuilder()));
230    }
231
232    /**
233     * add additional expand query parameter
234     * @param op builder for the value to be added
235     * @return ByProjectKeyAssociateRolesKeyByKeyDelete
236     */
237    public ByProjectKeyAssociateRolesKeyByKeyDelete addExpand(final Function<StringBuilder, StringBuilder> op) {
238        return copy().addQueryParam("expand", op.apply(new StringBuilder()));
239    }
240
241    /**
242     * set expand with the specified values
243     * @param expand values to be set
244     * @param <TValue> value type
245     * @return ByProjectKeyAssociateRolesKeyByKeyDelete
246     */
247    public <TValue> ByProjectKeyAssociateRolesKeyByKeyDelete withExpand(final Collection<TValue> expand) {
248        return copy().withoutQueryParam("expand")
249                .addQueryParams(
250                    expand.stream().map(s -> new ParamEntry<>("expand", s.toString())).collect(Collectors.toList()));
251    }
252
253    /**
254     * add additional expand query parameters
255     * @param expand values to be added
256     * @param <TValue> value type
257     * @return ByProjectKeyAssociateRolesKeyByKeyDelete
258     */
259    public <TValue> ByProjectKeyAssociateRolesKeyByKeyDelete addExpand(final Collection<TValue> expand) {
260        return copy().addQueryParams(
261            expand.stream().map(s -> new ParamEntry<>("expand", s.toString())).collect(Collectors.toList()));
262    }
263
264    @Override
265    public boolean equals(Object o) {
266        if (this == o)
267            return true;
268
269        if (o == null || getClass() != o.getClass())
270            return false;
271
272        ByProjectKeyAssociateRolesKeyByKeyDelete that = (ByProjectKeyAssociateRolesKeyByKeyDelete) o;
273
274        return new EqualsBuilder().append(projectKey, that.projectKey).append(key, that.key).isEquals();
275    }
276
277    @Override
278    public int hashCode() {
279        return new HashCodeBuilder(17, 37).append(projectKey).append(key).toHashCode();
280    }
281
282    @Override
283    protected ByProjectKeyAssociateRolesKeyByKeyDelete copy() {
284        return new ByProjectKeyAssociateRolesKeyByKeyDelete(this);
285    }
286}