Skip to content

Commit 37106a3

Browse files
committed
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
1 parent 7f87901 commit 37106a3

5 files changed

Lines changed: 199 additions & 19 deletions

File tree

axon/src/main/java/com/baeldung/axon/coreapi/events/OrderPlacedEvent.java

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,36 @@
55
public class OrderPlacedEvent {
66

77
private final String orderId;
8-
private final String product;
98

10-
public OrderPlacedEvent(String orderId, String product) {
9+
public OrderPlacedEvent(String orderId) {
1110
this.orderId = orderId;
12-
this.product = product;
1311
}
1412

1513
public String getOrderId() {
1614
return orderId;
1715
}
1816

19-
public String getProduct() {
20-
return product;
21-
}
22-
23-
@Override
24-
public int hashCode() {
25-
return Objects.hash(orderId, product);
26-
}
27-
2817
@Override
29-
public boolean equals(Object obj) {
30-
if (this == obj) {
18+
public boolean equals(Object o) {
19+
if (this == o) {
3120
return true;
3221
}
33-
if (obj == null || getClass() != obj.getClass()) {
22+
if (o == null || getClass() != o.getClass()) {
3423
return false;
3524
}
36-
final OrderPlacedEvent other = (OrderPlacedEvent) obj;
37-
return Objects.equals(this.orderId, other.orderId)
38-
&& Objects.equals(this.product, other.product);
25+
OrderPlacedEvent that = (OrderPlacedEvent) o;
26+
return Objects.equals(orderId, that.orderId);
27+
}
28+
29+
@Override
30+
public int hashCode() {
31+
return Objects.hash(orderId);
3932
}
4033

4134
@Override
4235
public String toString() {
4336
return "OrderPlacedEvent{" +
4437
"orderId='" + orderId + '\'' +
45-
", product='" + product + '\'' +
4638
'}';
4739
}
4840
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.baeldung.axon.coreapi.events;
2+
3+
import java.util.Objects;
4+
5+
public class ProductAddedEvent {
6+
7+
private final String orderId;
8+
private final String productId;
9+
10+
public ProductAddedEvent(String orderId, String productId) {
11+
this.orderId = orderId;
12+
this.productId = productId;
13+
}
14+
15+
public String getOrderId() {
16+
return orderId;
17+
}
18+
19+
public String getProductId() {
20+
return productId;
21+
}
22+
23+
@Override
24+
public boolean equals(Object o) {
25+
if (this == o) {
26+
return true;
27+
}
28+
if (o == null || getClass() != o.getClass()) {
29+
return false;
30+
}
31+
ProductAddedEvent that = (ProductAddedEvent) o;
32+
return Objects.equals(orderId, that.orderId) && Objects.equals(productId, that.productId);
33+
}
34+
35+
@Override
36+
public int hashCode() {
37+
return Objects.hash(orderId, productId);
38+
}
39+
40+
@Override
41+
public String toString() {
42+
return "ProductAddedEvent{" +
43+
"orderId='" + orderId + '\'' +
44+
", productId='" + productId + '\'' +
45+
'}';
46+
}
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.baeldung.axon.coreapi.events;
2+
3+
import java.util.Objects;
4+
5+
public class ProductCountDecrementedEvent {
6+
7+
private final String orderId;
8+
private final String productId;
9+
10+
public ProductCountDecrementedEvent(String orderId, String productId) {
11+
this.orderId = orderId;
12+
this.productId = productId;
13+
}
14+
15+
public String getOrderId() {
16+
return orderId;
17+
}
18+
19+
public String getProductId() {
20+
return productId;
21+
}
22+
23+
@Override
24+
public boolean equals(Object o) {
25+
if (this == o) {
26+
return true;
27+
}
28+
if (o == null || getClass() != o.getClass()) {
29+
return false;
30+
}
31+
ProductCountDecrementedEvent that = (ProductCountDecrementedEvent) o;
32+
return Objects.equals(orderId, that.orderId) && Objects.equals(productId, that.productId);
33+
}
34+
35+
@Override
36+
public int hashCode() {
37+
return Objects.hash(orderId, productId);
38+
}
39+
40+
@Override
41+
public String toString() {
42+
return "ProductCountDecrementedEvent{" +
43+
"orderId='" + orderId + '\'' +
44+
", productId='" + productId + '\'' +
45+
'}';
46+
}
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.baeldung.axon.coreapi.events;
2+
3+
import java.util.Objects;
4+
5+
public class ProductCountIncrementedEvent {
6+
7+
private final String orderId;
8+
private final String productId;
9+
10+
public ProductCountIncrementedEvent(String orderId, String productId) {
11+
this.orderId = orderId;
12+
this.productId = productId;
13+
}
14+
15+
public String getOrderId() {
16+
return orderId;
17+
}
18+
19+
public String getProductId() {
20+
return productId;
21+
}
22+
23+
@Override
24+
public boolean equals(Object o) {
25+
if (this == o) {
26+
return true;
27+
}
28+
if (o == null || getClass() != o.getClass()) {
29+
return false;
30+
}
31+
ProductCountIncrementedEvent that = (ProductCountIncrementedEvent) o;
32+
return Objects.equals(orderId, that.orderId) && Objects.equals(productId, that.productId);
33+
}
34+
35+
@Override
36+
public int hashCode() {
37+
return Objects.hash(orderId, productId);
38+
}
39+
40+
@Override
41+
public String toString() {
42+
return "ProductCountIncrementedEvent{" +
43+
"orderId='" + orderId + '\'' +
44+
", productId='" + productId + '\'' +
45+
'}';
46+
}
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.baeldung.axon.coreapi.events;
2+
3+
import java.util.Objects;
4+
5+
public class ProductRemovedEvent {
6+
7+
private final String orderId;
8+
private final String productId;
9+
10+
public ProductRemovedEvent(String orderId, String productId) {
11+
this.orderId = orderId;
12+
this.productId = productId;
13+
}
14+
15+
public String getOrderId() {
16+
return orderId;
17+
}
18+
19+
public String getProductId() {
20+
return productId;
21+
}
22+
23+
@Override
24+
public boolean equals(Object o) {
25+
if (this == o) {
26+
return true;
27+
}
28+
if (o == null || getClass() != o.getClass()) {
29+
return false;
30+
}
31+
ProductRemovedEvent that = (ProductRemovedEvent) o;
32+
return Objects.equals(orderId, that.orderId) && Objects.equals(productId, that.productId);
33+
}
34+
35+
@Override
36+
public int hashCode() {
37+
return Objects.hash(orderId, productId);
38+
}
39+
40+
@Override
41+
public String toString() {
42+
return "ProductRemovedEvent{" +
43+
"orderId='" + orderId + '\'' +
44+
", productId='" + productId + '\'' +
45+
'}';
46+
}
47+
}

0 commit comments

Comments
 (0)