Skip to content

Commit

Permalink
Merge pull request #42 from ZenWave360/develop
Browse files Browse the repository at this point in the history
Merging Develop for v1.7.0
  • Loading branch information
ivangsa authored Dec 30, 2024
2 parents d005b89 + 1b84fae commit 2cb50ae
Show file tree
Hide file tree
Showing 68 changed files with 1,660 additions and 297 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true

[*]

# We recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true


[*.md]
trim_trailing_whitespace = false
33 changes: 33 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Enforce LF line endings for all text files by default
* text=auto eol=lf

# Explicit exceptions for CRLF line endings
*.bat text eol=crlf
*.cmd text eol=crlf
*.ps1 text eol=crlf

# Explicitly mark binary files
# (Git automatically detects these, but this is a safeguard for clarity)
*.pdf binary
*.png binary
*.jpg binary
*.jpeg binary
*.gif binary
*.tif binary
*.tiff binary
*.ico binary
*.svg binary
*.eps binary
*.class binary
*.jar binary
*.war binary
*.7z binary
*.gz binary
*.rar binary
*.tar binary
*.zip binary
*.ttf binary
*.eot binary
*.otf binary
*.woff binary
*.woff2 binary
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package io.zenwave360.sdk.e2e;

import io.zenwave360.sdk.MainGenerator;
import io.zenwave360.sdk.Plugin;
import io.zenwave360.sdk.options.DatabaseType;
import io.zenwave360.sdk.options.PersistenceType;
import io.zenwave360.sdk.options.ProgrammingStyle;
import io.zenwave360.sdk.plugins.BackendApplicationDefaultPlugin;
import io.zenwave360.sdk.plugins.OpenAPIControllersPlugin;
import io.zenwave360.sdk.plugins.ZDLToAsyncAPIPlugin;
import io.zenwave360.sdk.plugins.ZDLToOpenAPIPlugin;
import io.zenwave360.sdk.testutils.MavenCompiler;
import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;

import java.io.File;

