Skip to content

Commit 8d7c785

Browse files
authored
Merge pull request #108 from slinkydeveloper/refactor-event-class
Rework the Event interface
2 parents 242b58a + d207ecc commit 8d7c785

File tree

191 files changed

+3065
-11958
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

191 files changed

+3065
-11958
lines changed

api/README.md

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@ Here we will see how to use the pre-configure marshallers and unmarshallers.
1111
The high-level API to marshal CloudEvents as binary content mode.
1212

1313
```java
14-
import java.net.URI;
15-
import java.time.ZonedDateTime;
1614

17-
import io.cloudevents.extensions.DistributedTracingExtension;
15+
1816
import io.cloudevents.extensions.ExtensionFormat;
1917
import io.cloudevents.format.Wire;
20-
import io.cloudevents.v1.CloudEventBuilder;
2118
import io.cloudevents.v1.CloudEventImpl;
2219
import io.cloudevents.v1.http.Marshallers;
2320

@@ -39,7 +36,7 @@ CloudEventImpl<String> ce =
3936
CloudEventBuilder.<String>builder()
4037
.withType("com.github.pull.create")
4138
.withSource(URI.create("https://github.com/cloudevents/spec/pull"))
42-
.withId("A234-1234-1234")
39+
.withId("A234-1234-1234")
4340
.withDataschema(URI.create("http://my.br"))
4441
.withTime(ZonedDateTime.now())
4542
.withDataContentType("text/plain")
@@ -69,13 +66,8 @@ wire.getPayload(); //Optional<String> which has the JSON
6966
The high-level API to unmarshal CloudEvents from binary content mode.
7067

7168
```java
72-
import java.util.HashMap;
73-
import java.util.Map;
7469

75-
import io.cloudevents.CloudEvent;
76-
import io.cloudevents.extensions.DistributedTracingExtension;
77-
import io.cloudevents.v1.AttributesImpl;
78-
import io.cloudevents.v1.CloudEventBuilder;
70+
7971
import io.cloudevents.v1.http.Unmarshallers;
8072

8173
// . . .
@@ -114,12 +106,9 @@ event.getExtensions();
114106
The high-level API to marshal CloudEvents as structured content mode.
115107

