This is an automated email from the ASF dual-hosted git repository.
djoseph pushed a commit to branch main
in repository
https://gitbox.apache.org/repos/asf/incubator-kie-kogito-runtimes.git
The following commit(s) were added to refs/heads/main by this push:
new e0095fddde Add a process configuration option for getter prefix for
Boolean object (#4032)
e0095fddde is described below
commit e0095fddde74523508f59a7c5c0df53a80922f50
Author: Soniya Abraham <[email protected]>
AuthorDate: Fri Aug 22 22:30:33 2025 +0530
Add a process configuration option for getter prefix for Boolean object
(#4032)
* Add a process configuration option for getter prefix for Boolean object
* Added license headers
* Formatting the files
* Adding the fix in the JandexProtoGenerator aswell and Adding new test
file for Person with Boolean object
* Adding a new line at the end of the file
---------
Co-authored-by: soniyaabraham <[email protected]>
---
.../api/context/ContextAttributesConstants.java | 2 +
.../marshaller/AbstractMarshallerGenerator.java | 8 +-
.../process/persistence/proto/ProtoGenerator.java | 1 +
.../proto/ReflectionProtoGenerator.java | 4 +
.../kogito/codegen/process/util/CodegenUtil.java | 18 ++
.../codegen/data/PersonWithBooleanGetAccessor.java | 104 +++++++
.../codegen/data/PersonWithBooleanObject.java | 314 +++++++++++++++++++++
.../AbstractMarshallerGeneratorTest.java | 59 ++++
.../codegen/process/util/CodegenUtilTest.java | 56 ++++
.../workflow/deployment/JandexProtoGenerator.java | 2 +
.../workflow/deployment/JandexTestUtils.java | 6 +-
11 files changed, 572 insertions(+), 2 deletions(-)
diff --git
a/kogito-codegen-modules/kogito-codegen-api/src/main/java/org/kie/kogito/codegen/api/context/ContextAttributesConstants.java
b/kogito-codegen-modules/kogito-codegen-api/src/main/java/org/kie/kogito/codegen/api/context/ContextAttributesConstants.java
index ce08076802..2203b15db8 100644
---
a/kogito-codegen-modules/kogito-codegen-api/src/main/java/org/kie/kogito/codegen/api/context/ContextAttributesConstants.java
+++
b/kogito-codegen-modules/kogito-codegen-api/src/main/java/org/kie/kogito/codegen/api/context/ContextAttributesConstants.java
@@ -29,6 +29,8 @@ public final class ContextAttributesConstants {
public static final String KOGITO_FAULT_TOLERANCE_ENABLED =
"kogito.faultToleranceEnabled";
+ public static final String
KOGITO_CODEGEN_BOOLEAN_OBJECT_ACCESSOR_BEHAVIOUR =
"kogito.codegen.booleanObjectAccessorBehaviour";
+
private ContextAttributesConstants() {
}
}
diff --git
a/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/persistence/marshaller/AbstractMarshallerGenerator.java
b/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/persistence/marshaller/AbstractMarshallerGenerator.java
index 26cfd1c7ca..113db6a3ec 100644
---
a/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/persistence/marshaller/AbstractMarshallerGenerator.java
+++
b/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/persistence/marshaller/AbstractMarshallerGenerator.java
@@ -48,6 +48,7 @@ import
org.kie.kogito.codegen.api.template.InvalidTemplateException;
import org.kie.kogito.codegen.api.template.TemplatedGenerator;
import org.kie.kogito.codegen.core.BodyDeclarationComparator;
import org.kie.kogito.codegen.process.persistence.ExclusionTypeUtils;
+import org.kie.kogito.codegen.process.util.CodegenUtil;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.NodeList;
@@ -79,6 +80,7 @@ import static
com.github.javaparser.ast.Modifier.Keyword.PUBLIC;
import static com.github.javaparser.ast.expr.BinaryExpr.Operator.EQUALS;
import static java.lang.String.format;
import static
org.kie.kogito.codegen.process.persistence.proto.ProtoGenerator.KOGITO_JAVA_CLASS_OPTION;
+import static
org.kie.kogito.codegen.process.persistence.proto.ProtoGenerator.KOGITO_JAVA_TYPE_BOOLEAN_OBJECT_OPTION;
public abstract class AbstractMarshallerGenerator<T> implements
MarshallerGenerator {
@@ -123,6 +125,7 @@ public abstract class AbstractMarshallerGenerator<T>
implements MarshallerGenera
serializationContext.registerProtoFiles(proto);
Map<String, FileDescriptor> descriptors =
serializationContext.getFileDescriptors();
+ String booleanObjectAccessorProperty =
CodegenUtil.getBooleanObjectAccessor(context);
for (Entry<String, FileDescriptor> entry : descriptors.entrySet()) {
@@ -184,7 +187,10 @@ public abstract class AbstractMarshallerGenerator<T>
implements MarshallerGenera
// has a mapped type
read = new MethodCallExpr(new NameExpr("reader"),
"read" + protoStreamMethodType)
.addArgument(new
StringLiteralExpr(field.getName()));
- String accessor =
protoStreamMethodType.equals("Boolean") ? "is" : "get";
+
+ String accessor =
+ protoStreamMethodType.equals("Boolean") ?
(field.getOptionByName(KOGITO_JAVA_TYPE_BOOLEAN_OBJECT_OPTION) != null ?
booleanObjectAccessorProperty : "is") : "get";
+
write = new MethodCallExpr(new NameExpr("writer"),
"write" + protoStreamMethodType)
.addArgument(new
StringLiteralExpr(field.getName()))
.addArgument(new MethodCallExpr(new
NameExpr("t"), accessor + StringUtils.ucFirst(field.getName())));
diff --git
a/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/persistence/proto/ProtoGenerator.java
b/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/persistence/proto/ProtoGenerator.java
index 9009a29c7e..fe32c217a4 100644
---
a/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/persistence/proto/ProtoGenerator.java
+++
b/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/persistence/proto/ProtoGenerator.java
@@ -29,6 +29,7 @@ public interface ProtoGenerator {
GeneratedFileType PROTO_TYPE = GeneratedFileType.of("PROTO",
GeneratedFileType.Category.STATIC_HTTP_RESOURCE);
String INDEX_COMMENT = "@Field(index = Index.YES, store = Store.YES)
@SortableField";
String KOGITO_JAVA_CLASS_OPTION = "kogito_java_class";
+ String KOGITO_JAVA_TYPE_BOOLEAN_OBJECT_OPTION =
"kogito_java_type_boolean_object";
String KOGITO_SERIALIZABLE = "kogito.Serializable";
String ARRAY = "Array";
String COLLECTION = "Collection";
diff --git
a/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/persistence/proto/ReflectionProtoGenerator.java
b/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/persistence/proto/ReflectionProtoGenerator.java
index c67c538192..05f3e7f57a 100644
---
a/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/persistence/proto/ReflectionProtoGenerator.java
+++
b/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/persistence/proto/ReflectionProtoGenerator.java
@@ -121,7 +121,11 @@ public class ReflectionProtoGenerator extends
AbstractProtoGenerator<Class<?>> {
protoField.setComment(completeFieldComment);
if (KOGITO_SERIALIZABLE.equals(protoType)) {
protoField.setOption(format("[%s = \"%s\"]",
KOGITO_JAVA_CLASS_OPTION, pd.getPropertyType().getCanonicalName()));
+
+ } else if ("java.lang.Boolean".equals(fieldTypeString)) {
+ protoField.setOption(format("[%s = \"%s\"]",
KOGITO_JAVA_TYPE_BOOLEAN_OBJECT_OPTION, fieldTypeString));
}
+
}
message.setComment(messageComment);
proto.addMessage(message);
diff --git
a/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/util/CodegenUtil.java
b/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/util/CodegenUtil.java
index c7c1d414f7..19baa76a2d 100644
---
a/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/util/CodegenUtil.java
+++
b/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/util/CodegenUtil.java
@@ -26,6 +26,7 @@ import
org.kie.kogito.codegen.api.context.impl.JavaKogitoBuildContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static
org.kie.kogito.codegen.api.context.ContextAttributesConstants.KOGITO_CODEGEN_BOOLEAN_OBJECT_ACCESSOR_BEHAVIOUR;
import static
org.kie.kogito.codegen.api.context.ContextAttributesConstants.KOGITO_FAULT_TOLERANCE_ENABLED;
public final class CodegenUtil {
@@ -123,4 +124,21 @@ public final class CodegenUtil {
return !JavaKogitoBuildContext.CONTEXT_NAME.equals(context.name()) &&
isFaultToleranceEnabled;
}
+
+ public static String getBooleanObjectAccessor(KogitoBuildContext context) {
+ return
context.getApplicationProperty(KOGITO_CODEGEN_BOOLEAN_OBJECT_ACCESSOR_BEHAVIOUR)
+ .map(value -> {
+ switch (value) {
+ case "isPrefix":
+ return "is";
+ case "javaBeans":
+ return "get";
+ default:
+ throw new IllegalArgumentException(
+ "Property " +
KOGITO_CODEGEN_BOOLEAN_OBJECT_ACCESSOR_BEHAVIOUR +
+ " defined but does not contain
proper value: expected 'isPrefix' or 'javaBeans'");
+ }
+ })
+ .orElse("is");
+ }
}
diff --git
a/kogito-codegen-modules/kogito-codegen-processes/src/test/java/org/kie/kogito/codegen/data/PersonWithBooleanGetAccessor.java
b/kogito-codegen-modules/kogito-codegen-processes/src/test/java/org/kie/kogito/codegen/data/PersonWithBooleanGetAccessor.java
new file mode 100644
index 0000000000..e76d6a0417
--- /dev/null
+++
b/kogito-codegen-modules/kogito-codegen-processes/src/test/java/org/kie/kogito/codegen/data/PersonWithBooleanGetAccessor.java
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.kogito.codegen.data;
+
+import java.util.Objects;
+
+public class PersonWithBooleanGetAccessor {
+ private String id;
+ private String name;
+ private int age;
+ private boolean adult;
+ private Boolean married;
+
+ public PersonWithBooleanGetAccessor() {
+ }
+
+ public PersonWithBooleanGetAccessor(String name, int age) {
+ this.name = name;
+ this.age = age;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+ public boolean isAdult() {
+ return adult;
+ }
+
+ public void setAdult(boolean adult) {
+ this.adult = adult;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public Boolean getMarried() {
+ return married;
+ }
+
+ public void setMarried(Boolean married) {
+ this.married = married;
+ }
+
+ @Override
+ public String toString() {
+ return "Person{" +
+ "id='" + id + '\'' +
+ ", name='" + name + '\'' +
+ ", age=" + age +
+ ", adult=" + adult +
+ ", married=" + married +
+ '}';
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (o == null || getClass() != o.getClass())
+ return false;
+ PersonWithBooleanGetAccessor person = (PersonWithBooleanGetAccessor) o;
+ return age == person.age && adult == person.adult && married ==
person.married;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(name, age, adult, married);
+ }
+
+}
diff --git
a/kogito-codegen-modules/kogito-codegen-processes/src/test/java/org/kie/kogito/codegen/data/PersonWithBooleanObject.java
b/kogito-codegen-modules/kogito-codegen-processes/src/test/java/org/kie/kogito/codegen/data/PersonWithBooleanObject.java
new file mode 100644
index 0000000000..77b9f26757
--- /dev/null
+++
b/kogito-codegen-modules/kogito-codegen-processes/src/test/java/org/kie/kogito/codegen/data/PersonWithBooleanObject.java
@@ -0,0 +1,314 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.kogito.codegen.data;
+
+import java.math.BigDecimal;
+import java.time.Duration;
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.OffsetDateTime;
+import java.time.ZonedDateTime;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
+import static java.util.Arrays.asList;
+
+public class PersonWithBooleanObject {
+
+ private static final String ADDRESS_SEPARATOR = "; ";
+
+ private String id;
+ private String name;
+ private int age;
+ private byte[] bytes;
+ private boolean adult;
+ private Boolean married;
+ private PersonWithBooleanObject parent;
+ private PersonWithBooleanObject[] relatives;
+ private Instant instant;
+ private LocalDateTime localDateTime;
+ private LocalDate localDate;
+ private Duration duration;
+ private ZonedDateTime zonedDateTime;
+ private OffsetDateTime offsetDateTime;
+ private Date date;
+ private BigDecimal bigDecimal;
+ @JsonIgnore
+ private Money salary;
+ @JsonIgnore
+ private Money[] earnings;
+ @JsonIgnore
+ private List<Money> expenses;
+
+ private transient String ignoreMe;
+
+ private static String staticallyIgnoreMe;
+
+ private transient List<Address> addresses = new ArrayList<>();
+
+ public PersonWithBooleanObject() {
+ }
+
+ public PersonWithBooleanObject(String name, int age) {
+ this.name = name;
+ this.age = age;
+ salary = Money.of(BigDecimal.valueOf(100));
+ earnings = new Money[] { Money.of(BigDecimal.valueOf(200)) };
+ expenses = asList(Money.of(BigDecimal.valueOf(50)));
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+ public boolean isAdult() {
+ return adult;
+ }
+
+ public void setAdult(boolean adult) {
+ this.adult = adult;
+ }
+
+ public String getIgnoreMe() {
+ return ignoreMe;
+ }
+
+ public void setIgnoreMe(String ignoreMe) {
+ this.ignoreMe = ignoreMe;
+ }
+
+ public static String getStaticallyIgnoreMe() {
+ return staticallyIgnoreMe;
+ }
+
+ public static void setStaticallyIgnoreMe(String staticallyIgnoreMe) {
+ PersonWithBooleanObject.staticallyIgnoreMe = staticallyIgnoreMe;
+ }
+
+ public void addAddress(final Address address) {
+ addresses.add(address);
+ }
+
+ public List<Address> getAddresses() {
+ return addresses;
+ }
+
+ public void setAddresses(final List<Address> addresses) {
+ this.addresses = addresses;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public PersonWithBooleanObject getParent() {
+ return parent;
+ }
+
+ public void setParent(PersonWithBooleanObject parent) {
+ this.parent = parent;
+ }
+
+ public Instant getInstant() {
+ return instant;
+ }
+
+ public void setInstant(Instant instant) {
+ this.instant = instant;
+ }
+
+ public LocalDateTime getLocalDateTime() {
+ return localDateTime;
+ }
+
+ public void setLocalDateTime(LocalDateTime localDateTime) {
+ this.localDateTime = localDateTime;
+ }
+
+ public LocalDate getLocalDate() {
+ return localDate;
+ }
+
+ public void setLocalDate(LocalDate localDate) {
+ this.localDate = localDate;
+ }
+
+ public Duration getDuration() {
+ return duration;
+ }
+
+ public void setDuration(Duration duration) {
+ this.duration = duration;
+ }
+
+ public ZonedDateTime getZonedDateTime() {
+ return zonedDateTime;
+ }
+
+ public void setZonedDateTime(ZonedDateTime zonedDateTime) {
+ this.zonedDateTime = zonedDateTime;
+ }
+
+ public OffsetDateTime getOffsetDateTime() {
+ return offsetDateTime;
+ }
+
+ public void setOffsetDateTime(OffsetDateTime offsetDateTime) {
+ this.offsetDateTime = offsetDateTime;
+ }
+
+ public Date getDate() {
+ return date;
+ }
+
+ public BigDecimal getBigDecimal() {
+ return bigDecimal;
+ }
+
+ public void setBigDecimal(BigDecimal bigDecimal) {
+ this.bigDecimal = bigDecimal;
+ }
+
+ public Money getSalary() {
+ return salary;
+ }
+
+ public void setSalary(Money salary) {
+ this.salary = salary;
+ }
+
+ public PersonWithBooleanObject[] getRelatives() {
+ return relatives;
+ }
+
+ public void setRelatives(PersonWithBooleanObject[] relatives) {
+ this.relatives = relatives;
+ }
+
+ public void setDate(Date date) {
+ this.date = date;
+ }
+
+ public byte[] getBytes() {
+ return bytes;
+ }
+
+ public void setBytes(byte[] bytes) {
+ this.bytes = bytes;
+ }
+
+ @JsonIgnore
+ public String getAddressesStr() {
+ return getAddresses() != null ? getAddresses().stream().map(
+ a ->
a.getAddress()).collect(Collectors.joining(ADDRESS_SEPARATOR)) : null;
+ }
+
+ public void setAddressesStr(String addresses) {
+ setAddresses(
+ Arrays.stream(addresses.split(ADDRESS_SEPARATOR)).map(a ->
Address.of(a)).collect(Collectors.toList()));
+ }
+
+ public Money[] getEarnings() {
+ return earnings;
+ }
+
+ public void setEarnings(Money[] earnings) {
+ this.earnings = earnings;
+ }
+
+ public List<Money> getExpenses() {
+ return expenses;
+ }
+
+ public void setExpenses(List<Money> expenses) {
+ this.expenses = expenses;
+ }
+
+ public Boolean isMarried() {
+ return married;
+ }
+
+ public void setMarried(Boolean married) {
+ this.married = married;
+ }
+
+ @Override
+ public String toString() {
+ return "Person{" +
+ "id='" + id + '\'' +
+ ", name='" + name + '\'' +
+ ", age=" + age +
+ ", adult=" + adult +
+ ", married=" + married +
+ ", parent=" + parent +
+ ", relatives=" + Arrays.toString(relatives) +
+ ", instant=" + instant +
+ ", localDateTime=" + localDateTime +
+ ", localDate=" + localDate +
+ ", duration=" + duration +
+ ", zonedDateTime=" + zonedDateTime +
+ ", offsetDateTime=" + offsetDateTime +
+ ", date=" + date +
+ ", bigDecimal=" + bigDecimal +
+ ", salary=" + salary +
+ ", ignoreMe='" + ignoreMe + '\'' +
+ ", addresses=" + addresses +
+ '}';
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (o == null || getClass() != o.getClass())
+ return false;
+ PersonWithBooleanObject person = (PersonWithBooleanObject) o;
+ return age == person.age && adult == person.adult && married ==
person.married && Objects.equals(name, person.name) && Objects.equals(parent,
person.parent)
+ && Objects.equals(ignoreMe, person.ignoreMe)
+ && Objects.equals(addresses, person.addresses);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(name, age, adult, married, parent, ignoreMe,
addresses);
+ }
+}
diff --git
a/kogito-codegen-modules/kogito-codegen-processes/src/test/java/org/kie/kogito/codegen/process/persistence/marshaller/AbstractMarshallerGeneratorTest.java
b/kogito-codegen-modules/kogito-codegen-processes/src/test/java/org/kie/kogito/codegen/process/persistence/marshaller/AbstractMarshallerGeneratorTest.java
index ac8430f2f7..d8d7a5fa40 100644
---
a/kogito-codegen-modules/kogito-codegen-processes/src/test/java/org/kie/kogito/codegen/process/persistence/marshaller/AbstractMarshallerGeneratorTest.java
+++
b/kogito-codegen-modules/kogito-codegen-processes/src/test/java/org/kie/kogito/codegen/process/persistence/marshaller/AbstractMarshallerGeneratorTest.java
@@ -34,6 +34,7 @@ import org.kie.kogito.codegen.data.AnswerWithAnnotations;
import org.kie.kogito.codegen.data.Person;
import org.kie.kogito.codegen.data.PersonWithAddress;
import org.kie.kogito.codegen.data.PersonWithAddresses;
+import org.kie.kogito.codegen.data.PersonWithBooleanGetAccessor;
import org.kie.kogito.codegen.data.PersonWithList;
import org.kie.kogito.codegen.data.Question;
import org.kie.kogito.codegen.data.QuestionWithAnnotatedEnum;
@@ -51,6 +52,9 @@ import
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import static java.util.stream.Collectors.toList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static
org.kie.kogito.codegen.api.context.ContextAttributesConstants.KOGITO_CODEGEN_BOOLEAN_OBJECT_ACCESSOR_BEHAVIOUR;
public abstract class AbstractMarshallerGeneratorTest<T> {
@@ -90,6 +94,61 @@ public abstract class AbstractMarshallerGeneratorTest<T> {
assertThat(compile(classes).getErrors()).isEmpty();
}
+ @Test
+ void testPersonWithBooleanIsAccessorMarshallers() throws Exception {
+
context.setApplicationProperty(KOGITO_CODEGEN_BOOLEAN_OBJECT_ACCESSOR_BEHAVIOUR,
"isPrefix");
+ ProtoGenerator generator =
protoGeneratorBuilder().withDataClasses(convertTypes(Person.class)).build(null);
+
+ Proto proto = generator.protoOfDataClasses("org.kie.kogito.test",
"import \"kogito-types.proto\";");
+ assertThat(proto).isNotNull();
+ assertThat(proto.getMessages()).hasSize(1);
+
+ MarshallerGenerator marshallerGenerator = withGenerator(Person.class);
+ List<CompilationUnit> classes =
marshallerGenerator.generate(proto.serialize());
+ assertThat(classes).isNotNull().hasSize(1);
+
+ Optional<ClassOrInterfaceDeclaration> marshallerClass =
classes.get(0).getClassByName("PersonMessageMarshaller");
+ assertThat(marshallerClass).isPresent();
+
+ assertThat(compile(classes).getErrors()).isEmpty();
+ }
+
+ @Test
+ void testPersonWithBooleanGetAccessorMarshallers() throws Exception {
+
context.setApplicationProperty(KOGITO_CODEGEN_BOOLEAN_OBJECT_ACCESSOR_BEHAVIOUR,
"javaBeans");
+ ProtoGenerator generator =
protoGeneratorBuilder().withDataClasses(convertTypes(PersonWithBooleanGetAccessor.class)).build(null);
+
+ Proto proto = generator.protoOfDataClasses("org.kie.kogito.test",
"import \"kogito-types.proto\";");
+ assertThat(proto).isNotNull();
+ assertThat(proto.getMessages()).hasSize(1);
+
+ MarshallerGenerator marshallerGenerator =
withGenerator(PersonWithBooleanGetAccessor.class);
+ List<CompilationUnit> classes =
marshallerGenerator.generate(proto.serialize());
+ assertThat(classes).isNotNull().hasSize(1);
+
+ Optional<ClassOrInterfaceDeclaration> marshallerClass =
classes.get(0).getClassByName("PersonWithBooleanGetAccessorMessageMarshaller");
+ assertThat(marshallerClass).isPresent();
+
+ assertThat(compile(classes).getErrors()).isEmpty();
+ }
+
+ @Test
+ void testInvalidBooleanAccessorThrowsMarshaller() throws Exception {
+
context.setApplicationProperty(KOGITO_CODEGEN_BOOLEAN_OBJECT_ACCESSOR_BEHAVIOUR,
"get");
+ ProtoGenerator generator =
protoGeneratorBuilder().withDataClasses(convertTypes(Person.class)).build(null);
+
+ Proto proto = generator.protoOfDataClasses("org.kie.kogito.test",
"import \"kogito-types.proto\";");
+ assertThat(proto).isNotNull();
+ assertThat(proto.getMessages()).hasSize(1);
+
+ MarshallerGenerator marshallerGenerator =
withGenerator(PersonWithBooleanGetAccessor.class);
+ Exception exception = assertThrows(IllegalArgumentException.class, ()
-> {
+ marshallerGenerator.generate(proto.serialize());
+ });
+ assertEquals("Property " +
KOGITO_CODEGEN_BOOLEAN_OBJECT_ACCESSOR_BEHAVIOUR + " defined but does not
contain proper value: expected 'isPrefix' or 'javaBeans'",
exception.getMessage());
+
+ }
+
@Test
void testPersonWithListMarshallers() throws Exception {
ProtoGenerator generator =
protoGeneratorBuilder().withDataClasses(convertTypes(PersonWithList.class)).build(null);
diff --git
a/kogito-codegen-modules/kogito-codegen-processes/src/test/java/org/kie/kogito/codegen/process/util/CodegenUtilTest.java
b/kogito-codegen-modules/kogito-codegen-processes/src/test/java/org/kie/kogito/codegen/process/util/CodegenUtilTest.java
new file mode 100644
index 0000000000..e57c7a10f4
--- /dev/null
+++
b/kogito-codegen-modules/kogito-codegen-processes/src/test/java/org/kie/kogito/codegen/process/util/CodegenUtilTest.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.kogito.codegen.process.util;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.kie.kogito.codegen.api.context.KogitoBuildContext;
+import org.kie.kogito.codegen.api.context.impl.QuarkusKogitoBuildContext;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static
org.kie.kogito.codegen.api.context.ContextAttributesConstants.KOGITO_CODEGEN_BOOLEAN_OBJECT_ACCESSOR_BEHAVIOUR;
+import static org.kie.kogito.codegen.process.util.CodegenUtil.*;
+
+public class CodegenUtilTest {
+
+ private KogitoBuildContext context;
+
+ @BeforeEach
+ public void setup() {
+ this.context = QuarkusKogitoBuildContext.builder().build();
+ }
+
+ @Test
+ public void testGetBooleanObjectAccessor() {
+ assertEquals("is", getBooleanObjectAccessor(context));
+
+
context.setApplicationProperty(KOGITO_CODEGEN_BOOLEAN_OBJECT_ACCESSOR_BEHAVIOUR,
"javaBeans");
+ assertEquals("get", getBooleanObjectAccessor(context));
+
+
context.setApplicationProperty(KOGITO_CODEGEN_BOOLEAN_OBJECT_ACCESSOR_BEHAVIOUR,
"isPrefix");
+ assertEquals("is", getBooleanObjectAccessor(context));
+
+
context.setApplicationProperty(KOGITO_CODEGEN_BOOLEAN_OBJECT_ACCESSOR_BEHAVIOUR,
"get1");
+ Exception exception = assertThrows(IllegalArgumentException.class, ()
-> {
+ getBooleanObjectAccessor(context);
+ });
+ assertEquals("Property " +
KOGITO_CODEGEN_BOOLEAN_OBJECT_ACCESSOR_BEHAVIOUR + " defined but does not
contain proper value: expected 'isPrefix' or 'javaBeans'",
exception.getMessage());
+ }
+}
diff --git
a/quarkus/extensions/kogito-quarkus-workflow-extension-common/kogito-quarkus-workflow-common-deployment/src/main/java/org/kie/kogito/quarkus/workflow/deployment/JandexProtoGenerator.java
b/quarkus/extensions/kogito-quarkus-workflow-extension-common/kogito-quarkus-workflow-common-deployment/src/main/java/org/kie/kogito/quarkus/workflow/deployment/JandexProtoGenerator.java
index f73d821a67..9aabb4dc56 100644
---
a/quarkus/extensions/kogito-quarkus-workflow-extension-common/kogito-quarkus-workflow-common-deployment/src/main/java/org/kie/kogito/quarkus/workflow/deployment/JandexProtoGenerator.java
+++
b/quarkus/extensions/kogito-quarkus-workflow-extension-common/kogito-quarkus-workflow-common-deployment/src/main/java/org/kie/kogito/quarkus/workflow/deployment/JandexProtoGenerator.java
@@ -175,6 +175,8 @@ public class JandexProtoGenerator extends
AbstractProtoGenerator<ClassInfo> {
protoField.setComment(completeFieldComment);
if (KOGITO_SERIALIZABLE.equals(protoType)) {
protoField.setOption(format("[%s = \"%s\"]",
KOGITO_JAVA_CLASS_OPTION, fieldTypeString.equals(ARRAY) ? pd.type().toString()
: pd.type().name().toString()));
+ } else if ("java.lang.Boolean".equals(fieldTypeString)) {
+ protoField.setOption(format("[%s = \"%s\"]",
KOGITO_JAVA_TYPE_BOOLEAN_OBJECT_OPTION, fieldTypeString));
}
}
message.setComment(messageComment);
diff --git
a/quarkus/extensions/kogito-quarkus-workflow-extension-common/kogito-quarkus-workflow-common-deployment/src/test/java/org/kie/kogito/quarkus/workflow/deployment/JandexTestUtils.java
b/quarkus/extensions/kogito-quarkus-workflow-extension-common/kogito-quarkus-workflow-common-deployment/src/test/java/org/kie/kogito/quarkus/workflow/deployment/JandexTestUtils.java
index 4aa815b09f..2201a3d51b 100644
---
a/quarkus/extensions/kogito-quarkus-workflow-extension-common/kogito-quarkus-workflow-common-deployment/src/test/java/org/kie/kogito/quarkus/workflow/deployment/JandexTestUtils.java
+++
b/quarkus/extensions/kogito-quarkus-workflow-extension-common/kogito-quarkus-workflow-common-deployment/src/test/java/org/kie/kogito/quarkus/workflow/deployment/JandexTestUtils.java
@@ -46,6 +46,8 @@ import org.kie.kogito.codegen.data.PersonSubClass;
import org.kie.kogito.codegen.data.PersonVarInfo;
import org.kie.kogito.codegen.data.PersonWithAddress;
import org.kie.kogito.codegen.data.PersonWithAddresses;
+import org.kie.kogito.codegen.data.PersonWithBooleanGetAccessor;
+import org.kie.kogito.codegen.data.PersonWithBooleanObject;
import org.kie.kogito.codegen.data.PersonWithList;
import org.kie.kogito.codegen.data.Question;
import org.kie.kogito.codegen.data.QuestionWithAnnotatedEnum;
@@ -79,7 +81,9 @@ public final class JandexTestUtils {
Travels.class,
PersonSubClass.class,
JacksonData.class,
- ListWithoutType.class);
+ ListWithoutType.class,
+ PersonWithBooleanObject.class,
+ PersonWithBooleanGetAccessor.class);
private static void indexClass(Indexer indexer, Class<?> toIndex) {
try {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]