Skip to content

Commit 11b01fc

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

File tree

3 files changed

+45
-12
lines changed

3 files changed

+45
-12
lines changed

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

Lines changed: 9 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;
@@ -36,6 +35,7 @@
3635
import java.util.Collection;
3736
import java.util.Collections;
3837
import java.util.Map;
38+
import java.util.Optional;
3939
import java.util.ServiceLoader;
4040
import java.util.ServiceLoader.Provider;
4141
import java.util.concurrent.ConcurrentHashMap;
@@ -52,9 +52,9 @@ public class WorkflowApplication implements AutoCloseable {
5252
private final ExpressionFactory exprFactory;
5353
private final ResourceLoaderFactory resourceLoaderFactory;
5454
private final SchemaValidatorFactory schemaValidatorFactory;
55-
private final WorkflowIdFactory idFactory;
55+
private final WorkflowInstanceIdFactory idFactory;
5656
private final Collection<WorkflowExecutionListener> listeners;
57-
private final Map<WorkflowId, WorkflowDefinition> definitions;
57+
private final Map<WorkflowDefinitionId, WorkflowDefinition> definitions;
5858
private final WorkflowPositionFactory positionFactory;
5959
private final ExecutorServiceFactory executorFactory;
6060
private final RuntimeDescriptorFactory runtimeDescriptorFactory;
@@ -106,7 +106,7 @@ public Collection<EventPublisher> eventPublishers() {
106106
return eventPublishers;
107107
}
108108

109-
public WorkflowIdFactory idFactory() {
109+
public WorkflowInstanceIdFactory idFactory() {
110110
return idFactory;
111111
}
112112

@@ -142,7 +142,7 @@ public SchemaValidator getValidator(SchemaInline inline) {
142142
private ResourceLoaderFactory resourceLoaderFactory = DefaultResourceLoaderFactory.get();
143143
private SchemaValidatorFactory schemaValidatorFactory;
144144
private WorkflowPositionFactory positionFactory = () -> new QueueWorkflowPosition();
145-
private WorkflowIdFactory idFactory = () -> UlidCreator.getMonotonicUlid().toString();
145+
private WorkflowInstanceIdFactory idFactory = () -> UlidCreator.getMonotonicUlid().toString();
146146
private ExecutorServiceFactory executorFactory = new DefaultExecutorServiceFactory();
147147
private EventConsumer<?, ?> eventConsumer;
148148
private Collection<EventPublisher> eventPublishers = new ArrayList<>();
@@ -192,7 +192,7 @@ public Builder withSchemaValidatorFactory(SchemaValidatorFactory factory) {
192192
return this;
193193
}
194194

195-
public Builder withIdFactory(WorkflowIdFactory factory) {
195+
public Builder withIdFactory(WorkflowInstanceIdFactory factory) {
196196
this.idFactory = factory;
197197
return this;
198198
}
@@ -249,15 +249,13 @@ public WorkflowApplication build() {
249249
}
250250
}
251251

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-
}
252+
public Optional<WorkflowDefinition> workflowDefinition(WorkflowDefinitionId workflowId) {
253+
return Optional.ofNullable(definitions.get(workflowId));
256254
}
257255

258256
public WorkflowDefinition workflowDefinition(Workflow workflow) {
259257
return definitions.computeIfAbsent(
260-
WorkflowId.of(workflow.getDocument()), k -> WorkflowDefinition.of(this, workflow));
258+
WorkflowDefinitionId.of(workflow), k -> WorkflowDefinition.of(this, workflow));
261259
}
262260

263261
@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)