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.List; 009import java.util.concurrent.CompletableFuture; 010 011import io.vrap.rmf.base.client.*; 012import io.vrap.rmf.base.client.utils.Generated; 013 014import org.apache.commons.lang3.builder.EqualsBuilder; 015import org.apache.commons.lang3.builder.HashCodeBuilder; 016 017/** 018 * <p>The My Business Unit endpoint does not support assigning existing Customers to a Business Unit. Associates with the <code>UpdateAssociates</code> Permission can use this endpoint to create a new Customer and associate it with the Business Unit. If the required Permission is missing, an AssociateMissingPermission error is returned.</p> 019 * 020 * <hr> 021 * <div class=code-example> 022 * <pre><code class='java'>{@code 023 * CompletableFuture<ApiHttpResponse<com.commercetools.api.models.customer.CustomerSignInResult>> result = apiRoot 024 * .withProjectKey("{projectKey}") 025 * .inBusinessUnitKeyWithBusinessUnitKeyValue("{businessUnitKey}") 026 * .me() 027 * .customers() 028 * .post("") 029 * .execute() 030 * }</code></pre> 031 * </div> 032 */ 033@Generated(value = "io.vrap.rmf.codegen.rendering.CoreCodeGenerator", comments = "https://github.com/commercetools/rmf-codegen") 034public class ByProjectKeyInBusinessUnitKeyByBusinessUnitKeyMeCustomersPostString extends 035 StringBodyApiMethod<ByProjectKeyInBusinessUnitKeyByBusinessUnitKeyMeCustomersPostString, com.commercetools.api.models.customer.CustomerSignInResult> { 036 037 private String projectKey; 038 private String businessUnitKey; 039 040 private String myBusinessUnitAssociateDraft; 041 042 public ByProjectKeyInBusinessUnitKeyByBusinessUnitKeyMeCustomersPostString(final ApiHttpClient apiHttpClient, 043 String projectKey, String businessUnitKey, String myBusinessUnitAssociateDraft) { 044 super(apiHttpClient); 045 this.projectKey = projectKey; 046 this.businessUnitKey = businessUnitKey; 047 this.myBusinessUnitAssociateDraft = myBusinessUnitAssociateDraft; 048 } 049 050 public ByProjectKeyInBusinessUnitKeyByBusinessUnitKeyMeCustomersPostString( 051 ByProjectKeyInBusinessUnitKeyByBusinessUnitKeyMeCustomersPostString t) { 052 super(t); 053 this.projectKey = t.projectKey; 054 this.businessUnitKey = t.businessUnitKey; 055 this.myBusinessUnitAssociateDraft = t.myBusinessUnitAssociateDraft; 056 } 057 058 @Override 059 protected ApiHttpRequest buildHttpRequest() { 060 List<String> params = new ArrayList<>(getQueryParamUriStrings()); 061 String httpRequestPath = String.format("%s/in-business-unit/key=%s/me/customers", this.projectKey, 062 this.businessUnitKey); 063 if (!params.isEmpty()) { 064 httpRequestPath += "?" + String.join("&", params); 065 } 066 return new ApiHttpRequest(ApiHttpMethod.POST, URI.create(httpRequestPath), getHeaders(), 067 myBusinessUnitAssociateDraft.getBytes(StandardCharsets.UTF_8)); 068 069 } 070 071 @Override 072 public ApiHttpResponse<com.commercetools.api.models.customer.CustomerSignInResult> executeBlocking( 073 final ApiHttpClient client, final Duration timeout) { 074 return executeBlocking(client, timeout, com.commercetools.api.models.customer.CustomerSignInResult.class); 075 } 076 077 @Override 078 public CompletableFuture<ApiHttpResponse<com.commercetools.api.models.customer.CustomerSignInResult>> execute( 079 final ApiHttpClient client) { 080 return execute(client, com.commercetools.api.models.customer.CustomerSignInResult.class); 081 } 082 083 public String getProjectKey() { 084 return this.projectKey; 085 } 086 087 public String getBusinessUnitKey() { 088 return this.businessUnitKey; 089 } 090 091 public void setProjectKey(final String projectKey) { 092 this.projectKey = projectKey; 093 } 094 095 public void setBusinessUnitKey(final String businessUnitKey) { 096 this.businessUnitKey = businessUnitKey; 097 } 098 099 public String getBody() { 100 return myBusinessUnitAssociateDraft; 101 } 102 103 public ByProjectKeyInBusinessUnitKeyByBusinessUnitKeyMeCustomersPostString withBody( 104 String myBusinessUnitAssociateDraft) { 105 ByProjectKeyInBusinessUnitKeyByBusinessUnitKeyMeCustomersPostString t = copy(); 106 t.myBusinessUnitAssociateDraft = myBusinessUnitAssociateDraft; 107 return t; 108 } 109 110 @Override 111 public boolean equals(Object o) { 112 if (this == o) 113 return true; 114 115 if (o == null || getClass() != o.getClass()) 116 return false; 117 118 ByProjectKeyInBusinessUnitKeyByBusinessUnitKeyMeCustomersPostString that = (ByProjectKeyInBusinessUnitKeyByBusinessUnitKeyMeCustomersPostString) o; 119 120 return new EqualsBuilder().append(projectKey, that.projectKey) 121 .append(businessUnitKey, that.businessUnitKey) 122 .append(myBusinessUnitAssociateDraft, that.myBusinessUnitAssociateDraft) 123 .isEquals(); 124 } 125 126 @Override 127 public int hashCode() { 128 return new HashCodeBuilder(17, 37).append(projectKey) 129 .append(businessUnitKey) 130 .append(myBusinessUnitAssociateDraft) 131 .toHashCode(); 132 } 133 134 @Override 135 protected ByProjectKeyInBusinessUnitKeyByBusinessUnitKeyMeCustomersPostString copy() { 136 return new ByProjectKeyInBusinessUnitKeyByBusinessUnitKeyMeCustomersPostString(this); 137 } 138}