Skip to content

Commit

Permalink
feat(element-template-generator): add a new EnumLabel annotation for …
Browse files Browse the repository at this point in the history
…dev simplicity 2
  • Loading branch information
mathias-vandaele committed Feb 11, 2025
1 parent a744928 commit 5948f2e
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,7 @@ public record ImapListEmails(
type = TemplateProperty.PropertyType.Dropdown,
constraints = @TemplateProperty.PropertyConstraints(notEmpty = true),
defaultValue = "RECEIVED_DATE",
choices = {
@TemplateProperty.DropdownPropertyChoice(
label = "Received Date",
value = "RECEIVED_DATE"),
@TemplateProperty.DropdownPropertyChoice(label = "Sent Date", value = "SENT_DATE"),
@TemplateProperty.DropdownPropertyChoice(label = "Size", value = "SIZE")
},
enumLabel = @TemplateProperty.EnumLabel,
binding = @TemplateProperty.PropertyBinding(name = "data.imapAction.sortField"))
@NotNull
SortFieldImap sortField,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,28 @@
*/
package io.camunda.connector.email.outbound.protocols.actions;

public enum SortFieldImap {
RECEIVED_DATE,
SENT_DATE,
SIZE;
import io.camunda.connector.generator.java.interfaces.Labelled;

public enum SortFieldImap implements Labelled {
RECEIVED_DATE("Received Date", "RECEIVED_DATE"),
SENT_DATE("Sent Date", "SENT_DATE"),
SIZE("Size", "SIZE");

private final String label;
private final String value;

SortFieldImap(String label, String value) {
this.label = label;
this.value = value;
}

@Override
public String getValue() {
return value;
}

@Override
public String getLabel() {
return label;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
/** Custom binding name of the property */
PropertyBinding binding() default @PropertyBinding(name = "");

EnumLabel enumLabel() default @EnumLabel();
/** Binding for enum */
EnumLabel enumLabel() default @EnumLabel;

/** Description of the property */
String description() default "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,18 @@ void annotated_StringProperty_definedByAnnotation() {
assertThat(property.getConstraints().pattern()).isNull();
}

@Test
void annotated_EnumProperty_definedByAnnotation() {
var template = generator.generate(MyConnectorFunction.FullyAnnotated.class).getFirst();
var property = getPropertyById("enumProperty2", template);

assertThat(property).isInstanceOf(DropdownProperty.class);
assertThat(property.getType()).isEqualTo("Dropdown");
assertThat(((DropdownProperty) property).getChoices())
.containsExactly(
new DropdownChoice("Value 1", "value1"), new DropdownChoice("Value 2", "value2"));
}

@Test
void objectProperty_hasRequiredFeelByDefault() {
var template = generator.generate(MyConnectorFunction.MinimallyAnnotated.class).getFirst();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ public record MyConnectorInput(
String notAnnotatedStringProperty,
Object objectProperty,
JsonNode jsonNodeProperty,
@TemplateProperty(enumLabel = @TemplateProperty.EnumLabel, defaultValue = "VALUE1")
MyEnum enumProperty,
MyEnumNotLabelled enumProperty,
@TemplateProperty(
id = "enumProperty2",
enumLabel = @TemplateProperty.EnumLabel,
defaultValue = "VALUE1")
MyEnum enumProperty2,
LocalDate dateProperty,
@TemplateProperty(type = PropertyType.String) NestedWithDefinedGroup propertyWithTypeOverride,
NestedWithoutDefinedGroup nestedProperty,
Expand Down Expand Up @@ -142,6 +146,11 @@ public String getLabel() {
}
}

enum MyEnumNotLabelled {
VALUE1,
VALUE2;
}

sealed interface NonAnnotatedSealedType permits FirstSubType, NestedSealedType, SecondSubType {

sealed interface NestedSealedType extends NonAnnotatedSealedType permits NestedSubType {
Expand Down

0 comments on commit 5948f2e

Please sign in to comment.