refactor: migrate plugin condition to dynamic properties (#6907)

* refactor: migrate plugin condition to dynamic properties
This commit is contained in:
Mathieu Gabelle
2025-04-04 08:18:01 +02:00
committed by GitHub
parent efe0c6e1e4
commit 1bba3e4035
38 changed files with 250 additions and 198 deletions

View File

@@ -8,12 +8,15 @@ 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.utils.DateUtils;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import lombok.experimental.SuperBuilder;
import java.time.ZonedDateTime;
import java.util.Map;
import jakarta.validation.constraints.NotNull;
@SuperBuilder
@@ -59,7 +62,7 @@ import jakarta.validation.constraints.NotNull;
- id: log_message
type: io.kestra.plugin.core.log.Log
message: "This flow will be executed once every 5 minutes between the before and after dates"
triggers:
- id: schedule
type: io.kestra.plugin.core.trigger.Schedule
@@ -88,30 +91,31 @@ public class DateTimeBetween extends Condition implements ScheduleCondition {
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<ZonedDateTime> 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<ZonedDateTime> before;
@Override
public boolean test(ConditionContext conditionContext) throws InternalException {
String render = conditionContext.getRunContext().render(date, conditionContext.getVariables());
Map<String, Object> vars = conditionContext.getVariables();
String render = conditionContext.getRunContext().render(date, vars);
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);
ZonedDateTime afterRendered = conditionContext.getRunContext().render(this.after).as(ZonedDateTime.class, vars).orElse(null);
ZonedDateTime beforeRendered = conditionContext.getRunContext().render(this.before).as(ZonedDateTime.class, vars).orElse(null);
if (beforeRendered != null && afterRendered != null) {
return currentDate.isAfter(afterRendered) && currentDate.isBefore(beforeRendered);
} else if (beforeRendered != null) {
return currentDate.isBefore(beforeRendered);
} else if (afterRendered != null) {
return currentDate.isAfter(afterRendered);
} else {
throw new IllegalConditionEvaluation("Invalid condition with no before nor after");
}
}
}

View File

@@ -3,10 +3,11 @@ package io.kestra.plugin.core.condition;
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.*;
@@ -57,19 +58,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<String> date = new Property<>("{{ trigger.date }}");
@NotNull
@Schema(title = "The day of week.")
@PluginProperty
private DayOfWeek dayOfWeek;
private Property<DayOfWeek> 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());
}
}

View File

@@ -7,6 +7,8 @@ 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.*;
@@ -15,6 +17,8 @@ import lombok.experimental.SuperBuilder;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
import java.util.Map;
import jakarta.validation.constraints.NotNull;
@SuperBuilder
@@ -64,30 +68,34 @@ public class DayWeekInMonth extends Condition implements ScheduleCondition {
@NotNull
@Schema(title = "The day of week.")
@PluginProperty
private DayOfWeek dayOfWeek;
private Property<DayOfWeek> dayOfWeek;
@NotNull
@Schema(title = "Are you looking for the first or the last day in the month?")
@PluginProperty
private DayWeekInMonth.DayInMonth dayInMonth;
private Property<DayWeekInMonth.DayInMonth> dayInMonth;
@Override
public boolean test(ConditionContext conditionContext) throws InternalException {
String render = conditionContext.getRunContext().render(date, conditionContext.getVariables());
Map<String, Object> vars = conditionContext.getVariables();
RunContext runContext = conditionContext.getRunContext();
String render = runContext.render(date, vars);
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));
DayOfWeek renderedDayOfWeek = runContext.render(this.dayOfWeek).as(DayOfWeek.class, vars).orElseThrow();
DayWeekInMonth.DayInMonth renderedDayInMonth = runContext.render(this.dayInMonth).as(DayWeekInMonth.DayInMonth.class, vars).orElseThrow();
if (renderedDayInMonth.equals(DayInMonth.FIRST)) {
computed = currentDate.with(TemporalAdjusters.firstInMonth(renderedDayOfWeek));
} else if (renderedDayInMonth.equals(DayInMonth.LAST)) {
computed = currentDate.with(TemporalAdjusters.lastInMonth(renderedDayOfWeek));
} else if (renderedDayInMonth.equals(DayInMonth.SECOND)) {
computed = currentDate.with(TemporalAdjusters.firstInMonth(renderedDayOfWeek)).with(TemporalAdjusters.next(renderedDayOfWeek));
} else if (renderedDayInMonth.equals(DayInMonth.THIRD)) {
computed = currentDate.with(TemporalAdjusters.firstInMonth(renderedDayOfWeek)).with(TemporalAdjusters.next(renderedDayOfWeek)).with(TemporalAdjusters.next(renderedDayOfWeek));
} else if (renderedDayInMonth.equals(DayInMonth.FOURTH)) {
computed = currentDate.with(TemporalAdjusters.firstInMonth(renderedDayOfWeek)).with(TemporalAdjusters.next(renderedDayOfWeek)).with(TemporalAdjusters.next(renderedDayOfWeek)).with(TemporalAdjusters.next(renderedDayOfWeek));
} else {
throw new IllegalArgumentException("Invalid dayInMonth");
}

