Skip to content

Commit 46daee5

Browse files
committed
[Fix #805] WorkflowDefinitionId should be public
Signed-off-by: fjtirado <[email protected]>
1 parent fec6de9 commit 46daee5

File tree

3 files changed

+44
-12
lines changed

3 files changed

+44
-12
lines changed

impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowApplication.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package io.serverlessworkflow.impl;
1717

1818
import com.github.f4b6a3.ulid.UlidCreator;
19-
import io.serverlessworkflow.api.types.Document;
2019
import io.serverlessworkflow.api.types.SchemaInline;
2120
import io.serverlessworkflow.api.types.Workflow;
2221
import io.serverlessworkflow.impl.events.EventConsumer;
@@ -52,9 +51,9 @@ public class WorkflowApplication implements AutoCloseable {
5251
private final ExpressionFactory exprFactory;
5352
private final ResourceLoaderFactory resourceLoaderFactory;
5453
private final SchemaValidatorFactory schemaValidatorFactory;
55-
private final WorkflowIdFactory idFactory;
54+
private final WorkflowInstanceIdFactory idFactory;
5655
private final Collection<WorkflowExecutionListener> listeners;
57-
private final Map<WorkflowId, WorkflowDefinition> definitions;
56+
private final Map<WorkflowDefinitionId, WorkflowDefinition> definitions;
5857
private final WorkflowPositionFactory positionFactory;
5958
private final ExecutorServiceFactory executorFactory;
6059
private final RuntimeDescriptorFactory runtimeDescriptorFactory;
@@ -106,7 +105,7 @@ public Collection<EventPublisher> eventPublishers() {
106105
return eventPublishers;
107106
}
108107

109-
public WorkflowIdFactory idFactory() {
108+
public WorkflowInstanceIdFactory idFactory() {
110109
return idFactory;
111110
}
112111

@@ -142,7 +141,7 @@ public SchemaValidator getValidator(SchemaInline inline) {
142141
private ResourceLoaderFactory resourceLoaderFactory = DefaultResourceLoaderFactory.get();
143142
private SchemaValidatorFactory schemaValidatorFactory;
144143
private WorkflowPositionFactory positionFactory = () -> new QueueWorkflowPosition();
145-
private WorkflowIdFactory idFactory = () -> UlidCreator.getMonotonicUlid().toString();
144+
private WorkflowInstanceIdFactory idFactory = () -> UlidCreator.getMonotonicUlid().toString();
146145
private ExecutorServiceFactory executorFactory = new DefaultExecutorServiceFactory();
147146
private EventConsumer<?, ?> eventConsumer;
148147
private Collection<EventPublisher> eventPublishers = new ArrayList<>();
@@ -192,7 +191,7 @@ public Builder withSchemaValidatorFactory(SchemaValidatorFactory factory) {
192191
return this;
193192
}
194193

195-
public Builder withIdFactory(WorkflowIdFactory factory) {
194+
public Builder withIdFactory(WorkflowInstanceIdFactory factory) {
196195
this.idFactory = factory;
197196
return this;
198197
}
@@ -249,15 +248,13 @@ public WorkflowApplication build() {
249248
}
250249
}
251250

252-
private static record WorkflowId(String namespace, String name, String version) {
253-
static WorkflowId of(Document document) {
254-
return new WorkflowId(document.getNamespace(), document.getName(), document.getVersion());
255-
}
251+
public Map<WorkflowDefinitionId, WorkflowDefinition> workflowDefinitions() {
252+
return Collections.unmodifiableMap(definitions);
256253
}
257254

258255
public WorkflowDefinition workflowDefinition(Workflow workflow) {
259256
return definitions.computeIfAbsent(
260-
WorkflowId.of(workflow.getDocument()), k -> WorkflowDefinition.of(this, workflow));
257+
WorkflowDefinitionId.of(workflow), k -> WorkflowDefinition.of(this, workflow));
261258
}
262259

263260
@Override
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.impl;
17+
18+
import io.serverlessworkflow.api.types.Document;
19+
import io.serverlessworkflow.api.types.Workflow;
20+
21+
record WorkflowDefinitionId(String namespace, String name, String version) {
22+
23+
public static final String DEFAULT_VERSION = "0.0.1";
24+
public static final String DEFAULT_NAMESPACE = "org.acme";
25+
26+
public static WorkflowDefinitionId of(Workflow workflow) {
27+
Document document = workflow.getDocument();
28+
return new WorkflowDefinitionId(
29+
document.getNamespace(), document.getName(), document.getVersion());
30+
}
31+
32+
public static WorkflowDefinitionId fromName(String name) {
33+
return new WorkflowDefinitionId(DEFAULT_NAMESPACE, name, DEFAULT_VERSION);
34+
}
35+
}

impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowIdFactory.java renamed to impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowInstanceIdFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
import java.util.function.Supplier;
1919

2020
@FunctionalInterface
21-
public interface WorkflowIdFactory extends Supplier<String> {}
21+
public interface WorkflowInstanceIdFactory extends Supplier<String> {}

0 commit comments

Comments
 (0)