Skip to content

Commit

Permalink
some fixes for EDALearn
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangsa committed Jan 6, 2023
1 parent c149550 commit e80b4fb
Show file tree
Hide file tree
Showing 16 changed files with 48 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public enum TransactionalOutboxType {
@DocumentedOption(description = "SC Streams Binder class suffix")
public String consumerSuffix = "Consumer";

@DocumentedOption(description = "SC Streams Binding Name Prefix (used in @Component name)" )
public String bindingPrefix = "";

@DocumentedOption(description = "Business/Service interface prefix")
public String servicePrefix = "I";

Expand All @@ -71,6 +74,9 @@ public enum TransactionalOutboxType {
@DocumentedOption(description = "Spring bean id for the tracing id supplier for runtime header with expression: '$tracingIdSupplier'")
public String tracingIdSupplierQualifier = "tracingIdSupplier";

@DocumentedOption(description = "Include Kafka common headers 'kafka_messageKey' as x-runtime-header")
private boolean includeKafkaCommonHeaders = false;

private HandlebarsEngine handlebarsEngine = new HandlebarsEngine();
{
handlebarsEngine.getHandlebars().registerHelper("consumerName", (context, options) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {{modelPackage}}.*;

{{#assign "messageCount"}}{{size operation.x--messages}}{{/assign~}}

@Component("{{operation.x--operationIdKebabCase}}")
@Component("{{bindingPrefix}}{{operation.x--operationIdKebabCase}}")
@jakarta.annotation.Generated(value = "io.zenwave360.sdk.plugins.SpringCloudStreams3Plugin", date = "{{date}}")
public class {{consumerName operation.x--operationIdCamelCase}} implements Consumer<Message<{{messageType operation}}>> {

Expand All @@ -40,7 +40,7 @@ public class {{consumerName operation.x--operationIdCamelCase}} implements Consu
this.streamBridge = streamBridge;
}

@Value("#{${spring.cloud.stream.bindings.{{operation.x--operationIdKebabCase}}-in-0.dead-letter-queue-error-map:{:}}}")
@Value("#{${spring.cloud.stream.bindings.{{bindingPrefix}}{{operation.x--operationIdKebabCase}}-in-0.dead-letter-queue-error-map:{:}}}")
public void setErrorQueueMap(Map<Class<? extends Exception>, String> errorQueueMap) {
this.errorQueueMap = errorQueueMap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import reactor.core.publisher.Mono;
import {{modelPackage}}.*;
{{/if}}

@Component("{{operation.x--operationIdKebabCase}}")
@Component("{{bindingPrefix}}{{operation.x--operationIdKebabCase}}")
@jakarta.annotation.Generated(value = "io.zenwave360.sdk.plugins.SpringCloudStreams3Plugin", date = "{{date}}")
public class {{consumerName operation.x--operationIdCamelCase}} implements Consumer<Flux<Message<{{messageType operation}}>>> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class {{apiClassName}}Captor implements I{{apiClassName}} {
protected Logger log = LoggerFactory.getLogger(getClass());

{{~#each operations as |operation|}}
public String {{operation.operationId}}BindingName = "{{operation.x--operationIdKebabCase}}-out{{bindingSuffix}}";
public String {{operation.operationId}}BindingName = "{{bindingPrefix}}{{operation.x--operationIdKebabCase}}-out{{bindingSuffix}}";
{{~/each}}

{{> (partial '../partials/tracing-id-supplier')}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ import {{modelPackage}}.*;
/**
* {{asyncapi.description}}
*/
@Component
@Component("{{bindingPrefix}}{{apiClassName}}")
@jakarta.annotation.Generated(value = "io.zenwave360.sdk.plugins.SpringCloudStreams3Plugin", date = "{{date}}")
public class {{apiClassName}} implements I{{apiClassName}} {

private Logger log = LoggerFactory.getLogger(getClass());

public String sqlSaveMessageToOutbox = "INSERT INTO {tableName} (binding_name, type, payload, headers) VALUES (?, ?, ?, ?)";
{{~#each operations as |operation|}}
public String {{operation.operationId}}BindingName = "{{operation.x--operationIdKebabCase}}-out{{bindingSuffix}}";
public String {{operation.operationId}}BindingName = "{{bindingPrefix}}{{operation.x--operationIdKebabCase}}-out{{bindingSuffix}}";
public String {{operation.operationId}}OutboxTableName = "{{snakeCase operation.operationId}}_outbox";
{{~/each}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ import {{modelPackage}}.*;
/**
* {{asyncapi.description}}
*/
@Component
@Component("{{bindingPrefix}}{{apiClassName}}")
@jakarta.annotation.Generated(value = "io.zenwave360.sdk.plugins.SpringCloudStreams3Plugin", date = "{{date}}")
public class {{apiClassName}} implements I{{apiClassName}} {

private Logger log = LoggerFactory.getLogger(getClass());

{{~#each operations as |operation|}}
public String {{operation.operationId}}BindingName = "{{operation.x--operationIdKebabCase}}-out{{bindingSuffix}}";
public String {{operation.operationId}}BindingName = "{{bindingPrefix}}{{operation.x--operationIdKebabCase}}-out{{bindingSuffix}}";
public String {{operation.operationId}}OutboxCollection = {{operation.operationId}}BindingName;
{{~/each}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import {{modelPackage}}.*;
/**
* {{asyncapi.description}}
*/
@Component
@Component("{{bindingPrefix}}{{apiClassName}}")
@jakarta.annotation.Generated(value = "io.zenwave360.sdk.plugins.SpringCloudStreams3Plugin", date = "{{date}}")
public class {{apiClassName}} implements I{{apiClassName}} {

protected Logger log = LoggerFactory.getLogger(getClass());

protected StreamBridge streamBridge;
{{~#each operations as |operation|}}
public String {{operation.operationId}}BindingName = "{{operation.x--operationIdKebabCase}}-out{{bindingSuffix}}";
public String {{operation.operationId}}BindingName = "{{bindingPrefix}}{{operation.x--operationIdKebabCase}}-out{{bindingSuffix}}";
{{~/each}}

{{~#if useEnterpriseEnvelope}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import org.springframework.transaction.annotation.Transactional;
* Service Implementation for managing {{service.entityNames}}.
*/
@Service
@Transactional
@Transactional(readOnly = true)
public class {{service.name}}Impl implements {{service.name}} {

private final Logger log = LoggerFactory.getLogger(getClass());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{{~#each entities as |entity|}}
{{~#if (isCrudMethod 'create' method=method entity=entity )}}
@Transactional(readOnly = false)
@Transactional
{{~else if (isCrudMethod 'update' method=method entity=entity )}}
@Transactional(readOnly = false)
@Transactional
{{~else if (isCrudMethod 'list' method=method entity=entity )}}
{{~else if (isCrudMethod 'search' method=method entity=entity )}}
{{~else if (isCrudMethod 'get' method=method entity=entity )}}
{{~else if (isCrudMethod 'delete' method=method entity=entity )}}
@Transactional(readOnly = false)
@Transactional
{{~/if}}
{{~/each}}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
var page = {{entity.instanceName}}Repository.findAll(pageable);
return {{wrapWithMapper entity}};
{{~else if (isCrudMethod 'search' method=method entity=entity )}}
log.debug("Request to search {{entity.classNamePlural}}: {} - {}", criteria, pageable);
log.debug("Request to search {{entity.classNamePlural}}: {} - {}", input, pageable);
// TODO implement this search by criteria
var page = {{entity.instanceName}}Repository.findAll(pageable);
return {{wrapWithMapper entity}};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{{~#each entities as |entity|}}
{{~#if (isCrudMethod 'create' method=method entity=entity )}}
@Transactional(readOnly = false)
@Transactional
{{~else if (isCrudMethod 'update' method=method entity=entity )}}
@Transactional(readOnly = false)
@Transactional
{{~else if (isCrudMethod 'list' method=method entity=entity )}}
{{~else if (isCrudMethod 'search' method=method entity=entity )}}
{{~else if (isCrudMethod 'get' method=method entity=entity )}}
{{~else if (isCrudMethod 'delete' method=method entity=entity )}}
@Transactional(readOnly = false)
@Transactional
{{~/if}}
{{~/each}}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
var page = {{entity.instanceName}}Repository.findAll(pageable);
return {{wrapWithMapper entity}};
{{~else if (isCrudMethod 'search' method=method entity=entity )}}
log.debug("Request to search {{entity.classNamePlural}}: {} - {}", criteria, pageable);
log.debug("Request to search {{entity.classNamePlural}}: {} - {}", input, pageable);
// TODO implement this search by criteria
var page = {{entity.instanceName}}Repository.findAll(pageable);
return {{wrapWithMapper entity}};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public List<TemplateOutput> generate(Map<String, Object> contextModel) {
}
if (AsyncapiVersionType.v3.equals(asyncapiVersion)) {
buildEventChannel(event, channels);
buildEventOperation(method, withEvents, withEvent, model, operations);
buildEventOperation(method, withEvent, model, operations);
}

}
Expand Down Expand Up @@ -164,11 +164,10 @@ private void addAllEventsAsMessages(LinkedHashMap<Object, Object> allMessages, M
}
}

private void buildEventOperation(Map<String, Object> method, List<String> withEvents, String withEvent, Map<String, Object> model, Map<String, Object> operations) {
var operationId = "on" + asJavaTypeName((String) method.get("name"));
var operationIdSuffix = (withEvents.size() > 0? withEvent : "");
var channelName = JSONPath.get(model, "$.events." + withEvent + ".options.asyncapi.channel", withEvent + "Channel");
operations.put(operationId + operationIdSuffix, Map.of("action", "send","serviceName", method.get("serviceName"), "channel", channelName));
private void buildEventOperation(Map<String, Object> method, String eventName, Map<String, Object> model, Map<String, Object> operations) {
var operationId = "on" + asJavaTypeName(eventName);
var channelName = JSONPath.get(model, "$.events." + eventName + ".options.asyncapi.channel", eventName + "Channel");
operations.put(operationId, Map.of("action", "send","serviceName", method.get("serviceName"), "channel", channelName));
}

private void buildEventChannel(Map<String, Object> event, Map<String, Object> channels) {
Expand All @@ -186,6 +185,9 @@ private void buildEventChannel(Map<String, Object> event, Map<String, Object> ch
}

private void buildMethodCommand(Map method, Map<String, Object> channels, Map<String, Object> operations, Map<String, Object> model, LinkedHashMap<Object, Object> messages) {
if(isMethodCommandThirdPartyAPI(method, model)) {
return;
}
var operationId = JSONPath.get(method, "$.options.asyncapi.operationId", (String) null);
var commandName = firstNonNull(operationId, "do" + asJavaTypeName((String) method.get("name")));
var channelName = JSONPath.get(method, "$.options.asyncapi.channel", commandName + "Channel");
Expand All @@ -208,6 +210,12 @@ private void buildMethodCommand(Map method, Map<String, Object> channels, Map<St
operations.put(commandName, Maps.of("action", "receive", "serviceName", method.get("serviceName"), "channel", channelName));
}

private boolean isMethodCommandThirdPartyAPI(Map method, Map<String, Object> model) {
var api = JSONPath.get(method, "$.options.asyncapi.api", (String) null);
var role = JSONPath.get(model, "$.apis." + api + ".role");
return "client".equals(role);
}

private void buildCommandChannelV2(Map method, Map<String, Object> channels, Map<String, Object> model, LinkedHashMap<Object, Object> messages) {
var operationId = JSONPath.get(method, "$.options.asyncapi.operationId", "do" + asJavaTypeName((String) method.get("name")));
var channelName = JSONPath.get(method, "$.options.asyncapi.channel", operationId + "Channel");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ channels:
x-address: "{{channel.x-address}}"
{{~#each channel.operations as |operation|}}
{{@key}}:
summary: {{operation.summary}}
summary: "{{operation.summary}}"
operationId: {{operation.operationId}}
tags:
- name: {{asTagName operation.serviceName}}
Expand All @@ -39,8 +39,8 @@ components:
{{message.name}}Message:
messageId: {{message.name}}Message
name: {{message.name}}Message
title: {{message.summary}}
summary: {{message.summary}}
title: "{{message.summary}}"
summary: "{{message.summary}}"
schemaFormat: {{{schemaFormatString}}}
traits:
- $ref: '#/components/messageTraits/CommonHeaders'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ components:
{{message.name}}Message:
messageId: {{message.name}}Message
name: {{message.name}}Message
title: {{message.javadoc}}
summary: {{message.javadoc}}
title: "{{message.javadoc}}"
summary: "{{message.javadoc}}"
schemaFormat: {{{schemaFormatString}}}
traits:
- $ref: '#/components/messageTraits/CommonHeaders'
Expand All @@ -52,13 +52,15 @@ components:
headers:
type: object
properties:
{{~#if includeKafkaCommonHeaders}}
kafka_messageKey:
type: string
description: This header value will be populated automatically at runtime
x-runtime-expression: $message.payload#/id
{{~/if}}
tracingId:
type: string
description: This header value will be populated automatically at runtime
description: This header value will be populated automatically at runtime (when using ZenWave code generator)
x-runtime-expression: $tracingIdSupplier

{{{schemasAsString}}}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<reflections.version>0.10.2</reflections.version>
<handlebars-java.version>4.3.0</handlebars-java.version>
<json-schema-ref-parser-jvm.version>0.8.2</json-schema-ref-parser-jvm.version>
<zdl-jvm.version>0.9.3</zdl-jvm.version>
<zdl-jvm.version>0.9.4</zdl-jvm.version>
<graphql-java.version>19.2</graphql-java.version>
<google-java-format.version>1.7</google-java-format.version>
<palantir-java-format.version>2.38.0</palantir-java-format.version>
Expand Down

0 comments on commit e80b4fb

Please sign in to comment.