diff --git a/core/src/main/java/io/kestra/plugin/core/condition/DateTimeBetween.java b/core/src/main/java/io/kestra/plugin/core/condition/DateTimeBetween.java index 119337265f8..5c6ef5c3a96 100644 --- a/core/src/main/java/io/kestra/plugin/core/condition/DateTimeBetween.java +++ b/core/src/main/java/io/kestra/plugin/core/condition/DateTimeBetween.java @@ -4,10 +4,11 @@ import io.kestra.core.exceptions.InternalException; import io.kestra.core.models.annotations.Example; import io.kestra.core.models.annotations.Plugin; -import io.kestra.core.models.annotations.PluginProperty; import io.kestra.core.models.conditions.Condition; import io.kestra.core.models.conditions.ConditionContext; import io.kestra.core.models.conditions.ScheduleCondition; +import io.kestra.core.models.property.Property; +import io.kestra.core.runners.RunContext; import io.kestra.core.utils.DateUtils; import io.swagger.v3.oas.annotations.media.Schema; import lombok.*; @@ -53,34 +54,35 @@ public class DateTimeBetween extends Condition implements ScheduleCondition { description = "Can be any variable or any valid ISO 8601 datetime. By default, it will use the trigger date." ) @Builder.Default - @PluginProperty(dynamic = true) - private final String date = "{{ trigger.date }}"; + private final Property date = new Property<>("{{ trigger.date }}"); @Schema( title = "The date to test must be after this one.", description = "Must be a valid ISO 8601 datetime with the zone identifier (use 'Z' for the default zone identifier)." ) - @PluginProperty - private ZonedDateTime after; + private Property after; @Schema( title = "The date to test must be before this one.", description = "Must be a valid ISO 8601 datetime with the zone identifier (use 'Z' for the default zone identifier)." ) - @PluginProperty - private ZonedDateTime before; + private Property before; @Override public boolean test(ConditionContext conditionContext) throws InternalException { - String render = conditionContext.getRunContext().render(date, conditionContext.getVariables()); + RunContext runContext = conditionContext.getRunContext(); + String render = runContext.render(date).as(String.class, conditionContext.getVariables()).orElseThrow(); ZonedDateTime currentDate = DateUtils.parseZonedDateTime(render); - if (this.before != null && this.after != null) { - return currentDate.isAfter(after) && currentDate.isBefore(before); - } else if (this.before != null) { - return currentDate.isBefore(before); - } else if (this.after != null) { - return currentDate.isAfter(after); + var renderedBefore = runContext.render(this.before).as(ZonedDateTime.class, conditionContext.getVariables()); + var renderedAfter = runContext.render(this.after).as(ZonedDateTime.class, conditionContext.getVariables()); + + if (renderedBefore.isPresent() && renderedAfter.isPresent()) { + return currentDate.isAfter(renderedAfter.get()) && currentDate.isBefore(renderedBefore.get()); + } else if (renderedBefore.isPresent()) { + return currentDate.isBefore(renderedBefore.get()); + } else if (renderedAfter.isPresent()) { + return currentDate.isAfter(renderedAfter.get()); } else { throw new IllegalConditionEvaluation("Invalid condition with no before nor after"); } diff --git a/core/src/main/java/io/kestra/plugin/core/condition/DayWeek.java b/core/src/main/java/io/kestra/plugin/core/condition/DayWeek.java index 4fb4ebf3706..de4ef649536 100644 --- a/core/src/main/java/io/kestra/plugin/core/condition/DayWeek.java +++ b/core/src/main/java/io/kestra/plugin/core/condition/DayWeek.java @@ -3,10 +3,11 @@ import io.kestra.core.exceptions.InternalException; import io.kestra.core.models.annotations.Example; import io.kestra.core.models.annotations.Plugin; -import io.kestra.core.models.annotations.PluginProperty; import io.kestra.core.models.conditions.Condition; import io.kestra.core.models.conditions.ConditionContext; import io.kestra.core.models.conditions.ScheduleCondition; +import io.kestra.core.models.property.Property; +import io.kestra.core.runners.RunContext; import io.kestra.core.utils.DateUtils; import io.swagger.v3.oas.annotations.media.Schema; import lombok.*; @@ -44,19 +45,18 @@ public class DayWeek extends Condition implements ScheduleCondition { description = "Can be any variable or any valid ISO 8601 datetime. By default, it will use the trigger date." ) @Builder.Default - @PluginProperty(dynamic = true) - private final String date = "{{ trigger.date }}"; + private final Property date = new Property<>("{{ trigger.date }}"); @NotNull @Schema(title = "The day of week.") - @PluginProperty - private DayOfWeek dayOfWeek; + private Property dayOfWeek; @Override public boolean test(ConditionContext conditionContext) throws InternalException { - String render = conditionContext.getRunContext().render(date, conditionContext.getVariables()); + RunContext runContext = conditionContext.getRunContext(); + String render = runContext.render(date).as(String.class, conditionContext.getVariables()).orElseThrow(); LocalDate currentDate = DateUtils.parseLocalDate(render); - return currentDate.getDayOfWeek().equals(this.dayOfWeek); + return currentDate.getDayOfWeek().equals(runContext.render(dayOfWeek).as(DayOfWeek.class, conditionContext.getVariables()).orElseThrow()); } } diff --git a/core/src/main/java/io/kestra/plugin/core/condition/DayWeekInMonth.java b/core/src/main/java/io/kestra/plugin/core/condition/DayWeekInMonth.java index ab54929af9b..24a992b7b88 100644 --- a/core/src/main/java/io/kestra/plugin/core/condition/DayWeekInMonth.java +++ b/core/src/main/java/io/kestra/plugin/core/condition/DayWeekInMonth.java @@ -7,6 +7,8 @@ import io.kestra.core.models.conditions.Condition; import io.kestra.core.models.conditions.ConditionContext; import io.kestra.core.models.conditions.ScheduleCondition; +import io.kestra.core.models.property.Property; +import io.kestra.core.runners.RunContext; import io.kestra.core.utils.DateUtils; import io.swagger.v3.oas.annotations.media.Schema; import lombok.*; @@ -46,38 +48,39 @@ public class DayWeekInMonth extends Condition implements ScheduleCondition { description = "Can be any variable or any valid ISO 8601 datetime. By default, it will use the trigger date." ) @Builder.Default - @PluginProperty(dynamic = true) - private final String date = "{{ trigger.date }}"; + private final Property date = new Property<>("{{ trigger.date }}"); @NotNull @Schema(title = "The day of week.") - @PluginProperty - private DayOfWeek dayOfWeek; + private Property dayOfWeek; @NotNull @Schema(title = "Are you looking for the first or the last day in the month?") - @PluginProperty - private DayWeekInMonth.DayInMonth dayInMonth; + private Property dayInMonth; @Override public boolean test(ConditionContext conditionContext) throws InternalException { - String render = conditionContext.getRunContext().render(date, conditionContext.getVariables()); + RunContext runContext = conditionContext.getRunContext(); + String render = runContext.render(date).as(String.class, conditionContext.getVariables()).orElseThrow(); LocalDate currentDate = DateUtils.parseLocalDate(render); - LocalDate computed; - if (dayInMonth.equals(DayInMonth.FIRST)) { - computed = currentDate.with(TemporalAdjusters.firstInMonth(dayOfWeek)); - } else if (dayInMonth.equals(DayInMonth.LAST)) { - computed = currentDate.with(TemporalAdjusters.lastInMonth(dayOfWeek)); - } else if (dayInMonth.equals(DayInMonth.SECOND)) { - computed = currentDate.with(TemporalAdjusters.firstInMonth(dayOfWeek)).with(TemporalAdjusters.next(dayOfWeek)); - } else if (dayInMonth.equals(DayInMonth.THIRD)) { - computed = currentDate.with(TemporalAdjusters.firstInMonth(dayOfWeek)).with(TemporalAdjusters.next(dayOfWeek)).with(TemporalAdjusters.next(dayOfWeek)); - } else if (dayInMonth.equals(DayInMonth.FOURTH)) { - computed = currentDate.with(TemporalAdjusters.firstInMonth(dayOfWeek)).with(TemporalAdjusters.next(dayOfWeek)).with(TemporalAdjusters.next(dayOfWeek)).with(TemporalAdjusters.next(dayOfWeek)); - } else { - throw new IllegalArgumentException("Invalid dayInMonth"); - } + var renderedDayOfWeek = runContext.render(this.dayOfWeek).as(DayOfWeek.class).orElseThrow(); + LocalDate computed = switch (runContext.render(dayInMonth).as(DayWeekInMonth.DayInMonth.class, conditionContext.getVariables()).orElseThrow()) { + case DayInMonth.FIRST -> currentDate.with(TemporalAdjusters.firstInMonth(renderedDayOfWeek)); + case DayInMonth.LAST -> currentDate.with(TemporalAdjusters.lastInMonth(renderedDayOfWeek)); + case DayInMonth.SECOND -> + currentDate.with(TemporalAdjusters.firstInMonth(renderedDayOfWeek)) + .with(TemporalAdjusters.next(renderedDayOfWeek)); + case DayInMonth.THIRD -> + currentDate.with(TemporalAdjusters.firstInMonth(renderedDayOfWeek)) + .with(TemporalAdjusters.next(renderedDayOfWeek)) + .with(TemporalAdjusters.next(renderedDayOfWeek)); + case DayInMonth.FOURTH -> + currentDate.with(TemporalAdjusters.firstInMonth(renderedDayOfWeek)) + .with(TemporalAdjusters.next(renderedDayOfWeek)) + .with(TemporalAdjusters.next(renderedDayOfWeek)) + .with(TemporalAdjusters.next(renderedDayOfWeek)); + }; return computed.isEqual(currentDate); } diff --git a/core/src/main/java/io/kestra/plugin/core/condition/ExecutionFlow.java b/core/src/main/java/io/kestra/plugin/core/condition/ExecutionFlow.java index 4d83df13789..8f351bfc18b 100644 --- a/core/src/main/java/io/kestra/plugin/core/condition/ExecutionFlow.java +++ b/core/src/main/java/io/kestra/plugin/core/condition/ExecutionFlow.java @@ -2,7 +2,8 @@ import io.kestra.core.exceptions.IllegalConditionEvaluation; import io.kestra.core.exceptions.InternalException; -import io.kestra.core.models.annotations.PluginProperty; +import io.kestra.core.models.property.Property; +import io.kestra.core.runners.RunContext; import io.swagger.v3.oas.annotations.media.Schema; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -41,13 +42,11 @@ public class ExecutionFlow extends Condition { @NotNull @Schema(title = "The namespace of the flow.") - @PluginProperty - private String namespace; + private Property namespace; @NotNull @Schema(title = "The flow id.") - @PluginProperty - private String flowId; + private Property flowId; @Override public boolean test(ConditionContext conditionContext) throws InternalException { @@ -55,6 +54,8 @@ public boolean test(ConditionContext conditionContext) throws InternalException throw new IllegalConditionEvaluation("Invalid condition with null execution"); } - return conditionContext.getExecution().getNamespace().equals(this.namespace) && conditionContext.getExecution().getFlowId().equals(this.flowId); + RunContext runContext = conditionContext.getRunContext(); + return conditionContext.getExecution().getNamespace().equals(runContext.render(this.namespace).as(String.class, conditionContext.getVariables()).orElseThrow()) + && conditionContext.getExecution().getFlowId().equals(runContext.render(this.flowId).as(String.class, conditionContext.getVariables()).orElseThrow()); } } diff --git a/core/src/main/java/io/kestra/plugin/core/condition/ExecutionNamespace.java b/core/src/main/java/io/kestra/plugin/core/condition/ExecutionNamespace.java index 4d1a1fc14b3..9f67de4542f 100644 --- a/core/src/main/java/io/kestra/plugin/core/condition/ExecutionNamespace.java +++ b/core/src/main/java/io/kestra/plugin/core/condition/ExecutionNamespace.java @@ -3,6 +3,8 @@ import io.kestra.core.exceptions.IllegalConditionEvaluation; import io.kestra.core.exceptions.InternalException; import io.kestra.core.models.annotations.PluginProperty; +import io.kestra.core.models.property.Property; +import io.kestra.core.runners.RunContext; import io.swagger.v3.oas.annotations.media.Schema; import lombok.*; import lombok.experimental.SuperBuilder; @@ -42,22 +44,19 @@ public class ExecutionNamespace extends Condition { @Schema( title = "String against which to match the execution namespace depending on the provided comparison." ) - @PluginProperty - private String namespace; + private Property namespace; @Schema( title = "Comparison to use when checking if namespace matches. If not provided, it will use `EQUALS` by default." ) - @PluginProperty - private Comparison comparison; + private Property comparison; @Schema( title = "Whether to look at the flow namespace by prefix. Shortcut for `comparison: PREFIX`.", description = "Only used when `comparison` is not set" ) - @PluginProperty @Builder.Default - private boolean prefix = false; + private Property prefix = Property.of(false); @Override public boolean test(ConditionContext conditionContext) throws InternalException { @@ -65,8 +64,13 @@ public boolean test(ConditionContext conditionContext) throws InternalException throw new IllegalConditionEvaluation("Invalid condition with null execution"); } - return Optional.ofNullable(this.comparison).orElse(prefix ? Comparison.PREFIX : Comparison.EQUALS) - .test(conditionContext.getExecution().getNamespace(), this.namespace); + RunContext runContext = conditionContext.getRunContext(); + var renderedPrefix = runContext.render(this.prefix).as(Boolean.class).orElseThrow(); + var renderedNamespace = runContext.render(this.namespace).as(String.class).orElseThrow(); + + return runContext.render(this.comparison).as(Comparison.class) + .orElse(Boolean.TRUE.equals(renderedPrefix) ? Comparison.PREFIX : Comparison.EQUALS) + .test(conditionContext.getExecution().getNamespace(), renderedNamespace); } public enum Comparison { diff --git a/core/src/main/java/io/kestra/plugin/core/condition/ExecutionOutputs.java b/core/src/main/java/io/kestra/plugin/core/condition/ExecutionOutputs.java index f6743d2b95a..4cd026581de 100644 --- a/core/src/main/java/io/kestra/plugin/core/condition/ExecutionOutputs.java +++ b/core/src/main/java/io/kestra/plugin/core/condition/ExecutionOutputs.java @@ -8,6 +8,7 @@ import io.kestra.core.models.conditions.ConditionContext; import io.kestra.core.models.conditions.ScheduleCondition; import io.kestra.core.models.executions.Execution; +import io.kestra.core.models.property.Property; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; @@ -50,9 +51,7 @@ public class ExecutionOutputs extends Condition implements ScheduleCondition { private static final String OUTPUTS_VAR = "outputs"; @NotNull - @NotEmpty - @PluginProperty - private String expression; + private Property expression; /** {@inheritDoc} **/ @SuppressWarnings("unchecked") @@ -68,8 +67,8 @@ public boolean test(ConditionContext conditionContext) throws InternalException Map.of(TRIGGER_VAR, Map.of(OUTPUTS_VAR, conditionContext.getExecution().getOutputs())) ); - String render = conditionContext.getRunContext().render(expression, variables); - return !(render.isBlank() || render.isEmpty() || render.trim().equals("false")); + String render = conditionContext.getRunContext().render(expression).as(String.class, variables).orElseThrow(); + return !(render.isBlank() || render.trim().equals("false")); } private boolean hasNoOutputs(final Execution execution) { diff --git a/core/src/main/java/io/kestra/plugin/core/condition/ExecutionStatus.java b/core/src/main/java/io/kestra/plugin/core/condition/ExecutionStatus.java index f97d82f4710..4889761f6b7 100644 --- a/core/src/main/java/io/kestra/plugin/core/condition/ExecutionStatus.java +++ b/core/src/main/java/io/kestra/plugin/core/condition/ExecutionStatus.java @@ -3,6 +3,8 @@ import io.kestra.core.exceptions.IllegalConditionEvaluation; import io.kestra.core.exceptions.InternalException; import io.kestra.core.models.annotations.PluginProperty; +import io.kestra.core.models.property.Property; +import io.kestra.core.runners.RunContext; import io.swagger.v3.oas.annotations.media.Schema; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -43,13 +45,11 @@ public class ExecutionStatus extends Condition { @Valid @Schema(title = "List of states that are authorized.") - @PluginProperty - private List in; + private Property> in; @Valid @Schema(title = "List of states that aren't authorized.") - @PluginProperty - private List notIn; + private Property> notIn; @Override public boolean test(ConditionContext conditionContext) throws InternalException { @@ -59,11 +59,14 @@ public boolean test(ConditionContext conditionContext) throws InternalException boolean result = true; - if (this.in != null && !this.in.contains(conditionContext.getExecution().getState().getCurrent())) { + RunContext runContext = conditionContext.getRunContext(); + var stateInRendered = runContext.render(this.in).asList(State.Type.class, conditionContext.getVariables()); + if (!stateInRendered.isEmpty() && !stateInRendered.contains(conditionContext.getExecution().getState().getCurrent())) { result = false; } - if (this.notIn != null && this.notIn.contains(conditionContext.getExecution().getState().getCurrent())) { + var stateNotInRendered = runContext.render(this.notIn).asList(State.Type.class, conditionContext.getVariables()); + if (!stateNotInRendered.isEmpty() && stateNotInRendered.contains(conditionContext.getExecution().getState().getCurrent())) { result = false; } diff --git a/core/src/main/java/io/kestra/plugin/core/condition/Expression.java b/core/src/main/java/io/kestra/plugin/core/condition/Expression.java index cf129f5f819..67e16ae6bbb 100644 --- a/core/src/main/java/io/kestra/plugin/core/condition/Expression.java +++ b/core/src/main/java/io/kestra/plugin/core/condition/Expression.java @@ -7,6 +7,7 @@ import io.kestra.core.models.conditions.Condition; import io.kestra.core.models.conditions.ConditionContext; import io.kestra.core.models.conditions.ScheduleCondition; +import io.kestra.core.models.property.Property; import io.swagger.v3.oas.annotations.media.Schema; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -42,13 +43,11 @@ ) public class Expression extends Condition implements ScheduleCondition { @NotNull - @NotEmpty - @PluginProperty - private String expression; + private Property expression; @Override public boolean test(ConditionContext conditionContext) throws InternalException { - String render = conditionContext.getRunContext().render(expression, conditionContext.getVariables()); - return !(render.isBlank() || render.isEmpty() || render.trim().equals("false")); + String render = conditionContext.getRunContext().render(expression).as(String.class, conditionContext.getVariables()).orElseThrow(); + return !(render.isBlank() || render.trim().equals("false")); } } diff --git a/core/src/main/java/io/kestra/plugin/core/condition/HasRetryAttempt.java b/core/src/main/java/io/kestra/plugin/core/condition/HasRetryAttempt.java index 72382b8a26f..5b27cda51b6 100644 --- a/core/src/main/java/io/kestra/plugin/core/condition/HasRetryAttempt.java +++ b/core/src/main/java/io/kestra/plugin/core/condition/HasRetryAttempt.java @@ -8,6 +8,8 @@ import io.kestra.core.models.conditions.Condition; import io.kestra.core.models.conditions.ConditionContext; import io.kestra.core.models.flows.State; +import io.kestra.core.models.property.Property; +import io.kestra.core.runners.RunContext; import io.swagger.v3.oas.annotations.media.Schema; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -43,13 +45,11 @@ public class HasRetryAttempt extends Condition { @Valid @Schema(title = "List of states that are authorized.") - @PluginProperty - private List in; + private Property> in; @Valid @Schema(title = "List of states that aren't authorized.") - @PluginProperty - private List notIn; + private Property> notIn; @Override public boolean test(ConditionContext conditionContext) throws InternalException { @@ -57,6 +57,10 @@ public boolean test(ConditionContext conditionContext) throws InternalException throw new IllegalConditionEvaluation("Invalid condition with null execution"); } + RunContext runContext = conditionContext.getRunContext(); + var stateInRendered = runContext.render(this.in).asList(String.class, conditionContext.getVariables()); + var stateNotInRendered = runContext.render(this.notIn).asList(String.class, conditionContext.getVariables()); + return conditionContext .getExecution() .getTaskRunList() @@ -66,11 +70,11 @@ public boolean test(ConditionContext conditionContext) throws InternalException .anyMatch(taskRunAttempt -> { boolean result = true; - if (this.in != null && !this.in.contains(taskRunAttempt.getState().getCurrent())) { + if (!stateInRendered.contains(taskRunAttempt.getState().getCurrent())) { result = false; } - if (this.notIn != null && this.notIn.contains(taskRunAttempt.getState().getCurrent())) { + if (stateNotInRendered.contains(taskRunAttempt.getState().getCurrent())) { result = false; } diff --git a/core/src/main/java/io/kestra/plugin/core/condition/PublicHoliday.java b/core/src/main/java/io/kestra/plugin/core/condition/PublicHoliday.java index 6c6fb8eb0a7..91c15fb6cae 100644 --- a/core/src/main/java/io/kestra/plugin/core/condition/PublicHoliday.java +++ b/core/src/main/java/io/kestra/plugin/core/condition/PublicHoliday.java @@ -9,9 +9,11 @@ import io.kestra.core.models.conditions.Condition; import io.kestra.core.models.conditions.ConditionContext; import io.kestra.core.models.conditions.ScheduleCondition; +import io.kestra.core.models.property.Property; import io.kestra.core.utils.DateUtils; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; import lombok.*; import lombok.experimental.SuperBuilder; @@ -56,36 +58,33 @@ aliases = {"io.kestra.core.models.conditions.types.PublicHolidayCondition", "io.kestra.plugin.core.condition.PublicHolidayCondition"} ) public class PublicHoliday extends Condition implements ScheduleCondition { - @NotEmpty @Schema( title = "The date to test.", description = "Can be any variable or any valid ISO 8601 datetime. By default, it will use the trigger date." ) + @NotNull @Builder.Default - @PluginProperty(dynamic = true) - private String date = "{{ trigger.date }}"; + private Property date = new Property<>("{{ trigger.date }}"); @Schema( title = "[ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) country code. If not set, it uses the country code from the default locale.", description = "It uses the [Jollyday](https://github.com/focus-shift/jollyday) library for public holiday calendar that supports more than 70 countries." ) - @PluginProperty(dynamic = true) - private String country; + private Property country; @Schema( title = "[ISO 3166-2](https://en.wikipedia.org/wiki/ISO_3166-2) country subdivision (e.g., provinces and states) code.", description = "It uses the [Jollyday](https://github.com/focus-shift/jollyday) library for public holiday calendar that supports more than 70 countries." ) - @PluginProperty(dynamic = true) - private String subDivision; + private Property subDivision; @Override public boolean test(ConditionContext conditionContext) throws InternalException { - var renderedCountry = conditionContext.getRunContext().render(this.country); - var renderedSubDivision = conditionContext.getRunContext().render(this.subDivision); + var renderedCountry = conditionContext.getRunContext().render(this.country).as(String.class).orElse(null); + var renderedSubDivision = conditionContext.getRunContext().render(this.subDivision).as(String.class).orElse(null); HolidayManager holidayManager = renderedCountry != null ? HolidayManager.getInstance(ManagerParameters.create(renderedCountry)) : HolidayManager.getInstance(); - LocalDate currentDate = DateUtils.parseLocalDate(conditionContext.getRunContext().render(date)); + LocalDate currentDate = DateUtils.parseLocalDate(conditionContext.getRunContext().render(date).as(String.class).orElseThrow()); return renderedSubDivision == null ? holidayManager.isHoliday(currentDate) : holidayManager.isHoliday(currentDate, renderedSubDivision); } } diff --git a/core/src/main/java/io/kestra/plugin/core/condition/TimeBetween.java b/core/src/main/java/io/kestra/plugin/core/condition/TimeBetween.java index 8dc2f6bb9e9..c2a7623bf1c 100644 --- a/core/src/main/java/io/kestra/plugin/core/condition/TimeBetween.java +++ b/core/src/main/java/io/kestra/plugin/core/condition/TimeBetween.java @@ -8,6 +8,7 @@ import io.kestra.core.models.conditions.Condition; import io.kestra.core.models.conditions.ConditionContext; import io.kestra.core.models.conditions.ScheduleCondition; +import io.kestra.core.models.property.Property; import io.kestra.core.utils.DateUtils; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; @@ -44,8 +45,7 @@ public class TimeBetween extends Condition implements ScheduleCondition { description = "Can be any variable or any valid ISO 8601 time. By default, it will use the trigger date." ) @Builder.Default - @PluginProperty(dynamic = true) - private final String date = "{{ trigger.date }}"; + private final Property date = new Property<>("{{ trigger.date }}"); @Schema( title = "The time to test must be after this one.", @@ -63,7 +63,7 @@ public class TimeBetween extends Condition implements ScheduleCondition { @Override public boolean test(ConditionContext conditionContext) throws InternalException { - String render = conditionContext.getRunContext().render(date, conditionContext.getVariables()); + String render = conditionContext.getRunContext().render(date).as(String.class, conditionContext.getVariables()).orElseThrow(); OffsetTime currentDate = DateUtils.parseZonedDateTime(render).toOffsetDateTime().toOffsetTime(); if (this.before != null && this.after != null) { diff --git a/core/src/main/java/io/kestra/plugin/core/condition/Weekend.java b/core/src/main/java/io/kestra/plugin/core/condition/Weekend.java index 815feb81802..572dc33330a 100644 --- a/core/src/main/java/io/kestra/plugin/core/condition/Weekend.java +++ b/core/src/main/java/io/kestra/plugin/core/condition/Weekend.java @@ -7,6 +7,7 @@ import io.kestra.core.models.conditions.Condition; import io.kestra.core.models.conditions.ConditionContext; import io.kestra.core.models.conditions.ScheduleCondition; +import io.kestra.core.models.property.Property; import io.kestra.core.utils.DateUtils; import io.swagger.v3.oas.annotations.media.Schema; import lombok.*; @@ -43,12 +44,11 @@ public class Weekend extends Condition implements ScheduleCondition { description = "Can be any variable or any valid ISO 8601 datetime. By default, it will use the trigger date." ) @Builder.Default - @PluginProperty(dynamic = true) - private final String date = "{{ trigger.date }}"; + private final Property date = new Property<>("{{ trigger.date }}"); @Override public boolean test(ConditionContext conditionContext) throws InternalException { - String render = conditionContext.getRunContext().render(date, conditionContext.getVariables()); + String render = conditionContext.getRunContext().render(date).as(String.class, conditionContext.getVariables()).orElseThrow(); LocalDate currentDate = DateUtils.parseLocalDate(render); return currentDate.getDayOfWeek().equals(DayOfWeek.SATURDAY) || diff --git a/core/src/test/java/io/kestra/core/models/flows/FlowWithSourceTest.java b/core/src/test/java/io/kestra/core/models/flows/FlowWithSourceTest.java index 5b98e8d4ddb..e1c837371ed 100644 --- a/core/src/test/java/io/kestra/core/models/flows/FlowWithSourceTest.java +++ b/core/src/test/java/io/kestra/core/models/flows/FlowWithSourceTest.java @@ -111,7 +111,7 @@ void of() { )) .listeners(List.of( Listener.builder() - .conditions(List.of(Expression.builder().expression("true").build())) + .conditions(List.of(Expression.builder().expression(Property.of("true")).build())) .build() )) .triggers(List.of( diff --git a/core/src/test/java/io/kestra/core/models/triggers/multipleflows/AbstractMultipleConditionStorageTest.java b/core/src/test/java/io/kestra/core/models/triggers/multipleflows/AbstractMultipleConditionStorageTest.java index e7b932b5592..1b32136baa7 100644 --- a/core/src/test/java/io/kestra/core/models/triggers/multipleflows/AbstractMultipleConditionStorageTest.java +++ b/core/src/test/java/io/kestra/core/models/triggers/multipleflows/AbstractMultipleConditionStorageTest.java @@ -2,6 +2,7 @@ import com.google.common.collect.ImmutableMap; import io.kestra.core.junit.annotations.KestraTest; +import io.kestra.core.models.property.Property; import org.apache.commons.lang3.tuple.Pair; import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.Test; @@ -239,12 +240,12 @@ private static Pair mockFlow(TimeWindow sla) { .id("condition-multiple") .conditions(ImmutableMap.of( "flow-a", ExecutionFlow.builder() - .flowId("flow-a") - .namespace(NAMESPACE) + .flowId(Property.of("flow-a")) + .namespace(Property.of(NAMESPACE)) .build(), "flow-b", ExecutionFlow.builder() - .flowId("flow-b") - .namespace(NAMESPACE) + .flowId(Property.of("flow-b")) + .namespace(Property.of(NAMESPACE)) .build() )) .timeWindow(sla) diff --git a/core/src/test/java/io/kestra/core/runners/ListenersTest.java b/core/src/test/java/io/kestra/core/runners/ListenersTest.java index a135f07ecd9..dd420c1daa4 100644 --- a/core/src/test/java/io/kestra/core/runners/ListenersTest.java +++ b/core/src/test/java/io/kestra/core/runners/ListenersTest.java @@ -20,7 +20,7 @@ import static org.hamcrest.Matchers.is; @KestraTest(startRunner = true) -public class ListenersTest { +class ListenersTest { @Inject private RunnerUtils runnerUtils; diff --git a/core/src/test/java/io/kestra/core/schedulers/SchedulerConditionTest.java b/core/src/test/java/io/kestra/core/schedulers/SchedulerConditionTest.java index e38f654ae8a..7b6ee183579 100644 --- a/core/src/test/java/io/kestra/core/schedulers/SchedulerConditionTest.java +++ b/core/src/test/java/io/kestra/core/schedulers/SchedulerConditionTest.java @@ -1,5 +1,6 @@ package io.kestra.core.schedulers; +import io.kestra.core.models.property.Property; import io.kestra.core.utils.TestsUtils; import io.kestra.jdbc.runner.JdbcScheduler; import io.kestra.plugin.core.condition.DayWeekInMonth; @@ -48,9 +49,9 @@ private static Flow createScheduleFlow() { .conditions(List.of( DayWeekInMonth.builder() .type(DayWeekInMonth.class.getName()) - .date("{{ trigger.date }}") - .dayOfWeek(DayOfWeek.MONDAY) - .dayInMonth(DayWeekInMonth.DayInMonth.FIRST) + .date(new Property<>("{{ trigger.date }}")) + .dayOfWeek(Property.of(DayOfWeek.MONDAY)) + .dayInMonth(Property.of(DayWeekInMonth.DayInMonth.FIRST)) .build() )) .build(); diff --git a/core/src/test/java/io/kestra/core/schedulers/SchedulerPollingTriggerTest.java b/core/src/test/java/io/kestra/core/schedulers/SchedulerPollingTriggerTest.java index e5ff09812fa..7e67606e98e 100644 --- a/core/src/test/java/io/kestra/core/schedulers/SchedulerPollingTriggerTest.java +++ b/core/src/test/java/io/kestra/core/schedulers/SchedulerPollingTriggerTest.java @@ -1,5 +1,6 @@ package io.kestra.core.schedulers; +import io.kestra.core.models.property.Property; import io.kestra.core.utils.TestsUtils; import io.kestra.jdbc.runner.JdbcScheduler; import io.kestra.plugin.core.condition.Expression; @@ -140,7 +141,7 @@ void failedEvaluationTest() throws Exception { List.of( Expression.builder() .type(Expression.class.getName()) - .expression("{{ trigger.date | date() < now() }}") + .expression(new Property<>("{{ trigger.date | date() < now() }}")) .build() )) .build(); diff --git a/core/src/test/java/io/kestra/core/schedulers/SchedulerScheduleTest.java b/core/src/test/java/io/kestra/core/schedulers/SchedulerScheduleTest.java index 6a3c8e0716c..7e6a8b148be 100644 --- a/core/src/test/java/io/kestra/core/schedulers/SchedulerScheduleTest.java +++ b/core/src/test/java/io/kestra/core/schedulers/SchedulerScheduleTest.java @@ -1,6 +1,7 @@ package io.kestra.core.schedulers; import io.kestra.core.models.flows.FlowWithSource; +import io.kestra.core.models.property.Property; import io.kestra.core.utils.TestsUtils; import io.kestra.jdbc.runner.JdbcScheduler; import io.kestra.plugin.core.condition.Expression; @@ -471,7 +472,7 @@ void failedEvaluationTest() { List.of( Expression.builder() .type(Expression.class.getName()) - .expression("{{ trigger.date | date() < now() }}") + .expression(new Property<>("{{ trigger.date | date() < now() }}")) .build() ) ) diff --git a/core/src/test/java/io/kestra/core/services/ConditionServiceTest.java b/core/src/test/java/io/kestra/core/services/ConditionServiceTest.java index 64d1738f74b..35b13aaf4e5 100644 --- a/core/src/test/java/io/kestra/core/services/ConditionServiceTest.java +++ b/core/src/test/java/io/kestra/core/services/ConditionServiceTest.java @@ -3,6 +3,7 @@ import com.google.common.collect.ImmutableMap; import io.kestra.core.models.conditions.Condition; import io.kestra.core.models.conditions.ConditionContext; +import io.kestra.core.models.property.Property; import io.kestra.core.runners.RunContext; import io.kestra.plugin.core.condition.ExecutionFlow; import io.kestra.plugin.core.condition.ExecutionNamespace; @@ -51,11 +52,11 @@ void valid() { List conditions = Arrays.asList( ExecutionFlow.builder() - .namespace(flow.getNamespace()) - .flowId(flow.getId()) + .namespace(Property.of(flow.getNamespace())) + .flowId(Property.of(flow.getId())) .build(), ExecutionNamespace.builder() - .namespace(flow.getNamespace()) + .namespace(Property.of(flow.getNamespace())) .build() ); @@ -78,8 +79,8 @@ void exception() { List conditions = Collections.singletonList( ExecutionFlow.builder() - .namespace(flow.getNamespace()) - .flowId(flow.getId()) + .namespace(Property.of(flow.getNamespace())) + .flowId(Property.of(flow.getId())) .build() ); diff --git a/core/src/test/java/io/kestra/core/services/FlowTopologyServiceTest.java b/core/src/test/java/io/kestra/core/services/FlowTopologyServiceTest.java index b43ac2020e1..e62372a6428 100644 --- a/core/src/test/java/io/kestra/core/services/FlowTopologyServiceTest.java +++ b/core/src/test/java/io/kestra/core/services/FlowTopologyServiceTest.java @@ -109,11 +109,11 @@ void trigger() { io.kestra.plugin.core.trigger.Flow.builder() .conditions(List.of( ExecutionFlow.builder() - .namespace("io.kestra.ee") - .flowId("parent") + .namespace(Property.of("io.kestra.ee")) + .flowId(Property.of("parent")) .build(), ExecutionStatus.builder() - .in(List.of(State.Type.SUCCESS)) + .in(Property.of(List.of(State.Type.SUCCESS))) .build() )) .build() @@ -151,23 +151,23 @@ void multipleCondition() { io.kestra.plugin.core.trigger.Flow.builder() .conditions(List.of( ExecutionStatus.builder() - .in(List.of(State.Type.SUCCESS)) + .in(Property.of(List.of(State.Type.SUCCESS))) .build(), MultipleCondition.builder() .conditions(Map.of( "first", ExecutionFlow.builder() - .namespace("io.kestra.ee") - .flowId("parent") + .namespace(Property.of("io.kestra.ee")) + .flowId(Property.of("parent")) .build(), "second", ExecutionFlow.builder() - .namespace("io.kestra.others") - .flowId("invalid") + .namespace(Property.of("io.kestra.others")) + .flowId(Property.of("invalid")) .build(), "filtered", ExecutionStatus.builder() - .in(List.of(State.Type.SUCCESS)) + .in(Property.of(List.of(State.Type.SUCCESS))) .build(), "variables", Expression.builder() - .expression("{{ true }}") + .expression(new Property<>("{{ true }}")) .build() )) .build() diff --git a/core/src/test/java/io/kestra/core/services/PluginDefaultServiceTest.java b/core/src/test/java/io/kestra/core/services/PluginDefaultServiceTest.java index 4236bf4c5b7..c8a7841b4f3 100644 --- a/core/src/test/java/io/kestra/core/services/PluginDefaultServiceTest.java +++ b/core/src/test/java/io/kestra/core/services/PluginDefaultServiceTest.java @@ -156,7 +156,7 @@ private static Stream flowDefaultsOverrideGlobalDefaults() { } @Test - public void injectFlowAndGlobals() { + void injectFlowAndGlobals() { String source = """ id: default-test namespace: io.kestra.tests @@ -202,7 +202,7 @@ public void injectFlowAndGlobals() { assertThat(((DefaultTester) injected.getTasks().getFirst()).getProperty().getLists().getFirst().getVal().size(), is(1)); assertThat(((DefaultTester) injected.getTasks().getFirst()).getProperty().getLists().getFirst().getVal().get("key"), is("test")); assertThat(((DefaultTriggerTester) injected.getTriggers().getFirst()).getSet(), is(123)); - assertThat(((Expression) injected.getTriggers().getFirst().getConditions().getFirst()).getExpression(), is("{{ test }}")); + assertThat(((Expression) injected.getTriggers().getFirst().getConditions().getFirst()).getExpression().toString(), is("{{ test }}")); } @Test diff --git a/core/src/test/java/io/kestra/plugin/core/condition/DateTimeBetweenTest.java b/core/src/test/java/io/kestra/plugin/core/condition/DateTimeBetweenTest.java index f1499e81087..793854b92a8 100644 --- a/core/src/test/java/io/kestra/plugin/core/condition/DateTimeBetweenTest.java +++ b/core/src/test/java/io/kestra/plugin/core/condition/DateTimeBetweenTest.java @@ -3,6 +3,7 @@ import com.google.common.collect.ImmutableMap; import io.kestra.core.models.executions.Execution; import io.kestra.core.models.flows.Flow; +import io.kestra.core.models.property.Property; import io.kestra.core.services.ConditionService; import io.kestra.core.utils.TestsUtils; import io.kestra.core.junit.annotations.KestraTest; @@ -40,9 +41,9 @@ void valid(String date, ZonedDateTime before, ZonedDateTime after, boolean resul Execution execution = TestsUtils.mockExecution(flow, ImmutableMap.of()); DateTimeBetween build = DateTimeBetween.builder() - .date(date) - .before(before) - .after(after) + .date(new Property<>(date)) + .before(Property.of(before)) + .after(Property.of(after)) .build(); boolean test = conditionService.isValid(build, flow, execution); diff --git a/core/src/test/java/io/kestra/plugin/core/condition/DayWeekInMonthTest.java b/core/src/test/java/io/kestra/plugin/core/condition/DayWeekInMonthTest.java index 4291d065ad7..087610578b2 100644 --- a/core/src/test/java/io/kestra/plugin/core/condition/DayWeekInMonthTest.java +++ b/core/src/test/java/io/kestra/plugin/core/condition/DayWeekInMonthTest.java @@ -3,6 +3,7 @@ import com.google.common.collect.ImmutableMap; import io.kestra.core.models.executions.Execution; import io.kestra.core.models.flows.Flow; +import io.kestra.core.models.property.Property; import io.kestra.core.services.ConditionService; import io.kestra.core.utils.TestsUtils; import io.kestra.core.junit.annotations.KestraTest; @@ -43,9 +44,9 @@ void valid(String date, DayOfWeek dayOfWeek, DayWeekInMonth.DayInMonth dayInMont Execution execution = TestsUtils.mockExecution(flow, ImmutableMap.of()); DayWeekInMonth build = DayWeekInMonth.builder() - .date(date) - .dayOfWeek(dayOfWeek) - .dayInMonth(dayInMonth) + .date(Property.of(date)) + .dayOfWeek(Property.of(dayOfWeek)) + .dayInMonth(Property.of(dayInMonth)) .build(); boolean test = conditionService.isValid(build, flow, execution); diff --git a/core/src/test/java/io/kestra/plugin/core/condition/DayWeekTest.java b/core/src/test/java/io/kestra/plugin/core/condition/DayWeekTest.java index 92e5d3ff9b2..3d2b942d5d1 100644 --- a/core/src/test/java/io/kestra/plugin/core/condition/DayWeekTest.java +++ b/core/src/test/java/io/kestra/plugin/core/condition/DayWeekTest.java @@ -3,6 +3,7 @@ import com.google.common.collect.ImmutableMap; import io.kestra.core.models.executions.Execution; import io.kestra.core.models.flows.Flow; +import io.kestra.core.models.property.Property; import io.kestra.core.services.ConditionService; import io.kestra.core.utils.TestsUtils; import io.kestra.core.junit.annotations.KestraTest; @@ -37,8 +38,8 @@ void valid(String date, DayOfWeek dayOfWeek, boolean result) { Execution execution = TestsUtils.mockExecution(flow, ImmutableMap.of()); DayWeek build = DayWeek.builder() - .date(date) - .dayOfWeek(dayOfWeek) + .date(Property.of(date)) + .dayOfWeek(Property.of(dayOfWeek)) .build(); boolean test = conditionService.isValid(build, flow, execution); diff --git a/core/src/test/java/io/kestra/plugin/core/condition/ExecutionFlowTest.java b/core/src/test/java/io/kestra/plugin/core/condition/ExecutionFlowTest.java index 0a83889a5c5..06cde802cee 100644 --- a/core/src/test/java/io/kestra/plugin/core/condition/ExecutionFlowTest.java +++ b/core/src/test/java/io/kestra/plugin/core/condition/ExecutionFlowTest.java @@ -2,6 +2,7 @@ import com.google.common.collect.ImmutableMap; import io.kestra.core.junit.annotations.KestraTest; +import io.kestra.core.models.property.Property; import org.junit.jupiter.api.Test; import io.kestra.core.models.executions.Execution; import io.kestra.core.models.flows.Flow; @@ -10,6 +11,8 @@ import jakarta.inject.Inject; +import java.util.Map; + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; @@ -24,8 +27,8 @@ void valid() { Execution execution = TestsUtils.mockExecution(flow, ImmutableMap.of()); ExecutionFlow build = ExecutionFlow.builder() - .namespace(flow.getNamespace()) - .flowId(flow.getId()) + .namespace(Property.of(flow.getNamespace())) + .flowId(Property.of(flow.getId())) .build(); boolean test = conditionService.isValid(build, flow, execution); @@ -39,8 +42,8 @@ void notValid() { Execution execution = TestsUtils.mockExecution(flow, ImmutableMap.of()); ExecutionFlow build = ExecutionFlow.builder() - .namespace(flow.getNamespace() + "a") - .flowId(flow.getId()) + .namespace(Property.of(flow.getNamespace() + "a")) + .flowId(Property.of(flow.getId())) .build(); boolean test = conditionService.isValid(build, flow, execution); diff --git a/core/src/test/java/io/kestra/plugin/core/condition/ExecutionNamespaceTest.java b/core/src/test/java/io/kestra/plugin/core/condition/ExecutionNamespaceTest.java index 5f6a1b7bd76..25066f25332 100644 --- a/core/src/test/java/io/kestra/plugin/core/condition/ExecutionNamespaceTest.java +++ b/core/src/test/java/io/kestra/plugin/core/condition/ExecutionNamespaceTest.java @@ -1,6 +1,7 @@ package io.kestra.plugin.core.condition; import com.google.common.collect.ImmutableMap; +import io.kestra.core.models.property.Property; import io.kestra.core.serializers.JacksonMapper; import io.kestra.core.junit.annotations.KestraTest; import org.junit.jupiter.api.Test; @@ -27,7 +28,7 @@ void valid() { Execution execution = TestsUtils.mockExecution(flow, ImmutableMap.of()); ExecutionNamespace build = ExecutionNamespace.builder() - .namespace(flow.getNamespace()) + .namespace(Property.of(flow.getNamespace())) .build(); boolean test = conditionService.isValid(build, flow, execution); @@ -36,8 +37,8 @@ void valid() { // Explicit build = ExecutionNamespace.builder() - .namespace(flow.getNamespace()) - .comparison(ExecutionNamespace.Comparison.EQUALS) + .namespace(Property.of(flow.getNamespace())) + .comparison(Property.of(ExecutionNamespace.Comparison.EQUALS)) .build(); test = conditionService.isValid(build, flow, execution); @@ -50,7 +51,7 @@ void invalid() { Execution execution = TestsUtils.mockExecution(flow, ImmutableMap.of()); ExecutionNamespace build = ExecutionNamespace.builder() - .namespace(flow.getNamespace() + "a") + .namespace(Property.of(flow.getNamespace() + "a")) .build(); boolean test = conditionService.isValid(build, flow, execution); @@ -73,16 +74,16 @@ void prefix() { assertThat(test, is(true)); build = ExecutionNamespace.builder() - .namespace(flow.getNamespace().substring(0, 3)) - .comparison(ExecutionNamespace.Comparison.PREFIX) + .namespace(Property.of(flow.getNamespace().substring(0, 3))) + .comparison(Property.of(ExecutionNamespace.Comparison.PREFIX)) .build(); test = conditionService.isValid(build, flow, execution); assertThat(test, is(true)); build = ExecutionNamespace.builder() - .namespace(flow.getNamespace().substring(0, 3)) - .prefix(true) + .namespace(Property.of(flow.getNamespace().substring(0, 3))) + .prefix(Property.of(true)) .build(); test = conditionService.isValid(build, flow, execution); @@ -96,7 +97,7 @@ void defaultBehaviour() { // Should use EQUALS if prefix is not set ExecutionNamespace build = ExecutionNamespace.builder() - .namespace(flow.getNamespace().substring(0, 3)) + .namespace(Property.of(flow.getNamespace().substring(0, 3))) .build(); boolean test = conditionService.isValid(build, flow, execution); @@ -109,8 +110,8 @@ void suffix() { Execution execution = TestsUtils.mockExecution(flow, ImmutableMap.of()); ExecutionNamespace build = ExecutionNamespace.builder() - .namespace(flow.getNamespace().substring(flow.getNamespace().length() - 4)) - .comparison(ExecutionNamespace.Comparison.SUFFIX) + .namespace(Property.of(flow.getNamespace().substring(flow.getNamespace().length() - 4))) + .comparison(Property.of(ExecutionNamespace.Comparison.SUFFIX)) .build(); boolean test = conditionService.isValid(build, flow, execution); diff --git a/core/src/test/java/io/kestra/plugin/core/condition/ExecutionOutputsTest.java b/core/src/test/java/io/kestra/plugin/core/condition/ExecutionOutputsTest.java index 72a624061f5..c0e8a2b2eac 100644 --- a/core/src/test/java/io/kestra/plugin/core/condition/ExecutionOutputsTest.java +++ b/core/src/test/java/io/kestra/plugin/core/condition/ExecutionOutputsTest.java @@ -2,6 +2,7 @@ import io.kestra.core.models.executions.Execution; import io.kestra.core.models.flows.Flow; +import io.kestra.core.models.property.Property; import io.kestra.core.services.ConditionService; import io.kestra.core.utils.TestsUtils; import io.kestra.core.junit.annotations.KestraTest; @@ -27,7 +28,7 @@ void shouldEvaluateToTrueGivenValidExpression() { Map.of("test", "value")); ExecutionOutputs build = ExecutionOutputs.builder() - .expression("{{ trigger.outputs.test == 'value' }}") + .expression(new Property<>("{{ trigger.outputs.test == 'value' }}")) .build(); boolean test = conditionService.isValid(build, flow, execution); @@ -44,7 +45,7 @@ void shouldEvaluateToFalseGivenInvalidExpression() { Map.of("test", "value")); ExecutionOutputs build = ExecutionOutputs.builder() - .expression("{{ unknown is defined }}") + .expression(new Property<>("{{ unknown is defined }}")) .build(); boolean test = conditionService.isValid(build, flow, execution); @@ -58,7 +59,7 @@ void shouldEvaluateToFalseGivenExecutionWithNoOutputs() { Execution execution = TestsUtils.mockExecution(flow, Map.of()); ExecutionOutputs build = ExecutionOutputs.builder() - .expression("{{ not evaluated }}") + .expression(new Property<>("{{ not evaluated }}")) .build(); boolean test = conditionService.isValid(build, flow, execution); diff --git a/core/src/test/java/io/kestra/plugin/core/condition/ExecutionStatusTest.java b/core/src/test/java/io/kestra/plugin/core/condition/ExecutionStatusTest.java index 3539489aad3..44a046a40fa 100644 --- a/core/src/test/java/io/kestra/plugin/core/condition/ExecutionStatusTest.java +++ b/core/src/test/java/io/kestra/plugin/core/condition/ExecutionStatusTest.java @@ -2,6 +2,7 @@ import com.google.common.collect.ImmutableMap; import io.kestra.core.junit.annotations.KestraTest; +import io.kestra.core.models.property.Property; import org.junit.jupiter.api.Test; import io.kestra.core.models.executions.Execution; import io.kestra.core.models.flows.Flow; @@ -27,7 +28,7 @@ void in() { Execution execution = TestsUtils.mockExecution(flow, ImmutableMap.of()); ExecutionStatus build = ExecutionStatus.builder() - .in(Collections.singletonList(State.Type.SUCCESS)) + .in(Property.of(Collections.singletonList(State.Type.SUCCESS))) .build(); boolean test = conditionService.isValid(build, flow, execution); @@ -41,7 +42,7 @@ void notIn() { Execution execution = TestsUtils.mockExecution(flow, ImmutableMap.of()); ExecutionStatus build = ExecutionStatus.builder() - .notIn(Collections.singletonList(State.Type.SUCCESS)) + .notIn(Property.of(Collections.singletonList(State.Type.SUCCESS))) .build(); boolean test = conditionService.isValid(build, flow, execution); @@ -55,8 +56,8 @@ void both() { Execution execution = TestsUtils.mockExecution(flow, ImmutableMap.of()); ExecutionStatus build = ExecutionStatus.builder() - .in(Collections.singletonList(State.Type.CREATED)) - .notIn(Collections.singletonList(State.Type.SUCCESS)) + .in(Property.of(Collections.singletonList(State.Type.CREATED))) + .notIn(Property.of(Collections.singletonList(State.Type.SUCCESS))) .build(); boolean test = conditionService.isValid(build, flow, execution); diff --git a/core/src/test/java/io/kestra/plugin/core/condition/ExpressionTest.java b/core/src/test/java/io/kestra/plugin/core/condition/ExpressionTest.java index a6dc69de5a2..2c1c0b42874 100644 --- a/core/src/test/java/io/kestra/plugin/core/condition/ExpressionTest.java +++ b/core/src/test/java/io/kestra/plugin/core/condition/ExpressionTest.java @@ -2,6 +2,7 @@ import com.google.common.collect.ImmutableMap; import io.kestra.core.junit.annotations.KestraTest; +import io.kestra.core.models.property.Property; import org.junit.jupiter.api.Test; import io.kestra.core.models.executions.Execution; import io.kestra.core.models.flows.Flow; @@ -24,7 +25,7 @@ void valid() { Execution execution = TestsUtils.mockExecution(flow, ImmutableMap.of("test", "value")); Expression build = Expression.builder() - .expression("{{ flow.id }}") + .expression(new Property<>("{{ flow.id }}")) .build(); boolean test = conditionService.isValid(build, flow, execution); @@ -38,7 +39,7 @@ void invalid() { Execution execution = TestsUtils.mockExecution(flow, ImmutableMap.of("test", "value")); Expression build = Expression.builder() - .expression("{{ unknown is defined }}") + .expression(new Property<>("{{ unknown is defined }}")) .build(); boolean test = conditionService.isValid(build, flow, execution); diff --git a/core/src/test/java/io/kestra/plugin/core/condition/HasRetryAttemptTest.java b/core/src/test/java/io/kestra/plugin/core/condition/HasRetryAttemptTest.java index 52c74fb3940..e93063657de 100644 --- a/core/src/test/java/io/kestra/plugin/core/condition/HasRetryAttemptTest.java +++ b/core/src/test/java/io/kestra/plugin/core/condition/HasRetryAttemptTest.java @@ -6,6 +6,7 @@ import io.kestra.core.models.executions.TaskRunAttempt; import io.kestra.core.models.flows.Flow; import io.kestra.core.models.flows.State; +import io.kestra.core.models.property.Property; import io.kestra.core.services.ConditionService; import io.kestra.core.utils.TestsUtils; import io.kestra.core.junit.annotations.KestraTest; @@ -41,7 +42,7 @@ void test() { )); HasRetryAttempt build = HasRetryAttempt.builder() - .in(Collections.singletonList(State.Type.KILLED)) + .in(Property.of(Collections.singletonList(State.Type.KILLED))) .build(); boolean test = conditionService.isValid(build, flow, execution); @@ -49,7 +50,7 @@ void test() { assertThat(test, is(true)); build = HasRetryAttempt.builder() - .in(Collections.singletonList(State.Type.FAILED)) + .in(Property.of(Collections.singletonList(State.Type.FAILED))) .build(); test = conditionService.isValid(build, flow, execution); diff --git a/core/src/test/java/io/kestra/plugin/core/condition/MultipleConditionTest.java b/core/src/test/java/io/kestra/plugin/core/condition/MultipleConditionTest.java index fc841623693..7aee7fdb4af 100644 --- a/core/src/test/java/io/kestra/plugin/core/condition/MultipleConditionTest.java +++ b/core/src/test/java/io/kestra/plugin/core/condition/MultipleConditionTest.java @@ -2,6 +2,7 @@ import com.google.common.collect.ImmutableMap; import io.kestra.core.models.conditions.Condition; +import io.kestra.core.models.property.Property; import io.kestra.core.models.triggers.multipleflows.MultipleConditionStorageInterface; import io.kestra.core.junit.annotations.KestraTest; import org.junit.jupiter.api.Test; @@ -33,10 +34,10 @@ void simple() { .conditions( ImmutableMap.of( "first", ExecutionStatus.builder() - .in(Collections.singletonList(State.Type.SUCCESS)) + .in(Property.of(Collections.singletonList(State.Type.SUCCESS))) .build(), "second", Expression.builder() - .expression("{{ flow.id }}") + .expression(new Property<>("{{ flow.id }}")) .build() )) .build(); diff --git a/core/src/test/java/io/kestra/plugin/core/condition/NotTest.java b/core/src/test/java/io/kestra/plugin/core/condition/NotTest.java index 2befca28c0b..699ef038cf5 100644 --- a/core/src/test/java/io/kestra/plugin/core/condition/NotTest.java +++ b/core/src/test/java/io/kestra/plugin/core/condition/NotTest.java @@ -4,6 +4,7 @@ import io.kestra.core.models.conditions.Condition; import io.kestra.core.models.executions.Execution; import io.kestra.core.models.flows.Flow; +import io.kestra.core.models.property.Property; import io.kestra.core.services.ConditionService; import io.kestra.core.utils.TestsUtils; import io.kestra.core.junit.annotations.KestraTest; @@ -31,8 +32,8 @@ static Stream source() { Arguments.of( Collections.singletonList( DayWeek.builder() - .date("2013-09-08") - .dayOfWeek(DayOfWeek.SUNDAY) + .date(Property.of("2013-09-08")) + .dayOfWeek(Property.of(DayOfWeek.SUNDAY)) .build() ), false @@ -40,12 +41,12 @@ static Stream source() { Arguments.of( Arrays.asList( DayWeek.builder() - .date("2013-09-08") - .dayOfWeek(DayOfWeek.SATURDAY) + .date(Property.of("2013-09-08")) + .dayOfWeek(Property.of(DayOfWeek.SATURDAY)) .build(), DayWeek.builder() - .date("2013-09-08") - .dayOfWeek(DayOfWeek.MONDAY) + .date(Property.of("2013-09-08")) + .dayOfWeek(Property.of(DayOfWeek.MONDAY)) .build() ), true @@ -53,12 +54,12 @@ static Stream source() { Arguments.of( Arrays.asList( DayWeek.builder() - .date("2013-09-08") - .dayOfWeek(DayOfWeek.SUNDAY) + .date(Property.of("2013-09-08")) + .dayOfWeek(Property.of(DayOfWeek.SUNDAY)) .build(), DayWeek.builder() - .date("2013-09-08") - .dayOfWeek(DayOfWeek.MONDAY) + .date(Property.of("2013-09-08")) + .dayOfWeek(Property.of(DayOfWeek.MONDAY)) .build() ), false diff --git a/core/src/test/java/io/kestra/plugin/core/condition/OrTest.java b/core/src/test/java/io/kestra/plugin/core/condition/OrTest.java index ab08687f3e1..012411fcea8 100644 --- a/core/src/test/java/io/kestra/plugin/core/condition/OrTest.java +++ b/core/src/test/java/io/kestra/plugin/core/condition/OrTest.java @@ -4,6 +4,7 @@ import io.kestra.core.models.conditions.Condition; import io.kestra.core.models.executions.Execution; import io.kestra.core.models.flows.Flow; +import io.kestra.core.models.property.Property; import io.kestra.core.services.ConditionService; import io.kestra.core.utils.TestsUtils; import io.kestra.core.junit.annotations.KestraTest; @@ -31,8 +32,8 @@ static Stream source() { Arguments.of( Collections.singletonList( DayWeek.builder() - .date("2013-09-08") - .dayOfWeek(DayOfWeek.SUNDAY) + .date(Property.of("2013-09-08")) + .dayOfWeek(Property.of(DayOfWeek.SUNDAY)) .build() ), true @@ -40,12 +41,12 @@ static Stream source() { Arguments.of( Arrays.asList( DayWeek.builder() - .date("2013-09-08") - .dayOfWeek(DayOfWeek.SATURDAY) + .date(Property.of("2013-09-08")) + .dayOfWeek(Property.of(DayOfWeek.SATURDAY)) .build(), DayWeek.builder() - .date("2013-09-08") - .dayOfWeek(DayOfWeek.MONDAY) + .date(Property.of("2013-09-08")) + .dayOfWeek(Property.of(DayOfWeek.MONDAY)) .build() ), false @@ -53,12 +54,12 @@ static Stream source() { Arguments.of( Arrays.asList( DayWeek.builder() - .date("2013-09-08") - .dayOfWeek(DayOfWeek.SUNDAY) + .date(Property.of("2013-09-08")) + .dayOfWeek(Property.of(DayOfWeek.SUNDAY)) .build(), DayWeek.builder() - .date("2013-09-08") - .dayOfWeek(DayOfWeek.MONDAY) + .date(Property.of("2013-09-08")) + .dayOfWeek(Property.of(DayOfWeek.MONDAY)) .build() ), true diff --git a/core/src/test/java/io/kestra/plugin/core/condition/PublicHolidayTest.java b/core/src/test/java/io/kestra/plugin/core/condition/PublicHolidayTest.java index f3c9ccd513f..f190f29ba64 100644 --- a/core/src/test/java/io/kestra/plugin/core/condition/PublicHolidayTest.java +++ b/core/src/test/java/io/kestra/plugin/core/condition/PublicHolidayTest.java @@ -3,6 +3,7 @@ import com.google.common.collect.ImmutableMap; import io.kestra.core.models.executions.Execution; import io.kestra.core.models.flows.Flow; +import io.kestra.core.models.property.Property; import io.kestra.core.services.ConditionService; import io.kestra.core.utils.TestsUtils; import io.kestra.core.junit.annotations.KestraTest; @@ -23,20 +24,20 @@ void valid() { Execution execution = TestsUtils.mockExecution(flow, ImmutableMap.of()); PublicHoliday publicHoliday = PublicHoliday.builder() - .date("2023-01-01") + .date(Property.of("2023-01-01")) .build(); assertThat(conditionService.isValid(publicHoliday, flow, execution), is(true)); publicHoliday = PublicHoliday.builder() - .date("2023-07-14") - .country("FR") + .date(Property.of("2023-07-14")) + .country(Property.of("FR")) .build(); assertThat(conditionService.isValid(publicHoliday, flow, execution), is(true)); publicHoliday = PublicHoliday.builder() - .date("2023-03-08") - .country("DE") - .subDivision("BE") + .date(Property.of("2023-03-08")) + .country(Property.of("DE")) + .subDivision(Property.of("BE")) .build(); assertThat(conditionService.isValid(publicHoliday, flow, execution), is(true)); } @@ -47,14 +48,14 @@ void invalid() { Execution execution = TestsUtils.mockExecution(flow, ImmutableMap.of()); PublicHoliday publicHoliday = PublicHoliday.builder() - .date("2023-01-02") - .country("FR") + .date(Property.of("2023-01-02")) + .country(Property.of("FR")) .build(); assertThat(conditionService.isValid(publicHoliday, flow, execution), is(false)); publicHoliday = PublicHoliday.builder() - .date("2023-03-08") - .country("DE") + .date(Property.of("2023-03-08")) + .country(Property.of("DE")) .build(); assertThat(conditionService.isValid(publicHoliday, flow, execution), is(false)); } diff --git a/core/src/test/java/io/kestra/plugin/core/condition/TimeBetweenTest.java b/core/src/test/java/io/kestra/plugin/core/condition/TimeBetweenTest.java index 0c26072ca1e..082f28c6d5a 100644 --- a/core/src/test/java/io/kestra/plugin/core/condition/TimeBetweenTest.java +++ b/core/src/test/java/io/kestra/plugin/core/condition/TimeBetweenTest.java @@ -3,6 +3,7 @@ import com.google.common.collect.ImmutableMap; import io.kestra.core.models.executions.Execution; import io.kestra.core.models.flows.Flow; +import io.kestra.core.models.property.Property; import io.kestra.core.services.ConditionService; import io.kestra.core.utils.TestsUtils; import io.kestra.core.junit.annotations.KestraTest; @@ -40,7 +41,7 @@ void valid(String date, OffsetTime before, OffsetTime after, boolean result) { Execution execution = TestsUtils.mockExecution(flow, ImmutableMap.of()); TimeBetween build = TimeBetween.builder() - .date(date) + .date(Property.of(date)) .before(before) .after(after) .build(); diff --git a/core/src/test/java/io/kestra/plugin/core/condition/WeekendTest.java b/core/src/test/java/io/kestra/plugin/core/condition/WeekendTest.java index d56dce4c7d6..ca8858a87f1 100644 --- a/core/src/test/java/io/kestra/plugin/core/condition/WeekendTest.java +++ b/core/src/test/java/io/kestra/plugin/core/condition/WeekendTest.java @@ -3,6 +3,7 @@ import com.google.common.collect.ImmutableMap; import io.kestra.core.models.executions.Execution; import io.kestra.core.models.flows.Flow; +import io.kestra.core.models.property.Property; import io.kestra.core.services.ConditionService; import io.kestra.core.utils.TestsUtils; import io.kestra.core.junit.annotations.KestraTest; @@ -38,7 +39,7 @@ void valid(String date, boolean result) { Execution execution = TestsUtils.mockExecution(flow, ImmutableMap.of()); Weekend build = Weekend.builder() - .date(date) + .date(new Property<>(date)) .build(); boolean test = conditionService.isValid(build, flow, execution); diff --git a/core/src/test/java/io/kestra/plugin/core/trigger/ScheduleTest.java b/core/src/test/java/io/kestra/plugin/core/trigger/ScheduleTest.java index 83baa1993b5..5a44edd1b7c 100644 --- a/core/src/test/java/io/kestra/plugin/core/trigger/ScheduleTest.java +++ b/core/src/test/java/io/kestra/plugin/core/trigger/ScheduleTest.java @@ -310,13 +310,15 @@ void systemBackfillChangedFromCronExpression() throws Exception { void conditions() throws Exception { Schedule trigger = Schedule.builder() .id("schedule") + .type(Schedule.class.getName()) .cron("0 12 * * 1") .timezone("Europe/Paris") .conditions(List.of( DayWeekInMonth.builder() - .dayOfWeek(DayOfWeek.MONDAY) - .dayInMonth(DayWeekInMonth.DayInMonth.FIRST) - .date("{{ trigger.date }}") + .type(DayWeekInMonth.class.getName()) + .dayOfWeek(Property.of(DayOfWeek.MONDAY)) + .dayInMonth(Property.of(DayWeekInMonth.DayInMonth.FIRST)) + .date(new Property<>("{{ trigger.date }}")) .build() )) .build(); @@ -343,12 +345,14 @@ void conditions() throws Exception { void impossibleNextConditions() throws Exception { Schedule trigger = Schedule.builder() .id("schedule") + .type(Schedule.class.getName()) .cron("0 12 * * 1") .timezone("Europe/Paris") .conditions(List.of( DateTimeBetween.builder() - .before(ZonedDateTime.parse("2021-08-03T12:00:00+02:00")) - .date("{{ trigger.date }}") + .type(DateTimeBetween.class.getName()) + .before(Property.of(ZonedDateTime.parse("2021-08-03T12:00:00+02:00"))) + .date(new Property<>("{{ trigger.date }}")) .build() )) .build();