Skip to content

Commit

Permalink
A lot more changes, working on final code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
czfdcn committed May 30, 2024
1 parent 961e0d3 commit f467cd0
Show file tree
Hide file tree
Showing 45 changed files with 1,971 additions and 1,248 deletions.
6 changes: 2 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<slf4j.version>2.6.18</slf4j.version>
<cloudevents.version>2.4.2</cloudevents.version>
<protobuf.version>3.21.10</protobuf.version>
<git.tag.name>uoptions_cleanup</git.tag.name>
<git.tag.name>main</git.tag.name>
</properties>

<licenses>
Expand Down Expand Up @@ -150,9 +150,7 @@
</executions>
<configuration>
<protocArtifact>com.google.protobuf:protoc:3.17.3:exe:${os.detected.classifier}</protocArtifact>
<protoSourceRoot>${project.build.directory}/up-spec/up-core-api/uprotocol</protoSourceRoot>
<outputDirectory>${project.build.directory}/generated-sources/protobuf/java</outputDirectory>

<protoSourceRoot>${project.build.directory}/up-spec/up-core-api</protoSourceRoot>
</configuration>
</plugin>
<plugin>
Expand Down
161 changes: 0 additions & 161 deletions src/main/java/org/eclipse/uprotocol/client/CallOptions.java

This file was deleted.

27 changes: 0 additions & 27 deletions src/main/java/org/eclipse/uprotocol/client/TransportWrapper.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,21 @@
*/
package org.eclipse.uprotocol.cloudevent.factory;

import org.eclipse.uprotocol.cloudevent.datamodel.UCloudEventAttributes;
import java.net.URI;
import java.util.Optional;


import com.google.protobuf.Any;
import com.google.protobuf.Empty;
import io.cloudevents.CloudEvent;
import io.cloudevents.core.builder.CloudEventBuilder;

import org.eclipse.uprotocol.cloudevent.datamodel.UCloudEventAttributes;
import org.eclipse.uprotocol.uuid.factory.UuidFactory;
import org.eclipse.uprotocol.uuid.serializer.UuidSerializer;
import org.eclipse.uprotocol.v1.UMessageType;
import org.eclipse.uprotocol.v1.UUID;
import org.eclipse.uprotocol.v1.UUri;

import java.net.URI;


