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