elguardian commented on code in PR #3671:
URL:
https://github.com/apache/incubator-kie-kogito-runtimes/pull/3671#discussion_r1764794865
##########
kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/ProcessResourceGenerator.java:
##########
@@ -314,40 +416,51 @@ public String generate() {
}
switchExpr.getEntries().add(0, userTask.getModelSwitchEntry());
}
-
}
+ }
- typeInterpolations.put("$Clazz$", resourceClazzName);
- typeInterpolations.put("$Type$", dataClazzName);
-
template.findAll(StringLiteralExpr.class).forEach(this::interpolateStrings);
- template.findAll(ClassOrInterfaceType.class).forEach(cls ->
interpolateTypes(cls, typeInterpolations));
-
- TagResourceGenerator.addTags(clazz, process, context);
-
-
template.findAll(MethodDeclaration.class).forEach(this::interpolateMethods);
-
- if (context.hasDI()) {
- template.findAll(FieldDeclaration.class,
- CodegenUtils::isProcessField).forEach(fd ->
context.getDependencyInjectionAnnotator().withNamedInjection(fd, processId));
- } else {
- template.findAll(FieldDeclaration.class,
-
CodegenUtils::isProcessField).forEach(this::initializeProcessField);
+ /**
+ * Conditionally add the <code>Transactional</code> annotation
+ *
+ * @param compilationUnit
+ */
+ protected void manageTransactional(CompilationUnit compilationUnit) {
+ if (transactionEnabled && context.hasDI()) {
+ LOG.info("Transaction is enabled, adding annotations...");
Review Comment:
set to debug level
##########
kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/ProcessResourceGenerator.java:
##########
@@ -314,40 +416,51 @@ public String generate() {
}
switchExpr.getEntries().add(0, userTask.getModelSwitchEntry());
}
-
}
+ }
- typeInterpolations.put("$Clazz$", resourceClazzName);
- typeInterpolations.put("$Type$", dataClazzName);
-
template.findAll(StringLiteralExpr.class).forEach(this::interpolateStrings);
- template.findAll(ClassOrInterfaceType.class).forEach(cls ->
interpolateTypes(cls, typeInterpolations));
-
- TagResourceGenerator.addTags(clazz, process, context);
-
-
template.findAll(MethodDeclaration.class).forEach(this::interpolateMethods);
-
- if (context.hasDI()) {
- template.findAll(FieldDeclaration.class,
- CodegenUtils::isProcessField).forEach(fd ->
context.getDependencyInjectionAnnotator().withNamedInjection(fd, processId));
- } else {
- template.findAll(FieldDeclaration.class,
-
CodegenUtils::isProcessField).forEach(this::initializeProcessField);
+ /**
+ * Conditionally add the <code>Transactional</code> annotation
+ *
+ * @param compilationUnit
+ */
+ protected void manageTransactional(CompilationUnit compilationUnit) {
+ if (transactionEnabled && context.hasDI()) {
+ LOG.info("Transaction is enabled, adding annotations...");
+ DependencyInjectionAnnotator dependencyInjectionAnnotator =
context.getDependencyInjectionAnnotator();
+ getRestMethods(compilationUnit)
+ .forEach(dependencyInjectionAnnotator::withTransactional);
}
+ }
- // if triggers are not empty remove createResource method as there is
another trigger to start process instances
- if ((!startable && !dynamic) || !isPublic()) {
- Optional<MethodDeclaration> createResourceMethod =
template.findFirst(MethodDeclaration.class).filter(md ->
md.getNameAsString().equals("createResource_" + processName));
- createResourceMethod.ifPresent(template::remove);
- }
+ /**
+ * Retrieves all the <b>Rest endpoint</b> <code>MethodDeclaration</code>s
+ *
+ * @param compilationUnit
+ * @return
+ */
+ protected Collection<MethodDeclaration> getRestMethods(CompilationUnit
compilationUnit) {
+ return compilationUnit.findAll(MethodDeclaration.class)
+ .stream()
+ .filter(this::isRest)
+ .toList();
+ }
- if (context.hasDI()) {
-
context.getDependencyInjectionAnnotator().withApplicationComponent(template);
+ /**
+ * Detect if a given <code>MethodDeclaration</code> represents a <b>Rest
endpoint</b> reading its annotations.
+ *
+ * @param methodDeclaration
+ * @return
+ */
+ protected boolean isRest(MethodDeclaration methodDeclaration) {
+ List<String> restMappings;
Review Comment:
set this logic inside the context, not here.
##########
kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/RestResourceSpringTemplate.java:
##########
@@ -43,6 +43,7 @@
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
Review Comment:
changes are not needed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]