Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into ev/snapshots_and_release_workflow
Browse files Browse the repository at this point in the history
# Conflicts:
#	.github/workflows/INTEGRATION_TEST.yml
  • Loading branch information
ev-codes committed May 29, 2024
2 parents 703a5b4 + f4ca332 commit 589bae3
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/RELEASE.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.release.tag_name || github.event.release.target_commitish }}
ref: ${{ github.event.release.target_commitish }}
fetch-depth: 0

- name: Validate release tag and determine previous tag
Expand All @@ -30,7 +30,7 @@ jobs:
- name: Determine release branch name
id: determine_release_branch
run: |
releaseBranch=$( git branch --contains ${RELEASE_VERSION} --format='%(refname:short)' | tail -1 )
releaseBranch=$( git branch --contains ${RELEASE_VERSION} --format='%(refname:short)' )
git checkout "$releaseBranch"
echo "releaseBranch=$releaseBranch" >> $GITHUB_OUTPUT
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class ConGen {
"-e bpmn:ServiceTask -e bpmn:IntermediateThrowEvent"
},
showDefaultValue = CommandLine.Help.Visibility.ALWAYS,
defaultValue = "bpmn:ServiceTask")
defaultValue = "ServiceTask")
List<String> elementTypes;

GeneratorConfiguration generatorConfiguration() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.RECORD_COMPONENT})
public @interface TemplateProperty {
public static boolean OPTIONAL_DEFAULT = false;

/** Custom property ID that can be referenced in conditions */
String id() default "";
Expand All @@ -52,7 +53,7 @@
String description() default "";

/** Whether the property should be marked as optional in the element template */
boolean optional() default false;
boolean optional() default OPTIONAL_DEFAULT;

/**
* Overrides the property type. By default, the generator will use the field type to determine the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,20 @@
package io.camunda.connector.generator.java.processor;

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

public interface FieldProcessor {

void process(
Field field, PropertyBuilder propertyBuilder, final TemplateGenerationContext context);

static boolean isOptional(Field field) {
var annotation = field.getAnnotation(TemplateProperty.class);
if (annotation == null) {
return TemplateProperty.OPTIONAL_DEFAULT;
}
return annotation.optional();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public void process(
constraintsBuilder.pattern(
new PropertyConstraints.Pattern(pattern.getLeft(), pattern.getRight()));
}

if (pattern != null && !hasNotEmptyConstraint(field) && FieldProcessor.isOptional(field)) {
constraintsBuilder.notEmpty(false);
}
var constraints = constraintsBuilder.build();
if (!isConstraintEmpty(constraints)) {
propertyBuilder.constraints(constraints);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void process(
if (annotation == null) {
return;
}
builder.optional(annotation.optional());
builder.optional(FieldProcessor.isOptional(field));

if (!(builder instanceof DropdownPropertyBuilder)) {
if (annotation.feel() == Property.FeelMode.system_default) {
Expand Down Expand Up @@ -182,6 +182,9 @@ private PropertyConstraints buildConstraints(TemplateProperty propertyAnnotation
builder.minLength(constraintsAnnotation.minLength());
}
if (!constraintsAnnotation.pattern().value().isBlank()) {
if (!constraintsAnnotation.notEmpty() && propertyAnnotation.optional()) {
builder.notEmpty(false);
}
builder.pattern(
new PropertyConstraints.Pattern(
constraintsAnnotation.pattern().value(), constraintsAnnotation.pattern().message()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,27 @@ void validationPresent_notEmpty_objectProperty() {
assertThat(notEmptyProperty.getConstraints().minLength()).isNull();
assertThat(notEmptyProperty.getConstraints().maxLength()).isNull();
}

@Test
void validationPresent_Pattern_optional() {
var template = generator.generate(MyConnectorFunction.MinimallyAnnotated.class).getFirst();
var mayBeEmptyOrRegexValidated = getPropertyById("mayBeEmptyOrRegexValidated", template);
assertThat(mayBeEmptyOrRegexValidated.getConstraints()).isNotNull();
assertThat(mayBeEmptyOrRegexValidated.getConstraints().notEmpty()).isFalse();
assertThat(mayBeEmptyOrRegexValidated.getConstraints().minLength()).isNull();
assertThat(mayBeEmptyOrRegexValidated.getConstraints().maxLength()).isNull();
}

@Test
void validationPresent_Pattern_optional_jakarta() {
var template = generator.generate(MyConnectorFunction.MinimallyAnnotated.class).getFirst();
var mayBeEmptyOrRegexValidated =
getPropertyById("mayBeEmptyOrRegexValidatedJakartaStyle", template);
assertThat(mayBeEmptyOrRegexValidated.getConstraints()).isNotNull();
assertThat(mayBeEmptyOrRegexValidated.getConstraints().notEmpty()).isFalse();
assertThat(mayBeEmptyOrRegexValidated.getConstraints().minLength()).isNull();
assertThat(mayBeEmptyOrRegexValidated.getConstraints().maxLength()).isNull();
}
}

@Nested
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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.PropertyCondition;
import io.camunda.connector.generator.java.annotation.TemplateProperty.PropertyConstraints;
import io.camunda.connector.generator.java.annotation.TemplateProperty.PropertyType;
import io.camunda.connector.generator.java.annotation.TemplateSubType;
import io.camunda.connector.generator.java.example.outbound.MyConnectorInput.AnnotatedSealedType.FirstAnnotatedSubType;
Expand Down Expand Up @@ -99,7 +100,17 @@ public record MyConnectorInput(
@TemplateProperty(
id = "dependsOnBooleanPropertyTrue",
condition = @PropertyCondition(property = "booleanProperty", equals = "true"))
String dependsOnBooleanPropertyTrue) {
String dependsOnBooleanPropertyTrue,
@TemplateProperty(
id = "mayBeEmptyOrRegexValidated",
optional = true,
constraints =
@PropertyConstraints(
pattern = @TemplateProperty.Pattern(value = "xxx", message = "Oh no!")))
String mayBeEmptyOrRegexValidated,
@TemplateProperty(id = "mayBeEmptyOrRegexValidatedJakartaStyle", optional = true)
@Pattern(regexp = "xxx", message = "Oh no!")
String mayBeEmptyOrRegexValidatedJakartaStyle) {

sealed interface NonAnnotatedSealedType permits FirstSubType, NestedSealedType, SecondSubType {

Expand Down

0 comments on commit 589bae3

Please sign in to comment.