eva4j 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/LICENSE +21 -0
  2. package/QUICK_REFERENCE.md +204 -0
  3. package/README.md +912 -0
  4. package/USAGE.md +349 -0
  5. package/bin/eva4j.js +234 -0
  6. package/config/defaults.json +46 -0
  7. package/package.json +57 -0
  8. package/src/commands/add-kafka-client.js +193 -0
  9. package/src/commands/add-module.js +221 -0
  10. package/src/commands/create.js +92 -0
  11. package/src/commands/detach.js +495 -0
  12. package/src/commands/generate-http-exchange.js +309 -0
  13. package/src/commands/generate-kafka-event.js +453 -0
  14. package/src/commands/generate-kafka-listener.js +267 -0
  15. package/src/commands/generate-resource.js +265 -0
  16. package/src/commands/generate-usecase.js +198 -0
  17. package/src/commands/info.js +63 -0
  18. package/src/generators/base-generator.js +150 -0
  19. package/src/generators/module-generator.js +48 -0
  20. package/src/generators/shared-generator.js +153 -0
  21. package/src/utils/config-manager.js +156 -0
  22. package/src/utils/context-builder.js +149 -0
  23. package/src/utils/naming.js +137 -0
  24. package/src/utils/template-engine.js +55 -0
  25. package/src/utils/validator.js +159 -0
  26. package/templates/base/application/Application.java.ejs +27 -0
  27. package/templates/base/docker/docker-compose.yml.ejs +41 -0
  28. package/templates/base/gradle/build.gradle.ejs +70 -0
  29. package/templates/base/gradle/settings.gradle.ejs +1 -0
  30. package/templates/base/resources/application-develop.yml.ejs +5 -0
  31. package/templates/base/resources/application-local.yml.ejs +5 -0
  32. package/templates/base/resources/application-production.yml.ejs +9 -0
  33. package/templates/base/resources/application-test.yml.ejs +5 -0
  34. package/templates/base/resources/application.yml.ejs +31 -0
  35. package/templates/base/resources/parameters/develop/cors.yml.ejs +4 -0
  36. package/templates/base/resources/parameters/develop/db.yaml.ejs +21 -0
  37. package/templates/base/resources/parameters/develop/kafka.yml.ejs +26 -0
  38. package/templates/base/resources/parameters/local/cors.yml.ejs +4 -0
  39. package/templates/base/resources/parameters/local/db.yaml.ejs +21 -0
  40. package/templates/base/resources/parameters/local/kafka.yml.ejs +26 -0
  41. package/templates/base/resources/parameters/production/cors.yml.ejs +4 -0
  42. package/templates/base/resources/parameters/production/db.yaml.ejs +21 -0
  43. package/templates/base/resources/parameters/production/kafka.yml.ejs +26 -0
  44. package/templates/base/root/README.md.ejs +126 -0
  45. package/templates/base/root/gitignore.ejs +42 -0
  46. package/templates/http-exchange/Adapter.java.ejs +39 -0
  47. package/templates/http-exchange/Config.java.ejs +24 -0
  48. package/templates/http-exchange/FeignClient.java.ejs +23 -0
  49. package/templates/http-exchange/Port.java.ejs +14 -0
  50. package/templates/kafka-event/Event.java.ejs +10 -0
  51. package/templates/kafka-event/KafkaConfigBean.java.ejs +7 -0
  52. package/templates/kafka-event/KafkaMessageBroker.java.ejs +32 -0
  53. package/templates/kafka-event/MessageBroker.java.ejs +8 -0
  54. package/templates/kafka-event/MessageBrokerImplMethod.java.ejs +9 -0
  55. package/templates/kafka-event/MessageBrokerMethod.java.ejs +1 -0
  56. package/templates/kafka-listener/KafkaController.java.ejs +34 -0
  57. package/templates/kafka-listener/ListenerMethod.java.ejs +9 -0
  58. package/templates/kafka-listener/ValueField.java.ejs +4 -0
  59. package/templates/module/controller.java.ejs +96 -0
  60. package/templates/module/exception.java.ejs +18 -0
  61. package/templates/module/mapper.java.ejs +67 -0
  62. package/templates/module/model.java.ejs +29 -0
  63. package/templates/module/package-info.java.ejs +7 -0
  64. package/templates/module/repository.java.ejs +26 -0
  65. package/templates/module/request-dto.java.ejs +24 -0
  66. package/templates/module/response-dto.java.ejs +26 -0
  67. package/templates/module/service-impl.java.ejs +112 -0
  68. package/templates/module/service.java.ejs +45 -0
  69. package/templates/module/update-dto.java.ejs +25 -0
  70. package/templates/resource/Command.java.ejs +9 -0
  71. package/templates/resource/CommandHandler.java.ejs +22 -0
  72. package/templates/resource/Controller.java.ejs +73 -0
  73. package/templates/resource/Query.java.ejs +12 -0
  74. package/templates/resource/QueryHandler.java.ejs +31 -0
  75. package/templates/resource/ResponseDto.java.ejs +6 -0
  76. package/templates/shared/annotations/ApplicationComponent.java.ejs +9 -0
  77. package/templates/shared/annotations/DomainComponent.java.ejs +9 -0
  78. package/templates/shared/annotations/LogAfter.java.ejs +11 -0
  79. package/templates/shared/annotations/LogBefore.java.ejs +11 -0
  80. package/templates/shared/annotations/LogExceptions.java.ejs +11 -0
  81. package/templates/shared/annotations/LogTimer.java.ejs +11 -0
  82. package/templates/shared/configurations/kafkaConfig/KafkaConfig.java.ejs +49 -0
  83. package/templates/shared/configurations/loggerConfig/HandlerLogs.java.ejs +56 -0
  84. package/templates/shared/configurations/securityConfig/SecurityConfig.java.ejs +57 -0
  85. package/templates/shared/configurations/swaggerConfig/SwaggerConfig.java.ejs +31 -0
  86. package/templates/shared/configurations/useCaseConfig/UseCaseAutoRegister.java.ejs +51 -0
  87. package/templates/shared/configurations/useCaseConfig/UseCaseConfig.java.ejs +25 -0
  88. package/templates/shared/configurations/useCaseConfig/UseCaseContainer.java.ejs +29 -0
  89. package/templates/shared/configurations/useCaseConfig/UseCaseMediator.java.ejs +38 -0
  90. package/templates/shared/customExceptions/BadRequestException.java.ejs +11 -0
  91. package/templates/shared/customExceptions/ConflictException.java.ejs +8 -0
  92. package/templates/shared/customExceptions/ForbiddenException.java.ejs +8 -0
  93. package/templates/shared/customExceptions/ImportFileException.java.ejs +6 -0
  94. package/templates/shared/customExceptions/NotFoundException.java.ejs +8 -0
  95. package/templates/shared/customExceptions/UnauthorizedException.java.ejs +9 -0
  96. package/templates/shared/customExceptions/ValidationException.java.ejs +17 -0
  97. package/templates/shared/errorMessage/ErrorMessage.java.ejs +5 -0
  98. package/templates/shared/errorMessage/FullErrorMessage.java.ejs +9 -0
  99. package/templates/shared/errorMessage/ShortErrorMessage.java.ejs +6 -0
  100. package/templates/shared/eventEnvelope/EventEnvelope.java.ejs +13 -0
  101. package/templates/shared/eventEnvelope/EventMetadata.java.ejs +24 -0
  102. package/templates/shared/filters/CorrelationIdFilter.java.ejs +45 -0
  103. package/templates/shared/handlerException/HandlerExceptions.java.ejs +148 -0
  104. package/templates/shared/interfaces/Command.java.ejs +4 -0
  105. package/templates/shared/interfaces/CommandHandler.java.ejs +5 -0
  106. package/templates/shared/interfaces/Dispatchable.java.ejs +4 -0
  107. package/templates/shared/interfaces/Handler.java.ejs +4 -0
  108. package/templates/shared/interfaces/Query.java.ejs +4 -0
  109. package/templates/shared/interfaces/QueryHandler.java.ejs +5 -0
  110. package/templates/shared/package-info.java.ejs +8 -0
  111. package/templates/usecase/command/Command.java.ejs +7 -0
  112. package/templates/usecase/command/CommandHandler.java.ejs +21 -0
  113. package/templates/usecase/query/Query.java.ejs +10 -0
  114. package/templates/usecase/query/QueryHandler.java.ejs +22 -0
  115. package/templates/usecase/query/ResponseDto.java.ejs +5 -0
