Skip to content

Commit

Permalink
Scaffold kotlin code Add EntryPoints Missing (#190)
Browse files Browse the repository at this point in the history
* Add kotlin files driver-adapters
* Update License MIT To Apache 2.0
* Add entryPoints Kotlin

Co-authored-by: ElvertMora
  • Loading branch information
jakspok authored Nov 25, 2021
1 parent c0ba2cb commit db2f5d8
Show file tree
Hide file tree
Showing 17 changed files with 132 additions and 172 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,10 @@ The **`generateEntryPoint | gep`** task will generate a module in Infrastructure
| generic | Empty Entry Point | --name [name] |☑|☑|
| restmvc | API REST (Spring Boot Starter Web) | --server [serverOption] default undertow |☑|☑|
| webflux | API REST (Spring Boot Starter WebFlux) | --router [true, false] default true |☑|☑|
| rsocket | Rsocket Controller Entry Point | |☑|☐|
| graphql | API GraphQL | --pathgql [name path] default /graphql |☑|☐|
| asynceventhandler | Async Event Handler | |☑|☐|
| mq | JMS MQ Client to listen messages | |☑|☐|
| rsocket | Rsocket Controller Entry Point | |☑|☑|
| graphql | API GraphQL | --pathgql [name path] default /graphql |☑|☑|
| asynceventhandler | Async Event Handler | |☑|☑|
| mq | JMS MQ Client to listen messages | |☑|☑|

Additionally, if you'll use a restmvc, you can specify the web server on which the application will run. By default, undertow.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package co.com.bancolombia.factory.entrypoints;

import static co.com.bancolombia.utils.Utils.buildImplementationFromProject;

import co.com.bancolombia.exceptions.CleanException;
import co.com.bancolombia.factory.ModuleBuilder;
import co.com.bancolombia.factory.ModuleFactory;
Expand All @@ -22,7 +24,8 @@ public void buildModule(ModuleBuilder builder) throws IOException, CleanExceptio
.put("mapping", "/playground")
.put("endpoint", name)
.put("enabled", true);
builder.appendDependencyToModule("app-service", "implementation project(':graphql-api')");
String dependency = buildImplementationFromProject(builder.isKotlin(), ":graphql-api");
builder.appendDependencyToModule("app-service", dependency);
builder.setupFromTemplate("entry-point/graphql-api");
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package co.com.bancolombia.factory.entrypoints;

import static co.com.bancolombia.utils.Utils.buildImplementationFromProject;

import co.com.bancolombia.exceptions.CleanException;
import co.com.bancolombia.factory.ModuleBuilder;
import co.com.bancolombia.factory.ModuleFactory;
Expand All @@ -11,7 +13,8 @@ public class EntryPointMQ implements ModuleFactory {
public void buildModule(ModuleBuilder builder) throws IOException, CleanException {
builder.setupFromTemplate(getTemplate(builder.isReactive()));
builder.appendToSettings("mq-listener", "infrastructure/entry-points");
builder.appendDependencyToModule("app-service", "implementation project(':mq-listener')");
String dependency = buildImplementationFromProject(builder.isKotlin(), ":mq-listener");
builder.appendDependencyToModule("app-service", dependency);

builder
.appendToProperties("commons.jms")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package co.com.bancolombia.factory.entrypoints;

import static co.com.bancolombia.utils.Utils.buildImplementationFromProject;

import co.com.bancolombia.exceptions.CleanException;
import co.com.bancolombia.factory.ModuleBuilder;
import co.com.bancolombia.factory.ModuleFactory;
Expand All @@ -13,7 +15,8 @@ public void buildModule(ModuleBuilder builder) throws IOException, CleanExceptio
builder.runValidations(ReactiveTypeValidation.class);
builder.appendToSettings("rsocket-responder", "infrastructure/entry-points");
builder.appendToProperties("spring.rsocket.server").put("port", 7000);
builder.appendDependencyToModule("app-service", "implementation project(':rsocket-responder')");
String dependency = buildImplementationFromProject(builder.isKotlin(), ":rsocket-responder");
builder.appendDependencyToModule("app-service", dependency);
builder.setupFromTemplate("entry-point/rsocket-responder");
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,17 @@
package {{package}}.events.handlers;

{{#lombok}}
import lombok.AllArgsConstructor;
{{/lombok}}
import org.reactivecommons.api.domain.Command;
import org.reactivecommons.async.impl.config.annotations.EnableCommandListeners;
import reactor.core.publisher.Mono;
package {{package}}.events.handlers

{{#lombok}}
@AllArgsConstructor
{{/lombok}}
@EnableCommandListeners
class CommandsHandler constructor(sampleUseCase: SampleUseCase) {
// val sampleUseCase: SampleUseCase;
import org.reactivecommons.api.domain.Command
import org.reactivecommons.async.impl.config.annotations.EnableCommandListeners
import reactor.core.publisher.Mono

{{^lombok}}
fun CommandsHandler(/*SampleUseCase sampleUseCase*/) {
//this.sampleUseCase = sampleUseCase;
@EnableCommandListeners
open class CommandsHandler //(private val sampleUseCase: SampleUseCase)
{
open fun handleCommandA(command: Command<Any>): Mono<Void> {
println("command received: " + command.name + " ->" + command.data) // TODO: Remove this line
//return sampleUseCase.doSomething(command.getData())
return Mono.empty()
}
{{/lombok}}
}

fun handleCommandA(command :Command<Any/*change for proper model*/>) : Mono<Unit> {
System.out.println("command received: " + command.getName() + " ->" + command.getData()); // TODO: Remove this line
// return sampleUseCase.doSomething(command.getData());
return Mono.empty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"entry-point/async-event-handler/build.gradle.mustache": "infrastructure/entry-points/async-event-handler/build.gradle"
},
"kotlin": {
"entry-point/async-event-handler/handler-registry-configuration.java.mustache": "infrastructure/entry-points/async-event-handler/src/main/{{language}}/{{packagePath}}/events/HandlerRegistryConfiguration.kt",
"entry-point/async-event-handler/handler-registry-configuration.kt.mustache": "infrastructure/entry-points/async-event-handler/src/main/{{language}}/{{packagePath}}/events/HandlerRegistryConfiguration.kt",
"entry-point/async-event-handler/events-handler.kt.mustache": "infrastructure/entry-points/async-event-handler/src/main/{{language}}/{{packagePath}}/events/handlers/EventsHandler.kt",
"entry-point/async-event-handler/commands-handler.kt.mustache": "infrastructure/entry-points/async-event-handler/src/main/{{language}}/{{packagePath}}/events/handlers/CommandsHandler.kt",
"entry-point/async-event-handler/queries-handler.kt.mustache": "infrastructure/entry-points/async-event-handler/src/main/{{language}}/{{packagePath}}/events/handlers/QueriesHandler.kt",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,15 @@
package {{package}}.events.handlers;
package {{package}}.events.handlers

{{#lombok}}
import lombok.AllArgsConstructor;
{{/lombok}}
import org.reactivecommons.api.domain.DomainEvent;
import org.reactivecommons.async.impl.config.annotations.EnableEventListeners;
import reactor.core.publisher.Mono;
import org.reactivecommons.api.domain.DomainEvent
import org.reactivecommons.async.impl.config.annotations.EnableEventListeners
import reactor.core.publisher.Mono

{{#lombok}}
@AllArgsConstructor
{{/lombok}}
@EnableEventListeners
class EventsHandler constructor(sampleUseCase: SampleUseCase) {
// final SampleUseCase sampleUseCase;
{{^lombok}}
fun EventsHandler(/*SampleUseCase sampleUseCase*/) {
//this.sampleUseCase = sampleUseCase;
}
{{/lombok}}

fun handleEventA(event :DomainEvent<Any/*change for proper model*/>):Mono<Unit> {
fun println("event received: " + event.getName() + " ->" + event.getData()); // TODO: Remove this line
// return sampleUseCase.doSomething(event.getData());
return Mono.empty();
open class EventsHandler //(private val sampleUseCase: SampleUseCase)
{
open fun handleEventA(event: DomainEvent<Any>): Mono<Void> {
println("event received: " + event.name + " ->" + event.data) // TODO: Remove this line
// return sampleUseCase.doSomething(event.getData())
return Mono.empty()
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,53 @@
package {{package}}.events;

import {{package}}.events.handlers.CommandsHandler;
import {{package}}.events.handlers.EventsHandler;
import {{package}}.events.handlers.QueriesHandler;
import org.reactivecommons.async.api.HandlerRegistry;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
package {{package}}.events

import {{package}}.events.handlers.CommandsHandler
import {{package}}.events.handlers.EventsHandler
import {{package}}.events.handlers.QueriesHandler
import org.reactivecommons.api.domain.Command
import org.reactivecommons.api.domain.DomainEvent
import org.reactivecommons.async.api.HandlerRegistry
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

@Configuration
class HandlerRegistryConfiguration {

@Configuration
open class HandlerRegistryConfiguration {
// see more at: https://reactivecommons.org/reactive-commons-java/#_handlerregistry_2
@Bean
fun handlerRegistry(commands :CommandsHandler, events :EventsHandler, queries QueriesHandler):HandlerRegistry {
open fun handlerRegistry(commands: CommandsHandler, events: EventsHandler, queries: QueriesHandler): HandlerRegistry {
return HandlerRegistry.register()
.listenNotificationEvent("some.broadcast.event.name", events::handleEventA, Object.class/*change for proper model*/)
.listenEvent("some.event.name", events::handleEventA, Object.class/*change for proper model*/)
.handleCommand("some.command.name", commands::handleCommandA, Object.class/*change for proper model*/)
.serveQuery("some.query.name", queries::handleQueryA, Object.class/*change for proper model*/);
.listenNotificationEvent(
"some.broadcast.event.name",
{ event: DomainEvent<Any> ->
events.handleEventA(
event
)
},
Any::class.java /*change for proper model*/
)
.listenEvent(
"some.event.name",
{ event: DomainEvent<Any> ->
events.handleEventA(
event
)
},
Any::class.java /*change for proper model*/
)
.handleCommand(
"some.command.name",
{ command: Command<Any> ->
commands.handleCommandA(
command
)
},
Any::class.java /*change for proper model*/
)
.serveQuery(
"some.query.name",
{ query: Any -> queries.handleQueryA(query) },
Any::class.java /*change for proper model*/
)
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
package {{package}}.events.handlers;

{{#lombok}}
import lombok.AllArgsConstructor;
{{/lombok}}
import org.reactivecommons.async.impl.config.annotations.EnableQueryListeners;
import reactor.core.publisher.Mono;
package {{package}}.events.handlers

{{#lombok}}
@AllArgsConstructor
{{/lombok}}
@EnableQueryListeners
class QueriesHandler constructor (sampleUseCase: SampleUseCase) {
// private final SampleUseCase sampleUseCase;
import org.reactivecommons.async.impl.config.annotations.EnableQueryListeners
import reactor.core.publisher.Mono

{{^lombok}}
fun QueriesHandler(/*SampleUseCase sampleUseCase*/) {
//this.sampleUseCase = sampleUseCase;
}
{{/lombok}}
@EnableQueryListeners
open class QueriesHandler //(private val sampleUseCase: SampleUseCase)
{
open fun handleQueryA(query: Any /*change for proper model*/): Mono<Any> {
println("query received->$query") // TODO: Remove this line
// return sampleUseCase.doSomethingReturningNoMonoVoid(query)
return Mono.just("Response Data")
fun handleQueryA(query/*change for proper model*/ :Any) :Mono<Any/*change for proper model*/> {
System.out.println("query received->" + query); // TODO: Remove this line
// return sampleUseCase.doSomethingReturningNoMonoVoid(query);
return Mono.just("Response Data");
}
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,18 @@
package {{package}}.graphqlapi;

import graphql.kickstart.tools.GraphQLMutationResolver;
{{#lombok}}
import lombok.RequiredArgsConstructor;
{{/lombok}}
import org.springframework.stereotype.Controller;
package {{package}}.graphqlapi

import graphql.kickstart.tools.GraphQLMutationResolver
import org.springframework.stereotype.Controller

{{#lombok}}
@RequiredArgsConstructor
{{/lombok}}
@Controller
/**
* To interact with the API make use of Playground in the "/playground" path, but remember,
* Playground ONLY must be used in dev or qa environments, not in production.
*/
class ApiMutations : GraphQLMutationResolver {
// private val useCase: MyUseCase;
{{^lombok}}
fun ApiMutations(useCase: MyUseCase ){
this.useCase = useCase;
}
{{/lombok}}
class ApiMutations(/*private val useCase: MyUseCase*/) : GraphQLMutationResolver {
fun addSomething(String objRequest/* change for object request */) : String {
// return useCase.doAction(objRequest);
return "Hello world from graphql-api mutations " + objRequest;
fun addSomething(objRequest :String/* change for object request */) : String {
// return useCase.doAction(objRequest)
return "Hello world from graphql-api mutations " + objRequest
}
}
28 changes: 8 additions & 20 deletions src/main/resources/entry-point/graphql-api/api-queries.kt.mustache
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
package {{package}}.graphqlapi;

import graphql.kickstart.tools.GraphQLQueryResolver;
{{#lombok}}
import lombok.RequiredArgsConstructor;
{{/lombok}}
import org.springframework.stereotype.Controller;
package {{package}}.graphqlapi

import graphql.kickstart.tools.GraphQLQueryResolver
import org.springframework.stereotype.Controller

{{#lombok}}
@RequiredArgsConstructor
{{/lombok}}
@Controller
/**
* To interact with the API make use of Playground in the "/playground" path, but remember,
* Playground ONLY must be used in dev or qa environments, not in production.
*/
class ApiQueries : GraphQLQueryResolver {
// private val useCase: MyUseCase ;
class ApiQueries(/*private val useCase :MyUseCase*/) : GraphQLQueryResolver {
{{^lombok}}
fun ApiQueries(useCase: MyUseCase){
this.useCase = useCase;
}
{{/lombok}}
fun getSomething(objRequest : String/* change for object request */) : String {
// return useCase.doAction(objRequest)
return "Hello world from graphql-api queries " + objRequest
fun getSomething(String objRequest/* change for object request */) : String {
// return useCase.doAction(objRequest);
return "Hello world from graphql-api queries " + objRequest;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dependencies {
implementation(project(":model"))
implementation(project(":usecase"))
implementation("org.springframework:spring-context")
implementation("com.graphql-java-kickstart:graphql-spring-boot-starter:11.0.0")
implementation("com.graphql-java-kickstart:playground-spring-boot-starter:11.0.0")
}
6 changes: 3 additions & 3 deletions src/main/resources/entry-point/graphql-api/definition.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"folders": [
"infrastructure/entry-points/graphql-api/src/main/java/{{packagePath}}/graphql-controllers",
"infrastructure/entry-points/graphql-api/src/test/java/{{packagePath}}/graphql-controllers",
"infrastructure/entry-points/graphql-api/src/main/{{language}}/{{packagePath}}/graphql-controllers",
"infrastructure/entry-points/graphql-api/src/test/{{language}}/{{packagePath}}/graphql-controllers",
"applications/app-service/src/main/resources/graphql"
],
"files": {},
Expand All @@ -15,6 +15,6 @@
"entry-point/graphql-api/config/api-schema.graphqls.mustache": "applications/app-service/src/main/resources/graphql/api-schema.graphqls",
"entry-point/graphql-api/api-queries.kt.mustache": "infrastructure/entry-points/graphql-api/src/main/{{language}}/{{packagePath}}/graphqlapi/ApiQueries.kt",
"entry-point/graphql-api/api-mutations.kt.mustache": "infrastructure/entry-points/graphql-api/src/main/{{language}}/{{packagePath}}/graphqlapi/ApiMutations.kt",
"entry-point/graphql-api/build.gradle.kts.mustache": "infrastructure/entry-points/graphql-api/build.gradle"
"entry-point/graphql-api/build.gradle.kts.mustache": "infrastructure/entry-points/graphql-api/build.gradle.kts"
}
}
2 changes: 1 addition & 1 deletion src/main/resources/entry-point/mq-listener/definition.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
},
"kotlin": {
"entry-point/mq-listener/sample-mq-message-listener.kt.mustache": "infrastructure/entry-points/mq-listener/src/main/{{language}}/{{packagePath}}/mq/listener/SampleMQMessageListener.kt",
"entry-point/mq-listener/build.gradle.kts.mustache": "infrastructure/entry-points/mq-listener/build.gradle"
"entry-point/mq-listener/build.gradle.kts.mustache": "infrastructure/entry-points/mq-listener/build.gradle.kts"
}
}
Loading

0 comments on commit db2f5d8

Please sign in to comment.