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>Produces the InventoryEntryCreated Message.</p> 022 * 023 * <hr> 024 * <div class=code-example> 025 * <pre><code class='java'>{@code 026 * CompletableFuture<ApiHttpResponse<com.commercetools.api.models.inventory.InventoryEntry>> result = apiRoot 027 * .withProjectKey("{projectKey}") 028 * .inventory() 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 ByProjectKeyInventoryPost extends 036 BodyApiMethod<ByProjectKeyInventoryPost, com.commercetools.api.models.inventory.InventoryEntry, com.commercetools.api.models.inventory.InventoryEntryDraft> 037 implements com.commercetools.api.client.ExpandableTrait<ByProjectKeyInventoryPost>, 038 com.commercetools.api.client.Deprecatable201Trait<ByProjectKeyInventoryPost>, 039 com.commercetools.api.client.ErrorableTrait<ByProjectKeyInventoryPost> { 040 041 private String projectKey; 042 043 private com.commercetools.api.models.inventory.InventoryEntryDraft inventoryEntryDraft; 044 045 public ByProjectKeyInventoryPost(final ApiHttpClient apiHttpClient, String projectKey, 046 com.commercetools.api.models.inventory.InventoryEntryDraft inventoryEntryDraft) { 047 super(apiHttpClient); 048 this.projectKey = projectKey; 049 this.inventoryEntryDraft = inventoryEntryDraft; 050 } 051 052 public ByProjectKeyInventoryPost(ByProjectKeyInventoryPost t) { 053 super(t); 054 this.projectKey = t.projectKey; 055 this.inventoryEntryDraft = t.inventoryEntryDraft; 056 } 057 058 @Override 059 protected ApiHttpRequest buildHttpRequest() { 060 List<String> params = new ArrayList<>(getQueryParamUriStrings()); 061 String httpRequestPath = String.format("%s/inventory", 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(inventoryEntryDraft))); 068 069 } 070 071 @Override 072 public ApiHttpResponse<com.commercetools.api.models.inventory.InventoryEntry> executeBlocking( 073 final ApiHttpClient client, final Duration timeout) { 074 return executeBlocking(client, timeout, com.commercetools.api.models.inventory.InventoryEntry.class); 075 } 076 077 @Override 078 public CompletableFuture<ApiHttpResponse<com.commercetools.api.models.inventory.InventoryEntry>> execute( 079 final ApiHttpClient client) { 080 return execute(client, com.commercetools.api.models.inventory.InventoryEntry.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 ByProjectKeyInventoryPost 100 */ 101 public <TValue> ByProjectKeyInventoryPost 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 ByProjectKeyInventoryPost 110 */ 111 public <TValue> ByProjectKeyInventoryPost 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 ByProjectKeyInventoryPost 119 */ 120 public ByProjectKeyInventoryPost 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 ByProjectKeyInventoryPost 128 */ 129 public ByProjectKeyInventoryPost 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 ByProjectKeyInventoryPost 137 */ 138 public ByProjectKeyInventoryPost 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 ByProjectKeyInventoryPost 146 */ 147 public ByProjectKeyInventoryPost 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 ByProjectKeyInventoryPost 156 */ 157 public <TValue> ByProjectKeyInventoryPost 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 ByProjectKeyInventoryPost 168 */ 169 public <TValue> ByProjectKeyInventoryPost 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.inventory.InventoryEntryDraft getBody() { 175 return inventoryEntryDraft; 176 } 177 178 public ByProjectKeyInventoryPost withBody( 179 com.commercetools.api.models.inventory.InventoryEntryDraft inventoryEntryDraft) { 180 ByProjectKeyInventoryPost t = copy(); 181 t.inventoryEntryDraft = inventoryEntryDraft; 182 return t; 183 } 184 185 @Override 186 public boolean equals(Object o) { 187 if (this == o) 188 return true; 189 190 if (o == null || getClass() != o.getClass()) 191 return false; 192 193 ByProjectKeyInventoryPost that = (ByProjectKeyInventoryPost) o; 194 195 return new EqualsBuilder().append(projectKey, that.projectKey) 196 .append(inventoryEntryDraft, that.inventoryEntryDraft) 197 .isEquals(); 198 } 199 200 @Override 201 public int hashCode() { 202 return new HashCodeBuilder(17, 37).append(projectKey).append(inventoryEntryDraft).toHashCode(); 203 } 204 205 @Override 206 protected ByProjectKeyInventoryPost copy() { 207 return new ByProjectKeyInventoryPost(this); 208 } 209}