Skip to content

Commit

Permalink
Merge pull request #26 from ZenWave360/develop
Browse files Browse the repository at this point in the history
Release 1.4.2
  • Loading branch information
ivangsa authored Mar 3, 2024
2 parents ddbc4dd + c31fa86 commit 7470440
Show file tree
Hide file tree
Showing 68 changed files with 295 additions and 260 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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()
Expand Down
2 changes: 1 addition & 1 deletion plugins/backend-application-default/README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand Down Expand Up @@ -251,6 +254,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 "";
Expand Down Expand Up @@ -318,6 +324,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)", ""));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ public List<Map> findOwnedOneToManyRelationships(Map entity, Options options) {
})
.collect(Collectors.toList());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected boolean is(Map<String, Object> model, String... annotations) {
}

protected Function<Map<String, Object>, Boolean> skipEntityRepository = (model) -> !is(model, "aggregate");
protected Function<Map<String, Object>, Boolean> skipEntityId = (model) -> is(model, "embedded", "vo", "input", "isSuperClass");
protected Function<Map<String, Object>, Boolean> skipEntityId = (model) -> is(model, "embedded", "vo", "input", "abstract");
protected Function<Map<String, Object>, Boolean> skipEntity = (model) -> is(model, "vo", "input");
protected Function<Map<String, Object>, Boolean> skipEntityInput = (model) -> inputDTOSuffix == null || inputDTOSuffix.isEmpty();

Expand Down

This file was deleted.

Empty file.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package {{basePackage}}.core.domain;
package {{entitiesPackage}};

/**
* Enum for {{defaultIfEmpty enum.description enum.name}}.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package {{basePackage}}.core.domain;
package {{entitiesPackage}};

import java.io.Serializable;
import java.math.*;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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}}

Expand Down
Original file line number Diff line number Diff line change
@@ -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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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~}}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package {{basePackage}}.core.domain;
package {{entitiesPackage}};

import java.io.Serializable;
import java.math.*;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package {{basePackage}}.core.domain;
package {{entitiesPackage}};

import java.io.Serializable;
import java.math.*;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package {{basePackage}}.core.implementation;
package {{coreImplementationPackage}};

import {{entitiesPackage}}.*;
import {{inboundPackage}}.*;
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package {{basePackage}}.core.implementation;
package {{coreImplementationPackage}};

import {{entitiesPackage}}.*;
import {{inboundPackage}}.*;
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
@Transactional
{{~/if}}
{{~/each}}
{{~#if method.options.async}}
@Async{{#if (not (eq method.options.async true))}}("{{method.options.async}}"){{/if}}
{{~/if}}
Original file line number Diff line number Diff line change
Expand Up @@ -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}}});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@
@Transactional
{{~/if}}
{{~/each}}
{{~#if method.options.async}}
@Async{{#if (not (eq method.options.async true))}}("{{method.options.async}}"){{/if}}
{{~/if}}

Loading

0 comments on commit 7470440

Please sign in to comment.