From 4f21151b83c8b9a2aa2ca3801bfd1020b106d520 Mon Sep 17 00:00:00 2001 From: Ivan Garcia Sainz-Aja Date: Sat, 11 Feb 2023 12:27:12 +0100 Subject: [PATCH 1/7] zdl2json and json help --- .../BackendApplicationDefaultHelpersTest.java | 1 - .../src/main/java/io/zenwave360/sdk/Help.java | 2 +- .../src/main/java/io/zenwave360/sdk/Main.java | 17 +++++++--- .../sdk/plugins/ZdlToJsonPlugin.java | 33 +++++++++++++++++++ .../test/java/io/zenwave360/sdk/HelpTest.java | 5 +++ .../sdk/plugins/ZdlToJsonPluginTest.java | 15 +++++++++ .../sdk/resources/zdl/customer-address.zdl | 2 +- 7 files changed, 68 insertions(+), 7 deletions(-) create mode 100644 zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/plugins/ZdlToJsonPlugin.java create mode 100644 zenwave-sdk-cli/src/test/java/io/zenwave360/sdk/plugins/ZdlToJsonPluginTest.java diff --git a/plugins/backend-application-default/src/test/java/io/zenwave360/sdk/plugins/BackendApplicationDefaultHelpersTest.java b/plugins/backend-application-default/src/test/java/io/zenwave360/sdk/plugins/BackendApplicationDefaultHelpersTest.java index 75b31d49..8f2d8ca7 100644 --- a/plugins/backend-application-default/src/test/java/io/zenwave360/sdk/plugins/BackendApplicationDefaultHelpersTest.java +++ b/plugins/backend-application-default/src/test/java/io/zenwave360/sdk/plugins/BackendApplicationDefaultHelpersTest.java @@ -74,7 +74,6 @@ void listOfPairEventEntity() throws Exception { "Customer=CustomerCreatedFailed", "Customer=CustomerEvent", "Customer=CustomerUpdated", - "CustomerInput=CustomerInput", "deleteCustomer=CustomerDeleted"), entityEvent); diff --git a/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/Help.java b/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/Help.java index f5e0c4ca..730d0e7f 100644 --- a/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/Help.java +++ b/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/Help.java @@ -118,7 +118,7 @@ protected Map asModel(Object plugin, Field field, DocumentedOpti public String help(Plugin plugin, Format format) { format = format == null ? Format.help : format; - var model = format == Format.list ? discoverAvailablePlugins() : buildHelpModel(plugin); + var model = plugin == null ? discoverAvailablePlugins() : buildHelpModel(plugin); model.put("version", getClass().getPackage().getImplementationVersion()); if (format == Format.json) { try { diff --git a/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/Main.java b/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/Main.java index cb8b2a02..9ae01d74 100644 --- a/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/Main.java +++ b/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/Main.java @@ -4,6 +4,8 @@ import java.util.Map; import java.util.concurrent.Callable; +import avro.shaded.com.google.common.base.Objects; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,6 +40,10 @@ public static void main(String... args) { boolean noPlugin = !parsed.hasMatchedOption("p"); boolean usage = parsed.hasMatchedOption("h") && !parsed.hasMatchedOption("p") && main.helpFormat == null; + if(main.helpFormat == Help.Format.json && !parsed.hasMatchedOption("p")) { + main.help(); + return; + } if(usage || noOptions || noPlugin) { cmd.usage(System.out); main.helpFormat = Help.Format.list; @@ -72,10 +78,13 @@ public Integer call() throws Exception { public void help() { try { - Plugin plugin = Plugin.of(this.pluginClass) - .withSpecFile((String) options.get("specFile")) - .withTargetFolder((String) options.get("targetFolder")) - .withOptions(options); + Plugin plugin = null; + if(StringUtils.isNotBlank(this.pluginClass)) { + plugin = Plugin.of(this.pluginClass) + .withSpecFile((String) options.get("specFile")) + .withTargetFolder((String) options.get("targetFolder")) + .withOptions(options); + } String help = new Help().help(plugin, helpFormat); System.out.println(help); } catch (Exception e) { diff --git a/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/plugins/ZdlToJsonPlugin.java b/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/plugins/ZdlToJsonPlugin.java new file mode 100644 index 00000000..c862aac0 --- /dev/null +++ b/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/plugins/ZdlToJsonPlugin.java @@ -0,0 +1,33 @@ +package io.zenwave360.sdk.plugins; + +import java.util.Map; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import io.zenwave360.sdk.Plugin; +import io.zenwave360.sdk.doc.DocumentedPlugin; +import io.zenwave360.sdk.parsers.ZDLParser; +import io.zenwave360.sdk.processors.Processor; +import io.zenwave360.sdk.processors.ZDLProcessor; + +@DocumentedPlugin(value = "Prints to StdOut ZDL Model as JSON", shortCode = "zdl-to-json") +public class ZdlToJsonPlugin extends Plugin implements Processor { + + public ZdlToJsonPlugin() { + withChain(ZDLParser.class, ZDLProcessor.class, ZdlToJsonPlugin.class); + } + + @Override + public Map process(Map contextModel) { + var zdl = contextModel.get("zdl"); + ObjectMapper objectMapper = new ObjectMapper(); + try { + var json = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(zdl); + System.out.println(json); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + return null; + } +} diff --git a/zenwave-sdk-cli/src/test/java/io/zenwave360/sdk/HelpTest.java b/zenwave-sdk-cli/src/test/java/io/zenwave360/sdk/HelpTest.java index 1dbf71da..75724f10 100644 --- a/zenwave-sdk-cli/src/test/java/io/zenwave360/sdk/HelpTest.java +++ b/zenwave-sdk-cli/src/test/java/io/zenwave360/sdk/HelpTest.java @@ -16,6 +16,11 @@ public void testMainHelp() { Main.main("-h"); } + @Test + public void testPluginsJsonHelp() { + Main.main("-h", "json"); + } + @Test public void testPluginHelp() { Main.main("-h", "-p", NoOpPluginConfiguration.class.getName()); diff --git a/zenwave-sdk-cli/src/test/java/io/zenwave360/sdk/plugins/ZdlToJsonPluginTest.java b/zenwave-sdk-cli/src/test/java/io/zenwave360/sdk/plugins/ZdlToJsonPluginTest.java new file mode 100644 index 00000000..1c2b13bc --- /dev/null +++ b/zenwave-sdk-cli/src/test/java/io/zenwave360/sdk/plugins/ZdlToJsonPluginTest.java @@ -0,0 +1,15 @@ +package io.zenwave360.sdk.plugins; + +import org.junit.jupiter.api.Test; + +import io.zenwave360.sdk.MainGenerator; +import io.zenwave360.sdk.Plugin; + +public class ZdlToJsonPluginTest { + + @Test + void testZdlToJsonPlugin() throws Exception { + Plugin plugin = new ZdlToJsonPlugin().withSpecFile("classpath:io/zenwave360/sdk/resources/zdl/customer-address.zdl"); + new MainGenerator().generate(plugin); + } +} diff --git a/zenwave-sdk-test-resources/src/main/resources/io/zenwave360/sdk/resources/zdl/customer-address.zdl b/zenwave-sdk-test-resources/src/main/resources/io/zenwave360/sdk/resources/zdl/customer-address.zdl index ab8cdeb5..c99a5471 100644 --- a/zenwave-sdk-test-resources/src/main/resources/io/zenwave360/sdk/resources/zdl/customer-address.zdl +++ b/zenwave-sdk-test-resources/src/main/resources/io/zenwave360/sdk/resources/zdl/customer-address.zdl @@ -105,7 +105,7 @@ event CustomerCreated { @asyncapi({channel: "customerEventsChannel", topic: "customer-events-topic"}) event CustomerCreatedFailed { - customerInput CustomerInput + customer Customer error String } From 8d75a6e843038f095b8d9914314ac2e2408ad637 Mon Sep 17 00:00:00 2001 From: Ivan Garcia Sainz-Aja Date: Sat, 24 Feb 2024 11:47:39 +0100 Subject: [PATCH 2/7] - OAS: inline query params - OAS: skip @inline - ZDL: Support primitives - @transient --- .../SpringCloudStreams3GeneratorV3Test.java | 27 +++++++++++++++++++ plugins/backend-application-default/README.md | 2 +- .../BackendApplicationDefaultHelpers.java | 3 +++ .../main/java/core/domain/jpa/Entity.java.hbs | 1 + .../sdk/plugins/ZDLToOpenAPIGenerator.java | 2 +- .../ZDLToOpenAPI.yml.hbs | 2 +- pom.xml | 2 +- .../generators/EntitiesToAvroConverter.java | 10 +++---- .../EntitiesToSchemasConverter.java | 17 +++++++----- .../io/zenwave360/sdk/parsers/ZDLParser.java | 2 +- .../io/zenwave360/sdk/utils/JSONPath.java | 10 +++++++ .../sdk/resources/zdl/customer-address.zdl | 2 +- .../zdl/order-faults-attachments-model.zdl | 1 + 13 files changed, 63 insertions(+), 18 deletions(-) diff --git a/plugins/asyncapi-spring-cloud-streams3/src/test/java/io/zenwave360/sdk/plugins/SpringCloudStreams3GeneratorV3Test.java b/plugins/asyncapi-spring-cloud-streams3/src/test/java/io/zenwave360/sdk/plugins/SpringCloudStreams3GeneratorV3Test.java index 7525ee85..51b5840f 100644 --- a/plugins/asyncapi-spring-cloud-streams3/src/test/java/io/zenwave360/sdk/plugins/SpringCloudStreams3GeneratorV3Test.java +++ b/plugins/asyncapi-spring-cloud-streams3/src/test/java/io/zenwave360/sdk/plugins/SpringCloudStreams3GeneratorV3Test.java @@ -68,6 +68,33 @@ public void test_generator_provider_for_events() throws Exception { Assertions.assertTrue(logs.contains("Writing template with targetFile: src/test/java/io/example/integration/test/api/provider_for_events/EventsProducerInMemoryContext.java")); } + @Test + public void test_generator_provider_for_events_skipProducerImplementation() throws Exception { + Plugin plugin = new SpringCloudStreams3Plugin() + .withSpecFile("classpath:io/zenwave360/sdk/resources/asyncapi/v3/customer-order-asyncapi.yml") + .withTargetFolder("target/zenwave630/out/v3/skipProducerImplementation") + .withOption("apiPackage", "io.example.integration.test.api.provider_for_events") + .withOption("modelPackage", "io.example.integration.test.api.model") + .withOption("skipProducerImplementation", true) + .withOption("role", AsyncapiRoleType.provider) + .withOption("style", ProgrammingStyle.imperative); + + new MainGenerator().generate(plugin); + + List logs = logCaptor.getLogs(); + Assertions.assertTrue(logs.contains("Writing template with targetFile: src/main/java/io/example/integration/test/api/provider_for_events/DoCustomerRequestConsumer.java")); + Assertions.assertTrue(logs.contains("Writing template with targetFile: src/main/java/io/example/integration/test/api/provider_for_events/IDoCustomerRequestConsumerService.java")); + Assertions.assertTrue(logs.contains("Writing template with targetFile: src/main/java/io/example/integration/test/api/provider_for_events/DoCustomerOrderRequestConsumer.java")); + Assertions.assertTrue(logs.contains("Writing template with targetFile: src/main/java/io/example/integration/test/api/provider_for_events/IDoCustomerOrderRequestConsumerService.java")); + Assertions.assertTrue(logs.contains("Writing template with targetFile: src/main/java/io/example/integration/test/api/provider_for_events/ICustomerEventsProducer.java")); + Assertions.assertFalse(logs.contains("Writing template with targetFile: src/main/java/io/example/integration/test/api/provider_for_events/CustomerEventsProducer.java")); + Assertions.assertTrue(logs.contains("Writing template with targetFile: src/test/java/io/example/integration/test/api/provider_for_events/CustomerEventsProducerCaptor.java")); + Assertions.assertTrue(logs.contains("Writing template with targetFile: src/main/java/io/example/integration/test/api/provider_for_events/ICustomerOrderEventsProducer.java")); + Assertions.assertFalse(logs.contains("Writing template with targetFile: src/main/java/io/example/integration/test/api/provider_for_events/CustomerOrderEventsProducer.java")); + Assertions.assertTrue(logs.contains("Writing template with targetFile: src/test/java/io/example/integration/test/api/provider_for_events/CustomerOrderEventsProducerCaptor.java")); + Assertions.assertTrue(logs.contains("Writing template with targetFile: src/test/java/io/example/integration/test/api/provider_for_events/EventsProducerInMemoryContext.java")); + } + @Test public void test_generator_client_with_operationId() throws Exception { Plugin plugin = new SpringCloudStreams3Plugin() diff --git a/plugins/backend-application-default/README.md b/plugins/backend-application-default/README.md index 08eff75c..612cab08 100644 --- a/plugins/backend-application-default/README.md +++ b/plugins/backend-application-default/README.md @@ -1,4 +1,4 @@ -# ZDL Backend Application Default Plugin +# Backend Application Default Plugin > 👉 ZenWave360 Helps You Create Software Easy to Understand Generates a full backend application using a flexible hexagonal architecture. diff --git a/plugins/backend-application-default/src/main/java/io/zenwave360/sdk/plugins/BackendApplicationDefaultHelpers.java b/plugins/backend-application-default/src/main/java/io/zenwave360/sdk/plugins/BackendApplicationDefaultHelpers.java index 2412bed6..c5f1cbb8 100644 --- a/plugins/backend-application-default/src/main/java/io/zenwave360/sdk/plugins/BackendApplicationDefaultHelpers.java +++ b/plugins/backend-application-default/src/main/java/io/zenwave360/sdk/plugins/BackendApplicationDefaultHelpers.java @@ -251,6 +251,9 @@ public String fieldPersistenceAnnotations(Object context, Options options) { if (documentedOptions > 0) { return "@DocumentReference"; } + if(JSONPath.get(field, "options.transient", false)) { + return "@org.springframework.data.annotation.Transient"; + } return "@Field"; } return ""; diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/Entity.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/Entity.java.hbs index 3d5a0be5..edef7c09 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/Entity.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/Entity.java.hbs @@ -62,6 +62,7 @@ public class {{entity.className}} {{addExtends entity}} implements Serializable @Column(name = "{{snakeCase field.name}}" {{#if field.validations.required}}, nullable = false{{/if}}{{#if field.validations.unique}}, unique = true{{/if}}{{#if field.validations.maxlength}}, length = {{field.validations.maxlength.value}}{{/if}}) {{~/if~}} {{~#if field.isEnum}} @Enumerated(EnumType.STRING){{/if}} + {{~#if field.options.transient}} @javax.persistence.Transient {{/if}} private {{{fieldType field}}} {{field.name}} {{{fieldTypeInitializer field}}}; {{/each}} diff --git a/plugins/zdl-to-openapi/src/main/java/io/zenwave360/sdk/plugins/ZDLToOpenAPIGenerator.java b/plugins/zdl-to-openapi/src/main/java/io/zenwave360/sdk/plugins/ZDLToOpenAPIGenerator.java index a58ebb81..ec3c53e2 100644 --- a/plugins/zdl-to-openapi/src/main/java/io/zenwave360/sdk/plugins/ZDLToOpenAPIGenerator.java +++ b/plugins/zdl-to-openapi/src/main/java/io/zenwave360/sdk/plugins/ZDLToOpenAPIGenerator.java @@ -168,7 +168,7 @@ protected List> filterSchemasToInclude(Map m if (JSONPath.get(entity, "$.options.inline", false)) { var fields = JSONPath.get(entity, "$.fields[*].type", List.of()); for (String type : fields) { - var inlineEntity = JSONPath.get(allEntitiesAndEnums, "$.['" + parameter + "']", null); + var inlineEntity = JSONPath.get(allEntitiesAndEnums, "$.['" + type + "']", null); if(inlineEntity != null) { schemasToInclude.add((Map) inlineEntity); } diff --git a/plugins/zdl-to-openapi/src/main/resources/io/zenwave360/sdk/plugins/ZDLToOpenAPIGenerator/ZDLToOpenAPI.yml.hbs b/plugins/zdl-to-openapi/src/main/resources/io/zenwave360/sdk/plugins/ZDLToOpenAPIGenerator/ZDLToOpenAPI.yml.hbs index 80546959..5d1ff71a 100644 --- a/plugins/zdl-to-openapi/src/main/resources/io/zenwave360/sdk/plugins/ZDLToOpenAPIGenerator/ZDLToOpenAPI.yml.hbs +++ b/plugins/zdl-to-openapi/src/main/resources/io/zenwave360/sdk/plugins/ZDLToOpenAPIGenerator/ZDLToOpenAPI.yml.hbs @@ -38,7 +38,7 @@ paths: format: {{pathParam.format}} {{~/if}} {{~/each}} - {{~#each path.queryParams as |queryParam|}} + {{~#each operation.queryParamsMap as |queryParam|}} - name: "{{queryParam.name}}" in: query schema: diff --git a/pom.xml b/pom.xml index 8d5a2f3a..c1dbd80a 100644 --- a/pom.xml +++ b/pom.xml @@ -69,7 +69,7 @@ 0.10.2 4.3.1 0.8.4 - 1.0.0 + 1.1.0-SNAPSHOT 19.2 1.7 2.38.0 diff --git a/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/generators/EntitiesToAvroConverter.java b/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/generators/EntitiesToAvroConverter.java index b6425256..cb1f72fe 100644 --- a/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/generators/EntitiesToAvroConverter.java +++ b/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/generators/EntitiesToAvroConverter.java @@ -82,19 +82,19 @@ public Map convertEntityToAvro(Map entity, Map schemaTypeAndFormat(String entityType) { } else if ("Duration".equals(entityType)) { property.put("type", "string"); // property.put("format", "date-time"); - } else if ("Integer".equals(entityType)) { + } else if ("Integer".equals(entityType) || "int".equals(entityType)) { property.put("type", "integer"); property.put("format", "int32"); - } else if ("Long".equals(entityType)) { + } else if ("Long".equals(entityType) || "long".equals(entityType)) { property.put("type", "integer"); property.put("format", "int64"); - } else if ("Float".equals(entityType)) { + } else if ("Float".equals(entityType) || "float".equals(entityType)) { property.put("type", "number"); property.put("format", "float"); - } else if ("Double".equals(entityType) || "BigDecimal".equals(entityType)) { + } else if ("Double".equals(entityType) || "double".equals(entityType) || "BigDecimal".equals(entityType)) { property.put("type", "number"); property.put("format", "double"); - } else if ("Boolean".equals(entityType)) { + } else if ("Boolean".equals(entityType) || "boolean".equals(entityType)) { property.put("type", "boolean"); } else if ("UUID".equals(entityType)) { property.put("type", "string"); property.put("pattern", "^[a-f\\d]{4}(?:[a-f\\d]{4}-){4}[a-f\\d]{12}$"); - } else if (blobTypes.contains(entityType)) { + } else if (ZDLParser.blobTypes.contains(entityType)) { property.put("type", "string"); property.put("format", "binary"); } else { property.put("type", "string"); } + if (property.get("initialValue") != null) { + property.put("default", property.get("initialValue")); + } return property; } diff --git a/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/parsers/ZDLParser.java b/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/parsers/ZDLParser.java index 9e339da0..f3f76071 100644 --- a/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/parsers/ZDLParser.java +++ b/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/parsers/ZDLParser.java @@ -10,7 +10,7 @@ public class ZDLParser implements Parser { - public static final List blobTypes = List.of("Blob", "AnyBlob", "ImageBlob"); + public static final List blobTypes = List.of("Blob", "AnyBlob", "ImageBlob", "byte"); @DocumentedOption(description = "ZDL files to parse") public String[] specFiles; diff --git a/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/utils/JSONPath.java b/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/utils/JSONPath.java index 64eeee9f..3d77e457 100644 --- a/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/utils/JSONPath.java +++ b/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/utils/JSONPath.java @@ -18,6 +18,7 @@ public static T get(Object object, String jsonPath) { return null; } try { + jsonPath = escapeByteArrayType(jsonPath); return (T) JsonPath.using(config).parse(object).read(jsonPath); } catch (PathNotFoundException e) { return null; @@ -41,6 +42,7 @@ public static T get(Object object, String jsonPath, T defaultIfNull) { return null; } try { + jsonPath = escapeByteArrayType(jsonPath); return ObjectUtils.firstNonNull(JsonPath.using(config).parse(object).read(jsonPath), defaultIfNull); } catch (PathNotFoundException e) { return defaultIfNull; @@ -69,4 +71,12 @@ public static void set(Object object, String jsonPath, Object value) { } JsonPath.parse(object).set(jsonPath, value); } + + /** 'byte[]' is a valid field type in ZDL so we need to test for it in 'entities', 'enums'... */ + private static String escapeByteArrayType(String jsonPath) { + if(jsonPath == null) { + return null; + } + return jsonPath.replace(".byte[]", "['byte[]']"); + } } diff --git a/zenwave-sdk-test-resources/src/main/resources/io/zenwave360/sdk/resources/zdl/customer-address.zdl b/zenwave-sdk-test-resources/src/main/resources/io/zenwave360/sdk/resources/zdl/customer-address.zdl index c99a5471..a6b2184c 100644 --- a/zenwave-sdk-test-resources/src/main/resources/io/zenwave360/sdk/resources/zdl/customer-address.zdl +++ b/zenwave-sdk-test-resources/src/main/resources/io/zenwave360/sdk/resources/zdl/customer-address.zdl @@ -83,7 +83,7 @@ service CustomerService for (Customer) { @get("/customers/{customerId}") getCustomer(id) Customer? - @get({path: "/customers", params: {search: "string"}}) + @get({path: "/customers", params: {search: String}}) @paginated listCustomers() Customer[] diff --git a/zenwave-sdk-test-resources/src/main/resources/io/zenwave360/sdk/resources/zdl/order-faults-attachments-model.zdl b/zenwave-sdk-test-resources/src/main/resources/io/zenwave360/sdk/resources/zdl/order-faults-attachments-model.zdl index ee6bdb8c..c3bda63e 100644 --- a/zenwave-sdk-test-resources/src/main/resources/io/zenwave360/sdk/resources/zdl/order-faults-attachments-model.zdl +++ b/zenwave-sdk-test-resources/src/main/resources/io/zenwave360/sdk/resources/zdl/order-faults-attachments-model.zdl @@ -20,6 +20,7 @@ entity PurchaseOrder { // Order is a reserved word mimetype String url String orderLineIds String[] + @transient contents byte[] } } From 39da02ae809bd3cf40b4cc52b58873622e9f99ae Mon Sep 17 00:00:00 2001 From: Ivan Garcia Sainz-Aja Date: Sat, 24 Feb 2024 14:19:59 +0100 Subject: [PATCH 3/7] - reviews package imports in templates. --- .../main/java/adapters/web/mvc/EntityResource.java.hbs | 8 ++++---- .../src/main/java/core/domain/common/Enum.java.hbs | 2 +- .../src/main/java/core/domain/jpa/Entity.java.hbs | 2 +- .../src/main/java/core/domain/mongodb/Entity.java.hbs | 2 +- .../src/main/java/core/domain/vo/Entity.java.hbs | 2 +- .../implementation/jpa/imperative/ServiceImpl.java.hbs | 2 +- .../core/implementation/mappers/ServiceMapper.java.hbs | 4 ++-- .../mongodb/imperative/ServiceImpl.java.hbs | 2 +- .../src/main/java/core/inbound/Service.java.hbs | 6 +++--- .../java/core/inbound/dtos/EntityCriteria.java.hbs | 4 ++-- .../main/java/core/inbound/dtos/EntityInput.java.hbs | 4 ++-- .../src/main/java/core/inbound/dtos/Enum.java.hbs | 2 +- .../main/java/core/inbound/dtos/InputOrOutput.java.hbs | 4 ++-- .../main/java/core/inbound/dtos/package-info.java.hbs | 2 +- .../src/main/java/infrastructure/package-info.java.hbs | 2 +- .../java/config/RepositoriesInMemoryConfig.java.hbs | 2 +- .../test/java/config/ServicesInMemoryConfig.java.hbs | 2 +- .../implementation/jpa/imperative/ServiceTest.java.hbs | 10 +++++----- .../mongodb/imperative/ServiceTest.java.hbs | 10 +++++----- .../imperative/BaseRepositoryIntegrationTest.java.hbs | 2 +- .../EntityRepositoryIntegrationTest.java.hbs | 4 ++-- .../inmemory/EntityRepositoryInMemory.java.hbs | 4 ++-- .../imperative/inmemory/InMemoryJpaRepository.java.hbs | 2 +- .../imperative/BaseRepositoryIntegrationTest.java.hbs | 2 +- .../EntityRepositoryIntegrationTest.java.hbs | 4 ++-- .../inmemory/EntityRepositoryInMemory.java.hbs | 4 ++-- .../inmemory/InMemoryMongodbRepository.java.hbs | 2 +- 27 files changed, 48 insertions(+), 48 deletions(-) diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/adapters/web/mvc/EntityResource.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/adapters/web/mvc/EntityResource.java.hbs index e501b257..fc51aaf3 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/adapters/web/mvc/EntityResource.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/adapters/web/mvc/EntityResource.java.hbs @@ -1,8 +1,8 @@ -package {{basePackage}}.adapters.web; +package {{adaptersPackage}}.web; -import {{basePackage}}.core.domain.*; -import {{basePackage}}.core.inbound.*; -import {{basePackage}}.core.inbound.dtos.*; +import {{entitiesPackage}}.*; +import {{inboundPackage}}.*; +import {{inboundDtosPackage}}.*; import java.net.URI; import java.net.URISyntaxException; diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/common/Enum.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/common/Enum.java.hbs index d1206ebb..16380710 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/common/Enum.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/common/Enum.java.hbs @@ -1,4 +1,4 @@ -package {{basePackage}}.core.domain; +package {{entitiesPackage}}; /** * Enum for {{defaultIfEmpty enum.description enum.name}}. diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/Entity.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/Entity.java.hbs index edef7c09..f1ffff2a 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/Entity.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/Entity.java.hbs @@ -1,4 +1,4 @@ -package {{basePackage}}.core.domain; +package {{entitiesPackage}}; import java.io.Serializable; import java.math.*; diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/mongodb/Entity.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/mongodb/Entity.java.hbs index 6e84577c..ee6c6cb6 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/mongodb/Entity.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/mongodb/Entity.java.hbs @@ -1,4 +1,4 @@ -package {{basePackage}}.core.domain; +package {{entitiesPackage}}; import java.io.Serializable; import java.math.*; diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/vo/Entity.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/vo/Entity.java.hbs index 975231f0..6dd02843 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/vo/Entity.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/vo/Entity.java.hbs @@ -1,4 +1,4 @@ -package {{basePackage}}.core.domain; +package {{entitiesPackage}}; import java.io.Serializable; import java.math.*; diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/implementation/jpa/imperative/ServiceImpl.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/implementation/jpa/imperative/ServiceImpl.java.hbs index e3e2836d..a0e604af 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/implementation/jpa/imperative/ServiceImpl.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/implementation/jpa/imperative/ServiceImpl.java.hbs @@ -1,4 +1,4 @@ -package {{basePackage}}.core.implementation; +package {{coreImplementationPackage}}; import {{entitiesPackage}}.*; import {{inboundPackage}}.*; diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/implementation/mappers/ServiceMapper.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/implementation/mappers/ServiceMapper.java.hbs index 6f347954..d9196d6b 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/implementation/mappers/ServiceMapper.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/implementation/mappers/ServiceMapper.java.hbs @@ -1,7 +1,7 @@ package {{coreImplementationPackage}}.mappers; -import {{basePackage}}.core.domain.*; -import {{basePackage}}.core.inbound.dtos.*; +import {{entitiesPackage}}.*; +import {{inboundDtosPackage}}.*; import org.mapstruct.AfterMapping; import java.util.List; diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/implementation/mongodb/imperative/ServiceImpl.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/implementation/mongodb/imperative/ServiceImpl.java.hbs index 3b06bd5a..42622290 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/implementation/mongodb/imperative/ServiceImpl.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/implementation/mongodb/imperative/ServiceImpl.java.hbs @@ -1,4 +1,4 @@ -package {{basePackage}}.core.implementation; +package {{coreImplementationPackage}}; import {{entitiesPackage}}.*; import {{inboundPackage}}.*; diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/Service.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/Service.java.hbs index 69e60039..acbb0f34 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/Service.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/Service.java.hbs @@ -1,7 +1,7 @@ -package {{basePackage}}.core.inbound; +package {{inboundPackage}}; -import {{basePackage}}.core.domain.*; -import {{basePackage}}.core.inbound.dtos.*; +import {{entitiesPackage}}.*; +import {{inboundDtosPackage}}.*; import java.math.*; import java.time.*; import java.util.*; diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/dtos/EntityCriteria.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/dtos/EntityCriteria.java.hbs index 8ebe1eb1..ddc4e1ca 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/dtos/EntityCriteria.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/dtos/EntityCriteria.java.hbs @@ -1,6 +1,6 @@ -package {{basePackage}}.core.inbound.dtos; +package {{inboundDtosPackage}}; -import {{basePackage}}.core.domain.*; +import {{entitiesPackage}}.*; import java.io.Serializable; import java.math.*; import java.time.*; diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/dtos/EntityInput.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/dtos/EntityInput.java.hbs index e48d7ff1..9de063ce 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/dtos/EntityInput.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/dtos/EntityInput.java.hbs @@ -1,6 +1,6 @@ -package {{basePackage}}.core.inbound.dtos; +package {{inboundDtosPackage}}; -import {{basePackage}}.core.domain.*; +import {{entitiesPackage}}.*; import java.io.Serializable; import java.math.*; import java.time.*; diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/dtos/Enum.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/dtos/Enum.java.hbs index 116bb2f3..c193c842 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/dtos/Enum.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/dtos/Enum.java.hbs @@ -1,4 +1,4 @@ -package {{basePackage}}.core.inbound.dtos; +package {{inboundDtosPackage}}; /** * Enum for {{defaultIfEmpty enum.description enum.name}}. diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/dtos/InputOrOutput.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/dtos/InputOrOutput.java.hbs index b0b35d1a..aad8510c 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/dtos/InputOrOutput.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/dtos/InputOrOutput.java.hbs @@ -1,6 +1,6 @@ -package {{basePackage}}.core.inbound.dtos; +package {{inboundDtosPackage}}; -import {{basePackage}}.core.domain.*; +import {{entitiesPackage}}.*; import java.io.Serializable; import java.math.*; import java.time.*; diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/dtos/package-info.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/dtos/package-info.java.hbs index f93b7a3e..c3074969 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/dtos/package-info.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/dtos/package-info.java.hbs @@ -1,6 +1,6 @@ /** Inbound DTOs. */ @keep -package {{basePackage}}.core.inbound.dtos; +package {{inboundDtosPackage}}; @interface keep { // keeps this package even when it's empty, // allowing wildcard import "{{basePackage}}.core.inbound.dtos.*;" diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/infrastructure/package-info.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/infrastructure/package-info.java.hbs index 69acedcc..595d1db5 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/infrastructure/package-info.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/infrastructure/package-info.java.hbs @@ -1,4 +1,4 @@ /** * Infrastructure classes, implementing {@link {{basePackage}}.core.outbound} interfaces. */ -package {{basePackage}}.infrastructure; +package {{infrastructurePackage}}; diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/config/RepositoriesInMemoryConfig.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/config/RepositoriesInMemoryConfig.java.hbs index a66586bc..4f57c970 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/config/RepositoriesInMemoryConfig.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/config/RepositoriesInMemoryConfig.java.hbs @@ -4,7 +4,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Primary; import {{basePackage}}.core.outbound.{{persistence}}.*; -import {{basePackage}}.infrastructure.{{persistence}}.inmemory.*; +import {{infrastructurePackage}}.{{persistence}}.inmemory.*; //@Configuration diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/config/ServicesInMemoryConfig.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/config/ServicesInMemoryConfig.java.hbs index ae2899ce..df0796cd 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/config/ServicesInMemoryConfig.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/config/ServicesInMemoryConfig.java.hbs @@ -1,7 +1,7 @@ package {{basePackage}}.config; {{#if services}} -import {{basePackage}}.core.implementation.*; +import {{coreImplementationPackage}}.*; {{/if}} {{#if includeEmitEventsImplementation}} import {{outboundEventsPackage}}.*; diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/core/implementation/jpa/imperative/ServiceTest.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/core/implementation/jpa/imperative/ServiceTest.java.hbs index 1f6a5ce8..43b5037a 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/core/implementation/jpa/imperative/ServiceTest.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/core/implementation/jpa/imperative/ServiceTest.java.hbs @@ -1,12 +1,12 @@ -package {{basePackage}}.core.implementation; +package {{coreImplementationPackage}}; import {{basePackage}}.config.*; -import {{basePackage}}.core.domain.*; -import {{basePackage}}.core.inbound.*; -import {{basePackage}}.core.inbound.dtos.*; +import {{entitiesPackage}}.*; +import {{inboundPackage}}.*; +import {{inboundDtosPackage}}.*; import {{basePackage}}.core.implementation.mappers.*; import {{basePackage}}.core.outbound.jpa.*; -import {{basePackage}}.infrastructure.jpa.inmemory.*; +import {{infrastructurePackage}}.jpa.inmemory.*; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.MethodOrderer; diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/core/implementation/mongodb/imperative/ServiceTest.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/core/implementation/mongodb/imperative/ServiceTest.java.hbs index 12323a4c..c9b40792 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/core/implementation/mongodb/imperative/ServiceTest.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/core/implementation/mongodb/imperative/ServiceTest.java.hbs @@ -1,12 +1,12 @@ -package {{basePackage}}.core.implementation; +package {{coreImplementationPackage}}; import {{basePackage}}.config.*; -import {{basePackage}}.core.domain.*; -import {{basePackage}}.core.inbound.*; -import {{basePackage}}.core.inbound.dtos.*; +import {{entitiesPackage}}.*; +import {{inboundPackage}}.*; +import {{inboundDtosPackage}}.*; import {{basePackage}}.core.implementation.mappers.*; import {{basePackage}}.core.outbound.mongodb.*; -import {{basePackage}}.infrastructure.mongodb.inmemory.*; +import {{infrastructurePackage}}.mongodb.inmemory.*; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.MethodOrderer; diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/jpa/imperative/BaseRepositoryIntegrationTest.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/jpa/imperative/BaseRepositoryIntegrationTest.java.hbs index 9f54d44a..14d173c5 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/jpa/imperative/BaseRepositoryIntegrationTest.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/jpa/imperative/BaseRepositoryIntegrationTest.java.hbs @@ -1,4 +1,4 @@ -package {{basePackage}}.infrastructure.jpa; +package {{infrastructurePackage}}.jpa; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/jpa/imperative/EntityRepositoryIntegrationTest.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/jpa/imperative/EntityRepositoryIntegrationTest.java.hbs index 215e5d68..7568d6b2 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/jpa/imperative/EntityRepositoryIntegrationTest.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/jpa/imperative/EntityRepositoryIntegrationTest.java.hbs @@ -1,10 +1,10 @@ -package {{basePackage}}.infrastructure.jpa; +package {{infrastructurePackage}}.jpa; import java.util.HashSet; import java.time.*; import java.math.BigDecimal; -import {{basePackage}}.core.domain.*; +import {{entitiesPackage}}.*; import {{basePackage}}.core.outbound.jpa.{{entity.className}}Repository; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/jpa/imperative/inmemory/EntityRepositoryInMemory.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/jpa/imperative/inmemory/EntityRepositoryInMemory.java.hbs index 191cf4f4..38bc493d 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/jpa/imperative/inmemory/EntityRepositoryInMemory.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/jpa/imperative/inmemory/EntityRepositoryInMemory.java.hbs @@ -1,6 +1,6 @@ -package {{basePackage}}.infrastructure.jpa.inmemory; +package {{infrastructurePackage}}.jpa.inmemory; -import {{basePackage}}.core.domain.*; +import {{entitiesPackage}}.*; import {{basePackage}}.core.outbound.jpa.{{entity.className}}Repository; public class {{entity.className}}RepositoryInMemory extends InMemoryJpaRepository<{{entity.className}}> implements {{entity.className}}Repository { diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/jpa/imperative/inmemory/InMemoryJpaRepository.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/jpa/imperative/inmemory/InMemoryJpaRepository.java.hbs index c58e5620..1657c4fd 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/jpa/imperative/inmemory/InMemoryJpaRepository.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/jpa/imperative/inmemory/InMemoryJpaRepository.java.hbs @@ -1,4 +1,4 @@ -package {{basePackage}}.infrastructure.jpa.inmemory; +package {{infrastructurePackage}}.jpa.inmemory; import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.data.domain.Example; diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/mongodb/imperative/BaseRepositoryIntegrationTest.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/mongodb/imperative/BaseRepositoryIntegrationTest.java.hbs index 2ac4dcb2..cfce3868 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/mongodb/imperative/BaseRepositoryIntegrationTest.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/mongodb/imperative/BaseRepositoryIntegrationTest.java.hbs @@ -1,4 +1,4 @@ -package {{basePackage}}.infrastructure.mongodb; +package {{infrastructurePackage}}.mongodb; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/mongodb/imperative/EntityRepositoryIntegrationTest.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/mongodb/imperative/EntityRepositoryIntegrationTest.java.hbs index 07eb98db..c0a6482d 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/mongodb/imperative/EntityRepositoryIntegrationTest.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/mongodb/imperative/EntityRepositoryIntegrationTest.java.hbs @@ -1,6 +1,6 @@ -package {{basePackage}}.infrastructure.mongodb; +package {{infrastructurePackage}}.mongodb; -import {{basePackage}}.core.domain.*; +import {{entitiesPackage}}.*; import {{basePackage}}.core.outbound.mongodb.{{entity.className}}Repository; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/mongodb/imperative/inmemory/EntityRepositoryInMemory.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/mongodb/imperative/inmemory/EntityRepositoryInMemory.java.hbs index fa131ac6..afc6498d 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/mongodb/imperative/inmemory/EntityRepositoryInMemory.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/mongodb/imperative/inmemory/EntityRepositoryInMemory.java.hbs @@ -1,6 +1,6 @@ -package {{basePackage}}.infrastructure.mongodb.inmemory; +package {{infrastructurePackage}}.mongodb.inmemory; -import {{basePackage}}.core.domain.*; +import {{entitiesPackage}}.*; import {{basePackage}}.core.outbound.mongodb.{{entity.className}}Repository; public class {{entity.className}}RepositoryInMemory extends InMemoryMongodbRepository<{{entity.className}}> implements {{entity.className}}Repository { diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/mongodb/imperative/inmemory/InMemoryMongodbRepository.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/mongodb/imperative/inmemory/InMemoryMongodbRepository.java.hbs index dc11529c..2744e024 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/mongodb/imperative/inmemory/InMemoryMongodbRepository.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/mongodb/imperative/inmemory/InMemoryMongodbRepository.java.hbs @@ -1,4 +1,4 @@ -package {{basePackage}}.infrastructure.mongodb.inmemory; +package {{infrastructurePackage}}.mongodb.inmemory; import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.data.domain.Example; From 11045f131a1be0a0f1cc6368ab2f6c4ac387eaa3 Mon Sep 17 00:00:00 2001 From: Ivan Garcia Sainz-Aja Date: Sat, 24 Feb 2024 19:45:23 +0100 Subject: [PATCH 4/7] - supports OneToOne @MapsId - supports required relationships --- ...r-address-relational-one-to-one-map-id.zdl | 2 +- .../BackendApplicationDefaultHelpers.java | 4 ++ .../BackendApplicationDefaultJpaHelpers.java | 1 + .../BackendDefaultApplicationGenerator.java | 2 +- .../main/java/core/domain/jpa/Entity.java.hbs | 2 +- .../core/domain/jpa/partials/ManyToMany.hbs | 3 ++ .../core/domain/jpa/partials/ManyToOne.hbs | 3 ++ .../core/domain/jpa/partials/OneToMany.hbs | 3 ++ .../core/domain/jpa/partials/OneToOne.hbs | 12 ++++- .../java/core/domain/mongodb/Entity.java.hbs | 2 +- .../main/java/core/domain/vo/Entity.java.hbs | 2 +- .../core/inbound/dtos/EntityCriteria.java.hbs | 54 ------------------- .../core/inbound/dtos/EntityInput.java.hbs | 2 +- .../core/inbound/dtos/InputOrOutput.java.hbs | 2 +- ...ApplicationJpaImperativeGeneratorTest.java | 2 +- .../sdk/processors/ZDLProcessor.java | 1 + 16 files changed, 33 insertions(+), 64 deletions(-) delete mode 100644 plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/dtos/EntityCriteria.java.hbs diff --git a/e2e/src/test/resources/projects/customer-address-relational/customer-address-relational-one-to-one-map-id.zdl b/e2e/src/test/resources/projects/customer-address-relational/customer-address-relational-one-to-one-map-id.zdl index 49bf3dc7..ef07422a 100644 --- a/e2e/src/test/resources/projects/customer-address-relational/customer-address-relational-one-to-one-map-id.zdl +++ b/e2e/src/test/resources/projects/customer-address-relational/customer-address-relational-one-to-one-map-id.zdl @@ -65,7 +65,7 @@ entity Address { enum AddressType { HOME(1) /** home description */, WORK(1) /** work description */ } relationship OneToOne { - Customer{address} to @Id Address{customer} + Customer{address required} to @Id Address{customer} } diff --git a/plugins/backend-application-default/src/main/java/io/zenwave360/sdk/plugins/BackendApplicationDefaultHelpers.java b/plugins/backend-application-default/src/main/java/io/zenwave360/sdk/plugins/BackendApplicationDefaultHelpers.java index c5f1cbb8..c6abbbb4 100644 --- a/plugins/backend-application-default/src/main/java/io/zenwave360/sdk/plugins/BackendApplicationDefaultHelpers.java +++ b/plugins/backend-application-default/src/main/java/io/zenwave360/sdk/plugins/BackendApplicationDefaultHelpers.java @@ -321,6 +321,10 @@ public Object addExtends(Object entity, Options options) { return ""; }; + public String abstractClass(Map entity, Options options) { + return JSONPath.get(entity, "options.abstract", false)? " abstract " : ""; + } + public Object eventsProducerInterface(String serviceName, Options options) { return String.format("I%sEventsProducer", serviceName.replaceAll("(Service|UseCases)", "")); } diff --git a/plugins/backend-application-default/src/main/java/io/zenwave360/sdk/plugins/BackendApplicationDefaultJpaHelpers.java b/plugins/backend-application-default/src/main/java/io/zenwave360/sdk/plugins/BackendApplicationDefaultJpaHelpers.java index 36771890..39cd042b 100644 --- a/plugins/backend-application-default/src/main/java/io/zenwave360/sdk/plugins/BackendApplicationDefaultJpaHelpers.java +++ b/plugins/backend-application-default/src/main/java/io/zenwave360/sdk/plugins/BackendApplicationDefaultJpaHelpers.java @@ -41,4 +41,5 @@ public List findOwnedOneToManyRelationships(Map entity, Options options) { }) .collect(Collectors.toList()); } + } diff --git a/plugins/backend-application-default/src/main/java/io/zenwave360/sdk/plugins/BackendDefaultApplicationGenerator.java b/plugins/backend-application-default/src/main/java/io/zenwave360/sdk/plugins/BackendDefaultApplicationGenerator.java index 721e9af2..a9612497 100644 --- a/plugins/backend-application-default/src/main/java/io/zenwave360/sdk/plugins/BackendDefaultApplicationGenerator.java +++ b/plugins/backend-application-default/src/main/java/io/zenwave360/sdk/plugins/BackendDefaultApplicationGenerator.java @@ -92,7 +92,7 @@ protected boolean is(Map model, String... annotations) { } protected Function, Boolean> skipEntityRepository = (model) -> !is(model, "aggregate"); - protected Function, Boolean> skipEntityId = (model) -> is(model, "embedded", "vo", "input", "isSuperClass"); + protected Function, Boolean> skipEntityId = (model) -> is(model, "embedded", "vo", "input", "abstract"); protected Function, Boolean> skipEntity = (model) -> is(model, "vo", "input"); protected Function, Boolean> skipEntityInput = (model) -> inputDTOSuffix == null || inputDTOSuffix.isEmpty(); diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/Entity.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/Entity.java.hbs index f1ffff2a..9c0355ca 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/Entity.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/Entity.java.hbs @@ -32,7 +32,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener; @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) {{~/if}} {{~#if entity.options.auditing}}@EntityListeners(AuditingEntityListener.class){{~/if}} -public class {{entity.className}} {{addExtends entity}} implements Serializable { +public {{abstractClass entity}} class {{entity.className}} {{addExtends entity}} implements Serializable { @java.io.Serial private static final long serialVersionUID = 1L; diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/partials/ManyToMany.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/partials/ManyToMany.hbs index 143795d2..0a2a882a 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/partials/ManyToMany.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/partials/ManyToMany.hbs @@ -1,5 +1,8 @@ @ManyToMany{{#if relationship.ownerSide}}(cascade = CascadeType.ALL){{else}}(mappedBy = "{{relationship.otherEntityFieldName}}"){{/if}} {{~#if relationship.ownerSide}} + {{~#if relationship.required}} +@NotNull + {{~/if}} @JoinTable(name = "{{snakeCase (concat entity.name relationship.otherEntityName)}}", joinColumns = @JoinColumn(name = "{{snakeCase (concat entity.name '_id')}}", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "{{snakeCase (concat relationship.otherEntityName '_id')}}", referencedColumnName = "id")) diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/partials/ManyToOne.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/partials/ManyToOne.hbs index 7211c3b2..2cad0d19 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/partials/ManyToOne.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/partials/ManyToOne.hbs @@ -2,5 +2,8 @@ @ManyToOne({{#if (addRelationshipById relationship entity=entity)}}fetch = FetchType.LAZY{{else}}cascade = CascadeType.ALL{{/if}}) @JoinColumn(name = "{{snakeCase relationship.fieldName}}_id"{{#if (addRelationshipById relationship entity=entity)}}, updatable = false, insertable = false{{/if}}) {{else}} + {{~#if relationship.required}} +@NotNull + {{~/if}} @OneToMany(mappedBy="{{relationship.otherEntityFieldName}}", fetch = FetchType.LAZY) {{/if}} diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/partials/OneToMany.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/partials/OneToMany.hbs index d946ead1..bc66759c 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/partials/OneToMany.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/partials/OneToMany.hbs @@ -1,4 +1,7 @@ {{#if relationship.ownerSide}} + {{~#if relationship.required}} +@NotNull + {{~/if}} @OneToMany(mappedBy = "{{relationship.otherEntityFieldName}}"{{#if entity.options.aggregate}}, cascade = CascadeType.ALL, orphanRemoval = true{{/if}}) {{else}} @ManyToOne(fetch = FetchType.LAZY) diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/partials/OneToOne.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/partials/OneToOne.hbs index 2fa57d38..80cc51ca 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/partials/OneToOne.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/partials/OneToOne.hbs @@ -1,7 +1,15 @@ {{#if relationship.ownerSide }} -@OneToOne{{#if entity.options.aggregate}}(cascade = CascadeType.ALL, orphanRemoval = true){{/if}} +@OneToOne(fetch = FetchType.LAZY {{#if entity.options.aggregate}}, cascade = CascadeType.ALL, orphanRemoval = true{{/if}}) + {{~#if relationship.required}} +@NotNull + {{~/if}} + {{~#if relationship.mapsId}} +@MapsId +@JoinColumn(name = "id") + {{~else}} @JoinColumn(unique = true) + {{/if~}} {{~else~}} -@OneToOne(mappedBy = "{{relationship.otherEntityFieldName}}"{{#if entity.options.aggregate}}, cascade = CascadeType.ALL, orphanRemoval = true{{/if}}) +@OneToOne(mappedBy = "{{relationship.otherEntityFieldName}}", fetch = FetchType.LAZY {{#if entity.options.aggregate}}, cascade = CascadeType.ALL, orphanRemoval = true{{/if}}) {{/if~}} diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/mongodb/Entity.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/mongodb/Entity.java.hbs index ee6c6cb6..336a1464 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/mongodb/Entity.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/mongodb/Entity.java.hbs @@ -24,7 +24,7 @@ import org.springframework.data.annotation.LastModifiedDate; @lombok.Getter @lombok.Setter {{~/if}} {{#unless (skipEntityId entity)~}}@Document(collection = "{{entity.tableName}}"){{/unless~}} -public class {{entity.className}} {{addExtends entity}} implements Serializable { +public {{abstractClass entity}} class {{entity.className}} {{addExtends entity}} implements Serializable { @java.io.Serial private static final long serialVersionUID = 1L; diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/vo/Entity.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/vo/Entity.java.hbs index 6dd02843..7a9c41ec 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/vo/Entity.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/vo/Entity.java.hbs @@ -12,7 +12,7 @@ import jakarta.validation.constraints.*; {{~#if useLombok}} @lombok.Getter @lombok.Setter {{~/if}} -public class {{entity.className}} {{addExtends entity}} implements Serializable { +public {{abstractClass entity}} class {{entity.className}} {{addExtends entity}} implements Serializable { @java.io.Serial private static final long serialVersionUID = 1L; diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/dtos/EntityCriteria.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/dtos/EntityCriteria.java.hbs deleted file mode 100644 index ddc4e1ca..00000000 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/dtos/EntityCriteria.java.hbs +++ /dev/null @@ -1,54 +0,0 @@ -package {{inboundDtosPackage}}; - -import {{entitiesPackage}}.*; -import java.io.Serializable; -import java.math.*; -import java.time.*; -import java.util.*; -import jakarta.validation.constraints.*; - -/** - * - */ -{{~#if useLombok}} -@lombok.Getter @lombok.Setter -{{~/if}} -{{#assign "_criteriaClassName"}}{{criteriaClassName entity}}{{/assign}} -public class {{_criteriaClassName}} {{addExtends entity suffix=inputDTOSuffix}} implements Serializable { - -{{#with entity.options.searchCriteriaObject as |entity| }} - -{{#each entity.fields as |field|}} - {{#each field.validations as |validation|}} - // @{{validation.name}}("{{validation.value}}") - {{/each}} - {{#assign "typeSuffix"}}{{#if field.isEntity}}{{inputDTOSuffix}}{{/if}}{{/assign}} - private {{{fieldType field suffix=typeSuffix}}} {{field.name}}; -{{/each}} - -{{#each entity.fields as |field|}} - {{#assign "typeSuffix"}}{{#if field.isEntity}}{{inputDTOSuffix}}{{/if}}{{/assign}} - {{~#if field.isArray}} - public {{_criteriaClassName}} add{{capitalize field.name}}({{javaType field}}{{typeSuffix}} {{field.name}}) { - this.{{field.name}}.add({{field.name}}); - return this; - } - {{~/if}} -{{/each}} - -{{~#unless useLombok}} -{{#each entity.fields as |field|}} - {{#assign "typeSuffix"}}{{#if field.isEntity}}{{inputDTOSuffix}}{{/if}}{{/assign}} - public {{{fieldType field suffix=typeSuffix}}} get{{capitalize field.name}}() { - return {{field.name}}; - } - - public {{_criteriaClassName}} set{{capitalize field.name}}({{{fieldType field suffix=typeSuffix}}} {{field.name}}) { - this.{{field.name}} = {{field.name}}; - return this; - } -{{/each}} -{{~/unless}} - -{{/with}} -} diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/dtos/EntityInput.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/dtos/EntityInput.java.hbs index 9de063ce..cf3587b9 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/dtos/EntityInput.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/dtos/EntityInput.java.hbs @@ -13,7 +13,7 @@ import jakarta.validation.constraints.*; {{~#if useLombok}} @lombok.Getter @lombok.Setter {{~/if}} -public class {{entity.className}}{{inputDTOSuffix entity}} {{addExtends entity suffix=(inputDTOSuffix entity)}} implements Serializable { +public {{abstractClass entity}} class {{entity.className}}{{inputDTOSuffix entity}} {{addExtends entity suffix=(inputDTOSuffix entity)}} implements Serializable { {{#unless (skipEntityId entity)~}} private {{idJavaType}} id; diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/dtos/InputOrOutput.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/dtos/InputOrOutput.java.hbs index aad8510c..d3cee928 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/dtos/InputOrOutput.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/dtos/InputOrOutput.java.hbs @@ -13,7 +13,7 @@ import jakarta.validation.constraints.*; {{~#if useLombok}} @lombok.Getter @lombok.Setter {{~/if}} -public class {{entity.className}} {{addExtends entity}} implements Serializable { +public {{abstractClass entity}} class {{entity.className}} {{addExtends entity}} implements Serializable { {{#each entity.fields as |field|}} {{{fieldValidationAnnotations field}}} diff --git a/plugins/backend-application-default/src/test/java/io/zenwave360/sdk/plugins/BackendApplicationJpaImperativeGeneratorTest.java b/plugins/backend-application-default/src/test/java/io/zenwave360/sdk/plugins/BackendApplicationJpaImperativeGeneratorTest.java index f3bfda1b..186914fa 100644 --- a/plugins/backend-application-default/src/test/java/io/zenwave360/sdk/plugins/BackendApplicationJpaImperativeGeneratorTest.java +++ b/plugins/backend-application-default/src/test/java/io/zenwave360/sdk/plugins/BackendApplicationJpaImperativeGeneratorTest.java @@ -37,7 +37,7 @@ public static void tearDown() { public void test_generator_hexagonal_jpa() throws Exception { String targetFolder = "target/zdl/test_generator_hexagonal_jpa_customer_address"; Plugin plugin = new BackendApplicationDefaultPlugin() - .withSpecFile("classpath:io/zenwave360/sdk/resources/zdl/customer-address-relational.zdl") + .withSpecFile("C:\\Users\\IvanGarcia\\workspace\\zenwave\\zenwave-sdk\\e2e\\src\\test\\resources\\projects\\customer-address-relational\\customer-address-relational-one-to-one-map-id.zdl") .withTargetFolder(targetFolder) .withOption("basePackage", "io.zenwave360.example") .withOption("persistence", PersistenceType.jpa) diff --git a/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/processors/ZDLProcessor.java b/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/processors/ZDLProcessor.java index 6ccef795..96d925ea 100644 --- a/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/processors/ZDLProcessor.java +++ b/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/processors/ZDLProcessor.java @@ -119,6 +119,7 @@ protected Map buildRelationship(String entityName, Map relationship) { relationshipMap.put("entityName", from); relationshipMap.put("otherEntityName", to); relationshipMap.put("ownerSide", true); + relationshipMap.put("mapsId", JSONPath.get(relationship, "toOptions.Id", false)); relationshipMap.put("isCollection", relationship.get("type").toString().endsWith("Many")); if(relationship.get("injectedFieldInFrom") != null) { var fillInjectedFieldInFrom = StringUtils.replace((String) relationship.get("injectedFieldInFrom"), ")","").split("\\("); From 2ff82b76e405f4f89b4e4e155c5d2ebbd0047a02 Mon Sep 17 00:00:00 2001 From: Ivan Garcia Sainz-Aja Date: Sun, 3 Mar 2024 12:52:07 +0100 Subject: [PATCH 5/7] - supports @Async --- .../BackendApplicationDefaultHelpers.java | 3 + .../adapters/web/mvc/EntityResource.java.hbs | 118 ------------------ .../web/webflux/EntityResource.java.hbs | 0 .../jpa/imperative/ServiceImpl.java.hbs | 4 + .../mongodb/imperative/ServiceImpl.java.hbs | 4 + .../partials/jpaMethodAnnotations.hbs | 3 + .../implementation/partials/jpaMethodBody.hbs | 5 +- .../partials/mongodbMethodAnnotations.hbs | 4 + .../partials/mongodbMethodBody.hbs | 5 +- .../main/java/core/inbound/Service.java.hbs | 3 + .../web/mappers/ServiceDTOsMapper.java.hbs | 4 +- .../web/mvc/ServiceApiController.java.hbs | 8 +- .../web/mvc/ServiceApiControllerTest.java.hbs | 5 +- .../AbstractZDLProjectGenerator.java | 2 +- .../sdk/processors/ZDLProcessor.java | 18 +++ .../sdk/zdl/ZDLJavaSignatureUtils.java | 4 + .../sdk/processors/ZDLProcessorTest.java | 11 ++ .../sdk/templates/HandlebarsEngineTest.java | 1 + .../sdk/zdl/ZDLJavaSignatureUtilsTest.java | 2 +- .../sdk/templating/handlebars-test.hbs | 1 + .../io/zenwave360/sdk/zdl/async-methods.zdl | 14 +++ .../zdl/order-faults-attachments-model.zdl | 1 + 22 files changed, 90 insertions(+), 130 deletions(-) delete mode 100644 plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/adapters/web/mvc/EntityResource.java.hbs delete mode 100644 plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/adapters/web/webflux/EntityResource.java.hbs create mode 100644 zenwave-sdk-cli/src/test/resources/io/zenwave360/sdk/zdl/async-methods.zdl diff --git a/plugins/backend-application-default/src/main/java/io/zenwave360/sdk/plugins/BackendApplicationDefaultHelpers.java b/plugins/backend-application-default/src/main/java/io/zenwave360/sdk/plugins/BackendApplicationDefaultHelpers.java index c6abbbb4..c9be63e6 100644 --- a/plugins/backend-application-default/src/main/java/io/zenwave360/sdk/plugins/BackendApplicationDefaultHelpers.java +++ b/plugins/backend-application-default/src/main/java/io/zenwave360/sdk/plugins/BackendApplicationDefaultHelpers.java @@ -5,7 +5,9 @@ import io.zenwave360.sdk.utils.NamingUtils; import io.zenwave360.sdk.zdl.ZDLFindUtils; +import io.zenwave360.sdk.zdl.ZDLHttpUtils; import io.zenwave360.sdk.zdl.ZDLJavaSignatureUtils; +import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import com.github.jknack.handlebars.Options; @@ -14,6 +16,7 @@ import io.zenwave360.sdk.utils.JSONPath; import static io.zenwave360.sdk.utils.NamingUtils.asJavaTypeName; +import static java.lang.String.format; public class BackendApplicationDefaultHelpers { diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/adapters/web/mvc/EntityResource.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/adapters/web/mvc/EntityResource.java.hbs deleted file mode 100644 index fc51aaf3..00000000 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/adapters/web/mvc/EntityResource.java.hbs +++ /dev/null @@ -1,118 +0,0 @@ -package {{adaptersPackage}}.web; - -import {{entitiesPackage}}.*; -import {{inboundPackage}}.*; -import {{inboundDtosPackage}}.*; - -import java.net.URI; -import java.net.URISyntaxException; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import jakarta.validation.Valid; -import jakarta.validation.constraints.NotNull; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; - - -/** - * REST controller for managing {@link {{entity.className}} }. - */ -@RestController -@RequestMapping("/api") -public class {{entity.className}}Resource { - - private final Logger log = LoggerFactory.getLogger(getClass()); - - private static final String ENTITY_NAME = "{{entity.kebabCase}}"; - - {{#assign "serviceClassName"}}{{entity.options.service}}{{/assign}} - {{#assign "serviceInstance"}}{{uncapFirst serviceClassName}}{{/assign}} - private final {{serviceClassName}} {{serviceInstance}}; - - public {{entity.className}}Resource({{serviceClassName}} {{serviceInstance}}) { - this.{{serviceInstance}} = {{serviceInstance}}; - } - - /** - * {@code POST /{{entity.kebabCasePlural}} } : Create a new {{entity.instanceName}}. - * - * @param {{entity.instanceName}} the {{entity.instanceName}} to create. - * @return the {@link ResponseEntity} with status {@code 201 (Created)} and with body the new {{entity.instanceName}}, or with status {@code 400 (Bad Request)} if the {{entity.instanceName}} has already an ID. - * @throws URISyntaxException if the Location URI syntax is incorrect. - */ - @PostMapping("/{{entity.kebabCasePlural}}") - public ResponseEntity<{{entity.className}}> create{{entity.className}}(@Valid @RequestBody {{entity.className}}{{inputDTOSuffix}} {{entity.instanceName}}) throws URISyntaxException { - log.debug("REST request to create {{entity.className}}{{inputDTOSuffix}} : {}", {{entity.instanceName}}); - {{entity.className}} result = {{serviceInstance}}.create{{entity.className}}({{entity.instanceName}}); - return ResponseEntity - .created(new URI("/api/{{entity.kebabCase}}s/" + result.getId())) - .body(result); - } - - /** - * {@code PUT /{{entity.kebabCasePlural}}/:id} } : Updates an existing {{entity.instanceName}}. - * - * @param id the id of the {{entity.instanceName}} to save. - * @param {{entity.instanceName}} the {{entity.instanceName}} to update. - * @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated {{entity.instanceName}}, - * or with status {@code 400 (Bad Request)} if the {{entity.instanceName}} is not valid, - * or with status {@code 500 (Internal Server Error)} if the {{entity.instanceName}} couldn't be updated. - * @throws URISyntaxException if the Location URI syntax is incorrect. - */ - @PutMapping("/{{entity.kebabCasePlural}}/{id}") - public ResponseEntity<{{entity.className}}> update{{entity.className}}(@PathVariable(value = "id", required = false) final {{idJavaType}} id, @Valid @RequestBody {{entity.className}}{{inputDTOSuffix}} {{entity.instanceName}}) - throws URISyntaxException { - log.debug("REST request to update {{entity.className}} : {}, {}", id, {{entity.instanceName}}); - Optional<{{entity.className}}> result = {{serviceInstance}}.update{{entity.className}}(id, {{entity.instanceName}}); - return wrapOrNotFound(result); - } - - /** - * {@code GET /{{entity.kebabCasePlural}} } : get all the {{entity.instanceName}}s. - * - * @return the {@link ResponseEntity} with status {@code 200 (OK)} and the list of {{entity.instanceName}}s in body. - */ - @GetMapping("/{{entity.kebabCasePlural}}") - public Page<{{entity.className}}> list{{entity.classNamePlural}}(Pageable pageable) { - log.debug("REST request to get all {{entity.classNamePlural}}s"); - return {{serviceInstance}}.list{{entity.classNamePlural}}(pageable); - } - - /** - * {@code GET /{{entity.kebabCasePlural}}/:id} } : get the "id" {{entity.instanceName}}. - * - * @param id the id of the {{entity.instanceName}} to retrieve. - * @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the {{entity.instanceName}}, or with status {@code 404 (Not Found)}. - */ - @GetMapping("/{{entity.kebabCasePlural}}/{id}") - public ResponseEntity<{{entity.className}}> get{{entity.className}}(@PathVariable {{idJavaType}} id) { - log.debug("REST request to get {{entity.className}} : {}", id); - Optional<{{entity.className}}> {{entity.instanceName}} = {{serviceInstance}}.get{{entity.className}}(id); - return wrapOrNotFound({{entity.instanceName}}); - } - - /** - * {@code DELETE /{{entity.kebabCasePlural}}/:id} } : delete the "id" {{entity.instanceName}}. - * - * @param id the id of the {{entity.instanceName}} to delete. - * @return the {@link ResponseEntity} with status {@code 204 (NO_CONTENT)}. - */ - @DeleteMapping("/{{entity.kebabCasePlural}}/{id}") - public ResponseEntity delete{{entity.className}}(@PathVariable {{idJavaType}} id) { - log.debug("REST request to delete {{entity.className}} : {}", id); - {{serviceInstance}}.delete{{entity.className}}(id); - return ResponseEntity.noContent().build(); - } - - static ResponseEntity wrapOrNotFound(Optional maybeResponse) { - return maybeResponse - .map(response -> ResponseEntity.ok().body(response)) - .orElseThrow(() -> new org.springframework.web.server.ResponseStatusException(org.springframework.http.HttpStatus.NOT_FOUND)); - } -} diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/adapters/web/webflux/EntityResource.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/adapters/web/webflux/EntityResource.java.hbs deleted file mode 100644 index e69de29b..00000000 diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/implementation/jpa/imperative/ServiceImpl.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/implementation/jpa/imperative/ServiceImpl.java.hbs index a0e604af..cf4b2d77 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/implementation/jpa/imperative/ServiceImpl.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/implementation/jpa/imperative/ServiceImpl.java.hbs @@ -18,6 +18,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; +{{~#if (jsonPath service 'methods[*][?(@.options.async)]')}} +import java.util.concurrent.CompletableFuture; +import org.springframework.scheduling.annotation.Async; +{{~/if}} import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/implementation/mongodb/imperative/ServiceImpl.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/implementation/mongodb/imperative/ServiceImpl.java.hbs index 42622290..68a9c9ba 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/implementation/mongodb/imperative/ServiceImpl.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/implementation/mongodb/imperative/ServiceImpl.java.hbs @@ -17,6 +17,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; +{{~#if (jsonPath service 'methods[*][?(@.options.async)]')}} +import java.util.concurrent.CompletableFuture; +import org.springframework.scheduling.annotation.Async; +{{~/if}} import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/implementation/partials/jpaMethodAnnotations.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/implementation/partials/jpaMethodAnnotations.hbs index 54475e67..48206ca1 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/implementation/partials/jpaMethodAnnotations.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/implementation/partials/jpaMethodAnnotations.hbs @@ -10,3 +10,6 @@ @Transactional {{~/if}} {{~/each}} +{{~#if method.options.async}} + @Async{{#if (not (eq method.options.async true))}}("{{method.options.async}}"){{/if}} +{{~/if}} diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/implementation/partials/jpaMethodBody.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/implementation/partials/jpaMethodBody.hbs index 0d61b404..83f77d6d 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/implementation/partials/jpaMethodBody.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/implementation/partials/jpaMethodBody.hbs @@ -42,7 +42,10 @@ {{~#unless method.isCrudMethod}} {{!-- comes from helper isCrudMethod --}} {{~assign "entity" (methodEntity method)}} {{~assign "returnEntity" (methodReturnEntity method)}} - {{~#if (and entity method.paramId method.returnType method.returnTypeIsOptional)}} + {{~#if method.options.async}} + log.debug("Request {{method.name}}: {}", input); + {{#if method.returnType}}return CompletableFuture.completedFuture({{/if}} {{method.name}}Sync({{methodParametersCallSignature method}}){{#if method.returnType}}){{/if}}; + {{~else if (and entity method.paramId method.returnType method.returnTypeIsOptional)}} log.debug("Request {{method.name}}: {}", id); var {{entity.instanceName}} = {{entity.instanceName}}Repository.findById(id).map(existing{{entity.className}} -> { return {{asInstanceName service.name}}Mapper.update(existing{{entity.className}}, {{{mapperInputCallSignature method.parameter}}}); diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/implementation/partials/mongodbMethodAnnotations.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/implementation/partials/mongodbMethodAnnotations.hbs index 54475e67..003daa2c 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/implementation/partials/mongodbMethodAnnotations.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/implementation/partials/mongodbMethodAnnotations.hbs @@ -10,3 +10,7 @@ @Transactional {{~/if}} {{~/each}} +{{~#if method.options.async}} + @Async{{#if (not (eq method.options.async true))}}("{{method.options.async}}"){{/if}} +{{~/if}} + diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/implementation/partials/mongodbMethodBody.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/implementation/partials/mongodbMethodBody.hbs index e2c61b33..527922ca 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/implementation/partials/mongodbMethodBody.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/implementation/partials/mongodbMethodBody.hbs @@ -44,7 +44,10 @@ {{~#unless method.isCrudMethod}} {{!-- comes from helper isCrudMethod --}} {{~assign "entity" (methodEntity method)}} {{~assign "returnEntity" (methodReturnEntity method)}} - {{~#if (and entity method.returnType method.returnTypeIsArray)}} + {{~#if method.options.async}} + log.debug("Request {{method.name}}: {}", input); + {{#if method.returnType}}return CompletableFuture.completedFuture({{/if}} {{method.name}}Sync({{methodParametersCallSignature method}}){{#if method.returnType}}){{/if}}; + {{~else if (and entity method.returnType method.returnTypeIsArray)}} {{~#if method.parameter}} log.debug("Request {{method.name}}: {}", input); {{~else}} diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/Service.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/Service.java.hbs index acbb0f34..738058b0 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/Service.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/inbound/Service.java.hbs @@ -5,6 +5,9 @@ import {{inboundDtosPackage}}.*; import java.math.*; import java.time.*; import java.util.*; +{{~#if (jsonPath service 'methods[*][?(@.options.async)]')}} +import java.util.concurrent.CompletableFuture; +{{~/if}} import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; diff --git a/plugins/openapi-controllers/src/main/resources/io/zenwave360/sdk/plugins/OpenAPIControllersGenerator/src/main/java/web/mappers/ServiceDTOsMapper.java.hbs b/plugins/openapi-controllers/src/main/resources/io/zenwave360/sdk/plugins/OpenAPIControllersGenerator/src/main/java/web/mappers/ServiceDTOsMapper.java.hbs index e3f50a5a..521dd92c 100644 --- a/plugins/openapi-controllers/src/main/resources/io/zenwave360/sdk/plugins/OpenAPIControllersGenerator/src/main/java/web/mappers/ServiceDTOsMapper.java.hbs +++ b/plugins/openapi-controllers/src/main/resources/io/zenwave360/sdk/plugins/OpenAPIControllersGenerator/src/main/java/web/mappers/ServiceDTOsMapper.java.hbs @@ -6,7 +6,9 @@ import {{openApiModelPackage}}.*; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; -import java.util.List; +import java.math.*; +import java.time.*; +import java.util.*; import org.springframework.data.domain.Page; @Mapper(uses = BaseMapper.class) diff --git a/plugins/openapi-controllers/src/main/resources/io/zenwave360/sdk/plugins/OpenAPIControllersGenerator/src/main/java/web/mvc/ServiceApiController.java.hbs b/plugins/openapi-controllers/src/main/resources/io/zenwave360/sdk/plugins/OpenAPIControllersGenerator/src/main/java/web/mvc/ServiceApiController.java.hbs index 7430885b..2490d990 100644 --- a/plugins/openapi-controllers/src/main/resources/io/zenwave360/sdk/plugins/OpenAPIControllersGenerator/src/main/java/web/mvc/ServiceApiController.java.hbs +++ b/plugins/openapi-controllers/src/main/resources/io/zenwave360/sdk/plugins/OpenAPIControllersGenerator/src/main/java/web/mvc/ServiceApiController.java.hbs @@ -9,11 +9,9 @@ import {{controllersPackage}}.mappers.*; import java.net.URI; import java.net.URISyntaxException; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.List; -import java.util.Objects; -import java.util.Optional; +import java.math.*; +import java.time.*; +import java.util.*; import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; import org.mapstruct.factory.Mappers; diff --git a/plugins/openapi-controllers/src/main/resources/io/zenwave360/sdk/plugins/OpenAPIControllersGenerator/src/test/java/web/mvc/ServiceApiControllerTest.java.hbs b/plugins/openapi-controllers/src/main/resources/io/zenwave360/sdk/plugins/OpenAPIControllersGenerator/src/test/java/web/mvc/ServiceApiControllerTest.java.hbs index 71f354f5..dd1acfe4 100644 --- a/plugins/openapi-controllers/src/main/resources/io/zenwave360/sdk/plugins/OpenAPIControllersGenerator/src/test/java/web/mvc/ServiceApiControllerTest.java.hbs +++ b/plugins/openapi-controllers/src/main/resources/io/zenwave360/sdk/plugins/OpenAPIControllersGenerator/src/test/java/web/mvc/ServiceApiControllerTest.java.hbs @@ -9,8 +9,9 @@ import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.List; -import java.util.Optional; +import java.math.*; +import java.time.*; +import java.util.*; /** * Test controller for {{serviceName}}ApiController. diff --git a/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/generators/AbstractZDLProjectGenerator.java b/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/generators/AbstractZDLProjectGenerator.java index 4d843f77..78aa22c8 100644 --- a/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/generators/AbstractZDLProjectGenerator.java +++ b/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/generators/AbstractZDLProjectGenerator.java @@ -90,7 +90,7 @@ public List generate(Map contextModel) { } for (TemplateInput template : templates.allServicesTemplates) { - templateOutputList.addAll(generateTemplateOutput(contextModel, template, Map.of("services", servicesList))); + templateOutputList.addAll(generateTemplateOutput(contextModel, template, Map.of("services", servicesList, "entities", entities.values()))); } diff --git a/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/processors/ZDLProcessor.java b/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/processors/ZDLProcessor.java index 96d925ea..d83a887b 100644 --- a/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/processors/ZDLProcessor.java +++ b/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/processors/ZDLProcessor.java @@ -26,6 +26,7 @@ public Map process(Map contextModel) { } processServiceName(zdlModel); + processServiceAsyncMethods(zdlModel); contextModel = new ZDL2JDLProcessor().process(contextModel); // FIXME: why here in the middle of the process? @@ -55,6 +56,23 @@ public void processServiceName(Map zdlModel) { } } + public void processServiceAsyncMethods(Map zdlModel) { + var asyncMethods = JSONPath.get(zdlModel, "$.services[*].methods[*][?(@.options.async)]", List.of()); + for (Map asyncMethod : asyncMethods) { + Map service = JSONPath.get(zdlModel, "$.services." + asyncMethod.get("serviceName")); + var syncMethodName = asyncMethod.get("name") + "Sync"; + if(JSONPath.get(service, "$.methods." + syncMethodName) == null) { + var syncMethod = Maps.copy(asyncMethod); + syncMethod.put("name", syncMethodName); + ((Map)syncMethod.get("options")).remove("async"); + ((List)syncMethod.get("optionsList")).removeIf(o -> "async".equals(((Map)o).get("name"))); + ((Map)service.get("methods")).put(syncMethodName, syncMethod); + } else { + log.error("Error Processing @async({}) in {}. Method {} already defined.", asyncMethod.get("name"), asyncMethod.get("serviceName"), syncMethodName); + } + } + } + public void processCopyAnnotation(Map zdlModel) { var allEntities = new HashMap<>(); allEntities.putAll(JSONPath.get(zdlModel, "$.allEntitiesAndEnums")); diff --git a/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/zdl/ZDLJavaSignatureUtils.java b/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/zdl/ZDLJavaSignatureUtils.java index 3ddcb815..03401c82 100644 --- a/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/zdl/ZDLJavaSignatureUtils.java +++ b/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/zdl/ZDLJavaSignatureUtils.java @@ -114,6 +114,10 @@ public static String methodReturnType(Map method) { if(isOptional) { return String.format("Optional<%s>", returnType); } + var isAsync = JSONPath.get(method, "options.async") != null; + if(isAsync) { + return String.format("CompletableFuture<%s>", returnType); + } return (String) returnType; } diff --git a/zenwave-sdk-cli/src/test/java/io/zenwave360/sdk/processors/ZDLProcessorTest.java b/zenwave-sdk-cli/src/test/java/io/zenwave360/sdk/processors/ZDLProcessorTest.java index d2d64f43..ba23838a 100644 --- a/zenwave-sdk-cli/src/test/java/io/zenwave360/sdk/processors/ZDLProcessorTest.java +++ b/zenwave-sdk-cli/src/test/java/io/zenwave360/sdk/processors/ZDLProcessorTest.java @@ -29,4 +29,15 @@ public void testProcessZDL_CopyAnnotation() throws Exception { Assertions.assertTrue(customerEventFields.size() > 1); } + @Test + public void testProcessZDL_ProcessAsyncMethods() throws Exception { + var model = loadZDL("classpath:io/zenwave360/sdk/zdl/async-methods.zdl"); + var methods = JSONPath.get(model, "$.zdl.services.SomeEntityService.methods", Map.of()); + Assertions.assertNotNull(methods); + Assertions.assertEquals(4, methods.size()); + var syncMethods = JSONPath.get(model, "$.zdl.services.SomeEntityService.methods[*][?(!@.options.async)]", List.of()); + Assertions.assertNotNull(syncMethods); + Assertions.assertEquals(2, syncMethods.size()); + } + } diff --git a/zenwave-sdk-cli/src/test/java/io/zenwave360/sdk/templates/HandlebarsEngineTest.java b/zenwave-sdk-cli/src/test/java/io/zenwave360/sdk/templates/HandlebarsEngineTest.java index a4b69dcd..e1728589 100644 --- a/zenwave-sdk-cli/src/test/java/io/zenwave360/sdk/templates/HandlebarsEngineTest.java +++ b/zenwave-sdk-cli/src/test/java/io/zenwave360/sdk/templates/HandlebarsEngineTest.java @@ -34,6 +34,7 @@ public void testHandlebarsEngine() throws IOException { Assertions.assertTrue(templateOutput.getContent().contains("asJavaTypeName TratraTratra")); Assertions.assertTrue(templateOutput.getContent().contains("kebabCase some-camel-case-with-spaces")); Assertions.assertTrue(templateOutput.getContent().contains("asPackageFolder io/zenwave360/sdk/templating")); + Assertions.assertTrue(templateOutput.getContent().contains("jsonPath entity1")); Assertions.assertTrue(templateOutput.getContent().contains("Prefix2Suffix")); Assertions.assertTrue(templateOutput.getContent().contains("ifTruthy true: true")); Assertions.assertTrue(templateOutput.getContent().contains("ifTruthy false: false")); diff --git a/zenwave-sdk-cli/src/test/java/io/zenwave360/sdk/zdl/ZDLJavaSignatureUtilsTest.java b/zenwave-sdk-cli/src/test/java/io/zenwave360/sdk/zdl/ZDLJavaSignatureUtilsTest.java index 78d8812a..193a2c99 100644 --- a/zenwave-sdk-cli/src/test/java/io/zenwave360/sdk/zdl/ZDLJavaSignatureUtilsTest.java +++ b/zenwave-sdk-cli/src/test/java/io/zenwave360/sdk/zdl/ZDLJavaSignatureUtilsTest.java @@ -94,7 +94,7 @@ void methodReturnType() throws IOException { var model = loadZDL("classpath:io/zenwave360/sdk/resources/zdl/order-faults-attachments-model.zdl"); var method = JSONPath.get(model, "$.services.AttachmentService.methods.uploadFile", Map.of()); var returnType = ZDLJavaSignatureUtils.methodReturnType(method); - Assertions.assertEquals("PurchaseOrder", returnType); + Assertions.assertEquals("CompletableFuture", returnType); } @Test diff --git a/zenwave-sdk-cli/src/test/resources/io/zenwave360/sdk/templating/handlebars-test.hbs b/zenwave-sdk-cli/src/test/resources/io/zenwave360/sdk/templating/handlebars-test.hbs index de1e592d..cda96149 100644 --- a/zenwave-sdk-cli/src/test/resources/io/zenwave360/sdk/templating/handlebars-test.hbs +++ b/zenwave-sdk-cli/src/test/resources/io/zenwave360/sdk/templating/handlebars-test.hbs @@ -7,6 +7,7 @@ asInstanceName {{asInstanceName "tratra-tratra"}} asJavaTypeName {{asJavaTypeName "tratra-tratra"}} kebabCase {{kebabCase "Some Camel Case with Spaces"}} asPackageFolder {{asPackageFolder "io.zenwave360.sdk.templating"}} +jsonPath {{jsonPath entities "entity1.name"}} ifTruthy true: {{ifTruthy "true" "true" "false"}} ifTruthy false: {{ifTruthy "false" "true" "false"}} diff --git a/zenwave-sdk-cli/src/test/resources/io/zenwave360/sdk/zdl/async-methods.zdl b/zenwave-sdk-cli/src/test/resources/io/zenwave360/sdk/zdl/async-methods.zdl new file mode 100644 index 00000000..ad73dcee --- /dev/null +++ b/zenwave-sdk-cli/src/test/resources/io/zenwave360/sdk/zdl/async-methods.zdl @@ -0,0 +1,14 @@ + +@aggregate +entity SomeEntity { +} + +service SomeEntityService for (SomeEntity) { + + @async("asyncExecutor") + oneMethod(id, SomeEntity) + + @async("asyncExecutor") + anotherMethod(id, SomeEntity) SomeEntity + +} diff --git a/zenwave-sdk-test-resources/src/main/resources/io/zenwave360/sdk/resources/zdl/order-faults-attachments-model.zdl b/zenwave-sdk-test-resources/src/main/resources/io/zenwave360/sdk/resources/zdl/order-faults-attachments-model.zdl index c3bda63e..8485f651 100644 --- a/zenwave-sdk-test-resources/src/main/resources/io/zenwave360/sdk/resources/zdl/order-faults-attachments-model.zdl +++ b/zenwave-sdk-test-resources/src/main/resources/io/zenwave360/sdk/resources/zdl/order-faults-attachments-model.zdl @@ -36,6 +36,7 @@ enum OrderFaultType { TIME, QUALITY } @rest("/order-attachments") service AttachmentService for (PurchaseOrder) { + @async("asyncExecutor") @post("/{businessUnit}/{orderId}") uploadFile(PurchaseOrder) PurchaseOrder From 0f885495d0a4f3bceaabac28335607310ac3e17c Mon Sep 17 00:00:00 2001 From: Ivan Garcia Sainz-Aja Date: Sun, 3 Mar 2024 13:10:16 +0100 Subject: [PATCH 6/7] zdl-jvm.version = 1.0.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c1dbd80a..fb7dacea 100644 --- a/pom.xml +++ b/pom.xml @@ -69,7 +69,7 @@ 0.10.2 4.3.1 0.8.4 - 1.1.0-SNAPSHOT + 1.0.1 19.2 1.7 2.38.0 From c31fa86640a75748a5c1726c20dbbff28b26f4bf Mon Sep 17 00:00:00 2001 From: Ivan Garcia Sainz-Aja Date: Sun, 3 Mar 2024 21:34:06 +0100 Subject: [PATCH 7/7] fixes specFile in test --- .../plugins/BackendApplicationJpaImperativeGeneratorTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/backend-application-default/src/test/java/io/zenwave360/sdk/plugins/BackendApplicationJpaImperativeGeneratorTest.java b/plugins/backend-application-default/src/test/java/io/zenwave360/sdk/plugins/BackendApplicationJpaImperativeGeneratorTest.java index 186914fa..f3bfda1b 100644 --- a/plugins/backend-application-default/src/test/java/io/zenwave360/sdk/plugins/BackendApplicationJpaImperativeGeneratorTest.java +++ b/plugins/backend-application-default/src/test/java/io/zenwave360/sdk/plugins/BackendApplicationJpaImperativeGeneratorTest.java @@ -37,7 +37,7 @@ public static void tearDown() { public void test_generator_hexagonal_jpa() throws Exception { String targetFolder = "target/zdl/test_generator_hexagonal_jpa_customer_address"; Plugin plugin = new BackendApplicationDefaultPlugin() - .withSpecFile("C:\\Users\\IvanGarcia\\workspace\\zenwave\\zenwave-sdk\\e2e\\src\\test\\resources\\projects\\customer-address-relational\\customer-address-relational-one-to-one-map-id.zdl") + .withSpecFile("classpath:io/zenwave360/sdk/resources/zdl/customer-address-relational.zdl") .withTargetFolder(targetFolder) .withOption("basePackage", "io.zenwave360.example") .withOption("persistence", PersistenceType.jpa)