View File

@@ -2,7 +2,8 @@ package io.kestra.plugin.core.condition;
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;
@@ -55,13 +56,11 @@ import jakarta.validation.constraints.NotNull;
public class ExecutionFlow extends Condition {
@NotNull
@Schema(title = "The namespace of the flow.")
@PluginProperty
private String namespace;
private Property<String> namespace;
@NotNull
@Schema(title = "The flow id.")
@PluginProperty
private String flowId;
private Property<String> flowId;
@Override
public boolean test(ConditionContext conditionContext) throws InternalException {
@@ -69,6 +68,8 @@ public class ExecutionFlow extends Condition {
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());
}
}

View File

@@ -3,6 +3,8 @@ package io.kestra.plugin.core.condition;
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;
@@ -56,22 +58,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<String> 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> 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<Boolean> prefix = Property.of(false);
@Override
public boolean test(ConditionContext conditionContext) throws InternalException {
@@ -79,8 +78,13 @@ public class ExecutionNamespace extends Condition {
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 {

View File

@@ -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.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;
@@ -89,9 +90,7 @@ public class ExecutionOutputs extends Condition implements ScheduleCondition {
private static final String OUTPUTS_VAR = "outputs";
@NotNull
@NotEmpty
@PluginProperty
private String expression;
private Property<String> expression;
/** {@inheritDoc} **/
@SuppressWarnings("unchecked")
@@ -107,8 +106,8 @@ public class ExecutionOutputs extends Condition implements ScheduleCondition {
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) {

View File

@@ -3,6 +3,8 @@ package io.kestra.plugin.core.condition;
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;
@@ -54,13 +56,11 @@ import jakarta.validation.Valid;
public class ExecutionStatus extends Condition {
@Valid
@Schema(title = "List of states that are authorized.")
@PluginProperty
private List<State.Type> in;
private Property<List<State.Type>> in;
@Valid
@Schema(title = "List of states that aren't authorized.")
@PluginProperty
private List<State.Type> notIn;
private Property<List<State.Type>> notIn;
@Override
public boolean test(ConditionContext conditionContext) throws InternalException {
@@ -70,11 +70,14 @@ public class ExecutionStatus extends Condition {
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;
}

View File

@@ -7,6 +7,7 @@ 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.swagger.v3.oas.annotations.media.Schema;
import lombok.EqualsAndHashCode;
import lombok.Getter;
@@ -54,13 +55,11 @@ import jakarta.validation.constraints.NotNull;
)
public class Expression extends Condition implements ScheduleCondition {
@NotNull
@NotEmpty
@PluginProperty
private String expression;
private Property<String> 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"));
}
}

View File

@@ -8,6 +8,8 @@ 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.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;
@@ -55,13 +57,11 @@ import jakarta.validation.Valid;
public class HasRetryAttempt extends Condition {
@Valid
@Schema(title = "List of states that are authorized.")
@PluginProperty
private List<State.Type> in;
private Property<List<State.Type>> in;
@Valid
@Schema(title = "List of states that aren't authorized.")
@PluginProperty
private List<State.Type> notIn;
private Property<List<State.Type>> notIn;
@Override
public boolean test(ConditionContext conditionContext) throws InternalException {
@@ -69,6 +69,10 @@ public class HasRetryAttempt extends Condition {
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()
@@ -78,11 +82,11 @@ public class HasRetryAttempt extends Condition {
.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;
}

View File

@@ -9,9 +9,11 @@ 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.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;
@@ -76,36 +78,33 @@ import java.time.LocalDate;
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<String> 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<String> 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<String> 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);
}
}

View File

@@ -4,10 +4,11 @@ import io.kestra.core.exceptions.IllegalConditionEvaluation;
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 jakarta.validation.constraints.NotNull;
@@ -15,6 +16,7 @@ import lombok.*;
import lombok.experimental.SuperBuilder;
import java.time.OffsetTime;
import java.util.Map;
@SuperBuilder
@ToString
@@ -58,34 +60,37 @@ 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<String> date = new Property<>("{{ trigger.date }}");
@Schema(
title = "The time to test must be after this one.",
description = "Must be a valid ISO 8601 time with offset."
)
@PluginProperty
private OffsetTime after;
private Property<OffsetTime> after;
@Schema(
title = "The time to test must be before this one.",
description = "Must be a valid ISO 8601 time with offset."
)
@PluginProperty
private OffsetTime before;
private Property<OffsetTime> before;
@Override
public boolean test(ConditionContext conditionContext) throws InternalException {
String render = conditionContext.getRunContext().render(date, conditionContext.getVariables());
OffsetTime currentDate = DateUtils.parseZonedDateTime(render).toOffsetDateTime().toOffsetTime();
RunContext runContext = conditionContext.getRunContext();
Map<String, Object> variables = conditionContext.getVariables();
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);
String dateRendered = runContext.render(date).as(String.class, variables).orElseThrow();
OffsetTime currentDate = DateUtils.parseZonedDateTime(dateRendered).toOffsetDateTime().toOffsetTime();
OffsetTime beforeRendered = runContext.render(before).as(OffsetTime.class, variables).orElse(null);
OffsetTime afterRendered = runContext.render(after).as(OffsetTime.class, variables).orElse(null);
if (beforeRendered != null && afterRendered != null) {
return currentDate.isAfter(afterRendered) && currentDate.isBefore(beforeRendered);
} else if (beforeRendered != null) {
return currentDate.isBefore(beforeRendered);
} else if (afterRendered != null) {
return currentDate.isAfter(afterRendered);
} else {
throw new IllegalConditionEvaluation("Invalid condition with no before nor after");
}

View File

@@ -7,6 +7,7 @@ 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.utils.DateUtils;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
@@ -56,12 +57,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<String> 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) ||

View File

@@ -110,7 +110,7 @@ class FlowWithSourceTest {
))
.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(

View File

@@ -2,6 +2,7 @@ package io.kestra.core.models.triggers.multipleflows;
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.Test;
import io.kestra.plugin.core.condition.ExecutionFlow;
@@ -237,12 +238,12 @@ public abstract class AbstractMultipleConditionStorageTest {
.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)

View File

@@ -20,7 +20,7 @@ import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
@KestraTest(startRunner = true)
public class ListenersTest {
class ListenersTest {
@Inject
private RunnerUtils runnerUtils;

View File

@@ -3,6 +3,7 @@ package io.kestra.core.schedulers;
import io.kestra.core.models.executions.Execution;
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.models.triggers.Trigger;
import io.kestra.core.repositories.FlowRepositoryInterface;
import io.kestra.core.runners.FlowListeners;
@@ -55,8 +56,8 @@ class SchedulerConditionTest extends AbstractSchedulerTest {
DayWeekInMonth.builder()
.type(DayWeekInMonth.class.getName())
.date("{{ trigger.date }}")
.dayOfWeek(DayOfWeek.MONDAY)
.dayInMonth(DayWeekInMonth.DayInMonth.FIRST)
.dayOfWeek(Property.of(DayOfWeek.MONDAY))
.dayInMonth(Property.of(DayWeekInMonth.DayInMonth.FIRST))
.build()
))
.build();

View File

@@ -1,6 +1,7 @@
package io.kestra.core.schedulers;
import io.kestra.core.models.Label;
import io.kestra.core.models.property.Property;
import io.kestra.core.repositories.FlowRepositoryInterface;
import io.kestra.core.utils.TestsUtils;
import io.kestra.jdbc.runner.JdbcScheduler;
@@ -145,7 +146,7 @@ public class SchedulerPollingTriggerTest extends AbstractSchedulerTest {
List.of(
Expression.builder()
.type(Expression.class.getName())
.expression("{{ trigger.date | date() < now() }}")
.expression(new Property<>("{{ trigger.date | date() < now() }}"))
.build()
))
.build();

View File

@@ -4,6 +4,7 @@ import com.devskiller.friendly_id.FriendlyId;
import io.kestra.core.models.executions.TaskRun;
import io.kestra.core.models.flows.FlowWithSource;
import io.kestra.core.models.flows.PluginDefault;
import io.kestra.core.models.property.Property;
import io.kestra.core.repositories.FlowRepositoryInterface;
import io.kestra.core.utils.TestsUtils;
import io.kestra.jdbc.runner.JdbcScheduler;
@@ -480,7 +481,7 @@ public class SchedulerScheduleTest extends AbstractSchedulerTest {
List.of(
Expression.builder()
.type(Expression.class.getName())
.expression("{{ trigger.date | date() < now() }}")
.expression(new Property<>("{{ trigger.date | date() < now() }}"))
.build()
)
)

View File

@@ -3,6 +3,7 @@ package io.kestra.core.services;
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 @@ class ConditionServiceTest {
List<Condition> 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 @@ class ConditionServiceTest {
List<Condition> conditions = Collections.singletonList(
ExecutionFlow.builder()
.namespace(flow.getNamespace())
.flowId(flow.getId())
.namespace(Property.of(flow.getNamespace()))
.flowId(Property.of(flow.getId()))
.build()
);

View File

@@ -109,11 +109,11 @@ class FlowTopologyServiceTest {
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 @@ class FlowTopologyServiceTest {
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()

View File

@@ -176,7 +176,7 @@ class PluginDefaultServiceTest {
}
@Test
public void injectFlowAndGlobals() {
void injectFlowAndGlobals() {
String source = """
id: default-test
namespace: io.kestra.tests
@@ -222,7 +222,7 @@ class PluginDefaultServiceTest {
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

View File

@@ -3,6 +3,7 @@ package io.kestra.plugin.core.condition;
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;
@@ -41,8 +42,8 @@ class DateTimeBetweenTest {
DateTimeBetween build = DateTimeBetween.builder()
.date(date)
.before(before)
.after(after)
.before(Property.of(before))
.after(Property.of(after))
.build();
boolean test = conditionService.isValid(build, flow, execution);

View File

@@ -3,6 +3,7 @@ package io.kestra.plugin.core.condition;
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;
@@ -44,8 +45,8 @@ class DayWeekInMonthTest {
DayWeekInMonth build = DayWeekInMonth.builder()
.date(date)
.dayOfWeek(dayOfWeek)
.dayInMonth(dayInMonth)
.dayOfWeek(Property.of(dayOfWeek))
.dayInMonth(Property.of(dayInMonth))
.build();
boolean test = conditionService.isValid(build, flow, execution);

View File

@@ -3,6 +3,7 @@ package io.kestra.plugin.core.condition;
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 @@ class DayWeekTest {
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);

View File

@@ -2,6 +2,7 @@ package io.kestra.plugin.core.condition;
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 io.kestra.core.utils.TestsUtils;
import jakarta.inject.Inject;
import java.util.Map;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
@@ -24,8 +27,8 @@ class ExecutionFlowTest {
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 @@ class ExecutionFlowTest {
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);

View File

@@ -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 @@ class ExecutionNamespaceTest {
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 @@ class ExecutionNamespaceTest {
// 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 @@ class ExecutionNamespaceTest {
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 @@ class ExecutionNamespaceTest {
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 @@ class ExecutionNamespaceTest {
// 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 @@ class ExecutionNamespaceTest {
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);

View File

@@ -2,6 +2,7 @@ package io.kestra.plugin.core.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;
@@ -27,7 +28,7 @@ class ExecutionOutputsTest {
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 @@ class ExecutionOutputsTest {
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 @@ class ExecutionOutputsTest {
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);

View File

@@ -2,6 +2,7 @@ package io.kestra.plugin.core.condition;
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 @@ class ExecutionStatusTest {
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 @@ class ExecutionStatusTest {
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 @@ class ExecutionStatusTest {
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);

View File

@@ -2,6 +2,7 @@ package io.kestra.plugin.core.condition;
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 @@ class ExpressionTest {
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 @@ class ExpressionTest {
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);

View File

@@ -6,6 +6,7 @@ import io.kestra.core.models.executions.TaskRun;
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 @@ class HasRetryAttemptTest {
));
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 @@ class HasRetryAttemptTest {
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);

View File

@@ -2,6 +2,7 @@ package io.kestra.plugin.core.condition;
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 @@ class MultipleConditionTest {
.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();

View File

@@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableMap;
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 @@ class NotTest {
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 @@ class NotTest {
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 @@ class NotTest {
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

View File

@@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableMap;
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 @@ class OrTest {
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 @@ class OrTest {
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 @@ class OrTest {
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

View File

@@ -3,6 +3,7 @@ package io.kestra.plugin.core.condition;
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 @@ class PublicHolidayTest {
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 @@ class PublicHolidayTest {
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));
}

View File

@@ -3,6 +3,7 @@ package io.kestra.plugin.core.condition;
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 @@ class TimeBetweenTest {
Execution execution = TestsUtils.mockExecution(flow, ImmutableMap.of());
TimeBetween build = TimeBetween.builder()
.date(date)
.before(before)
.after(after)
.date(Property.of(date))
.before(Property.of(before))
.after(Property.of(after))
.build();
boolean test = conditionService.isValid(build, flow, execution);

View File

@@ -3,6 +3,7 @@ package io.kestra.plugin.core.condition;
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 @@ class WeekendTest {
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);

View File

@@ -315,12 +315,14 @@ class ScheduleTest {
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)
.type(DayWeekInMonth.class.getName())
.dayOfWeek(Property.of(DayOfWeek.MONDAY))
.dayInMonth(Property.of(DayWeekInMonth.DayInMonth.FIRST))
.date("{{ trigger.date }}")
.build()
))
@@ -348,11 +350,13 @@ class ScheduleTest {
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"))
.type(DateTimeBetween.class.getName())
.before(Property.of(ZonedDateTime.parse("2021-08-03T12:00:00+02:00")))
.date("{{ trigger.date }}")
.build()
))

View File

@@ -121,6 +121,6 @@ class LogConsumerTest {
assertThat(logs.stream().filter(m -> m.getLevel().equals(Level.INFO)).count(), is(1L));
assertThat(logs.stream().filter(m -> m.getLevel().equals(Level.ERROR)).count(), is(1L));
assertThat(logs.stream().filter(m -> m.getLevel().equals(Level.TRACE)).filter(m -> m.getMessage().contains("Trace 2")).count(), is(1L));
assertThat(logs.stream().filter(m -> m.getLevel().equals(Level.TRACE)).count(), greaterThanOrEqualTo(5L));
assertThat(logs.stream().filter(m -> m.getLevel().equals(Level.TRACE)).count(), greaterThanOrEqualTo(4L));
}
}