Skip to content

Commit 7b7ee3d

Browse files
authored
Add eventId field to B2EventNotificationEvent (#81) (#197)
1 parent 412f227 commit 7b7ee3d

File tree

4 files changed

+49
-10
lines changed

4 files changed

+49
-10
lines changed

CHANGELOG.md

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# Changelog
22
## [Unreleased] - TBD
3+
### Added
4+
* Added `eventId` field to `B2EventNotificationEvent`.
35

4-
### [6.2.0] - 2024-04-15
6+
## [6.2.0] - 2024-04-15
7+
### Added
58
* Added support to specify B2Json union types using annotations. Annotation support for union types is required because
69
Java records do not support inheritance. Example usage:
710
```java
@@ -28,20 +31,22 @@
2831
@B2Json.type
2932
record Point(@B2Json.required int x, @B2Json.required int y) { }
3033
```
31-
* Optimized B2DateTimeUtil.formatFguidDateTime
32-
* Reduced memory allocation for small input when deserializing byte[] to JSON
33-
* Reduced lock contention in B2Clock
3434
* Added support for B2 Event Notifications
3535
* Added B2Json `fromJson` methods that take a `java.io.Reader` as input for JSON
36-
* Updated B2Json `fromJson` methods to utilize a BufferedReader when deserializing JSON for performance improvement
3736
* Added B2StorageClient.storePartsForLargeFile
3837
* Added support for daysFromStartingToCancelingUnfinishedLargeFiles to B2LifecycleRule
39-
* Reduced lock contention in B2AccountAuthorizationCache
4038
* Added the `serializedName` annotation to rename the serialized Json member name
4139
* Added support for AtomicLongArray in B2Json
40+
* Added support for custom upload timestamps
41+
42+
### Changed
43+
* Optimized `B2DateTimeUtil.formatFguidDateTime`
44+
* Reduced memory allocation for small input when deserializing byte[] to JSON
45+
* Reduced lock contention in B2Clock
46+
* Updated B2Json `fromJson` methods to utilize a BufferedReader when deserializing JSON for performance improvement
47+
* Reduced lock contention in B2AccountAuthorizationCache
4248
* Reduced lock contention in B2Json
4349
* Updated internal python for building to python3
44-
* Added support for custom upload timestamps
4550

4651
### Fixed
4752
* Fixed union types to ignore extra and discarded fields when deserializing JSON to Java objects

core/src/main/java/com/backblaze/b2/client/structures/B2EventNotificationEvent.java

+14
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public class B2EventNotificationEvent {
2626
@B2Json.required
2727
private final String eventType;
2828
@B2Json.required
29+
String eventId;
30+
@B2Json.required
2931
private final int eventVersion;
3032
@B2Json.required
3133
private final String matchedRuleName;
@@ -42,6 +44,7 @@ public B2EventNotificationEvent(String accountId,
4244
String bucketName,
4345
long eventTimestamp,
4446
String eventType,
47+
String eventId,
4548
int eventVersion,
4649
String matchedRuleName,
4750
String objectName,
@@ -61,6 +64,7 @@ public B2EventNotificationEvent(String accountId,
6164
this.bucketName = bucketName;
6265
this.eventTimestamp = eventTimestamp;
6366
this.eventType = eventType;
67+
this.eventId = eventId;
6468
this.eventVersion = eventVersion;
6569
this.matchedRuleName = matchedRuleName;
6670
this.objectName = objectName;
@@ -79,6 +83,7 @@ public boolean equals(Object o) {
7983
Objects.equals(bucketId, that.bucketId) &&
8084
Objects.equals(bucketName, that.bucketName) &&
8185
Objects.equals(eventType, that.eventType) &&
86+
Objects.equals(eventId, that.eventId) &&
8287
Objects.equals(matchedRuleName, that.matchedRuleName) &&
8388
Objects.equals(objectName, that.objectName) &&
8489
Objects.equals(objectSize, that.objectSize) &&
@@ -93,6 +98,7 @@ public int hashCode() {
9398
bucketName,
9499
eventTimestamp,
95100
eventType,
101+
eventId,
96102
eventVersion,
97103
matchedRuleName,
98104
objectName,
@@ -149,6 +155,13 @@ public String getEventType() {
149155
return eventType;
150156
}
151157

158+
/**
159+
* The unique ID of the event.
160+
*/
161+
public String getEventId() {
162+
return eventId;
163+
}
164+
152165
/**
153166
* The name of the object that corresponds to the event. This will be null for test events.
154167
*/
@@ -178,6 +191,7 @@ public String toString() {
178191
"accountId='" + accountId + '\'' +
179192
", bucketId='" + bucketId + '\'' +
180193
", bucketName='" + bucketName + '\'' +
194+
", eventId=" + eventId + '\'' +
181195
", eventTimestamp=" + eventTimestamp +
182196
", eventType='" + eventType + '\'' +
183197
", eventVersion=" + eventVersion +

core/src/test/java/com/backblaze/b2/client/structures/B2EventNotificationEventTest.java

+19-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public void testToJsonAndBack() {
1515
" \"accountId\": \"e85c6a500333\",\n" +
1616
" \"bucketId\": \"aea8c5bc362ae55070130333\",\n" +
1717
" \"bucketName\": \"mySampleBucket\",\n" +
18+
" \"eventId\": \"eventId\",\n" +
1819
" \"eventTimestamp\": 1684793309123,\n" +
1920
" \"eventType\": \"b2:ObjectCreated:Upload\",\n" +
2021
" \"eventVersion\": 1,\n" +
@@ -29,11 +30,19 @@ public void testToJsonAndBack() {
2930
B2EventNotificationEvent.class
3031
);
3132

32-
final B2EventNotificationEvent expectedEvent = new B2EventNotificationEvent("e85c6a500333", "aea8c5bc362ae55070130333", "mySampleBucket", 1684793309123L, "b2:ObjectCreated:Upload", 1,
33+
final B2EventNotificationEvent expectedEvent = new B2EventNotificationEvent(
34+
"e85c6a500333",
35+
"aea8c5bc362ae55070130333",
36+
"mySampleBucket",
37+
1684793309123L,
38+
"b2:ObjectCreated:Upload",
39+
"eventId",
40+
1,
3341
"mySampleRule1",
3442
"objectName.txt",
3543
10495842L,
36-
"4_zaea8c5bc362ae55070130333_f117c7bd5d6c6597c_d20230521_m235957_c001_v0001044_t0052_u01684713597235");
44+
"4_zaea8c5bc362ae55070130333_f117c7bd5d6c6597c_d20230521_m235957_c001_v0001044_t0052_u01684713597235"
45+
);
3746
final String convertedJson = B2Json.toJsonOrThrowRuntime(expectedEvent);
3847
assertEquals(expectedEvent, event);
3948
assertEquals(jsonString, convertedJson);
@@ -45,6 +54,7 @@ public void testToJsonAndBack_testEvent() {
4554
" \"accountId\": \"e85c6a500333\",\n" +
4655
" \"bucketId\": \"aea8c5bc362ae55070130333\",\n" +
4756
" \"bucketName\": \"mySampleBucket\",\n" +
57+
" \"eventId\": \"eventId\",\n" +
4858
" \"eventTimestamp\": 1684793309123,\n" +
4959
" \"eventType\": \"b2:TestEvent\",\n" +
5060
" \"eventVersion\": 1,\n" +
@@ -62,6 +72,7 @@ public void testToJsonAndBack_testEvent() {
6272
"mySampleBucket",
6373
1684793309123L,
6474
"b2:TestEvent",
75+
"eventId",
6576
1,
6677
"mySampleRule1",
6778
null,
@@ -83,6 +94,7 @@ public void testTestEventsMustNotHaveObjectName() {
8394
"mySampleBucket",
8495
1684793309123L,
8596
"b2:TestEvent",
97+
"eventId",
8698
1,
8799
"mySampleRule1",
88100
"objectName.txt",
@@ -103,6 +115,7 @@ public void testTestEventsMustNotHaveObjectSize() {
103115
"mySampleBucket",
104116
1684793309123L,
105117
"b2:TestEvent",
118+
"eventId",
106119
1,
107120
"mySampleRule1",
108121
null,
@@ -123,6 +136,7 @@ public void testTestEventsMustNotHaveObjectVersionId() {
123136
"mySampleBucket",
124137
1684793309123L,
125138
"b2:TestEvent",
139+
"eventId",
126140
1,
127141
"mySampleRule1",
128142
null,
@@ -143,6 +157,7 @@ public void testNonTestEventsMustHaveObjectName() {
143157
"mySampleBucket",
144158
1684793309123L,
145159
"b2:ObjectCreated:Upload",
160+
"eventId",
146161
1,
147162
"mySampleRule1",
148163
null,
@@ -163,6 +178,7 @@ public void testNonTestEventsMustHaveObjectVersionId() {
163178
"mySampleBucket",
164179
1684793309123L,
165180
"b2:ObjectCreated:Upload",
181+
"eventId",
166182
1,
167183
"mySampleRule1",
168184
"objectName.txt",
@@ -172,4 +188,4 @@ public void testNonTestEventsMustHaveObjectVersionId() {
172188
);
173189
assertEquals(illegalArgumentException.getMessage(), "objectVersionId is required");
174190
}
175-
}
191+
}

core/src/test/java/com/backblaze/b2/client/structures/B2EventNotificationTest.java

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class B2EventNotificationTest extends B2BaseTest {
2626
" \"accountId\": \"e85c6a500333\",\n" +
2727
" \"bucketId\": \"aea8c5bc362ae55070130333\",\n" +
2828
" \"bucketName\": \"mySampleBucket\",\n" +
29+
" \"eventId\": \"eventId\",\n" +
2930
" \"eventTimestamp\": 1684793309123,\n" +
3031
" \"eventType\": \"b2:ObjectCreated:Upload\",\n" +
3132
" \"eventVersion\": 1,\n" +
@@ -54,6 +55,7 @@ public void testToJsonAndBack() {
5455
"mySampleBucket",
5556
1684793309123L,
5657
"b2:ObjectCreated:Upload",
58+
"eventId",
5759
1,
5860
"mySampleRule1",
5961
"objectName.txt",
@@ -76,6 +78,7 @@ public void testToJsonAndBackWithNullSize() {
7678
" \"accountId\": \"e85c6a500333\",\n" +
7779
" \"bucketId\": \"aea8c5bc362ae55070130333\",\n" +
7880
" \"bucketName\": \"mySampleBucket\",\n" +
81+
" \"eventId\": \"eventId\",\n" +
7982
" \"eventTimestamp\": 1684793309123,\n" +
8083
" \"eventType\": \"b2:ObjectCreated:Upload\",\n" +
8184
" \"eventVersion\": 1,\n" +
@@ -98,6 +101,7 @@ public void testToJsonAndBackWithNullSize() {
98101
"mySampleBucket",
99102
1684793309123L,
100103
"b2:ObjectCreated:Upload",
104+
"eventId",
101105
1,
102106
"mySampleRule1",
103107
"objectName.txt",

0 commit comments

Comments
 (0)