116108
```java
117-
import java.net.URI;
118-
import java.time.ZonedDateTime;
119109

120-
import io.cloudevents.extensions.DistributedTracingExtension;
110+
121111
import io.cloudevents.extensions.ExtensionFormat;
122-
import io.cloudevents.v1.CloudEventBuilder;
123112
import io.cloudevents.v1.CloudEventImpl;
124113
import io.cloudevents.v1.http.Marshallers;
125114

@@ -382,14 +371,9 @@ Wire<String, String, String> wire =
382371
/*
383372
* The imports used by the example bellow
384373
*/
385-
import io.cloudevents.CloudEvent;
386-
import io.cloudevents.extensions.DistributedTracingExtension;
387374
import io.cloudevents.format.BinaryUnmarshaller;
388375
import io.cloudevents.format.builder.HeadersStep;
389-
import io.cloudevents.json.Json;
390376
import io.cloudevents.json.types.Much;
391-
import io.cloudevents.v1.AttributesImpl;
392-
import io.cloudevents.v1.CloudEventBuilder;
393377

394378
// . . .
395379

@@ -520,7 +504,7 @@ HeadersStep<AttributesImpl, Much, String> step =
520504
* - now we get the HeadersStep<AttributesImpl, Much, String>, a common step that event unmarshaller must returns
521505
* - from here we just call withHeaders(), withPayload() and unmarshal()
522506
*/
523-
.map((payload, extensions) -> {
507+
.map((payload, extensions) -> {
524508
CloudEventImpl<Much> event =
525509
Json.<CloudEventImpl<Much>>
526510
decodeValue(payload, CloudEventImpl.class, Much.class);

api/pom.xml

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -23,47 +23,30 @@
2323
<version>1.3.0</version>
2424
</parent>
2525

26-
<groupId>io.cloudevents</groupId>
2726
<artifactId>cloudevents-api</artifactId>
2827
<name>CloudEvents - API</name>
29-
<version>1.3.0</version>
28+
<version>${parent.version}</version>
3029
<packaging>jar</packaging>
3130

32-
<dependencies>
33-
<dependency>
34-
<groupId>com.fasterxml.jackson.core</groupId>
35-
<artifactId>jackson-core</artifactId>
36-
<version>${jackson.version}</version>
37-
</dependency>
38-
39-
<dependency>
40-
<groupId>com.fasterxml.jackson.core</groupId>
41-
<artifactId>jackson-databind</artifactId>
42-
<version>${jackson.version}</version>
43-
</dependency>
31+
<dependencyManagement>
32+
<dependencies>
33+
<dependency>
34+
<groupId>com.fasterxml.jackson</groupId>
35+
<artifactId>jackson-bom</artifactId>
36+
<version>${jackson.version}</version>
37+
<scope>import</scope>
38+
<type>pom</type>
39+
</dependency>
40+
</dependencies>
41+
</dependencyManagement>
4442

45-
<dependency>
46-
<groupId>com.fasterxml.jackson.datatype</groupId>
47-
<artifactId>jackson-datatype-jdk8</artifactId>
48-
<version>${jackson.version}</version>
49-
</dependency>
50-
51-
<dependency>
52-
<groupId>org.hibernate.validator</groupId>
53-
<artifactId>hibernate-validator</artifactId>
54-
<version>${hibernate-validator.version}</version>
55-
</dependency>
56-
57-
<dependency>
58-
<groupId>org.glassfish</groupId>
59-
<artifactId>jakarta.el</artifactId>
60-
<version>${jakarta.el.version}</version>
61-
</dependency>
43+
<dependencies>
6244

45+
<!-- Test deps -->
6346
<dependency>
64-
<groupId>junit</groupId>
65-
<artifactId>junit</artifactId>
66-
<version>4.12</version>
47+
<groupId>org.junit.jupiter</groupId>
48+
<artifactId>junit-jupiter</artifactId>
49+
<version>5.4.2</version>
6750
<scope>test</scope>
6851
</dependency>
6952

@@ -76,10 +59,26 @@
7659

7760
</dependencies>
7861

79-
<properties>
80-
<jackson.version>2.10.1</jackson.version>
81-
<hibernate-validator.version>6.0.17.Final</hibernate-validator.version>
82-
<jakarta.el.version>3.0.3</jakarta.el.version>
83-
</properties>
62+
<build>
63+
<plugins>
64+
<plugin>
65+
<groupId>org.apache.maven.plugins</groupId>
66+
<artifactId>maven-surefire-plugin</artifactId>
67+
<version>3.0.0-M4</version>
68+
</plugin>
69+
<plugin>
70+
<groupId>org.apache.maven.plugins</groupId>
71+
<artifactId>maven-jar-plugin</artifactId>
72+
<version>3.2.0</version>
73+
<executions>
74+
<execution>
75+
<goals>
76+
<goal>test-jar</goal>
77+
</goals>
78+
</execution>
79+
</executions>
80+
</plugin>
81+
</plugins>
82+
</build>
8483

8584
</project>

api/src/main/java/io/cloudevents/Attributes.java

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,50 +16,52 @@
1616
package io.cloudevents;
1717

1818
import java.net.URI;
19+
import java.time.ZonedDateTime;
1920
import java.util.Optional;
2021

21-
import javax.validation.constraints.NotBlank;
22-
import javax.validation.constraints.NotNull;
23-
24-
import com.fasterxml.jackson.annotation.JsonIgnore;
25-
2622
/**
2723
* The marker interface for CloudEvents attributes
28-
*
24+
*
2925
* @author fabiojose
3026
*
3127
*/
3228
public interface Attributes {
3329

30+
/**
31+
* @return The version of the CloudEvents specification which the event uses
32+
*/
33+
SpecVersion getSpecVersion();
34+
3435
/**
3536
* @return Identifies the event. Producers MUST ensure that source + id is unique for each distinct event
3637
*/
37-
@NotBlank
3838
String getId();
3939

4040
/**
4141
* @return A value describing the type of event related to the originating occurrence.
4242
*/
43-
@NotBlank
4443
String getType();
4544

4645
/**
4746
* @return The context in which an event happened.
4847
*/
49-
@NotNull
5048
URI getSource();
5149

5250
/**
53-
* @return The version of the CloudEvents specification which the event uses
54-
*/
55-
@NotBlank
56-
String getSpecversion();
57-
58-
/**
51+
* TODO
5952
* A common way to get the media type of CloudEvents 'data';
6053
* @return If has a value, it MUST follows the <a href="https://tools.ietf.org/html/rfc2046">RFC2046</a>
6154
*/
62-
@JsonIgnore
63-
Optional<String> getMediaType();
64-
55+
Optional<String> getDataContentType();
56+
57+
Optional<URI> getDataSchema();
58+
59+
Optional<String> getSubject();
60+
61+
Optional<ZonedDateTime> getTime();
62+
63+
Attributes toV03();
64+
65+
Attributes toV1();
66+
6567
}

api/src/main/java/io/cloudevents/Builder.java

Lines changed: 0 additions & 39 deletions
This file was deleted.

api/src/main/java/io/cloudevents/CloudEvent.java

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,58 @@
1515
*/
1616
package io.cloudevents;
1717

18+
import io.cloudevents.format.EventFormat;
19+
import io.cloudevents.message.BinaryMessage;
20+
import io.cloudevents.message.StructuredMessage;
21+
1822
import java.util.Map;
1923
import java.util.Optional;
2024

2125
/**
2226
* An abstract event envelope
23-
* @param <A> The attributes type
24-
* @param <T> The 'data' type
2527
* @author fabiojose
28+
* @author slinkydeveloper
2629
*/
27-
public interface CloudEvent<A extends Attributes, T> {
30+
public interface CloudEvent {
2831

2932
/**
3033
* The event context attributes
3134
*/
32-
A getAttributes();
35+
Attributes getAttributes();
3336

3437
/**
3538
* The event data
3639
*/
37-
Optional<T> getData();
38-
39-
byte[] getDataBase64();
40+
Optional<byte[]> getData();
4041

4142
/**
4243
* The event extensions
44+
*
45+
* Extensions values could be String/Number/Boolean
4346
*/
4447
Map<String, Object> getExtensions();
48+
49+
CloudEvent toV03();
50+
51+
CloudEvent toV1();
52+
53+
BinaryMessage asBinaryMessage();
54+
55+
StructuredMessage asStructuredMessage(EventFormat format);
56+
57+
static io.cloudevents.v1.CloudEventBuilder buildV1() {
58+
return new io.cloudevents.v1.CloudEventBuilder();
59+
}
60+
61+
static io.cloudevents.v1.CloudEventBuilder buildV1(CloudEvent event) {
62+
return new io.cloudevents.v1.CloudEventBuilder(event);
63+
}
64+
65+
static io.cloudevents.v03.CloudEventBuilder buildV03() {
66+
return new io.cloudevents.v03.CloudEventBuilder();
67+
}
68+
69+
static io.cloudevents.v03.CloudEventBuilder buildV03(CloudEvent event) {
70+
return new io.cloudevents.v03.CloudEventBuilder(event);
71+
}
4572
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package io.cloudevents;
2+
3+
import java.util.Map;
4+
5+
public interface Extension {
6+
7+
void readFromEvent(CloudEvent event);
8+
9+
Map<String, Object> asMap();
10+
11+
}

0 commit comments

Comments
 (0)