Skip to content

Commit

Permalink
feat(template generator): set default value feel = false for all inbo…
Browse files Browse the repository at this point in the history
…und connectors (#2264)
  • Loading branch information
Oleksiivanov committed Apr 2, 2024
1 parent 8d92aa3 commit e7566e0
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public record JWTProperties(
@TemplateProperty(
label = "JWK URL",
description = "Well-known URL of JWKs",
feel = FeelMode.optional,
group = "authorization")
@FEEL
String jwkUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ record BasicAuth(
@TemplateProperty(
label = "Username",
description = "Username for basic authentication",
feel = FeelMode.optional,
group = "authorization")
@FEEL
String username,
@TemplateProperty(
label = "Password",
description = "Password for basic authentication",
feel = FeelMode.optional,
group = "authorization")
@FEEL
String password)
Expand All @@ -59,6 +61,7 @@ record ApiKeyAuth(
@TemplateProperty(
label = "API key",
description = "Expected API key",
feel = FeelMode.optional,
group = "authorization")
@FEEL
String apiKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public record WebhookConnectorProperties(
description = "Shared secret key",
group = "authentication",
optional = true,
feel = FeelMode.optional,
condition =
@PropertyCondition(property = "inbound.shouldValidateHmac", equals = "enabled"))
String hmacSecret,
Expand All @@ -76,6 +77,7 @@ public record WebhookConnectorProperties(
label = "HMAC header",
description = "Name of header attribute that will contain the HMAC value",
group = "authentication",
feel = FeelMode.optional,
optional = true,
condition =
@PropertyCondition(property = "inbound.shouldValidateHmac", equals = "enabled"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ public enum FeelMode {
optional,
required,
@JsonIgnore
disabled
disabled,
@JsonIgnore
system_default,
}

public record GeneratedValue(String type) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@
*/
DropdownPropertyChoice[] choices() default {};

/** Whether the property should support FEEL expressions */
FeelMode feel() default FeelMode.optional;
/**
* Defines the support for FEEL expressions in the property. By default, for inbound connectors,
* FEEL is disabled; for outbound connectors, FEEL is optional.
*/
FeelMode feel() default FeelMode.system_default;

/** Default value for the property */
String defaultValue() default "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
package io.camunda.connector.generator.java.processor;

import io.camunda.connector.generator.dsl.PropertyBuilder;
import io.camunda.connector.generator.java.util.TemplateGenerationContext;
import java.lang.reflect.Field;

public interface FieldProcessor {

void process(Field field, PropertyBuilder propertyBuilder);
void process(
Field field, PropertyBuilder propertyBuilder, final TemplateGenerationContext context);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.camunda.connector.generator.dsl.PropertyBuilder;
import io.camunda.connector.generator.dsl.PropertyConstraints;
import io.camunda.connector.generator.dsl.PropertyConstraints.PropertyConstraintsBuilder;
import io.camunda.connector.generator.java.util.TemplateGenerationContext;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
Expand All @@ -31,7 +32,8 @@
public class JakartaValidationFieldProcessor implements FieldProcessor {

@Override
public void process(Field field, PropertyBuilder propertyBuilder) {
public void process(
Field field, PropertyBuilder propertyBuilder, final TemplateGenerationContext context) {
PropertyConstraintsBuilder constraintsBuilder = PropertyConstraints.builder();

if (hasNotEmptyConstraint(field)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,35 @@
package io.camunda.connector.generator.java.processor;

import io.camunda.connector.generator.dsl.DropdownProperty.DropdownPropertyBuilder;
import io.camunda.connector.generator.dsl.Property;
import io.camunda.connector.generator.dsl.PropertyBuilder;
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.util.TemplateGenerationContext;
import java.lang.reflect.Field;
import java.util.Arrays;

/** {@link TemplateProperty} annotation processor */
public class TemplatePropertyFieldProcessor implements FieldProcessor {

@Override
public void process(Field field, PropertyBuilder builder) {
public void process(
Field field, PropertyBuilder builder, final TemplateGenerationContext context) {
var annotation = field.getAnnotation(TemplateProperty.class);
if (annotation == null) {
return;
}
builder.optional(annotation.optional());

if (!(builder instanceof DropdownPropertyBuilder)) {
builder.feel(annotation.feel());
if (annotation.feel() == Property.FeelMode.system_default) {
builder.feel(determineDefaultFeelModeBasedOnContext(context));
} else {
builder.feel(annotation.feel());
}
}

if (!annotation.label().isBlank()) {
builder.label(annotation.label());
}
Expand All @@ -53,6 +62,13 @@ public void process(Field field, PropertyBuilder builder) {
builder.constraints(buildConstraints(annotation));
}

private Property.FeelMode determineDefaultFeelModeBasedOnContext(
final TemplateGenerationContext context) {
return context instanceof TemplateGenerationContext.Inbound
? Property.FeelMode.disabled
: Property.FeelMode.optional;
}

private PropertyCondition buildCondition(TemplateProperty propertyAnnotation) {
var conditionAnnotation = propertyAnnotation.condition();
if (conditionAnnotation.property().isBlank()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ private static PropertyBuilder buildProperty(Field field, TemplateGenerationCont
.binding(createBinding(bindingName, context));

for (FieldProcessor processor : fieldProcessors) {
processor.process(field, propertyBuilder);
processor.process(field, propertyBuilder, context);
}
return propertyBuilder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
import io.camunda.connector.generator.dsl.DropdownProperty;
import io.camunda.connector.generator.dsl.DropdownProperty.DropdownChoice;
import io.camunda.connector.generator.dsl.Property.FeelMode;
import io.camunda.connector.generator.dsl.PropertyBinding;
import io.camunda.connector.generator.dsl.PropertyBinding.MessageProperty;
import io.camunda.connector.generator.dsl.PropertyBinding.ZeebeProperty;
import io.camunda.connector.generator.dsl.PropertyBinding.ZeebeSubscriptionProperty;
import io.camunda.connector.generator.dsl.PropertyCondition.Equals;
import io.camunda.connector.generator.dsl.StringProperty;
import io.camunda.connector.generator.java.example.inbound.MyConnectorExecutable;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -258,4 +260,25 @@ void messageStartEvent_hasCorrelationProperties() {
.isEqualTo("messageIdExpression");
}
}

@Test
void stringProperty_hasCorrectDefaults() {
// given
var type =
new ConnectorElementType(
Set.of(BpmnType.START_EVENT), BpmnType.MESSAGE_START_EVENT, null, null);
var config = new GeneratorConfiguration(ConnectorMode.NORMAL, null, null, null, Set.of(type));

// when
var template = generator.generate(MyConnectorExecutable.class, config).getFirst();

var property = getPropertyByLabel("Prop 1", template);

assertThat(property).isInstanceOf(StringProperty.class);
assertThat(property.getType()).isEqualTo("String");
assertThat(property.isOptional()).isFalse();
assertThat(property.getFeel()).isEqualTo(null);
assertThat(property.getBinding()).isEqualTo(new PropertyBinding.ZeebeProperty("prop1"));
assertThat(property.getConstraints()).isNull();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@
*/
package io.camunda.connector.generator.java.example.inbound;

public record MyConnectorProperties(String prop1) {}
import io.camunda.connector.generator.java.annotation.TemplateProperty;

public record MyConnectorProperties(@TemplateProperty() String prop1) {}

0 comments on commit e7566e0

Please sign in to comment.