001 002package com.commercetools.api.client; 003 004import java.net.URI; 005import java.time.Duration; 006import java.util.ArrayList; 007import java.util.List; 008import java.util.concurrent.CompletableFuture; 009 010import io.vrap.rmf.base.client.*; 011import io.vrap.rmf.base.client.utils.Generated; 012 013import org.apache.commons.lang3.builder.EqualsBuilder; 014import org.apache.commons.lang3.builder.HashCodeBuilder; 015 016/** 017 * <p>Creates a new Cart by replicating an existing Cart or Order. Can be useful in cases where a customer wants to cancel a recent order to make some changes or reorder a previous order.</p> 018 * <p>The replicated Cart preserves Customer information, Line Items and Custom Line Items, Custom Fields, Discount Codes, and other settings of the Cart or Order. If the Line Items become invalid, for example, due to removed Products or Prices, they are removed from the new Cart. If the Customer switches to another Customer Group, the new Cart is updated with the new value. It has up-to-date Tax Rates, Prices, and Line Item product data and is in <code>Active</code> CartState.</p> 019 * <p>The new Cart does not contain payments or deliveries. The State of Line Items and Custom Line Items is reset to <code>initial</code>.</p> 020 * 021 * <hr> 022 * <div class=code-example> 023 * <pre><code class='java'>{@code 024 * CompletableFuture<ApiHttpResponse<com.commercetools.api.models.cart.Cart>> result = apiRoot 025 * .withProjectKey("{projectKey}") 026 * .inStoreKeyWithStoreKeyValue("{storeKey}") 027 * .carts() 028 * .replicate() 029 * .post(null) 030 * .execute() 031 * }</code></pre> 032 * </div> 033 */ 034@Generated(value = "io.vrap.rmf.codegen.rendering.CoreCodeGenerator", comments = "https://github.com/commercetools/rmf-codegen") 035public class ByProjectKeyInStoreKeyByStoreKeyCartsReplicatePost extends 036 BodyApiMethod<ByProjectKeyInStoreKeyByStoreKeyCartsReplicatePost, com.commercetools.api.models.cart.Cart, com.commercetools.api.models.cart.ReplicaCartDraft> 037 implements com.commercetools.api.client.ErrorableTrait<ByProjectKeyInStoreKeyByStoreKeyCartsReplicatePost> { 038 039 private String projectKey; 040 private String storeKey; 041 042 private com.commercetools.api.models.cart.ReplicaCartDraft replicaCartDraft; 043 044 public ByProjectKeyInStoreKeyByStoreKeyCartsReplicatePost(final ApiHttpClient apiHttpClient, String projectKey, 045 String storeKey, com.commercetools.api.models.cart.ReplicaCartDraft replicaCartDraft) { 046 super(apiHttpClient); 047 this.projectKey = projectKey; 048 this.storeKey = storeKey; 049 this.replicaCartDraft = replicaCartDraft; 050 } 051 052 public ByProjectKeyInStoreKeyByStoreKeyCartsReplicatePost(ByProjectKeyInStoreKeyByStoreKeyCartsReplicatePost t) { 053 super(t); 054 this.projectKey = t.projectKey; 055 this.storeKey = t.storeKey; 056 this.replicaCartDraft = t.replicaCartDraft; 057 } 058 059 @Override 060 protected ApiHttpRequest buildHttpRequest() { 061 List<String> params = new ArrayList<>(getQueryParamUriStrings()); 062 String httpRequestPath = String.format("%s/in-store/key=%s/carts/replicate", this.projectKey, this.storeKey); 063 if (!params.isEmpty()) { 064 httpRequestPath += "?" + String.join("&", params); 065 } 066 return new ApiHttpRequest(ApiHttpMethod.POST, URI.create(httpRequestPath), getHeaders(), 067 io.vrap.rmf.base.client.utils.json.JsonUtils 068 .executing(() -> apiHttpClient().getSerializerService().toJsonByteArray(replicaCartDraft))); 069 070 } 071 072 @Override 073 public ApiHttpResponse<com.commercetools.api.models.cart.Cart> executeBlocking(final ApiHttpClient client, 074 final Duration timeout) { 075 return executeBlocking(client, timeout, com.commercetools.api.models.cart.Cart.class); 076 } 077 078 @Override 079 public CompletableFuture<ApiHttpResponse<com.commercetools.api.models.cart.Cart>> execute( 080 final ApiHttpClient client) { 081 return execute(client, com.commercetools.api.models.cart.Cart.class); 082 } 083 084 public String getProjectKey() { 085 return this.projectKey; 086 } 087 088 public String getStoreKey() { 089 return this.storeKey; 090 } 091 092 public void setProjectKey(final String projectKey) { 093 this.projectKey = projectKey; 094 } 095 096 public void setStoreKey(final String storeKey) { 097 this.storeKey = storeKey; 098 } 099 100 public com.commercetools.api.models.cart.ReplicaCartDraft getBody() { 101 return replicaCartDraft; 102 } 103 104 public ByProjectKeyInStoreKeyByStoreKeyCartsReplicatePost withBody( 105 com.commercetools.api.models.cart.ReplicaCartDraft replicaCartDraft) { 106 ByProjectKeyInStoreKeyByStoreKeyCartsReplicatePost t = copy(); 107 t.replicaCartDraft = replicaCartDraft; 108 return t; 109 } 110 111 @Override 112 public boolean equals(Object o) { 113 if (this == o) 114 return true; 115 116 if (o == null || getClass() != o.getClass()) 117 return false; 118 119 ByProjectKeyInStoreKeyByStoreKeyCartsReplicatePost that = (ByProjectKeyInStoreKeyByStoreKeyCartsReplicatePost) o; 120 121 return new EqualsBuilder().append(projectKey, that.projectKey) 122 .append(storeKey, that.storeKey) 123 .append(replicaCartDraft, that.replicaCartDraft) 124 .isEquals(); 125 } 126 127 @Override 128 public int hashCode() { 129 return new HashCodeBuilder(17, 37).append(projectKey).append(storeKey).append(replicaCartDraft).toHashCode(); 130 } 131 132 @Override 133 protected ByProjectKeyInStoreKeyByStoreKeyCartsReplicatePost copy() { 134 return new ByProjectKeyInStoreKeyByStoreKeyCartsReplicatePost(this); 135 } 136}