001 002package com.commercetools.history.models.change_history; 003 004import java.time.*; 005import java.util.*; 006import java.util.function.Function; 007import java.util.stream.Collectors; 008 009import javax.annotation.Nullable; 010import javax.validation.Valid; 011import javax.validation.constraints.NotNull; 012 013import com.commercetools.history.models.change.Change; 014import com.commercetools.history.models.common.KeyReference; 015import com.commercetools.history.models.common.ResourceIdentifier; 016import com.commercetools.history.models.label.Label; 017import com.fasterxml.jackson.annotation.*; 018import com.fasterxml.jackson.databind.annotation.*; 019 020import io.vrap.rmf.base.client.utils.Generated; 021 022/** 023 * <p>Captures the differences between the previous and next version of a resource.</p> 024 * <p>The maximum number of Records that can be stored and their retention period are subject to a limit.</p> 025 * 026 * <hr> 027 * Example to create an instance using the builder pattern 028 * <div class=code-example> 029 * <pre><code class='java'> 030 * Record record = Record.builder() 031 * .version(1) 032 * .previousVersion(1) 033 * .type("{type}") 034 * .modifiedBy(modifiedByBuilder -> modifiedByBuilder) 035 * .modifiedAt("{modifiedAt}") 036 * .label(labelBuilder -> labelBuilder) 037 * .previousLabel(previousLabelBuilder -> previousLabelBuilder) 038 * .plusChanges(changesBuilder -> changesBuilder) 039 * .resource(resourceBuilder -> resourceBuilder) 040 * .plusStores(storesBuilder -> storesBuilder) 041 * .withoutChanges(true) 042 * .build() 043 * </code></pre> 044 * </div> 045 */ 046@Generated(value = "io.vrap.rmf.codegen.rendering.CoreCodeGenerator", comments = "https://github.com/commercetools/rmf-codegen") 047@JsonDeserialize(as = RecordImpl.class) 048public interface Record { 049 050 /** 051 * <p>Version of the resource after the change.</p> 052 * <p>For more information on how the version is incremented, see Optimistic Concurrency Control.</p> 053 * @return version 054 */ 055 @NotNull 056 @JsonProperty("version") 057 public Integer getVersion(); 058 059 /** 060 * <p>Version of the resource before the change.</p> 061 * @return previousVersion 062 */ 063 @NotNull 064 @JsonProperty("previousVersion") 065 public Integer getPreviousVersion(); 066 067 /** 068 * <p>Indicates the type of change. For creation, update, or deletion, the value is <code>"ResourceCreated"</code>, <code>"ResourceUpdated"</code>, or <code>"ResourceDeleted"</code> respectively.</p> 069 * @return type 070 */ 071 @NotNull 072 @JsonProperty("type") 073 public String getType(); 074 075 /** 076 * <p>Information about the user or API Client who performed the change.</p> 077 * @return modifiedBy 078 */ 079 @NotNull 080 @Valid 081 @JsonProperty("modifiedBy") 082 public ModifiedBy getModifiedBy(); 083 084 /** 085 * <p>Date and time (UTC) when the change was made.</p> 086 * @return modifiedAt 087 */ 088 @NotNull 089 @JsonProperty("modifiedAt") 090 public String getModifiedAt(); 091 092 /** 093 * <p>Information that describes the resource after the change.</p> 094 * @return label 095 */ 096 @NotNull 097 @Valid 098 @JsonProperty("label") 099 public Label getLabel(); 100 101 /** 102 * <p>Information that describes the resource before the change.</p> 103 * @return previousLabel 104 */ 105 @NotNull 106 @Valid 107 @JsonProperty("previousLabel") 108 public Label getPreviousLabel(); 109 110 /** 111 * <p>Shows the differences in the resource between <code>previousVersion</code> and <code>version</code>.</p> 112 * <p>The value is not identical to the actual array of update actions sent and is not limited to update actions (see, for example, Optimistic Concurrency Control).</p> 113 * @return changes 114 */ 115 @NotNull 116 @Valid 117 @JsonProperty("changes") 118 public List<Change> getChanges(); 119 120 /** 121 * <p>ResourceIdentifier of the changed resource.</p> 122 * @return resource 123 */ 124 @NotNull 125 @Valid 126 @JsonProperty("resource") 127 public ResourceIdentifier getResource(); 128 129 /** 130 * <p>References to the Stores associated with the Change.</p> 131 * @return stores 132 */ 133 @NotNull 134 @Valid 135 @JsonProperty("stores") 136 public List<KeyReference> getStores(); 137 138 /** 139 * <p><code>true</code> if no change was detected.</p> 140 * <p>The version number of the resource can be increased even without any change in the resource.</p> 141 * @return withoutChanges 142 */ 143 @NotNull 144 @JsonProperty("withoutChanges") 145 public Boolean getWithoutChanges(); 146 147 /** 148 * <p>Version of the resource after the change.</p> 149 * <p>For more information on how the version is incremented, see Optimistic Concurrency Control.</p> 150 * @param version value to be set 151 */ 152 153 public void setVersion(final Integer version); 154 155 /** 156 * <p>Version of the resource before the change.</p> 157 * @param previousVersion value to be set 158 */ 159 160 public void setPreviousVersion(final Integer previousVersion); 161 162 /** 163 * <p>Indicates the type of change. For creation, update, or deletion, the value is <code>"ResourceCreated"</code>, <code>"ResourceUpdated"</code>, or <code>"ResourceDeleted"</code> respectively.</p> 164 * @param type value to be set 165 */ 166 167 public void setType(final String type); 168 169 /** 170 * <p>Information about the user or API Client who performed the change.</p> 171 * @param modifiedBy value to be set 172 */ 173 174 public void setModifiedBy(final ModifiedBy modifiedBy); 175 176 /** 177 * <p>Date and time (UTC) when the change was made.</p> 178 * @param modifiedAt value to be set 179 */ 180 181 public void setModifiedAt(final String modifiedAt); 182 183 /** 184 * <p>Information that describes the resource after the change.</p> 185 * @param label value to be set 186 */ 187 188 public void setLabel(final Label label); 189 190 /** 191 * <p>Information that describes the resource before the change.</p> 192 * @param previousLabel value to be set 193 */ 194 195 public void setPreviousLabel(final Label previousLabel); 196 197 /** 198 * <p>Shows the differences in the resource between <code>previousVersion</code> and <code>version</code>.</p> 199 * <p>The value is not identical to the actual array of update actions sent and is not limited to update actions (see, for example, Optimistic Concurrency Control).</p> 200 * @param changes values to be set 201 */ 202 203 @JsonIgnore 204 public void setChanges(final Change... changes); 205 206 /** 207 * <p>Shows the differences in the resource between <code>previousVersion</code> and <code>version</code>.</p> 208 * <p>The value is not identical to the actual array of update actions sent and is not limited to update actions (see, for example, Optimistic Concurrency Control).</p> 209 * @param changes values to be set 210 */ 211 212 public void setChanges(final List<Change> changes); 213 214 /** 215 * <p>ResourceIdentifier of the changed resource.</p> 216 * @param resource value to be set 217 */ 218 219 public void setResource(final ResourceIdentifier resource); 220 221 /** 222 * <p>References to the Stores associated with the Change.</p> 223 * @param stores values to be set 224 */ 225 226 @JsonIgnore 227 public void setStores(final KeyReference... stores); 228 229 /** 230 * <p>References to the Stores associated with the Change.</p> 231 * @param stores values to be set 232 */ 233 234 public void setStores(final List<KeyReference> stores); 235 236 /** 237 * <p><code>true</code> if no change was detected.</p> 238 * <p>The version number of the resource can be increased even without any change in the resource.</p> 239 * @param withoutChanges value to be set 240 */ 241 242 public void setWithoutChanges(final Boolean withoutChanges); 243 244 /** 245 * factory method 246 * @return instance of Record 247 */ 248 public static Record of() { 249 return new RecordImpl(); 250 } 251 252 /** 253 * factory method to create a shallow copy Record 254 * @param template instance to be copied 255 * @return copy instance 256 */ 257 public static Record of(final Record template) { 258 RecordImpl instance = new RecordImpl(); 259 instance.setVersion(template.getVersion()); 260 instance.setPreviousVersion(template.getPreviousVersion()); 261 instance.setType(template.getType()); 262 instance.setModifiedBy(template.getModifiedBy()); 263 instance.setModifiedAt(template.getModifiedAt()); 264 instance.setLabel(template.getLabel()); 265 instance.setPreviousLabel(template.getPreviousLabel()); 266 instance.setChanges(template.getChanges()); 267 instance.setResource(template.getResource()); 268 instance.setStores(template.getStores()); 269 instance.setWithoutChanges(template.getWithoutChanges()); 270 return instance; 271 } 272 273 /** 274 * factory method to create a deep copy of Record 275 * @param template instance to be copied 276 * @return copy instance 277 */ 278 @Nullable 279 public static Record deepCopy(@Nullable final Record template) { 280 if (template == null) { 281 return null; 282 } 283 RecordImpl instance = new RecordImpl(); 284 instance.setVersion(template.getVersion()); 285 instance.setPreviousVersion(template.getPreviousVersion()); 286 instance.setType(template.getType()); 287 instance.setModifiedBy( 288 com.commercetools.history.models.change_history.ModifiedBy.deepCopy(template.getModifiedBy())); 289 instance.setModifiedAt(template.getModifiedAt()); 290 instance.setLabel(com.commercetools.history.models.label.Label.deepCopy(template.getLabel())); 291 instance.setPreviousLabel(com.commercetools.history.models.label.Label.deepCopy(template.getPreviousLabel())); 292 instance.setChanges(Optional.ofNullable(template.getChanges()) 293 .map(t -> t.stream() 294 .map(com.commercetools.history.models.change.Change::deepCopy) 295 .collect(Collectors.toList())) 296 .orElse(null)); 297 instance.setResource( 298 com.commercetools.history.models.common.ResourceIdentifier.deepCopy(template.getResource())); 299 instance.setStores(Optional.ofNullable(template.getStores()) 300 .map(t -> t.stream() 301 .map(com.commercetools.history.models.common.KeyReference::deepCopy) 302 .collect(Collectors.toList())) 303 .orElse(null)); 304 instance.setWithoutChanges(template.getWithoutChanges()); 305 return instance; 306 } 307 308 /** 309 * builder factory method for Record 310 * @return builder 311 */ 312 public static RecordBuilder builder() { 313 return RecordBuilder.of(); 314 } 315 316 /** 317 * create builder for Record instance 318 * @param template instance with prefilled values for the builder 319 * @return builder 320 */ 321 public static RecordBuilder builder(final Record template) { 322 return RecordBuilder.of(template); 323 } 324 325 /** 326 * accessor map function 327 * @param <T> mapped type 328 * @param helper function to map the object 329 * @return mapped value 330 */ 331 default <T> T withRecord(Function<Record, T> helper) { 332 return helper.apply(this); 333 } 334 335 /** 336 * gives a TypeReference for usage with Jackson DataBind 337 * @return TypeReference 338 */ 339 public static com.fasterxml.jackson.core.type.TypeReference<Record> typeReference() { 340 return new com.fasterxml.jackson.core.type.TypeReference<Record>() { 341 @Override 342 public String toString() { 343 return "TypeReference<Record>"; 344 } 345 }; 346 } 347}