@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class TestPatchAndNaturalIdProject {
private String basePackage = "io.zenwave360.example";

@Test
public void testPatchAndNaturalIdProject() throws Exception {
String sourceFolder = "src/test/resources/projects/patch-and-natural-id/";
String targetFolder = "target/patch-and-natural-id/";
String zdlFile = targetFolder + "/patch-and-natural-id.zdl";

// copy whole dir from sourceFolder to targetFolder
FileUtils.deleteDirectory(new File(targetFolder));
FileUtils.forceMkdir(new File(targetFolder));
FileUtils.copyDirectory(new File(sourceFolder), new File(targetFolder));
Assertions.assertTrue(new File(targetFolder).exists());

Plugin plugin = null;
int exitCode = 0;

plugin = new ZDLToOpenAPIPlugin()
.withZdlFile(zdlFile)
.withOption("idType", "integer")
.withOption("idTypeFormat", "int64")
.withOption("targetFile", "/src/main/resources/apis/openapi.yml")
.withTargetFolder(targetFolder);
new MainGenerator().generate(plugin);

plugin = new ZDLToAsyncAPIPlugin()
.withZdlFile(zdlFile)
.withOption("asyncapiVersion", "v3")
.withOption("idType", "integer")
.withOption("idTypeFormat", "int64")
.withOption("targetFile", "/src/main/resources/apis/asyncapi.yml")
.withTargetFolder(targetFolder);
new MainGenerator().generate(plugin);

plugin = new BackendApplicationDefaultPlugin()
.withZdlFile(zdlFile)
.withTargetFolder(targetFolder)
.withOption("basePackage", basePackage)
.withOption("persistence", PersistenceType.jpa)
.withOption("databaseType", DatabaseType.postgresql)
.withOption("style", ProgrammingStyle.imperative)
.withOption("useLombok", true)
.withOption("includeEmitEventsImplementation", true)
.withOption("forceOverwrite", true)
.withOption("haltOnFailFormatting", false);

new MainGenerator().generate(plugin);

TextUtils.replaceInFile(new File(targetFolder + "/src/main/java/io/zenwave360/example/core/implementation/mappers/EventsMapper.java"),
"io.zenwave360.example.core.outbound.events.dtos.Customer asCustomer\\(Customer customer\\);",
"""
@org.mapstruct.Mapping(target = "extraProperties", ignore = true)
io.zenwave360.example.core.outbound.events.dtos.Customer asCustomer(Customer customer);
""");

exitCode = MavenCompiler.compile(new File(targetFolder));
Assertions.assertEquals(0, exitCode);

plugin = new OpenAPIControllersPlugin()
.withApiFile(targetFolder + "/src/main/resources/apis/openapi.yml")
.withTargetFolder(targetFolder)
.withOption("zdlFile", zdlFile)
.withOption("basePackage", basePackage)
.withOption("controllersPackage", "{{basePackage}}.adapters.web")
.withOption("openApiApiPackage", "{{basePackage}}.adapters.web")
.withOption("openApiModelPackage", "{{basePackage}}.adapters.web.model")
.withOption("openApiModelNameSuffix", "DTO")
.withOption("style", ProgrammingStyle.imperative)
.withOption("haltOnFailFormatting", false);
new MainGenerator().generate(plugin);

TextUtils.replaceInFile(new File(targetFolder + "/src/main/java/io/zenwave360/example/adapters/web/mappers/CustomerDTOsMapper.java"),
"// request mappings",
"""
// request mappings
default Map map(Object value) { return new HashMap();}
""");

exitCode = MavenCompiler.compile(new File(targetFolder));
Assertions.assertEquals(0, exitCode);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
<useSpringBoot3>true</useSpringBoot3>
<documentationProvider>none</documentationProvider>
<openApiNullable>false</openApiNullable>
<useOptional>true</useOptional>
<useOptional>false</useOptional>
<useTags>true</useTags>
<interfaceOnly>true</interfaceOnly>
<skipDefaultInterface>true</skipDefaultInterface>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
<useSpringBoot3>true</useSpringBoot3>
<documentationProvider>none</documentationProvider>
<openApiNullable>false</openApiNullable>
<useOptional>true</useOptional>
<useOptional>false</useOptional>
<useTags>true</useTags>
<interfaceOnly>true</interfaceOnly>
<skipDefaultInterface>true</skipDefaultInterface>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
<useJakartaEe>true</useJakartaEe>
<documentationProvider>none</documentationProvider>
<openApiNullable>false</openApiNullable>
<useOptional>true</useOptional>
<useOptional>false</useOptional>
<useTags>true</useTags>
</configOptions>
</configuration>
Expand All @@ -158,7 +158,7 @@
<useJakartaEe>true</useJakartaEe>
<documentationProvider>none</documentationProvider>
<openApiNullable>false</openApiNullable>
<useOptional>true</useOptional>
<useOptional>false</useOptional>
<useTags>true</useTags>
</configOptions>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
<useSpringBoot3>true</useSpringBoot3>
<documentationProvider>none</documentationProvider>
<openApiNullable>false</openApiNullable>
<useOptional>true</useOptional>
<useOptional>false</useOptional>
<useTags>true</useTags>
<interfaceOnly>true</interfaceOnly>
<skipDefaultInterface>true</skipDefaultInterface>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: '3.8'
services:
mariadb:
image: mariadb:10.7.1
# volumes:
# - ~/volumes/mysql/:/var/lib/mysql/
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
- MYSQL_DATABASE=zenwave-playground
ports:
- 127.0.0.1:3306:3306
command: mysqld --lower_case_table_names=1 --skip-ssl --character_set_server=utf8mb4 --explicit_defaults_for_timestamp
kafka:
image: bashj79/kafka-kraft
ports:
- '9092:9092'
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* Sample ZenWave Model Definition.
* Use zenwave-scripts.zdl to generate your code from this model definition.
*/
config {}

/**
* Customer entity
*/
@aggregate
@auditing // adds auditing fields to the entity
entity Customer {
@naturalId
customerId Long required
@naturalId
anotherId String required

name String required maxlength(254) /** Customer name */
email String required maxlength(254)
/** 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)
}
}

@auditing
entity 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 directly
input CustomerSearchCriteria {
name String
email String
city String
state String
}

@rest("/customers")
service CustomerService for (Customer) {
@post
createCustomer(Customer) Customer withEvents CustomerEvent

@get("/{customerId}/{anotherId}") @naturalId(Customer)
getCustomer(id) Customer?
@put("/{customerId}/{anotherId}") @naturalId(Customer)
updateCustomer(id, Customer) Customer? withEvents CustomerEvent
@patch("/{customerId}/{anotherId}") @naturalId(Customer)
patchCustomer(id, Customer) Customer? withEvents CustomerEvent
@delete("/{customerId}/{anotherId}") @naturalId(Customer)
deleteCustomer(id) withEvents CustomerEvent

@get("/search") @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[]
}
Loading

0 comments on commit 2cb50ae

Please sign in to comment.