001 002package com.commercetools.api.client; 003 004import java.net.URI; 005import java.time.Duration; 006import java.util.ArrayList; 007import java.util.Collection; 008import java.util.List; 009import java.util.concurrent.CompletableFuture; 010import java.util.function.Function; 011import java.util.function.Supplier; 012import java.util.stream.Collectors; 013 014import io.vrap.rmf.base.client.*; 015import io.vrap.rmf.base.client.utils.Generated; 016 017import org.apache.commons.lang3.builder.EqualsBuilder; 018import org.apache.commons.lang3.builder.HashCodeBuilder; 019 020/** 021 * <p>This endpoint can only update a Payment when it has no Transactions.</p> 022 * 023 * <hr> 024 * <div class=code-example> 025 * <pre><code class='java'>{@code 026 * CompletableFuture<ApiHttpResponse<com.commercetools.api.models.me.MyPayment>> result = apiRoot 027 * .withProjectKey("{projectKey}") 028 * .me() 029 * .payments() 030 * .withKey("{key}") 031 * .post(null) 032 * .execute() 033 * }</code></pre> 034 * </div> 035 */ 036@Generated(value = "io.vrap.rmf.codegen.rendering.CoreCodeGenerator", comments = "https://github.com/commercetools/rmf-codegen") 037public class ByProjectKeyMePaymentsKeyByKeyPost extends 038 BodyApiMethod<ByProjectKeyMePaymentsKeyByKeyPost, com.commercetools.api.models.me.MyPayment, com.commercetools.api.models.me.MyPaymentUpdate> 039 implements com.commercetools.api.client.ConflictingTrait<ByProjectKeyMePaymentsKeyByKeyPost>, 040 com.commercetools.api.client.ExpandableTrait<ByProjectKeyMePaymentsKeyByKeyPost>, 041 com.commercetools.api.client.Deprecatable200Trait<ByProjectKeyMePaymentsKeyByKeyPost>, 042 com.commercetools.api.client.ErrorableTrait<ByProjectKeyMePaymentsKeyByKeyPost> { 043 044 private String projectKey; 045 private String key; 046 047 private com.commercetools.api.models.me.MyPaymentUpdate myPaymentUpdate; 048 049 public ByProjectKeyMePaymentsKeyByKeyPost(final ApiHttpClient apiHttpClient, String projectKey, String key, 050 com.commercetools.api.models.me.MyPaymentUpdate myPaymentUpdate) { 051 super(apiHttpClient); 052 this.projectKey = projectKey; 053 this.key = key; 054 this.myPaymentUpdate = myPaymentUpdate; 055 } 056 057 public ByProjectKeyMePaymentsKeyByKeyPost(ByProjectKeyMePaymentsKeyByKeyPost t) { 058 super(t); 059 this.projectKey = t.projectKey; 060 this.key = t.key; 061 this.myPaymentUpdate = t.myPaymentUpdate; 062 } 063 064 @Override 065 protected ApiHttpRequest buildHttpRequest() { 066 List<String> params = new ArrayList<>(getQueryParamUriStrings()); 067 String httpRequestPath = String.format("%s/me/payments/key=%s", this.projectKey, this.key); 068 if (!params.isEmpty()) { 069 httpRequestPath += "?" + String.join("&", params); 070 } 071 return new ApiHttpRequest(ApiHttpMethod.POST, URI.create(httpRequestPath), getHeaders(), 072 io.vrap.rmf.base.client.utils.json.JsonUtils 073 .executing(() -> apiHttpClient().getSerializerService().toJsonByteArray(myPaymentUpdate))); 074 075 } 076 077 @Override 078 public ApiHttpResponse<com.commercetools.api.models.me.MyPayment> executeBlocking(final ApiHttpClient client, 079 final Duration timeout) { 080 return executeBlocking(client, timeout, com.commercetools.api.models.me.MyPayment.class); 081 } 082 083 @Override 084 public CompletableFuture<ApiHttpResponse<com.commercetools.api.models.me.MyPayment>> execute( 085 final ApiHttpClient client) { 086 return execute(client, com.commercetools.api.models.me.MyPayment.class); 087 } 088 089 public String getProjectKey() { 090 return this.projectKey; 091 } 092 093 public String getKey() { 094 return this.key; 095 } 096 097 public List<String> getExpand() { 098 return this.getQueryParam("expand"); 099 } 100 101 public void setProjectKey(final String projectKey) { 102 this.projectKey = projectKey; 103 } 104 105 public void setKey(final String key) { 106 this.key = key; 107 } 108 109 /** 110 * set expand with the specified value 111 * @param expand value to be set 112 * @param <TValue> value type 113 * @return ByProjectKeyMePaymentsKeyByKeyPost 114 */ 115 public <TValue> ByProjectKeyMePaymentsKeyByKeyPost withExpand(final TValue expand) { 116 return copy().withQueryParam("expand", expand); 117 } 118 119 /** 120 * add additional expand query parameter 121 * @param expand value to be added 122 * @param <TValue> value type 123 * @return ByProjectKeyMePaymentsKeyByKeyPost 124 */ 125 public <TValue> ByProjectKeyMePaymentsKeyByKeyPost addExpand(final TValue expand) { 126 return copy().addQueryParam("expand", expand); 127 } 128 129 /** 130 * set expand with the specified value 131 * @param supplier supplier for the value to be set 132 * @return ByProjectKeyMePaymentsKeyByKeyPost 133 */ 134 public ByProjectKeyMePaymentsKeyByKeyPost withExpand(final Supplier<String> supplier) { 135 return copy().withQueryParam("expand", supplier.get()); 136 } 137 138 /** 139 * add additional expand query parameter 140 * @param supplier supplier for the value to be added 141 * @return ByProjectKeyMePaymentsKeyByKeyPost 142 */ 143 public ByProjectKeyMePaymentsKeyByKeyPost addExpand(final Supplier<String> supplier) { 144 return copy().addQueryParam("expand", supplier.get()); 145 } 146 147 /** 148 * set expand with the specified value 149 * @param op builder for the value to be set 150 * @return ByProjectKeyMePaymentsKeyByKeyPost 151 */ 152 public ByProjectKeyMePaymentsKeyByKeyPost withExpand(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 ByProjectKeyMePaymentsKeyByKeyPost 160 */ 161 public ByProjectKeyMePaymentsKeyByKeyPost addExpand(final Function<StringBuilder, StringBuilder> op) { 162 return copy().addQueryParam("expand", op.apply(new StringBuilder())); 163 } 164 165 /** 166 * set expand with the specified values 167 * @param expand values to be set 168 * @param <TValue> value type 169 * @return ByProjectKeyMePaymentsKeyByKeyPost 170 */ 171 public <TValue> ByProjectKeyMePaymentsKeyByKeyPost withExpand(final Collection<TValue> expand) { 172 return copy().withoutQueryParam("expand") 173 .addQueryParams( 174 expand.stream().map(s -> new ParamEntry<>("expand", s.toString())).collect(Collectors.toList())); 175 } 176 177 /** 178 * add additional expand query parameters 179 * @param expand values to be added 180 * @param <TValue> value type 181 * @return ByProjectKeyMePaymentsKeyByKeyPost 182 */ 183 public <TValue> ByProjectKeyMePaymentsKeyByKeyPost addExpand(final Collection<TValue> expand) { 184 return copy().addQueryParams( 185 expand.stream().map(s -> new ParamEntry<>("expand", s.toString())).collect(Collectors.toList())); 186 } 187 188 public com.commercetools.api.models.me.MyPaymentUpdate getBody() { 189 return myPaymentUpdate; 190 } 191 192 public ByProjectKeyMePaymentsKeyByKeyPost withBody( 193 com.commercetools.api.models.me.MyPaymentUpdate myPaymentUpdate) { 194 ByProjectKeyMePaymentsKeyByKeyPost t = copy(); 195 t.myPaymentUpdate = myPaymentUpdate; 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 ByProjectKeyMePaymentsKeyByKeyPost that = (ByProjectKeyMePaymentsKeyByKeyPost) o; 208 209 return new EqualsBuilder().append(projectKey, that.projectKey) 210 .append(key, that.key) 211 .append(myPaymentUpdate, that.myPaymentUpdate) 212 .isEquals(); 213 } 214 215 @Override 216 public int hashCode() { 217 return new HashCodeBuilder(17, 37).append(projectKey).append(key).append(myPaymentUpdate).toHashCode(); 218 } 219 220 @Override 221 protected ByProjectKeyMePaymentsKeyByKeyPost copy() { 222 return new ByProjectKeyMePaymentsKeyByKeyPost(this); 223 } 224}