/**
Expand All @@ -48,10 +50,10 @@ public interface CloudEventFactory {
*/
static CloudEvent request(String applicationUriForRPC,
String serviceMethodUri,
Any protoPayload,
Optional<Any> protoPayload,
UCloudEventAttributes attributes) {
String id = generateCloudEventId();
return buildBaseCloudEvent(id, applicationUriForRPC, protoPayload.toByteArray(), protoPayload.getTypeUrl(), attributes )
return buildBaseCloudEvent(id, applicationUriForRPC, protoPayload, attributes )
.withType(UCloudEvent.getEventType(UMessageType.UMESSAGE_TYPE_REQUEST))
.withExtension("sink", URI.create(serviceMethodUri))
.build();
Expand All @@ -71,10 +73,10 @@ static CloudEvent request(String applicationUriForRPC,
static CloudEvent response(String applicationUriForRPC,
String serviceMethodUri,
String requestId,
Any protoPayload,
Optional<Any> protoPayload,
UCloudEventAttributes attributes) {
String id = generateCloudEventId();
return buildBaseCloudEvent(id, serviceMethodUri, protoPayload.toByteArray(), protoPayload.getTypeUrl(), attributes)
return buildBaseCloudEvent(id, serviceMethodUri, protoPayload, attributes)
.withType(UCloudEvent.getEventType(UMessageType.UMESSAGE_TYPE_RESPONSE))
.withExtension("sink", URI.create(applicationUriForRPC))
.withExtension("reqid", requestId)
Expand All @@ -97,8 +99,8 @@ static CloudEvent failedResponse(String applicationUriForRPC,
Integer communicationStatus,
UCloudEventAttributes attributes) {
String id = generateCloudEventId();
final Any protoPayload = Any.pack(Empty.getDefaultInstance());
return buildBaseCloudEvent(id, serviceMethodUri, protoPayload.toByteArray(), protoPayload.getTypeUrl(), attributes)

return buildBaseCloudEvent(id, serviceMethodUri, Optional.empty(), attributes)
.withType(UCloudEvent.getEventType(UMessageType.UMESSAGE_TYPE_RESPONSE))
.withExtension("sink", URI.create(applicationUriForRPC))
.withExtension("reqid", requestId)
Expand All @@ -114,9 +116,9 @@ static CloudEvent failedResponse(String applicationUriForRPC,
* @param attributes Additional attributes such as ttl, hash and priority.
* @return Returns a publish CloudEvent.
*/
static CloudEvent publish(String source, Any protoPayload, UCloudEventAttributes attributes) {
static CloudEvent publish(String source, Optional<Any> protoPayload, UCloudEventAttributes attributes) {
String id = generateCloudEventId();
return buildBaseCloudEvent(id, source, protoPayload.toByteArray(), protoPayload.getTypeUrl(), attributes )
return buildBaseCloudEvent(id, source, protoPayload, attributes)
.withType(UCloudEvent.getEventType(UMessageType.UMESSAGE_TYPE_PUBLISH))
.build();
}
Expand All @@ -131,10 +133,10 @@ static CloudEvent publish(String source, Any protoPayload, UCloudEventAttributes
* @param attributes Additional attributes such as ttl, hash and priority.
* @return Returns a publish CloudEvent.
*/
static CloudEvent notification(String source, String sink, Any protoPayload, UCloudEventAttributes attributes) {
static CloudEvent notification(String source, String sink, Optional<Any> protoPayload, UCloudEventAttributes attributes) {
String id = generateCloudEventId();
return buildBaseCloudEvent(id, source, protoPayload.toByteArray(), protoPayload.getTypeUrl(), attributes )
.withType(UCloudEvent.getEventType(UMessageType.UMESSAGE_TYPE_PUBLISH))
return buildBaseCloudEvent(id, source, protoPayload, attributes )
.withType(UCloudEvent.getEventType(UMessageType.UMESSAGE_TYPE_NOTIFICATION))
.withExtension("sink", URI.create(sink))
.build();
}
Expand All @@ -153,26 +155,20 @@ static String generateCloudEventId() {
* @param id Event unique identifier.
* @param source Identifies who is sending this event in the format of a uProtocol URI that
* can be built from a {@link UUri} object.
* @param protoPayloadBytes The serialized Event data with the content type of "application/x-protobuf".
* @param protoPayloadSchema The schema of the proto payload bytes, for example you can use <code>protoPayload.getTypeUrl()</code> on your service/app object.
* @param attributes Additional cloud event attributes that can be passed in. All attributes are optional and will be added only if they
* @param protPayload Optional payload for the message
* @param attributes Additional cloud event attributes that can be passed in. All attributes are optional and will be added only if they
* were configured.
* @return Returns a CloudEventBuilder that can be additionally configured and then by calling .build() construct a CloudEvent
* ready to be serialized and sent to the transport layer.
*/
@SuppressWarnings("null")
static CloudEventBuilder buildBaseCloudEvent(String id, String source,
byte[] protoPayloadBytes,
String protoPayloadSchema,
Optional<Any> protoPayload,
UCloudEventAttributes attributes) {
final CloudEventBuilder cloudEventBuilder = CloudEventBuilder.v1()
CloudEventBuilder cloudEventBuilder = CloudEventBuilder.v1()
.withId(id)
.withSource(URI.create(source))
/* Not needed:
.withDataContentType(PROTOBUF_CONTENT_TYPE)
.withDataSchema(URI.create(protoPayloadSchema))
*/
.withData(protoPayloadBytes);
.withSource(URI.create(source));

protoPayload.ifPresent(payload -> cloudEventBuilder.withData(payload.toByteArray()));

attributes.ttl().ifPresent(ttl -> cloudEventBuilder.withExtension("ttl", ttl));
attributes.priority().ifPresent(priority -> cloudEventBuilder.withExtension("priority",
Expand Down
Loading

0 comments on commit f467cd0

Please sign in to comment.