这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a57b45b
start refactor using templates
juancgalvis Jun 8, 2020
7b7386c
dirs creation using json template
juancgalvis Jun 8, 2020
cf3c4e2
generate model using templates
juancgalvis Jun 8, 2020
017b39a
remove redundant dirs from json array
juancgalvis Jun 8, 2020
243084e
refactor default task name
juancgalvis Jun 8, 2020
70f6fcb
extract base task methods to module builder, build azure pipeline wit…
juancgalvis Jun 8, 2020
c57a07f
update usecase generation with template
juancgalvis Jun 9, 2020
c62ee4c
update usecase generation with template
juancgalvis Jun 9, 2020
180c4d1
generate rest entrypoints with template
juancgalvis Jun 9, 2020
f36ed67
generate rest entrypoints with template
juancgalvis Jun 9, 2020
6e1c4c1
generate adapters and entrypoints using templates
juancgalvis Jun 10, 2020
c8fcaf6
append dependencies to subproject, update yaml properties
juancgalvis Jun 10, 2020
b3d50c3
add some unit tests
juancgalvis Jun 11, 2020
16311ab
add some unit tests
juancgalvis Jun 11, 2020
ea4c83b
update version and readme
juancgalvis Jun 11, 2020
ab38333
update gitignore
juancgalvis Jun 11, 2020
1dc5f42
add new projec dependencies automatically to build.gradle, update h2 …
juancgalvis Jun 11, 2020
932c39c
release new version with mustache templates
juancgalvis Jun 12, 2020
35b58b0
add some test
juancgalvis Jun 13, 2020
cfcbdfb
fix source compatibility
juancgalvis Jun 13, 2020
36d692a
fix source compatibility
juancgalvis Jun 13, 2020
c60868d
move jpa commons directly in jpa driven adapter
juancgalvis Jun 13, 2020
20ddf58
move mongo commons directly in mongodb driven adapter
juancgalvis Jun 14, 2020
c51ded4
update functional test
juancgalvis Jun 14, 2020
6238db3
Merge branch 'master' into feature/driven-config
juancgalvis Jun 14, 2020
6f8040a
fix merge
juancgalvis Jun 14, 2020
d184ee7
setup config model for mongodb
juancgalvis Jun 15, 2020
9956f4c
add some unit test assertions
juancgalvis Jun 15, 2020
8424027
allow secrets manager option creating a datasource driven adapter
juancgalvis Jun 16, 2020
3c4b204
update readme task options
juancgalvis Jun 16, 2020
ed5a6d3
create some unit test
juancgalvis Jun 16, 2020
76121d5
update version, fix some code smell
juancgalvis Jun 16, 2020
9a73b58
remove unused autogenerated methods
juancgalvis Jun 16, 2020
c2b908f
remove module depencency
juancgalvis Jun 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,24 @@ gradle generateDrivenAdapter --type=[drivenAdapterType]
gradle gda --type [drivenAdapterType]
```

| Reference driven adapter value | Name |
| ------------------ | ------------ |
| GENERIC|Empty Driven Adapter |
| JPA|JPA Repository |
| MONGODB|Mongo Repository |
| ASYNCEVENTBUS|Async Event Bus |
|Reference for drivenAdapterType|Name |Additional Options |
|-------------------------------|--------------------|---------------------|
|GENERIC |Empty Driven Adapter|--name [name] |
|JPA |JPA Repository |--secret [true-false]|
|MONGODB |Mongo Repository |--secret [true-false]|
|ASYNCEVENTBUS |Async Event Bus | |

5 The ```generateEntryPoint | gep``` task will generate a class in Infrastructure layer, this task have one required parameter ```type```.
```sh
gradle generateEntryPoint --type=[entryPointType]
gradle gep --type [entryPointType]
```
| Reference entry point value | Name |
| ------------------ | ------------ |
| GENERIC|Empty Entry Point |
| RESTMVC|API REST (Spring Boot Starter Web) |
| WEBFLUX|API REST (Spring Boot Starter WebFlux) |


|Reference for entryPointType|Name |Additional Options|
|----------------------------|--------------------------------------|------------------|
|GENERIC |Empty Entry Point |--name [name] |
|RESTMVC |API REST (Spring Boot Starter Web) | |
|WEBFLUX |API REST (Spring Boot Starter WebFlux)| |

6 The ```validateStructure | vs``` Validate that project references aren't violated.
```sh
Expand All @@ -85,9 +84,10 @@ gradle vs
gradle generatePipeline --type=[pipelineType]
gradle gpl --type=[pipelineType]
````
| Reference pipeline value | Name |
| ------------------ | ------------ |
| AZURE|Azure Pipeline |

