diff --git a/element-template-generator/core/src/main/java/io/camunda/connector/generator/java/annotation/TemplateProperty.java b/element-template-generator/core/src/main/java/io/camunda/connector/generator/java/annotation/TemplateProperty.java index f56ced13d7..016be635be 100644 --- a/element-template-generator/core/src/main/java/io/camunda/connector/generator/java/annotation/TemplateProperty.java +++ b/element-template-generator/core/src/main/java/io/camunda/connector/generator/java/annotation/TemplateProperty.java @@ -135,11 +135,37 @@ enum DefaultValueType { String name(); } + enum EqualsBoolean { + TRUE, + FALSE, + NULL; + + public static EqualsBoolean fromBoolean(Boolean value) { + if (value == null) { + return NULL; + } else if (value) { + return TRUE; + } else { + return FALSE; + } + } + + public Boolean toBoolean() { + if (this == NULL) { + return null; + } else { + return this == TRUE; + } + } + } + @interface PropertyCondition { String property(); String equals() default ""; + EqualsBoolean equalsBoolean() default EqualsBoolean.NULL; + String[] oneOf() default {}; NestedPropertyCondition[] allMatch() default {}; @@ -153,6 +179,8 @@ enum DefaultValueType { /** For string properties */ String equals() default ""; + EqualsBoolean equalsBoolean() default EqualsBoolean.NULL; + String[] oneOf() default {}; boolean isActive() default false; diff --git a/element-template-generator/core/src/main/java/io/camunda/connector/generator/java/processor/TemplatePropertyFieldProcessor.java b/element-template-generator/core/src/main/java/io/camunda/connector/generator/java/processor/TemplatePropertyFieldProcessor.java index 48f96053a5..2cb53621c4 100644 --- a/element-template-generator/core/src/main/java/io/camunda/connector/generator/java/processor/TemplatePropertyFieldProcessor.java +++ b/element-template-generator/core/src/main/java/io/camunda/connector/generator/java/processor/TemplatePropertyFieldProcessor.java @@ -22,6 +22,7 @@ import io.camunda.connector.generator.dsl.PropertyCondition; import io.camunda.connector.generator.dsl.PropertyConstraints; import io.camunda.connector.generator.java.annotation.TemplateProperty; +import io.camunda.connector.generator.java.annotation.TemplateProperty.EqualsBoolean; import io.camunda.connector.generator.java.annotation.TemplateProperty.NestedPropertyCondition; import io.camunda.connector.generator.java.util.TemplateGenerationContext; import java.lang.reflect.Field; @@ -88,6 +89,7 @@ private PropertyCondition buildCondition(TemplateProperty propertyAnnotation) { validateCondition( conditionAnnotation.property(), conditionAnnotation.equals(), + conditionAnnotation.equalsBoolean(), conditionAnnotation.oneOf(), conditionAnnotation.allMatch()); return transformToCondition(conditionAnnotation); @@ -99,6 +101,9 @@ public static PropertyCondition transformToCondition( if (!conditionAnnotation.equals().isBlank()) { return new PropertyCondition.Equals( conditionAnnotation.property(), conditionAnnotation.equals()); + } else if (conditionAnnotation.equalsBoolean() != TemplateProperty.EqualsBoolean.NULL) { + return new PropertyCondition.Equals( + conditionAnnotation.property(), conditionAnnotation.equalsBoolean().toBoolean()); } else if (conditionAnnotation.oneOf().length > 0) { return new PropertyCondition.OneOf( conditionAnnotation.property(), Arrays.asList(conditionAnnotation.oneOf())); @@ -119,11 +124,15 @@ public static PropertyCondition transformToNestedCondition( validateCondition( conditionAnnotation.property(), conditionAnnotation.equals(), + conditionAnnotation.equalsBoolean(), conditionAnnotation.oneOf(), new NestedPropertyCondition[] {}); if (!conditionAnnotation.equals().isBlank()) { return new PropertyCondition.Equals( conditionAnnotation.property(), conditionAnnotation.equals()); + } else if (conditionAnnotation.equalsBoolean() != TemplateProperty.EqualsBoolean.NULL) { + return new PropertyCondition.Equals( + conditionAnnotation.property(), conditionAnnotation.equalsBoolean().toBoolean()); } else if (conditionAnnotation.oneOf().length > 0) { return new PropertyCondition.OneOf( conditionAnnotation.property(), Arrays.asList(conditionAnnotation.oneOf())); @@ -135,16 +144,26 @@ public static PropertyCondition transformToNestedCondition( } private static void validateCondition( - String property, String equals, String[] oneOf, NestedPropertyCondition[] allMatch) { + String property, + String equals, + EqualsBoolean equalsBoolean, + String[] oneOf, + NestedPropertyCondition[] allMatch) { var equalsSet = !equals.isBlank(); + var equalsBooleanSet = !equalsBoolean.equals(TemplateProperty.EqualsBoolean.NULL); var oneOfSet = oneOf != null && oneOf.length > 0; var allMatchSet = allMatch != null && allMatch.length > 0; // equalsBoolean always has a value, so it's not included in the check // if everything else is not set, we consider it an equalsBoolean condition - if (equalsSet && oneOfSet || equalsSet && allMatchSet || oneOfSet && allMatchSet) { + if (equalsSet && equalsBooleanSet + || equalsSet && oneOfSet + || equalsSet && allMatchSet + || oneOfSet && allMatchSet + || oneOfSet && equalsBooleanSet + || allMatchSet && equalsBooleanSet) { throw new IllegalStateException( - "Condition must have only one of 'equals', 'oneOf', 'isActive', or 'allMatch' set"); + "Condition must have only one of 'equals', 'equalsBoolean', 'oneOf', 'isActive', or 'allMatch' set"); } if (equalsSet && property.isBlank()) { throw new IllegalStateException("Condition 'equals' must have 'property' set"); diff --git a/element-template-generator/core/src/test/java/io/camunda/connector/generator/java/OutboundClassBasedTemplateGeneratorTest.java b/element-template-generator/core/src/test/java/io/camunda/connector/generator/java/OutboundClassBasedTemplateGeneratorTest.java index 692cb01934..7770f8cdcb 100644 --- a/element-template-generator/core/src/test/java/io/camunda/connector/generator/java/OutboundClassBasedTemplateGeneratorTest.java +++ b/element-template-generator/core/src/test/java/io/camunda/connector/generator/java/OutboundClassBasedTemplateGeneratorTest.java @@ -554,9 +554,9 @@ void booleanProperty() { void booleanProperty_dependants() { var template = generator.generate(MyConnectorFunction.MinimallyAnnotated.class).getFirst(); var dependsOnTrue = getPropertyById("dependsOnBooleanPropertyTrue", template); - assertThat(dependsOnTrue.getCondition()).isEqualTo(new Equals("booleanProperty", "true")); + assertThat(dependsOnTrue.getCondition()).isEqualTo(new Equals("booleanProperty", true)); var dependsOnFalse = getPropertyById("dependsOnBooleanPropertyFalse", template); - assertThat(dependsOnFalse.getCondition()).isEqualTo(new Equals("booleanProperty", "false")); + assertThat(dependsOnFalse.getCondition()).isEqualTo(new Equals("booleanProperty", false)); } } diff --git a/element-template-generator/core/src/test/java/io/camunda/connector/generator/java/example/outbound/MyConnectorInput.java b/element-template-generator/core/src/test/java/io/camunda/connector/generator/java/example/outbound/MyConnectorInput.java index 6cb6449a5f..a94d13b18f 100644 --- a/element-template-generator/core/src/test/java/io/camunda/connector/generator/java/example/outbound/MyConnectorInput.java +++ b/element-template-generator/core/src/test/java/io/camunda/connector/generator/java/example/outbound/MyConnectorInput.java @@ -21,6 +21,7 @@ import io.camunda.connector.generator.java.annotation.TemplateDiscriminatorProperty; import io.camunda.connector.generator.java.annotation.TemplateProperty; import io.camunda.connector.generator.java.annotation.TemplateProperty.DefaultValueType; +import io.camunda.connector.generator.java.annotation.TemplateProperty.EqualsBoolean; import io.camunda.connector.generator.java.annotation.TemplateProperty.PropertyCondition; import io.camunda.connector.generator.java.annotation.TemplateProperty.PropertyConstraints; import io.camunda.connector.generator.java.annotation.TemplateProperty.PropertyType; @@ -96,11 +97,17 @@ public record MyConnectorInput( Boolean booleanProperty, @TemplateProperty( id = "dependsOnBooleanPropertyFalse", - condition = @PropertyCondition(property = "booleanProperty", equals = "false")) + condition = + @PropertyCondition( + property = "booleanProperty", + equalsBoolean = EqualsBoolean.FALSE)) String dependsOnBooleanPropertyFalse, @TemplateProperty( id = "dependsOnBooleanPropertyTrue", - condition = @PropertyCondition(property = "booleanProperty", equals = "true")) + condition = + @PropertyCondition( + property = "booleanProperty", + equalsBoolean = EqualsBoolean.TRUE)) String dependsOnBooleanPropertyTrue, @TemplateProperty( id = "mayBeEmptyOrRegexValidated",