-
Notifications
You must be signed in to change notification settings - Fork 15
/
ByProjectKeyProductsByIDImagesPost.java
396 lines (335 loc) · 13.3 KB
/
ByProjectKeyProductsByIDImagesPost.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
package com.commercetools.api.client;
import java.net.URI;
import java.net.URLConnection;
import java.nio.file.Files;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import io.vrap.rmf.base.client.*;
import io.vrap.rmf.base.client.utils.Generated;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
/**
* <p>Upload a JPEG, PNG and GIF file to a ProductVariant. The maximum file size of the image is 10MB. <code>variant</code> or <code>sku</code> is required to update a specific ProductVariant. The image is uploaded to the Master Variant if <code>variant</code> or <code>sku</code> are not included. Produces the ProductImageAdded Message when the <code>Small</code> version of the image has been uploaded to the CDN.</p>
*
* <hr>
* <div class=code-example>
* <pre><code class='java'>{@code
* CompletableFuture<ApiHttpResponse<com.commercetools.api.models.product.Product>> result = apiRoot
* .withProjectKey("{projectKey}")
* .products()
* .withId("{ID}")
* .images()
* .post(file)
* .execute()
* }</code></pre>
* </div>
*/
@Generated(value = "io.vrap.rmf.codegen.rendering.CoreCodeGenerator", comments = "https://github.com/commercetools/rmf-codegen")
public class ByProjectKeyProductsByIDImagesPost extends
BodyApiMethod<ByProjectKeyProductsByIDImagesPost, com.commercetools.api.models.product.Product, java.io.File> {
private String projectKey;
private String ID;
private java.io.File file;
public ByProjectKeyProductsByIDImagesPost(final ApiHttpClient apiHttpClient, String projectKey, String ID,
java.io.File file) {
super(apiHttpClient);
this.projectKey = projectKey;
this.ID = ID;
this.file = file;
}
public ByProjectKeyProductsByIDImagesPost(ByProjectKeyProductsByIDImagesPost t) {
super(t);
this.projectKey = t.projectKey;
this.ID = t.ID;
this.file = t.file;
}
@Override
protected ApiHttpRequest buildHttpRequest() {
List<String> params = new ArrayList<>(getQueryParamUriStrings());
String httpRequestPath = String.format("/%s/products/%s/images", this.projectKey, this.ID);
if (!params.isEmpty()) {
httpRequestPath += "?" + String.join("&", params);
}
ApiHttpHeaders headers = getHeaders();
if (headers.getFirst(ApiHttpHeaders.CONTENT_TYPE) == null) {
final String mimeType = Optional.ofNullable(URLConnection.guessContentTypeFromName(file.getName()))
.orElse("application/octet-stream");
headers = headers.withHeader(ApiHttpHeaders.CONTENT_TYPE, mimeType);
}
return new ApiHttpRequest(ApiHttpMethod.POST, URI.create(httpRequestPath), headers,
io.vrap.rmf.base.client.utils.FileUtils.executing(() -> Files.readAllBytes(file.toPath())));
}
@Override
public ApiHttpResponse<com.commercetools.api.models.product.Product> executeBlocking(final ApiHttpClient client,
final Duration timeout) {
return executeBlocking(client, timeout, com.commercetools.api.models.product.Product.class);
}
@Override
public CompletableFuture<ApiHttpResponse<com.commercetools.api.models.product.Product>> execute(
final ApiHttpClient client) {
return execute(client, com.commercetools.api.models.product.Product.class);
}
public String getProjectKey() {
return this.projectKey;
}
public String getID() {
return this.ID;
}
public List<String> getFilename() {
return this.getQueryParam("filename");
}
public List<String> getVariant() {
return this.getQueryParam("variant");
}
public List<String> getSku() {
return this.getQueryParam("sku");
}
public List<String> getStaged() {
return this.getQueryParam("staged");
}
public void setProjectKey(final String projectKey) {
this.projectKey = projectKey;
}
public void setID(final String ID) {
this.ID = ID;
}
/**
* set filename with the specified value
*/
public <TValue> ByProjectKeyProductsByIDImagesPost withFilename(final TValue filename) {
return copy().withQueryParam("filename", filename);
}
/**
* add additional filename query parameter
*/
public <TValue> ByProjectKeyProductsByIDImagesPost addFilename(final TValue filename) {
return copy().addQueryParam("filename", filename);
}
/**
* set filename with the specified value
*/
public ByProjectKeyProductsByIDImagesPost withFilename(final Supplier<String> supplier) {
return copy().withQueryParam("filename", supplier.get());
}
/**
* add additional filename query parameter
*/
public ByProjectKeyProductsByIDImagesPost addFilename(final Supplier<String> supplier) {
return copy().addQueryParam("filename", supplier.get());
}
/**
* set filename with the specified value
*/
public ByProjectKeyProductsByIDImagesPost withFilename(final Function<StringBuilder, StringBuilder> op) {
return copy().withQueryParam("filename", op.apply(new StringBuilder()));
}
/**
* add additional filename query parameter
*/
public ByProjectKeyProductsByIDImagesPost addFilename(final Function<StringBuilder, StringBuilder> op) {
return copy().addQueryParam("filename", op.apply(new StringBuilder()));
}
/**
* set filename with the specified values
*/
public <TValue> ByProjectKeyProductsByIDImagesPost withFilename(final List<TValue> filename) {
return copy().withoutQueryParam("filename")
.addQueryParams(filename.stream()
.map(s -> new ParamEntry<>("filename", s.toString()))
.collect(Collectors.toList()));
}
/**
* add additional filename query parameters
*/
public <TValue> ByProjectKeyProductsByIDImagesPost addFilename(final List<TValue> filename) {
return copy().addQueryParams(
filename.stream().map(s -> new ParamEntry<>("filename", s.toString())).collect(Collectors.toList()));
}
/**
* set variant with the specified value
*/
public <TValue> ByProjectKeyProductsByIDImagesPost withVariant(final TValue variant) {
return copy().withQueryParam("variant", variant);
}
/**
* add additional variant query parameter
*/
public <TValue> ByProjectKeyProductsByIDImagesPost addVariant(final TValue variant) {
return copy().addQueryParam("variant", variant);
}
/**
* set variant with the specified value
*/
public ByProjectKeyProductsByIDImagesPost withVariant(final Supplier<Long> supplier) {
return copy().withQueryParam("variant", supplier.get());
}
/**
* add additional variant query parameter
*/
public ByProjectKeyProductsByIDImagesPost addVariant(final Supplier<Long> supplier) {
return copy().addQueryParam("variant", supplier.get());
}
/**
* set variant with the specified value
*/
public ByProjectKeyProductsByIDImagesPost withVariant(final Function<StringBuilder, StringBuilder> op) {
return copy().withQueryParam("variant", op.apply(new StringBuilder()));
}
/**
* add additional variant query parameter
*/
public ByProjectKeyProductsByIDImagesPost addVariant(final Function<StringBuilder, StringBuilder> op) {
return copy().addQueryParam("variant", op.apply(new StringBuilder()));
}
/**
* set variant with the specified values
*/
public <TValue> ByProjectKeyProductsByIDImagesPost withVariant(final List<TValue> variant) {
return copy().withoutQueryParam("variant")
.addQueryParams(
variant.stream().map(s -> new ParamEntry<>("variant", s.toString())).collect(Collectors.toList()));
}
/**
* add additional variant query parameters
*/
public <TValue> ByProjectKeyProductsByIDImagesPost addVariant(final List<TValue> variant) {
return copy().addQueryParams(
variant.stream().map(s -> new ParamEntry<>("variant", s.toString())).collect(Collectors.toList()));
}
/**
* set sku with the specified value
*/
public <TValue> ByProjectKeyProductsByIDImagesPost withSku(final TValue sku) {
return copy().withQueryParam("sku", sku);
}
/**
* add additional sku query parameter
*/
public <TValue> ByProjectKeyProductsByIDImagesPost addSku(final TValue sku) {
return copy().addQueryParam("sku", sku);
}
/**
* set sku with the specified value
*/
public ByProjectKeyProductsByIDImagesPost withSku(final Supplier<String> supplier) {
return copy().withQueryParam("sku", supplier.get());
}
/**
* add additional sku query parameter
*/
public ByProjectKeyProductsByIDImagesPost addSku(final Supplier<String> supplier) {
return copy().addQueryParam("sku", supplier.get());
}
/**
* set sku with the specified value
*/
public ByProjectKeyProductsByIDImagesPost withSku(final Function<StringBuilder, StringBuilder> op) {
return copy().withQueryParam("sku", op.apply(new StringBuilder()));
}
/**
* add additional sku query parameter
*/
public ByProjectKeyProductsByIDImagesPost addSku(final Function<StringBuilder, StringBuilder> op) {
return copy().addQueryParam("sku", op.apply(new StringBuilder()));
}
/**
* set sku with the specified values
*/
public <TValue> ByProjectKeyProductsByIDImagesPost withSku(final List<TValue> sku) {
return copy().withoutQueryParam("sku")
.addQueryParams(
sku.stream().map(s -> new ParamEntry<>("sku", s.toString())).collect(Collectors.toList()));
}
/**
* add additional sku query parameters
*/
public <TValue> ByProjectKeyProductsByIDImagesPost addSku(final List<TValue> sku) {
return copy().addQueryParams(
sku.stream().map(s -> new ParamEntry<>("sku", s.toString())).collect(Collectors.toList()));
}
/**
* set staged with the specified value
*/
public <TValue> ByProjectKeyProductsByIDImagesPost withStaged(final TValue staged) {
return copy().withQueryParam("staged", staged);
}
/**
* add additional staged query parameter
*/
public <TValue> ByProjectKeyProductsByIDImagesPost addStaged(final TValue staged) {
return copy().addQueryParam("staged", staged);
}
/**
* set staged with the specified value
*/
public ByProjectKeyProductsByIDImagesPost withStaged(final Supplier<Boolean> supplier) {
return copy().withQueryParam("staged", supplier.get());
}
/**
* add additional staged query parameter
*/
public ByProjectKeyProductsByIDImagesPost addStaged(final Supplier<Boolean> supplier) {
return copy().addQueryParam("staged", supplier.get());
}
/**
* set staged with the specified value
*/
public ByProjectKeyProductsByIDImagesPost withStaged(final Function<StringBuilder, StringBuilder> op) {
return copy().withQueryParam("staged", op.apply(new StringBuilder()));
}
/**
* add additional staged query parameter
*/
public ByProjectKeyProductsByIDImagesPost addStaged(final Function<StringBuilder, StringBuilder> op) {
return copy().addQueryParam("staged", op.apply(new StringBuilder()));
}
/**
* set staged with the specified values
*/
public <TValue> ByProjectKeyProductsByIDImagesPost withStaged(final List<TValue> staged) {
return copy().withoutQueryParam("staged")
.addQueryParams(
staged.stream().map(s -> new ParamEntry<>("staged", s.toString())).collect(Collectors.toList()));
}
/**
* add additional staged query parameters
*/
public <TValue> ByProjectKeyProductsByIDImagesPost addStaged(final List<TValue> staged) {
return copy().addQueryParams(
staged.stream().map(s -> new ParamEntry<>("staged", s.toString())).collect(Collectors.toList()));
}
public java.io.File getBody() {
return file;
}
public ByProjectKeyProductsByIDImagesPost withBody(java.io.File file) {
ByProjectKeyProductsByIDImagesPost t = copy();
t.file = file;
return t;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
ByProjectKeyProductsByIDImagesPost that = (ByProjectKeyProductsByIDImagesPost) o;
return new EqualsBuilder().append(projectKey, that.projectKey)
.append(ID, that.ID)
.append(file, that.file)
.isEquals();
}
@Override
public int hashCode() {
return new HashCodeBuilder(17, 37).append(projectKey).append(ID).append(file).toHashCode();
}
@Override
protected ByProjectKeyProductsByIDImagesPost copy() {
return new ByProjectKeyProductsByIDImagesPost(this);
}
}