1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package de.kaiserpfalzedv.commons.rest.workflow;
19
20 import java.util.Optional;
21
22 import de.kaiserpfalzedv.commons.core.workflow.WorkflowInfoImpl;
23 import jakarta.enterprise.inject.Produces;
24 import jakarta.inject.Singleton;
25 import jakarta.validation.constraints.NotNull;
26
27
28
29
30
31
32
33 @Singleton
34 public class WorkflowProvider {
35 private final ThreadLocal<WorkflowInfoImpl> infos = new WorkflowInfoThreadLocal();
36
37 @Produces
38 public Optional<WorkflowInfoImpl> getWorkflowInfo() {
39 return Optional.ofNullable(this.infos.get());
40 }
41
42 public void registerWorkflowInfo(@NotNull final WorkflowInfoImpl context) {
43 this.infos.set(context);
44 }
45
46 public void unregisterWorkflowInfo() {
47 this.infos.remove();
48 }
49
50
51
52
53 private static class WorkflowInfoThreadLocal extends ThreadLocal<WorkflowInfoImpl> {
54 @Override
55 public WorkflowInfoImpl initialValue() {
56 return WorkflowInfoImpl.builder().build();
57 }
58 }
59 }