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