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 * <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> 023 * 024 * <hr> 025 * <div class=code-example> 026 * <pre><code class='java'>{@code 027 * CompletableFuture<ApiHttpResponse<com.commercetools.api.models.product.Product>> result = apiRoot 028 * .withProjectKey("{projectKey}") 029 * .products() 030 * .withId("{ID}") 031 * .images() 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 ByProjectKeyProductsByIDImagesPostString extends 039 StringBodyApiMethod<ByProjectKeyProductsByIDImagesPostString, com.commercetools.api.models.product.Product> { 040 041 private String projectKey; 042 private String ID; 043 044 private String file; 045 046 public ByProjectKeyProductsByIDImagesPostString(final ApiHttpClient apiHttpClient, String projectKey, String ID, 047 String file) { 048 super(apiHttpClient); 049 this.projectKey = projectKey; 050 this.ID = ID; 051 this.file = file; 052 } 053 054 public ByProjectKeyProductsByIDImagesPostString(ByProjectKeyProductsByIDImagesPostString t) { 055 super(t); 056 this.projectKey = t.projectKey; 057 this.ID = t.ID; 058 this.file = t.file; 059 } 060 061 @Override 062 protected ApiHttpRequest buildHttpRequest() { 063 List<String> params = new ArrayList<>(getQueryParamUriStrings()); 064 String httpRequestPath = String.format("%s/products/%s/images", this.projectKey, this.ID); 065 if (!params.isEmpty()) { 066 httpRequestPath += "?" + String.join("&", params); 067 } 068 return new ApiHttpRequest(ApiHttpMethod.POST, URI.create(httpRequestPath), getHeaders(), 069 file.getBytes(StandardCharsets.UTF_8)); 070 071 } 072 073 @Override 074 public ApiHttpResponse<com.commercetools.api.models.product.Product> executeBlocking(final ApiHttpClient client, 075 final Duration timeout) { 076 return executeBlocking(client, timeout, com.commercetools.api.models.product.Product.class); 077 } 078 079 @Override 080 public CompletableFuture<ApiHttpResponse<com.commercetools.api.models.product.Product>> execute( 081 final ApiHttpClient client) { 082 return execute(client, com.commercetools.api.models.product.Product.class); 083 } 084 085 public String getProjectKey() { 086 return this.projectKey; 087 } 088 089 public String getID() { 090 return this.ID; 091 } 092 093 public List<String> getFilename() { 094 return this.getQueryParam("filename"); 095 } 096 097 public List<String> getVariant() { 098 return this.getQueryParam("variant"); 099 } 100 101 public List<String> getSku() { 102 return this.getQueryParam("sku"); 103 } 104 105 public List<String> getStaged() { 106 return this.getQueryParam("staged"); 107 } 108 109 public void setProjectKey(final String projectKey) { 110 this.projectKey = projectKey; 111 } 112 113 public void setID(final String ID) { 114 this.ID = ID; 115 } 116 117 /** 118 * set filename with the specified value 119 * @param <TValue> value type 120 * @param filename value to be set 121 * @return ByProjectKeyProductsByIDImagesPostString 122 */ 123 public <TValue> ByProjectKeyProductsByIDImagesPostString withFilename(final TValue filename) { 124 return copy().withQueryParam("filename", filename); 125 } 126 127 /** 128 * add additional filename query parameter 129 * @param <TValue> value type 130 * @param filename value to be added 131 * @return ByProjectKeyProductsByIDImagesPostString 132 */ 133 public <TValue> ByProjectKeyProductsByIDImagesPostString addFilename(final TValue filename) { 134 return copy().addQueryParam("filename", filename); 135 } 136 137 /** 138 * set filename with the specified value 139 * @param supplier supplier for the value to be set 140 * @return ByProjectKeyProductsByIDImagesPostString 141 */ 142 public ByProjectKeyProductsByIDImagesPostString withFilename(final Supplier<String> supplier) { 143 return copy().withQueryParam("filename", supplier.get()); 144 } 145 146 /** 147 * add additional filename query parameter 148 * @param supplier supplier for the value to be added 149 * @return ByProjectKeyProductsByIDImagesPostString 150 */ 151 public ByProjectKeyProductsByIDImagesPostString addFilename(final Supplier<String> supplier) { 152 return copy().addQueryParam("filename", supplier.get()); 153 } 154 155 /** 156 * set filename with the specified value 157 * @param op builder for the value to be set 158 * @return ByProjectKeyProductsByIDImagesPostString 159 */ 160 public ByProjectKeyProductsByIDImagesPostString withFilename(final Function<StringBuilder, StringBuilder> op) { 161 return copy().withQueryParam("filename", op.apply(new StringBuilder())); 162 } 163 164 /** 165 * add additional filename query parameter 166 * @param op builder for the value to be added 167 * @return ByProjectKeyProductsByIDImagesPostString 168 */ 169 public ByProjectKeyProductsByIDImagesPostString addFilename(final Function<StringBuilder, StringBuilder> op) { 170 return copy().addQueryParam("filename", op.apply(new StringBuilder())); 171 } 172 173 /** 174 * set filename with the specified values 175 * @param <TValue> value type 176 * @param filename values to be set 177 * @return ByProjectKeyProductsByIDImagesPostString 178 */ 179 public <TValue> ByProjectKeyProductsByIDImagesPostString withFilename(final Collection<TValue> filename) { 180 return copy().withoutQueryParam("filename") 181 .addQueryParams(filename.stream() 182 .map(s -> new ParamEntry<>("filename", s.toString())) 183 .collect(Collectors.toList())); 184 } 185 186 /** 187 * add additional filename query parameters 188 * @param <TValue> value type 189 * @param filename values to be added 190 * @return ByProjectKeyProductsByIDImagesPostString 191 */ 192 public <TValue> ByProjectKeyProductsByIDImagesPostString addFilename(final Collection<TValue> filename) { 193 return copy().addQueryParams( 194 filename.stream().map(s -> new ParamEntry<>("filename", s.toString())).collect(Collectors.toList())); 195 } 196 197 /** 198 * set variant with the specified value 199 * @param <TValue> value type 200 * @param variant value to be set 201 * @return ByProjectKeyProductsByIDImagesPostString 202 */ 203 public <TValue> ByProjectKeyProductsByIDImagesPostString withVariant(final TValue variant) { 204 return copy().withQueryParam("variant", variant); 205 } 206 207 /** 208 * add additional variant query parameter 209 * @param <TValue> value type 210 * @param variant value to be added 211 * @return ByProjectKeyProductsByIDImagesPostString 212 */ 213 public <TValue> ByProjectKeyProductsByIDImagesPostString addVariant(final TValue variant) { 214 return copy().addQueryParam("variant", variant); 215 } 216 217 /** 218 * set variant with the specified value 219 * @param supplier supplier for the value to be set 220 * @return ByProjectKeyProductsByIDImagesPostString 221 */ 222 public ByProjectKeyProductsByIDImagesPostString withVariant(final Supplier<Long> supplier) { 223 return copy().withQueryParam("variant", supplier.get()); 224 } 225 226 /** 227 * add additional variant query parameter 228 * @param supplier supplier for the value to be added 229 * @return ByProjectKeyProductsByIDImagesPostString 230 */ 231 public ByProjectKeyProductsByIDImagesPostString addVariant(final Supplier<Long> supplier) { 232 return copy().addQueryParam("variant", supplier.get()); 233 } 234 235 /** 236 * set variant with the specified value 237 * @param op builder for the value to be set 238 * @return ByProjectKeyProductsByIDImagesPostString 239 */ 240 public ByProjectKeyProductsByIDImagesPostString withVariant(final Function<StringBuilder, StringBuilder> op) { 241 return copy().withQueryParam("variant", op.apply(new StringBuilder())); 242 } 243 244 /** 245 * add additional variant query parameter 246 * @param op builder for the value to be added 247 * @return ByProjectKeyProductsByIDImagesPostString 248 */ 249 public ByProjectKeyProductsByIDImagesPostString addVariant(final Function<StringBuilder, StringBuilder> op) { 250 return copy().addQueryParam("variant", op.apply(new StringBuilder())); 251 } 252 253 /** 254 * set variant with the specified values 255 * @param <TValue> value type 256 * @param variant values to be set 257 * @return ByProjectKeyProductsByIDImagesPostString 258 */ 259 public <TValue> ByProjectKeyProductsByIDImagesPostString withVariant(final Collection<TValue> variant) { 260 return copy().withoutQueryParam("variant") 261 .addQueryParams( 262 variant.stream().map(s -> new ParamEntry<>("variant", s.toString())).collect(Collectors.toList())); 263 } 264 265 /** 266 * add additional variant query parameters 267 * @param <TValue> value type 268 * @param variant values to be added 269 * @return ByProjectKeyProductsByIDImagesPostString 270 */ 271 public <TValue> ByProjectKeyProductsByIDImagesPostString addVariant(final Collection<TValue> variant) { 272 return copy().addQueryParams( 273 variant.stream().map(s -> new ParamEntry<>("variant", s.toString())).collect(Collectors.toList())); 274 } 275 276 /** 277 * set sku with the specified value 278 * @param <TValue> value type 279 * @param sku value to be set 280 * @return ByProjectKeyProductsByIDImagesPostString 281 */ 282 public <TValue> ByProjectKeyProductsByIDImagesPostString withSku(final TValue sku) { 283 return copy().withQueryParam("sku", sku); 284 } 285 286 /** 287 * add additional sku query parameter 288 * @param <TValue> value type 289 * @param sku value to be added 290 * @return ByProjectKeyProductsByIDImagesPostString 291 */ 292 public <TValue> ByProjectKeyProductsByIDImagesPostString addSku(final TValue sku) { 293 return copy().addQueryParam("sku", sku); 294 } 295 296 /** 297 * set sku with the specified value 298 * @param supplier supplier for the value to be set 299 * @return ByProjectKeyProductsByIDImagesPostString 300 */ 301 public ByProjectKeyProductsByIDImagesPostString withSku(final Supplier<String> supplier) { 302 return copy().withQueryParam("sku", supplier.get()); 303 } 304 305 /** 306 * add additional sku query parameter 307 * @param supplier supplier for the value to be added 308 * @return ByProjectKeyProductsByIDImagesPostString 309 */ 310 public ByProjectKeyProductsByIDImagesPostString addSku(final Supplier<String> supplier) { 311 return copy().addQueryParam("sku", supplier.get()); 312 } 313 314 /** 315 * set sku with the specified value 316 * @param op builder for the value to be set 317 * @return ByProjectKeyProductsByIDImagesPostString 318 */ 319 public ByProjectKeyProductsByIDImagesPostString withSku(final Function<StringBuilder, StringBuilder> op) { 320 return copy().withQueryParam("sku", op.apply(new StringBuilder())); 321 } 322 323 /** 324 * add additional sku query parameter 325 * @param op builder for the value to be added 326 * @return ByProjectKeyProductsByIDImagesPostString 327 */ 328 public ByProjectKeyProductsByIDImagesPostString addSku(final Function<StringBuilder, StringBuilder> op) { 329 return copy().addQueryParam("sku", op.apply(new StringBuilder())); 330 } 331 332 /** 333 * set sku with the specified values 334 * @param <TValue> value type 335 * @param sku values to be set 336 * @return ByProjectKeyProductsByIDImagesPostString 337 */ 338 public <TValue> ByProjectKeyProductsByIDImagesPostString withSku(final Collection<TValue> sku) { 339 return copy().withoutQueryParam("sku") 340 .addQueryParams( 341 sku.stream().map(s -> new ParamEntry<>("sku", s.toString())).collect(Collectors.toList())); 342 } 343 344 /** 345 * add additional sku query parameters 346 * @param <TValue> value type 347 * @param sku values to be added 348 * @return ByProjectKeyProductsByIDImagesPostString 349 */ 350 public <TValue> ByProjectKeyProductsByIDImagesPostString addSku(final Collection<TValue> sku) { 351 return copy().addQueryParams( 352 sku.stream().map(s -> new ParamEntry<>("sku", s.toString())).collect(Collectors.toList())); 353 } 354 355 /** 356 * set staged with the specified value 357 * @param <TValue> value type 358 * @param staged value to be set 359 * @return ByProjectKeyProductsByIDImagesPostString 360 */ 361 public <TValue> ByProjectKeyProductsByIDImagesPostString withStaged(final TValue staged) { 362 return copy().withQueryParam("staged", staged); 363 } 364 365 /** 366 * add additional staged query parameter 367 * @param <TValue> value type 368 * @param staged value to be added 369 * @return ByProjectKeyProductsByIDImagesPostString 370 */ 371 public <TValue> ByProjectKeyProductsByIDImagesPostString addStaged(final TValue staged) { 372 return copy().addQueryParam("staged", staged); 373 } 374 375 /** 376 * set staged with the specified value 377 * @param supplier supplier for the value to be set 378 * @return ByProjectKeyProductsByIDImagesPostString 379 */ 380 public ByProjectKeyProductsByIDImagesPostString withStaged(final Supplier<Boolean> supplier) { 381 return copy().withQueryParam("staged", supplier.get()); 382 } 383 384 /** 385 * add additional staged query parameter 386 * @param supplier supplier for the value to be added 387 * @return ByProjectKeyProductsByIDImagesPostString 388 */ 389 public ByProjectKeyProductsByIDImagesPostString addStaged(final Supplier<Boolean> supplier) { 390 return copy().addQueryParam("staged", supplier.get()); 391 } 392 393 /** 394 * set staged with the specified value 395 * @param op builder for the value to be set 396 * @return ByProjectKeyProductsByIDImagesPostString 397 */ 398 public ByProjectKeyProductsByIDImagesPostString withStaged(final Function<StringBuilder, StringBuilder> op) { 399 return copy().withQueryParam("staged", op.apply(new StringBuilder())); 400 } 401 402 /** 403 * add additional staged query parameter 404 * @param op builder for the value to be added 405 * @return ByProjectKeyProductsByIDImagesPostString 406 */ 407 public ByProjectKeyProductsByIDImagesPostString addStaged(final Function<StringBuilder, StringBuilder> op) { 408 return copy().addQueryParam("staged", op.apply(new StringBuilder())); 409 } 410 411 /** 412 * set staged with the specified values 413 * @param <TValue> value type 414 * @param staged values to be set 415 * @return ByProjectKeyProductsByIDImagesPostString 416 */ 417 public <TValue> ByProjectKeyProductsByIDImagesPostString withStaged(final Collection<TValue> staged) { 418 return copy().withoutQueryParam("staged") 419 .addQueryParams( 420 staged.stream().map(s -> new ParamEntry<>("staged", s.toString())).collect(Collectors.toList())); 421 } 422 423 /** 424 * add additional staged query parameters 425 * @param <TValue> value type 426 * @param staged values to be added 427 * @return ByProjectKeyProductsByIDImagesPostString 428 */ 429 public <TValue> ByProjectKeyProductsByIDImagesPostString addStaged(final Collection<TValue> staged) { 430 return copy().addQueryParams( 431 staged.stream().map(s -> new ParamEntry<>("staged", s.toString())).collect(Collectors.toList())); 432 } 433 434 public String getBody() { 435 return file; 436 } 437 438 public ByProjectKeyProductsByIDImagesPostString withBody(String file) { 439 ByProjectKeyProductsByIDImagesPostString t = copy(); 440 t.file = file; 441 return t; 442 } 443 444 @Override 445 public boolean equals(Object o) { 446 if (this == o) 447 return true; 448 449 if (o == null || getClass() != o.getClass()) 450 return false; 451 452 ByProjectKeyProductsByIDImagesPostString that = (ByProjectKeyProductsByIDImagesPostString) o; 453 454 return new EqualsBuilder().append(projectKey, that.projectKey) 455 .append(ID, that.ID) 456 .append(file, that.file) 457 .isEquals(); 458 } 459 460 @Override 461 public int hashCode() { 462 return new HashCodeBuilder(17, 37).append(projectKey).append(ID).append(file).toHashCode(); 463 } 464 465 @Override 466 protected ByProjectKeyProductsByIDImagesPostString copy() { 467 return new ByProjectKeyProductsByIDImagesPostString(this); 468 } 469}