Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[incubator-kie-issues-1517] Add Transactional Rest endpoints to UserTasks #3701

Merged
merged 4 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@

import org.kie.kogito.codegen.api.Generator;
import org.kie.kogito.codegen.api.context.KogitoBuildContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class CodegenUtil {

private static final Logger LOG = LoggerFactory.getLogger(CodegenUtil.class);
/**
* Flag used to configure transaction enabling. Default to <code>true</code>
*/
Expand Down Expand Up @@ -61,7 +65,9 @@ public static String globalProperty(String propertyName) {
* @see CodegenUtil#getProperty
*/
public static boolean isTransactionEnabled(Generator generator, KogitoBuildContext context) {
return getProperty(generator, context, TRANSACTION_ENABLED, Boolean::parseBoolean, true);
boolean propertyValue = getProperty(generator, context, TRANSACTION_ENABLED, Boolean::parseBoolean, true);
LOG.info("trying to compute property {} for generator {} property with value {}", generator.name(), TRANSACTION_ENABLED, propertyValue);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a nit-pick, generator.name() and TRANSACTION_ENABLED should be switched around

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

return propertyValue;
}

/**
Expand All @@ -81,6 +87,7 @@ public static <T> T getProperty(Generator generator, KogitoBuildContext context,
}

String globalProperty = globalProperty(propertyName);

if (isApplicationPropertyDefined(context, globalProperty)) {
return converter.apply(getApplicationProperty(context, globalProperty));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public class UserTaskCodegen extends AbstractGenerator {
BPMN_SEMANTIC_MODULES.addSemanticModule(new BPMNDISemanticModule());
}

public static final String SECTION_CLASS_NAME = "usertask";
public static final String SECTION_CLASS_NAME = "usertasks";

private TemplatedGenerator templateGenerator;
private List<Work> descriptors;
Expand Down Expand Up @@ -162,19 +162,19 @@ protected Collection<GeneratedFile> internalGenerate() {

public GeneratedFile generateRestEndpiont() {
String packageName = context().getPackageName();
CompilationUnit compilationUnit = producerTemplateGenerator.compilationUnitOrThrow("Not rest endpoints template found for user tasks");
CompilationUnit compilationUnit = restTemplateGenerator.compilationUnitOrThrow("Not rest endpoints template found for user tasks");
compilationUnit.setPackageDeclaration(packageName);
if (CodegenUtil.isTransactionEnabled(this, context())) {
compilationUnit.findAll(MethodDeclaration.class).stream().filter(MethodDeclaration::isPublic).forEach(context().getDependencyInjectionAnnotator()::withTransactional);
}
String className = compilationUnit.findFirst(ClassOrInterfaceDeclaration.class).get().getNameAsString();
String urlBase = packageName.replaceAll("\\.", File.separator);
return new GeneratedFile(GeneratedFileType.SOURCE, Path.of(urlBase).resolve(className + ".java"), compilationUnit.toString());
return new GeneratedFile(GeneratedFileType.REST, Path.of(urlBase).resolve(className + ".java"), compilationUnit.toString());
}

public GeneratedFile generateProducer() {
String packageName = context().getPackageName();
CompilationUnit compilationUnit = restTemplateGenerator.compilationUnitOrThrow("No producer template found for user tasks");
CompilationUnit compilationUnit = producerTemplateGenerator.compilationUnitOrThrow("No producer template found for user tasks");
compilationUnit.setPackageDeclaration(packageName);
String className = compilationUnit.findFirst(ClassOrInterfaceDeclaration.class).get().getNameAsString();
String urlBase = packageName.replaceAll("\\.", File.separator);
Expand Down
Loading