From a89ce23aa6f20c4b053e548e6b49ac67223c6ae2 Mon Sep 17 00:00:00 2001 From: Clemens Vasters Date: Fri, 5 Apr 2024 14:53:51 +0200 Subject: [PATCH] simple java producer factory and consumer dispatch Signed-off-by: Clemens Vasters --- .../templates/java/_common/mqtt.jinja.include | 2 +- xregistry/templates/java/_templateinfo.json | 2 +- .../java/consumer/_templateinfo.json | 2 +- .../main/{classdir}EventDispatcher.java.jinja | 79 ++++++++ .../templates/java/consumer/pom.xml.jinja | 21 +- .../java/producer/_templateinfo.json | 2 +- .../main/{classdir}EventFactory.java.jinja | 72 +++++++ .../templates/java/producer/pom.xml.jinja | 21 +- .../java/xconsumer/_templateinfo.json | 4 + .../{classdir}DispatchInterfaces.java.jinja | 11 ++ .../main/{classdir}EventConsumer.java.jinja | 0 .../{projectdir}ExceptionMessages.java.jinja | 19 ++ .../main/{projectdir}RegexPatterns.java.jinja | 10 + .../templates/java/xconsumer/pom.xml.jinja | 183 ++++++++++++++++++ .../java/xproducer/_templateinfo.json | 4 + .../main/{classdir}EventProducer.java.jinja | 0 .../{projectdir}ExceptionMessages.java.jinja | 19 ++ .../main/{projectdir}RegexPatterns.java.jinja | 10 + .../templates/java/xproducer/pom.xml.jinja | 183 ++++++++++++++++++ 19 files changed, 604 insertions(+), 40 deletions(-) create mode 100644 xregistry/templates/java/consumer/main/{classdir}EventDispatcher.java.jinja create mode 100644 xregistry/templates/java/producer/main/{classdir}EventFactory.java.jinja create mode 100644 xregistry/templates/java/xconsumer/_templateinfo.json create mode 100644 xregistry/templates/java/xconsumer/main/{classdir}DispatchInterfaces.java.jinja rename xregistry/templates/java/{consumer => xconsumer}/main/{classdir}EventConsumer.java.jinja (100%) create mode 100644 xregistry/templates/java/xconsumer/main/{projectdir}ExceptionMessages.java.jinja create mode 100644 xregistry/templates/java/xconsumer/main/{projectdir}RegexPatterns.java.jinja create mode 100644 xregistry/templates/java/xconsumer/pom.xml.jinja create mode 100644 xregistry/templates/java/xproducer/_templateinfo.json rename xregistry/templates/java/{producer => xproducer}/main/{classdir}EventProducer.java.jinja (100%) create mode 100644 xregistry/templates/java/xproducer/main/{projectdir}ExceptionMessages.java.jinja create mode 100644 xregistry/templates/java/xproducer/main/{projectdir}RegexPatterns.java.jinja create mode 100644 xregistry/templates/java/xproducer/pom.xml.jinja diff --git a/xregistry/templates/java/_common/mqtt.jinja.include b/xregistry/templates/java/_common/mqtt.jinja.include index 076a80d..2cb2aa7 100644 --- a/xregistry/templates/java/_common/mqtt.jinja.include +++ b/xregistry/templates/java/_common/mqtt.jinja.include @@ -2,7 +2,7 @@ {%- macro PahoImports() -%} import org.eclipse.paho.client.mqttv3.MqttMessage as MqttMessageV2; -iomport org.eclipse.paho.mqttv5.common.packet.MqttWireMessage as MqttMessageV5; +import org.eclipse.paho.mqttv5.common.packet.MqttWireMessage as MqttMessageV5; {%- endmacro -%} {%- macro EmitArguments(props) -%} diff --git a/xregistry/templates/java/_templateinfo.json b/xregistry/templates/java/_templateinfo.json index b2e5971..87dd3f6 100644 --- a/xregistry/templates/java/_templateinfo.json +++ b/xregistry/templates/java/_templateinfo.json @@ -1,4 +1,4 @@ { - "description" : "Java 13+", + "description" : "Java 21+", "priority" : 2 } \ No newline at end of file diff --git a/xregistry/templates/java/consumer/_templateinfo.json b/xregistry/templates/java/consumer/_templateinfo.json index 364363f..b781388 100644 --- a/xregistry/templates/java/consumer/_templateinfo.json +++ b/xregistry/templates/java/consumer/_templateinfo.json @@ -1,4 +1,4 @@ { - "description" : "Java CloudEvents SDK endpoint consumer class", + "description" : "Java Experimental CloudEvents SDK endpoint consumer class", "priority" : 1 } \ No newline at end of file diff --git a/xregistry/templates/java/consumer/main/{classdir}EventDispatcher.java.jinja b/xregistry/templates/java/consumer/main/{classdir}EventDispatcher.java.jinja new file mode 100644 index 0000000..8699c12 --- /dev/null +++ b/xregistry/templates/java/consumer/main/{classdir}EventDispatcher.java.jinja @@ -0,0 +1,79 @@ +{%- import "cloudevents.jinja.include" as cloudEvents -%} +{%- import "amqp.jinja.include" as amqp -%} +{%- import "mqtt.jinja.include" as mqtt -%} +{%- set messagegroups = root.messagegroups %} +{%- set uses_cloudevents_message = (root | exists( "format", "cloudevents" )) %} +{%- set uses_http_endpoint = (root | exists( "protocol", "http" )) %} +{%- set uses_amqp_message = (root | exists( "binding", "amqp" )) %} +{%- set uses_amqp_endpoint = (root | exists( "protocol", "amqp" )) %} +{%- set uses_mqtt_message = (root | exists( "binding", "mqtt" )) %} +{%- set uses_mqtt_endpoint = (root | exists( "protocol", "mqtt" )) %} +// this file was generated by a tool +package {{ class_name | namespace | lower }}; + +{%- if uses_amqp_message %} +{{ amqp.AmqpImports() }} +{%- endif %} +{%- if uses_mqtt_message %} +{{ mqtt.PahoImports() }} +{%- endif %} +{%- if uses_cloudevents_message %} +import io.cloudevents.CloudEvent; +{%- endif %} +import java.util.concurrent.CompletableFuture; +import java.util.ArrayList; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; + +{% for messagegroup_key, messagegroup in messagegroups.items() -%} +{%- set pascalGroupName = messagegroup.id | pascal -%} +{%- set className = (pascalGroupName | strip_namespace)+"EventDispatcher" %} +public class {{ className | strip_namespace }} +{ + + private Logger _logger = LogManager.getLogger({{ className }}.class); + + {%- if uses_cloudevents_message %} + {{ cloudEvents.DeclareDispatchObjectsFields( project_name, messagegroups ) | indent(4) }} + {{ cloudEvents.DeclareDispatchObjectsConstructor( project_name, className, messagegroups, '', '') | indent(4) }} + {%- endif %} + {%- if uses_amqp_message %} + {{ amqp.DeclareDispatchObjectsFields( project_name, messagegroups ) | indent(4) }} + {{ amqp.DeclareDispatchObjectsConstructor( project_name, className, messagegroups, '', '') | indent(4) }} + {%- endif %} + {%- if uses_mqtt_message %} + {{ mqtt.DeclareDispatchObjectsFields( project_name, messagegroups ) | indent(4) }} + {{ mqtt.DeclareDispatchObjectsConstructor( project_name, className, messagegroups, '', '') | indent(4) }} + {%- endif %} + + {%- if uses_cloudevents_message %} + public CompletableFuture dispatchCloudEventAsync( + CloudEvent cloudEvent) + { + {{ cloudEvents.DispatchToDispatchObjects(project_name, root, "cloudEvent", messagegroups, "_logger" ) | indent(12) }} + } + {%- endif %} + + {%- if uses_amqp_message %} + public CompletableFuture dispatchMessageAsync( + Message amqpMessage, MessageContext messageContext) + { + {{ amqp.DispatchToDispatchObjects(project_name, root, "amqpMessage", messagegroups, "_logger" ) | indent(12) }} + } + {%- endif %} + + {%- if uses_mqtt_message %} + public CompletableFuture dispatchMqttMessageV5Async( + MqttMessageV5 mqttMessage) + { + {{ mqtt.DispatchToDispatchObjects(project_name, root, "mqttMessage", messagegroups, "_logger" ) | indent(12) }} + } + + public CompletableFuture dispatchMqttMessageV3Async( + MqttMessageV3 mqttMessage) + { + {{ mqtt.DispatchToDispatchObjects(project_name, root, "mqttMessage", messagegroups, "_logger") | indent(12) }} + } + {%- endif %} +} +{% endfor %} \ No newline at end of file diff --git a/xregistry/templates/java/consumer/pom.xml.jinja b/xregistry/templates/java/consumer/pom.xml.jinja index c503ff3..9db409d 100644 --- a/xregistry/templates/java/consumer/pom.xml.jinja +++ b/xregistry/templates/java/consumer/pom.xml.jinja @@ -20,7 +20,6 @@ {%- endif %} 2.23.1 3.0.0 - 0.1.1-SNAPSHOT @@ -46,24 +45,10 @@ ${io.cloudevents.version} - io.cloudevents.experimental - endpoints - ${io.cloudevents.experimental.version} + io.cloudevents + cloudevents-json-jackson + ${io.cloudevents.version} - {%- if uses_amqp_endpoint %} - - io.cloudevents.experimental - endpoints-amqp - ${io.cloudevents.experimental.version} - - {%- endif %} - {%- if uses_mqtt_endpoint %} - - io.cloudevents.experimental - endpoints-mqtt - ${io.cloudevents.experimental.version} - - {%- endif %} {%- if uses_protobuf %} io.cloudevents diff --git a/xregistry/templates/java/producer/_templateinfo.json b/xregistry/templates/java/producer/_templateinfo.json index df95240..9506ded 100644 --- a/xregistry/templates/java/producer/_templateinfo.json +++ b/xregistry/templates/java/producer/_templateinfo.json @@ -1,4 +1,4 @@ { - "description" : "Java CloudEvents SDK endpoint producer class", + "description" : "Java Experimental CloudEvents SDK endpoint producer class", "priority" : 1 } \ No newline at end of file diff --git a/xregistry/templates/java/producer/main/{classdir}EventFactory.java.jinja b/xregistry/templates/java/producer/main/{classdir}EventFactory.java.jinja new file mode 100644 index 0000000..6ad9963 --- /dev/null +++ b/xregistry/templates/java/producer/main/{classdir}EventFactory.java.jinja @@ -0,0 +1,72 @@ +{%- import "cloudevents.jinja.include" as cloudEvents -%} +{%- import "amqp.jinja.include" as amqp -%} +{%- import "mqtt.jinja.include" as mqtt -%} +{%- set messagegroups = root.messagegroups %} +{%- set uses_cloudevents_message = (root | exists( "format", "cloudevents" )) %} +{%- set uses_http_endpoint = (root | exists( "protocol", "http" )) %} +{%- set uses_amqp_message = (root | exists( "binding", "amqp" )) %} +{%- set uses_amqp_endpoint = (root | exists( "protocol", "amqp" )) %} +{%- set uses_mqtt_message = (root | exists( "binding", "mqtt" )) %} +{%- set uses_mqtt_endpoint = (root | exists( "protocol", "mqtt" )) %} +// this file was generated by a tool +package {{ class_name | namespace | lower }}; + +import io.cloudevents.CloudEvent; +import io.cloudevents.CloudEventData; +import io.cloudevents.core.v1.CloudEventBuilder; +import io.cloudevents.core.format.EventFormat; +import io.cloudevents.core.message.Encoding; + +{%- if uses_amqp_message %} +{{ amqp.AmqpImports() }} +{%- endif %} +{%- if uses_mqtt_message %} +{{ mqtt.PahoImports() }} +{%- endif %} +import java.util.ArrayList; + +{% for messagegroup_key, messagegroup in messagegroups.items() -%} +{%- set pascalGroupName = messagegroup.id | pascal -%} +{%- set className = (pascalGroupName | strip_namespace)+"EventFactory" %} +public class {{ className | strip_namespace }} +{ + {% for id in messagegroup.messages -%} + {%- set definition = messagegroup.messages[id] -%} + {%- set pascalDefinitionName = definition.id | pascal %} + {%- set isCloudEvent = not definition.format or definition.format.lower().startswith("cloudevents") -%} + {%- set isAmqp = not isCloudEvent and definition.format.lower().startswith("amqp") %} + {%- set isMqtt = not isCloudEvent and definition.format.lower().startswith("mqtt") %} + public {% if isCloudEvent %}CloudEvent{% elif isAmqp %}Amqp.Message{% elif isMqtt %}MqttMessageV5{% endif %} create{{ pascalDefinitionName | strip_namespace }}( + {%- if definition.schemaurl -%} + {%- set toBytes="data.toByteArray()" -%} + {%- set type = (definition.schemaurl if definition.schemaurl else definition.schema) | schema_type( project_name, root, definition.schemaformat) %} + {%- set typePackage = type | namespace | lower %} + {%- set typeName = type | strip_namespace | pascal %} + {{ typePackage }}.{{ typeName }} data + {%- else -%} + {% set toBytes="data.toBytes()" %} + CloudEventData data + {%- endif %} + {%- if isCloudEvent -%} + {{- cloudEvents.DeclareUriTemplateArguments(definition) -}} + {%- elif isAmqp -%} + {{- amqp.DeclareUriTemplateArguments(definition) -}} + {%- elif isMqtt -%} + {{- mqtt.DeclareUriTemplateArguments(definition) -}} + {%- endif -%} + ) throws Exception { + {% if isCloudEvent %} + {{- cloudEvents.DeclareCloudNativeCloudEvent("cloudEvent", toBytes, definition) | indent(12)}} + return cloudEvent; + {%- elif isAmqp %} + {{- amqp.DeclareAmqpNetLiteMessage("amqpMessage", definition) | indent(12)}} + amqpMessage.BodySection = new Data() { Binary = {{ toBytes }} }; + return amqpMessage; + {%- elif isMqtt %} + {{- mqtt.DeclareMqttNetMessage("mqttMessage", definition) | indent(12)}} + return mqttMessage; + {%- endif %} + } + {% endfor %} +} +{% endfor -%} \ No newline at end of file diff --git a/xregistry/templates/java/producer/pom.xml.jinja b/xregistry/templates/java/producer/pom.xml.jinja index 9c2a174..01e0a1f 100644 --- a/xregistry/templates/java/producer/pom.xml.jinja +++ b/xregistry/templates/java/producer/pom.xml.jinja @@ -20,7 +20,6 @@ {%- endif %} 2.23.1 3.0.0 - 0.1.1-SNAPSHOT @@ -46,24 +45,10 @@ ${io.cloudevents.version} - io.cloudevents.experimental - endpoints - ${io.cloudevents.experimental.version} + io.cloudevents + cloudevents-json-jackson + ${io.cloudevents.version} - {%- if uses_amqp_endpoint %} - - io.cloudevents.experimental - endpoints-amqp - ${io.cloudevents.experimental.version} - - {%- endif %} - {%- if uses_mqtt_endpoint %} - - io.cloudevents.experimental - endpoints-mqtt - ${io.cloudevents.experimental.version} - - {%- endif %} {%- if uses_protobuf %} io.cloudevents diff --git a/xregistry/templates/java/xconsumer/_templateinfo.json b/xregistry/templates/java/xconsumer/_templateinfo.json new file mode 100644 index 0000000..b781388 --- /dev/null +++ b/xregistry/templates/java/xconsumer/_templateinfo.json @@ -0,0 +1,4 @@ +{ + "description" : "Java Experimental CloudEvents SDK endpoint consumer class", + "priority" : 1 +} \ No newline at end of file diff --git a/xregistry/templates/java/xconsumer/main/{classdir}DispatchInterfaces.java.jinja b/xregistry/templates/java/xconsumer/main/{classdir}DispatchInterfaces.java.jinja new file mode 100644 index 0000000..3e39b3f --- /dev/null +++ b/xregistry/templates/java/xconsumer/main/{classdir}DispatchInterfaces.java.jinja @@ -0,0 +1,11 @@ +{%- import "cloudevents.jinja.include" as cloudEvents -%} +{%- import "mqtt.jinja.include" as mqtt -%} +{%- import "amqp.jinja.include" as amqp -%} + +{{ cloudEvents.DeclareDispatchInterfaces( project_name, root) }} +{{ mqtt.DeclareDispatchInterfaces( project_name, root) }} +{{ amqp.DeclareDispatchInterfaces( project_name, root) }} + +{# the macros are pushing all generated interfaces onto the "files" stack #} +{# therefore we exit the template here to avoid generating this file #} +{% exit %} \ No newline at end of file diff --git a/xregistry/templates/java/consumer/main/{classdir}EventConsumer.java.jinja b/xregistry/templates/java/xconsumer/main/{classdir}EventConsumer.java.jinja similarity index 100% rename from xregistry/templates/java/consumer/main/{classdir}EventConsumer.java.jinja rename to xregistry/templates/java/xconsumer/main/{classdir}EventConsumer.java.jinja diff --git a/xregistry/templates/java/xconsumer/main/{projectdir}ExceptionMessages.java.jinja b/xregistry/templates/java/xconsumer/main/{projectdir}ExceptionMessages.java.jinja new file mode 100644 index 0000000..30c008f --- /dev/null +++ b/xregistry/templates/java/xconsumer/main/{projectdir}ExceptionMessages.java.jinja @@ -0,0 +1,19 @@ +package {{ project_name | lower }}; + +public class ExceptionMessages +{ + public static final String ValueIsTooLow = "%s value is too low. (min: %d)"; + public static final String ValueIsTooHigh = "%s value is too high. (max: %d)"; + public static final String ValueIsTooLong = "%s value is too long. (max length: %d)"; + public static final String ValueIsTooShort = "%s value is too short. (min length: %d)"; + public static final String ValueIsTooBig = "%s value is too big. (max: %d)"; + public static final String ValueIsTooSmall = "%s value is too small. (min: %d)"; + public static final String ValueIsInvalid = "%s value is invalid."; + public static final String ValueIsRequired = "%s value is required."; + public static final String ValueIsNotUnique = "%s value is not unique."; + public static final String ValueIsNotAnEmail = "%s value is not an email."; + public static final String ValueIsNotAnUrl = "%s value is not an URL."; + public static final String ValueIsNotADate = "%s value is not a date."; + public static final String ValueIsNotADateTime = "%s value is not a date time."; + public static final String ValueIsNotATime = "%s value is not a time."; +} \ No newline at end of file diff --git a/xregistry/templates/java/xconsumer/main/{projectdir}RegexPatterns.java.jinja b/xregistry/templates/java/xconsumer/main/{projectdir}RegexPatterns.java.jinja new file mode 100644 index 0000000..74037d8 --- /dev/null +++ b/xregistry/templates/java/xconsumer/main/{projectdir}RegexPatterns.java.jinja @@ -0,0 +1,10 @@ +package {{ project_name | lower }}; + +public class RegexPatterns +{ + public static final String Email = "^\\S+@\\S+$"; + public static final String Url = "^(http:\\/\\/www\\.|https:\\/\\/www\\.|http:\\/\\/|https:\\/\\/)?[a-z0-9]+([\\-\\.]{1}[a-z0-9]+)*\\.[a-z]{2,5}(:[0-9]{1,5})?(\\/.*)?$"; + public static final String Date = "^\\d{4}-\\d{2}-\\d{2}$"; + public static final String DateTime = "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}:\\d{2})|Z)?$"; + public static final String Time = "^\\d{2}:\\d{2}:\\d{2}$"; +} \ No newline at end of file diff --git a/xregistry/templates/java/xconsumer/pom.xml.jinja b/xregistry/templates/java/xconsumer/pom.xml.jinja new file mode 100644 index 0000000..c503ff3 --- /dev/null +++ b/xregistry/templates/java/xconsumer/pom.xml.jinja @@ -0,0 +1,183 @@ +{%- set uses_protobuf = uses_protobuf | default(false) -%} +{%- set uses_avro = uses_avro | default(false) -%} +{%- set uses_cloudevents_message = (root | exists( "format", "cloudevents" )) %} +{%- set uses_amqp_message = (root | exists( "binding", "amqp" )) %} +{%- set uses_amqp_endpoint = (root | exists("protocol", "amqp" )) %} +{%- set uses_mqtt_message = (root | exists( "binding", "mqtt" )) %} +{%- set uses_mqtt_endpoint = (root | exists("protocol", "mqtt" )) %} + + 4.0.0 + {{ project_name | lower }} + consumer + 1.0-SNAPSHOT + + {%- if uses_avro %} + 1.11.3 + {%- endif %} + {%- if uses_protobuf %} + 3.11.4 + {%- endif %} + 2.23.1 + 3.0.0 + 0.1.1-SNAPSHOT + + + + org.apache.logging.log4j + log4j-api + ${log4j.version} + provided + + + org.apache.logging.log4j + log4j-core + ${log4j.version} + provided + + + io.cloudevents + cloudevents-http-basic + ${io.cloudevents.version} + + + io.cloudevents + cloudevents-api + ${io.cloudevents.version} + + + io.cloudevents.experimental + endpoints + ${io.cloudevents.experimental.version} + + {%- if uses_amqp_endpoint %} + + io.cloudevents.experimental + endpoints-amqp + ${io.cloudevents.experimental.version} + + {%- endif %} + {%- if uses_mqtt_endpoint %} + + io.cloudevents.experimental + endpoints-mqtt + ${io.cloudevents.experimental.version} + + {%- endif %} + {%- if uses_protobuf %} + + io.cloudevents + cloudevents-protobuf + ${io.cloudevents.version} + + + com.google.protobuf + protobuf-java + ${protobuf.version} + + {%- endif %} + {%- if uses_avro %} + + + org.apache.avro + avro + ${avro.version} + + + org.apache.avro + avro-maven-plugin + ${avro.version} + + + org.apache.avro + avro-compiler + ${avro.version} + + + org.apache.avro + avro-ipc + ${avro.version} + + {%- endif %} + + + + clean package install + main + + {%- if uses_protobuf %} + + com.github.os72 + protoc-jar-maven-plugin + ${protobuf.version} + + + generate-sources + + run + + + ${protobuf.version} + + main/protobuf + + + + java + main + + + descriptor + none + ${project.build.directory}/classes + + + + + + + {%- endif %} + {%- if uses_avro %} + + org.apache.avro + avro-maven-plugin + ${avro.version} + + + generate-sources + + schema + + + main/avro + target/generated-sources/avro + + + + + {%- endif %} + + org.apache.maven.plugins + maven-resources-plugin + 3.3.1 + + UTF-8 + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.13.0 + + 21 + UTF-8 + + + + + \ No newline at end of file diff --git a/xregistry/templates/java/xproducer/_templateinfo.json b/xregistry/templates/java/xproducer/_templateinfo.json new file mode 100644 index 0000000..9506ded --- /dev/null +++ b/xregistry/templates/java/xproducer/_templateinfo.json @@ -0,0 +1,4 @@ +{ + "description" : "Java Experimental CloudEvents SDK endpoint producer class", + "priority" : 1 +} \ No newline at end of file diff --git a/xregistry/templates/java/producer/main/{classdir}EventProducer.java.jinja b/xregistry/templates/java/xproducer/main/{classdir}EventProducer.java.jinja similarity index 100% rename from xregistry/templates/java/producer/main/{classdir}EventProducer.java.jinja rename to xregistry/templates/java/xproducer/main/{classdir}EventProducer.java.jinja diff --git a/xregistry/templates/java/xproducer/main/{projectdir}ExceptionMessages.java.jinja b/xregistry/templates/java/xproducer/main/{projectdir}ExceptionMessages.java.jinja new file mode 100644 index 0000000..30c008f --- /dev/null +++ b/xregistry/templates/java/xproducer/main/{projectdir}ExceptionMessages.java.jinja @@ -0,0 +1,19 @@ +package {{ project_name | lower }}; + +public class ExceptionMessages +{ + public static final String ValueIsTooLow = "%s value is too low. (min: %d)"; + public static final String ValueIsTooHigh = "%s value is too high. (max: %d)"; + public static final String ValueIsTooLong = "%s value is too long. (max length: %d)"; + public static final String ValueIsTooShort = "%s value is too short. (min length: %d)"; + public static final String ValueIsTooBig = "%s value is too big. (max: %d)"; + public static final String ValueIsTooSmall = "%s value is too small. (min: %d)"; + public static final String ValueIsInvalid = "%s value is invalid."; + public static final String ValueIsRequired = "%s value is required."; + public static final String ValueIsNotUnique = "%s value is not unique."; + public static final String ValueIsNotAnEmail = "%s value is not an email."; + public static final String ValueIsNotAnUrl = "%s value is not an URL."; + public static final String ValueIsNotADate = "%s value is not a date."; + public static final String ValueIsNotADateTime = "%s value is not a date time."; + public static final String ValueIsNotATime = "%s value is not a time."; +} \ No newline at end of file diff --git a/xregistry/templates/java/xproducer/main/{projectdir}RegexPatterns.java.jinja b/xregistry/templates/java/xproducer/main/{projectdir}RegexPatterns.java.jinja new file mode 100644 index 0000000..74037d8 --- /dev/null +++ b/xregistry/templates/java/xproducer/main/{projectdir}RegexPatterns.java.jinja @@ -0,0 +1,10 @@ +package {{ project_name | lower }}; + +public class RegexPatterns +{ + public static final String Email = "^\\S+@\\S+$"; + public static final String Url = "^(http:\\/\\/www\\.|https:\\/\\/www\\.|http:\\/\\/|https:\\/\\/)?[a-z0-9]+([\\-\\.]{1}[a-z0-9]+)*\\.[a-z]{2,5}(:[0-9]{1,5})?(\\/.*)?$"; + public static final String Date = "^\\d{4}-\\d{2}-\\d{2}$"; + public static final String DateTime = "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}:\\d{2})|Z)?$"; + public static final String Time = "^\\d{2}:\\d{2}:\\d{2}$"; +} \ No newline at end of file diff --git a/xregistry/templates/java/xproducer/pom.xml.jinja b/xregistry/templates/java/xproducer/pom.xml.jinja new file mode 100644 index 0000000..9c2a174 --- /dev/null +++ b/xregistry/templates/java/xproducer/pom.xml.jinja @@ -0,0 +1,183 @@ +{%- set uses_protobuf = uses_protobuf | default(false) -%} +{%- set uses_avro = uses_avro | default(false) -%} +{%- set uses_cloudevents_message = (root | exists( "format", "cloudevents" )) %} +{%- set uses_amqp_message = (root | exists( "binding", "amqp" )) %} +{%- set uses_amqp_endpoint = (root | exists("protocol", "amqp" )) %} +{%- set uses_mqtt_message = (root | exists( "binding", "mqtt" )) %} +{%- set uses_mqtt_endpoint = (root | exists("protocol", "mqtt" )) %} + + 4.0.0 + {{ project_name | lower }} + producer + 1.0-SNAPSHOT + + {%- if uses_avro %} + 1.11.3 + {%- endif %} + {%- if uses_protobuf %} + 3.11.4 + {%- endif %} + 2.23.1 + 3.0.0 + 0.1.1-SNAPSHOT + + + + org.apache.logging.log4j + log4j-api + ${log4j.version} + provided + + + org.apache.logging.log4j + log4j-core + ${log4j.version} + provided + + + io.cloudevents + cloudevents-http-basic + ${io.cloudevents.version} + + + io.cloudevents + cloudevents-api + ${io.cloudevents.version} + + + io.cloudevents.experimental + endpoints + ${io.cloudevents.experimental.version} + + {%- if uses_amqp_endpoint %} + + io.cloudevents.experimental + endpoints-amqp + ${io.cloudevents.experimental.version} + + {%- endif %} + {%- if uses_mqtt_endpoint %} + + io.cloudevents.experimental + endpoints-mqtt + ${io.cloudevents.experimental.version} + + {%- endif %} + {%- if uses_protobuf %} + + io.cloudevents + cloudevents-protobuf + ${io.cloudevents.version} + + + com.google.protobuf + protobuf-java + ${protobuf.version} + + {%- endif %} + {%- if uses_avro %} + + + org.apache.avro + avro + ${avro.version} + + + org.apache.avro + avro-maven-plugin + ${avro.version} + + + org.apache.avro + avro-compiler + ${avro.version} + + + org.apache.avro + avro-ipc + ${avro.version} + + {%- endif %} + + + + clean package install + main + + {%- if uses_protobuf %} + + com.github.os72 + protoc-jar-maven-plugin + ${protobuf.version} + + + generate-sources + + run + + + ${protobuf.version} + + main/protobuf + + + + java + main + + + descriptor + none + ${project.build.directory}/classes + + + + + + + {%- endif %} + {%- if uses_avro %} + + org.apache.avro + avro-maven-plugin + ${avro.version} + + + generate-sources + + schema + + + main/avro + target/generated-sources/avro + + + + + {%- endif %} + + org.apache.maven.plugins + maven-resources-plugin + 3.3.1 + + UTF-8 + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.13.0 + + 21 + UTF-8 + + + + + \ No newline at end of file