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.
- package/LICENSE +21 -0
- package/QUICK_REFERENCE.md +204 -0
- package/README.md +912 -0
- package/USAGE.md +349 -0
- package/bin/eva4j.js +234 -0
- package/config/defaults.json +46 -0
- package/package.json +57 -0
- package/src/commands/add-kafka-client.js +193 -0
- package/src/commands/add-module.js +221 -0
- package/src/commands/create.js +92 -0
- package/src/commands/detach.js +495 -0
- package/src/commands/generate-http-exchange.js +309 -0
- package/src/commands/generate-kafka-event.js +453 -0
- package/src/commands/generate-kafka-listener.js +267 -0
- package/src/commands/generate-resource.js +265 -0
- package/src/commands/generate-usecase.js +198 -0
- package/src/commands/info.js +63 -0
- package/src/generators/base-generator.js +150 -0
- package/src/generators/module-generator.js +48 -0
- package/src/generators/shared-generator.js +153 -0
- package/src/utils/config-manager.js +156 -0
- package/src/utils/context-builder.js +149 -0
- package/src/utils/naming.js +137 -0
- package/src/utils/template-engine.js +55 -0
- package/src/utils/validator.js +159 -0
- package/templates/base/application/Application.java.ejs +27 -0
- package/templates/base/docker/docker-compose.yml.ejs +41 -0
- package/templates/base/gradle/build.gradle.ejs +70 -0
- package/templates/base/gradle/settings.gradle.ejs +1 -0
- package/templates/base/resources/application-develop.yml.ejs +5 -0
- package/templates/base/resources/application-local.yml.ejs +5 -0
- package/templates/base/resources/application-production.yml.ejs +9 -0
- package/templates/base/resources/application-test.yml.ejs +5 -0
- package/templates/base/resources/application.yml.ejs +31 -0
- package/templates/base/resources/parameters/develop/cors.yml.ejs +4 -0
- package/templates/base/resources/parameters/develop/db.yaml.ejs +21 -0
- package/templates/base/resources/parameters/develop/kafka.yml.ejs +26 -0
- package/templates/base/resources/parameters/local/cors.yml.ejs +4 -0
- package/templates/base/resources/parameters/local/db.yaml.ejs +21 -0
- package/templates/base/resources/parameters/local/kafka.yml.ejs +26 -0
- package/templates/base/resources/parameters/production/cors.yml.ejs +4 -0
- package/templates/base/resources/parameters/production/db.yaml.ejs +21 -0
- package/templates/base/resources/parameters/production/kafka.yml.ejs +26 -0
- package/templates/base/root/README.md.ejs +126 -0
- package/templates/base/root/gitignore.ejs +42 -0
- package/templates/http-exchange/Adapter.java.ejs +39 -0
- package/templates/http-exchange/Config.java.ejs +24 -0
- package/templates/http-exchange/FeignClient.java.ejs +23 -0
- package/templates/http-exchange/Port.java.ejs +14 -0
- package/templates/kafka-event/Event.java.ejs +10 -0
- package/templates/kafka-event/KafkaConfigBean.java.ejs +7 -0
- package/templates/kafka-event/KafkaMessageBroker.java.ejs +32 -0
- package/templates/kafka-event/MessageBroker.java.ejs +8 -0
- package/templates/kafka-event/MessageBrokerImplMethod.java.ejs +9 -0
- package/templates/kafka-event/MessageBrokerMethod.java.ejs +1 -0
- package/templates/kafka-listener/KafkaController.java.ejs +34 -0
- package/templates/kafka-listener/ListenerMethod.java.ejs +9 -0
- package/templates/kafka-listener/ValueField.java.ejs +4 -0
- package/templates/module/controller.java.ejs +96 -0
- package/templates/module/exception.java.ejs +18 -0
- package/templates/module/mapper.java.ejs +67 -0
- package/templates/module/model.java.ejs +29 -0
- package/templates/module/package-info.java.ejs +7 -0
- package/templates/module/repository.java.ejs +26 -0
- package/templates/module/request-dto.java.ejs +24 -0
- package/templates/module/response-dto.java.ejs +26 -0
- package/templates/module/service-impl.java.ejs +112 -0
- package/templates/module/service.java.ejs +45 -0
- package/templates/module/update-dto.java.ejs +25 -0
- package/templates/resource/Command.java.ejs +9 -0
- package/templates/resource/CommandHandler.java.ejs +22 -0
- package/templates/resource/Controller.java.ejs +73 -0
- package/templates/resource/Query.java.ejs +12 -0
- package/templates/resource/QueryHandler.java.ejs +31 -0
- package/templates/resource/ResponseDto.java.ejs +6 -0
- package/templates/shared/annotations/ApplicationComponent.java.ejs +9 -0
- package/templates/shared/annotations/DomainComponent.java.ejs +9 -0
- package/templates/shared/annotations/LogAfter.java.ejs +11 -0
- package/templates/shared/annotations/LogBefore.java.ejs +11 -0
- package/templates/shared/annotations/LogExceptions.java.ejs +11 -0
- package/templates/shared/annotations/LogTimer.java.ejs +11 -0
- package/templates/shared/configurations/kafkaConfig/KafkaConfig.java.ejs +49 -0
- package/templates/shared/configurations/loggerConfig/HandlerLogs.java.ejs +56 -0
- package/templates/shared/configurations/securityConfig/SecurityConfig.java.ejs +57 -0
- package/templates/shared/configurations/swaggerConfig/SwaggerConfig.java.ejs +31 -0
- package/templates/shared/configurations/useCaseConfig/UseCaseAutoRegister.java.ejs +51 -0
- package/templates/shared/configurations/useCaseConfig/UseCaseConfig.java.ejs +25 -0
- package/templates/shared/configurations/useCaseConfig/UseCaseContainer.java.ejs +29 -0
- package/templates/shared/configurations/useCaseConfig/UseCaseMediator.java.ejs +38 -0
- package/templates/shared/customExceptions/BadRequestException.java.ejs +11 -0
- package/templates/shared/customExceptions/ConflictException.java.ejs +8 -0
- package/templates/shared/customExceptions/ForbiddenException.java.ejs +8 -0
- package/templates/shared/customExceptions/ImportFileException.java.ejs +6 -0
- package/templates/shared/customExceptions/NotFoundException.java.ejs +8 -0
- package/templates/shared/customExceptions/UnauthorizedException.java.ejs +9 -0
- package/templates/shared/customExceptions/ValidationException.java.ejs +17 -0
- package/templates/shared/errorMessage/ErrorMessage.java.ejs +5 -0
- package/templates/shared/errorMessage/FullErrorMessage.java.ejs +9 -0
- package/templates/shared/errorMessage/ShortErrorMessage.java.ejs +6 -0
- package/templates/shared/eventEnvelope/EventEnvelope.java.ejs +13 -0
- package/templates/shared/eventEnvelope/EventMetadata.java.ejs +24 -0
- package/templates/shared/filters/CorrelationIdFilter.java.ejs +45 -0
- package/templates/shared/handlerException/HandlerExceptions.java.ejs +148 -0
- package/templates/shared/interfaces/Command.java.ejs +4 -0
- package/templates/shared/interfaces/CommandHandler.java.ejs +5 -0
- package/templates/shared/interfaces/Dispatchable.java.ejs +4 -0
- package/templates/shared/interfaces/Handler.java.ejs +4 -0
- package/templates/shared/interfaces/Query.java.ejs +4 -0
- package/templates/shared/interfaces/QueryHandler.java.ejs +5 -0
- package/templates/shared/package-info.java.ejs +8 -0
- package/templates/usecase/command/Command.java.ejs +7 -0
- package/templates/usecase/command/CommandHandler.java.ejs +21 -0
- package/templates/usecase/query/Query.java.ejs +10 -0
- package/templates/usecase/query/QueryHandler.java.ejs +22 -0
- 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,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
|
+
}
|