Update Event API

- Adjust OrderPlacedEvent to only construct the order
- Introduce ProductAddedEvent to be able to add several products
to a order
- Introduce ProductCountIncrementedEvent to increase the number of
product instances for a given Order
- Introduce ProductCountDecrementedEvent to increase the number of
product instances for a given Order
- Introduce ProductRemovedEvent to signal whenever all the product count
 drops below 1

#BAEL-4767
This commit is contained in:
Steven van Beelen 2021-03-19 10:59:26 +01:00
parent 10c0f2302e
commit a9812052df
5 changed files with 200 additions and 20 deletions

View File

@ -5,44 +5,36 @@ import java.util.Objects;
public class OrderPlacedEvent {
private final String orderId;
private final String product;
public OrderPlacedEvent(String orderId, String product) {
public OrderPlacedEvent(String orderId) {
this.orderId = orderId;
this.product = product;
}
public String getOrderId() {
return orderId;
}
public String getProduct() {
return product;
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
OrderPlacedEvent that = (OrderPlacedEvent) o;
return Objects.equals(orderId, that.orderId);
}
@Override
public int hashCode() {
return Objects.hash(orderId, product);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
final OrderPlacedEvent other = (OrderPlacedEvent) obj;
return Objects.equals(this.orderId, other.orderId)
&& Objects.equals(this.product, other.product);
return Objects.hash(orderId);
}
@Override
public String toString() {
return "OrderPlacedEvent{" +
"orderId='" + orderId + '\'' +
", product='" + product + '\'' +
'}';
}
}

View File

@ -0,0 +1,47 @@
package com.baeldung.axon.coreapi.events;
import java.util.Objects;
public class ProductAddedEvent {
private final String orderId;
private final String productId;
public ProductAddedEvent(String orderId, String productId) {
this.orderId = orderId;
this.productId = productId;
}
public String getOrderId() {
return orderId;
}
public String getProductId() {
return productId;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ProductAddedEvent that = (ProductAddedEvent) o;
return Objects.equals(orderId, that.orderId) && Objects.equals(productId, that.productId);
}
@Override
public int hashCode() {
return Objects.hash(orderId, productId);
}
@Override
public String toString() {
return "ProductAddedEvent{" +
"orderId='" + orderId + '\'' +
", productId='" + productId + '\'' +
'}';
}
}

View File

@ -0,0 +1,47 @@
package com.baeldung.axon.coreapi.events;
import java.util.Objects;
public class ProductCountDecrementedEvent {
private final String orderId;
private final String productId;
public ProductCountDecrementedEvent(String orderId, String productId) {
this.orderId = orderId;
this.productId = productId;
}
public String getOrderId() {
return orderId;
}
public String getProductId() {
return productId;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ProductCountDecrementedEvent that = (ProductCountDecrementedEvent) o;
return Objects.equals(orderId, that.orderId) && Objects.equals(productId, that.productId);
}
@Override
public int hashCode() {
return Objects.hash(orderId, productId);
}
@Override
public String toString() {
return "ProductCountDecrementedEvent{" +
"orderId='" + orderId + '\'' +
", productId='" + productId + '\'' +
'}';
}
}

View File

@ -0,0 +1,47 @@
package com.baeldung.axon.coreapi.events;
import java.util.Objects;
public class ProductCountIncrementedEvent {
private final String orderId;
private final String productId;
public ProductCountIncrementedEvent(String orderId, String productId) {
this.orderId = orderId;
this.productId = productId;
}
public String getOrderId() {
return orderId;
}
public String getProductId() {
return productId;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ProductCountIncrementedEvent that = (ProductCountIncrementedEvent) o;
return Objects.equals(orderId, that.orderId) && Objects.equals(productId, that.productId);
}
@Override
public int hashCode() {
return Objects.hash(orderId, productId);
}
@Override
public String toString() {
return "ProductCountIncrementedEvent{" +
"orderId='" + orderId + '\'' +
", productId='" + productId + '\'' +
'}';
}
}

View File

@ -0,0 +1,47 @@
package com.baeldung.axon.coreapi.events;
import java.util.Objects;
public class ProductRemovedEvent {
private final String orderId;
private final String productId;
public ProductRemovedEvent(String orderId, String productId) {
this.orderId = orderId;
this.productId = productId;
}
public String getOrderId() {
return orderId;
}
public String getProductId() {
return productId;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ProductRemovedEvent that = (ProductRemovedEvent) o;
return Objects.equals(orderId, that.orderId) && Objects.equals(productId, that.productId);
}
@Override
public int hashCode() {
return Objects.hash(orderId, productId);
}
@Override
public String toString() {
return "ProductRemovedEvent{" +
"orderId='" + orderId + '\'' +
", productId='" + productId + '\'' +
'}';
}
}