Skip to content

Commit

Permalink
[incubator-kie-issues#1473] Add withTransactional method to Dependenc…
Browse files Browse the repository at this point in the history
…yInjectionAnnotator (#6090)

* [incubator-kie-issues#1473] Add withTransactional method to  DependencyInjectionAnnotator

* [incubator-kie-issues#1473] Refactoring DependencyInjectionAnnotator. Add "Patch" annotation to RestAnnotators

* [incubator-kie-issues#1473] Restore formatting

---------

Co-authored-by: Gabriele-Cardosi <[email protected]>
  • Loading branch information
gitgabrio and Gabriele-Cardosi authored Oct 3, 2024
1 parent 7052421 commit 5448192
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@ default <T extends NodeWithAnnotations<?>> T withInjection(T node) {
*/
<T extends NodeWithAnnotations<?>> T withConfigInjection(T node, String configKey, String defaultValue);

/**
* Annotates given node with Transactional annotation
*
* @param node node to be annotated
*/
default <T extends NodeWithAnnotations<?>> T withTransactional(T node) {
node.addAnnotation(getTransactionalAnnotation());
return node;
}

String getTransactionalAnnotation();

/**
* Annotates and enhances method used to produce messages
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ public <T extends NodeWithAnnotations<?>> T withFactoryMethod(T node) {
return node;
}

@Override
public String getTransactionalAnnotation() {
return "jakarta.transaction.Transactional";
}

@Override
public <T extends NodeWithAnnotations<?>> T withTagAnnotation(T node, NodeList<MemberValuePair> attributes) {
node.addAnnotation(new NormalAnnotationExpr(new Name("org.eclipse.microprofile.openapi.annotations.tags.Tag"), attributes));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
*/
package org.drools.codegen.common.di.impl;

import java.util.Collection;
import java.util.Collections;
import java.util.Optional;

import com.github.javaparser.ast.NodeList;
import com.github.javaparser.ast.expr.BinaryExpr;
import com.github.javaparser.ast.expr.BooleanLiteralExpr;
Expand All @@ -36,10 +40,6 @@
import com.github.javaparser.ast.type.ClassOrInterfaceType;
import org.drools.codegen.common.di.DependencyInjectionAnnotator;

import java.util.Collection;
import java.util.Collections;
import java.util.Optional;

public class SpringDependencyInjectionAnnotator implements DependencyInjectionAnnotator {

@Override
Expand Down Expand Up @@ -181,6 +181,11 @@ public <T extends NodeWithAnnotations<?>> T withFactoryClass(T node) {
return node;
}

@Override
public String getTransactionalAnnotation() {
return "org.springframework.transaction.annotation.Transactional";
}

@Override
public <T extends NodeWithAnnotations<?>> T withFactoryMethod(T node) {
node.addAnnotation("org.springframework.context.annotation.Bean");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class CDIRestAnnotator implements RestAnnotator {

@Override
public <T extends NodeWithAnnotations<?>> boolean isRestAnnotated(T node) {
return Stream.of("POST", "GET", "PUT", "DELETE")
return Stream.of("POST", "GET", "PUT", "DELETE", "PATCH")
.map(node::getAnnotationByName)
.anyMatch(Optional::isPresent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class SpringRestAnnotator implements RestAnnotator {

@Override
public <T extends NodeWithAnnotations<?>> boolean isRestAnnotated(T node) {
return Stream.of("PostMapping", "GetMapping", "PutMapping", "DeleteMapping")
return Stream.of("PostMapping", "GetMapping", "PutMapping", "DeleteMapping", "PatchMapping")
.map(node::getAnnotationByName)
.anyMatch(Optional::isPresent);
}
Expand Down

0 comments on commit 5448192

Please sign in to comment.