From 46daee5de5cac7bde387420eef95b5a13db19b79 Mon Sep 17 00:00:00 2001 From: fjtirado Date: Tue, 23 Sep 2025 20:24:14 +0200 Subject: [PATCH] [Fix #805] WorkflowDefinitionId should be public Signed-off-by: fjtirado --- .../impl/WorkflowApplication.java | 19 +++++----- .../impl/WorkflowDefinitionId.java | 35 +++++++++++++++++++ ...ry.java => WorkflowInstanceIdFactory.java} | 2 +- 3 files changed, 44 insertions(+), 12 deletions(-) create mode 100644 impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowDefinitionId.java rename impl/core/src/main/java/io/serverlessworkflow/impl/{WorkflowIdFactory.java => WorkflowInstanceIdFactory.java} (91%) diff --git a/impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowApplication.java b/impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowApplication.java index bc70f8d2..09cfe7c3 100644 --- a/impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowApplication.java +++ b/impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowApplication.java @@ -16,7 +16,6 @@ package io.serverlessworkflow.impl; import com.github.f4b6a3.ulid.UlidCreator; -import io.serverlessworkflow.api.types.Document; import io.serverlessworkflow.api.types.SchemaInline; import io.serverlessworkflow.api.types.Workflow; import io.serverlessworkflow.impl.events.EventConsumer; @@ -52,9 +51,9 @@ public class WorkflowApplication implements AutoCloseable { private final ExpressionFactory exprFactory; private final ResourceLoaderFactory resourceLoaderFactory; private final SchemaValidatorFactory schemaValidatorFactory; - private final WorkflowIdFactory idFactory; + private final WorkflowInstanceIdFactory idFactory; private final Collection listeners; - private final Map definitions; + private final Map definitions; private final WorkflowPositionFactory positionFactory; private final ExecutorServiceFactory executorFactory; private final RuntimeDescriptorFactory runtimeDescriptorFactory; @@ -106,7 +105,7 @@ public Collection eventPublishers() { return eventPublishers; } - public WorkflowIdFactory idFactory() { + public WorkflowInstanceIdFactory idFactory() { return idFactory; } @@ -142,7 +141,7 @@ public SchemaValidator getValidator(SchemaInline inline) { private ResourceLoaderFactory resourceLoaderFactory = DefaultResourceLoaderFactory.get(); private SchemaValidatorFactory schemaValidatorFactory; private WorkflowPositionFactory positionFactory = () -> new QueueWorkflowPosition(); - private WorkflowIdFactory idFactory = () -> UlidCreator.getMonotonicUlid().toString(); + private WorkflowInstanceIdFactory idFactory = () -> UlidCreator.getMonotonicUlid().toString(); private ExecutorServiceFactory executorFactory = new DefaultExecutorServiceFactory(); private EventConsumer eventConsumer; private Collection eventPublishers = new ArrayList<>(); @@ -192,7 +191,7 @@ public Builder withSchemaValidatorFactory(SchemaValidatorFactory factory) { return this; } - public Builder withIdFactory(WorkflowIdFactory factory) { + public Builder withIdFactory(WorkflowInstanceIdFactory factory) { this.idFactory = factory; return this; } @@ -249,15 +248,13 @@ public WorkflowApplication build() { } } - private static record WorkflowId(String namespace, String name, String version) { - static WorkflowId of(Document document) { - return new WorkflowId(document.getNamespace(), document.getName(), document.getVersion()); - } + public Map workflowDefinitions() { + return Collections.unmodifiableMap(definitions); } public WorkflowDefinition workflowDefinition(Workflow workflow) { return definitions.computeIfAbsent( - WorkflowId.of(workflow.getDocument()), k -> WorkflowDefinition.of(this, workflow)); + WorkflowDefinitionId.of(workflow), k -> WorkflowDefinition.of(this, workflow)); } @Override diff --git a/impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowDefinitionId.java b/impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowDefinitionId.java new file mode 100644 index 00000000..0c9dfb40 --- /dev/null +++ b/impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowDefinitionId.java @@ -0,0 +1,35 @@ +/* + * Copyright 2020-Present The Serverless Workflow Specification Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.serverlessworkflow.impl; + +import io.serverlessworkflow.api.types.Document; +import io.serverlessworkflow.api.types.Workflow; + +record WorkflowDefinitionId(String namespace, String name, String version) { + + public static final String DEFAULT_VERSION = "0.0.1"; + public static final String DEFAULT_NAMESPACE = "org.acme"; + + public static WorkflowDefinitionId of(Workflow workflow) { + Document document = workflow.getDocument(); + return new WorkflowDefinitionId( + document.getNamespace(), document.getName(), document.getVersion()); + } + + public static WorkflowDefinitionId fromName(String name) { + return new WorkflowDefinitionId(DEFAULT_NAMESPACE, name, DEFAULT_VERSION); + } +} diff --git a/impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowIdFactory.java b/impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowInstanceIdFactory.java similarity index 91% rename from impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowIdFactory.java rename to impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowInstanceIdFactory.java index 12b0f7c6..22a27559 100644 --- a/impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowIdFactory.java +++ b/impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowInstanceIdFactory.java @@ -18,4 +18,4 @@ import java.util.function.Supplier; @FunctionalInterface -public interface WorkflowIdFactory extends Supplier {} +public interface WorkflowInstanceIdFactory extends Supplier {}