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>When using this endpoint, if omitted, the Customer <code>stores</code> field is set to the Store specified in the path parameter.</p> 023 * <p>If the <code>anonymousCart</code> field is set on the CustomerDraft, then the newly created Customer will be assigned to that Cart. Similarly, if the <code>anonymousId</code> field is set, the Customer will be set on all Carts, Orders, ShoppingLists and Payments with the same <code>anonymousId</code>. If a Cart with a <code>store</code> field specified, the <code>store</code> field must reference the same Store specified in the <code>{storeKey}</code> path parameter. Creating a Customer produces the CustomerCreated Message.</p> 024 * 025 * <hr> 026 * <div class=code-example> 027 * <pre><code class='java'>{@code 028 * CompletableFuture<ApiHttpResponse<com.commercetools.api.models.customer.CustomerSignInResult>> result = apiRoot 029 * .withProjectKey("{projectKey}") 030 * .inStoreKeyWithStoreKeyValue("{storeKey}") 031 * .customers() 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 ByProjectKeyInStoreKeyByStoreKeyCustomersPostString extends 039 StringBodyApiMethod<ByProjectKeyInStoreKeyByStoreKeyCustomersPostString, com.commercetools.api.models.customer.CustomerSignInResult> 040 implements com.commercetools.api.client.ExpandableTrait<ByProjectKeyInStoreKeyByStoreKeyCustomersPostString>, 041 com.commercetools.api.client.Deprecatable201Trait<ByProjectKeyInStoreKeyByStoreKeyCustomersPostString>, 042 com.commercetools.api.client.ErrorableTrait<ByProjectKeyInStoreKeyByStoreKeyCustomersPostString> { 043 044 private String projectKey; 045 private String storeKey; 046 047 private String customerDraft; 048 049 public ByProjectKeyInStoreKeyByStoreKeyCustomersPostString(final ApiHttpClient apiHttpClient, String projectKey, 050 String storeKey, String customerDraft) { 051 super(apiHttpClient); 052 this.projectKey = projectKey; 053 this.storeKey = storeKey; 054 this.customerDraft = customerDraft; 055 } 056 057 public ByProjectKeyInStoreKeyByStoreKeyCustomersPostString(ByProjectKeyInStoreKeyByStoreKeyCustomersPostString t) { 058 super(t); 059 this.projectKey = t.projectKey; 060 this.storeKey = t.storeKey; 061 this.customerDraft = t.customerDraft; 062 } 063 064 @Override 065 protected ApiHttpRequest buildHttpRequest() { 066 List<String> params = new ArrayList<>(getQueryParamUriStrings()); 067 String httpRequestPath = String.format("%s/in-store/key=%s/customers", this.projectKey, this.storeKey); 068 if (!params.isEmpty()) { 069 httpRequestPath += "?" + String.join("&", params); 070 } 071 return new ApiHttpRequest(ApiHttpMethod.POST, URI.create(httpRequestPath), getHeaders(), 072 customerDraft.getBytes(StandardCharsets.UTF_8)); 073 074 } 075 076 @Override 077 public ApiHttpResponse<com.commercetools.api.models.customer.CustomerSignInResult> executeBlocking( 078 final ApiHttpClient client, final Duration timeout) { 079 return executeBlocking(client, timeout, com.commercetools.api.models.customer.CustomerSignInResult.class); 080 } 081 082 @Override 083 public CompletableFuture<ApiHttpResponse<com.commercetools.api.models.customer.CustomerSignInResult>> execute( 084 final ApiHttpClient client) { 085 return execute(client, com.commercetools.api.models.customer.CustomerSignInResult.class); 086 } 087 088 public String getProjectKey() { 089 return this.projectKey; 090 } 091 092 public String getStoreKey() { 093 return this.storeKey; 094 } 095 096 public List<String> getExpand() { 097 return this.getQueryParam("expand"); 098 } 099 100 public void setProjectKey(final String projectKey) { 101 this.projectKey = projectKey; 102 } 103 104 public void setStoreKey(final String storeKey) { 105 this.storeKey = storeKey; 106 } 107 108 /** 109 * set expand with the specified value 110 * @param <TValue> value type 111 * @param expand value to be set 112 * @return ByProjectKeyInStoreKeyByStoreKeyCustomersPostString 113 */ 114 public <TValue> ByProjectKeyInStoreKeyByStoreKeyCustomersPostString withExpand(final TValue expand) { 115 return copy().withQueryParam("expand", expand); 116 } 117 118 /** 119 * add additional expand query parameter 120 * @param <TValue> value type 121 * @param expand value to be added 122 * @return ByProjectKeyInStoreKeyByStoreKeyCustomersPostString 123 */ 124 public <TValue> ByProjectKeyInStoreKeyByStoreKeyCustomersPostString addExpand(final TValue expand) { 125 return copy().addQueryParam("expand", expand); 126 } 127 128 /** 129 * set expand with the specified value 130 * @param supplier supplier for the value to be set 131 * @return ByProjectKeyInStoreKeyByStoreKeyCustomersPostString 132 */ 133 public ByProjectKeyInStoreKeyByStoreKeyCustomersPostString withExpand(final Supplier<String> supplier) { 134 return copy().withQueryParam("expand", supplier.get()); 135 } 136 137 /** 138 * add additional expand query parameter 139 * @param supplier supplier for the value to be added 140 * @return ByProjectKeyInStoreKeyByStoreKeyCustomersPostString 141 */ 142 public ByProjectKeyInStoreKeyByStoreKeyCustomersPostString addExpand(final Supplier<String> supplier) { 143 return copy().addQueryParam("expand", supplier.get()); 144 } 145 146 /** 147 * set expand with the specified value 148 * @param op builder for the value to be set 149 * @return ByProjectKeyInStoreKeyByStoreKeyCustomersPostString 150 */ 151 public ByProjectKeyInStoreKeyByStoreKeyCustomersPostString withExpand( 152 final Function<StringBuilder, StringBuilder> op) { 153 return copy().withQueryParam("expand", op.apply(new StringBuilder())); 154 } 155 156 /** 157 * add additional expand query parameter 158 * @param op builder for the value to be added 159 * @return ByProjectKeyInStoreKeyByStoreKeyCustomersPostString 160 */ 161 public ByProjectKeyInStoreKeyByStoreKeyCustomersPostString addExpand( 162 final Function<StringBuilder, StringBuilder> op) { 163 return copy().addQueryParam("expand", op.apply(new StringBuilder())); 164 } 165 166 /** 167 * set expand with the specified values 168 * @param <TValue> value type 169 * @param expand values to be set 170 * @return ByProjectKeyInStoreKeyByStoreKeyCustomersPostString 171 */ 172 public <TValue> ByProjectKeyInStoreKeyByStoreKeyCustomersPostString withExpand(final Collection<TValue> expand) { 173 return copy().withoutQueryParam("expand") 174 .addQueryParams( 175 expand.stream().map(s -> new ParamEntry<>("expand", s.toString())).collect(Collectors.toList())); 176 } 177 178 /** 179 * add additional expand query parameters 180 * @param <TValue> value type 181 * @param expand values to be added 182 * @return ByProjectKeyInStoreKeyByStoreKeyCustomersPostString 183 */ 184 public <TValue> ByProjectKeyInStoreKeyByStoreKeyCustomersPostString addExpand(final Collection<TValue> expand) { 185 return copy().addQueryParams( 186 expand.stream().map(s -> new ParamEntry<>("expand", s.toString())).collect(Collectors.toList())); 187 } 188 189 public String getBody() { 190 return customerDraft; 191 } 192 193 public ByProjectKeyInStoreKeyByStoreKeyCustomersPostString withBody(String customerDraft) { 194 ByProjectKeyInStoreKeyByStoreKeyCustomersPostString t = copy(); 195 t.customerDraft = customerDraft; 196 return t; 197 } 198 199 @Override 200 public boolean equals(Object o) { 201 if (this == o) 202 return true; 203 204 if (o == null || getClass() != o.getClass()) 205 return false; 206 207 ByProjectKeyInStoreKeyByStoreKeyCustomersPostString that = (ByProjectKeyInStoreKeyByStoreKeyCustomersPostString) o; 208 209 return new EqualsBuilder().append(projectKey, that.projectKey) 210 .append(storeKey, that.storeKey) 211 .append(customerDraft, that.customerDraft) 212 .isEquals(); 213 } 214 215 @Override 216 public int hashCode() { 217 return new HashCodeBuilder(17, 37).append(projectKey).append(storeKey).append(customerDraft).toHashCode(); 218 } 219 220 @Override 221 protected ByProjectKeyInStoreKeyByStoreKeyCustomersPostString copy() { 222 return new ByProjectKeyInStoreKeyByStoreKeyCustomersPostString(this); 223 } 224}