|Reference for pipelineType|Name |
|--------------------------|--------------|
|AZURE |Azure Pipeline|


How I can help?
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
package=co.com.bancolombia
systemProp.version=1.6.0
systemProp.version=1.6.1
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,8 @@ public void canRunTaskGenerateDrivenAdapterWithParameters() {
assertTrue(new File("build/functionalTest/infrastructure/driven-adapters/jpa-repository/build.gradle").exists());
assertTrue(new File("build/functionalTest/infrastructure/driven-adapters/jpa-repository/src/main/java/co/com/bancolombia/jpa/JPARepository.java").exists());
assertTrue(new File("build/functionalTest/infrastructure/driven-adapters/jpa-repository/src/main/java/co/com/bancolombia/jpa/JPARepositoryAdapter.java").exists());

assertTrue(new File("build/functionalTest/infrastructure//helpers/jpa-repository-commons/build.gradle").exists());
assertTrue(new File("build/functionalTest/infrastructure/helpers/jpa-repository-commons/src/main/java/co/com/bancolombia/jpa/AdapterOperations.java").exists());

// TODO: Enable test
// assertTrue(new File("build/functionalTest/applications/app-service/src/main/java/co/com/bancolombia/config/jpa/JpaConfig.java").exists());
// assertTrue(new File("build/functionalTest/applications/app-service/src/main/resources/application-jpaAdapter.yaml").exists());
// assertTrue(new File("build/functionalTest/domain/model/src/main/java/co/com/bancolombia/model/secret/Secret.java").exists());
assertTrue(new File("build/functionalTest/infrastructure/driven-adapters/jpa-repository/src/main/java/co/com/bancolombia/jpa/helper/AdapterOperations.java").exists());
assertTrue(new File("build/functionalTest/applications/app-service/src/main/java/co/com/bancolombia/config/JpaConfig.java").exists());

assertEquals(result.task(":" + task).getOutcome(), TaskOutcome.SUCCESS);
}
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/co/com/bancolombia/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,10 @@ public class Constants {
public static final String SPRING_CLOUD_VERSION = "Greenwich.M1";
public static final String SONAR_VERSION = "2.7";
public static final String JACOCO_VERSION = "0.8.5";
public static final String PLUGIN_VERSION = "1.6.0";
public static final String PLUGIN_VERSION = "1.6.1";
public static final String SECRETS_VERSION = "2.1.0";

public enum BooleanOption {
TRUE, FALSE
}
}
14 changes: 12 additions & 2 deletions src/main/java/co/com/bancolombia/factory/ModuleBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,14 @@ public void setupFromTemplate(String resourceGroup) throws IOException, ParamNot
}

public void appendToSettings(String module, String baseDir) throws IOException {
appendToFile("settings.gradle", settings -> settings + ("\ninclude ':" + module + "'\n" +
"project(':" + module + "').projectDir = file('./" + baseDir + "/" + module + "')"));
appendToFile("settings.gradle", settings -> {
String toAppend = "\ninclude ':" + module + "'\nproject(':" + module + "').projectDir = file('./" + baseDir
+ "/" + module + "')";
if (settings.contains(toAppend)) {
return settings;
}
return settings + toAppend;
});
}

