pefernan commented on code in PR #3850:
URL:
https://github.com/apache/incubator-kie-kogito-runtimes/pull/3850#discussion_r1967555415
##########
kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/ProcessCodegen.java:
##########
@@ -459,10 +467,24 @@ protected Collection<GeneratedFile> internalGenerate() {
staticDependencyInjectionProducerGenerator.generate()
.entrySet()
.forEach(entry -> storeFile(PRODUCER_TYPE, entry.getKey(),
entry.getValue()));
+
Boolean isBusinessCalendarPresent =
context().getContextAttribute(IS_BUSINESS_CALENDAR_PRESENT, Boolean.class);
+ String customBusinessCalendarClassName = CodegenUtil.getProperty(this,
context(), CUSTOM_BUSINESS_CALENDAR_PROPERTY, String::valueOf, null);
if (Objects.nonNull(isBusinessCalendarPresent) &&
isBusinessCalendarPresent) {
Review Comment:
this could be an `||` we want to enter in this if in either case.
##########
kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/ProcessCodegen.java:
##########
@@ -459,10 +467,24 @@ protected Collection<GeneratedFile> internalGenerate() {
staticDependencyInjectionProducerGenerator.generate()
.entrySet()
.forEach(entry -> storeFile(PRODUCER_TYPE, entry.getKey(),
entry.getValue()));
+
Boolean isBusinessCalendarPresent =
context().getContextAttribute(IS_BUSINESS_CALENDAR_PRESENT, Boolean.class);
+ String customBusinessCalendarClassName = CodegenUtil.getProperty(this,
context(), CUSTOM_BUSINESS_CALENDAR_PROPERTY, String::valueOf, null);
if (Objects.nonNull(isBusinessCalendarPresent) &&
isBusinessCalendarPresent) {
-
staticDependencyInjectionProducerGenerator.generate(List.of(BUSINESS_CALENDAR_PRODUCER_TEMPLATE))
- .forEach((key, value) -> storeFile(PRODUCER_TYPE, key,
value));
+ String businessCalendarDeclarationStatement =
DEFAULT_BUSINESS_CALENDAR_INSTANCE;
+ if (Objects.nonNull(customBusinessCalendarClassName)) {
+ ClassOrInterfaceType customBusinessCalendarClass =
StaticJavaParser.parseClassOrInterfaceType(customBusinessCalendarClassName);
Review Comment:
I guess that here you could go with a Class.forName... and check if the
class is assignable to BusinessCalendar.class, and if it's not an
interface/abstract
##########
kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/StaticDependencyInjectionProducerGenerator.java:
##########
@@ -58,12 +60,23 @@ public Map<String, String> generate() {
* @return Map with the generated resources
*/
public Map<String, String> generate(List<String> templates) {
+ return generate(templates, null);
+ }
+
+ public Map<String, String> generate(List<String> templates, String
customClass) {
Review Comment:
This has to be rolled back
##########
kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/ProcessCodegen.java:
##########
@@ -582,4 +595,50 @@ public Optional<ApplicationSection> section() {
public int priority() {
return 10;
}
+
+ private void processProducerTemplate(Optional<Expression> statement) {
+ TemplatedGenerator generator = TemplatedGenerator.builder()
+ .withTemplateBasePath("/class-templates/producer/")
+ .withFallbackContext(JavaKogitoBuildContext.CONTEXT_NAME)
+ .withTargetTypeName(BUSINESS_CALENDAR_PRODUCER_TEMPLATE)
+ .build(context(), BUSINESS_CALENDAR_PRODUCER_TEMPLATE);
+ CompilationUnit compilationUnit = generator.compilationUnitOrThrow();
+
+ statement.ifPresent(expression ->
compilationUnit.findFirst(ClassOrInterfaceDeclaration.class)
+ .flatMap(NodeWithMembers::getDefaultConstructor)
+ .ifPresent(constructor ->
constructor.getBody().getStatements().stream()
+ .filter(Statement::isExpressionStmt)
+ .flatMap(stmt -> stmt.getChildNodes().stream())
+ .filter(AssignExpr.class::isInstance)
+ .map(AssignExpr.class::cast)
+ .filter(assignExpr -> assignExpr.getTarget()
instanceof FieldAccessExpr field &&
+
BUSINESS_CALENDAR_FIELD_NAME.equals(field.getNameAsString()))
+ .forEach(assignExpr ->
assignExpr.setValue(expression))));
+
+ storeFile(PRODUCER_TYPE, generator.generatedFilePath(),
compilationUnit.toString());
+ }
+
+ private Optional<Expression>
deriveBusinessCalendarDeclarationStatement(String businessCalendarClassName) {
+ Class<?> businessCalendarClass;
+ boolean validBusinessCalendar = false;
+ ObjectCreationExpr declarationStmt = null;
+ if (Objects.isNull(businessCalendarClassName)) {
+ return Optional.empty();
+ }
+ try {
+ businessCalendarClass = Class.forName(businessCalendarClassName,
true, context().getClassLoader());
Review Comment:
I'd also check here the class modifiers to throw an exception if the class
is abstract or interface
```
Class<? extends BusinessCalendar> businessCalendarClass;
...
int mod = businessCalendarClass.getModifiers();
if (Modifier.isAbstract(mod) || Modifier.isInterface(mod)) {
throw new ProcessCodegenException(...);
}
```
--
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]