diff --git a/core/src/main/java/io/kestra/core/services/FlowService.java b/core/src/main/java/io/kestra/core/services/FlowService.java index ad28bb433d5..222f1949829 100644 --- a/core/src/main/java/io/kestra/core/services/FlowService.java +++ b/core/src/main/java/io/kestra/core/services/FlowService.java @@ -68,6 +68,10 @@ public List findByNamespaceWithSource(String tenantId, String na return flowRepository.findByNamespaceWithSource(tenantId, namespace); } + public Optional findById(String tenantId, String namespace, String id) { + return flowRepository.findById(tenantId, namespace, id); + } + public Stream keepLastVersion(Stream stream) { return keepLastVersionCollector(stream); } diff --git a/core/src/test/java/io/kestra/core/services/FlowServiceTest.java b/core/src/test/java/io/kestra/core/services/FlowServiceTest.java index 1feae757fd1..9af285330f0 100644 --- a/core/src/test/java/io/kestra/core/services/FlowServiceTest.java +++ b/core/src/test/java/io/kestra/core/services/FlowServiceTest.java @@ -1,5 +1,6 @@ package io.kestra.core.services; +import io.kestra.core.repositories.FlowRepositoryInterface; import io.micronaut.test.extensions.junit5.annotation.MicronautTest; import org.junit.jupiter.api.Test; import io.kestra.core.models.flows.Flow; @@ -16,13 +17,20 @@ @MicronautTest class FlowServiceTest { + @Inject + private FlowRepositoryInterface flowRepository; @Inject private FlowService flowService; private static Flow create(String flowId, String taskId, Integer revision) { + return create(null, flowId, taskId, revision); + } + + private static Flow create(String tenantId, String flowId, String taskId, Integer revision) { return Flow.builder() .id(flowId) .namespace("io.kestra.unittest") + .tenantId(tenantId) .revision(revision) .tasks(Collections.singletonList(Return.builder() .id(taskId) @@ -100,4 +108,12 @@ public void multipleFlow() { assertThat(collect.stream().filter(flow -> flow.getId().equals("test2")).findFirst().orElseThrow().getRevision(), is(3)); assertThat(collect.stream().filter(flow -> flow.getId().equals("test3")).findFirst().orElseThrow().getRevision(), is(3)); } + + @Test + public void findById() { + Flow flow = create("my-tenant", "test", "test", 1); + flowRepository.create(flow, flow.generateSource(), flow); + assertThat(flowService.findById("my-tenant", "io.kestra.unittest", "test").isPresent(), is(true)); + assertThat(flowService.findById(null, "io.kestra.unittest", "test").isPresent(), is(false)); + } } \ No newline at end of file