public void appendDependencyToModule(String module, String dependency) throws IOException {
Expand Down Expand Up @@ -127,6 +133,10 @@ public String getStringParam(String key) {
return (String) params.get(key);
}

public Boolean getBooleanParam(String key) {
return (Boolean) params.get(key);
}

private void appendToFile(String path, FileAppender appender) throws IOException {
FileModel current = files.get(path);
String content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public class DrivenAdapterJPA implements ModuleFactory {
@Override
public void buildModule(ModuleBuilder builder) throws IOException, CleanException {
builder.addParamPackage(FileUtils.readProperties("package"));
builder.setupFromTemplate("helper/jpa-repository-commons"); // TODO: include in driven adapter
builder.setupFromTemplate("driven-adapter/jpa-repository");
builder.appendToSettings("jpa-repository", "infrastructure/driven-adapters");
builder.appendToSettings("jpa-repository-commons", "infrastructure/helpers");
Expand All @@ -23,6 +22,6 @@ public void buildModule(ModuleBuilder builder) throws IOException, CleanExceptio
builder.appendToProperties("spring.jpa")
.put("databasePlatform", "org.hibernate.dialect.H2Dialect");
builder.appendDependencyToModule("app-service", "implementation project(':jpa-repository')");
// TODO: Generate JPA Config validate secrets manager usage
new DrivenAdapterSecrets().buildModule(builder);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ public class DrivenAdapterMongoDB implements ModuleFactory {
@Override
public void buildModule(ModuleBuilder builder) throws IOException, CleanException {
builder.addParamPackage(FileUtils.readProperties("package"));
builder.setupFromTemplate("helper/mongo-repository-commons"); // TODO: include in driven adapter
builder.setupFromTemplate("driven-adapter/mongo-repository");
builder.appendToSettings("mongo-repository", "infrastructure/driven-adapters");
builder.appendToSettings("mongo-repository-commons", "infrastructure/helpers");
builder.appendToProperties("spring.data.mongodb")
.put("uri", "mongodb://user:pass@hostname/db");
.put("uri", "mongodb://localhost:27017/test");
builder.appendDependencyToModule("app-service",
"implementation project(':mongo-repository')");
new DrivenAdapterSecrets().buildModule(builder);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package co.com.bancolombia.factory.adapters;

import co.com.bancolombia.Constants;
import co.com.bancolombia.exceptions.CleanException;
import co.com.bancolombia.factory.ModuleBuilder;
import co.com.bancolombia.factory.ModuleFactory;

import java.io.IOException;

public class DrivenAdapterSecrets implements ModuleFactory {
@Override
public void buildModule(ModuleBuilder builder) throws IOException, CleanException {
if (builder.getBooleanParam("include-secret")) {
builder.setupFromTemplate("driven-adapter/secrets");
builder.appendDependencyToModule("app-service",
"compile 'co.com.bancolombia:secretsmanager:" + Constants.SECRETS_VERSION + "'");
builder.appendToProperties("aws")
.put("region", "us-east-1")
.put("secretName", "my-secret");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,16 @@ public class ModuleFactoryDrivenAdapter {

public static ModuleFactory getDrivenAdapterFactory(DrivenAdapterType type) throws InvalidTaskOptionException {
switch (type) {
case JPA: {
case JPA:
return new DrivenAdapterJPA();
}
case MONGODB: {
case MONGODB:
return new DrivenAdapterMongoDB();
}
case ASYNCEVENTBUS: {
case ASYNCEVENTBUS:
return new DrivenAdapterAsyncEventBus();
}
case GENERIC: {
case GENERIC:
return new DrivenAdapterGeneric();
}
default: {
default:
throw new InvalidTaskOptionException("Driven Adapter type invalid");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,14 @@ public class ModuleFactoryEntryPoint {

public static ModuleFactory getEntryPointFactory(EntryPointType type) throws InvalidTaskOptionException {
switch (type) {
case RESTMVC: {
case RESTMVC:
return new EntryPointRestMvc();
}
case WEBFLUX: {
case WEBFLUX:
return new EntryPointRestWebflux();
}
case GENERIC: {
case GENERIC:
return new EntryPointGeneric();
}
default: {
default:
throw new InvalidTaskOptionException("Entry Point type invalid");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ public class ModuleFactoryPipeline {
@SuppressWarnings("SwitchStatementWithTooFewBranches")
public static ModuleFactory getPipelineFactory(PipelineType type) throws InvalidTaskOptionException {
switch (type) {
case AZURE: {
case AZURE:
return new PipelineAzure();
}
default: {
default:
throw new InvalidTaskOptionException("Pipeline value invalid");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package co.com.bancolombia.models;

import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.List;
import java.util.Map;

@Data
@NoArgsConstructor
@Getter
@Setter
public class TemplateDefinition {
private Map<String, String> files;
private List<String> folders;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package co.com.bancolombia.task;

import co.com.bancolombia.Constants.BooleanOption;
import co.com.bancolombia.exceptions.CleanException;
import co.com.bancolombia.factory.ModuleBuilder;
import co.com.bancolombia.factory.ModuleFactory;
Expand All @@ -23,6 +24,7 @@ public class GenerateDrivenAdapterTask extends DefaultTask {

private DrivenAdapterType type;
private String name;
private BooleanOption secret = BooleanOption.FALSE;

@Option(option = "type", description = "Set type of driven adapter to be generated")
public void setType(DrivenAdapterType type) {
Expand All @@ -34,13 +36,21 @@ public void setName(String name) {
this.name = name;
}

// TODO: Enable autogeneration of secrets manager boolean
@Option(option = "secret", description = "Enable secrets for this driven adapter")
public void setSecret(BooleanOption secret) {
this.secret = secret;
}

@OptionValues("type")
public List<DrivenAdapterType> getTypes() {
return new ArrayList<>(Arrays.asList(DrivenAdapterType.values()));
}

@OptionValues("secret")
public List<BooleanOption> getSecretOptions() {
return new ArrayList<>(Arrays.asList(BooleanOption.values()));
}

@TaskAction
public void generateDrivenAdapterTask() throws IOException, CleanException {
if (type == null) {
Expand All @@ -51,6 +61,7 @@ public void generateDrivenAdapterTask() throws IOException, CleanException {
logger.lifecycle("Clean Architecture plugin version: {}", Utils.getVersionPlugin());
logger.lifecycle("Driven Adapter type: {}", type);
builder.addParam("task-param-name", name);
builder.addParam("include-secret", secret == BooleanOption.TRUE);
moduleFactory.buildModule(builder);
builder.persist();
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/co/com/bancolombia/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public static String formatTaskOptions(List<?> options) {
}

public static String addDependency(String build, String dependency) {
if (build.contains(dependency)) {
return build;
}
int start = build.indexOf("dependencies");
int realStart = build.indexOf('{', start);
return build.substring(0, realStart + 1) + "\n\t" + dependency + build.substring(realStart + 1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
dependencies {
implementation project(':model')
implementation project(':jpa-repository-commons')

compile 'org.springframework.boot:spring-boot-starter-data-jpa'
compile 'org.reactivecommons.utils:object-mapper-api:0.1.0'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.reactivecommons.utils:object-mapper-api:0.1.0'

runtime 'com.h2database:h2'
testCompile 'org.reactivecommons.utils:object-mapper:0.1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package {{package}}.jpa.config;

{{#include-secret}}
import lombok.Data;
{{/include-secret}}
{{^include-secret}}
import lombok.Builder;
import lombok.Getter;
{{/include-secret}}

{{#include-secret}}
@Data
{{/include-secret}}
{{^include-secret}}
@Builder
@Getter
{{/include-secret}}
public class DBSecret {
private {{^include-secret}}final {{/include-secret}}String url;
private {{^include-secret}}final {{/include-secret}}String username;
private {{^include-secret}}final {{/include-secret}}String password;
}
Loading