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