@@ -0,0 +1,148 @@
1
+ package <%= packageName %>.shared.infrastructure.handlerException;
2
+
3
+
4
+ import <%= packageName %>.shared.domain.customExceptions.*;
5
+ import <%= packageName %>.shared.domain.errorMessage.ErrorMessage;
6
+ import <%= packageName %>.shared.domain.errorMessage.FullErrorMessage;
7
+ import <%= packageName %>.shared.domain.errorMessage.ShortErrorMessage;
8
+ import feign.RetryableException;
9
+ import jakarta.validation.ConstraintViolationException;
10
+ import org.springframework.dao.DataIntegrityViolationException;
11
+ import org.springframework.http.HttpStatus;
12
+ import org.springframework.http.converter.HttpMessageNotReadableException;
13
+ import org.springframework.security.authentication.BadCredentialsException;
14
+ import org.springframework.security.authentication.DisabledException;
15
+ import org.springframework.security.authentication.InternalAuthenticationServiceException;
16
+ import org.springframework.security.authentication.LockedException;
17
+ import org.springframework.security.authorization.AuthorizationDeniedException;
18
+ import org.springframework.web.bind.MethodArgumentNotValidException;
19
+ import org.springframework.web.bind.annotation.ExceptionHandler;
20
+ import org.springframework.web.bind.annotation.ResponseBody;
21
+ import org.springframework.web.bind.annotation.ResponseStatus;
22
+ import org.springframework.web.bind.annotation.RestControllerAdvice;
23
+ import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
24
+ import org.springframework.web.server.MethodNotAllowedException;
25
+ import org.springframework.web.server.ServerWebInputException;
26
+ import org.yaml.snakeyaml.constructor.DuplicateKeyException;
27
+
28
+ import java.util.ArrayList;
29
+ import java.util.List;
30
+
31
+ @RestControllerAdvice
32
+ public class HandlerExceptions {
33
+
34
+ @ResponseStatus(HttpStatus.BAD_REQUEST)
35
+ @ExceptionHandler(MethodArgumentNotValidException.class)
36
+ @ResponseBody
37
+ public ErrorMessage onMethodArgumentNotValidException(MethodArgumentNotValidException ex){
38
+ List<String> messagesErrors = new ArrayList<>();
39
+ ex.getBindingResult().getFieldErrors().forEach(error -> {
40
+ messagesErrors.add(error.getField() + " " + error.getDefaultMessage());
41
+ });
42
+ return new FullErrorMessage(messagesErrors,"BadRequest",HttpStatus.BAD_REQUEST.value());
43
+ }
44
+
45
+
46
+ @ResponseStatus(HttpStatus.BAD_REQUEST)
47
+ @ExceptionHandler(ConstraintViolationException.class)
48
+ @ResponseBody
49
+ public ErrorMessage onConstraintValidationException(ConstraintViolationException ex){
50
+ List<String> errors = new ArrayList<>();
51
+ ex.getConstraintViolations().forEach( error -> {
52
+ errors.add(error.getMessage());
53
+ });
54
+ return new FullErrorMessage(errors,"Bad Request",HttpStatus.BAD_REQUEST.value());
55
+ }
56
+
57
+ //Spring Exceptions
58
+ @ResponseStatus(HttpStatus.BAD_REQUEST)
59
+ @ExceptionHandler({
60
+ DuplicateKeyException.class,
61
+ MethodNotAllowedException.class,
62
+ ServerWebInputException.class,
63
+ MethodArgumentTypeMismatchException.class,
64
+ HttpMessageNotReadableException.class,
65
+ DataIntegrityViolationException.class
66
+ })
67
+ @ResponseBody
68
+ public ErrorMessage onSpringBadRequest(Exception ex){
69
+ return new FullErrorMessage( List.of(ex.getClass().getSimpleName()), "Bad Request",HttpStatus.BAD_REQUEST.value());
70
+ }
71
+
72
+ @ResponseStatus(HttpStatus.FORBIDDEN)
73
+ @ExceptionHandler(
74
+ AuthorizationDeniedException.class
75
+ )
76
+ @ResponseBody
77
+ public ErrorMessage onAuthorizationDeniedException( AuthorizationDeniedException ex) {
78
+ if (ex.getMessage() == null) return new ShortErrorMessage("Forbidden", HttpStatus.FORBIDDEN.value());
79
+ return new FullErrorMessage(List.of(ex.getMessage()), "Forbidden", HttpStatus.FORBIDDEN.value());
80
+ }
81
+
82
+ // custom exceptions
83
+ //------------------
84
+ @ResponseStatus(HttpStatus.BAD_REQUEST)
85
+ @ExceptionHandler(BadRequestException.class)
86
+ @ResponseBody
87
+ public ErrorMessage onBadRequestException(BadRequestException ex) {
88
+ if (ex.getMessage() == null) return new ShortErrorMessage("Bad Request", HttpStatus.BAD_REQUEST.value());
89
+ return new FullErrorMessage(List.of(ex.getMessage()),"Bad Request", HttpStatus.BAD_REQUEST.value());
90
+ }
91
+
92
+ @ResponseStatus(HttpStatus.NOT_FOUND)
93
+ @ExceptionHandler(NotFoundException.class)
94
+ @ResponseBody
95
+ public ErrorMessage onNotFoundException(NotFoundException ex) {
96
+ if (ex.getMessage() == null) return new ShortErrorMessage("Not Found", HttpStatus.NOT_FOUND.value());
97
+ return new FullErrorMessage(List.of(ex.getMessage()), "Not Found", HttpStatus.NOT_FOUND.value());
98
+ }
99
+
100
+ @ResponseStatus(HttpStatus.UNAUTHORIZED)
101
+ @ExceptionHandler({
102
+ UnauthorizedException.class,
103
+ BadCredentialsException.class,
104
+ DisabledException.class,
105
+ LockedException.class,
106
+ InternalAuthenticationServiceException.class
107
+ })
108
+ @ResponseBody
109
+ public ErrorMessage onUnauthorizedException(Exception ex) {
110
+ if (ex.getMessage() == null) return new ShortErrorMessage("Unauthorized", HttpStatus.UNAUTHORIZED.value());
111
+ return new FullErrorMessage(List.of(ex.getMessage()), "Unauthorized", HttpStatus.UNAUTHORIZED.value());
112
+ }
113
+
114
+ @ResponseStatus(HttpStatus.FORBIDDEN)
115
+ @ExceptionHandler(
116
+ ForbiddenException.class
117
+ )
118
+ @ResponseBody
119
+ public ErrorMessage onForbiddenException( ForbiddenException ex) {
120
+ if (ex.getMessage() == null) return new ShortErrorMessage("Forbidden", HttpStatus.FORBIDDEN.value());
121
+ return new FullErrorMessage(List.of(ex.getMessage()), "Forbidden", HttpStatus.FORBIDDEN.value());
122
+ }
123
+
124
+ @ResponseStatus(HttpStatus.CONFLICT)
125
+ @ExceptionHandler(ConflictException.class)
126
+ @ResponseBody
127
+ public ErrorMessage onConflictException(ConflictException ex) {
128
+ if (ex.getMessage() == null) return new ShortErrorMessage("Conflict", HttpStatus.CONFLICT.value());
129
+ return new FullErrorMessage(List.of(ex.getMessage()), "Conflict", HttpStatus.CONFLICT.value());
130
+ }
131
+
132
+ //error de feign client
133
+ @ResponseStatus(HttpStatus.SERVICE_UNAVAILABLE)
134
+ @ExceptionHandler(RetryableException.class)
135
+ @ResponseBody
136
+ public ErrorMessage onRetryableException(RetryableException ex) {
137
+ return new ShortErrorMessage(ex.request().url() + " not available", HttpStatus.SERVICE_UNAVAILABLE.value());
138
+ }
139
+
140
+ //Internal Server Error
141
+ @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
142
+ @ExceptionHandler(Exception.class)
143
+ @ResponseBody
144
+ public ErrorMessage onServerError(Exception ex){
145
+ return new FullErrorMessage(List.of(ex.getClass().getSimpleName()) ,"Internal Server Error", HttpStatus.INTERNAL_SERVER_ERROR.value());
146
+ }
147
+
148
+ }
@@ -0,0 +1,4 @@
1
+ package <%= packageName %>.shared.domain.interfaces;
2
+
3
+ public interface Command extends Dispatchable{
4
+ }
@@ -0,0 +1,5 @@
1
+ package <%= packageName %>.shared.domain.interfaces;
2
+
3
+ public interface CommandHandler<T extends Command> extends Handler {
4
+ void handle(T command);
5
+ }
@@ -0,0 +1,4 @@
1
+ package <%= packageName %>.shared.domain.interfaces;
2
+
3
+ public interface Dispatchable {
4
+ }
@@ -0,0 +1,4 @@
1
+ package <%= packageName %>.shared.domain.interfaces;
2
+
3
+ public interface Handler {
4
+ }
@@ -0,0 +1,4 @@
1
+ package <%= packageName %>.shared.domain.interfaces;
2
+
3
+ public interface Query<R> extends Dispatchable{
4
+ }
@@ -0,0 +1,5 @@
1
+ package <%= packageName %>.shared.domain.interfaces;
2
+
3
+ public interface QueryHandler<Q extends Query<R>, R> extends Handler{
4
+ R handle(Q query);
5
+ }
@@ -0,0 +1,8 @@
1
+
2
+ @ApplicationModule(
3
+ displayName = "<%= projectName %> - Shared",
4
+ type = org.springframework.modulith.ApplicationModule.Type.OPEN
5
+ )
6
+ package <%= packageName %>.shared;
7
+
8
+ import org.springframework.modulith.ApplicationModule;
@@ -0,0 +1,7 @@
1
+ package <%= packageName %>.<%= moduleName %>.application.commands;
2
+
3
+ import <%= packageName %>.shared.domain.interfaces.Command;
4
+
5
+ public record <%= usecaseName %>Command(
6
+
7
+ ) implements Command { }
@@ -0,0 +1,21 @@
1
+ package <%= packageName %>.<%= moduleName %>.application.usecases;
2
+
3
+ import <%= packageName %>.<%= moduleName %>.application.commands.<%= usecaseName %>Command;
4
+ import <%= packageName %>.shared.domain.annotations.ApplicationComponent;
5
+ import <%= packageName %>.shared.domain.interfaces.CommandHandler;
6
+
7
+
8
+ @ApplicationComponent
9
+ public class <%= usecaseName %>CommandHandler implements CommandHandler<<%= usecaseName %>Command> {
10
+
11
+
12
+ public <%= usecaseName %>CommandHandler() {
13
+
14
+ }
15
+
16
+ @Override
17
+ public void handle(<%= usecaseName %>Command command) {
18
+
19
+ }
20
+
21
+ }
@@ -0,0 +1,10 @@
1
+ package <%= packageName %>.<%= moduleName %>.application.queries;
2
+ <% if (isFindAll) { %>
3
+ import java.util.List;
4
+ <% } %>
5
+ import <%= packageName %>.<%= moduleName %>.application.dtos.<%= usecaseName %>ResponseDto;
6
+ import <%= packageName %>.shared.domain.interfaces.Query;
7
+
8
+ public record <%= usecaseName %>Query(
9
+
10
+ ) implements Query<<% if (isFindAll) { %>List<<%= usecaseName %>ResponseDto><% } else { %><%= usecaseName %>ResponseDto<% } %>> { }
@@ -0,0 +1,22 @@
1
+ package <%= packageName %>.<%= moduleName %>.application.usecases;
2
+
3
+ import <%= packageName %>.<%= moduleName %>.application.dtos.<%= usecaseName %>ResponseDto;
4
+ import <%= packageName %>.<%= moduleName %>.application.queries.<%= usecaseName %>Query;
5
+ import <%= packageName %>.shared.domain.annotations.ApplicationComponent;
6
+ import <%= packageName %>.shared.domain.interfaces.QueryHandler;
7
+
8
+
9
+ @ApplicationComponent
10
+ public class <%= usecaseName %>QueryHandler implements QueryHandler<<%= usecaseName %>Query, <%= usecaseName %>ResponseDto> {
11
+
12
+
13
+
14
+ public <%= usecaseName %>QueryHandler(
15
+
16
+ ) {}
17
+
18
+ @Override
19
+ public <%= usecaseName %>ResponseDto handle(<%= usecaseName %>Query query) {
20
+ return null;
21
+ }
22
+ }
@@ -0,0 +1,5 @@
1
+ package <%= packageName %>.<%= moduleName %>.application.dtos;
2
+
3
+ public record <%= usecaseName %>ResponseDto(
4
+
5
+ ) { }