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