Customer Address JPA Service
Section titled “Customer Address JPA Service”https://github.com/ZenWave360/zenwave-playground/tree/main/examples/kustomer-address-jpa
SpringBoot + Java microservice for a “Customer Address Service” using JPA for persistence for this Domain Model:
With these REST Endpoints:

And these Domain Events published to a Kafka Topic:

As defined on this
ZenWave Model for Customer Address JPA Service
/** * Sample ZenWave Model Definition. * Use zenwave-scripts.zdl to generate your code from this model definition. */config { title "Project Name" basePackage "io.zenwave360.examples.kotlin" persistence jpa databaseType postgresql
// you can choose: DefaultProjectLayout, CleanHexagonalProjectLayout, LayeredProjectLayout, SimpleDomainProjectLayout, HexagonalProjectLayout, CleanArchitectureProjectLayout layout LayeredProjectLayout
// these should match the values of openapi-generator-maven-plugin // used by the OpenAPIControllersPlugin and SpringWebTestClientPlugin layout.openApiApiPackage "{{basePackage}}.web" layout.openApiModelPackage "{{basePackage}}.web.dtos" openApiModelNameSuffix DTO}
/*** Customer entity*/@aggregate@auditing // adds auditing fields to the entityentity Customer { name String required maxlength(254) /** Customer name */ email String required maxlength(254) pattern(/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/) /** Customer Addresses can be stored in a JSON column in the database. */ @json addresses Address[] minlength(1) maxlength(5) { street String required maxlength(254) city String required maxlength(254) }}
@auditingentity PaymentMethod { type PaymentMethodType required cardNumber String required}
enum PaymentMethodType { VISA(1), MASTERCARD(2) }
relationship OneToMany { @eager Customer{paymentMethods required maxlength(3)} to PaymentMethod{customer required}}
// you can create 'inputs' as dtos for your service methods, or use entities directlyinput CustomerSearchCriteria { name String email String city String state String}
@rest("/customers")service CustomerService for (Customer) { @post createCustomer(Customer) Customer withEvents CustomerEvent @get("/{customerId}") getCustomer(id) Customer? @put("/{customerId}") updateCustomer(id, Customer) Customer? withEvents CustomerEvent @delete("/{customerId}") deleteCustomer(id) withEvents CustomerEvent @post({path: "/search", status: 200}) @paginated searchCustomers(CustomerSearchCriteria) Customer[]}
@copy(Customer)@asyncapi({ channel: "CustomersChannel", topic: "customers" })event CustomerEvent { id Long version Integer // all fields from Customer are copied here, but not relationships paymentMethods PaymentMethod[]}And generated using this
ZenWave Scripts for Customer Address JPA Service
@import("io.zenwave360.sdk.plugins.customizations:kotlin-backend-application:2.1.0-SNAPSHOT")
config {
zdlFile "zenwave-model.zdl"
plugins {
ZDLToOpenAPIPlugin { idType integer idTypeFormat int64 targetFile "src/main/resources/public/apis/openapi.yml" }
ZDLToAsyncAPIPlugin { asyncapiVersion v3 idType integer idTypeFormat int64 targetFile "src/main/resources/public/apis/asyncapi.yml" // includeKafkaCommonHeaders true }
BackendApplicationDefaultPlugin { templates "new io.zenwave360.sdk.plugins.kotlin.BackendApplicationKotlinTemplates()" includeEmitEventsImplementation true haltOnFailFormatting false --force // overwite all files }
OpenAPIControllersPlugin { openapiFile "src/main/resources/public/apis/openapi.yml" templates "new io.zenwave360.sdk.plugins.kotlin.OpenAPIControllersKotlinTemplates()" }
SpringWebTestClientPlugin { openapiFile "src/main/resources/public/apis/openapi.yml" templates "new io.zenwave360.sdk.plugins.kotlin.SpringWebTestClientKotlinTemplates()" }
SpringWebTestClientPlugin { openapiFile "src/main/resources/public/apis/openapi.yml" templates "new io.zenwave360.sdk.plugins.kotlin.SpringWebTestClientKotlinTemplates()" groupBy businessFlow businessFlowTestName CreateUpdateDeleteCustomerIntegrationTest operationIds createCustomer,updateCustomer,deleteCustomer,getCustomer }
OpenAPIKaratePlugin { openapiFile "src/main/resources/public/apis/openapi.yml" }
OpenAPIKaratePlugin { openapiFile "src/main/resources/public/apis/openapi.yml" groupBy businessFlow businessFlowTestName CreateUpdateDeleteCustomerKarateTest operationIds createCustomer,updateCustomer,deleteCustomer,getCustomer } }}with [ZenWave Model Editor] for IntelliJ IDEA.